Edouard@2885: // detachable_pages.ysl2 edouard@2875: // edouard@2875: // compute what elements are required by pages Edouard@2887: // and decide where to cut when removing/attaching edouard@2875: // pages elements on page switch Edouard@2779: Edouard@2887: const "hmi_pages_descs", "$parsed_widgets/widget[@type = 'Page']"; Edouard@2887: const "hmi_pages", "$hmi_elements[@id = $hmi_pages_descs/@id]"; Edouard@2877: Edouard@2911: const "keypads_descs", "$parsed_widgets/widget[@type = 'Keypad']"; Edouard@2911: const "keypads", "$hmi_elements[@id = $keypads_descs/@id]"; Edouard@2911: Edouard@2877: const "default_page" choose { Edouard@2877: when "count($hmi_pages) > 1" { Edouard@2877: choose { Edouard@2887: when "$hmi_pages_descs/arg[1]/@value = 'Home'" > Home Edouard@2877: otherwise { Edouard@2877: error "No Home page defined!"; Edouard@2877: } Edouard@2877: } Edouard@2877: } Edouard@2877: when "count($hmi_pages) = 0" { Edouard@2877: error "No page defined!"; Edouard@2877: } edouard@2886: otherwise > «func:widget($hmi_pages/@id)/arg[1]/@value» Edouard@2877: } Edouard@2877: edouard@2875: // returns all directly or indirectly refered elements edouard@2875: def "func:refered_elements" { edouard@2875: param "elems"; edouard@2875: const "descend", "$elems/descendant-or-self::svg:*"; edouard@2875: const "clones", "$descend[self::svg:use]"; edouard@2875: const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]"; edouard@2875: choose { edouard@2875: when "$originals" edouard@2875: result "$descend | func:refered_elements($originals)"; edouard@2875: otherwise edouard@2875: result "$descend"; edouard@2875: } edouard@2875: } Edouard@2792: edouard@2875: def "func:all_related_elements" { edouard@2875: param "page"; edouard@2875: const "page_overlapping_geometry", "func:overlapping_geometry($page)"; edouard@2875: const "page_overlapping_elements", "//svg:*[@id = $page_overlapping_geometry/@Id]"; edouard@2875: const "page_sub_elements", "func:refered_elements($page | $page_overlapping_elements)"; edouard@2875: result "$page_sub_elements"; edouard@2875: } Edouard@2808: edouard@2875: def "func:required_elements" { edouard@2875: param "pages"; edouard@2875: choose{ edouard@2875: when "$pages"{ edouard@2875: result """func:all_related_elements($pages[1]) edouard@2875: | func:required_elements($pages[position()!=1])"""; edouard@2875: }otherwise{ edouard@2875: result "/.."; Edouard@2844: } Edouard@2844: } edouard@2875: } Edouard@2844: edouard@2875: const "required_elements", edouard@2875: """//svg:defs/descendant-or-self::svg:* Edouard@2911: | func:required_elements($hmi_pages | $keypads)/ancestor-or-self::svg:*"""; edouard@2873: edouard@2875: const "discardable_elements", "//svg:*[not(@id = $required_elements/@id)]"; Edouard@2844: edouard@2875: def "func:sumarized_elements" { edouard@2875: param "elements"; edouard@2875: const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]"; edouard@2875: const "filled_groups", """$short_list/parent::svg:*[ edouard@2875: not(descendant::*[ edouard@2875: not(self::svg:g) and edouard@2875: not(@id = $discardable_elements/@id) and edouard@2875: not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id) edouard@2875: ])]"""; edouard@2875: const "groups_to_add", "$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]"; edouard@2875: result "$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]"; edouard@2875: } Edouard@2844: edouard@2875: def "func:detachable_elements" { edouard@2875: param "pages"; edouard@2875: choose{ edouard@2875: when "$pages"{ edouard@2875: result """func:sumarized_elements(func:all_related_elements($pages[1])) edouard@2875: | func:detachable_elements($pages[position()!=1])"""; edouard@2875: }otherwise{ edouard@2875: result "/.."; Edouard@2846: } Edouard@2846: } edouard@2875: } Edouard@2846: edouard@2875: // Avoid nested detachables Edouard@2911: const "_detachable_elements", "func:detachable_elements($hmi_pages | $keypads)"; edouard@2875: const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"; Edouard@2846: Edouard@2888: const "forEach_widgets_ids", "$parsed_widgets/widget[@type = 'ForEach']/@id"; Edouard@2888: const "forEach_widgets", "$hmi_elements[@id = $forEach_widgets_ids]"; Edouard@2888: const "in_forEach_widget_ids", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]/@id"; Edouard@2888: Edouard@2877: template "svg:*", mode="page_desc" { edouard@2886: const "desc", "func:widget(@id)"; Edouard@2877: const "page", "."; Edouard@2877: const "p", "$geometry[@Id = $page/@id]"; Edouard@2877: Edouard@2877: const "page_all_elements", "func:all_related_elements($page)"; Edouard@2877: Edouard@2901: const "all_page_widgets","$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id]"; Edouard@2901: const "page_managed_widgets","$all_page_widgets[not(@id=$in_forEach_widget_ids)]"; Edouard@2877: const "page_relative_widgets", Edouard@2901: "$page_managed_widgets[func:is_descendant_path(func:widget(@id)/path/@value, $desc/path/@value)]"; Edouard@2877: Edouard@2877: // Take closest ancestor in detachable_elements Edouard@2877: // since nested detachable elements are filtered out Edouard@2877: const "required_detachables", Edouard@2877: """func:sumarized_elements($page_all_elements)/ Edouard@2877: ancestor-or-self::*[@id = $detachable_elements/@id]"""; Edouard@2877: Edouard@2877: | "«$desc/arg[1]/@value»": { Edouard@2877: | widget: hmi_widgets["«@id»"], Edouard@2877: | bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»], Edouard@2877: if "$desc/path/@value" { Edouard@2877: if "count($desc/path/@index)=0" Edouard@2877: warning > Page id="«$page/@id»" : No match for path "«$desc/path/@value»" in HMI tree Edouard@2877: | page_index: «$desc/path/@index», Edouard@2877: } Edouard@2877: | relative_widgets: [ Edouard@2877: foreach "$page_relative_widgets" { Edouard@2877: | hmi_widgets["«@id»"]`if "position()!=last()" > ,` Edouard@2877: } Edouard@2877: | ], Edouard@2877: | absolute_widgets: [ Edouard@2901: foreach "$page_managed_widgets[not(@id = $page_relative_widgets/@id)]" { Edouard@2877: | hmi_widgets["«@id»"]`if "position()!=last()" > ,` Edouard@2877: } Edouard@2877: | ], Edouard@2903: | jumps: [ Edouard@2903: foreach "$parsed_widgets/widget[@id = $all_page_widgets/@id and @type='Jump']" { Edouard@2903: const "_id","@id"; Edouard@2903: const "opts" call "jump_widget_activity" with "hmi_element", "$hmi_elements[@id=$_id]"; Edouard@2903: if "string-length($opts)>0" Edouard@2903: | hmi_widgets["«@id»"]`if "position()!=last()" > ,` Edouard@2903: } Edouard@2903: | ], Edouard@2877: | required_detachables: { Edouard@2877: foreach "$required_detachables" { Edouard@2877: | "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,` Edouard@2877: } Edouard@2877: | } Edouard@2903: /* TODO generate some code for init() instead */ Edouard@2901: apply "$parsed_widgets/widget[@id = $all_page_widgets/@id]", mode="per_page_widget_template"{ Edouard@2901: with "page_desc", "$desc"; Edouard@2901: } Edouard@2877: | }`if "position()!=last()" > ,` Edouard@2877: } Edouard@2877: Edouard@2901: template "*", mode="per_page_widget_template"; Edouard@2901: edouard@2904: edouard@2904: reflect:detachable_pages; edouard@2904: edouard@2904: template "reflect:detachable-pages", mode="debug" { edouard@2904: Edouard@2888: | DETACHABLES: Edouard@2876: foreach "$detachable_elements"{ Edouard@2876: | «@id» Edouard@2876: } Edouard@2888: | In Foreach: Edouard@2888: foreach "$in_forEach_widget_ids"{ Edouard@2888: | «.» Edouard@2888: } Edouard@2876: }