Customize Requirements and Links by Using Stereotypes
You can use stereotypes to define custom requirement or link types with custom properties. You can use stereotypes to apply properties to a subset of requirements or links in a requirement set or link set. To define a stereotype, create a profile to contain the stereotype, assign the profile to a requirement set or link set, then use the stereotypes with the requirements or links. You can reuse stereotypes by assigning profiles to multiple requirement sets or link sets.
You can create custom requirement and link types and properties by using
sl_customization
files and custom attributes. For more information,
see Define Custom Requirement and Link Types and Properties.
Create a Profile and Define Stereotypes
Stereotypes define domain-specific metadata. A profile is a package of stereotypes. In Requirements Toolbox™, you can use stereotypes to define custom requirement or link types with custom properties by using the Profile Editor.
Create Profiles
Before you can define stereotypes, you must create a profile.
Open the Requirements Editor by entering this command at the MATLAB® command line:
slreq.editor
In the Profile section, click Profile Editor .
In the Profile Editor, click New Profile. Select the new profile.
In the right pane, name the profile and add a description. Click Save.
The editor saves the profile as an XML file.
Define Stereotypes
To define a stereotype:
In the Profile Editor, select the profile to contain the stereotype and click New Stereotype. Select the new stereotype.
In the right pane, enter a name and description for the stereotype.
Set Applies to to
Requirement
orLink
.Set Base behavior to one of the built-in requirement types or link types.
The base behavior affects how the requirement or link contributes to the implementation and verification status. Requirement and link stereotypes inherit functionality from the built-in requirement and link types the same way as custom requirement and link types. For more information, see Choose a Built-in Type as a Base Behavior.
If you are creating a stereotype for links, set the forward and backward name for the stereotype by using the Forward name and Backward name properties.
The Requirements Editor uses the forward name and backward name to describe the relationship between two linked items. For example, if you create a stereotype named
Satisfy
, you might choose the forward nameSatisfies
and the backward nameSatisfied by
. For more information, see the table in Link Types.
Tip
To inherit properties from another stereotype, set Base stereotype to a stereotype from an open profile. The base stereotype and the child stereotype must both have Applies to set to the same value. However, the base and child stereotypes can have different Base behavior values.
You can only use abstract stereotypes as base stereotypes and cannot apply them directly to requirements or links. To create an abstract stereotype, select Abstract stereotype.
Add Properties to Stereotypes
You can add properties to stereotypes to provide additional information about requirements and links. Stereotype properties only apply to the requirements or links that you apply the stereotype to. This behavior is different from custom attributes, which apply to all of the requirements or links in the requirement set or link set. For more information, see Define Custom Requirement and Link Types and Properties.
To add properties to a stereotype, in the Profile Editor, select a stereotype, then click the Add a new property button . Enter a name for the property and select a type. For numeric types, you can set the unit.
To use an enumeration as the type for a stereotype property, set
Type to Enumeration
. Enter the name
of an existing enumeration class in the Enumeration Definition dialog, then click
OK. If an enumeration class does not exist, you can create
one by entering the name for a new enumeration class, then clicking
OK. In the Enumeration class not found dialog, click
Create to create an enumeration class file from a template.
Edit the class file to contain your desired enumerations. For more information, see
Define Enumeration Classes.
Assign Profiles and Use Stereotypes
To use stereotypes with requirements and links, assign the profile to the requirement set or link set:
Load a requirement set or link set or create a new one. For more information, see the Examples section of Requirements Editor.
In the Requirements Editor, click Show Requirements and select a requirement set, or click Show Links and select a link set.
In the Profile section, click Load.
Select the profile, then click Open.
Alternatively, you can assign profiles programmatically by using the
importProfile
function for slreq.ReqSet
or importProfile
for slreq.LinkSet
.
To use a stereotype with a requirement or a link, in the Requirements Editor, select the requirement or link. In the right pane, under Properties, set the Type to the stereotype.
Alternatively, you can programmatically set the Type
property of
the requirement or link to the fully qualified name of the stereotype. For
example:
myReq.Type = "myProfile.ReqStereotype";
Set Stereotype Property Values
To set stereotype property values, in the Requirements Editor, select the requirement or link. In the right pane, under Stereotype Attributes, set the value.
To set stereotype property values programmatically, use the setAttribute
method of slreq.Requirement
or the setAttribute
method of slreq.Link
. To view stereotype
property values programmatically, use the getAttribute
method of slreq.Requirement
or the getAttribute
method of slreq.Link
.
Edit Profiles and Stereotypes
Before you can edit profiles or stereotypes, close the requirement sets and link sets
that the profile is assigned to. In the Requirements Editor, select the
requirement set or link set, then click Close. Alternatively, you
can use close
or slreq.clear
.
To edit a profile or stereotype, open the Profile Editor. Click Open to open the profile. You can edit properties of the profile and its stereotypes, including the name, description, base behavior, base stereotype, and stereotype properties.
Fix Outdated Profiles
If you make changes to a profile and then load a requirement set or link set that uses that profile, Requirements Toolbox indicates that the profile assigned to the requirement set or link set is outdated.
If you load a requirement set with an outdated profile, the Outdated Profile dialog appears. You can view the changes made to the profile since the requirement set was last loaded by expanding the Details section. To apply the changes to the requirement set, next to Delete all stereotypes and properties not found in a profile and synchronize all changes, click Fix. If you do not want to apply the changes to your requirement set, you can close the requirement set by, next to Close the requirement set and make sure all profiles can be found on the MATLAB search path, clicking Fix.
Alternatively, you can load a requirement set and fix the outdated profile by
using slreq.load
with the forceResolve
argument set to
true
.
If you load a link set with an outdated profile, the MATLAB command window displays a warning that a profile assigned to the link set is outdated. To open the Outdated Profile dialog, in the Requirements Editor, click Show Links. Select the link set and, in the right pane, under Properties, click Details.
Note
You cannot load the link set and fix the outdated profile by using the API.
Remove Stereotypes or Properties
If you remove a stereotype from a profile and apply the profile changes to a
requirement set or link set, Requirements Toolbox reverts the requirement type to Functional
and the
link type to Relate
for requirements or links that used that
stereotype.
If you remove a stereotype property from a stereotype and apply the profile changes to a requirement set or link set, Requirements Toolbox removes that property and the property values from the requirements or links that used that stereotype.
Manage and Remove Profiles
To view the profiles applied to a requirement set or link set, in the Requirements Editor, select the requirement set or link set and click Manage. The Linked profiles dialog shows the profiles assigned to the selected requirement set or link set.
To remove a profile from a requirement set or link set, select the profile in the Linked profiles dialog and click Remove. If you remove a profile, Requirements Toolbox applies these changes to requirements and links that used the profile:
Sets the requirement type to
Functional
Sets the link type to
Relate
Removes the stereotype properties and deletes the stereotype property values
Note
Requirements Toolbox also applies these changes if you delete or rename the profile XML file.
Create Stereotypes from Built-In Profiles
If you have Simulink®
Fault Analyzer™, you can specify automotive safety requirements using the
mwAutomotive
built-in profile template. To create a new profile from
this template, in the Requirements Editor, in the Profile
section, click Load > mwAutomotive.
Click Profile Editor. The profile includes a stereotype that has the properties shown below.
Modify the properties of this stereotype to meet your design specifications.