systemcomposer.profile.Stereotype
配置文件中的构造型
说明
Stereotype
对象表示 System Composer™ 模型配置文件中的构造型。
创建对象
使用 addStereotype
函数将构造型添加到配置文件中。
profile = systemcomposer.profile.Profile.createProfile("profileName"); addStereotype(profile,"stereotypeName");
属性
构造型名称,指定为字符串。该属性必须是有效的 MATLAB® 标识符。
示例: "HardwareComponent"
数据类型: string
构造型的描述文本,指定为字符串。
数据类型: string
构造型的图标名称,指定为以下选项之一:
"default"
"application"
"channel"
"controller"
"database"
"devicedriver"
"memory"
"network"
"plant"
"sensor"
"subsystem"
"transmitter"
该属性仅对组件构造型有效。使用 AppliesTo
属性设置构造型所适用的元素。
数据类型: string
构造型从中继承属性的构造型,指定为 systemcomposer.profile.Stereotype
对象。
可应用构造型的元素类型,指定为这些选项之一:
""
将构造型应用于所有元素类型。"Component"
."Port"
."Connector"
."Interface"
."InterfaceElement"
."Allocation"
.有关详细信息,请参阅交互式创建和管理分配。"Function"
,它只适用于软件架构。有关详细信息,请参阅将构造型应用于软件架构的函数。"Requirement"
,使用 Requirements Toolbox™ 许可证。有关详细信息,请参阅使用原型自定义需求和链接 (Requirements Toolbox)。"Link"
,使用 Requirements Toolbox 许可证。
数据类型: string
构造型是否为抽象构造型,指定为 1
(true
) 或 0
(false
)。如果是 true
,则该构造型不能直接应用于模型元素,而应作为其他构造型的父构造型。
数据类型: logical
构造型的限定名称,指定为 '<profile>.<stereotype>'
形式的字符向量。
数据类型: char
组件标题颜色,指定为 1x3 uint32
行向量 [Red Green Blue]
。
该属性仅对组件构造型有效。使用 AppliesTo
属性设置构造型所适用的元素。
示例: [206 232 246]
数据类型: uint32
连接线颜色,指定为 1x3 uint32
行向量 [Red Green Blue]
。
该属性仅对连接器、端口和接口构造型有效。使用 AppliesTo
属性设置构造型所适用的元素。
示例: [206 232 246]
数据类型: uint32
连接器线条样式,指定为字符向量或字符串。选项包括:
"Default"
"Dot"
"Dash"
"Dash Dot"
"Dash Dot Dot"
该属性仅对连接器、端口和接口构造型有效。使用 AppliesTo
属性设置构造型所适用的元素。
数据类型: char
| string
构造型的配置文件,构造型从该配置文件继承属性,指定为 systemcomposer.profile.Profile
对象。
包含在构造型中并从构造型基础层次结构中继承的属性,指定为字符向量元胞数组。
数据类型: char
拥有构造型中包含的属性,指定为字符向量元胞数组、字符串数组或 systemcomposer.profile.Property
对象数组。所拥有的属性不包括从构造型基础层次结构中继承的属性。
数据类型: char
| string
对象函数
addProperty | 为构造型定义自定义属性 |
removeProperty | 从构造型中删除属性 |
getDefaultElementStereotype | 获取元素的默认构造型 |
setDefaultElementStereotype | 为元素设置默认构造型 |
find | 按名称查找构造型 |
destroy | 移除模型元素 |
示例
使用 System Composer™ 以编程方式构建架构模型。
要构建模型,需添加包含数据接口、数据元素、值类型和物理接口的数据字典,然后添加组件、端口和连接。创建带有构造型和属性的配置文件,然后将这些构造型应用于模型元素。为端口分配专属接口。模型构建完成后,您可以创建自定义视图来关注特定的考虑因素。您还可以查询模型,根据指定的准则收集不同的模型元素。
添加组件、端口、连接和接口
创建一个模型并提取其架构。
model = systemcomposer.createModel("mobileRobotAPI");
arch = model.Architecture;
创建一个数据字典并添加一个数据接口。向该数据接口添加一个数据元素。向数据字典中添加一个值类型。将数据元素的类型指定为该值类型。添加一个物理接口和带有物理域类型的物理元素。将数据字典链接到模型。
dictionary = systemcomposer.createDictionary("SensorInterfaces.sldd"); interface = dictionary.addInterface("GPSInterface"); element = interface.addElement("SignalStrength"); valueType = dictionary.addValueType("SignalStrengthType",Units="dB", ... Description="GPS Signal Strength"); element.setType(valueType); physicalInterface = dictionary.addPhysicalInterface("PhysicalInterface"); physicalElement = addElement(physicalInterface,"ElectricalElement", ... Type="electrical.electrical"); linkDictionary(model,"SensorInterfaces.sldd");
保存对数据字典的更改。
dictionary.save
保存模型。
model.save
打开模型。
systemcomposer.openModel("mobileRobotAPI");
在接口编辑器中查看接口。
添加组件、端口和连接。将物理接口设置为稍后要连接的物理端口。
componentSensor = addComponent(arch,"Sensor"); sensorPorts = addPort(componentSensor.Architecture,{'MotionData','SensorPower'}, ... {'in','physical'}); sensorPorts(2).setInterface(physicalInterface) componentPlanning = addComponent(arch,"Planning"); planningPorts = addPort(componentPlanning.Architecture, ... {'Command','SensorPower1','MotionCommand'}, ... {'in','physical','out'}); planningPorts(2).setInterface(physicalInterface) componentMotion = addComponent(arch,"Motion"); motionPorts = addPort(componentMotion.Architecture,{'MotionCommand','MotionData'}, ... {'in','out'});
在 MotionData
端口上创建一个专属接口。在专属数据接口下添加一个专属数据元素。为数据元素 Rotation
指定一个单位设置为 degrees
的值类型。
ownedInterface = motionPorts(2).createInterface("DataInterface"); ownedElement = ownedInterface.addElement("Rotation"); subInterface = ownedElement.createOwnedType(Units="degrees");
在接口编辑器中查看接口。选择 Motion
组件上的 MotionData
端口。在接口编辑器中,将视图从字典视图切换为端口接口视图。
使用接口规则和默认名称规则连接组件。接口规则会将共享同一接口的组件端口连接起来。默认情况下,名称规则会将共享相同名称的组件端口连接起来。
c_sensorData = connect(arch,componentSensor,componentPlanning,Rule="interface");
c_motionData = connect(arch,componentMotion,componentSensor);
c_motionCommand = connect(arch,componentPlanning,componentMotion);
添加和连接架构端口
在架构上添加一个架构端口。
archPort = addPort(arch,"Command","in");
connect
命令需要一个组件端口作为参量。先获取组件端口,然后进行连接。
compPort = getPort(componentPlanning,"Command");
c_Command = connect(archPort,compPort);
保存模型。
model.save
按 Ctrl+Shift+A 或使用以下命令整理布局。
Simulink.BlockDiagram.arrangeSystem("mobileRobotAPI");
创建和应用带有构造型的配置文件
配置文件是可以应用于任何模型的 XML 文件。您可以在配置文件中添加具有属性的构造型,然后在配置文件编辑器中用特定值来为这些属性赋值。除了 System Composer 的内置分析功能之外,构造型还可以帮助您优化系统的性能、成本和可靠性。
创建配置文件并添加构造型
创建一个配置文件。
profile = systemcomposer.createProfile("GeneralProfile");
创建一个适用于所有元素类型的构造型。
elemSType = addStereotype(profile,"projectElement");
为不同类型的组件创建构造型。您可以根据自己的设计需求选择适当的类型。
pCompSType = addStereotype(profile,"physicalComponent",AppliesTo="Component"); sCompSType = addStereotype(profile,"softwareComponent",AppliesTo="Component");
为连接创建一个构造型。
sConnSType = addStereotype(profile,"standardConn",AppliesTo="Connector");
添加属性
为构造型添加属性。您可以使用属性来捕获模型元素的元数据,并分析非功能性需求。在导入了该配置文件的任何模型中,这些属性都会被添加到应用了该构造型的所有元素中。
addProperty(elemSType,'ID',Type="uint8"); addProperty(elemSType,'Description',Type="string"); addProperty(pCompSType,'Cost',Type="double",Units="USD"); addProperty(pCompSType,'Weight',Type="double",Units="g"); addProperty(sCompSType,'develCost',Type="double",Units="USD"); addProperty(sCompSType,'develTime',Type="double",Units="hour"); addProperty(sConnSType,'unitCost',Type="double"',Units="USD"); addProperty(sConnSType,'unitWeight',Type="double",Units="g"); addProperty(sConnSType,'length',Type="double",Units="m");
保存配置文件
profile.save;
将配置文件应用到模型
将配置文件应用到模型。
applyProfile(model,"GeneralProfile");
将构造型应用于组件。有些组件是物理组件,有些组件是软件组件。
applyStereotype(componentPlanning,"GeneralProfile.softwareComponent") applyStereotype(componentSensor,"GeneralProfile.physicalComponent") applyStereotype(componentMotion,"GeneralProfile.physicalComponent")
将连接器构造型应用于所有连接。
batchApplyStereotype(arch,'Connector',"GeneralProfile.standardConn");
将通用元素构造型应用于所有连接器和端口。
batchApplyStereotype(arch,'Component',"GeneralProfile.projectElement"); batchApplyStereotype(arch,'Connector',"GeneralProfile.projectElement");
为每个组件设置属性。
setProperty(componentSensor,'GeneralProfile.projectElement.ID','001'); setProperty(componentSensor,'GeneralProfile.projectElement.Description', ... 'Central unit for all sensors'); setProperty(componentSensor,'GeneralProfile.physicalComponent.Cost','200'); setProperty(componentSensor,'GeneralProfile.physicalComponent.Weight','450'); setProperty(componentPlanning,'GeneralProfile.projectElement.ID','002'); setProperty(componentPlanning,'GeneralProfile.projectElement.Description', ... 'Planning computer'); setProperty(componentPlanning,'GeneralProfile.softwareComponent.develCost','20000'); setProperty(componentPlanning,'GeneralProfile.softwareComponent.develTime','300'); setProperty(componentMotion,'GeneralProfile.projectElement.ID','003'); setProperty(componentMotion,'GeneralProfile.projectElement.Description', ... 'Motor and motor controller'); setProperty(componentMotion,'GeneralProfile.physicalComponent.Cost','4500'); setProperty(componentMotion,'GeneralProfile.physicalComponent.Weight','2500');
将所有连接的属性设置为相同值。
connections = [c_sensorData c_motionData c_motionCommand c_Command]; for k = 1:length(connections) setProperty(connections(k),'GeneralProfile.standardConn.unitCost','0.2'); setProperty(connections(k),'GeneralProfile.standardConn.unitWeight','100'); setProperty(connections(k),'GeneralProfile.standardConn.length','0.3'); end
添加层次结构
在 Motion
组件内添加两个名为 Controller
和 Scope
的组件。定义端口。将组件连接到架构以及彼此之间,并应用连接器构造型。架构图中的层次结构可以为组件的内部行为提供更详细的描述。
motionArch = componentMotion.Architecture; motionController = motionArch.addComponent('Controller'); controllerPorts = addPort(motionController.Architecture,{'controlIn','controlOut'}, ... {'in','out'}); controllerCompPortIn = motionController.getPort('controlIn'); controllerCompPortOut = motionController.getPort('controlOut'); motionScope = motionArch.addComponent('Scope'); scopePorts = addPort(motionScope.Architecture,{'scopeIn','scopeOut'},{'in','out'}); scopeCompPortIn = motionScope.getPort('scopeIn'); scopeCompPortOut = motionScope.getPort('scopeOut'); c_planningController = connect(motionPorts(1),controllerCompPortIn);
对于输出端口连接,可以指定目标数据元素。
c_planningScope = connect(scopeCompPortOut,motionPorts(2),DestinationElement="Rotation"); c_planningConnect = connect(controllerCompPortOut,scopeCompPortIn, ... "GeneralProfile.standardConn");
保存模型。
model.save
按 Ctrl+Shift+A 或使用以下命令整理布局。
Simulink.BlockDiagram.arrangeSystem("mobileRobotAPI/Motion");
创建模型引用
模型引用可以帮助您按层次结构组织大型模型,并可实现对其架构和行为的一次定义,多次重用。当一个组件引用另一个模型时,该组件上的任何现有端口都会被删除,而引用模型上的端口会出现在该组件上。
创建一个新的 System Composer 模型。将 Controller
组件转换为引用组件,以引用新模型。要在 Controller
组件上添加端口,必须更新引用模型 mobileMotion
。
referenceModel = systemcomposer.createModel("mobileMotion"); referenceArch = referenceModel.Architecture; newComponents = addComponent(referenceArch,"Gyroscope"); referenceModel.save linkToModel(motionController,"mobileMotion");
保存模型。
referenceModel.save model.save
创建变体组件
您可以使用 makeVariant
函数将 Motion
组件转换为变体组件。原始组件会作为可选的变体选择项之一嵌入到变体组件中。您可以在变体组件中设计其他变体选择项,并切换活动选择项。变体组件允许您在架构模型中以编程方式选择不同的行为设计,从而进行权衡研究和分析。
[variantComp,choice1] = makeVariant(componentMotion);
添加一个名为 MotionAlt
的变体选择项。第二个参量定义名称,第三个参量定义标签。标签用于标识选择项。活动选择项由标签控制。
choice2 = addChoice(variantComp,{'MotionAlt'},{'MotionAlt'});
在 MotionAlt
上创建所需的端口。
motionAltPorts = addPort(choice2.Architecture,{'MotionCommand','MotionData'},{'in','out'});
将 MotionAlt
设置为活动变体。
setActiveChoice(variantComp,"MotionAlt")
按 Ctrl+Shift+A 或使用以下命令整理布局。
Simulink.BlockDiagram.arrangeSystem("mobileRobotAPI/Motion");
保存模型。
model.save
清理
在再次运行此示例之前,请运行此脚本以删除生成的工件。
cleanUpArtifacts
详细信息
术语 | 定义 | 应用 | 更多信息 |
---|---|---|---|
构造型 | 构造型提供了一种扩展核心语言元素和添加域特定元数据的机制。 | 将构造型应用于核心元素类型。一个元素可以有多个构造型。您可以利用构造型为不同的元素设置样式。构造型为元素提供了一组通用的属性,例如质量、成本和功率。 | |
属性 | 属性是构造型中的一个字段。您可以为应用了该构造型的每个元素指定属性值。 | 使用属性来存储与模型元素相关联的定量特征,例如重量或速度。属性也可以是描述性的,或者表示一种状态。您可以使用属性检查器查看和编辑架构模型中每个元素的属性。有关详细信息,请参阅在 System Composer 中使用属性检查器。 | |
配置文件 | 配置文件是一系列构造型的集合。 | 您可以使用配置文件来创建专门的元素类型域。使用配置文件编辑器编写配置文件并将配置文件应用于模型。您可以将用于工程的构造型存储在一个或多个配置文件中。当您保存配置文件时,它们会存储在 XML 文件中。 |
版本历史记录
在 R2019a 中推出
另请参阅
工具
模块
对象
函数
systemcomposer.profile.Profile.createProfile
|systemcomposer.loadProfile
|applyProfile
|removeProfile
|renameProfile
|systemcomposer.profile.editor
|systemcomposer.profile.Profile.find
|systemcomposer.profile.Profile.load
|save
|open
|close
|systemcomposer.profile.Profile.closeAll
|systemcomposer.profile.Stereotype.find
|getDefaultStereotype
|setDefaultStereotype
|getDefaultElementStereotype
|setDefaultElementStereotype
|addStereotype
|removeStereotype
|getStereotype
|applyStereotype
|batchApplyStereotype
|getStereotypes
|changeStereotype
|removeStereotype
|hasStereotype
|addProperty
|removeProperty
|hasProperty
|setProperty
|getProperty
|getPropertyValue
|getEvaluatedPropertyValue
|getStereotypeProperties
|applyStereotypeOrder
|getStereotypeNamesByOrder
|increaseStereotypeOrder
|decreaseStereotypeOrder
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)