Main Content

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:

  1. Open your requirement set by clicking Open. Select the SLREQX file and click Open.

  2. Select the requirement set in the Requirements Editor.

  3. In the Details pane, under Callbacks, select the PostLoadFcn or PreSaveFcn tab.

    Requirements Editor with the PostLoadFcn and PreSaveFcn tabs in view.

  4. 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:

  1. In MATLAB, select the Home tab, then click New Script.

  2. In the script, enter the code that you want the callback to execute.

  3. Select the Editor tab, then click Save. Enter a name for the script, then click Save.

  4. Load your requirement set and return the slreq.ReqSet object by using slreq.load or slreq.open.

  5. Assign the script as the PostLoadFcn or PreSaveFcn callback by using setPostLoadFcn or setPreSaveFcn.

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 callback to customize the requirement set load and save behavior. For example, you can use the PostLoadFcn 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.

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

| | |

Related Topics