我正在为系统动力学建模创建一个库,它与Cellier现有的免费库不同,它使用非因果连接器。对于“流” - 元素我有一个GenericFlow
定义接口的类:
partial model GenericFlow "Flow Template with replaceable ports"
replaceable FlowPort portA "Flow from/to Stock A";
replaceable FlowPort portB "Flow to/from Stock B";
end GenericFlow;
洋红色FlowPort
连接器被声明为replaceable
- System Modeler 中的图标如下所示:
对于一些特殊情况,我将使用不同的端口,一个称为连接器SpecialFlowPort
的连接器被可视化为红色方块。举个例子,下面是一个名为的类Outflow
,它将重新声明用于其端口之一的连接器类(即 portA):
model Outflow "Outflow from a stock"
extends Interfaces.GenericFlow(redeclare Interfaces.SpecialFlowPort portA);
[...]
end Outflow;
它的图标将自动显示已交换为 portA 的红色 SpecialFlowPort(在左侧):
但是,当我在新模型中使用此组件(拖放)时,它将显示两个洋红色端口,并且在悬停在端口上时 System Modeler 会将类名命名为FlowPort
- 而不是SpecialFlowPort
:
但是组件的行为是正确的,并且禁止将洋红色FlowPort
端口与所示的左侧端口连接。Outflow
难道我做错了什么?为什么在模型中使用重新声明的连接器的类的图形注释正确显示?
更新:
来自 Wolfram MathCore 的 Otto Tronarp 正确地指出,上面的示例并不完整,因为我没有包含图形注释(这通常会使代码不可读,但在这种情况下相当重要)。
因此,为了提供SSCCE,我将在此处包含他的示例:
package ConnectorsTest
partial model GenericFlow "Flow Template with replaceable ports"
replaceable FlowPort portA "Flow from/to Stock A" annotation(Placement(visible = true, transformation(origin = {-66.537, 24.02}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
replaceable FlowPort portB "Flow to/from Stock B" annotation(Placement(visible = true, transformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, -0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
end GenericFlow;
model Outflow "Outflow from a stock"
extends GenericFlow(redeclare SpecialFlowPort portA);
end Outflow;
connector FlowPort
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Rectangle(visible = true, origin = {0, 5}, fillColor = {107, 255, 252}, fillPattern = FillPattern.Solid, extent = {{-50, -55}, {50, 55}})}));
end FlowPort;
connector SpecialFlowPort
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Rectangle(visible = true, origin = {0, 5}, fillColor = {246, 114, 123}, fillPattern = FillPattern.Solid, extent = {{-50, -55}, {50, 55}})}));
end SpecialFlowPort;
end ConnectorsTest;
Outflow
在 WSM 4.3 的模型图中使用此包中定义的类将显示错误的图形注释(例如,两个绿色而不是一个红色和一个绿色连接器)。