Skip to main content
summaryrefslogtreecommitdiffstats
blob: 83f1850a146677b6f0e397cf3611d616a0d84706 (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

--Author Manel Fredj-CEA LIST

import ElementType;
import Converter.Utils.ConverterLibs;	// for getElement

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';


transformation Transfo(in src : di2, out target1 : notation, out target2:di);


-------------------------------------------------------------------------------------------------------------------------
----------------------------------------         QUERIES for notation             ---------------------------------------
-------------------------------------------------------------------------------------------------------------------------

// in Java already
--query di2::RGB::RGB2Int() : Integer
--{
-- 	return 0;
-- 	-- TODO: check the conversion form RGB to int
--}


query di2::Diagram::getDiagramtype() : String
{
	--class diagram
	if (self.type = ClassDiagram_P1) then {
		if (self.getElement().oclIsTypeOf(uml::Profile)) then {
			return ProfileDiagram_P2.oclAsType(String);
		}
		else {
			return ClassDiagram_P2.oclAsType(String);
		} endif;
	} endif;
	--composite diagram
	if (self.type = CompositeStructure_P1) then {
		return CompositeStructure_P2.oclAsType(String);
	} endif;
	--activity diagram		
	if (self.type = ActivityDiagram_P1) then {
		return ActivityDiagram_P2.oclAsType(String);
	} endif; --TODO: check for papyrus 1 le type
	--sequence diagram
	if (self.type = SequenceDiagram_P1) then {
		return SequenceDiagram_P2.oclAsType(String);
	} endif;
	--component diagram
	if (self.type = ComponentDiagram_P1) then {
		return ComponentDiagram_P1.oclAsType(String);
	} endif; --TODO: check for papyrus 2 le type
	--state Machine diagram
	if (self.type = StateMachineDiagram_P1) then {
		return StateMachineDiagram_P2;
	} endif;
	--Use case diagram
	if (self.type = UseCaseDiagram_P1) then {
		return UseCaseDiagram_P2;
	} endif;
	--otherwise
	return null;
}

query di2::GraphElement::getDiagramtype() : String {
	var parent : Stdlib::Element := self.container();
	
	if (parent.oclIsTypeOf (di2::Diagram)) then {
		return parent.oclAsType (di2::Diagram).getDiagramtype();
	}
	else {
		if (parent.oclIsTypeOf (di2::GraphElement)) then {
			return parent.oclAsType (di2::GraphElement).getDiagramtype();
		} endif;
	} endif;
	return null;
}

query di2::GraphNode::getOperations() : OrderedSet(ecore::EObject)
{
	return self.getSubElementsOfType("Operation");
}


query di2::GraphNode::getProperties() : OrderedSet(ecore::EObject)
{
	return self.getSubElementsOfType("Property");
}

query di2::GraphNode::getEnumLiterals() : OrderedSet(ecore::EObject)
{
	return self.getSubElementsOfType("EnumerationLiteral");
}

query di2::GraphNode::getSubElementsOfType(type : String) : OrderedSet(ecore::EObject)
{
	var containedSubElements : OrderedSet(ecore::EObject);
	var elem : uml::Element;
	
	self.contained->forEach (node|node.oclIsTypeOf(di2::GraphNode)) {
		
		if (node.oclAsType(di2::GraphNode).contained != null) then
		{
			var contained:OrderedSet(di2::DiagramElement) := node.oclAsType(di2::GraphNode).contained;
			contained->forEach (op|op.oclIsTypeOf(di2::GraphNode)){
				elem := op.oclAsType(di2::GraphNode).semanticModel.oclAsType(di2::Uml1SemanticModelBridge).element;
				if (elem.metaClassName() = type) then {
					containedSubElements += elem.oclAsType(ecore::EObject);
				} endif;								
			};
		} endif;						
	};
	return containedSubElements;
}

query di2::GraphNode::getClassifierTemplateParameter():OrderedSet(ecore::EObject){
	--containedCTPs stands for contained "Classifier Template Parameters"
	var containedCTPs: OrderedSet(ecore::EObject);
	var elem : uml::Element;
	
	self.contained->forEach (node|node.oclIsTypeOf(di2::GraphNode)){
		node.oclAsType(di2::GraphNode).contained->forEach(subnode|subnode.oclIsTypeOf(di2::GraphNode)) {
			elem:=subnode.oclAsType(di2::GraphNode).getElement();
			if (elem.oclIsTypeOf(uml::ClassifierTemplateParameter)) then {
			     containedCTPs += elem.oclAsType(ecore::EObject);
			} endif;
		};
	};

	return containedCTPs;
}

query di2::GraphNode::getSemanticParent(): di2::DiagramElement {

	if (self.getElement().oclIsTypeOf(uml::RedefinableTemplateSignature)) then {
		 return self.semanticParent;
	} endif;
	
	if (self.getElement().oclIsTypeOf(uml::Port))then{
		return self.semanticParent;
	} endif;
	
	return null;
}

query di2::GraphNode::getSubElementsOfPackage() : OrderedSet(di2::GraphNode)
{
	var containedElements : OrderedSet(di2::GraphNode);

	self.contained->forEach (node|node.oclIsTypeOf(di2::GraphNode)) {
		if (node.oclAsType(di2::GraphNode).getElement().oclIsKindOf(uml::Element)) then
		{
			containedElements +=node.oclAsType(di2::GraphNode);			
		} endif;						
	};
	return containedElements;
}

query di2::GraphEdge::getAnchors()
{
	var anchors:OrderedSet (di2::GraphConnector):= self.anchor;
	anchors->forEach (gc) {
		--log("the anchor is " + gc.metaClassName());
	};
}

Back to the top