svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2869 d9eb50c015d1
parent 2868 8d9757191f05
child 2870 634b43d69897
equal deleted inserted replaced
2868:8d9757191f05 2869:d9eb50c015d1
   303             with "parentpath" > «$parentpath»
   303             with "parentpath" > «$parentpath»
   304         }
   304         }
   305     }
   305     }
   306 
   306 
   307 
   307 
       
   308     def "func:is_descendant_path" {
       
   309         param "ancest";
       
   310         param "descend";
       
   311         result "starts-with($descend,$ancest)";
       
   312     }
   308 
   313 
   309     //////////////// Inline SVG
   314     //////////////// Inline SVG
   310 
   315 
   311     // Identity template :
   316     // Identity template :
   312     //  - copy every attributes 
   317     //  - copy every attributes 
   499                     attrib "value" > «.»
   504                     attrib "value" > «.»
   500                 }
   505                 }
   501             }
   506             }
   502             const "paths", "substring-after($description,'@')";
   507             const "paths", "substring-after($description,'@')";
   503             foreach "str:split($paths, '@')" {
   508             foreach "str:split($paths, '@')" {
   504                 path {
   509                 if "string-length(.) > 0" path {
   505                     attrib "value" > «.»
   510                     attrib "value" > «.»
       
   511                     const "path", ".";
       
   512                     const "item", "$indexed_hmitree/*[@hmipath = $path]";
       
   513                     if "count($item) = 1"
       
   514                         attrib "index" > «$item/@index»
   506                 }
   515                 }
   507             }
   516             }
   508         }
   517         }
   509 
   518 
   510         result "exsl:node-set($ast)";
   519         result "exsl:node-set($ast)";
   546             foreach "$widget/arg"
   555             foreach "$widget/arg"
   547         |         "«@value»"`if "position()!=last()" > ,`
   556         |         "«@value»"`if "position()!=last()" > ,`
   548         |     ],
   557         |     ],
   549         |     indexes: [
   558         |     indexes: [
   550             foreach "$widget/path" {
   559             foreach "$widget/path" {
   551                 const "hmipath","@value";
       
   552                 const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]";
       
   553                 choose {
   560                 choose {
   554                     when "count($hmitree_match) = 0" {
   561                     when "not(@index)" {
   555                         warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«$hmipath»" in HMI tree
   562                         warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
   556                     }
   563                     }
   557                     otherwise {
   564                     otherwise {
   558         |             «$hmitree_match/@index»`if "position()!=last()" > ,`
   565         |             «@index»`if "position()!=last()" > ,`
   559                     }
   566                     }
   560                 }
   567                 }
   561             }
   568             }
   562         |     ],
   569         |     ],
   563         |     element: id("«@id»"),
   570         |     element: id("«@id»"),
   591             const "page", ".";
   598             const "page", ".";
   592             const "p", "$geometry[@Id = $page/@id]";
   599             const "p", "$geometry[@Id = $page/@id]";
   593 
   600 
   594             const "page_all_elements", "func:all_related_elements($page)";
   601             const "page_all_elements", "func:all_related_elements($page)";
   595 
   602 
   596             const "all_page_ids","$page_all_elements[@id = $hmi_elements/@id and @id != $page/@id]/@id";
   603             const "all_page_widgets","$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id]";
       
   604 
       
   605             const "page_relative_widgets",
       
   606                 "$all_page_widgets[func:is_descendant_path($desc/path/@value, path/@value)]";
   597 
   607 
   598             // Take closest ancestor in detachable_elements
   608             // Take closest ancestor in detachable_elements
   599             // since nested detachable elements are filtered out
   609             // since nested detachable elements are filtered out
   600             const "required_detachables", 
   610             const "required_detachables", 
   601                 """func:sumarized_elements($page_all_elements)/
   611                 """func:sumarized_elements($page_all_elements)/
   602                    ancestor-or-self::*[@id = $detachable_elements/@id]""";
   612                    ancestor-or-self::*[@id = $detachable_elements/@id]""";
   603 
   613 
   604             |   "«$desc/arg[1]/@value»": {
   614             |   "«$desc/arg[1]/@value»": {
   605             |     widget: hmi_widgets["«@id»"],
   615             |     widget: hmi_widgets["«@id»"],
   606             |     bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
   616             |     bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
   607             |     widgets: [
   617             if "$desc/path/@value" {
   608             foreach "$all_page_ids" {
   618                 if "count($desc/path/@index)=0"
   609             |         hmi_widgets["«.»"]`if "position()!=last()" > ,`
   619                     warning > Page id="«$page/@id»" : No match for path "«$desc/path/@value»" in HMI tree
       
   620             |     page_index: «$desc/path/@index»,
       
   621             }
       
   622             |     relative_widgets: [
       
   623             foreach "$page_relative_widgets" {
       
   624             |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
       
   625             }
       
   626             |     ],
       
   627             |     absolute_widgets: [
       
   628             foreach "$all_page_widgets[not(@id = $page_relative_widgets/@id)]" {
       
   629             |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
   610             }
   630             }
   611             |     ],
   631             |     ],
   612             |     required_detachables: {
   632             |     required_detachables: {
   613             foreach "$required_detachables" {
   633             foreach "$required_detachables" {
   614             |         "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,`
   634             |         "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,`
   822         |     ],
   842         |     ],
   823     }
   843     }
   824     template "widget[@type='Jump']", mode="widget_defs" {
   844     template "widget[@type='Jump']", mode="widget_defs" {
   825         param "hmi_element";
   845         param "hmi_element";
   826         |     on_click: function(evt) {
   846         |     on_click: function(evt) {
   827         |         switch_page(this.args[0]);
   847         |         switch_page(this.args[0], this.indexes[0]);
   828         |     },
   848         |     },
   829         |     init: function() {
   849         |     init: function() {
   830         /* registering event this way doies not "click" through svg:use 
   850         /* registering event this way doies not "click" through svg:use 
   831         |     this.element.onclick = evt => switch_page(this.args[0]);
   851         |     this.element.onclick = evt => switch_page(this.args[0]);
   832         event must be registered by adding attribute to element instead
   852         event must be registered by adding attribute to element instead