Execute Code When Loading and Saving Requirement Sets
You can use Requirements Toolbox™ callbacks to execute code when you load and save requirement sets. The
PostLoadFcn
callback executes when you load the requirement set and
the PreSaveFcn
callback executes when you save the requirement set. You
can assign code to the callbacks to customize the requirement set load and save
behavior.
Assign Code to Callbacks
You can assign code to the callbacks in the Requirements Editor or at the MATLAB® command line.
Assign Code to Callbacks in the Requirements Editor
To assign code to the PostLoadFcn
and
PreSaveFcn
callbacks in the Requirements Editor:
Open your requirement set by clicking Open. Select the SLREQX file and click Open.
Select the requirement set in the Requirements Editor.
In the right pane, under Callbacks, select the PostLoadFcn or PreSaveFcn tab.
Enter your code in the box.
Alternatively, you can enter your code in a script. In the PostLoadFcn or PreSaveFcn tab, enter the name of the script. The script must be on the MATLAB path.
Assign Code to Callbacks Programmatically
To assign code to the PostLoadFcn
or
PreSaveFcn
callback at the MATLAB command line:
In MATLAB, select the Home tab, then click New Script.
In the script, enter the code that you want the callback to execute.
Select the Editor tab, then click Save. Enter a name for the script, then click Save.
Load your requirement set and return the
slreq.ReqSet
object by usingslreq.load
orslreq.open
.Assign the script as the
PostLoadFcn
orPreSaveFcn
callback by usingsetPostLoadFcn
orsetPreSaveFcn
.
You can view the code assigned to the PostLoadFcn
and
PreSaveFcn
callbacks by using getPostLoadFcn
and getPreSaveFcn
.
Customize Requirement Set Load and Save Behavior
You can use the code assigned to a callback to customize the requirement set load and
save behavior. For example, you can use the PostLoadFcn
callback to:
Load the Requirements Editor view settings from a MAT file by using
slreq.importViewSettings
.Open a design artifact, such as a Simulink® model or MATLAB script, by using
open
.Run linked tests by using
runTests
.
Note
To copy the requirement links when you copy a block in the
PostLoadFcn
callback, you must load the link set file
before you copy the block. Use slreq.map
to get the link set file path. Then, use slreq.load
to load the link set.
You can also, for example, use PreSaveFcn
to export the
current Requirements Editor view settings to a MAT-file by using slreq.exportViewSettings
.
You can use slreq.getCurrentObject
in the PostLoadFcn
and
PreSaveFcn
callbacks to get a handle to the requirement set
within the callbacks. For more information, see the Tips section of slreq.getCurrentObject
.
See Also
slreq.ReqSet
| slreq.getCurrentObject
| setPostLoadFcn
| setPreSaveFcn