blob: ea96fa9406dc662a403622caead1e90731828d16 [file]
/*****************************************************************************
* Copyright (c) 2016 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*****************************************************************************/
import org.eclipse.papyrus.interoperability.rpy.blackboxes.sysml11.NestedConnectorEndBlackboxes;
import org.eclipse.papyrus.interoperability.rpy.blackboxes.Rpy2PapyrusNotationBlackboxes;
import Rpy2PapyrusSemanticElements;
import RpyToPapyrus;
import RpyUtils;
import SysMLRpyUtils;
modeltype umlrpy "strict" uses 'http://www.eclipse.org/Papyrus/UMLRpy/1.0.0';
modeltype uml "strict" uses 'http://www.eclipse.org/uml2/5.0.0/UML';
modeltype marte "strict" uses 'http://www.eclipse.org/papyrus/MARTE/1';
modeltype ecore "strict" uses 'http://www.eclipse.org/emf/2002/Ecore';
modeltype UMLPrimitivesTypes "strict" uses 'http://www.eclipse.org/uml2/5.0.0/Types' ;
/**
*
* This transfo apply the Marte profile and required stereotype to the model
*
*/
/**TODO : the dependency on Marte was refused at this time, that's why the plugin doesn't have dependency on it, and this transformation doesn't compile.
*
* Nevertheless, to avoid to lose this work, I keep this file in the plugin
*/
transformation MarteProfile(in inModel:umlrpy, out outModel:uml, in marteProfile:marte, in primitives:UMLPrimitivesTypes)
extends Rpy2PapyrusSemanticElements(in inModel:umlrpy, out outModel:uml, in primitives:UMLPrimitivesTypes)
{
//TODO : remove this field
property retunitStero = marteProfile.objectsOfType(Profile)![name = "HLAM"].ownedStereotype![name = "RtUnit"];
main() {
if (isRpyMarteAppliedProfile() and marteProfile<>null ) {
//if yes apply it to the output model
var model: Model := outModel.rootObjects()[uml::Model]->any(true);
// apply marte profile with all sub profiles
var marteProfiles : Set(Profile) := marteProfile.objectsOfType(Profile);
marteProfiles->forEach(profile){
model.applyProfile(profile);
};
//transform the Rpy MARTE applied sterotype to Papyrus MARTE applied sterotype
inModel.rootObjects()[IProject].Subsystems.map toMartePapyrusProfile();
// change one sterotype tagged value
//var sterotypedClass:uml::Class=outModel.objectsOfType(uml::Class)->select(c|not (c.getAppliedStereotypes()->isEmpty()))->any(true);
//sterotypedClass.setValue(sterotypedClass.getAppliedStereotypes()![Stereotype], "isMain", true);
};
};
}
mapping DefaultSubsystemType::toMartePapyrusProfile(){
self.allSubobjectsOfKind(IClass)->forEach(classe)
{
if ( not(classe[IClass].Stereotypes.oclIsUndefined()->any(true)))
{
var stereotypes:Set(IUnit):=classe[IClass].Stereotypes->asSet();
stereotypes->forEach(stereotype)
{
if (stereotype.oclIsTypeOf(IStereotype))
{
// map it to the papyrus marte profile
var papyMarteSter:uml::Stereotype := stereotype[IStereotype].map toPapyrusMarteStereotype()->any(true);
var umlClass:uml::Class:=classe.resolveIn(IClass::toClasses, Class)![Class];
if(not(papyMarteSter.oclIsUndefined())){
umlClass.applyStereotype(papyMarteSter);
//
umlClass.setValue(umlClass.getAppliedStereotypes()![Stereotype], "isMain", true);
}
}
}
}
};
}
/**
*
* Return the UML Stereotype to apply for the Rahspdoy stereotype or null when not found
*/
//TODO : remove me
mapping umlrpy::IStereotype::iStereotypeToUMLStereotype():uml::Stereotype disjuncts
// umlrpy::IStereotype::toPapyrusSysML11Stereotype,
umlrpy::IStereotype::toPapyrusMarteStereotype
{}
/**
*
* Map a Rpy MARTE Stereotype on a (Papyrus) MARTE Stereotype when this one exists
*/
mapping IStereotype::toPapyrusMarteStereotype() :uml::Stereotype when {self.name<>null and self.isARpyMARTEStereotype() and getMarteStereotype(self.name)<>null}{
init{
result :=getMarteStereotype(self.name);
}
}
/**
* Return the MARTE Stereotype for the given string or null if not found
*
*/
query getMarteStereotype(s:String ) :uml::Stereotype {
var stereotype: uml::Stereotype = null;
stereotype:= switch {
case (s="RtUnit") marteProfile.objectsOfType(Stereotype)![name = "RtUnit"];
case (s="PpUnit") marteProfile.objectsOfType(Stereotype)![name = "PpUnit"];
};
return stereotype;
}
/**
* Return true if the Rpy Marte Profile is applied on the Rpy model
*
*/
query isRpyMarteAppliedProfile() :Boolean {
var ret:Boolean = false;
var isProfiledModel:Boolean:=inModel.objectsOfType(IStereotype)->size()>0;
if (isProfiledModel) {
inModel.objectsOfType(IStereotype)->forEach(stereotype){
if(stereotype.isARpyMARTEStereotype()){
ret:= true;
break;
}
}
};
return ret;
}
/**
* Return true if the IStereotype comes from the MARTE Rpy profile
*
*/
query umlrpy::IStereotype::isARpyMARTEStereotype():Boolean{
var ret:Boolean:=false;
var profileresource:EResource:=self[EObject].eResource()![EResource];
if(profileresource<>null){
ret:=profileresource.toString().endsWith("MARTE.umlrpy'")
};
return ret;
}