导入需求并重用现有链接
在此步骤中,您使用 Requirements Toolbox™ 编程接口从 Microsoft® Word 文档导入需求并创建到 Simulink®模型的链接。然后,您导入另一组需求,并通过将链接目标迁移到最近导入的需求来重用现有链接。
导入需求
打开slvnvdemo_powerwindowController
模型,它也会打开其关联的链接集。
open_system("slvnvdemo_powerwindowController.slx")
PowerWindowSpecification
Word 文档包含电动车窗控制器设计的需求。将需求作为引用需求导入,以便您可以继续在 Microsoft Word 文档中管理它们,并在 Word 文档中进行更改时更新导入的需求集。
[~,~,refReqSet] = slreq.import("PowerWindowSpecification.docx", ... ReqSet="ReadOnlyImport.slreqx");
找到 Index
属性设置为 1.3.5
的引用需求。
ref = find(refReqSet,Index="1.3.5");
创建从 Truth Table
模块到所引用需求的链接。
designModel = "slvnvdemo_powerwindowController"; truthTable = designModel+ "/Truth Table"; link1 = slreq.createLink(truthTable,ref);
创建从 Truth Table1
模块到所引用需求的链接。
truthTable1 = designModel+"/Truth Table1";
link2 = slreq.createLink(truthTable1,ref);
导航到 Simulink模型中第一个链接的源。
slreq.show(link1.source);
导航到需求编辑器中第一个链接的目标。
slreq.show(link1.destination);
重新导入需求并重用现有链接
假设您决定将需求的真实来源从 Microsoft Word 迁移到 Requirements Toolbox。将 Microsoft Word 文档中的需求重新导入为可编辑需求。
[~,~,editableReqSet] = slreq.import("PowerWindowSpecification.docx", ... ReqSet="EditableImport.slreqx",AsReference=false);
获取包含 Simulink模型和引用需求之间的链接的链接集的句柄。从链接集中获取链接。
ls = slreq.find(Type="LinkSet");
links = getLinks(ls);
对于链接集中的每个链接,检查链接目标是否是引用需求集集中的需求,然后使用 slreq.structToObj
获取引用需求的句柄。获取引用需求的 ID,然后在可编辑需求集中查找具有相同 ID 的需求。使用setDestination
将链接目标重定向至可编辑需求。
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); link.setDestination(req); updatedLinks = updatedLinks + 1; end end
显示更新的链接数量。
disp("Updated "+num2str(updatedLinks)+" links from "+designModel);
Updated 2 links from slvnvdemo_powerwindowController