Use Callbacks to Customize Requirement Import Behavior
You can use callbacks to execute code when you import requirements from third-party tools
or when you update requirements. The PreImportFcn
callback executes
before you import requirements and the PostImportFcn
callback executes
after you import the requirements. You can use these callbacks to customize import
behavior.
Assign Code to Callbacks
You can assign code to the PreImportFcn
and
PostImportFcn
callbacks by using the Requirements
Editor or at the MATLAB® command line.
Assign Code to Callbacks by Using the Requirements Editor
To use the Requirements Editor to assign code to the
PreImportFcn
and PostImportFcn
callbacks:
In the Requirements Editor, click Import.
In the Importing Requirements dialog, set Document type to the third-party tool that you are importing requirements from.
Next to Document location, click Browse and select the requirement file, document, module, or other requirement container.
Apply your desired import settings. For more information, see Import Requirements from Third-Party Applications.
In the Importing Requirements dialog box, expand the Callbacks section.
Select the PreImportFcn or PostImportFcn tab.
Enter your code in the box. You can enter code or the name of a MATLAB script that contains your code.
Click Import.
Assign Code to Callbacks Programmatically
To assign code to callbacks programmatically:
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.
At the MATLAB command line, use
slreq.import
to import your requirements. Use thepreImportFcn
andpostImportFcn
arguments to assign your scripts to the callbacks.
getPreImportFcn
and getPostImportFcn
. You can change the code assigned to the callbacks by
using setPreImportFcn
and setPostImportFcn
.Customize Requirement Import Behavior
You can use the code assigned to callbacks to execute commands before and after you
import requirements. For example, you can use the PreImportFcn
callback to customize your import options or use the PostImportFcn
callback to specify property values of imported requirements.
Customize the Pre-Import Behavior
You can use the PreImportFcn
callback to specify how
Requirements Toolbox™ imports requirements from different third-party tools. Use slreq.getCurrentImportOptions
in the callback to return one of these
objects, depending on the third-party tool:
You can modify this object in the callback code to change how Requirements Toolbox imports the requirements.
For example, you can specify the mapping file to use when you import ReqIF™ files. Modify this example code to specify the full file path of your
mapping file and assign the code to the PreImportFcn
callback:
importOptions = slreq.getCurrentImportOptions;
importOptions.MappingFile = "C:\Users\jdoe\Documents\myMappingFile.xml";
Customize the Post-Import Behavior
You can use the PostImportFcn
callback to execute code that
modifies requirements after the import completes.
For example, to specify property values of the imported requirements in the
PostImportFcn
callback, use slreq.getCurrentObject
to get a handle to the Import node, then use
slreq.Reference
methods to get handles to the imported requirements.
Then, use dot notation to set the property values. For more information, see Property Access Syntax. This example code shows how to get handles to the child referenced requirements
under the current import
node.
topRef = slreq.getCurrentObject; refs = find(topRef);
IndexEnabled
and IndexNumber
properties to customize requirement index numbering. For more
information, see Customize Requirement Index Numbering. For an
example, see Import Requirements from a Microsoft Excel Document.To move a referenced requirement, use setParent
, moveUp
, or moveDown
in the PostImportFcn
callback.
See Also
slreq.getCurrentObject
| slreq.getCurrentImportOptions
| setParent