User`s guide

9 Custom Types of Requirements Documents
9-12
% Create a default (blank) requirement link type
linkType = ReqMgr.LinkType;
linkType.Registration = mfilename;
% Label describing this link type
linkType.Label = 'ABC file (for demonstration)';
% File information
linkType.IsFile = 1;
linkType.Extensions = {'.abc'};
% Location delimiters
linkType.LocDelimiters = '>@';
linkType.Version = ''; % not required
% Uncomment the functions that are implemented below
linkType.NavigateFcn = @NavigateFcn;
linkType.ContentsFcn = @ContentsFcn;
function NavigateFcn(filename,locationStr)
if ~isempty(locationStr)
findId=0;
switch(locationStr(1))
case '>'
lineNum = str2num(locationStr(2:end));
openFileToLine(filename, lineNum);
case '@'
openFileToItem(filename,locationStr(2:end));
otherwise
openFileToLine(filename, 1);
end
end
function openFileToLine(fileName, lineNum)
if lineNum > 0
if matlab.desktop.editor.isEditorAvailable
matlab.desktop.editor.openAndGoToLine(fileName, lineNum);
end
else
edit(fileName);
end
function openFileToItem(fileName, itemName)
reqStr = ['Requirement:: "' itemName '"'];
lineNum = 0;
fid = fopen(fileName);
i = 1;
while lineNum == 0
lineStr = fgetl(fid);
if ~isempty(strfind(lineStr, reqStr))
lineNum = i;
end;
if ~ischar(lineStr), break, end;
i = i + 1;
end;
fclose(fid);
openFileToLine(fileName, lineNum);