Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2b96a246166b2d337d2f296ab1a492b237aededb (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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*****************************************************************************
 * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, and others.
 *
 * 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:
 *  Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
 *  Christian W. Damus - bug 465656
 *****************************************************************************/
import RSAToPapyrus;

modeltype notation "strict" uses 'http://www.eclipse.org/gmf/runtime/1.0.2/notation';
modeltype umlNotation "strict" uses 'http://www.eclipse.org/papyrus/umlnotation';
modeltype uml "strict" uses 'http://www.eclipse.org/uml2/5.0.0/UML';
modeltype ecore "strict" uses 'http://www.eclipse.org/emf/2002/Ecore';
modeltype sash "strict" uses 'http://www.eclipse.org/papyrus/0.7.0/sashdi';
modeltype config "strict" uses 'http:///RSAToPapyrusParameters.ecore';

transformation RSAProfileDiagram(inout semantics : uml, inout graphics : notation, out di : sash, in param : config);

main() {
	//RSA uses Classes, whereas Papyrus uses DataTypes. The Semantics is the same
	//semantics.objectsOfType(Class)->map toDatatype(); //Disabled 2014/04/28. Papyrus now properly supports Classes in Profile Diagrams
	//we generate our diagrams
	semantics.rootObjects()[uml::Profile]
		->selectByType(uml::Profile) /* Workaround for Bug 445083/445198 */ 
		->map toOwnedDiagrams();	
}

mapping notation::Diagram::generateDiagram() : notation::Diagram inherits Diagram::toPapyrusDiagram when {
	self.findElement().oclIsTypeOf(Profile)
}{
	end {
		//POST ACTION UPDATE meta class to import element
		semantics.objectsOfType(UMLConnector)->map toContextLink();
		graphics.objectsOfType(Shape)->select(type = 'Comment_Shape').map addCommentDecoration();
		graphics.objectsOfType(Shape)->select(type = 'Constraint_PackagedElementShape').map addConstraintDecoration();
	}
}

mapping inout Shape::addCommentDecoration() when {
	self.type = 'Comment_Shape' and self.diagram.type = self.getDiagramType()
} {
	
	self.children += object DecorationNode{
		type := 'Comment_BodyLabel'; //Comment body
	}	

}

mapping inout Shape::addConstraintDecoration() when {
	self.type = 'Constraint_PackagedElementShape' and self.diagram.type = self.getDiagramType()
} {
	
	self.children += object DecorationNode{
		type := 'Constraint_BodyLabel'; //Constraint specification
	}	

}

query View::getDiagramType() : String{
	return 'PapyrusUMLProfileDiagram';
}

mapping UMLConnector::toContextLink() : notation::Connector inherits Connector::toPapyrusConnector when {
	self.type = 'Reference' and self.source.element.oclIsKindOf(Constraint) and self.target.element.oclIsKindOf(Namespace)
}{
	result.type := 'Constraint_ContextEdge';
	self.diagram.map generateDiagram().edges += result;
}

mapping notation::Diagram::toPapyrusProfileDiagram() : notation::Diagram inherits Diagram::toPapyrusDiagram when {
	self.type = 'Profile'
}{
	
}

mapping Node::toNode() : Node disjuncts
	UMLShape::toPapyrusShape,
	UMLShapeCompartment::toStructureCompartment,
	BasicSemanticCompartment::toListCompartment,
	BasicDecorationNode::toConnectorLabel,
	BasicDecorationNode::toLabel
	//TODO: Disjunct nodes mapping
;

mapping Edge::toEdge() : Edge disjuncts
	UMLConnector::toPapyrusConnector
	//TODO: Disjunct edges mapping
;

mapping UMLShapeCompartment::toStructureCompartment() : DecorationNode inherits UMLShapeCompartment::toAbstractStructureCompartment when {
	self.type = 'StructureCompartment' or self.type = 'PackageContents' and not self.getType().oclIsUndefined();
}{
	
}


/***** Nodes **********/

mapping UMLShape::toPapyrusShape() : Shape inherits Shape::toPapyrusShape when {
	self.type = '' and not self.getType().oclIsUndefined() and (
		self.element.oclIsTypeOf(Dependency)or
	self.element.oclIsTypeOf(Association)or
	self.element.oclIsTypeOf(Stereotype)or
	self.element.oclIsTypeOf(Class)or
	self.element.oclIsTypeOf(Class)or
	self.element.oclIsTypeOf(Comment)or
	self.element.oclIsTypeOf(Constraint)or
	self.element.oclIsTypeOf(Model)or
	self.element.oclIsTypeOf(Profile)or
	self.element.oclIsTypeOf(Package)or
	self.element.oclIsTypeOf(Enumeration)or
	self.element.oclIsTypeOf(PrimitiveType)or
	self.element.oclIsTypeOf(DataType)or
	self.element.oclIsTypeOf(Diagram)
	)
}{
	
}


/****** Connector Labels ******/

mapping BasicDecorationNode::toConnectorLabel() : DecorationNode inherits Node::toPapyrusConnectorLabel when {
	not self.getType().oclIsUndefined() and (
		self.type = 'ToMultiplicityLabel' or
		self.type = 'ToRoleLabel' or
		self.type = 'FromMultiplicityLabel' or
		self.type = 'FromRoleLabel' or
		self.type = 'NameLabel' or
		self.type = 'KindLabel'
	)
};

/****** Compartments *******/

mapping BasicDecorationNode::toLabel() : DecorationNode inherits Node::toPapyrusNode when {
	not self.getType().oclIsUndefined() and
	self.element.oclIsKindOf(uml::NamedElement) and 
	self.type = 'Name'
};

mapping BasicSemanticCompartment::toListCompartment() : BasicCompartment inherits Node::toPapyrusNode, DrawerStyle::toDrawerStyle when {
	self.type.endsWith('Compartment') and not self.getType().oclIsUndefined()
}{
	result.children := self.findElement().map toContents(self);
}

mapping Element::toContents(node : BasicSemanticCompartment) : Sequence(Node) disjuncts
	Stereotype::toContents,
	Class::toContents,
	Enumeration::toContents,
	DataType::toContents
;

mapping Stereotype::toContents(node : BasicSemanticCompartment) : Sequence(Node) disjuncts
	Stereotype::toAttributeCompartmentContents,
	Stereotype::toOperationCompartmentContents
;

mapping Class::toContents(node : BasicSemanticCompartment) : Sequence(Node) disjuncts
	Class::toOperationCompartmentContents,
	Class::toAttributeCompartmentContents
;

mapping Enumeration::toContents(node : BasicSemanticCompartment) : Sequence(Node) disjuncts
	Enumeration::toEnumerationEnumerationLiteralContents
;

mapping DataType::toContents(node : BasicSemanticCompartment) : Sequence(Node) disjuncts
	DataType::toDataTypeAttributeCompartmentContents,
	DataType::toDataTypeOperationCompartmentContents
;

mapping Stereotype::toAttributeCompartmentContents(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type = 'AttributeCompartment';
}{
	init {
		result := (self.map fillProperty(node))
	}
}

mapping Stereotype::toOperationCompartmentContents(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type = 'OperationCompartment';
}{
	init {
		result := (self.map fillOperation(node))
	}
}

mapping Class::toOperationCompartmentContents(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type = 'OperationCompartment' 
	and not self.isMetaclass();
}{
	init {
		result := (self.map fillOperation(node))
	}
}

mapping Class::toAttributeCompartmentContents(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type = 'AttributeCompartment'
	and not self.isMetaclass();
}{
	init {
		result := (self.map fillProperty(node))
	}
}

mapping Enumeration::toEnumerationEnumerationLiteralContents(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type = 'EnumerationCompartment';
}{
	init {
		result := (self.map fillEnumerationLiteral(node))
	}
}

mapping DataType::toDataTypeAttributeCompartmentContents(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type = 'AttributeCompartment';
}{
	init {
		result := (self.map fillProperty(node))
	}
}

mapping DataType::toDataTypeOperationCompartmentContents(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type = 'OperationCompartment';
}{
	init {
		result := (self.map fillOperation(node))
	}
}

mapping uml::DataType::fillOperation(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type='OperationCompartment';
}{
	init {
		result := self.ownedOperation->selectByKind(Operation).map toOperationInDataType(node)->asSequence();
	}
}

mapping uml::Enumeration::fillEnumerationLiteral(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type='EnumerationCompartment';
}{
	init {
		result := self.ownedLiteral->selectByKind(EnumerationLiteral).map toEnumerationLiteralInEnumeration(node)->asSequence();
	}
}

mapping uml::DataType::fillProperty(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type='AttributeCompartment';
}{
	init {
		result := self.ownedAttribute->selectByKind(Property).map toPropertyInDataType(node)->asSequence();
	}
}

mapping uml::Stereotype::fillProperty(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type='AttributeCompartment';
}{
	init {
		result := self.ownedAttribute->selectByKind(Property).map toPropertyInStereotype(node)->asSequence();
	}
}

mapping uml::Stereotype::fillOperation(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type='OperationCompartment';
}{
	init {
		result := self.ownedOperation->selectByKind(Operation).map toOperationInStereotype(node)->asSequence();
	}
}

mapping uml::Class::fillProperty(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type='AttributeCompartment'
	and not self.isMetaclass();
}{
	init {
		result := self.ownedAttribute->selectByKind(Property).map toPropertyInClass(node)->asSequence();
	}
}

mapping uml::Class::fillOperation(node : BasicSemanticCompartment) : Sequence(Node) when {
	node.type='OperationCompartment'
	and not self.isMetaclass();
}{
	init {
		result := self.ownedOperation->selectByKind(Operation).map toOperationInClass(node)->asSequence();
	}
}

mapping Operation::toOperationInDataType(node : Node) : Shape inherits Element::toCompartmentEntry {
	result.type := 'Operation_DataTypeOperationLabel';
}

mapping EnumerationLiteral::toEnumerationLiteralInEnumeration(node : Node) : Shape inherits Element::toCompartmentEntry {
	result.type := 'EnumerationLiteral_LiteralLabel';
}

mapping Property::toPropertyInDataType(node : Node) : Shape inherits Element::toCompartmentEntry {
	result.type := 'Property_DataTypeAttributeLabel';
}

mapping Property::toPropertyInStereotype(node : Node) : Shape inherits Element::toCompartmentEntry when{
	not self.name.startsWith('base_')
}{
	result.type := 'Property_ClassAttributeLabel';
}

mapping Operation::toOperationInStereotype(node : Node) : Shape inherits Element::toCompartmentEntry {
	result.type := 'Operation_ClassOperationLabel';
}

mapping Property::toPropertyInClass(node : Node) : Shape inherits Element::toCompartmentEntry when{
	not self.name.startsWith('base_')
}{
	result.type := 'Property_ClassAttributeLabel';
}

mapping Operation::toOperationInClass(node : Node) : Shape inherits Element::toCompartmentEntry {
	result.type := 'Operation_ClassOperationLabel';
}



/******* Edges ********/


mapping UMLConnector::toPapyrusConnector() : Connector inherits Connector::toPapyrusConnector when {
	self.type = '' and 
	not self.getType().oclIsUndefined() and (
		self.element.oclIsTypeOf(Extension)or
		self.element.oclIsTypeOf(Association)or
		self.element.oclIsTypeOf(ProfileApplication)or
		self.element.oclIsTypeOf(Association)or
		self.element.oclIsTypeOf(Generalization)or
		self.element.oclIsTypeOf(Dependency)or
		self.element.oclIsTypeOf(Dependency)or
		self.element.oclIsTypeOf(ElementImport)or
		self.element.oclIsTypeOf(PackageImport)
	)
}{
	result.styles := self.map toFontStyle();
}

/****** Element Type queries ******/

query View::getNodeType(element : Element) : String {
	return
		if element.oclIsTypeOf(Dependency) then 'Dependency_Shape' 
		elif element.oclIsTypeOf(Association) then 'Association_Shape' 
		elif element.oclIsTypeOf(Stereotype) then 'Stereotype_Shape' 
		elif element.oclIsTypeOf(Class) and not element.oclAsType(Class).isMetaclass() then 'Class_Shape' //Class
		elif element.oclIsTypeOf(Class) and element.oclAsType(Class).isMetaclass() then 'Class_MetaclassShape' //Metaclass
		elif element.oclIsTypeOf(Comment) then 'Comment_Shape' 
		elif element.oclIsTypeOf(Constraint) then 'Constraint_PackagedElementShape' 
		elif element.oclIsTypeOf(Model) then 'Model_Shape' 
		elif element.oclIsTypeOf(Profile) then 'Profile_Shape' 
		elif element.oclIsTypeOf(Package) then 'Package_Shape' 
		elif element.oclIsTypeOf(Enumeration) then 'Enumeration_Shape' 
		elif element.oclIsTypeOf(PrimitiveType) then 'PrimitiveType_Shape' 
		elif element.oclIsTypeOf(DataType) then 'DataType_Shape' 
		elif element.oclIsTypeOf(Diagram) then 'Diagram_ShortcutShape' 
		else self.fail()
	endif;
}


query View::getDecorationType(element : Element) : String{
	var res := self.doGetDecorationType(element);
	
	/*
	log('Get papyrus ID for'+ self.element.eClass().name+', '+self.type);
	
	log(res);
	
	if self.container().oclIsKindOf(Node) then 
		log('IsNode')
	else 
		log('IsEdge')
	endif;
	*/
	
	return res;
}

query View::doGetDecorationType(element : Element) : String{
	return if self.container().oclIsKindOf(Node) then {
		return if element.oclIsTypeOf(Stereotype) then
			return switch {
				case (self.type = 'Name') 'Stereotype_NameLabel';
				case (self.type = 'AttributeCompartment') 'Stereotype_AttributeCompartment';
				case (self.type = 'OperationCompartment') 'Stereotype_OperationCompartment';
			}
			elif element.oclIsTypeOf(Class) and not element.oclAsType(Class).isMetaclass() then //Class
				return switch {
					case (self.type = 'Name') 'Class_NameLabel';
					case (self.type = 'OperationCompartment') 'Class_OperationCompartment';
					case (self.type = 'AttributeCompartment') 'Class_AttributeCompartment';
				}
			elif element.oclIsTypeOf(Class) and element.oclAsType(Class).isMetaclass() then //Metaclass
				return switch {
					case (self.type = 'Name') 'Class_MetaclassNameLabel';
					
				}
			elif element.oclIsTypeOf(Constraint) then
				return switch {
					case (self.type = 'Name') 'Constraint_NameLabel';
					
				}
			elif element.oclIsTypeOf(Model) then
				return switch {
					case (self.type = 'Name') 'Model_NameLabel';
					case (self.type = 'StructureCompartment') 'Model_PackagedElementCompartment';
				}
			elif element.oclIsTypeOf(Profile) then
				return switch {
					
					case (self.type = 'StructureCompartment') 'Profile_PackagedElementCompartment';
				}
			elif element.oclIsTypeOf(Package) then
				return switch {
					case (self.type = 'Name') 'Package_NameLabel';
					case (self.type = 'PackageContents') 'Package_PackagedElementCompartment';
				}
			elif element.oclIsTypeOf(Enumeration) then
				return switch {
					case (self.type = 'Name') 'Enumeration_NameLabel';
					case (self.type = 'EnumerationCompartment') 'Enumeration_LiteralCompartment';
				}
			elif element.oclIsTypeOf(PrimitiveType) then
				return switch {
					case (self.type = 'Name') 'PrimitiveType_NameLabel';
					
				}
			elif element.oclIsTypeOf(DataType) then
				return switch {
					case (self.type = 'Name') 'DataType_NameLabel';
					case (self.type = 'AttributeCompartment') 'DataType_AttributeCompartment';
					case (self.type = 'OperationCompartment') 'DataType_OperationCompartment'; //TODO: Disable?
				}
			elif element.oclIsTypeOf(Diagram) then
				return switch {
					case (self.type = 'Name') 'Diagram_NameLabel';
					
				}
		endif
	} else {
		return if element.oclIsTypeOf(Association)  then
			return switch {
				case (self.type='Name') 'Association_NameLabel';		
				case (self.type = 'KindLabel') 'Association_StereotypeLabel';
				case (self.type = 'NameLabel') 'Association_NameLabel';
				
				
				case (self.type = 'FromMultiplicityLabel') 'Association_SourceMultiplicityLabel';
				case (self.type = 'ToMultiplicityLabel') 'Association_TargetMultiplicityLabel';
			}
			elif element.oclIsTypeOf(Generalization)  then
				return switch {
							
					case (self.type = 'KindLabel') 'Generalization_StereotypeLabel';
				}
			elif element.oclIsTypeOf(Dependency)  then
				return switch {
					case (self.type='Name') 'Dependency_NameLabel';		
					case (self.type = 'NameLabel') 'Dependency_NameLabel';
					case (self.type = 'KindLabel') 'Dependency_StereotypeLabel';
				}
			elif element.oclIsTypeOf(ElementImport)  then
				return switch {
							
					
					case (self.type = 'KindLabel') 'ElementImport_StereotypeLabel';
				}
			elif element.oclIsTypeOf(PackageImport)  then
				return switch {
							
					case (self.type = 'KindLabel') 'PackageImport_StereotypeLabel';
				}
		endif
	} endif;
}


query View::getEdgeType(element : Element) : String {
	return
		if self.type = 'Reference' then '' /* Context Links handled separately */
		elif element.oclIsTypeOf(Extension) then 'Extension_Edge'
		elif element.oclIsTypeOf(Association) then 'Association_Edge'
		elif element.oclIsTypeOf(ProfileApplication) then 'ProfileApplication_Edge'
		elif element.oclIsTypeOf(Association) then 'Association_BranchEdge'
		elif element.oclIsTypeOf(Generalization) then 'Generalization_Edge'
		elif element.oclIsTypeOf(Dependency) then 'Dependency_Edge'
		elif element.oclIsTypeOf(Dependency) then 'Dependency_BranchEdge'
		elif element.oclIsTypeOf(ElementImport) then 'ElementImport_Edge'
		elif element.oclIsTypeOf(PackageImport) then 'PackageImport_Edge'
		else self.fail()
	endif;
}

Back to the top