# HG changeset patch
# User Edouard Tisserant
# Date 1617285658 -7200
# Node ID ec365ef396b1ff3facfe5cece44904890751de08
# Parent cc0ecc5e918f55707ed0f0278c8249fd78d5ddf0
SVGHMI: Ensure that when widgets are nested in HMI:Switch widget, their sub-elements are taken as switch's choice in case their label match the syntax.
diff -r cc0ecc5e918f -r ec365ef396b1 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Thu Apr 01 15:57:06 2021 +0200
+++ b/svghmi/gen_index_xhtml.xslt Thu Apr 01 16:00:58 2021 +0200
@@ -6715,7 +6715,10 @@
choices: [
-
+
+
+
+
{
@@ -6770,15 +6773,7 @@
//toggle state and apply
- if (this.state) {
-
- this.state = 0;
-
- } else {
-
- this.state = 1;
-
- }
+ this.state = this.state ? false : true;
this.apply_hmi_value(0, this.state);
@@ -6792,23 +6787,27 @@
+ activate(val) {
+
+ let [active, inactive] = val ? ["none",""] : ["", "none"];
+
+ if (this.active_elt)
+
+ this.active_elt.style.display = active;
+
+ if (this.inactive_elt)
+
+ this.inactive_elt.style.display = inactive;
+
+ }
+
+
+
animate(){
- // redraw toggle button on screen refresh
-
- if (this.state) {
-
- this.active_elt.setAttribute("style", this.active_style);
-
- this.inactive_elt.setAttribute("style", "display:none");
-
- } else {
-
- this.inactive_elt.setAttribute("style", this.inactive_style);
-
- this.active_elt.setAttribute("style", "display:none");
-
- }
+ // redraw toggle button on screen refresh
+
+ this.activate(this.state);
}
@@ -6816,23 +6815,9 @@
init() {
- this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
-
- this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
-
-
-
- if (this.active_style && this.inactive_style) {
-
- this.active_elt.setAttribute("style", "display:none");
-
- this.inactive_elt.setAttribute("style", this.inactive_style);
-
- }
-
-
-
- this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
+ this.activate(false);
+
+ this.element.onclick = (evt) => this.on_click(evt);
}
@@ -6848,8 +6833,6 @@
-
-
diff -r cc0ecc5e918f -r ec365ef396b1 svghmi/widget_switch.ysl2
--- a/svghmi/widget_switch.ysl2 Thu Apr 01 15:57:06 2021 +0200
+++ b/svghmi/widget_switch.ysl2 Thu Apr 01 16:00:58 2021 +0200
@@ -20,7 +20,12 @@
param "hmi_element";
| choices: [
const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!;
- foreach "$result_svg_ns//*[@id = $hmi_element/@id]//*[regexp:test(@inkscape:label,$regex)]" {
+
+ const "subelts", "$result_widgets[@id = $hmi_element/@id]//*";
+ const "subwidgets", "$subelts//*[@id = $hmi_widgets/@id]";
+ const "accepted", "$subelts[not(ancestor-or-self::*/@id = $subwidgets/@id)]";
+
+ foreach "$accepted[regexp:test(@inkscape:label,$regex)]" {
const "literal", "regexp:match(@inkscape:label,$regex)[2]";
| {
| elt:id("«@id»"),
diff -r cc0ecc5e918f -r ec365ef396b1 tests/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Thu Apr 01 15:57:06 2021 +0200
+++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Thu Apr 01 16:00:58 2021 +0200
@@ -128,9 +128,9 @@
inkscape:current-layer="hmi0"
showgrid="false"
units="px"
- inkscape:zoom="0.42177815"
- inkscape:cx="1614.7137"
- inkscape:cy="168.68416"
+ inkscape:zoom="1.1929688"
+ inkscape:cx="772.0138"
+ inkscape:cy="-68.272506"
inkscape:window-width="1600"
inkscape:window-height="836"
inkscape:window-x="0"
@@ -2575,6 +2575,152 @@
style="fill:#8667bf;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-linejoin:round"
id="path3447"
inkscape:connector-curvature="0" />
+
+
+
+ 4
+
+
+
+ 3
+
+
+
+ 2
+
+
+
+ 1
+
+
page node
+
+
+
+
+ up
+
+