Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f88e9680aea8fe826472e2a14c15908e0f78134a (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
--Author Manel Fredj-CEA LIST
library Diagram;

import ClassDiagNodes;
import StateDiagNodes;
import ProfileDiagNodes;
import ClassAndProfileDiagEdges;
import CompositeDiagNodes;
import StateDiagEdges;
import CompositeDiagEdges;

--import VisualIDs;
import NotationQueries;
import GeneralMappingsandHelpers;

modeltype di uses 'http://www.eclipse.org/papyrus/0.7.0/sashdi';
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::Diagram::diagram2diagram() : notation::Diagram inherits di2::GraphElement::element2View
{
	--the id is set automatically
	--assign type
	type := self.getDiagramtype();
	--assign name
	name := self.name;

	--assign element
	measurementUnit := notation::MeasurementUnit::Pixel;

	--transform contained nodes and edges

	if (type = ClassDiagram_P2) then {
		children := setChildrenForClassDiagram(self.contained);
		edges := setEdgesForClassAndProfileDiagram(self.contained);
	} endif;
	if (type = ProfileDiagram_P2) then {
		children := setChildrenForProfileDiagram(self.contained);
		edges := setEdgesForClassAndProfileDiagram(self.contained);
	} endif;
	if (type = CompositeStructure_P2) then {
		children := setChildrenForCompositeDiagram(self.contained);
		edges := setEdgesForCompositeDiagram(self.contained);
	} endif;
	if (type = StateMachineDiagram_P2) then {
		children := setChildrenForStateDiagram(self.contained);
		edges := setEdgesForStateDiagram(self.contained);
	} endif;

	--Set Style of diagram
	if (type != null) then {
		styles := setStylesForDiagram();
	} endif;
}


--------------------------------------------------------------
--converting a composite diagram
helper setChildrenForCompositeDiagram(in contained:OrderedSet(di2::DiagramElement)) : OrderedSet(notation::Node)
{
	var setOfChildren:OrderedSet(notation::Node); 
	var child:notation::Node;
	var itsParent: notation::Shape;																	
	contained ->forEach (node|node.oclIsTypeOf(di2::GraphNode)) {
			--case of containing a class
			if (node.oclAsType(di2::GraphNode).getElement().oclIsTypeOf(uml::Class) ) then {
				child := node.oclAsType(di2::GraphNode).map compositeDiagNode2Shape();
				setOfChildren += child;
			} endif;
			--case of containing a port : map the potr and attach it to the semantic parent
			if (node.oclAsType(di2::GraphNode).getElement().oclIsTypeOf(uml::Port) ) then {
				child := node.oclAsType(di2::GraphNode).map compositeDiagPort2Shape();
				var temp: di2::DiagramElement:=node.oclAsType(di2::GraphNode).getSemanticParent();
				itsParent:= temp.oclAsType(di2::GraphNode).resolveone (notation::Shape);
				--add the child to the semantic parent
				itsParent.children+= child;
			} endif;
	};								

	return setOfChildren;
}

------------------------------------------------------------
--converting a class diagram 
helper setChildrenForClassDiagram (in contained:OrderedSet(di2::DiagramElement)) : OrderedSet(notation::Node)
{
	var setOfChildren:OrderedSet(notation::Node); 
	var child:notation::Node;																
	contained ->forEach (node|node.oclIsTypeOf(di2::GraphNode)) {
			child := node.oclAsType(di2::GraphNode).map classDiagNode2Shape();
			setOfChildren += child;
	};								

	return setOfChildren;
}

------------------------------------------------------------
--converting a profile diagram 
helper setChildrenForProfileDiagram (in contained:OrderedSet(di2::DiagramElement)) : OrderedSet(notation::Node)
{
	var setOfChildren:OrderedSet(notation::Node); 
	var child:notation::Node;																
	contained ->forEach (node|node.oclIsTypeOf(di2::GraphNode)) {
			child := node.oclAsType(di2::GraphNode).map profileDiagNode2Shape();
			setOfChildren += child;
	};								

	return setOfChildren;
}

--converting a state diagram 
helper setChildrenForStateDiagram (in contained:OrderedSet(di2::DiagramElement)) : OrderedSet(notation::Node)
{
	var setOfChildren:OrderedSet(notation::Node); 
	var child:notation::Node;																
	contained ->forEach (node|node.oclIsTypeOf(di2::GraphNode)) {
			child := node.oclAsType(di2::GraphNode).map stateDiagNode2Shape();
			setOfChildren += child;
	};								

	return setOfChildren;
}

helper setEdgesForClassAndProfileDiagram (in contained : OrderedSet(di2::DiagramElement)) : OrderedSet (notation::Edge)
{
	var setofEdges : OrderedSet(notation::Edge); 
	var edge : notation::Edge;																
	contained->forEach (node|node.oclIsTypeOf(di2::GraphEdge)) {
			edge := node.oclAsType(di2::GraphEdge).map classAndProfileDiagEdge2Edge();
			setofEdges += edge;
	};
	contained->forEach (composite|composite.oclIsTypeOf(di2::GraphNode)) {
			composite.oclAsType(di2::GraphNode).contained->forEach (elem|elem.oclIsTypeOf(di2::GraphEdge)) {
				edge := elem.oclAsType(di2::GraphEdge).map classAndProfileDiagEdge2Edge();
				setofEdges += edge;
			};
			composite.oclAsType(di2::GraphNode).contained->forEach (prop|prop.oclIsTypeOf(di2::GraphNode)) {
				prop.oclAsType(di2::GraphNode).contained->forEach (connect|connect.oclIsTypeOf(di2::GraphEdge)) {
					edge := connect.oclAsType(di2::GraphEdge).map classAndProfileDiagEdge2Edge();
					setofEdges += edge;
				};					
			};				
	};
	
	return setofEdges;
}

helper setEdgesForCompositeDiagram (in contained : OrderedSet(di2::DiagramElement)) : OrderedSet (notation::Edge)
{
	var setofEdges : OrderedSet(notation::Edge); 
	var edge : notation::Edge;																
	contained->forEach (node|node.oclIsTypeOf(di2::GraphEdge)) {
			edge := node.oclAsType(di2::GraphEdge).map compositeDiagEdge2Edge();
			setofEdges += edge;
	};
	contained->forEach (composite|composite.oclIsTypeOf(di2::GraphNode)) {
			composite.oclAsType(di2::GraphNode).contained->forEach (elem|elem.oclIsTypeOf(di2::GraphEdge)) {
				edge := elem.oclAsType(di2::GraphEdge).map compositeDiagEdge2Edge();
				setofEdges += edge;
			};
			composite.oclAsType(di2::GraphNode).contained->forEach (prop|prop.oclIsTypeOf(di2::GraphNode)) {
				prop.oclAsType(di2::GraphNode).contained->forEach (connect|connect.oclIsTypeOf(di2::GraphEdge)) {
					edge := connect.oclAsType(di2::GraphEdge).map compositeDiagEdge2Edge();
					setofEdges += edge;
				};					
			};				
	};
	
	return setofEdges;
}

helper setEdgesForStateDiagram (in contained : OrderedSet(di2::DiagramElement)) : OrderedSet (notation::Edge)
{
	var setofEdges : OrderedSet(notation::Edge); 
	var edge : notation::Edge;																
	contained->forEach (node|node.oclIsTypeOf(di2::GraphEdge)) {
			edge := node.oclAsType(di2::GraphEdge).map stateDiagEdge2Edge();
			setofEdges += edge;
	};
	contained->forEach (composite|composite.oclIsTypeOf(di2::GraphNode)) {
			composite.oclAsType(di2::GraphNode).contained->forEach (elem|elem.oclIsTypeOf(di2::GraphEdge)) {
				edge := elem.oclAsType(di2::GraphEdge).map stateDiagEdge2Edge();
				setofEdges += edge;
			};
			composite.oclAsType(di2::GraphNode).contained->forEach (prop|prop.oclIsTypeOf(di2::GraphNode)) {
				prop.oclAsType(di2::GraphNode).contained->forEach (connect|connect.oclIsTypeOf(di2::GraphEdge)) {
					edge := connect.oclAsType(di2::GraphEdge).map stateDiagEdge2Edge();
					setofEdges += edge;
				};					
			};				
	};
	
	return setofEdges;
}

--------------------------------
--Helpers related to a diagram
helper setStylesForDiagram() : OrderedSet (notation::Style)
{
	--<styles xmi:type="notation:DiagramStyle""/>

	var setofStyles : OrderedSet(notation::Style);
	var style := object notation::DiagramStyle {
		--the id is set automatically
	};

	setofStyles := OrderedSet{style};

	return setofStyles;	
}

Back to the top