Modelica 为什么连接器的图形注释在重新声明时没有继承?
我正在创建一个建模库,与现有库不同的是,它使用了acausal连接器。对于“流”-元素,我有一个定义接口的Modelica 为什么连接器的图形注释在重新声明时没有继承?,modelica,systemmodeler,Modelica,Systemmodeler,我正在创建一个建模库,与现有库不同的是,它使用了acausal连接器。对于“流”-元素,我有一个定义接口的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 Gene
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
连接器声明为可更换的连接器-System Modeler中的图标如下所示:
对于一些特殊情况,我将使用不同的端口,一个名为SpecialFlowPort
的连接器,它被可视化为一个红色方块。举个例子,下面是一个名为
Outflow的类,它将重新声明用于其一个端口(即portA)的连接器类:
其图标将自动显示已交换为portA的红色SpecialFlowPort(左侧):
但是,当我在新模型中使用此组件(拖放)时,它将显示为两个洋红色端口,悬停在端口上时,系统建模器将给出类名为FlowPort
-而不是SpecialFlowPort
:
但是,组件的行为是正确的,并且禁止洋红出油口
端口与为出油口
显示的左侧端口连接
我做错什么了吗?为什么带有重新声明的连接器的类的图形注释在模型中使用时未正确显示?
更新:
Wolfram MathCore的Otto Tronarp正确地指出,上面的示例并不完整,因为我没有包含图形注释(这通常会使代码不可读,但在这种情况下非常重要)
因此,为了给出一个例子,我将在这里包括他的例子:
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;
在WSM 4.3的模型图中使用此包中定义的类
将显示错误的图形注释(例如,两个绿色而不是一个红色和一个绿色连接器)。Wolfram社区Wolfram MatheCore的人员表示,这是Wolfram System Modeler 5.1版之前的问题:
非常感谢你的这份报告。确实,Model Center似乎没有正确渲染组件内部重新声明的连接器。这是我们将要调查的事情
作为解决方案,您可以创建组件的多个版本
使用不同的连接器集初始化,并生成
组件类可替换。不确定这是否可以接受
为你工作,但它应该工作
这里给出的示例是在Windows 10(64位)上使用Wolfram System Modeler 4.3完成的。我还交叉发布了一个类似的问题,尽管到目前为止还没有答案。
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;