Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 77861625eec4a8672cd573957682dd3b8f039d3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*****************************************************************************
 * 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 Rhapsody2PapyrusSemanticElements;
import RhapsodyUtils;
import SysMLRhapsodyUtils;
import RhapsodyToPapyrusDiagamCommon;
import org.eclipse.papyrus.migration.rhapsody.blackboxes.Rhapsody2PapyrusNotationBlackboxes;
import org.eclipse.papyrus.migration.rhapsody.blackboxes.sysml11.diagrams.ParametricDiagramFixLayoutLocationBlackboxes;

modeltype umlrhapsody "strict" uses 'http://www.eclipse.org/Papyrus/UMLRhapsody/1.0.0';
modeltype notation "strict" uses 'http://www.eclipse.org/gmf/runtime/1.0.2/notation';
modeltype uml "strict" uses 'http://www.eclipse.org/uml2/5.0.0/UML';
modeltype sysml11 "strict" uses 'http://www.eclipse.org/papyrus/0.7.0/SysML';
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 transformation allows to import Rhapsody Parametric Diagram as Papyrus SysML 1.1 Parametric Diagram
*
*/
transformation SysML11ParametricDiagram(in semantics : umlrhapsody, out graphics : notation, inout model:uml ,in Sysml11Profile:sysml11, in primitives:UMLPrimitivesTypes)
access transformation Rhapsody2PapyrusSemanticElements(in inModel:umlrhapsody, out outModel:uml, in primitives:UMLPrimitivesTypes) 
extends Rhapsody2PapyrusSemanticElements(in inModel:umlrhapsody, out outModel:uml, in primitives:UMLPrimitivesTypes)
{
	//nothing to do here
}


mapping rhapsodymetamodel::IDiagram::iDiagramToSysML11ParametricDiagram(rpyProject:IProject):Diagram when{self.isUserModelDiagram() and self.isSysMLParametricDiagram()}{
	init{
		var owner:EObject;
			//2. setting the diagram owner
		var iDiagramOwner:ecore::EObject:=self[EObject].eContainer()![EObject];
		if(iDiagramOwner.oclIsKindOf(umlrhapsody::IClass)){
			owner:= iDiagramOwner.resolveIn(umlrhapsody::IClass::toUMLElement, uml::Element)![EObject];
		};

		result:=self.map createAndInitDiagram(rpyProject,getPapyrusDiagramType(), owner, owner);
	}
	
	//0. find some objects
	var cgiClassChart:CGIClassChart:=self.graphicChart->oclAsSet().selectByType(CGIClassChart)->any(true);
	
	//0.a find the object root of the diagram
	var cgiClass:GraphElementsType:=null;
	if(cgiClassChart.m_pRoot.oclIsKindOf(CGIClass)){
		cgiClass:=cgiClassChart.m_pRoot.oclAsType(GraphElementsType);
	};
	
	var cgiDiagramFrame:CGIDiagramFrame:=cgiClassChart.graphElements->selectByType(CGIDiagramFrame)->any(true);
		
	//3. as it is an ParametricDiagram, we must represent the owner in the diagram. This is the Rhapsody Frame
	var rootBlockShape:Shape= object Shape{
		type:="shape_sysml_block_as_composite";
		children+= object DecorationNode { type:="label_sysml_block_name"};
		layoutConstraint:=object Bounds{x:=cgiDiagramFrame.get_X_Position(); y:=cgiDiagramFrame.get_Y_Position(); width:=cgiDiagramFrame.get_Width(); height:=cgiDiagramFrame.get_Height()};
	};
	
	children+=rootBlockShape;

	var basicCompartment:BasicCompartment:= object BasicCompartment { 
			type:="compartment_sysml_structure";
			styles+= object TitleStyle{};
	};
	rootBlockShape.children+=basicCompartment;
	

	//mapping object inside the container 
	basicCompartment.children+=cgiClassChart.graphElements->select(a | a.isAllowedAsCompartmentChildren(basicCompartment)).map graphElementsTypeToPDShapes(cgiClassChart, cgiClass->asSequence());
	
	//mapping affixed child node
	rootBlockShape.children+=cgiClassChart.graphElements->select(a | a.isAllowedAsAffixedChildNode(rootBlockShape)).map graphElementsTypeToPDShapes(cgiClassChart, cgiDiagramFrame->asSequence());
	edges+=cgiClassChart.graphElements.map graphElementsTypeToPBEdges(cgiClassChart, cgiClass->asSequence());
	
	fixLayout(result);
};

/**
* Returns the type of the diagram to create
*/
query getPapyrusDiagramType():String{
	return 'Parametric';
};

/**
* Returns true when the graph element can be used as an affixed child node in Papyrus Diagram
*/
query umlrhapsody::GraphElementsType::isAllowedAsAffixedChildNode(shape:Shape):Boolean{
	return self.oclIsTypeOf(CGIPortConnector);
}

/**
* Returns true when the graph element can be set as a children of a given compartment
*/
query umlrhapsody::GraphElementsType::isAllowedAsCompartmentChildren(cpt:BasicCompartment):Boolean{
	return not self.oclIsTypeOf(CGIPortConnector);
}

/**
* This mapping take GraphElementsType and returns Shape.
* @param
*		cgiClassChart : the class chart of the diagram, it is useful to find child to create for the created element
* @param
* 		rpyAllowedParent : the list of the allowed Rhapsody parent to manage the object.
*		if the Rhapsody parent is not in this list, the object won't be mapped
*	
*/
mapping rhapsodymetamodel::GraphElementsType::graphElementsTypeToPDShapes(cgiClassChart:CGIClassChart, rpyAllowedParent:Sequence(GraphElementsType)):Shape disjuncts
	rhapsodymetamodel::CGIAnnotation::CGIAnnotationToCommentCN,
	rhapsodymetamodel::CGIObjectInstance::CGIObjectInstanceToPDContraintProperty,
	rhapsodymetamodel::CGIObjectInstance::CGIObjectInstanceToPDPart,
	rhapsodymetamodel::CGIGenericElement::CGIGenericElementToPDBlockPropertyAsComposite, 
	rhapsodymetamodel::CGIPortConnector::CGIPortConnectorToPorpertyAsAffixedChildNode
{}


/**
* This mapping take GraphElementsType and returns Shape
*/
mapping rhapsodymetamodel::GraphElementsType::graphElementsTypeToPBEdges(cgiClassChart:CGIClassChart, rpyAllowedParent:Sequence(GraphElementsType)):Edge disjuncts
	rhapsodymetamodel::CGIObjectLink::graphElementsTypeToPDConnector,
	rhapsodymetamodel::CGIAnchor::graphElementsTypeToPDCommentLink
{}

/**
* This method allows to map comment link
*
*/
mapping rhapsodymetamodel::CGIAnchor::graphElementsTypeToPDCommentLink(cgiClassChart:CGIClassChart, rpyAllowedParent:Sequence(GraphElementsType)):Connector when {self.getLinkSourceView()<>null and self.getLinkTargetView()<>null}{
	type:="Comment_AnnotatedElementEdge";
	source:=self.getLinkSourceView();
	target:=self.getLinkTargetView();
	var sourceNode:M_pRootType:=self.m_pSource;
	var targetNode:M_pRootType:=self.m_pTarget;
	addAnchorsAndBendpoints(self,result);
	
	//manage connector routing
	routing:=self.oclAsType(GraphElementsType).getConnectorRouting();	
	eAnnotations+=createCSSForceValue("routing");
}

/**
*
* This method allows to map the connector link
*/
mapping rhapsodymetamodel::CGIObjectLink::graphElementsTypeToPDConnector(cgiClassChart:CGIClassChart, rpyAllowedParent:Sequence(GraphElementsType)):Connector when {self.getLinkSourceView()<>null and self.getLinkTargetView()<>null}{
	type:="link_uml_connector";
	source:=self.getLinkSourceView();
	target:=self.getLinkTargetView();
	element:= self.m_pModelObject.resolveoneIn(umlrhapsody::IObjectLink::iObjectLinkToUMLElement).oclAsType(EObject);
		
	addAnchorsAndBendpoints(self,result);
	
	children+=object DecorationNode{
		 type:="linklabel_uml_appliedstereotype";
		 layoutConstraint:=object Location{
		 	y:=-30; //TODO : a dummy value
		 };
	};
	
	
	//managing the name label of the connector
//	var nameText:CGIText:=self.m_rpn;
	children+=object DecorationNode{
		type:="linklabel_uml_connector_label";
		layoutConstraint:=object Location{
			y:=-10; //TODO : a dummy value 
		};
	};
	
	//manage connector routing
	routing:=self.oclAsType(GraphElementsType).getConnectorRouting();	
	eAnnotations+=createCSSForceValue("routing");
}

//TODO : calling resolve method could not work in soem case : if we are mapping a link linked to another link not yet mapped -> we will not able to resolve it!
//TODO : manage link linked to an other link (comment link for example)
query umlrhapsody::CGIAnchor::getLinkSourceView():View{
	var source:View:=self.m_pSource![M_pRootType].resolveIn(umlrhapsody::GraphElementsType::graphElementsTypeToPDShapes, Shape)![View];
	if(source=null){
//		source:=self.m_pSource![M_pRootType].resolveIn(umlrhapsody::GraphElementsType::graphElementsTypeToIBDEdges, Connector)![View];
	};
	return source;
}

query umlrhapsody::CGIAnchor::getLinkTargetView():View{
	var target:View:=self.m_pTarget![M_pRootType].resolveIn(umlrhapsody::GraphElementsType::graphElementsTypeToPDShapes, Shape)![View];
	if(target=null){
//		target:=self.m_pTarget![M_pRootType].resolveIn(umlrhapsody::GraphElementsType::graphElementsTypeToIBDEdges, Connector)![View];
	};
	return target
}

query umlrhapsody::CGIObjectLink::getLinkSourceView():View{
	var source:View:=self.m_pSource![M_pRootType].resolveIn(umlrhapsody::GraphElementsType::graphElementsTypeToPDShapes, Shape)![View];
	if(source=null){
//		source:=self.m_pSource![M_pRootType].resolveIn(umlrhapsody::GraphElementsType::graphElementsTypeToIBDEdges, Connector)![View];
	};
	return source;
}

query umlrhapsody::CGIObjectLink::getLinkTargetView():View{
	var target:View:=self.m_pTarget![M_pRootType].resolveIn(umlrhapsody::GraphElementsType::graphElementsTypeToPDShapes, Shape)![View];
	if(target=null){
//		target:=self.m_pTarget![M_pRootType].resolveIn(umlrhapsody::GraphElementsType::graphElementsTypeToIBDEdges, Connector)![View];
	};
	return target
}


mapping rhapsodymetamodel::CGIPortConnector::CGIPortConnectorToPorpertyAsAffixedChildNode(cgiClassChart:CGIClassChart, rpyAllowedParent:Sequence(GraphElementsType)): Shape when {rpyAllowedParent->includes(self.m_pParent.oclAsType(GraphElementsType))}{
	type:="shape_uml_property_as_affixed";

	children+=object DecorationNode{
		type:="affixedlabel_uml_port_label";
		layoutConstraint:= object Location{
			x:=-40; //TODO dummy value
			y:=-40; //TODO dummy value
		};
	};
	
	children+=object DecorationNode{
		type:="affixedlabel_uml_appliedstereotype";
		layoutConstraint:= object Location{
		};
	};
	
	layoutConstraint:= object Bounds{
		x:=getX(self);
		y:=getY(self);
		width:=20;
		height:=20;
	};
	
	element:=self.m_pModelObject.resolveoneIn(umlrhapsody::IRelation::iRelationToUMLElement).oclAsType(EObject);
}

mapping rhapsodymetamodel::CGIObjectInstance::CGIObjectInstanceToPDContraintProperty(cgiClassChart:CGIClassChart, rpyAllowedParent:Sequence(GraphElementsType)): Shape when {self.m_pModelObject.oclIsKindOf(IPart) and self.m_pModelObject.oclAsType(IPart).isSysMLConstraintProperty() and self.m_pParent.oclIsTypeOf(CGIClass) and self.m_pParent.oclIsKindOf(GraphElementsType) and rpyAllowedParent->includes(self.m_pParent.oclAsType(GraphElementsType))}{ 
//we are not able to generate children of ContraintProperty
	type:= "shape_sysml_constraintblockproperty_as_composite";
	children+= object DecorationNode {type:="label_uml_property_label"};
	element:=self.m_pModelObject.resolveone().oclAsType(EObject);
	
	//this part is not required for Rhapsody model!
	//children+= object DecorationNode {
	//type:="shape_uml_constraint_as_label";
	//	//parent element should be a property typed by a constraint block. This constraint block contains a constraint! We map on it!
	//	var t:uml::Type:=element.oclAsType(uml::TypedElement).type;
	//	if(t<>null){
	//		element:=t.ownedElement->selectByType(uml::Constraint)->any(true).oclAsType(EObject);
	//	};
	//		};
	
	layoutConstraint:= object Bounds{x:=getX(self); y:=getY(self); width:=getRectangleWidth(self); height:=getRectangleHeight(self);};
	
	//we add the affixed child node
	children+= cgiClassChart.graphElements->select(a | a.isAllowedAsAffixedChildNode(result)).map graphElementsTypeToPDShapes(cgiClassChart, self->asSequence());
}

mapping rhapsodymetamodel::CGIObjectInstance::CGIObjectInstanceToPDPart(cgiClassChart:CGIClassChart, rpyAllowedParent:Sequence(GraphElementsType)):Shape when {self.oclIsTypeOf(CGIObjectInstance) and self.m_pParent.oclIsKindOf(GraphElementsType) and rpyAllowedParent->includes(self.m_pParent.oclAsType(GraphElementsType))}{
	type:="shape_sysml_blockproperty_as_composite";
	children+= object DecorationNode{
		type:="label_uml_property_label";
	};
	var blockPropertyStructure:BasicCompartment:= object BasicCompartment {
		type:="compartment_sysml_blockproperty_structure";
		styles+=object TitleStyle{};
	};
	
	children+=blockPropertyStructure;
	layoutConstraint:= object Bounds{ 
		x:=getX(self); 
		y:=getY(self); 
		width :=getRectangleWidth(self); 
		height := getRectangleHeight(self)
	};
	element:=self.m_pModelObject.resolveone().oclAsType(EObject);

	//we fill the compartment
	blockPropertyStructure.children+= cgiClassChart.graphElements->selectByType(CGIGenericElement)->select(g | g.m_pParent=self).map graphElementsTypeToPDShapes(cgiClassChart, self->asSequence());
}

mapping rhapsodymetamodel::CGIGenericElement::CGIGenericElementToPDBlockPropertyAsComposite(cgiClassChart:CGIClassChart,rpyAllowedParent:Sequence(GraphElementsType)):Shape when {self.oclIsTypeOf(CGIGenericElement) and self.m_pParent.oclIsKindOf(GraphElementsType) and rpyAllowedParent->includes(self.m_pParent.oclAsType(GraphElementsType))}{
	type:="shape_sysml_blockproperty_as_composite";
	children+= object DecorationNode{
		type:="label_uml_property_label";
	};
	children+= object BasicCompartment {
		type:="compartment_sysml_blockproperty_structure";
		styles+=object TitleStyle{};
	};
	layoutConstraint:= object Bounds{ 
		x:=getX(self); 
		y:=getY(self); 
		width :=getRectangleWidth(self); 
		height := getRectangleHeight(self)};
	element:=self.m_pModelObject.resolveone().oclAsType(EObject);
}

Back to the top