# HG changeset patch
# User Edouard Tisserant
# Date 1584972816 -3600
# Node ID d57a12b8f5dbc64fa5e59dbd0d8fc193b2d3adff
# Parent 27dd409fba1dc1d5ca5a80a0e561991647acf62c
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
diff -r 27dd409fba1d -r d57a12b8f5db svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Mon Mar 23 10:16:38 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Mon Mar 23 15:13:36 2020 +0100
@@ -74,6 +74,49 @@
+
+
+
+
+ get_hmi_tree_elt
+
+
+
+
+ Given path "
+
+ " should start with a "/"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -600,9 +643,9 @@
- /*
-
- */
+ /*
+
+ */
,
@@ -711,36 +754,62 @@
},
+ index_pool: [
+
+ ],
+
+ buttons: [
+
+
+
+
+
+ ["
+
+ ", id("
+
+ ")]
+
+ ,
+
+
+
+
+ ],
+
init: function() {
-
- id("
-
- ").addEventListener(
-
- "click",
-
- evt => {let new_val = "
-
- ");
-
- // do something with new_val
-
- });
-
-
+ /* TODO elt.setAttribute("onclick", "hmi_widgets['
+
+ '].on_click(evt)");*/
+
},
- widgets: [
-
-
-
+ items: [
+
+
+
+
+
+
+
+ /*
+
+ */
+
[ /*
-
+
*/
-
-
+
+
+ Missing item labeled
+
+ in ForEach widget
+
+
+
+
hmi_widgets["
"]
@@ -763,13 +832,13 @@
sub: function(off){
- subscribe.call(this,off)
+ subscribe.call(this,off);
},
unsub: function(){
- unsubscribe.call(this)
+ unsubscribe.call(this);
},
diff -r 27dd409fba1d -r d57a12b8f5db svghmi/hmi_tree.ysl2
--- a/svghmi/hmi_tree.ysl2 Mon Mar 23 10:16:38 2020 +0100
+++ b/svghmi/hmi_tree.ysl2 Mon Mar 23 15:13:36 2020 +0100
@@ -52,14 +52,44 @@
}
}
+def "func:get_hmi_tree_elt" {
+ param "path";
+ param "root", "$hmitree";
+ message > get_hmi_tree_elt «$path»
+ if "not(starts-with($path, '/'))" error > Given path "«$path»" should start with a "/"
+ const "stripped", "substring($path, 2)";
+ const "token" choose {
+ when "contains($stripped, '/')" value "substring-before($stripped, '/')";
+ otherwise value "$stripped";
+ }
+
+ choose {
+ when "string-length($token) = 0"{
+ result "$root";
+ }
+ otherwise{
+ const "rest", "substring-after($stripped, $token)";
+ const "match", "$root/*[@name = $token]";
+ choose {
+ when "string-length($rest) > 0"{
+ result "func:get_hmi_tree_el($rest, $match)";
+ }
+ otherwise{
+ result "$match";
+ }
+ }
+ }
+ }
+}
+
// Parses:
// "HMI:WidgetType:param1:param2@path1@path2"
//
// Into:
-// widget type="WidgetType" {
+// widget type="WidgetType" id="blah456" {
// arg value="param1";
// arg value="param2";
-// path value="path1";
+// path value="path1" index="345";
// path value="path2";
// }
//
diff -r 27dd409fba1d -r d57a12b8f5db svghmi/widget_foreach.ysl2
--- a/svghmi/widget_foreach.ysl2 Mon Mar 23 10:16:38 2020 +0100
+++ b/svghmi/widget_foreach.ysl2 Mon Mar 23 15:13:36 2020 +0100
@@ -6,23 +6,32 @@
| dispatch: function(value) {
| // do something
| },
+ | index_pool: [
+ | ],
+ | buttons: [
+ const "class","arg[1]/@value";
+ const "prefix","concat($class,':')";
+ const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')";
+ foreach "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]" {
+ | ["«substring-after(@inkscape:label, concat(arg[1]/@value, ':'))»", id("«@id»")]`if "position()!=last()" > ,`
+ }
+ | ],
| init: function() {
- foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
- | id("«@id»").addEventListener(
- | "click",
- | evt => {let new_val = "«func:escape_quotes(@inkscape:label)»");
- | // do something with new_val
- | });
- }
+ | /* TODO elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");*/
| },
- | widgets: [
- const "labels_regex","concat('^',arg[1]/@value,':[0-9]+')";
- foreach "$hmi_element/*[regexp:test(@inkscape:label, $labels_regex)]" {
- | [ /* «@inkscape:label» */
- const "elt",".";
- //foreach "$hmi_elements[ancestor::svg:*/@id = $_id]" {
- foreach "func:refered_elements(.)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
+ | items: [
+ const "base_path","path/@value";
+ const "items_regex","concat('^',$prefix,'[0-9]+')";
+ const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]";
+ foreach "$unordered_items" {
+ const "elt_label","concat($prefix, string(position()))";
+ const "elt","$unordered_items[@inkscape:label = $elt_label]";
+
+ | /* `apply "func:get_hmi_tree_elt($base_path)", mode="testtree";` */
+ | [ /* «$elt_label» */
+ if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id»
+ foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
| hmi_widgets["«@id»"]`if "position()!=last()" > ,`
}
| ]`if "position()!=last()" > ,`
diff -r 27dd409fba1d -r d57a12b8f5db svghmi/widgets_common.ysl2
--- a/svghmi/widgets_common.ysl2 Mon Mar 23 10:16:38 2020 +0100
+++ b/svghmi/widgets_common.ysl2 Mon Mar 23 15:13:36 2020 +0100
@@ -28,7 +28,7 @@
warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
}
otherwise {
- | «@index» /*«$widget/path»*/ `if "position()!=last()" > ,`
+ | «@index» /* «@value» */ `if "position()!=last()" > ,`
}
}
}