svghmi/widget_foreach.ysl2
branchsvghmi
changeset 2894 4cf9ad35e6d0
parent 2893 d57a12b8f5db
child 2895 89c02b452717
equal deleted inserted replaced
2893:d57a12b8f5db 2894:4cf9ad35e6d0
     1 
     1 
     2 template "widget[@type='ForEach']", mode="widget_defs" {
     2 template "widget[@type='ForEach']", mode="widget_defs" {
     3     param "hmi_element";
     3     param "hmi_element";
     4     const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]";
     4     const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]";
     5     |     frequency: 2,
     5 
     6     |     dispatch: function(value) {
     6     const "class","arg[1]/@value";
     7     |                     // do something
     7 
     8     |     },
     8     const "base_path","path/@value";
       
     9     const "hmi_index_base", "$indexed_hmitree/*[@hmipath = $base_path]";
       
    10     const "hmi_tree_base", "$hmitree/descendant-or-self::*[@path = $hmi_index_base/@path]";
       
    11     const "hmi_tree_items", "$hmi_tree_base/*[@class = $class]";
       
    12     const "hmi_index_items", "$indexed_hmitree/*[@path = $hmi_tree_items/@path]"; 
       
    13     const "items_paths", "$hmi_index_items/@hmipath"; 
     9     |     index_pool: [
    14     |     index_pool: [
       
    15     foreach "$hmi_index_items" {
       
    16     |       «@index»`if "position()!=last()" > ,`
       
    17     }
    10     |     ],
    18     |     ],
    11     |     buttons: [
    19     |     buttons: [
    12     const "class","arg[1]/@value";
       
    13     const "prefix","concat($class,':')";
    20     const "prefix","concat($class,':')";
    14     const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')";
    21     const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')";
    15     foreach "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]" {
    22     foreach "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]" {
    16     |         ["«substring-after(@inkscape:label, concat(arg[1]/@value, ':'))»", id("«@id»")]`if "position()!=last()" > ,`
    23     |         ["«substring-after(@inkscape:label, concat(arg[1]/@value, ':'))»", id("«@id»")]`if "position()!=last()" > ,`
    17     }
    24     }
    19     |     init: function() {
    26     |     init: function() {
    20     |         /* TODO elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");*/
    27     |         /* TODO elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");*/
    21     |     },
    28     |     },
    22 
    29 
    23     |     items: [
    30     |     items: [
    24     const "base_path","path/@value";
       
    25     const "items_regex","concat('^',$prefix,'[0-9]+')";
    31     const "items_regex","concat('^',$prefix,'[0-9]+')";
    26     const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]";
    32     const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]";
    27     foreach "$unordered_items" {
    33     foreach "$unordered_items" {
    28         const "elt_label","concat($prefix, string(position()))"; 
    34         const "elt_label","concat($prefix, string(position()))"; 
    29         const "elt","$unordered_items[@inkscape:label = $elt_label]";
    35         const "elt","$unordered_items[@inkscape:label = $elt_label]";
    30         
    36         const "pos","position()";
    31     |   /* `apply "func:get_hmi_tree_elt($base_path)", mode="testtree";` */
    37         const "item_path", "$items_paths[$pos]";
    32     |       [ /* «$elt_label» */
    38     |       [ /* item="«$elt_label»" path="«$item_path»" */
    33         if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id»
    39         if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id»
    34         foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
    40         foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
       
    41             if "not(func:is_descendant_path(func:widget(@id)/path/@value, $item_path))"
       
    42                 error > Widget id="«@id»" label="«@inkscape:label»" is having wrong path. Accroding to ForEach widget ancestor id="«$hmi_element/@id»", path should be descendant of «$item_path».
    35     |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
    43     |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
    36         }
    44         }
    37     |       ]`if "position()!=last()" > ,`
    45     |       ]`if "position()!=last()" > ,`
    38     }
    46     }
    39     |     ],
    47     |     ],
    40 }
    48 }
    41 
    49 
    42 template "widget[@type='ForEach']", mode="widget_subscribe"{
    50 template "widget[@type='ForEach']", mode="widget_subscribe"{
    43     // param "hmi_element";
    51     // param "hmi_element";
    44     |     sub: function(off){
    52     |     sub: function(off){
    45     |         subscribe.call(this,off);
    53     |         /*subscribe.call(this,off);*/
    46         /* TODO */
    54         /* TODO */
    47     |     },
    55     |     },
    48 
    56 
    49     |     unsub: function(){
    57     |     unsub: function(){
    50     |         unsubscribe.call(this);
    58     |         /*unsubscribe.call(this);*/
    51         /* TODO */
    59         /* TODO */
    52     |     },
    60     |     },
    53 }
    61 }