Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Icon Update on Diagram View based on Component Parameter

Icon Update on Diagram View based on Component Parameter

Hallo,

I'm trying to add a function that chenge the icon of one component based on the parameter selected in the diagram view with out needed to simulate the whole model (e.g. to make it easier for modeler to differentiate which function one model used).

my first idea is just to add a small rectangle in the middle of the larger rectangle and controll the visibility of the small rectangle using an if condirion set by parameter but it doesn't work.

Code:


model foo

  parameter Boolean isRed = false;

  annotation(
  Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-80, -80}, {80, 80}}, initialScale = 0.1),
  graphics = {Rectangle( origin = {0, -12}, fillColor = {0, 152, 154}, pattern = LinePattern.Dash, fillPattern = FillPattern.Solid, lineThickness = 1.5, extent = {{-60, 58}, {60, -28}}),
                     Rectangle(visible = isRed, origin = {-2, -10}, fillColor = {255, 0, 0}, pattern = LinePattern.Dash, fillPattern = FillPattern.Solid, lineThickness = 1.5, extent = {{-28, 32}, {36, -10}})
);

end foo;

Using the DynamicSelect on the small rectangle also didn't work

Code:


Rectangle(origin = {-2, -10}, fillColor = DynamicSelect({255, 0, 0},if isRed then {255,0,0} else {255,255,255}), pattern = LinePattern.Dash, fillPattern = FillPattern.Solid, lineThickness = 1.5, extent = {{-28, 32}, {36, -10}})

I think i've missed something. I've seen some example of water tank that change level or colour based on the parameter but it was happened during a simulation/ after the simulation was run and not automatically change into plotting view.

Is it possible to achieve what i intended in current OMEdit?

thanks in advance

Re: Icon Update on Diagram View based on Component Parameter

I guess DynamicSelect is not what you want here since the Modelica specification says,

"DynamicSelect has the syntax of a function call with two arguments, where the first argument specifies the value of the editing state and the second argument the value of the non-editing state."

So in modeling view it will always use the first argument.

You could use a boolean parameter like this,

Code:


Rectangle(origin = {-2, -10}, fillColor = if isRed then {255,0,0} else {255,255,255}, pattern = LinePattern.Dash, fillPattern = FillPattern.Solid, lineThickness = 1.5, extent = {{-28, 32}, {36, -10}})

But note that it will always use the default value of the parameter. We don't support the parameter changes yet. See https://trac.openmodelica.org/OpenModelica/ticket/2081

Adeel.

Re: Icon Update on Diagram View based on Component Parameter

Using conditional in the fill Color is a better idea. I hope it is not hard to implement this function in future version. thanks, Adeel.

There are 0 guests and 0 other users also viewing this topic
You are here: