SVGHMI: various insignificant code moves, commenting and typos fixes. svghmi
authorEdouard Tisserant
Tue, 29 Oct 2019 11:18:58 +0100
branchsvghmi
changeset 2810 63b9a37b73c7
parent 2809 b9c540253263
child 2811 4a81cec5f786
SVGHMI: various insignificant code moves, commenting and typos fixes.
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
svghmi/svghmi.js
tests/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/svghmi/gen_index_xhtml.xslt	Tue Oct 29 09:10:10 2019 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Tue Oct 29 11:18:58 2019 +0100
@@ -700,8 +700,6 @@
 </xsl:text>
     <xsl:text>    /* TODO hide / show widgets */
 </xsl:text>
-    <xsl:text>    /* TODO move viewport */
-</xsl:text>
     <xsl:text>
 </xsl:text>
     <xsl:text>    /* remove subsribers of previous page if any */
@@ -783,78 +781,6 @@
     <xsl:text>//})();
 </xsl:text>
   </xsl:template>
-  <xsl:template mode="page_desc" match="*"/>
-  <xsl:template mode="code_from_descs" match="*">
-    <xsl:text>{
-</xsl:text>
-    <xsl:text>    var path, role, name, priv;
-</xsl:text>
-    <xsl:text>    var id = "</xsl:text>
-    <xsl:value-of select="@id"/>
-    <xsl:text>";
-</xsl:text>
-    <xsl:if test="@inkscape:label">
-      <xsl:text>name = "</xsl:text>
-      <xsl:value-of select="@inkscape:label"/>
-      <xsl:text>";
-</xsl:text>
-    </xsl:if>
-    <xsl:text>/* -------------- */
-</xsl:text>
-    <xsl:value-of select="substring-after(svg:desc, $mark)"/>
-    <xsl:text>
-</xsl:text>
-    <xsl:text>    /* -------------- */
-</xsl:text>
-    <xsl:text>    res.push({
-</xsl:text>
-    <xsl:text>        path:path,
-</xsl:text>
-    <xsl:text>        role:role,
-</xsl:text>
-    <xsl:text>        name:name,
-</xsl:text>
-    <xsl:text>        priv:priv
-</xsl:text>
-    <xsl:text>    })
-</xsl:text>
-    <xsl:text>}
-</xsl:text>
-  </xsl:template>
-  <xsl:template mode="testgeo" match="bbox">
-    <xsl:text>ID: </xsl:text>
-    <xsl:value-of select="@Id"/>
-    <xsl:text> x: </xsl:text>
-    <xsl:value-of select="@x"/>
-    <xsl:text> y: </xsl:text>
-    <xsl:value-of select="@y"/>
-    <xsl:text> w: </xsl:text>
-    <xsl:value-of select="@w"/>
-    <xsl:text> h: </xsl:text>
-    <xsl:value-of select="@h"/>
-    <xsl:text>
-</xsl:text>
-  </xsl:template>
-  <xsl:template mode="testtree" match="*">
-    <xsl:param name="indent" select="''"/>
-    <xsl:value-of select="$indent"/>
-    <xsl:text> </xsl:text>
-    <xsl:value-of select="local-name()"/>
-    <xsl:text> </xsl:text>
-    <xsl:for-each select="@*">
-      <xsl:value-of select="local-name()"/>
-      <xsl:text>=</xsl:text>
-      <xsl:value-of select="."/>
-      <xsl:text> </xsl:text>
-    </xsl:for-each>
-    <xsl:text>
-</xsl:text>
-    <xsl:apply-templates mode="testtree" select="*">
-      <xsl:with-param name="indent">
-        <xsl:value-of select="concat($indent,'&gt;')"/>
-      </xsl:with-param>
-    </xsl:apply-templates>
-  </xsl:template>
   <xsl:template name="defs_by_labels">
     <xsl:param name="labels" select="''"/>
     <xsl:param name="mandatory" select="'yes'"/>
@@ -903,7 +829,7 @@
     <xsl:call-template name="defs_by_labels">
       <xsl:with-param name="hmi_element" select="$hmi_element"/>
       <xsl:with-param name="labels">
-        <test>value min max needle range</test>
+        <xsl:text>value min max needle range</xsl:text>
       </xsl:with-param>
     </xsl:call-template>
     <xsl:text>dispatch: function(value) {
@@ -940,7 +866,7 @@
     <xsl:call-template name="defs_by_labels">
       <xsl:with-param name="hmi_element" select="$hmi_element"/>
       <xsl:with-param name="labels">
-        <test>value</test>
+        <xsl:text>value</xsl:text>
       </xsl:with-param>
     </xsl:call-template>
     <xsl:text>dispatch: function(value) {
--- a/svghmi/gen_index_xhtml.ysl2	Tue Oct 29 09:10:10 2019 +0100
+++ b/svghmi/gen_index_xhtml.ysl2	Tue Oct 29 11:18:58 2019 +0100
@@ -5,7 +5,7 @@
 
 in xsl decl labels(*ptr, name="defs_by_labels") alias call-template {
     with "hmi_element", "$hmi_element";
-    with "labels"{test *ptr};
+    with "labels"{text *ptr};
 };
 
 istylesheet
@@ -144,6 +144,19 @@
         }
     }
 
+    /*
+        Parses:
+        "HMI:WidgetType:param1:param2@path1@path2"
+
+        Into:
+        widget type="WidgetType" {
+            arg value="param1";
+            arg value="param2";
+            path value="path1";
+            path value="path2";
+        }
+    */
+
     func:function name="func:parselabel" {
         param "label";
         const "description", "substring-after($label,'HMI:')";
@@ -263,53 +276,38 @@
         | //})();
     }
 
+    // template "*", mode="code_from_descs" {
+    //     ||
+    //     {
+    //         var path, role, name, priv;
+    //         var id = "«@id»";
+    //     ||
+
+    //     /* if label is used, use it as default name */
+    //     if "@inkscape:label"
+    //         |> name = "«@inkscape:label»";
+
+    //     | /* -------------- */
+
+    //     // this breaks indent, but fixing indent could break string literals
+    //     value "substring-after(svg:desc, $mark)";
+    //     // nobody reads generated code anyhow...
+
+    //     ||
+
+    //         /* -------------- */
+    //         res.push({
+    //             path:path,
+    //             role:role,
+    //             name:name,
+    //             priv:priv
+    //         })
+    //     }
+    //     ||
+    // }
+
+
     /*
-        Parses:
-        "HMI:WidgetType:param1:param2@path1@path2"
-
-        Into:
-        widget type="WidgetType" {
-            arg value="param1";
-            arg value="param2";
-            path value="path1";
-            path value="path2";
-        }
-    */
-
-    template "*", mode="page_desc" {
-    }
-
-    template "*", mode="code_from_descs" {
-        ||
-        {
-            var path, role, name, priv;
-            var id = "«@id»";
-        ||
-
-        /* if label is used, use it as default name */
-        if "@inkscape:label"
-            |> name = "«@inkscape:label»";
-
-        | /* -------------- */
-
-        // this breaks indent, but fixing indent could break string literals
-        value "substring-after(svg:desc, $mark)";
-        // nobody reads generated code anyhow...
-
-        ||
-
-            /* -------------- */
-            res.push({
-                path:path,
-                role:role,
-                name:name,
-                priv:priv
-            })
-        }
-        ||
-    }
-
-
     template "bbox", mode="testgeo"{
         | ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h»
     }
@@ -323,7 +321,7 @@
             with "indent" value "concat($indent,'>')"
         };
     }
-
+    */
 
     function "defs_by_labels" {
         param "labels","''";
@@ -363,6 +361,7 @@
         |     let [min,max,totallength] = this.range;
         |     let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
         |     let tip = this.range_elt.getPointAtLength(length);
+        // TODO : deal with transformations between needle and range
         |     this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
         | },
         | origin: undefined,
--- a/svghmi/svghmi.js	Tue Oct 29 09:10:10 2019 +0100
+++ b/svghmi/svghmi.js	Tue Oct 29 11:18:58 2019 +0100
@@ -180,7 +180,6 @@
     let old_desc = page_desc[current_page];
     let new_desc = page_desc[page_name];
     /* TODO hide / show widgets */
-    /* TODO move viewport */
 
     /* remove subsribers of previous page if any */
     if(old_desc) for(let widget of old_desc.widgets){
@@ -197,6 +196,7 @@
             }
         }
         svg_root.setAttribute('viewBox',new_desc.bbox.join(" "));
+        // TODO dispatch current cache in newly opened page
     }
     current_page = page_name;
 
--- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg	Tue Oct 29 09:10:10 2019 +0100
+++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg	Tue Oct 29 11:18:58 2019 +0100
@@ -117,8 +117,8 @@
      showgrid="false"
      units="px"
      inkscape:zoom="0.8046875"
-     inkscape:cx="283.03663"
-     inkscape:cy="-454.38089"
+     inkscape:cx="478.76479"
+     inkscape:cy="-403.42943"
      inkscape:window-width="1600"
      inkscape:window-height="886"
      inkscape:window-x="0"
@@ -679,13 +679,14 @@
     <text
        xml:space="preserve"
        style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:125%;font-family:sans-serif;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#ff6600;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="134.69675"
-       y="-16.777117"
+       x="-20.624428"
+       y="-109.67243"
        id="text104"
-       inkscape:label="value"><tspan
-         sodipodi:role="line"
-         x="134.69675"
-         y="-16.777117"
+       inkscape:label="value"
+       transform="rotate(90)"><tspan
+         sodipodi:role="line"
+         x="-20.624428"
+         y="-109.67243"
          style="text-align:center;text-anchor:middle;fill:#ff6600;stroke-width:0.26458332px"
          id="tspan102">000</tspan></text>
     <text