Main Content

Import Requirements and Reuse Existing Links

In this step, you use the Requirements Toolbox™ programmatic interface to import requirements from a Microsoft® Word document and create links to the Simulink® model. Then, you import another set of requirements and reuse the existing links by migrating the link destinations to the most recenty imported requirements.

Import the Requirements

Open the slvnvdemo_powerwindowController model, which also opens its associated link set.


The PowerWindowSpecification Word document contains requirements for the power window controller design. Import the requirements as referenced requirements so that you can continue to manage them in the Microsoft Word document and update the imported requirement set when you make changes in the Word document.

[~,~,refReqSet] = slreq.import("PowerWindowSpecification.docx",ReqSet="ReadOnlyImport.slreqx");

Find the referenced requirement with the Index property set to 1.3.5.

ref = find(refReqSet,Index="1.3.5");

Create a link from the Truth Table block to the referenced requirement.

designModel = "slvnvdemo_powerwindowController";
truthTable = designModel+ "/Truth Table";
link1 = slreq.createLink(truthTable,ref);

Create a link from the Truth Table1 block to the referenced requirement.

truthTable1 = designModel+"/Truth Table1";
link2 = slreq.createLink(truthTable1,ref);

Navigate to the source of the first link in the Simulink model.;

Navigate to the destination of the first link in the Requirements Editor.;

Re-Import Requirements and Reuse Existing Links

Suppose that you decide to migrate the source of truth of the requirements from Microsoft Word to Requirements Toolbox. Re-import requirements from the Microsoft Word document as editable requirements.

[~,~,editableReqSet] = slreq.import("PowerWindowSpecification.docx",ReqSet="EditableImport.slreqx",AsReference=false);

Get a handle to the link set that contains links between the Simulink model and the referenced requirements. Get the links from the link set.

ls = slreq.find(Type="LinkSet");
links = getLinks(ls);

For each link in the link set, check if the link destination is a requirement in the referenced requirement set, then get a handle to the referenced requirement by using slreq.structToObj. Get the ID of the referenced requirement, then find a requirement in the editable requirement set with the same ID. Use setDestination to redirect the link destination to point to the editable requirement.

updatedLinks = 0;
for linkIdx = 1:numel(links)
    link = links(linkIdx);
    if strcmp(link.destination.reqSet,strcat(refReqSet.Name,".slreqx"))
        ref = slreq.structToObj(link.destination);
        ID = ref.Id;
        req = find(editableReqSet,Id=ID);
        updatedLinks = updatedLinks + 1;

Display the number of updated links.

disp("Updated "+num2str(updatedLinks)+" links from "+designModel);
Updated 2 links from slvnvdemo_powerwindowController

See Also



Related Topics