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

redefining color of graphic in subclass

redefining color of graphic in subclass

Hi folks.  I would like to create a class/block that has an annotation that defines icon/drawing graphics and then have subclasses/subblocks slightly modify the graphics. So for example:

block BaseGraphic
  constant Color color = {255,0,0};
  annotation
  (
       Icon
      (
        coordinateSystem
        (
          extent={{-100,-100},{100,100}},
          initialScale=0.2
        ),
        graphics=
        {
          Polygon
          (
            lineColor=color,
            fillColor=color,
            points={{-100,100},{100,0},{-100,-100}}
          )
        }
      )
  )
end BaseGraphic;

block YellowGraphic
  extends BaseGraphic(color={255,255,0});
end YellowGraphic;


When I instantiate a YellowGraphic object, the color does not change to yellow. It seems that the inherited annotation in YellowGraphic is not evaluated in the context of YellowGraphic and the color remains red. I've tried redeclaring the constant color in YellowGraphic as well with the same results.

How do I go about doing so? I really don't want to repeat what is a much more complicated graphic definition than shown in the example above in the 6 derived classes/blocks I want to define.

Thanks in advance.

Re: redefining color of graphic in subclass

This should work, is a bug. It should be fixed when we start using the new front-end.

Re: redefining color of graphic in subclass

  Thanks for the reply Adrian. Is this something that I should be entering as a bug report?  Could you please point me to information about the new front end (what it is, when it is supposed to be available)?

Re: redefining color of graphic in subclass

You can report bugs here:
https://trac.openmodelica.org/OpenModelica/
click on New Ticket

The new front-end is work in progress to replace the current one. The front-end handles instantiation of models (removal of structure, applications of modifiers, inheritance, etc until you get to a flat DAE system). We also use the front-end to do query operations on the Modelica code such as getting information about annotations, etc. You can find some information here:
https://trac.openmodelica.org/OpenModelica/ticket/4138

In the case of your annotation, because you use constants declared in the model, an instantiation of the model is needed to evaluate the annotation. It seems that the current front-end somehow misses the modification in the extends and then you end up with the one declared in the model.

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