svghmi/detachable_pages.ysl2
branchsvghmi
changeset 2941 ef13a4007538
parent 2940 034b6ce4f885
child 2943 304e88bae115
equal deleted inserted replaced
2940:034b6ce4f885 2941:ef13a4007538
     4 // and decide where to cut when removing/attaching
     4 // and decide where to cut when removing/attaching
     5 // pages elements on page switch
     5 // pages elements on page switch
     6 
     6 
     7 const "hmi_pages_descs", "$parsed_widgets/widget[@type = 'Page']";
     7 const "hmi_pages_descs", "$parsed_widgets/widget[@type = 'Page']";
     8 const "hmi_pages", "$hmi_elements[@id = $hmi_pages_descs/@id]";
     8 const "hmi_pages", "$hmi_elements[@id = $hmi_pages_descs/@id]";
     9 
       
    10 const "keypads_descs", "$parsed_widgets/widget[@type = 'Keypad']";
       
    11 const "keypads", "$hmi_elements[@id = $keypads_descs/@id]";
       
    12 
     9 
    13 const "default_page" choose {
    10 const "default_page" choose {
    14     when "count($hmi_pages) > 1" {
    11     when "count($hmi_pages) > 1" {
    15         choose {
    12         choose {
    16             when "$hmi_pages_descs/arg[1]/@value = 'Home'" > Home
    13             when "$hmi_pages_descs/arg[1]/@value = 'Home'" > Home
    22     when "count($hmi_pages) = 0" {
    19     when "count($hmi_pages) = 0" {
    23         error "No page defined!";
    20         error "No page defined!";
    24     }
    21     }
    25     otherwise > «func:widget($hmi_pages/@id)/arg[1]/@value»
    22     otherwise > «func:widget($hmi_pages/@id)/arg[1]/@value»
    26 }
    23 }
       
    24 
       
    25 emit "preamble:default-page" {
       
    26     |
       
    27     | var default_page = "«$default_page»";
       
    28 }
       
    29 
       
    30 const "keypads_descs", "$parsed_widgets/widget[@type = 'Keypad']";
       
    31 const "keypads", "$hmi_elements[@id = $keypads_descs/@id]";
    27 
    32 
    28 // returns all directly or indirectly refered elements
    33 // returns all directly or indirectly refered elements
    29 def "func:refered_elements" {
    34 def "func:refered_elements" {
    30     param "elems";
    35     param "elems";
    31     const "descend", "$elems/descendant-or-self::svg:*";
    36     const "descend", "$elems/descendant-or-self::svg:*";
    92 
    97 
    93 // Avoid nested detachables
    98 // Avoid nested detachables
    94 const "_detachable_elements", "func:detachable_elements($hmi_pages | $keypads)";
    99 const "_detachable_elements", "func:detachable_elements($hmi_pages | $keypads)";
    95 const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]";
   100 const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]";
    96 
   101 
       
   102 emit "epilogue:detachable-elements" {
       
   103     |
       
   104     | var detachable_elements = {
       
   105     foreach "$detachable_elements"{
       
   106     |     "«@id»":[id("«@id»"), id("«../@id»")]`if "position()!=last()" > ,`
       
   107     }
       
   108     | }
       
   109 }
       
   110 
    97 const "forEach_widgets_ids", "$parsed_widgets/widget[@type = 'ForEach']/@id";
   111 const "forEach_widgets_ids", "$parsed_widgets/widget[@type = 'ForEach']/@id";
    98 const "forEach_widgets", "$hmi_elements[@id = $forEach_widgets_ids]";
   112 const "forEach_widgets", "$hmi_elements[@id = $forEach_widgets_ids]";
    99 const "in_forEach_widget_ids", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]/@id";
   113 const "in_forEach_widget_ids", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]/@id";
   100 
   114 
   101 template "svg:*", mode="page_desc" {
   115 template "svg:*", mode="page_desc" {
   152         with "page_desc", "$desc";
   166         with "page_desc", "$desc";
   153     }
   167     }
   154     |   }`if "position()!=last()" > ,`
   168     |   }`if "position()!=last()" > ,`
   155 }
   169 }
   156 
   170 
       
   171 emit "epilogue:page-desc" {
       
   172     |
       
   173     | var page_desc = {
       
   174     apply "$hmi_pages", mode="page_desc";
       
   175     | }
       
   176 }
       
   177 
   157 template "*", mode="per_page_widget_template";
   178 template "*", mode="per_page_widget_template";
   158 
   179 
   159 
   180 
   160 emit "debug:detachable-pages" {
   181 emit "debug:detachable-pages" {
   161 
   182     |
   162     | DETACHABLES:
   183     | DETACHABLES:
   163     foreach "$detachable_elements"{
   184     foreach "$detachable_elements"{
   164         |  «@id»
   185         |  «@id»
   165     }
   186     }
   166     | In Foreach:
   187     | In Foreach: