Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 22de9f8446cd8ea9ee97ab7d7d2de6e8e728b593 (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
-- modeltype HSVTree: '../../model/HSVTree.ecore'; -- modeltype instead of import to match QVTo
import 'HSVTree.ecore'::HSVTree; -- modeltype instead of import to match QVTo
import 'HLSTree.ecore'::HLSTree;  -- No name because we defined the package
import hsv2hls_0 : 'HSV2HLS.ecore'::HSV2HLS; -- A name is useful to define an alias for the same metamodel

-- library '../../myOclHelper.ocl'; -- Import a complete OCL with helpers

transformation hsv2hls {
	hsv imports HSVTree;  -- Should specify the correct package
	hls imports HLSTree;  --
	-- hls imports "strict" HLSTree;  -- 
	-- hls imports HLSTree{strict};   -- The model has to strictly conform to the HLSTree mm, without strict the model can have classes that match the name but not completely conform to the mm  
	middle imports HSV2HLS;
}

query hsv2hls::hls2rgb(color : HLSTree::HLS) : HSV2HLS::RGB;
query hsv2hls::hsv2rgb(color : HSVTree::HSV) : HSV2HLS::RGB;
query hsv2hls::rgb2hls(color : HSV2HLS::RGB) : HLSTree::HLS;
query hsv2hls::rgb2hsv(color : HSV2HLS::RGB) : HSVTree::HSV;

map __root__ in hsv2hls {
    for hsvRoot : HSVTree::HSVNode in HSVTree::HSVNode.allInstances() {
--    for hsvRoot : HSVTree::HSVNode in hsv.objectsOfKind(HSVTree::HSVNode) {
        call HSV2MiddleRoot {
            hsvRoot := hsvRoot;
        } 
    } 
}

map HSV2MiddleRoot in hsv2hls {	-- Mapping root nodes L to M
	check hsv(hsvRoot : HSVNode) { } 
	enforce middle() {
		realize middleRoot : HSVNode2HLSNode
	}
	where(
		hsvRoot.parent = null;
	) {
		middleRoot.hsv := hsvRoot;
		middleRoot.name := hsvRoot.name;
		--middleRoot.rgb := hsv2rgb(hsvRoot.hsv);
	}
	for hsvChild in hsvRoot.children {		-- recursive call to visit children
		call HSV2MiddleRecursion {
			hsvNode := hsvChild;
			middleParent := middleRoot;
		}
	}
	call Middle2HLSRoot {		-- invoke middle to output mapping
		middleNode := middleRoot;
	}
}

map HSV2MiddleRecursion in hsv2hls { -- Mapping child nodes L to M
	check hsv(hsvNode : HSVNode) {}
	enforce middle(middleParent : HSVNode2HLSNode) {
		realize middleNode : HSVNode2HLSNode
	}
	where() {
		middleNode.parent := middleParent;
		middleNode.hsv := hsvNode;
		middleNode.name := hsvNode.name;
		--middleNode.rgb := hsv2rgb(hsvNode.hsv);
	}
	for hsvChild in hsvNode.children {		-- recursive call to visit children
		call HSV2MiddleRecursion {
			hsvNode := hsvChild;
			middleParent := middleNode;
		}
	}
}

map Middle2HLSRoot in hsv2hls { -- Mapping root nodes M to R
	check middle(middleNode : HSVNode2HLSNode) {}
	enforce hls() {
		realize hlsNode : HLSNode
	}
	where() {
		hlsNode.parent := null;
		middleNode.hls := hlsNode;
		hlsNode.name := middleNode.name;
		--hlsNode.hls := rgb2hls(middleNode.rgb);
	}
	for middleChild in middleNode.children {		-- recursive call to visit children
		call Middle2HLSRecursion {
			middleNode := middleChild;
		}
	}
}

map Middle2HLSRecursion in hsv2hls { -- Mapping child nodes M to R
	check middle(middleNode : HSVNode2HLSNode) {}
	enforce hls() {
		realize hlsNode : HLSNode
	}
	where() {
		hlsNode.parent := middleNode.parent.hls;
		middleNode.hls := hlsNode;
		hlsNode.name := middleNode.name;
		--hlsNode.hls := rgb2hls(middleNode.rgb);
	}
	for middleChild in middleNode.children {		-- recursive call to visit children
		call Middle2HLSRecursion {
			middleNode := middleChild;
		}
	}
}

Back to the top