Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Transformation XText to Papyrus and vice versa
Transformation XText to Papyrus and vice versa [message #1835623] Wed, 09 December 2020 01:56 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi all,

I am trying to write transformation rules on ETL between a graphical UML model created with Papyrus using UML Profiles, and a textual model created through the grammar that I have defined on XText.

I first used a different approach. I created the UML Profile and XText grammar, and then I created an EMF model for these two. I created two different .etl files, for the following two transformations: graphical2textual and textual2graphical. These transformations were working fine and whenever I opened the coronagraphical.model or coronatextual. model (the two EMF models I created), I could see the changes after the transformation.

However, what I want to do is something different. After creating the UML Profile and writing the XText grammar, I dont want to create EMF models, but I want to create a UML model and an xtext model, and then run the transformations. So that is what I did. These are the steps I followed:

1. Write the DSML
2. Run a second Eclipse instance, and create the XText model.
3. Create a UML profile and a UML model.
4. Write the transformations.
5. Create the run configurations for both .etl files. Add the UML model as UML model and name it coronagraphical and add the XText model as EMF model and name it coronatextual.
6. Run the transformations.

Note: Steps 2-6 take place on the second instance on Eclipse.

Now the issue is that if I run the textual2graphical transformation, when I open the UML model I get the following window. It looks like the transformation is working but there are errors somehow.

If I run the graphical2textual transformation I get nothing. I wanted to check if I could see the changes from the transformation on ecore, so I opened the XText model using Sample Ecore Model Editor, but nothing happens there after I run the transformation.

Attached I am also providing the zip files of this project.

First instance - The files of the DSML I have written on the first instance
coronaepsilon - The files I have on the second instance that include the UML Profile, UML model, Xtext model and the transformation files.

Please let me know if you need further information.

Thank you

[Updated on: Wed, 09 December 2020 10:30] by Moderator

Report message to a moderator

Re: Transformation XText to Papyrus and vice versa [message #1835633 is a reply to message #1835623] Wed, 09 December 2020 07:05 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Could you please also include a copy of your stored launch configuration in the second zip as per https://www.eclipse.org/epsilon/doc/articles/minimal-examples/#epsilon-launch-configurations?

Thanks,
Dimitris

[Updated on: Wed, 09 December 2020 07:06]

Report message to a moderator

Re: Transformation XText to Papyrus and vice versa [message #1835635 is a reply to message #1835633] Wed, 09 December 2020 08:40 Go to previous messageGo to next message
Malvina Latifaj is currently offline Malvina LatifajFriend
Messages: 11
Registered: June 2020
Junior Member
No Message Body

[Updated on: Wed, 09 December 2020 08:43]

Report message to a moderator

Re: Transformation XText to Papyrus and vice versa [message #1835636 is a reply to message #1835633] Wed, 09 December 2020 08:44 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Ok, here comes the first issue. I actually thought this might be a problem somehow being that I was using two instances.

So, I was able to get the graphical2textual launch configuration and I have uploaded that file here. However, when I tried to save the textual2graphical.etl, I get the following error.

Could not locate a metamodel with the URI 'http://www.coronaepsilon.corona/MyDsl'. Please ensure that this metamodel has been registered with Epsilon.Type 'coronatextual!WorldMap' not found


This metamodel is in the first instance, not the second.

Thank you!
Re: Transformation XText to Papyrus and vice versa [message #1835637 is a reply to message #1835636] Wed, 09 December 2020 09:29 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Ok, so i had to register the Epackage on the first instance and I was able to generate the launch configuration, so I am uploading that here.

Thank you!
Re: Transformation XText to Papyrus and vice versa [message #1835639 is a reply to message #1835637] Wed, 09 December 2020 10:29 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Malvina,

The problem seems to be the input UML model (corona.uml). If you open it with the built-in tree-based editor, right-click on its root and select "Validate", EMF validation should report several errors (see attached). Once you have fixed these, please try to run the transformation again and let me know if the problem persists.

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835650 is a reply to message #1835639] Wed, 09 December 2020 13:32 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

I made a few changes and I am uploading the zip files once again. When I run the model validation now, I get no errors.

I believe that transformation does happen, but I do not know where to check that. Whenever I tried the graphical2textual transformation with the first approach, I could see the changes reflected on my EMF model, because I did not write the DSL model on Xtext but I created an EMF model. However, now I cannot see any changes.

The reason why I say that I believe that the transformation does take place is because if i run the other transformation, textual2graphical, I get this error.

index.php/fa/39506/0/

So that means that four stereotypes are created on the graphical model because I have four of them on the textual one (one world map and three countries).

So my first question is, how can I fix this? Do I need to change the transformation rules and hardcode the profile definition for each of these stereotypes? If so, do you have any idea on how that can be done?

Second thing is regarding the graphical2textual transformation.

I understand that this transformation also takes place because after running the textual2graphical transformation mentioned above and getting 4 dangling stereotypes, I try to run the graphical2textual transformation and then once again textual2graphical.

Now I get 8 dangling stereotypes, which means that the graphical2textual transformation also works. However, I do not know where to see the ones that have been added. When I open the XText file with sample ecore model editor, I only get the ones that I have written myself on XText, not the ones added by the transformation.

Any idea about this?
Re: Transformation XText to Papyrus and vice versa [message #1835653 is a reply to message #1835650] Wed, 09 December 2020 14:14 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

The issue with the graphical2textual transformation seems to be that world maps do not get connected to countries in the target model (and therefore Xtext refuses to serialise them). Updating your graphical2textual.etl transformation as follows seems to be doing the trick. If you open your UML model with a text editor you will notice three instances of WorldMap and several copies of the same countries - which should be cleaned up and then you shouldn't need the guard of the first rule. Please note that in the configurations of your transformations, only the "Read on load" option should be selected for the source model, and only the "Store on disposal" option should be selected for the target model.

rule WorldMap2Worldmap
transform g: coronagraphical!WorldMap
to t: coronatextual!WorldMap {
	guard: g.base_Package != null

	t.name = g.name;
	t.country ::= g.getCountries();
}

// transformation rule for object country
rule Country2Country
transform g: coronagraphical!Country
to t: coronatextual!Country {
	t.name = g.name;
	t.population = g.population;
	t.zone = g.zone.getzone();
} 

//operation for enumeration zonelabel
operation Any getzone() {
	if (self == coronagraphical!zonelabel#green) {
		return coronatextual!zonelabelcolour#green;
	}
	else if (self = coronagraphical!zonelabel#red) {
		return coronatextual!zonelabelcolour#red;
	}
	else {
		return coronatextual!zonelabelcolour#yellow;
	}
}

operation coronagraphical!WorldMap getCountries() {
	return coronagraphical!Country.all.select(c|self.base_Package.
		packagedElement.includes(c.base_Component));
}


Thanks,
Dimitris

[Updated on: Wed, 09 December 2020 14:20]

Report message to a moderator

Re: Transformation XText to Papyrus and vice versa [message #1835664 is a reply to message #1835653] Wed, 09 December 2020 16:40 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

Thank you for your answer. Everything seems to be working fine now with the graphical2textual transformation.

Regarding the textual2graphical transformation where I get the window "Repair Stereotypes" as shown in the prior messages, how would you suggest I proceed? I guess that somehow I must hardcode in the ETL transformation the part where I apply the stereotypes?
Re: Transformation XText to Papyrus and vice versa [message #1835677 is a reply to message #1835664] Thu, 10 December 2020 09:35 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

> I guess that somehow I must hardcode in the ETL transformation the part where I apply the stereotypes?

This is correct. There's an example that shows how to apply profiles to UML models here: https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/examples/org.eclipse.epsilon.examples.applyprofile

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835678 is a reply to message #1835677] Thu, 10 December 2020 09:51 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

Thank you very much for the example, I was looking for similar. You have been extremely helpful.

Big thanks!
Re: Transformation XText to Papyrus and vice versa [message #1835680 is a reply to message #1835678] Thu, 10 December 2020 10:05 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

You're very welcome! Any further issues, please give us a shout.

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835696 is a reply to message #1835680] Thu, 10 December 2020 15:54 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

I wrote some transformation rules based onthe example you sent me and this post: https://www.eclipse.org/forums/index.php/t/744410/

The zip file is same as the one I sent before and these are the transformation rules.

rule WorldMapT2WorldMapG
transform s: coronatextual!WorldMap 
to t: coronagraphical!WorldMap
{
t.name=s.name;
t.packagedElement.add(s.country.equivalent());
t.applyProfile(PROFILE!Profile.allInstances -> selectOne(p | p.name= 'corona'));
t.applyProfile(PROFILE!Profile.allInstances -> selectOne(p | p.name= 'WorldMap'));
}

rule Country2CountryComponent
transform s: coronatextual!Country
to t: coronagraphical!Country
{
t.name=s.name;
t.population=s.population;
t.zone=s.zone.getZone();
t.applyStereotype(PROFILE!Stereotype.allInstances -> selectOne(p | p.name= 'Country'));
}

//operation for enumeration zonelabel
operation Any getzone() {
	if (self == coronagraphical!zonelabel#green) {
		return coronatextual!zonelabelcolour#green;
	}
	else if (self = coronagraphical!zonelabel#red) {
		return coronatextual!zonelabelcolour#red;
	}
	else {
		return coronatextual!zonelabelcolour#yellow;
	}
}


However I get an error saying:

Quote:

Type 'coronatextual!WorldMap' not found
at (/Users/User/runtime-EclipseXtext/coronaepsilon/specs/textual2graphical.etl@2:13-2:35)


However, I am certain that I have defined the source and target models correctly. Do you know what might be wrong?

Big thanks!
Re: Transformation XText to Papyrus and vice versa [message #1835698 is a reply to message #1835696] Thu, 10 December 2020 16:08 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Could you please send me a fresh copy that includes your stored launch configuration for this transformation?

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835699 is a reply to message #1835698] Thu, 10 December 2020 16:24 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Sure, here it is.

I have not been able to see if the transformation rules are ok because I cannot run it. Before adding the textual2graphical transformation, the graphical2textual one was working fine. however after running textual2graphical I got errors for both of the tranformations. And even though I create the xtext model at corona.coronapesilon, it gets deleted after I run the transformations.
Re: Transformation XText to Papyrus and vice versa [message #1835721 is a reply to message #1835699] Thu, 10 December 2020 22:41 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

I re-generated the XText artifacts, recreated the corona.coronaepsilon Xtext file and the UML model and the graphical2textual transformation works fine as before. However, when I run the textual2graphical transformation it is still the same issue. I am uploading the zip files once again.

Thank you!
Re: Transformation XText to Papyrus and vice versa [message #1835724 is a reply to message #1835721] Fri, 11 December 2020 00:01 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hello,

I've just posted an article [1] and an example [2] showing how to create and query profiled UML models using Epsilon. The first section of the article should help you sort out any remaining issues with the textual2graphical transformation; if not, please let me know.

Thanks,
Dimitris

[1] https://eclipse.org/epsilon/doc/articles/profiled-uml-models/
[2] https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/examples/org.eclipse.epsilon.examples.eol.uml.profiled
Re: Transformation XText to Papyrus and vice versa [message #1835753 is a reply to message #1835724] Fri, 11 December 2020 14:24 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

Thank you for taking the time to write this article and share it with us.

However, I have one question. From what I see on your example, your source model is the one containing the profile, and your target model the one you want to create where you apply that profile.

Being that in my case it is the opposite, meaning that it is not my source model containing the profile, but my target model (in the case of the textual2graphical transformation), will that make a difference?

Thank you!
Re: Transformation XText to Papyrus and vice versa [message #1835754 is a reply to message #1835753] Fri, 11 December 2020 14:54 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

You're welcome! That should work equally well in your scenario too.

Thanks,
Dimitris

[Updated on: Fri, 11 December 2020 14:54]

Report message to a moderator

Re: Transformation XText to Papyrus and vice versa [message #1835759 is a reply to message #1835754] Fri, 11 December 2020 17:52 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

I followed your example and made some change to the transformation. However, now I get an error. The zip files are attached. Do you think it is something wrong with the transformation or it might be another issue?

Quote:

org.eclipse.epsilon.eol.types.EolModelElementType
at (/Users/User/runtime-EclipseXtext/coronaepsilon/specs/textual2graphical.etl@16:0-16:41)
at (/Users/User/runtime-EclipseXtext/coronaepsilon/specs/textual2graphical.etl@16:0-16:41)
at (unknown@0:0-0:0)
at (/Users/User/runtime-EclipseXtext/coronaepsilon/specs/textual2graphical.etl@1:0-56:1)


Thank you!
Re: Transformation XText to Papyrus and vice versa [message #1835760 is a reply to message #1835759] Fri, 11 December 2020 17:58 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Try changing "var Model" to "var model" so that there is no confusion between the "Model" variable and the "Model" UML metaclass. In general, by convention, variable names in Epsilon programs tend to start with lower-case letters (like in Java).

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835762 is a reply to message #1835760] Fri, 11 December 2020 18:57 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

I changed that and Package, and it seems fine now. However I am getting the same issue I was getting yesterday with the graphical2textual transformation, but that did not occur anymore. When I run the textual2graphical transformation, I get

Quote:

Type 'coronagraphical!WorldMap' not found


I would get the same thing yesterday with the graphical2textual transformation but I would get

Quote:

Type 'coronatextual!WorldMap' not found


When I run the textual2graphcial transformation and I get that error, the content of the graphical model (corona.uml) gets deleted.
Re: Transformation XText to Papyrus and vice versa [message #1835814 is a reply to message #1835760] Mon, 14 December 2020 08:06 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

I tried to re-generate everything from scratch but it seems like the problem still persists. Do you think it might be a bug or something?

Thank you!
Re: Transformation XText to Papyrus and vice versa [message #1835816 is a reply to message #1835814] Mon, 14 December 2020 08:51 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi,

You need to apply the profile only once, in a pre block [1] before any of your rules are executed as shown below.

pre {
	// Profile application code here
}

rule WorldMapT2WorldMapG
	transform s: coronatextual!WorldMap 
	to t: coronagraphical!WorldMap {
	...
}


Thanks,
Dimitris

[Updated on: Mon, 14 December 2020 08:51]

Report message to a moderator

Re: Transformation XText to Papyrus and vice versa [message #1835817 is a reply to message #1835816] Mon, 14 December 2020 09:25 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

I get the "coronatextual!WorldMap" not found error, in both cases. Even when in the pre block I only include getting hold of the profile and model and applying the profile to the model as below:

pre {
//get hold of the profile
var profile = coronagraphical!Profile.all.first();
//get hold of the model
var appliedmod = coronagraphical!Model.allInstances->first();
//applyProfile
appliedmod.applyProfile(profile);

}

rule WorldMapT2WorldMapG
transform s: coronatextual!WorldMap 
to t: coronagraphical!WorldMap
{
//get hold of the stereotype WorldMap
var WorldMapStereotype = profile.getPackagedElement("WorldMap");
// get hold of the Package
var appliedpackage = coronagraphical!Package;
//add it as a child to the model
appliedmod.packagedElement.add(appliedpackage);
//apply the stereotype to the Package
var WorldMap=package.applyStereotype(WorldMapStereotype);
t.name=s.name;
}


And either if I include everything in the pre block :

pre {
//get hold of the profile
var profile = coronagraphical!Profile.all.first();
//get hold of the model
var appliedmod = coronagraphical!Model.allInstances->first();
//applyProfile
appliedmod.applyProfile(profile);
//get hold of the stereotype WorldMap
var WorldMapStereotype = profile.getPackagedElement("WorldMap");
// get hold of the Package
var appliedpackage = coronagraphical!Package;
//add it as a child to the model
appliedmod.packagedElement.add(appliedpackage);
//apply the stereotype to the Package
var WorldMap=package.applyStereotype(WorldMapStereotype);
}

rule WorldMapT2WorldMapG
transform s: coronatextual!WorldMap 
to t: coronagraphical!WorldMap
{
t.name=s.name;
}
Re: Transformation XText to Papyrus and vice versa [message #1835820 is a reply to message #1835817] Mon, 14 December 2020 09:34 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

The solution I suggested was for the profiled UML model (coronagraphical). Adding the following pre-block to your textual2graphical.etl transformation prints the expected result, which indicates that your textual model is loaded and processed without issues.

pre {
    coronatextual!WorldMap.all.first().println();
}


Given that we may need to go back and forth a few more times on this, could you please put your minimal example in a public GitHub repo so that I can fetch your updates without needing to delete/re-import the projects in every iteration?

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835834 is a reply to message #1835820] Mon, 14 December 2020 15:06 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
I did this, but still no luck.

Sure, this is the repository: https://github.com/TRworkspace/EpsilonTransformation

Many thanks!
Re: Transformation XText to Papyrus and vice versa [message #1835843 is a reply to message #1835834] Mon, 14 December 2020 19:35 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

The projects in the repo seem to be missing ".project" files and hence I cannot import them in my Eclipse. Could you please let me know when you've pushed the missing files?

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835846 is a reply to message #1835843] Mon, 14 December 2020 23:19 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
The .project files are added and the github should be fine now :)

Many thanks!

[Updated on: Tue, 15 December 2020 13:09]

Report message to a moderator

Re: Transformation XText to Papyrus and vice versa [message #1835871 is a reply to message #1835846] Tue, 15 December 2020 14:56 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

In the first rule of your textual2graphical.etl transformation you should create a UML package (or model) instead of a WorldMap and in the body you should apply the WorldMap stereotype to it as follows (the 2nd rule should be updated accordingly). You also need to add another CoronaProfile model to your run configuration, which points at your corona.profile.uml profile.

rule WorldMapT2WorldMapG
	transform s: Coronatextual!WorldMap 
	to t: Coronagraphical!Model {
	
	//get hold of the profile
	var profile = CoronaProfile!Profile.all.first();
	//get hold of the model
	t.applyProfile(profile);
	//get hold of the stereotype WorldMap
	var worldMapStereotype = profile.getPackagedElement("WorldMap");
	//apply the stereotype to the model
	var worldMap = t.applyStereotype(worldMapStereotype);
	worldMap.name=s.name;
}


If you could grant me write access to your repo (my GitHub id is @kolovos) I can push the changes directly.

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835872 is a reply to message #1835871] Tue, 15 December 2020 15:13 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

Oh I see, so I should not get hold of the profile from the graphical model, but from a new model that I create and which points at my profile.

Is there a specific reason for that? On why should I create another model, when also my former graphical model points to the same profile?

Yes, thank you, I just provided you access :)

Many thanks once again!
Re: Transformation XText to Papyrus and vice versa [message #1835873 is a reply to message #1835871] Tue, 15 December 2020 15:14 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Fixed in https://github.com/TRworkspace/EpsilonTransformation/commit/2dfb5c036c0f13d314c3ff44f41868ce0efb1469. The complete transformation is below for anyone else to whom this might be useful in the future.

rule WorldMapT2WorldMapG
	transform s: Coronatextual!WorldMap 
	to t: Coronagraphical!Model {
	
	//get hold of the profile
	var profile = CoronaProfile!Profile.all.first();
	
	//get hold of the model
	t.applyProfile(profile);
	//get hold of the stereotype WorldMap
	var worldMapStereotype = profile.getPackagedElement("WorldMap");
	//apply the stereotype to the model
	var worldMap = t.applyStereotype(worldMapStereotype);
	worldMap.name=s.name;
	
	// Get hold of the EPackage representation of the profile
	var profileEPackage = t.profileApplications.first().appliedDefinition;
	// ... and add it to the package registry of our UML model
	Coronagraphical.resource.resourceSet.packageRegistry.
		put(profileEPackage.nsURI, profileEPackage);
	
}

rule Country2CountryComponent
	transform s: Coronatextual!Country
	to t: Coronagraphical!Component {
	
	// Add the component as a child of the model
	// produced by its world map
	s.eContainer().equivalent().packagedElement.add(t);
	
	//get hold of the profile
	var profile = CoronaProfile!Profile.all.first();
	//get hold of the stereotype Country
	var countryStereotype = profile.getPackagedElement("Country");
	
	//apply the stereotype to the Component
	var country= t.applyStereotype(countryStereotype);
	
	country.name=s.name;
	country.population=s.population;
	country.zone = s.zone.getZone();
}

//operation for enumeration zonelabel
operation Any getZone() {
	if (self == Coronatextual!zonelabelcolour#green) {
		return Coronagraphical!zonelabelcolour#green;
	}
	else if (self = Coronatextual!zonelabelcolour#red) {
		return Coronagraphical!zonelabelcolour#red;
	}
	else {
		return Coronagraphical!zonelabelcolour#yellow;
	}
}


Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835874 is a reply to message #1835873] Tue, 15 December 2020 15:16 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

> Is there a specific reason for that? On why should I create another model, when also my former graphical model points to the same profile?

As the "Read on load" option of your target UML model is (rightly) not ticked in the run configuration of textual2graphical, its existing contents are ignored.

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1835889 is a reply to message #1835874] Tue, 15 December 2020 21:25 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

I made a few changes to the code and pushed it on Github.

The changes include:

1. Changed the Xtext grammar by adding a

Model:
name=String
worldmap=WorldMap

The reason for that is because when I create a UML model the structure of the uml file is:

-Model
-----Package
-----------Component

while with the code that I had, the uml file after the tranformation would have this structure:

-Package
----Component

So, I created a model in xtext and added a new transformation rule. However, the only thing that gets transformed is the model and not the package and component as children of the model.

However, I have added the package as a child of the model.

Do you know what might be the issue?

Many thanks!
Re: Transformation XText to Papyrus and vice versa [message #1835895 is a reply to message #1835889] Wed, 16 December 2020 01:03 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

Everything works fine now with the textual2graphical transformation. However, being that I modified the Xtext grammar, where I added:

Model:
	name=STRING
	worldmap=WorldMap
;


Now I need to also modify the transformation graphical2textual, so I added the following:

rule Model2Model 
transform g: coronagraphical!Model
to t: coronatextual!Model
{
t.name=g.name;
t.worldmap ::= g.getWorldMap();
}

operation coronagraphical!Model getWorldMap() {
 return coronagraphical!WorldMap.all.select(p|self.
 packagedElement.includes(p.base_Package));
}


However, it doesn't work as there is an error:

java.util.ArrayList cannot be cast to corona.corona.WorldMap


I believe there should be something wrong with the syntax of the operation?

Thank you!
Re: Transformation XText to Papyrus and vice versa [message #1835913 is a reply to message #1835895] Wed, 16 December 2020 10:35 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi,

Replacing select() with selectOne in your operation should do the trick.

Thanks,
Dimitris
Re: Transformation XText to Papyrus and vice versa [message #1836023 is a reply to message #1835913] Fri, 18 December 2020 12:46 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Dimitris,

It is all working perfectly fine now.

Thank you very much for the continuous support :)
Re: Transformation XText to Papyrus and vice versa [message #1836024 is a reply to message #1836023] Fri, 18 December 2020 12:54 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

That's good to hear - you're welcome!

Thanks,
Dimitris
Previous Topic:SysML/UML to Simulink/Matlab Transformation
Next Topic:possible to open .model file in an DSL graphic editor?
Goto Forum:
  


Current Time: Thu Apr 25 00:36:28 GMT 2024

Powered by FUDForum. Page generated in 0.06338 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top