Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2eab4fe4c1719f33a5209d4683c81656ce48d9c8 (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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*****************************************************************************
 * 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.migration.rhapsody.blackboxes.sysml11.NestedConnectorEndBlackboxes;
import org.eclipse.papyrus.migration.rhapsody.blackboxes.Rhapsody2PapyrusNotationBlackboxes;
import org.eclipse.papyrus.migration.rhapsody.blackboxes.uml.UMLRhapsodySemanticHelper;
import Rhapsody2PapyrusSemanticElements;
import RhapsodyToPapyrus;
import RhapsodyUtils;
import SysMLRhapsodyUtils;

modeltype umlrhapsody "strict" uses 'http://www.eclipse.org/Papyrus/UMLRhapsody/1.0.0';
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' ;


/**
*
* WARNING : ISysMLPort is a part of Rhapsody metamodel and doesn't come from the SysML Rhapsody Profile
*
*
*/
transformation SysML11Profile(in inModel:umlrhapsody, out outModel:uml, in Sysml11Profile:sysml11, in primitives:UMLPrimitivesTypes)
extends Rhapsody2PapyrusSemanticElements(in inModel:umlrhapsody, out outModel:uml, in primitives:UMLPrimitivesTypes)

{
	main() {
			if (isRhapsodySysMLProfileApplied() and sysml11<>null ) {
				log("Start SysML Profiles and Stereotypes Application");
				//if yes apply it to the output model
				var model: Model := outModel.rootObjects()[uml::Model]->any(true);
			
				// apply sysml 1.1 profile with all sub profiles
				var sysml11Profiles : Set(Profile) := Sysml11Profile.objectsOfType(Profile);
	
				sysml11Profiles->forEach(profile) {
					model.applyProfile(profile);
				};
	
				//apply SysML 1.1 stereotype when it is applied in Rhapsody Model
				inModel.objects()->select(rpy | not rpy.oclIsKindOf( GraphElementsType))->selectByKind(EObject).map applyRequiredSysML11Stereotype();
		
				//apply NestedConnectorEnd stereotype
				outModel.objects()->selectByKind(uml::ConnectorEnd).map applySysML11ConnectorEndStereotype();
				
				log("End SysML Profiles and Stereotypes Application");
			};
	};
}

/**
* This mapping create the NestedConnectorEnd stereotype when required for the given object
*
*/
mapping uml::ConnectorEnd::applySysML11ConnectorEndStereotype() : sysml11::blocks::NestedConnectorEnd when {getNestedConnectorEndPropertyPath(self)->size()>0}{
	base_ConnectorEnd:=self;
	propertyPath:=getNestedConnectorEndPropertyPath(self);
}


/**
*
* Return true if the Rhapsody SysML Profile is applied on the Rhapsody model
*/
query isRhapsodySysMLProfileApplied():Boolean {
	var ret:Boolean = false;
	var isProfiledModel:Boolean:=inModel.objectsOfType(IStereotype)->size()>0;
	if (isProfiledModel) {
		inModel.objectsOfType(IStereotype)->forEach(stereotype){
			if(stereotype.isARhapsodySysMLStereotype()){	
				ret:= true;
				break;
			}
		}
	};
	return ret;
}


//--------------------------Here we are working on the Rhapsody Stereotypes--------------

/**
* This method manage the stereotype application from Rhapsody to Papyrus for a set of Rhapsody element
* 
* TODO : edit the Rhapsody metamodel to get a common ancestor to manipulate easily the stereotyped element in Rhapsody
*/
mapping ecore::EObject::applyRequiredSysML11Stereotype() disjuncts
	ecore::EObject::applyStereotypeFromIClass,
	ecore::EObject::applyStereotypeFromIType_To_InstanceSpecification,
	ecore::EObject::applyStereotypeFromIType_To_DataType,
	ecore::EObject::applyStereotypeFromIType_To_Class,
	ecore::EObject::applyStereotypeFromIType_To_Type,
	ecore::EObject::applyStereotypeFromISysMLPort,
	ecore::EObject::applyStereotypeFromIPart,
	ecore::EObject::applyStereotypeFromIAttribute,
	ecore::EObject::applyStereotypeFromIInformationFlow
{}

/**
* This method cross the stereotypes applied on the IClass and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromIClass() when {self.oclIsTypeOf(IClass) /*and not self.oclAsType(IClass).Stereotypes->isEmpty()*/}{ //test on stereotype must be done in the method, because we always need to do some thing for IClass
	var rpyElement:IClass:=self.oclAsType(IClass);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(IClass::toUMLElement, uml::Element);
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		}
	};
	
	//apply Block and PropertySpecificType on some class
	var nestedClassesForPart:Sequence(IClass):=rpyElement.Associations[IPart]->select(current | current.implicitClass<>null).implicitClass.oclAsSet();
    nestedClassesForPart->forEach(current){
    	var umlClass:uml::Class:=current.resolveone().oclAsType(uml::Class);
    	umlClass.map applySysML11Stereotype(current.oclAsType(EObject), "Block");
    	umlClass.map applySysML11Stereotype(current.oclAsType(EObject), "PropertySpecificType");
    };
}

/**
* This method cross the stereotypes applied on the IType and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromIType_To_InstanceSpecification() when {self.oclIsTypeOf(IType)  and not self.oclAsType(IType).Stereotypes->isEmpty() and self.oclAsType(IType).resolveoneIn(IType::toUMLInstanceSpecification, InstanceSpecification)<>null}{
	var rpyElement:IType:=self.oclAsType(IType);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(IType::toUMLInstanceSpecification, InstanceSpecification);
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		}		
	}
}

/**
* This method cross the stereotypes applied on the IType and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromIType_To_DataType() when {self.oclIsTypeOf(IType)  and not self.oclAsType(IType).Stereotypes->isEmpty() and self.oclAsType(IType).resolveoneIn(IType::toUMLDatatype, DataType)<>null}{
	var rpyElement:IType:=self.oclAsType(IType);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(IType::toUMLDatatype, DataType);
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		}		
	}
}

//TODO umlDataType and umlClass are probably useless now, waiting for JUnit tests to remove them from this method
/**
* This method cross the stereotypes applied on the IType and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromIType_To_Class() when {self.oclIsTypeOf(IType)  and not self.oclAsType(IType).Stereotypes->isEmpty() and self.oclAsType(IType).resolveoneIn(IType::iTypeToUMLClass, Class)<>null}{
	var rpyElement:IType:=self.oclAsType(IType);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(IType::iTypeToUMLClass, Class);
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		};
		
		//in all case, we apply block on the class
		umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName("Block"));		
	}
}

/**
* This method cross the stereotypes applied on the IType and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromIType_To_Type() when {self.oclIsTypeOf(IType)  and not self.oclAsType(IType).Stereotypes->isEmpty() and self.oclAsType(IType).resolveoneIn(IType::iTypeToUMLElement, Type)<>null}{
	var rpyElement:IType:=self.oclAsType(IType);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(IType::iTypeToUMLElement, Type);
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		}		
	}
}

/**
* This method cross the stereotypes applied on the ISysMLPort and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromISysMLPort() when {self.oclIsTypeOf(ISysMLPort) and not self.oclAsType(ISysMLPort).Stereotypes->isEmpty()}{
	var rpyElement:ISysMLPort:=self.oclAsType(ISysMLPort);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(umlrhapsody::IRelation::iRelationToUMLElement); 
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		}		
	}
}

/**
* This method cross the stereotypes applied on the IPart and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromIPart() when {self.oclIsTypeOf(IPart)  and not self.oclAsType(IPart).Stereotypes->isEmpty()}{ 
	var rpyElement:IPart:=self.oclAsType(IPart);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(umlrhapsody::IPart::iPartToUMLElement);
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		}		
	}
}

/**
* This method cross the stereotypes applied on the IAttribute and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromIAttribute() when {self.oclIsTypeOf(IAttribute) and not self.oclAsType(IAttribute).Stereotypes->isEmpty()}{ 
	var rpyElement:IAttribute:=self.oclAsType(IAttribute);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(IVariable::iVariableToUMLElement, uml::Property);
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		}		
	}
}

/**
* This method cross the stereotypes applied on the IInformationFlow and call the method to apply them on the equivalent uml element
*/
mapping ecore::EObject::applyStereotypeFromIInformationFlow() when {self.oclIsTypeOf(IInformationFlow)  and not self.oclAsType(IInformationFlow).Stereotypes->isEmpty()}{ 
	var rpyElement:IInformationFlow:=self.oclAsType(IInformationFlow);
	//we look for the created uml element
	var umlElement:Element:=rpyElement.resolveoneIn(umlrhapsody::IInformationFlow::iInformationFlowToUMLElement); 
	if(umlElement<>null){
		rpyElement.Stereotypes->selectByType(umlrhapsody::IStereotype)->forEach(current){
				umlElement.map applySysML11Stereotype(rpyElement.oclAsType(EObject), getSysML11StereotypeName(current.name));
		}		
	}
}


//--------------------------Here we are working on the UML Stereotypes-------------------
/**
* Common method to apply a UML stereotype from the rhapsody element and from its name to a UML Element 
*/
mapping uml::Element::applySysML11Stereotype(rpyElement:EObject, umlSteName:String):EObject disjuncts
	uml::DataType::applySysML11ValueType,
	uml::InstanceSpecification::applySysML11Dimension,
	uml::InstanceSpecification::applySysML11Unit,
	uml::Class::applySysML11Block,
	uml::Property::applySysML11FlowProperty,
	uml::Port::applySysML11FlowPort,
	
	//default mapping method
	uml::Element::applySysML11Stereotype_DefaultMapping
{}

/**
* Default mapping to apply Sysml11 stereotype
*
*/
mapping uml::Element::applySysML11Stereotype_DefaultMapping(rpyElement:EObject, umlSteName:String):EObject when {getSysML11Stereotype(umlSteName)<>null}{
	init {
		var stereotypeToApply:Stereotype:=getSysML11Stereotype(umlSteName);
		self.applyStereotype(stereotypeToApply);
		result:=self.getAppliedStereotype(stereotypeToApply.getQualifiedName()).oclAsType(EObject);
	}
}

/**
*
* This method apply the stereotype SysML FlowPort
*/
mapping uml::Port::applySysML11FlowPort(rpyElement:EObject, stereotypeName:String):EObject when{rpyElement.oclIsKindOf(ISysMLPort) and stereotypeName="FlowPort"}{
	init{
		var stereotypeApplication:sysml11::portandflows::FlowPort:= object sysml11::portandflows::FlowPort{
			base_Port:=self;
			direction:=getSysML11FlowDirection(rpyElement.oclAsType(ISysMLPort).direction);
			isConjugated:=rpyElement.oclAsType(ISysMLPort).isConjugated();
		};
		result:=stereotypeApplication.oclAsType(EObject);
	}
}

/**
*
* This method apply the stereotype SysML FlowPort
*/
mapping uml::Property::applySysML11FlowProperty(rpyElement:EObject, stereotypeName:String):EObject when{rpyElement.oclIsKindOf(IAttribute) and stereotypeName="FlowProperty"}{
	init{
		var stereotypeApplication:sysml11::portandflows::FlowProperty:= object sysml11::portandflows::FlowProperty{
			base_Property:=self;
			
			//we have model with 2 kind of declaration for the same thing...
			//the first way!
			var dir:String:=rpyElement.oclAsType(IAttribute).Tags->select(t | (t.name="direction" and t.typeOf.oclAsType(IType).name="FlowDirection"))	
				->any(true).ValueSpecifications->any(true).oclAsType(ILiteralSpecification).value;
				
			//the 2nd way when required
			if(dir=null){
				dir:=rpyElement.oclAsType(IAttribute).Tags->select(t | (t.name="direction" and t.typeOf.oclAsType(IType).name="RhpString"))	//probably due to an error in the model
					->any(true).ValueSpecifications->any(true).oclAsType(ILiteralSpecification).value;
			};
			direction:=getSysML11FlowDirection(dir);
		};
		result:=stereotypeApplication.oclAsType(EObject);
	}
}

/**
* This method apply the stereotype Block
*/
mapping uml::Class::applySysML11Block(rpyElement:EObject, stereotypeName:String):EObject when{stereotypeName="Block"}{
	init{
		var stereotypeApplication:sysml11::blocks::Block:= object sysml11::blocks::Block{
			base_Class:=self;
		};
		result:=stereotypeApplication.oclAsType(EObject);
	}
}

/**
* This method apply the stereotype Dimension
*/
mapping uml::InstanceSpecification::applySysML11Dimension(rpyElement:EObject, umlSteName:String):EObject when {umlSteName="Dimension"}{
	init{
		var stereotypeApplication:sysml11::blocks::Dimension:= object sysml11::blocks::Dimension{
			base_InstanceSpecification:=self;
		};
		result:=stereotypeApplication.oclAsType(EObject);
	}
}

/**
* This method apply the stereotype Unit
*/
mapping uml::InstanceSpecification::applySysML11Unit(rpyElement:EObject, umlSteName:String):EObject when {umlSteName="Unit" and  rpyElement.oclIsKindOf(IType)}{
	init{
		var stereotypeApplication:sysml11::blocks::Unit:= object sysml11::blocks::Unit{
			base_InstanceSpecification:=self;

			//manage the dimension field
			var tt:umlrhapsody::ITag=rpyElement.oclAsType(IType).Tags->select(t | t.name="dimension")->any(true);
			var iinstancespec:umlrhapsody::IInstanceValue=tt.ValueSpecifications->selectByKind(umlrhapsody::IInstanceValue)->any(true);
			if(iinstancespec<>null){
				var val = iinstancespec.value;
	   			var res:uml::InstanceSpecification = val.resolveoneIn(IType::toUMLInstanceSpecification);
	   			dimension:=res.map applySysML11Stereotype(val.oclAsType(EObject),"Dimension").oclAsType(sysml11::blocks::Dimension);
			}
		};
		result:=stereotypeApplication.oclAsType(EObject);
	}
}

mapping uml::DataType::applySysML11ValueType(rpyElement:EObject, umlSteName:String):EObject when {umlSteName="ValueType" and rpyElement.oclIsKindOf(IType)}{
	init{
		var stereotypeApplication:sysml11::blocks::ValueType:= object sysml11::blocks::ValueType{
			base_DataType:=self;
			
			//manage the dimension field
			var dimensionTag:umlrhapsody::ITag=rpyElement.oclAsType(IType).Tags->select(t | t.name="dimension")->any(true);
			var dimensionInstanceIInstancespec:umlrhapsody::IInstanceValue=dimensionTag.ValueSpecifications -> selectByKind(umlrhapsody::IInstanceValue)->any(true);
			if(dimensionInstanceIInstancespec<>null){
				var val = dimensionInstanceIInstancespec.value;
	   			var res:uml::InstanceSpecification = val.resolveoneIn(IType::toUMLInstanceSpecification);
	   			dimension:=res.map applySysML11Stereotype(val.oclAsType(EObject),"Dimension").oclAsType(sysml11::blocks::Dimension);
			};
			
			//manage the unit field
			var unitTag:umlrhapsody::ITag=rpyElement.oclAsType(IType).Tags->select(t | t.name="unit")->any(true);
			var unitInstanceIInstancespec:umlrhapsody::IInstanceValue=unitTag.ValueSpecifications -> selectByKind(umlrhapsody::IInstanceValue)->any(true);
			if(unitInstanceIInstancespec<>null){
				var val = unitInstanceIInstancespec.value;
	   			var res:uml::InstanceSpecification = val.resolveoneIn(IType::toUMLInstanceSpecification);
	   			unit:=res.map applySysML11Stereotype(val.oclAsType(EObject),"Unit").oclAsType(sysml11::blocks::Unit);
			};
		};
		result:=stereotypeApplication.oclAsType(EObject);
	}
}


/**
*
* Return the SysML 1.1 Stereotype for the given string or null if not found
*/
query getSysML11Stereotype(rpyStereotypeName:String ) :uml::Stereotype {
	return Sysml11Profile.objectsOfType(Stereotype)![name=getSysML11StereotypeName(rpyStereotypeName)];
}

/**
* Return the SysML 1.1 name corresponding to the Rhapsody SysML Name
*/
query getSysML11StereotypeName(rpyStereotypeName:String): String{
	var sysml11SteName:=switch{
		case (rpyStereotypeName="flowSpecification") 	"FlowSpecification";
		case (rpyStereotypeName="flowProperty") 		"FlowProperty";
		case (rpyStereotypeName="flowPort") 			"FlowPort";
		
		//all case where the Rhapsody SysML Stereotype name is the same than the Papyrus SysML Name
		case (true) rpyStereotypeName;
	};
	return sysml11SteName
}

/**
*
* This method convert the rhaspody flow direction into the SysML  FlowDirection 
*/ 
query getSysML11FlowDirection(rpyDirection:String) : sysml11::portandflows::FlowDirection{
	var direction:  sysml11::portandflows::FlowDirection;
	direction:= switch  {
		case (rpyDirection="In") sysml11::portandflows::FlowDirection::_in;
		case (rpyDirection="Out") sysml11::portandflows::FlowDirection::_out;
		case (rpyDirection="InOut") sysml11::portandflows::FlowDirection::_inout; 
		case (rpyDirection="Bidirectional") sysml11::portandflows::FlowDirection::_inout;
		case (true) sysml11::portandflows::FlowDirection::_inout;
	};
	return direction;
}

Back to the top