setPreImportFcn
Class: slreq.Reference
Namespace: slreq
Syntax
setPreImportFcn(topRef,callbackScript)
Description
setPreImportFcn(
assigns the script specified by topRef
,callbackScript
)callbackScript
as the
PreImportFcn
callback script for the Import node
topRef
.
Input Arguments
topRef
— Import node
slreq.Reference
object
Import node, specified as an slreq.Reference
object.
callbackScript
— Name of script to register
string scalar | character vector
Name of the script to register as the PreImportFcn
callback for
the Import node, specified as a string scalar or character vector.
Examples
Use PreImportFcn
Callback During Import
This example shows how to assign a script as the PreImportFcn
callback for an Import node. You get the contents of the PreImportFcn
callback for an Import node and register a different script as the PreImportFcn
callback after you import the requirements.
Import the Requirements
Use slreq.import
to import the ReqIF™ file mySpec.reqif
into Requirements Toolbox™. Name the imported requirement set myReqSet
and register the script myPreImportScript
as the PreImportFcn
callback to use during import. Return a handle to the requirement set.
[~,~,rs] = slreq.import("mySpec.reqif",ReqSet="myReqSet",preImportFcn="myPreImportScript");
The script myPreImportScript
uses slreq.getCurrentImportOptions
to get the import options, then specifies the attribute mapping file to use during import.
type myPreImportScript.m
importOptions = slreq.getCurrentImportOptions; importOptions.MappingFile = "myMappingFile.xml";
The mapping file myMappingFile.xml
uses a generic mapping.
Get the custom ID for the requirement with Index
set to 1
.
req1 = find(rs,Index="1");
cID = req1.CustomId
cID = 0x0 empty char array
The generic mapping does not map the ReqIF attribute ID
to the Requirement Toolbox attribute Custom ID
. Instead, ID
imports as a custom attribute. Get the value for the ID
custom attribute for Requirement 1
.
cID = getAttribute(req1,"ID")
cID = 'A1'
Get and Set the PreImportFcn
Callback Script
Get a handle to the Import node, then register the script myPreImportScrip2
as the PreImportFcn
callback. Confirm that the registered callback was changed.
topRef = children(rs);
setPreImportFcn(topRef,"myPreImportScript2")
newCallback = getPreImportFcn(topRef)
newCallback = 'myPreImportScript2'
The script myPreImportScript2
uses slreq.getCurrentImportOptions
to get the import options, then specifies the attribute mapping file to use during import.
type myPreImportScript2.m
importOptions = slreq.getCurrentImportOptions; importOptions.MappingFile = "myMappingFile2.xml";
The mapping file myMappingFile2.xml
maps these attributes from the ReqIF™ file to these properties in Requirements Toolbox™:
ReqSum
toSummary
Desc
toDescription
ID
toCustom ID
Update the requirement set. The PreImportFcn
callback script also executes when you update the requirement set.
updateReferences(rs,topRef);
Get the custom ID for the requirement with Index
set to 1
.
req1 = find(rs,Index="1");
cID = req1.CustomId
cID = 'A1'
Version History
Introduced in R2022a
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)