Programatically generate concept within a node
Hi,
I am new to MPS. (Please forgive if the terminologies used are wrong)
I need to programmatically generate concepts. How can we acheive this ?
Creating the models within the solutions was achieved using the below code
SModel modelTemp=modelRoot.createModel("TestDemo");
node<MyConcept>node=new node<MyConcept>();
node.name="DemoNodeName";
modelTemp.addRootNode(node);
where modelRoot = model root obtained from a SModel
MyConcept = root concept defined in the languague
But the language contains many other concepts which shall be created within the node.
So how can we create multiple concepts within the node programmatically?
Please sign in to leave a comment.
To be more precise, lets consider the sample example of MPS "ie., Shapes" In this example, let us assume that the information of the shapes are available as a txt / xml format. And this file is parsed and to be loaded to MPS programmatically by (Refer attachment)
- Creating a solution (Step1)
- Create a model within a solution (Step2)
- Inside the created model, the information about the shapes has to be made available. (Step3)
So how do we do the above 3 steps programatically ?
I would create a UI plugin solution with and action in it. This action will do the import using the smodel language and the classes in j.m.ide - check out NewModuleUtil, NewLanguageDialog and NewSolutionDialog.
action FooBarAction {
execute outside command: false
also available in: everywhere
caption: Import Shapes
mnemonic: <no mnemonic>
description: Imports foo
icon: <no icon>
construction parameters
<< ... >>
action context parameters ( always visible = true )
MPSProject mpsProject key: MPS_PROJECT required
Frame frame key: FRAME required
<update block>
execute(event)->void {
//examples of the smodel API
sequence<? extends SModule> modules = this.mpsProject.getModules();
list<string> languages = modules.ofType<Language>.select({~it => it.getModuleName(); }).toList;
mySolution = NewModuleUtil.createSolution(solutionName, solutionBaseDirFile.getPath(), mpsProject)
this.mpsProject.addModule(mySolution)
;
Thanks for the reply.
i assume the above mentioned steps solves only the Step1. (For Reference, i am using MPS3.3 version. What API has to be used - modules.ofType<Language> is missing in v.3.3)
But how do we handle Stpe2 (model Creation under solution) and Step3 (contents marked in Red Box in the image)
1. try modules.where {it.isInstanceOf(Language)}.select {it : Language}
2. You need to attach models to model roots inside modules, so something along these lines (although with proper null checks) should work:
Iterable<ModelRoot> modelRoots = mySolution.getModelRoots();
modelRoots.iterator().next().createModel("myModel");