我认为将某些颜色定义为常量可能比较方便,以便稍后在Modelica颜色注释中使用。由于web颜色似乎是一个公认的标准,我将所有这些颜色复制到一个由常量数组组成的包中:
但是我似乎不能按预期使用它们,下面的示例失败了。如果我在同一个类中定义常量,但如果导入它,它似乎是有效的。我是做错了什么,还是我所使用的工具的限制?
within ;
package Modelica_Colors
type RealColor = Modelica.Icons.TypeReal[3] (each min=0, each max=255);
package BasicColors
final constant RealColor Aqua={0,255,255};
final constant RealColor Black={0,0,0};
final constant RealColor Blue={0,0,255};
final constant RealColor Fuchsia={255,0,255};
final constant RealColor Gray={128,128,128};
final constant RealColor Grey={128,128,128};
final constant RealColor Green={0,128,0};
final constant RealColor Lime={0,255,0};
final constant RealColor Maroon={128,0,0};
final constant RealColor Navy={0,0,128};
final constant RealColor Olive={128,128,0};
final constant RealColor Purple={128,0,128};
final constant RealColor Red={255,0,0};
final constant RealColor Silver={192,192,192};
final constant RealColor Teal={0,128,128};
final constant RealColor White={255,255,255};
final constant RealColor Yellow={255,255,0};
end BasicColors;
package Colors
final constant RealColor Crimson={220,20,60};
final constant RealColor Cyan={0,255,255};
final constant RealColor DarkBlue={0,0,139};
final constant RealColor DarkCyan={0,139,139};
final constant RealColor OliveDrab={107,142,35};
final constant RealColor Orange={255,165,0};
final constant RealColor OrangeRed={255,69,0};
final constant RealColor Orchid={218,112,214};
final constant RealColor PaleGoldenRod={238,232,170};
final constant RealColor PaleGreen={152,251,152};
final constant RealColor Yellow={255,255,0};
final constant RealColor YellowGreen={154,205,50};
end Colors;
model Test
// works
constant RealColor test_const1={255,20,147}; // pinkish
// does not work
final constant RealColor test_equal=Modelica_Colors.Colors.OrangeRed;
constant RealColor test_pi={Modelica.Constants.pi,2*Modelica.Constants.pi,3*Modelica.Constants.pi};
import Modelica_Colors.BasicColors.Yellow;
protected
// works
constant RealColor test_const2={147,20,255};
annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={
Rectangle(
extent={{-100,100},{0,0}},
lineColor=test_const2,
fillColor=test_const1,
fillPattern=FillPattern.Solid),
Rectangle(
extent={{0,0},{100,-100}},
lineColor=Modelica_Colors.Colors.Cyan,
fillColor=Yellow,
fillPattern=FillPattern.Solid),
Rectangle(
extent={{0,100},{100,0}},
lineColor=test_equal,
fillColor=test_equal,
fillPattern=FillPattern.Solid),
Rectangle(
extent={{-100,0},{0,-100}},
lineColor=test_equal,
fillColor=test_pi,
fillPattern=FillPattern.Solid)}), Diagram(coordinateSystem(
preserveAspectRatio=false)));
end Test;
annotation (uses(Modelica(version="3.2.3")));
end Modelica_Colors;发布于 2020-10-05 10:01:25
原因很简单:图形注释取决于变量,只有在结果文件中存在变量时才能工作。因此,当您的颜色注释使用导入调用数据时,结果文件中不包含黄色代码,因此您的测试框无法着色。同样的逻辑可以应用于受保护的变量:它将不能应用于任何图形注释。
https://stackoverflow.com/questions/64204801
复制相似问题