Skip to main content
summaryrefslogtreecommitdiffstats
blob: 60802fb3c3f7bb6f7c5f49046359464b787a0485 (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
--Author Manel Fredj-CEA LIST
library StateDiagram;

import Converter.Utils.ConverterLibs;
import StateDiagVisualIDs;
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::stateDiagNode2Shape() : notation::Shape inherits di2::GraphNode::node2Shape
{
	--add 3 eAnnotations as in class diagram
	eAnnotations := setEAnnotations ();
	
	if (self.getElement().oclIsTypeOf(uml::State)) then {
		type := VisualId_State;
		children := setChildrenForState(self);	
	} endif;
	if (self.getElement().oclIsTypeOf(uml::StateMachine)) then {
		type := VisualId_StateMachine;
		children := setChildrenForStateMachine(self);		
	} endif;
	if (self.getElement().oclIsTypeOf(uml::Comment)) then {
		-- type := VisualId_Comment;
	} endif;
	if (self.getElement().oclIsTypeOf(uml::Region)) then {
		type := VisualId_Region;
		children := setChildrenForRegion(self);
	  	eAnnotations += object ecore::EAnnotation {
			source := "RegionAnnotationKey";
			details := object ecore::EStringToStringMapEntry {
				key   := "RegionZoneKey";
				value := "";
			};
		};
	} endif;
	if (self.getElement().oclIsTypeOf(uml::FinalState)) then {
		type := VisualId_FinalState;
		children := setChildrenForPseudoState (self, VisualId_FinalState_DecoNode1, VisualId_FinalState_DecoNode2);
	} endif;
	if (self.getElement().oclIsTypeOf(uml::ConnectionPointReference)) then {
		type := VisualId_ConnectionPoint;
		children := setChildrenForPseudoState (self, VisualId_ConnectionPoint_DecoNode1, VisualId_ConnectionPoint_DecoNode2);
	} endif;
	if (self.getElement().oclIsTypeOf(uml::Pseudostate)) then {
		var pseudoState := self.getElement().oclAsType(uml::Pseudostate);
		if (pseudoState.kind = uml::PseudostateKind::initial) then {
			type := VisualId_InitialState;
			children := setChildrenForPseudoState (self, VisualId_InitialState_DecoNode1, VisualId_InitialState_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::shallowHistory) then {
			type := VisualId_ShallowHistoryState;
			children := setChildrenForPseudoState (self, VisualId_ShallowHistoryState_DecoNode1, VisualId_ShallowHistoryState_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::deepHistory) then {
			type := VisualId_DeepHistoryState;
			children := setChildrenForPseudoState (self, VisualId_DeepHistoryState_DecoNode1, VisualId_DeepHistoryState_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::choice) then {
			type := VisualId_Choice;
			children := setChildrenForPseudoState (self, VisualId_Choice_DecoNode1, VisualId_Choice_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::join) then {
			type := VisualId_Choice;
			children := setChildrenForPseudoState (self, VisualId_Choice_DecoNode1, VisualId_Choice_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::fork) then {
			type := VisualId_Fork;
			children := setChildrenForPseudoState (self, VisualId_Fork_DecoNode1, VisualId_Fork_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::junction) then {
			type := VisualId_Junction;
			children := setChildrenForPseudoState (self, VisualId_Junction_DecoNode1, VisualId_Junction_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::terminate) then {
			type := VisualId_Terminate;
			children := setChildrenForPseudoState (self, VisualId_Terminate_DecoNode1, VisualId_Terminate_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::entryPoint) then {
			type := VisualId_EntryPoint;
			children := setChildrenForPseudoState (self, VisualId_EntryPoint_DecoNode1, VisualId_EntryPoint_DecoNode2);
		} endif;
		if (pseudoState.kind = uml::PseudostateKind::exitPoint) then {
			type := VisualId_ExitPoint;
			children := setChildrenForPseudoState (self, VisualId_ExitPoint_DecoNode1, VisualId_ExitPoint_DecoNode2);
		} endif;
	} endif;
}


helper setChildrenForPseudoState(in node : di2::GraphNode, in visualID1 : String, in visualID2 : String) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := visualID1;
		layoutConstraint := object notation::Location {
			x := 20
		};
	};
	var child2 := object notation::DecorationNode {
		type := visualID2;
		layoutConstraint := object notation::Location {
			x := 20
		};
	};
	return OrderedSet {
		child1, child2
	};
};
		
---------------------------------------------------------------------------
--set children for state

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

	-- first child	
	var child2 := object notation::DecorationNode {
		type:=VisualId_State_DecoNode2;
	};
	/*
	-- second child	
	var child2 := object notation::BasicCompartment {
		type:=VisualId_Class_Composite_Compartiment;
		--set children as properties
		children:= setPropertiesForState(node.contained);
		layoutConstraint:=object notation::Bounds {};
	};		
	*/
	--convert edges in the composite 

	return OrderedSet {
		child1, child2
	};
}

helper setChildrenForStateMachine(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_StateMachine_DecoNode1;
	};
	var child2 := object notation::DecorationNode {
		type := VisualId_StateMachine_DecoNode2;
		var containedElements : OrderedSet(di2::GraphNode) := node.getSubElementsOfPackage();
		containedElements->forEach (containedElement) {
			var shape : notation::Shape ::= containedElement.map stateDiagNode2Shape();		
			if (shape.type != "") then {
				--don't add invalid IDs
				children += shape;
			} endif;
		};
	};

	return OrderedSet {
		child1, child2
	};
}

helper setChildrenForRegion(in node : di2::GraphNode) : OrderedSet(notation::Node)
{
	-- first child	
	var child1 := object notation::DecorationNode {
		type := VisualId_Region_DecoNode;
		var containedElements : OrderedSet(di2::GraphNode) := node.getSubElementsOfPackage();
		containedElements->forEach (containedElement) {
			var shape : notation::Shape ::= containedElement.map stateDiagNode2Shape();
			if (shape.type != "") then {		
				--don't add invalid IDs
				children += shape;
			} endif;
		};
	};

	return OrderedSet {
		child1
	};
}

/*
--in contrained attributes: properties or nested classes
helper setPropertiesForState(in contained:OrderedSet(di2::DiagramElement)) : OrderedSet(notation::Node)
{
	var setOfChildren:OrderedSet(notation::Node); 
	var child:notation::Node;																
	contained ->forEach (node|node.oclIsTypeOf(di2::GraphNode)) {
	
		if(node.oclAsType(di2::GraphNode).getElement().oclIsTypeOf(uml::Property)) then {
			child := node.oclAsType(di2::GraphNode).map ComponentClass2Property();
			setOfChildren += child;
		} endif;
		if (node.oclAsType(di2::GraphNode).getElement().oclIsTypeOf(uml::Class)) then {
			child := node.oclAsType(di2::GraphNode).map ComponentClass2Class(node.oclAsType(di2::GraphNode));
			setOfChildren += child;
		} endif;
	};								

	return setOfChildren;
}


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

	type := VisualId_Component_Property ;
	--seteAnnotation
	eAnnotations := setEAnnotations ();
	--setchildren
	children:=setChildrenForComponentProperty();	
	
	--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; 
	};	
	--set element	
	element := self.getElement().oclAsType(ecore::EObject);
}  

helper setChildrenForComponentProperty() : OrderedSet(notation::Node)
{
      --<children xmi:type="notation:DecorationNode"     type="5126"/>
      --<children xmi:type="notation:BasicCompartment"   type="7077">
      --	<layoutConstraint xmi:type="notation:Bounds" />
      --</children>

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

	-- second child	
	var child2 := object notation::BasicCompartment {
		type:=VisualId_Component_Property_Compartiment;
		layoutConstraint:=object notation::Bounds {};
	};

	return OrderedSet {child1, child2};
}


-----------------------------------------------------------------------------
-- case of nested classes

mapping di2::GraphNode::ComponentClass2Class(in node:di2::GraphNode) : notation::Shape {

	type := VisualId_Component_Class;
	--seteAnnotation
	eAnnotations := setEAnnotations ();
	--setchildren
	children:=setChildrenForComponentClass(node);	
	
	--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; 
	};
	
	--set element
	element := self.getElement().oclAsType(ecore::EObject);
} 

helper setChildrenForComponentClass(in node:di2::GraphNode) : OrderedSet(notation::Node)
{
      --<children xmi:type="notation:DecorationNode"     type="5126"/>
      --<children xmi:type="notation:BasicCompartment"   type="7077">
      --	<layoutConstraint xmi:type="notation:Bounds" />
      --</children>

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

	-- second child	
	var child2 := object notation::BasicCompartment {
		type:=VisualId_Component_Class_Compartiment;
		
		--set children as properties in the case that the nested class contains properties
		children:= setPropertiesForState(node.contained);
		layoutConstraint:=object notation::Bounds {};
	};
	
	return OrderedSet{child1, child2};
}


*/

Back to the top