Skip to main content
summaryrefslogtreecommitdiffstats
blob: 046a85c23baa254054e1cdd013b0e9b6410dc9de (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
--Author Manel Fredj-CEA LIST

library HelpersEdge;
import GeneralMappingsandHelpers;
import NotationQueries;
import ClassAndProfileDiagEdgeVisualIDs;

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

--class and profile have identical visual IDs for relationships
--Since the profile diagram has been developed starting with a class diagram. This
--is not the case for other diagram types
mapping di2::GraphEdge::classAndProfileDiagEdge2Edge() : notation::Connector inherits di2::GraphEdge::edge2Connector
{
	--setting the type and children
	if (self.getElement() != null) then {
	
		if (self.getElement().isGeneralization()) then {
	 		type := VisualId_Edge_Generalization;
	 		--adding children
			children := setChildrenForGeneralization();
		} endif;
		if (self.getElement().oclIsTypeOf(uml::Extension)) then {
	 		type := VisualId_Edge_Extension;
	 		--adding children
			// children := setChildrenForExtension();
		} else {
			// extension is also an association, use "else" (else if is unfortunatley not supported in QVTO)
			if (self.getElement().isAssociation()) then {
				type := VisualId_Edge_Association;
				children := setChildrenForAssociation();
			} endif;
		} endif;
		if (self.getElement().oclIsTypeOf(uml::PackageImport)) then {
			type := VisualId_Edge_PackageImport;
			children := setChildrenForPackageImport();
		} endif;
		if (self.getElement().isDependency()) then {
			type := VisualId_Edge_Dependency;
		 	--adding children
			children := setChildrenForDependency();
		} endif;
		if (self.getElement().isRealization()) then {
		 	type := VisualId_Edge_Realization;
		 	--adding children
			children := setChildrenForRealization();
		} endif;
	}
	else {
		--it is  a link
		var diagType : String = self.getDiagramtype ();
		if (diagType = ClassDiagram_P2) then {
			type := VisualId_CEdge_Link;
		}
		else {
			if (diagType = ProfileDiagram_P2) then {
				type := VisualId_PEdge_Link;
			} endif;
		} endif;
		element := null;
	} endif;
	
	--setting the source and target Anchors
	var anchors : OrderedSet (di2::GraphConnector) := self.anchor;
	anchors->forEach (gc) {
		--log("the anchor is "+ gc.graphElement.repr());
		gc.graphElement;
	};			
	source := anchors->first().graphElement.oclAsType(di2::GraphNode).late resolveone(notation::Shape);
	target := anchors->last().graphElement.oclAsType(di2::GraphNode).late resolveone(notation::Shape);
	--adding style
	styles := setStyleForEdge();

	--adding element: already done in View

	--adding the bend points
	bendpoints := setBendpointsForEdge();

	--adding the source and target Anchor	
	sourceAnchor := setSourceAnchor();
	targetAnchor := setTargetAnchor();	
}
    
    
--Helpers related to an Edge
--------------------------------


--generic helper for an edge with two children
--takes as input the visual ids of the the two children

helper setChildrenForEdge2Children(in VisualId1: String, in VisualId2: String): OrderedSet(notation::Node)
{
	var child1 := object notation::DecorationNode {
		--the id is set automatically
		type := VisualId1;
		layoutConstraint := object notation::Location {
			y := 40;
		};
	};
	
	--second child	
	var child2 :=object notation::DecorationNode {
		--the id is set automatically
		type := VisualId2;
		layoutConstraint := object notation::Location {
			y := 60;
		};
	};
	
	return OrderedSet {child1,child2};
}

helper setChildrenForRealization(): OrderedSet(notation::Node)
{    
	return setChildrenForEdge2Children(VisualId_Edge_Realization_DecoNode1, VisualId_Edge_Realization_DecoNode2);
	
}

helper setChildrenForDependency(): OrderedSet(notation::Node)
{    
	  --<children xmi:type="notation:DecorationNode" type="6026">
      --  <layoutConstraint xmi:type="notation:Location" y="40"/>
     -- </children>
     -- <children xmi:type="notation:DecorationNode" type="6027">
     --   <layoutConstraint xmi:type="notation:Location" y="60"/>
     -- </children>
 	return setChildrenForEdge2Children(VisualId_Edge_Dependency_DecoNode1, VisualId_Edge_Dependency_DecoNode2);
	
}

helper setChildrenForGeneralization(): OrderedSet(notation::Node)
{    
	 --<children xmi:type="notation:DecorationNode"  type="6007">
      --  <layoutConstraint xmi:type="notation:Location"  y="40"/>
     --</children>
 
	var child1 := object notation::DecorationNode {
		--the id is set automatically
		--type := VisualId_DecoNodeGeneralization;
		type := VisualId_Edge_Generalization_DecoNode;
		layoutConstraint := object notation::Location {
			y := 40;
		};
	};
	
	return OrderedSet {child1};
}

    
helper setChildrenForAssociation(): OrderedSet(notation::Node)
{
	----------------------------------------------------------------------
	--under an Edge "association"
	-----------------------------------------------------------------------
	--In the case that we have an association we will have:
		--1 edge with a xmi:type:="notation:Connector", a geneerated Id, type= "4001", a target and a source that includes:
			-- 6 "children" typed with decoration nodes 
			-- 1 "styles
			-- 1 element
			-- 1 bendpoints
			-- 1 sourceAnchor
			-- 1 targetAnchor
	-----------------------------------------------------------------------	

	--first child	
	var child1 := object notation::DecorationNode {
		--the id is set automatically
		type := VisualId_Edge_Association_DecoNode1;
		layoutConstraint := object notation::Location {
			y := -20;
		};
	};

	--second child	
	var child2 :=object notation::DecorationNode {
		--association label
		type := VisualId_Edge_Association_DecoNode2;
		layoutConstraint := object notation::Location {
			y := 20;
		};
		// make label of association itself (not its endpoints) non visible by default
		visible := false;
	};
	
	--third child
	var child3 := object  notation::DecorationNode {
		--label first association end
		type := VisualId_Edge_Association_DecoNode3;
		layoutConstraint := object notation::Location {
			y := -20;
		};
		eAnnotations += noTypeEAnnotation();
	};

	--fourth child	
	var child4 := object  notation::DecorationNode {
		--label 2nd association end
		type := VisualId_Edge_Association_DecoNode4;
		layoutConstraint := object notation::Location {
			y := 20;
		};
		eAnnotations += noTypeEAnnotation();
	};
	
	--fifth child	
	var child5 := object notation::DecorationNode {
		--multiplicity first association end
		type := VisualId_Edge_Association_DecoNode5;
		visible := false;
		--layoutConstraint := object notation::Location{
			--y := 20;
			--x := 20;
		--};
	};
						
	--sixth child	
	var child6 := object notation::DecorationNode {
		--the id is set automatically
		--multiplicity 2nd association end
		type := VisualId_Edge_Association_DecoNode6;
		visible := false;
		--layoutConstraint := object notation::Location {
			--y := -20;
			--x := -20;
		--};
	};					
						
	--add the set of children to the node
	return OrderedSet {
		child1, child2, child3, child4, child5, child6
	};
}


helper setStyleForEdge() : OrderedSet(notation::Style)
{
	--<styles xmi:type="notation:FontStyle" fontName="Sans Serif"/>
	var style := object notation::FontStyle {
		--the id is set automatically
		--fontName="Sans Serif";
	};

	return OrderedSet{style};
}

helper setSourceAnchor() : notation::Anchor
{
	return object notation::IdentityAnchor { };
}


helper setTargetAnchor():notation::Anchor
{
	return object notation::IdentityAnchor { };
}


helper setBendpointsForEdge():notation::RelativeBendpoints
{
	--<bendpoints xmi:type="notation:RelativeBendpoints" points="[-7, -2, 323, 58]$[-282, -65, 48, -5]"/>
	// var pts : notation::RelativeBendpointList;
 	// var bendpoints:=object notation::RelativeBendpoints { };
	var bendpoints := createBendpoints().oclAsType (notation::RelativeBendpoints);
	
	return bendpoints;
}

helper setChildrenForPackageImport(): OrderedSet(notation::Node)
{    
	var child1 := object notation::DecorationNode {
		--the id is set automatically
		--type := VisualId_DecoNodeGeneralization;
		type := VisualId_Edge_PackageImport_DecoNode;
	};
	
	return OrderedSet {child1};
}

Back to the top