Skip to main content
summaryrefslogtreecommitdiffstats
blob: 162d0f27d1b6a9443d923f07366d75f17259c915 (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
--Author Ansgar Radermacher - CEA LIST
library ProfileDiagram;

import Converter.Utils.ConverterLibs;
import ProfileDiagVisualIDs;
import GeneralMappingsandHelpers;


modeltype di2 uses 'http://www.papyrusuml.org/di2';
modeltype notation uses 'http://www.eclipse.org/gmf/runtime/1.0.2/notation';
modeltype ecore uses 'http://www.eclipse.org/emf/2002/Ecore';
modeltype uml uses 'http://www.eclipse.org/uml2/2.1.0/UML';


mapping di2::GraphNode::profileDiagNode2Shape() : notation::Shape inherits di2::GraphNode::node2Shape
{
	--add 3 eAnnotations as in class diagram
	eAnnotations := setEAnnotations ();

	if (self.getElement().oclIsTypeOf(uml::Stereotype)) then {
		type := VisualId_Stereotype;
	  	children := setChildrenForStereotype(self);
	} endif;
	if (self.getElement().oclIsTypeOf(uml::ElementImport)) then {
		// TODO: in Papyrus 1, meta-classes refer to element imports, but not all element imports are meta-classes
		type := VisualId_Metaclass;
	  	children := setChildrenForMetaclass(self);
	  	// replace element import by meta-class reference
	    element := self.getSemanticModel().getMetaclassRef().oclAsType(ecore::EObject);
	} endif;
	if (self.getElement().oclIsTypeOf(uml::Comment)) then {
		type := VisualId_Comment;
	  	children := setChildrenForComment(self);
	} endif;
	if (self.getElement().oclIsTypeOf(uml::Package)) then {
		type := VisualId_Package;
	  	children := setChildrenForPackage(self);
	} endif;
	if (self.getElement().oclIsTypeOf(uml::Profile)) then {
		type := VisualId_Profile;
	  	children := setChildrenForProfile(self);
	} endif;
	if (self.getElement().oclIsTypeOf(uml::DataType)) then {
		type := VisualId_DataType;
	  	children := setChildrenForDataType(self);
	} endif;
	if (self.getElement().oclIsTypeOf(uml::Enumeration)) then {
		type := VisualId_Enum;
	  	children := setChildrenForEnum(self);
	} endif;
}


---------------------------------------------------------------------------
--set children for stereotype

helper setChildrenForStereotype(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_Stereotype_DecoNode;
		--the id is set automatically
	};

	-- second child	
	var child2 := object notation::BasicCompartment {
		type := VisualId_Stereotype_Label;
		styles := OrderedSet {
			object notation::SortingStyle { },
			object notation::FilteringStyle { }
		};
		layoutConstraint := object notation::Bounds {};
	};
	
	-- third child	
	var child3 := object notation::BasicCompartment {
		type := VisualId_Stereotype_Compartment;
		--set children as properties
		children:= setPropertiesForStereotype(node.contained);
		layoutConstraint := object notation::Bounds {};
	};
	
	return OrderedSet {
		child1, child2, child3
	};
}

--in contained attributes: properties or nested classes
helper setPropertiesForStereotype(in contained:OrderedSet(di2::DiagramElement)) : OrderedSet(notation::Node)
{
	var setOfChildren : OrderedSet(notation::Node); 
	--var child : notation::Node;	

	contained ->forEach (node|node.oclIsTypeOf(di2::GraphNode)) {									
		node.oclAsType(di2::GraphNode).contained->forEach (subNode|subNode.oclIsTypeOf(di2::GraphNode)) {	
			if(subNode.oclAsType(di2::GraphNode).getElement().oclIsTypeOf(uml::Property)) then {
				var child : notation::Shape := subNode.oclAsType(di2::GraphNode).map stereotype2Property();
				-- var child : notation::Shape;	
				setOfChildren += child;
			} endif;
		};
	};								

	return setOfChildren;
}

-----------------------------------------------------------------------------
-- case of properties
mapping di2::GraphNode::stereotype2Property() : notation::Shape  {

	type := VisualId_StereotypeProperty;
	
	--set element	
	element := self.getElement().oclAsType(ecore::EObject);
	
	--set size and width and high 
	layoutConstraint := object notation::Bounds {
		var size : notation::Size :=  self.size.map dimension2Size();
		var location : notation::Location := self.oclAsType(di2::GraphNode).position.map point2Location();
		x := location.x; 
		y := location.y; 		
		width := size.width;
		height := size.height; 
	};	
}


helper setChildrenForMetaclass(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_Metaclass_DecoNode;
		--the id is set automatically
	};

	return OrderedSet {
		child1
	};
}

helper setChildrenForComment(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_Comment_DecoNode;
		--the id is set automatically
	};
 
	return OrderedSet {
		child1
	};
}

helper setChildrenForProfile(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_Profile_DecoNode1;
	};
	var child2 := object notation::DecorationNode {
		type := VisualId_Profile_DecoNode2;
	 
		var containedElements : OrderedSet(di2::GraphNode) := node.getSubElementsOfPackage();
		containedElements->forEach (containedElement) {
			var shape : notation::Shape ::= containedElement.map profileDiagNode2Shape();		
			children += shape;
		};
	};
	
	return OrderedSet {
		child1, child2
	};
}

helper setChildrenForPackage(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_Package_DecoNode1;
	};
	var child2 := object notation::DecorationNode {
		type := VisualId_Package_DecoNode2;
		var containedElements : OrderedSet(di2::GraphNode) := node.getSubElementsOfPackage();
		containedElements->forEach (containedElement) {
			var shape : notation::Shape ::= containedElement.map profileDiagNode2Shape();		
			children += shape;
		};
	};
	
	return OrderedSet {
		child1, child2
	};
}

---------------------------------------------------------------------------
--set children for enumeration
helper setChildrenForEnum(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	var childrenOfStereotype: OrderedSet(notation::Node);
	
   --<children xmi:type="notation:DecorationNode" type="5156"/>

    --<children xmi:type="notation:BasicCompartment"  type="7073">
    -- <layoutConstraint xmi:type="notation:Bounds" />
   --</children>

	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_Enum_DecoNode;
		--the id is set automatically
	};

	-- second child	
	var child2 := object notation::BasicCompartment {
		type := VisualId_Enum_BasicCompartment;
		children := getEnumLiterals(node);
		layoutConstraint := object notation::Bounds {};
	};
		
	childrenOfStereotype := OrderedSet {
		child1, child2
	};
	
	--convert edges in the composite 

	return  childrenOfStereotype;
}

--for enumeration literals
helper getEnumLiterals(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	var enumLiteralsShape : OrderedSet(notation::Node); 
	var enumLiterals : OrderedSet(ecore::EObject) := node.getEnumLiterals();
	enumLiterals->forEach (enumLiteral) {
		var enumLiteralShape := object notation::Shape {
			type := VisualId_EnumLiteral;
			--fontName="Sans Serif";
			--lineColor="0";
        	element := enumLiteral;
        	layoutConstraint := object notation::Location{};
		};
		enumLiteralsShape += enumLiteralShape;
	};
									
	return enumLiteralsShape;
}

helper setChildrenForDataType(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_DataType_DecoNode;
	};

	-- second child	
	var child2 := object notation::BasicCompartment {
		type := VisualId_DataType_CompartmentAttr;
		--TODO set children
		layoutConstraint := object notation::Bounds {};
	};
	
	-- third child	
	var child3 := object notation::BasicCompartment {
		type := VisualId_DataType_CompartmentOper;
		--set children as properties
		--children:= setPropertiesForStereotype(node.contained);
		layoutConstraint := object notation::Bounds {};
	};
	
	return OrderedSet {
		child1, child2, child3
	};
}

Back to the top