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

how to reference certain "built in" classes

how to reference certain "built in" classes


Hey folks. Here's something I'm puzzling over. Inside a graphical or icon annotation, one can reference type names like Color and FillColor, eg FillColor.None. However, I cannot seem to be able to reference these type names outside of the context of an annotation. For example:

block TestColorReference
  constant Color blue = {0,0,255};
end TestColorReference

Manually checking this model in OMEdit yields the following errors:

[1] 08:57:26 Translation Error
[TestColorReference: 2:3-2:34]: Class Color not found in scope TestColorReference.

[2] 08:57:26 Translation Error
Error occurred while flattening model TestColorReference


I presume I'm missing some sort of appropriate namespace in front of the word Color?

Re: how to reference certain "built in" classes

Hello DanField

Your presumption is good - what you can do, is use LibraryBrowser. I typed "color", and found that class in some library.
Working code is:

block TestColor
    constant Modelica.Mechanics.MultiBody.Types.Color blue = {0,0,255};
end TestColor;

Hope that solves your problem.

Edited by: DawidG - Dec-08-18 10:54:13

Re: how to reference certain "built in" classes

Thanks for the reply.

My example doesn't exhibit the full extent of the problem. The definition of Color in Modelica.Mechanics.MultiBody.Types.Color must be a re-declaration of the color type definition used in the graphical annotations: I say that because there are no other similar definitions for other types of graphical attributes (eg the FillPattern enumeration) in the Modelica library.

1)  Re-declarations of the basic Color type used in graphical annotations as such this (when it works) isn't the best solution: DRY and all that. What would happen if the graphical annotation color definitions decide to add an alpha channel?

2) I've tried similarly re-declaring the FillPattern enumeration type using the same names and ordering as the enumeration as described in various bits of documentation. This causes other semantic errors. Alternatively, declaring an enumeration with the type name MyFillPattern (and same FillPattern enumeration names and values) and then using those values within graphic annotations results with the behavior of FillPatern.None regardless of which MyFIllPattern value I use.  Either workaround (even if they did work) violates DRY.

So either I'm misunderstanding how to correctly reference the real Color and FillPattern types outside of graphical annotations or they just aren't available outside of the graphic annotation context. If it is the latter case, then I think this is a language deficiency since it means graphic annotation style values cannot be cleanly obtained from variable values  that are defined within a class as per the example because those type names cannot be referenced.

Re: how to reference certain "built in" classes

DanField wrote:


So either I'm misunderstanding how to correctly reference the real Color and FillPattern types outside of graphical annotations or they just aren't available outside of the graphic annotation context.

It's the latter I'm afraid, see section 4.8.8.5 in the Modelica specification:


Graphical Annotation Types
A number of “predefined” record types and enumeration types for graphical annotations are described in Chapter 18. These types are not predefined in the usual sense since they cannot be referenced in ordinary Modelica code, only within annotations.

Re: how to reference certain "built in" classes

Thanks for clarifying this as well as the quote from the spec document. It is indeed unfortunate and I think an oversight that these types cannot be referenced outside of graphical annotations in order that their values can be set from variables outside of those annotations. This was how I was going to parameterize and factor different subclasses of model components with slightly different style options. Doing so would also allow simplification of many of the object definitions within the Modelica library.

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