modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
101 stars 41 forks source link

Should extent be inherited if local coordinate system has no extent? #3219

Closed MarkusOlssonModelon closed 2 years ago

MarkusOlssonModelon commented 2 years ago

If a class defines a local coordinate system to modify one the attributes that are not extent, e.g., preserveAspectRatio, should the extent be inherited? My interpretation of the specification is that it should not be inherited (from point 1 below). Is this the desired behavior? I think it would be more natural if the attributes of the coordinate system were inherited separately.

From section 18.6.1.1 Coordinate Systems:

The coordinate system (including preserveAspectRatio) of a class is defined by the following priority:

  1. The coordinate system annotation given in the class (if specified).
  2. The coordinate systems of the first base class where the extent on the extends-clause specifies a null-region (if any). Note that null-region is the default for base classes, see section 18.6.3.
  3. The default coordinate system CoordinateSystem(extent = {{-100, -100}, {100, 100}}).

Example

model BaseClass
    annotation(Icon(coordinateSystem(extent={{0,0},{100,100}})));
end BaseClass;

model Example
    extends BaseClass;
    annotation(Icon(coordinateSystem(preserveAspectRatio=false)));
end Example;

What is the extent for the icon of Example?

henrikt-ma commented 2 years ago

I think it would be more natural if the attributes of the coordinate system were inherited separately.

I agree.

HansOlsson commented 2 years ago

If a class defines a local coordinate system to modify one the attributes that are not extent, e.g., preserveAspectRatio, should the extent be inherited? My interpretation of the specification is that it should not be inherited (from point 1 below). Is this the desired behavior? I think it would be more natural if the attributes of the coordinate system were inherited separately.

I agree for this example, and to me the problem is that if you just set preserveAspectRatio there is no extent defined in step 1 (no default for the extent), so it makes sense that we inherit the extent in step 2 as there isn't any value in step 1.

However, if you on the other hand have:

model BaseClass
    annotation(Icon(coordinateSystem(preserveAspectRatio=false)));
end BaseClass;

model Example
    extends BaseClass;
    annotation(Icon(coordinateSystem(extent={{0,0},{100,100}})));
end Example;

there does exist a default for preserveAspectRatio in CoordinateSystem, and thus preserveAspectRatio=true shall be used.

That is consistent with the goal when we introduced the slightly complicated rules:

Note models normally don't specify preserveAspectRatio, and of the ones that do most also give the extent. I believe there are about 20 cases of specifying coordinatesystem without extent in MSL; and I haven't found any cases where these rules matter.