为什么连接器的图形注释在重新声明后不会继承?

时间:2018-09-30 16:23:53

标签: modelica systemmodeler

我正在为System Dynamics建模创建一个库,该库不同于现有的free library by 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中的图标如下所示:

Icon of the partial model GenericFlow with FlowPort connectors

在某些特殊情况下,我将使用不同的端口,即称为SpecialFlowPort连接器,该端口显示为红色正方形。举个例子,下面是一个名为Outflow的类,它将重新声明用于其端口之一(即portA)的连接器类:

model Outflow "Outflow from a stock"
    extends Interfaces.GenericFlow(redeclare Interfaces.SpecialFlowPort portA);
    [...]
end Outflow;

其图标将自动显示已被交换为portA的红色SpecialFlowPort(在左侧):

Icon for model Outflow showing the redeclared connector

但是,当我在新模型中使用此组件(拖放)时,它将显示有两个洋红色端口,并且将鼠标悬停在这些端口上时,System Modeler会将类名命名为FlowPort-而不是{ {1}}:

Where have all the colors gone?

尽管组件的行为正确完成,并且禁止将品红色SpecialFlowPort端口与为FlowPort显示的左侧端口连接。

我做错什么了吗?为什么在带有模型的模型中正确显示了带有重新声明的连接器的类的图形注释?

更新

Wolfram MathCore的Otto Tronarp正确地noted,因为我未能包括图形注释(通常使代码不可读,但在这种情况下是必不可少的),因此上述示例并不完整。

因此,请举一个SSCCE,我将在此处提供他的示例:

Outflow

在WSM 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; 将显示错误的图形注释(例如,两个绿色而不是一个红色和一个绿色连接器)。

1 个答案:

答案 0 :(得分:2)

Wolfram社区posted的Wolfram MatheCore的人们说,这是与Wolfram System Modeler(版本5.1之前)有关的问题:

  

非常感谢您的报告。确实确实似乎Model Center无法在组件内部正确呈现重新声明的连接器。这是我们将要研究的东西。

     

作为解决方法,您可以创建组件的多个版本   类具有不同的连接器集,并创建   组件类可替换。不确定这是否可以接受   解决方法,但是应该可以。