| -- modeltype HSVTree: '../../model/HSVTree.ecore'; -- modeltype instead of import to match QVTo |
| import 'HSVTree.ecore'::HSVTree; -- modeltype instead of import to match QVTo |
| import 'HSLTree.ecore'::HSLTree; -- No name because we defined the package |
| import hsv2hsl_0 : 'HSV2HSL.ecore'::HSV2HSL; -- A name is useful to define an alias for the same metamodel |
| |
| -- library '../../myOclHelper.ocl'; -- Import a complete OCL with helpers |
| |
| transformation hsv2hsl { |
| check hsv imports HSVTree; -- Should specify the correct package |
| enforce hsl imports HSLTree; -- |
| -- hsl imports "strict" HSLTree; -- |
| -- hsl imports HSLTree{strict}; -- The model has to strictly conform to the HSLTree mm, without strict the model can have classes that match the name but not completely conform to the mm |
| middle imports HSV2HSL; |
| } |
| |
| query hsv2hsl::hsl2rgb(color : HSLTree::HSL) : HSV2HSL::RGB; |
| query hsv2hsl::hsv2rgb(color : HSVTree::HSV) : HSV2HSL::RGB; |
| query hsv2hsl::rgb2hsl(color : HSV2HSL::RGB) : HSLTree::HSL; |
| query hsv2hsl::rgb2hsv(color : HSV2HSL::RGB) : HSVTree::HSV; |
| |
| map __root__ in hsv2hsl { |
| append nodes : HSVTree::HSVNode; |
| for hsvRoot : HSVTree::HSVNode in nodes { |
| call HSV2MiddleRoot { |
| hsvRoot iterates hsvRoot; |
| } |
| } |
| } |
| |
| map HSV2MiddleRoot in hsv2hsl { -- Mapping root nodes L to M |
| guard:hsv hsvRoot : HSVNode; |
| check hsvRoot.parent = null; |
| new:middle middleRoot : HSVNode2HSLNode; |
| 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 Middle2HSLRoot { -- invoke middle to outset mapping |
| middleNode uses middleRoot; |
| } |
| } |
| |
| map HSV2MiddleRecursion in hsv2hsl { -- Mapping child nodes L to M |
| guard:hsv hsvNode : HSVNode; |
| in:middle middleParent : HSVNode2HSLNode; |
| new:middle middleNode : HSVNode2HSLNode; |
| 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 Middle2HSLRoot in hsv2hsl { -- Mapping root nodes M to R |
| in:middle middleNode : HSVNode2HSLNode; |
| new:hsl hslNode : HSLNode; |
| set hslNode.parent := null; |
| set middleNode.hsl := hslNode; |
| set hslNode.name := middleNode.name; |
| -- set hslNode.hsl := rgb2hsl(middleNode.rgb); |
| for middleChild in middleNode.children { -- recursive call to visit children |
| call Middle2HSLRecursion { |
| middleNode iterates middleChild; |
| } |
| } |
| } |
| |
| map Middle2HSLRecursion in hsv2hsl { -- Mapping child nodes M to R |
| guard:middle middleNode : HSVNode2HSLNode; |
| new:hsl hslNode : HSLNode; |
| set hslNode.parent := middleNode.parent.hsl; |
| set middleNode.hsl := hslNode; |
| set hslNode.name := middleNode.name; |
| -- set hslNode.hsl := rgb2hsl(middleNode.rgb); |
| for middleChild in middleNode.children { -- recursive call to visit children |
| call Middle2HSLRecursion { |
| middleNode iterates middleChild; |
| } |
| } |
| } |