SVGHMI: fix Switch widget so that order of choices elements is preserved across detaching and re-attaching.
authorEdouard Tisserant
Mon, 20 Jun 2022 09:19:56 +0200
changeset 3518 c663d1f9f03b
parent 3517 dacf329abdd9
child 3519 43b2bff95289
SVGHMI: fix Switch widget so that order of choices elements is preserved across detaching and re-attaching.
svghmi/widget_switch.ysl2
tests/projects/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/svghmi/widget_switch.ysl2	Wed Jun 15 11:46:48 2022 +0200
+++ b/svghmi/widget_switch.ysl2	Mon Jun 20 09:19:56 2022 +0200
@@ -43,7 +43,7 @@
                     }
                 } else {
                     if(choice.parent != undefined){
-                        choice.parent.appendChild(choice.elt);
+                        choice.parent.insertBefore(choice.elt,choice.sibling);
                         choice.parent = undefined;
                     }
                 }
@@ -60,11 +60,21 @@
     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 "choices", "$accepted[regexp:test(@inkscape:label,$regex)]";
+    foreach "$choices" {
         const "literal", "regexp:match(@inkscape:label,$regex)[2]";
+        const "sibling", "following-sibling::*[not(@id = $choices/@id)][position()=1]";
     |         {
     |             elt:id("«@id»"),
     |             parent:undefined,
+    choose {
+        when "count($sibling)=0" {
+    |             sibling:null,
+        }
+        otherwise {
+    |             sibling:id("«$sibling/@id»"),
+        }
+    }
     |             value:«$literal»
     |         }`if "position()!=last()" > ,`
     }
--- a/tests/projects/svghmi/svghmi_0@svghmi/svghmi.svg	Wed Jun 15 11:46:48 2022 +0200
+++ b/tests/projects/svghmi/svghmi_0@svghmi/svghmi.svg	Mon Jun 20 09:19:56 2022 +0200
@@ -125,12 +125,12 @@
      inkscape:pageopacity="0"
      inkscape:pageshadow="2"
      inkscape:document-units="px"
-     inkscape:current-layer="hmi0"
+     inkscape:current-layer="g5053"
      showgrid="false"
      units="px"
-     inkscape:zoom="0.20046201"
-     inkscape:cx="1401.1703"
-     inkscape:cy="-1495.7332"
+     inkscape:zoom="0.80184804"
+     inkscape:cx="784.66046"
+     inkscape:cy="-449.34319"
      inkscape:window-width="1600"
      inkscape:window-height="836"
      inkscape:window-x="0"
@@ -2244,6 +2244,42 @@
      inkscape:label="HMI:Switch@/PUMP0/BOOLOUT"
      transform="translate(43.983597,40.477445)">
     <g
+       inkscape:label="true"
+       style="fill:#ff0000;stroke:#ff00ff"
+       id="g1242"
+       transform="rotate(90,931.73133,997.97991)">
+      <path
+         inkscape:connector-curvature="0"
+         id="path1230"
+         style="fill:#353564;fill-rule:evenodd;stroke:none;stroke-linejoin:round"
+         d="M 825.90067,963.24473 V 1105.042 L 960.08282,916.47893 V 809.26931 Z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path1232"
+         style="fill:#afafde;fill-rule:evenodd;stroke:none;stroke-linejoin:round"
+         d="m 825.90067,1105.042 90.50966,81.6485 121.15167,-225.30346 -77.47918,-44.90811 z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path1234"
+         style="fill:#e9e9ff;fill-rule:evenodd;stroke:none;stroke-linejoin:round"
+         d="m 960.08282,809.26931 77.47918,36.25625 v 115.86148 l -77.47918,-44.90811 z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path1236"
+         style="fill:#4d4d9f;fill-rule:evenodd;stroke:none;stroke-linejoin:round"
+         d="M 825.90067,963.24473 916.41033,1029.3537 1037.562,845.52556 960.08282,809.26931 Z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path1238"
+         style="fill:#d7d7ff;fill-rule:evenodd;stroke:none;stroke-linejoin:round"
+         d="m 916.41033,1029.3537 v 157.3368 L 1037.562,961.38704 V 845.52556 Z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path1240"
+         style="fill:#8686bf;fill-rule:evenodd;stroke:none;stroke-linejoin:round"
+         d="m 825.90067,963.24473 90.50966,66.10897 v 157.3368 l -90.50966,-81.6485 z" />
+    </g>
+    <g
        id="g473"
        style="fill:#ff0000;stroke:#ff00ff"
        inkscape:label="true">
@@ -2278,6 +2314,15 @@
          id="path3461"
          inkscape:connector-curvature="0" />
     </g>
+    <rect
+       style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#808080;fill-opacity:1;fill-rule:nonzero;stroke:#ff8080;stroke-width:3.77952766;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
+       id="rect1228"
+       width="140.92445"
+       height="229.46991"
+       x="903.8269"
+       y="859.10773"
+       rx="7"
+       ry="7" />
     <g
        id="g501"
        style="fill:#ff0000;stroke:#ff00ff"