colors - Modelica 网页颜色
问题描述
我认为将一些颜色定义为稍后在 Modelica 颜色注释中使用的常量可能会很方便。看起来 web 颜色是一个公认的标准,我将它们全部复制到一个常量数组包中:
- https://en.wikipedia.org/wiki/Web_colors
- https://gist.github.com/thorade/a1298571938231ef90d3bedf6b514967
但似乎我无法按预期使用它们,以下示例失败。似乎文字工作,或者如果我在同一个类中定义常量,但如果我导入它则不行。我做错了什么,还是我正在使用的工具的限制?
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;
解决方案
原因很简单:图形注释取决于变量,仅当变量存在于结果文件中时才有效。因此,由于您的颜色注释正在使用导入调用数据,因此黄色代码不包含在结果文件中,因此您的测试框无法着色。相同的逻辑可以应用于受保护的变量:它将无法应用于任何图形注释。
推荐阅读
- laravel - 如何将集合或数组发送到通知门面
- javascript - “this”如何引用父类?
- python - (Host Django Pythonanywhere) Manage.py collectstatic 返回 FileNotFoundError: [Errno 2]
- java - 将 ServerValue.TIMESTAMP 保存为实时数据库中的字符串
- android - 在第一次运行时初始化数据库
- java - 我们是否需要 Observable.just(..) 或 Observable.fromCallable{...},因为我们已经有了 Single.just(..) 或 Single.fromCallable{...}?
- c++ - 看不懂learnopengl.com漫射辐照度教程中的captureViews
- node.js - 如何在 express 中包含 api 路由器的 css 文件?
- eclipse - 在 pom .xml 中显示错误:Failure to transfer org.apache.maven.shared:file-management:pom:3.0.0
- file - 使用 fancybox 和 google doc viewer 查看 j2ee web 应用程序中的文件