Import ecore package / referenced resources in Xtext/MWE2 - eclipse

I'm not quite sure how to reference a model I want to use in my Xtext grammar by import in the GeneratyMydsl.mwe2 file in the workflow section.
I the example they reference the model by adding referencedResource =
"platform:/resource/org.example.domainmodel/model/Domainmodel.genmodel"
What does platform mean and how exactly do I reference my own model? The file location of my grammar has no real correlation to the file location of the model.

platform:/resource/project/folder/file is a uri within eclipse. So platform:/resource/org.example.domainmodel/model/Domainmodel.genmodel points to the org.example.domainmodel project, model folder, Domainmodel.genmodel file.
EMF and MWE have facilities to "mimic" that behavour in standalone mode by looking at the folder structure and classpath.

Related

Create a package in Modelica

I am using Modelica in my work, where I have modeled a system that contains many models. I want to make it simple to use by creating a package using " within" so this package contains all the models. What I want is to open the package instead of opening many models, which takes time.
Instead of doing everything by hand, I suggest to create your packages with a Modelica tool (OpenModelica, Dymola, SimulationX, ...).
The tool will automatically create the folder structure and the within lines in the .mo files for you. Doing it manually is not much fun.
You could e.g. use OMEdit (part of OpenModelica) to create your package structure as follow:
create your top-level package via File > New Modelica Class
insert sub-models and sub-packages in existing packages via right-click > New Modelica Class
According to this website http://omwebbook.openmodelica.org/
A package is simply a container or namespace for names of classes, functions, constants, and other allowed definitions. The package name is prefixed to all definitions in the package using standard dot notation. An import language construct is provided for Modelica packages.
the package can help us to gather components that build the main model together in same place inside it , just by clicking on the package you open all your components inside it.
to open a package in Modelica we follow the follwing instructions:
After creationg the package you will get a folder with the package name in the place that you chosed to saved it in it , when you open the folder you click on package in order to open your package .
hope this can be helpfull

Adding additional libraries to MODELICAPATH in JModelica

In JModelica I want to create models using components from multiple existing libraries.
This means that it would be very useful to add the multiple libraries to the MODELICAPATH so components can be referenced without changing their existing paths. Something similar seems possible in Dymola.
In JModelica 1.13 it seems that this was once possible using:
c_opts =
{'extra_lib_dirs':['c:\MyLibs1','c:\MyLibs2']}
compile_fmu(class_path, compiler_options=c_opts)
I have read through the JModelica 2.1 document and there seems to be no mention of this argument. I have also tried running the script above and the compiler is not able to locate the path of the model contained within a library listed in the options.
Adding libraries to the Third Party MSL Folder inside the JModelica installation is not an option, as the multiple libraries I'll be working with are GitHub repos.
Is it possible to add these multiple libraries to the MODELICAPATH via startup script or IPython code?
The option "extra_lib_dirs" has been removed in favour of the simpler interface:
from pymodelica import compile_fmu
name = compile_fmu("MyModel", ["MyModelicaFile.mo", "C:\My\Modelica\Lib", ...])
The list after the model is specificed can take any number of Modelica files or directories to where Modelica libraries are located.
Yes, JModelica.org looks at the environment variable MODELICAPATH for additional locations of Modelica libraries (as per the Modelica language specification, section 13.2.4).
Either you modify the variable in batch before starting JModelica.org, or you modify the environment inside Python:
import os
os.environ['MODELICAPATH'] = "C:/somePath/;" + os.environ['JMODELICA_HOME'] + "/ThirdParty/MSL"
from pymodelica import compile_fmu
compile_fmu("SomeLibrary.SomeModel")
Note, if you're going to compile models from MSL or models using parts of MSL, then you have to add the MSL folder from the JModelica.org installation to the MODELICAPATH as well. The reason for this is that we are overriding the default MODELICAPATH and JModelica.org uses MODELICAPATH to find MSL.
I might add that it is more efficient to add the library folders to MODELICAPATH than listing them in the compile_fmu command. The reason for this is that if you list them to the compile_fmu command, then all the libraries will be parsed, while, if you add them (or rather the parent folder) to MODELICAPATH, then they are loaded as needed.

Creating Modelica Libraries

I have created a small Modelica library of my own. The way I have created it is in a single file. But I would like to make it a proper Modelica Library, as in the one with multiple directories for each subpackages.
So this is what i followed. File > New Modelica Class > Specialization - Package > Unchecked Save contents in one file. I copied the entire package code from the single file library, pasted it here and saved it. while doing so, I've noticed that the library lost most of its extends clauses, few models went missing.
Have I followed the correct procedure to create the library or did I do something wrong?
Can anyone point me towards the right direction?
#MSK, I cannot help you with OpenModelica as I work with Dymola. I did however recently split a single-file library (called package in Modelica) into several files manually. I did this so that the library hierarchy is represented in the file system hierarchy (i.e. several subfolders and .mo files in a library folder). For 35,000 lines of code this took roughly 10 hours. Just follow these steps:
create folder with same name as library
in this folder, create a text file "package.mo"
"package.mo" has to start with the statement
within ;
package [name of your package, i.e. the folder name...without the brackets];
now you want to create a subclass within this package. To do this create another folder containing a text file called "package.mo"
start this "package.mo" with
within [name of your package];
and declare the model as usual.
continue all the way down your library hierarchy
at the lowest hierarchy level you no longer need to create folders. You can simply create a .mo with the name of the lowest level class. As usual, start this file with
within [name of your package].[subclass1].[subclass2];
For an example of implementation please refer to the Physiolibrary found at https://www.modelica.org/libraries or the Modelica Standard Library which also uses this structure.

Reference Ecore model path of a different Ecore model

Here is my problem>
We currently have several Ecore models for our applications. One of the Ecore models (mainModel.ecore) has stuff that is common in all the rest of the models. So, what i want to do is have all the other models reference the contents of that one model so we do not have to constantly copy the contents of that one model into all the models every time there is a change.
Is this possible and how can I do this?
(I am very new to Ecore and still do not understand a lot of the terminology.)
EDIT:
How do i get the EcoreUtil.getRootContainer to return the the container of the loaded resource? I need to have that location so that i can resolve certain paths from that root. This may resolve my issue.
Here is what i attempted so far:
I tried "load resource..." by loading the mainModel.ecore into all the other models and deleting the local references. There were a lot of places that i had to fix after doing this and i did. After re-generating the source and trying to compile there are places where it tried accessing the "dotpath" that was local to the original file and i do not know how to change that "dotpath" to reference the "loaded resource". So it is not able to resolve those paths.
Thanks!
You'll generally get answers about EMF more readily by using the EMF newsgroup (eclipse.tools.emf) which is web accessible via
http://www.eclipse.org/forums/index.php/f/108/
Your problem isn't so clear. I don't understand how the compiled code accesses anything via a "dot path". I know if you load a resource and refer to it's contents you'll generally end up with relative paths, but those are normally resolved during loading to an absolute URI. Of course the referencing resource itself needs to be loaded with an absolute URI, but the generator does that properly...

XML schema for Eclipse target definition files

Where can I find the XML schema and/or documentation for Eclipse target definition files (*.target)?
May be this schema might fit the target files created for an RCP platform.
Part of that schema file is visible in the Eclipse help page.
There is no schema or documentation defining the structure of a target definition file (.target). This is because the file structure is not intended to be API (it may change between release).
The structure has changed several times already. The code used to serialize/deserialize the file can be found in the following classes:
org.eclipse.pde.internal.core.target.TargetDefinitionPersistenceHelper
org.eclipse.pde.internal.core.target.TargetPersistence38Helper
org.eclipse.pde.internal.core.target.TargetPersistence36Helper
org.eclipse.pde.internal.core.target.TargetPersistence35Helper
org.eclipse.pde.internal.core.target.TargetPersistence34Helper