Main Content

setSource

Class: slreq.Link
Package: slreq

Set requirement link source

Syntax

setSource(myLink,src)

Description

setSource(myLink,src) sets the link source artifact src for the slreq.Link object myLink. You can set a link source only to a linkable artifact that belongs to the original link source artifact.

Input Arguments

expand all

Handle to a link, specified as an slreq.Link object.

Artifact to serve as the link source, specified as a Simulink Requirements linkable artifact. See Linkable Items.

Examples

Set Simulink Blocks as Link Sources

% Set the Gain block in model myModel as the source for link myLink
setSource(myLink, 'myModel/Gain');

Set Simulink Test Objects as Link Source

% Create a test file, test suite, and a test case
myTestfile = sltest.testmanager.TestFile('my_test_file.mldatx');
myTestsuite = sltest.testmanager.TestSuite(myTestfile,'My Test Suite');
myTestcase = sltest.testmanager.TestCase(myTestsuite,'equivalence','Equivalence Test Case');

% Create a link from the test case to requirement myReq
myLink = slreq.createLink(myTestcase, req);

% Set the link source to the test suite
setSource(myLink, myTestsuite);

Set Stateflow Objects as Link Sources

% Get Stateflow Root Handle
rt = sfroot;

% Find the state with the name 'Intermediate'
myState = rt.find('-isa', 'Stateflow.State', 'Name', 'Intermediate');

% Set the source for link myLink to myState
setSource(myLink, myState);

Set Simulink Data Dictionary Entries as Link Sources

% Get handle to Simulink data dictionary entry
myDict = Simulink.data.dictionary.open('myDictionary.sldd');
dataSectObj = getSection(myDict,'Design Data');
myDictEntry = getEntry(dataSectObj,'myEntry');

% Set the source for link myLink to myDictEntry
setSource(myLink, myDictEntry);

Change a Link Source to a Different Source Artifact

% Get destination of link link_1
dest = destination(link_1);

% Create a new link, link_2, with source newSrc and destination dest
link_2 = slreq.createLink(newSrc, dest);

% Copy link properties
link_2.Description = link_1.Description;
link_2.Rationale = link_1.Rationale;
link_2.Keywords = link_1.Keywords;
comments = link_1.Comments;
for i = 1:length(comments)
  link_2.addComment(comments(i).Text);
end

% Delete link_1
remove(link_1);
Introduced in R2019b