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