| -- 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 { |
| check hsv imports HSVTree; -- Should specify the correct package |
| enforce 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 iterates hsvRoot; |
| } |
| } |
| } |
| |
| map HSV2MiddleRoot in hsv2hls { -- Mapping root nodes L to M |
| guard:hsv hsvRoot : HSVNode; |
| check hsvRoot.parent = null; |
| new:middle middleRoot : HSVNode2HLSNode; |
| set middleRoot.hsv := hsvRoot; |
| set middleRoot.name := hsvRoot.name; |
| -- set middleRoot.rgb := hsv2rgb(hsvRoot.hsv); |
| for hsvChild in hsvRoot.children { -- recursive call to visit children |
| call HSV2MiddleRecursion { |
| hsvNode iterates hsvChild; |
| middleParent uses middleRoot; |
| } |
| } |
| call Middle2HLSRoot { -- invoke middle to outset mapping |
| middleNode uses middleRoot; |
| } |
| } |
| |
| map HSV2MiddleRecursion in hsv2hls { -- Mapping child nodes L to M |
| guard:hsv hsvNode : HSVNode; |
| in:middle middleParent : HSVNode2HLSNode; |
| new:middle middleNode : HSVNode2HLSNode; |
| set middleNode.parent := middleParent; |
| set middleNode.hsv := hsvNode; |
| set middleNode.name := hsvNode.name; |
| -- set middleNode.rgb := hsv2rgb(hsvNode.hsv); |
| for hsvChild in hsvNode.children { -- recursive call to visit children |
| call HSV2MiddleRecursion { |
| hsvNode iterates hsvChild; |
| middleParent uses middleNode; |
| } |
| } |
| } |
| |
| map Middle2HLSRoot in hsv2hls { -- Mapping root nodes M to R |
| in:middle middleNode : HSVNode2HLSNode; |
| new:hls hlsNode : HLSNode; |
| set hlsNode.parent := null; |
| set middleNode.hls := hlsNode; |
| set hlsNode.name := middleNode.name; |
| -- set hlsNode.hls := rgb2hls(middleNode.rgb); |
| for middleChild in middleNode.children { -- recursive call to visit children |
| call Middle2HLSRecursion { |
| middleNode iterates middleChild; |
| } |
| } |
| } |
| |
| map Middle2HLSRecursion in hsv2hls { -- Mapping child nodes M to R |
| guard:middle middleNode : HSVNode2HLSNode; |
| new:hls hlsNode : HLSNode; |
| set hlsNode.parent := middleNode.parent.hls; |
| set middleNode.hls := hlsNode; |
| set hlsNode.name := middleNode.name; |
| -- set hlsNode.hls := rgb2hls(middleNode.rgb); |
| for middleChild in middleNode.children { -- recursive call to visit children |
| call Middle2HLSRecursion { |
| middleNode iterates middleChild; |
| } |
| } |
| } |