#4110 closed defect (fixed)
OMEdit introduces wrong newline if annotation starts on new line
Reported by: | rfranke | Owned by: | sjoelund.se |
---|---|---|---|
Priority: | high | Milestone: | 1.9.x |
Component: | Interactive Environment | Version: | |
Keywords: | Cc: |
Description (last modified by rfranke)
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 Changed 7 years ago by adeas31
- Component changed from OMEdit to Interactive Environment
- Owner changed from adeas31 to sjoelund.se
- Status changed from new to assigned
comment:2 Changed 7 years ago by rfranke
- Description modified (diff)
- Summary changed from OMEdit introduces additional newline if annotation starts on new line to OMEdit introduces wrong newline if annotation starts on new line
comment:3 Changed 7 years ago by Christoph <buchner@…>
comment:4 Changed 7 years ago by sjoelund.se
This is not related to #4065. It seems the newline simply shifts its position.
comment:5 Changed 7 years ago by sjoelund.se
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 Changed 7 years ago by rfranke
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 Changed 7 years ago by sjoelund.se
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 Changed 7 years ago by sjoelund.se
- Milestone changed from 1.11.0 to 1.9.x
- Status changed from assigned to accepted
comment:9 Changed 7 years ago by sjoelund.se
- Resolution set to fixed
- Status changed from accepted to 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 Changed 7 years ago by rfranke
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 Changed 7 years ago by sjoelund.se
Odd that OMEdit changes the type of the component when moving it. And makes the name longer...
comment:12 Changed 7 years ago by sjoelund.se
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();
comment:13 Changed 7 years ago by sjoelund.se
That issue is now fixed in d1a6452/OMCompiler
Please see also #4065 (Linebreaks, comments in component argument list are mangled after moving it), which could be connected.