Create and Store Links
You can use links and link sets to trace requirements to the design and test items that implement and verify them. Each link and link set has a corresponding API object. You can use theRequirements Editor, Requirements Perspective, a traceability matrix, or the MATLAB®command line to create links between requirements, MATLAB code, Simulink®blocks,动态仿真模块Test™test cases, and other items. You can also view and edit the links.
Link Objects, Sources, and Destinations
Each link has a correspondingslreq.Link
object. You can provide additional traceability information by using link properties, custom attributes, and stereotypes. For more information, see:
Links point from source items to destination items, which are contained in source artifacts and destination artifacts, respectively. For example, consider a link that points from a Simulink block to a requirement. The Simulink model is the source artifact and the block is the source item. The requirement set is the destination artifact and it contains the requirement, which is the destination item.
相关项如果是有外向链接urce of a link. Conversely, an item has an incoming link if it is the destination of a link. For example, if a link points from a Simulink block to a requirement, the Simulink block has an outgoing link and the requirement has an incoming link.
Link Storage
Link sets contain links. Each link set you load has a correspondingslreq.LinkSet
object. When you create a link, Requirements Toolbox™ creates a link set and saves it as an SLMX file in the same folder as the source artifact. The link set name is the source artifact base name and the source artifact extension, separated by a tilde. For example, Requirements Toolbox stores outgoing links from a MATLAB function calledmyFunction.m
in a link set file calledmyFunction~m.slmx
.
Note
Link sets that contain links from Simulink models combine the model base name and~mdl
to prevent link resolution issues if the model file extension changes between.mdl
and.slx
. For example, Requirements Toolbox stores outgoing links fromvdp.slx
in a link set file calledvdp~mdl.slmx
.
年代ave Links
When you create links from artifacts such as Simulink models or动态仿真模块Testfiles, you can save the changes to the link set by saving the artifact.
To save the changes to a link set when you create or edit links to lines of MATLAB code or plain-text external code, use one of these approaches:
In the MATLAB Editor, right-click and selectRequirements>年代ave Links.
In theRequirements Editor, click年代how Links. Select the link set, and click年代ave.
At the MATLAB command line, use
save
.
Linkable Items
You can create links between these requirements items, model entities, test artifacts, and code:
Requirements Toolboxobjects:
slreq.Requirement
objectsslreq.Reference
objectsslreq.Justification
objects
动态仿真模块entities:
Blocks
年代ubsystems
动态仿真模块data dictionary entries
年代tateflow®objects:
年代tates
Charts and subcharts
Transitions
年代ystem Composer™ architecture entities:
Components
Ports
Views
年代ystem Composer sequence diagram entities:
Lifelines
Gates
Messages
Fragments
动态仿真模块Testobjects:
Test files
Test suites
Test cases
Iterations
Assessments
Lines of MATLAB code in:
MATLAB code files (
.m
extension). For more information, seeRequirements Traceability for MATLAB Code.MATLAB Function blocks. For more information, seeIntegrate Basic Algorithms Using MATLAB Function Block(Simulink).
MATLAB-based Simulink tests. For more information, seeTest Models Using MATLAB-Based Simulink Tests(Simulink Test).
Lines of code in plain-text external code files, such as C and H files. You can also link to HTML files, but not XML or JSON.
Note
To create links to lines of plain-text external code, you must open the code in the MATLAB Editor. For more information, seeLink Requirements to MATLAB or Plain Text Code.
Create Links
You can use theRequirements Editor, Requirements Perspective, a traceablity matrix, or the MATLAB command line to create links.
To create a link from a design or test item to a requirement by using theRequirements Editor:
年代elect one of these items:
动态仿真模块or Stateflow model element
年代ystem Composer architecture element
动态仿真模块Testtest case
Code range in the MATLAB Editor
动态仿真模块data dictionary entry
Tip
To link to MATLAB functions and enable change tracking for the entire body of the function, create the link to the line that contains the
function
keyword.In theRequirements Editor, select the requirement.
ClickAdd Link, then select the menu option that contains the selection that you want to link to.
To create a requirement-to-requirement link:
年代elect the requirement that you want to link as the source item.
ClickAdd Link>年代elect for Linking with Requirement.
年代elect the requirement that you want to link as the destination item.
Create the link by selectingAdd Link>Create a link from.
Tip
You can create links without leaving the Simulink Editor by using the Requirements Perspective. For more information, seeLink Blocks and Requirements.
You can create links between multiple artifacts in a single window by using a traceability matrix. For more information, seeTrack Requirement Links with a Traceability Matrix.
Create Links Programmatically
To create links at the MATLAB command line:
Get the object or handle for the link source. For example:
open_system("vdp") src = get_param("vdp/Mu","Handle");
Get the object or handle for the link destination. For example:
dest = slreq.find(Type="Requirement",Summary="My requirement");
Use the
slreq.createLink
function to create the link.newLink = slreq.createLink(src,dest);
To create links to MATLAB code or plain-text external code programmatically, useslreq.TextRange
对象。有关更多信息,请参见Requirements Traceability for MATLAB Code.
Link Types
Each link has a type that describes the relationship between the source and destination items. TheTypeproperty value of theslreq.Link
object describes the link type.
Assigned Link Types
Each link type has an intended use case. For example, theImplement
link type indicates a relationship between a requirement and a design item that implements the requirement. When you create a link between two items,Requirements Toolbox设置链接类型和指定items as the source or destination depending on the type of artifact that they belong to. For example, if you create a link between a requirement and a Simulink model element,Requirements Toolboxassumes that the model element implements the requirement, sets the link type toImplement
, and designates the model element as the source and the requirement as the destination.
If there is no assumed link type for a link created between two items, thenRequirements Toolboxsets the link type toRelate
. For example, requirement-to-requirement links and links from plain-text external code default toRelate
.
Edit the Link Type
After you create the link, you can edit the link type in theRequirements Editor, the Requirements Perspective, or at the MATLAB command line. In theRequirements Editor, click年代how Links. Select a link and, in the right pane, underProperties, select the desired link type from theTypelist.
Built-in Link Types
Requirements Toolboxprovides six built-in link types.
The forward direction indicates how the source relates to the destination. Similarly, the backward direction indicates how the destination relates to the source.
Type | Description | 年代ource-to-Destination Example | Forward Direction | Backward Direction |
---|---|---|---|---|
Relate |
|
Requirement to requirement | The first requirement isrelated tothe second requirement. |
The second requirement isrelated tothe first requirement. |
Implement |
有关更多信息,请参见Review Requirements Implementation Status. |
动态仿真模块model element to requirement | The Simulink model elementimplementsthe requirement. |
The requirement isimplemented bythe Simulink model element. |
Verify |
有关更多信息,请参见Review Requirements Verification Status. |
动态仿真模块test case to requirement | The Simulink test caseverifiesthe requirement. |
The requirement isverified bythe Simulink test case. |
Derive |
年代pecifies which source item derives the destination item |
Importedreferenced requirementto requirement | The imported referenced requirementderivesthe requirement. |
The requirement isderived fromthe imported referenced requirement. |
Refine |
年代pecifies which source item adds detail for the functionality specified by the destination item |
Low-level requirement to high-level requirement | The low-level requirementrefinesthe high-level requirement. |
The high-level requirement isrefined bythe low-level requirement. |
Confirm |
有关更多信息,请参见Include Results from External Sources in Verification Status. |
Requirement to external test result | The requirement isconfirmed bythe external test result. |
The external test resultconfirmsthe requirement. |
TheImplement
andVerify
link types describe requirement-to-model and requirement-to-test relationships. These links affect the implementation status and verification status. For more information, seeReview Requirements Implementation StatusandReview Requirements Verification Status.
The link type also affects the impact direction in the Traceability Diagram window. For more information, seeVisualize Links with Traceability Diagrams.
Custom Link Types
In addition to the built-in types, you can define custom link types. Custom link types must use one of the built-in types as the base behavior. The custom link type inherits some functionality from the built-in type, including how the link type contributes to the implementation and verification statuses. For more information, seeChoose a Built-in Type as a Base Behavior.
You can define custom link types by using stereotypes or by usingsl_customization
files. For more information, seeDefine Custom Requirement and Link Types and Properties.
View and Edit Links
To view the loaded link sets and the links they contain, in theRequirements Editor, clickView Links. You can then select a link and view or edit its properties or custom attributes. For more information, see年代et Link Properties, Custom Attributes, or Stereotype Properties.
You can also view the links for a particular requirement in theRequirements Editorwhen you select a requirement. In the right pane, underLinks, the outgoing links iconindicates outgoing links and the incoming links iconindicates incoming links.
To view links in the Simulink Editor by using the Requirements Perspective:
Open the Requirements Perspective in a Simulink model by clicking the年代how Perspectives viewsicon in the lower-right corner of the model canvas and selectRequirements.
In theRequirementstab, ensure thatLayout>Requirements Browser被选中。
In theRequirementspane, in theViewmenu, select
Links
.
To visualize links, create a traceability matrix or traceability diagram. For more information, seeTrack Requirement Links with a Traceability MatrixandVisualize Links with Traceability Diagrams.
Delete Links and Link Sets
To delete a link, in theRequirements Editor, click年代how Links. Select a link and, in theLinkssection, click.
To delete a link set:
Locate the SLMX file that contains the link set. By default, link set files are in the same folder as the source artifact.
Close the linked artifacts before deleting a link set, including requirement sets,动态仿真模块Testfiles, MATLAB code, Simulink data dictionaries, and Simulink, Stateflow or System Composer models.
At the MATLAB command line, clear the loaded requirements and links by entering:
slreq.clear
Delete the SLMX file.
Note
If you want to delete a link set file associated with a Simulink model, ensure that the links are stored externally. For more information about how to store links externally, seeRequirements Link Storage.
年代ee Also
Requirements Editor|slreq.createLink