#4110 closed defect (fixed)
OMEdit introduces wrong newline if annotation starts on new line
Reported by: | Rüdiger Franke | Owned by: | Martin Sjölund |
---|---|---|---|
Priority: | high | Milestone: | 1.9.x |
Component: | Interactive Environment | Version: | |
Keywords: | Cc: |
Description (last modified by )
Many models place the annotation of a component declaration on a new line. OMEdit will introduce an additional newline between the component name and the modifiers.
See the following example. Open the parameter dialog for IconWithValues.Test.component1
, change the value of x
and press OK
.
package IconWithValues model Test Component component1(x = 5) annotation(Placement(visible = true, transformation(origin = {0, 0}, extent = {{-45, -45}, {45, 45}}))); end Test; model Component parameter Real x; Real y = sin(x); Boolean neg = y < 0; Boolean pos = not neg; annotation(Icon(graphics = { Rectangle(origin = {0, 0}, extent = {{-95, 95}, {95, -95}}, visible = DynamicSelect(false, neg)), Text(origin = {-55, 35}, extent = {{-35, 15}, {50, -30}}, textString = "x = "), Text(origin = {-55, 35}, extent = {{50, 15}, {150, -30}}, textString = DynamicSelect("x", String(x))), Text(origin = {-55, -30}, extent = {{-35, 15}, {150, -30}}, textString = DynamicSelect("%y", String(y, significantDigits = 3)), visible = DynamicSelect(true, pos)), Text(origin = {-55, -30}, extent = {{-35, 15}, {150, -30}}, textString = DynamicSelect("%y", String(y, significantDigits = 3)), visible = DynamicSelect(false, neg), lineColor = {255, 0, 0})}, coordinateSystem(initialScale = 0.1))); end Component; end IconWithValues;
This will result in the following model text with wrong newline before the modifier:
model Test Component component1 (x = 6) annotation(Placement(visible = true, ...); end Test;
Change History (13)
comment:1 by , 8 years ago
Component: | OMEdit → Interactive Environment |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 8 years ago
Description: | modified (diff) |
---|---|
Summary: | OMEdit introduces additional newline if annotation starts on new line → OMEdit introduces wrong newline if annotation starts on new line |
comment:3 by , 8 years ago
comment:4 by , 8 years ago
This is not related to #4065. It seems the newline simply shifts its position.
comment:5 by , 8 years ago
A smaller example:
echo(false); a := "model Test Component component1(x = 5) annotation(); end Test;"; b := "model Test Component component1(x = 6) annotation(); end Test;"; echo(true); diffModelicaFileListings( a, b, OpenModelica.Scripting.DiffFormat.color); getErrorString();
The error only shows if there is a newline before the annotation.
comment:6 by , 8 years ago
Having a look at MSL (Modelica.Blocks.Examples), most models have annotations starting on new lines. See e.g.:
- Filter*
- InverseModel
- ShowLogicalSources
- Real/Integer/BooleanNetwork1
LogicalNetwork1 and BusUsage have only annotations starting on the same line.
comment:7 by , 8 years ago
I have a fix for this, but it breaks the existing tests. I will see if the new output is better or if the fix is a good one.
comment:8 by , 8 years ago
Milestone: | 1.11.0 → 1.9.x |
---|---|
Status: | assigned → accepted |
comment:9 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
Fixed in 9c32ee8/OMCompiler (and getting fixed in maintenance/v1.9 as well), simply by moving whitespace around to get a better diff.
comment:10 by , 8 years ago
One more thing with this example:
- open IconWithValues.Test in OMEdit
- click on the component and move it (e.g. by clicking an arrow buttwon)
[2] 14:12:21 Syntax Error No viable alternative near token: ( [3] 14:12:21 Translation Error [OpenModelica/OMCompiler/Compiler/Script/CevalScriptBackend.mo: 1049:13-1049:124]: Internal error Failed to parse merged string (see generated file SanityCheckFail.mo)
SanityCheckFail.mo contains component1 without the class Component:
package IconWithValues model Test component1(x = 5) annotation(Placement(visible = true, transformation(origin = {10, 2}, extent = {{-45, -45}, {45, 45}}, rotation = 0))); end Test; model Component parameter Real x; Real y = sin(x); Boolean neg = y < 0; Boolean pos = not neg; annotation(Icon(graphics = { Rectangle(origin = {0, 0}, extent = {{-95, 95}, {95, -95}}, visible = DynamicSelect(false, neg)), Text(origin = {-55, 35}, extent = {{-35, 15}, {50, -30}}, textString = "x = "), Text(origin = {-55, 35}, extent = {{50, 15}, {150, -30}}, textString = DynamicSelect("x", String(x))), Text(origin = {-55, -30}, extent = {{-35, 15}, {150, -30}}, textString = DynamicSelect("%y", String(y, significantDigits = 3)), visible = DynamicSelect(true, pos)), Text(origin = {-55, -30}, extent = {{-35, 15}, {150, -30}}, textString = DynamicSelect("%y", String(y, significantDigits = 3)), visible = DynamicSelect(false, neg), lineColor = {255, 0, 0})}, coordinateSystem(initialScale = 0.1))); end Component; end IconWithValues;
comment:11 by , 8 years ago
Odd that OMEdit changes the type of the component when moving it. And makes the name longer...
comment:12 by , 8 years ago
Smaller model with this error:
echo(false); a := "model Test\n Comp component1(x = 5)\n annotation(origin = {0, 0});\nend Test;"; b := "model Test\n Icon.Comp component1(x = 5) annotation(origin = {2, 0});\nend Test;"; echo(true); diffModelicaFileListings(a, b, OpenModelica.Scripting.DiffFormat.plain);getErrorString();
Please see also #4065 (Linebreaks, comments in component argument list are mangled after moving it), which could be connected.