Opened 9 years ago

Last modified 9 years ago

#3591 new defect

OMEdit fails when opening "total save" model

Reported by: Bernhard Thiele Owned by: Adeel Asghar
Priority: low Milestone: Future
Component: OMEdit Version:
Keywords: Cc:

Description

The attached model is created by using File->Save Total on the model Modelica.Blocks.Examples.PID_Controller.

It works to simulate the model using scripting:

loadFile("PID_ControllerTotal.mo");
simulate(PID_Controller_total);

However, it is not possible to open the model in OMEdit. Trying to open it results in an error message, similar to

Only single nonstructured entity is allowed to be stored in the file PID_ControllerTotal.mo

Attachments (1)

PID_ControllerTotal.mo (33.9 KB ) - added by Bernhard Thiele 9 years ago.

Download all attachments as: .zip

Change History (10)

by Bernhard Thiele, 9 years ago

Attachment: PID_ControllerTotal.mo added

comment:1 by Adrian Pop, 9 years ago

I think this is a new restriction on OMEdit so that is easier to implement indentation preserving things. The problem is that we cannot change the export so that we encapsulate anything in a package. Adeel, maybe we could support such files with multiple classes at the top level by making them read-only.

comment:2 by Adeel Asghar, 9 years ago

This is not new. It was in OMEdit from a long time and it is because of Modelica specification section 13.2.2.2 Mapping a Package/Class Hierarchy into a Single File (Nonstructured Entity) which says,

"A nonstructured entity [e.g. the file A.mo] shall contain only a stored-definition that defines a class [A] with a name matching the name of the nonstructured entity. In a file hierarchy the files shall have the extension “.mo”."

Generate better code from save total API.

in reply to:  1 comment:3 by Adeel Asghar, 9 years ago

Replying to adrpo:

I think this is a new restriction on OMEdit so that is easier to implement indentation preserving things. The problem is that we cannot change the export so that we encapsulate anything in a package.

Why this is a problem?

comment:4 by Adrian Pop, 9 years ago

Because when you generate code from a total model you in general have at the top level:

Modelica
ModelicaServices
Etc

I think that any Modelica tool (including Dymola) does it in the same way.
Also, the grammar allows it even thou' maybe other parts of the specification doesn't.
I think we should remove this restriction if possible (maybe make it a warning only).

in reply to:  4 comment:5 by Adeel Asghar, 9 years ago

Replying to adrpo:

Because when you generate code from a total model you in general have at the top level:

Modelica
ModelicaServices
Etc

I think that any Modelica tool (including Dymola) does it in the same way.

Well Dymola does the same and also allows loading back the file but then make some change in the model and save it again, all the top level packages are removed from the file.

Also, the grammar allows it even thou' maybe other parts of the specification doesn't.
I think we should remove this restriction if possible (maybe make it a warning only).

No, how do you save two or more top level classes in one file?

comment:6 by Adrian Pop, 9 years ago

The grammar says:

stored_definition:
[ within [ name ] ";" ]              // within is optional
{ [ final ] class_definition ";" }   // means 0 or more class definitions

So saving any number of top level classes in one file is fine:

within ;
package A end A;
package B end B;
package C end C;

I'll open a ticket on the Modelica website about this as it needs to be cleared.

comment:7 by Adrian Pop, 9 years ago

Opened #m:1854 about this.

Note that what you quoted from the spec:

"A nonstructured entity [e.g. the file A.mo] shall contain only a stored-definition 
that defines a class [A] with a name matching the name of the nonstructured entity.
In a file hierarchy the files shall have the extension “.mo”."

can be read a bit differently and could be interpreted as saying it shall only exits ONE class with name A in the A.mo file.

comment:8 by Adeel Asghar, 9 years ago

That is exactly how i want it to be interpreted. I don't care if the class name is A or not but there should be only one class per file.

in reply to:  8 comment:9 by Adrian Pop, 9 years ago

Replying to adeas31:

That is exactly how i want it to be interpreted. I don't care if the class name is A or not but there should be only one class per file.

No. What I meant is that it can be interpreted as you can have multiple classes but just one with name A :)

Note: See TracTickets for help on using tickets.