SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation. svghmi
authorEdouard Tisserant
Tue, 03 Mar 2020 16:29:22 +0100
branchsvghmi
changeset 2852 f7349ca820c9
parent 2851 8d15c6238e62
child 2853 6d39beb19f38
SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Tue Mar 03 10:58:00 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Tue Mar 03 16:29:22 2020 +0100
@@ -261,9 +261,13 @@
     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
       <head/>
       <body style="margin:0;overflow:hidden;">
-        <xsl:apply-templates mode="inline_svg" select="svg:svg"/>
+        <xsl:variable name="_result_svg">
+          <xsl:apply-templates mode="inline_svg" select="svg:svg"/>
+        </xsl:variable>
+        <xsl:copy-of select="$_result_svg"/>
+        <xsl:variable name="result_svg" select="exsl:node-set($_result_svg)"/>
         <script>
-          <xsl:call-template name="scripts"/>
+          <xsl:apply-templates mode="scripts" select="svg:svg"/>
         </script>
       </body>
     </html>
@@ -319,7 +323,7 @@
     </xsl:variable>
     <func:result select="exsl:node-set($ast)"/>
   </func:function>
-  <xsl:template name="scripts">
+  <xsl:template mode="scripts" match="svg:svg">
     <xsl:text>//(function(){
 </xsl:text>
     <xsl:text>
@@ -336,18 +340,18 @@
 </xsl:text>
     <xsl:for-each select="$hmi_elements">
       <xsl:variable name="widget" select="func:parselabel(@inkscape:label)/widget"/>
-      <xsl:text>    "</xsl:text>
+      <xsl:text>  "</xsl:text>
       <xsl:value-of select="@id"/>
       <xsl:text>": {
 </xsl:text>
-      <xsl:text>        type: "</xsl:text>
+      <xsl:text>    type: "</xsl:text>
       <xsl:value-of select="$widget/@type"/>
       <xsl:text>",
 </xsl:text>
-      <xsl:text>        args: [
+      <xsl:text>    args: [
 </xsl:text>
       <xsl:for-each select="$widget/arg">
-        <xsl:text>            "</xsl:text>
+        <xsl:text>        "</xsl:text>
         <xsl:value-of select="@value"/>
         <xsl:text>"</xsl:text>
         <xsl:if test="position()!=last()">
@@ -356,9 +360,9 @@
         <xsl:text>
 </xsl:text>
       </xsl:for-each>
-      <xsl:text>        ],
-</xsl:text>
-      <xsl:text>        indexes: [
+      <xsl:text>    ],
+</xsl:text>
+      <xsl:text>    indexes: [
 </xsl:text>
       <xsl:for-each select="$widget/path">
         <xsl:variable name="hmipath" select="@value"/>
@@ -457,15 +461,15 @@
       <xsl:variable name="page_all_elements" select="func:all_related_elements($page)"/>
       <xsl:variable name="all_page_ids" select="$page_all_elements[@id = $hmi_elements/@id and @id != $page/@id]/@id"/>
       <xsl:variable name="required_detachables" select="func:sumarized_elements($page_all_elements)"/>
-      <xsl:text>    "</xsl:text>
+      <xsl:text>  "</xsl:text>
       <xsl:value-of select="$desc/arg[1]/@value"/>
       <xsl:text>": {
 </xsl:text>
-      <xsl:text>        widget: hmi_widgets["</xsl:text>
+      <xsl:text>    widget: hmi_widgets["</xsl:text>
       <xsl:value-of select="@id"/>
       <xsl:text>"],
 </xsl:text>
-      <xsl:text>        bbox: [</xsl:text>
+      <xsl:text>    bbox: [</xsl:text>
       <xsl:value-of select="$p/@x"/>
       <xsl:text>, </xsl:text>
       <xsl:value-of select="$p/@y"/>
@@ -475,10 +479,10 @@
       <xsl:value-of select="$p/@h"/>
       <xsl:text>],
 </xsl:text>
-      <xsl:text>        widgets: [
+      <xsl:text>    widgets: [
 </xsl:text>
       <xsl:for-each select="$all_page_ids">
-        <xsl:text>            hmi_widgets["</xsl:text>
+        <xsl:text>        hmi_widgets["</xsl:text>
         <xsl:value-of select="."/>
         <xsl:text>"]</xsl:text>
         <xsl:if test="position()!=last()">
@@ -487,12 +491,12 @@
         <xsl:text>
 </xsl:text>
       </xsl:for-each>
-      <xsl:text>        ],
-</xsl:text>
-      <xsl:text>        required_detachables: {
+      <xsl:text>    ],
+</xsl:text>
+      <xsl:text>    required_detachables: {
 </xsl:text>
       <xsl:for-each select="$required_detachables">
-        <xsl:text>            "</xsl:text>
+        <xsl:text>        "</xsl:text>
         <xsl:value-of select="@id"/>
         <xsl:text>": detachable_elements["</xsl:text>
         <xsl:value-of select="@id"/>
@@ -503,9 +507,9 @@
         <xsl:text>
 </xsl:text>
       </xsl:for-each>
-      <xsl:text>        }
-</xsl:text>
-      <xsl:text>    }</xsl:text>
+      <xsl:text>    }
+</xsl:text>
+      <xsl:text>  }</xsl:text>
       <xsl:if test="position()!=last()">
         <xsl:text>,</xsl:text>
       </xsl:if>
@@ -1173,6 +1177,7 @@
           </xsl:if>
         </xsl:when>
         <xsl:otherwise>
+          <xsl:text>    </xsl:text>
           <xsl:value-of select="$name"/>
           <xsl:text>_elt: id("</xsl:text>
           <xsl:value-of select="$elt_id"/>
@@ -1184,13 +1189,13 @@
   </xsl:template>
   <xsl:template mode="widget_defs" match="widget[@type='Display']">
     <xsl:param name="hmi_element"/>
-    <xsl:text>frequency: 5,
-</xsl:text>
-    <xsl:text>dispatch: function(value) {
+    <xsl:text>    frequency: 5,
+</xsl:text>
+    <xsl:text>    dispatch: function(value) {
 </xsl:text>
     <xsl:choose>
       <xsl:when test="$hmi_element[self::svg:text]">
-        <xsl:text>  this.element.textContent = String(value);
+        <xsl:text>      this.element.textContent = String(value);
 </xsl:text>
       </xsl:when>
       <xsl:otherwise>
@@ -1199,12 +1204,12 @@
         </xsl:message>
       </xsl:otherwise>
     </xsl:choose>
-    <xsl:text>},
+    <xsl:text>    },
 </xsl:text>
   </xsl:template>
   <xsl:template mode="widget_defs" match="widget[@type='Meter']">
     <xsl:param name="hmi_element"/>
-    <xsl:text>frequency: 10,
+    <xsl:text>    frequency: 10,
 </xsl:text>
     <xsl:call-template name="defs_by_labels">
       <xsl:with-param name="hmi_element" select="$hmi_element"/>
@@ -1212,31 +1217,31 @@
         <xsl:text>value min max needle range</xsl:text>
       </xsl:with-param>
     </xsl:call-template>
-    <xsl:text>dispatch: function(value) {
-</xsl:text>
-    <xsl:text>    this.value_elt.textContent = String(value);
-</xsl:text>
-    <xsl:text>    let [min,max,totallength] = this.range;
-</xsl:text>
-    <xsl:text>    let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
-</xsl:text>
-    <xsl:text>    let tip = this.range_elt.getPointAtLength(length);
-</xsl:text>
-    <xsl:text>    this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
-</xsl:text>
-    <xsl:text>},
-</xsl:text>
-    <xsl:text>origin: undefined,
-</xsl:text>
-    <xsl:text>range: undefined,
-</xsl:text>
-    <xsl:text>init: function() {
-</xsl:text>
-    <xsl:text>    this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
-</xsl:text>
-    <xsl:text>    this.origin = this.needle_elt.getPointAtLength(0);
-</xsl:text>
-    <xsl:text>},
+    <xsl:text>    dispatch: function(value) {
+</xsl:text>
+    <xsl:text>        this.value_elt.textContent = String(value);
+</xsl:text>
+    <xsl:text>        let [min,max,totallength] = this.range;
+</xsl:text>
+    <xsl:text>        let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
+</xsl:text>
+    <xsl:text>        let tip = this.range_elt.getPointAtLength(length);
+</xsl:text>
+    <xsl:text>        this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
+</xsl:text>
+    <xsl:text>    },
+</xsl:text>
+    <xsl:text>    origin: undefined,
+</xsl:text>
+    <xsl:text>    range: undefined,
+</xsl:text>
+    <xsl:text>    init: function() {
+</xsl:text>
+    <xsl:text>        this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
+</xsl:text>
+    <xsl:text>        this.origin = this.needle_elt.getPointAtLength(0);
+</xsl:text>
+    <xsl:text>    },
 </xsl:text>
   </xsl:template>
   <func:function name="func:escape_quotes">
--- a/svghmi/gen_index_xhtml.ysl2	Tue Mar 03 10:58:00 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2	Tue Mar 03 16:29:22 2020 +0100
@@ -484,13 +484,13 @@
         | var hmi_widgets = {
         foreach "$hmi_elements" {
             const "widget", "func:parselabel(@inkscape:label)/widget";
-        |     "«@id»": {
-        |         type: "«$widget/@type»",
-        |         args: [
+        |   "«@id»": {
+        |     type: "«$widget/@type»",
+        |     args: [
             foreach "$widget/arg"
-        |             "«@value»"`if "position()!=last()" > ,`
-        |         ],
-        |         indexes: [
+        |         "«@value»"`if "position()!=last()" > ,`
+        |     ],
+        |     indexes: [
             foreach "$widget/path" {
                 const "hmipath","@value";
                 const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]";
@@ -541,20 +541,20 @@
 
             const "required_detachables", "func:sumarized_elements($page_all_elements)";
 
-            |     "«$desc/arg[1]/@value»": {
-            |         widget: hmi_widgets["«@id»"],
-            |         bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
-            |         widgets: [
+            |   "«$desc/arg[1]/@value»": {
+            |     widget: hmi_widgets["«@id»"],
+            |     bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
+            |     widgets: [
             foreach "$all_page_ids" {
-            |             hmi_widgets["«.»"]`if "position()!=last()" > ,`
-            }
-            |         ],
-            |         required_detachables: {
+            |         hmi_widgets["«.»"]`if "position()!=last()" > ,`
+            }
+            |     ],
+            |     required_detachables: {
             foreach "$required_detachables" {
-            |             "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,`
-            }
-            |         }
-            |     }`if "position()!=last()" > ,`
+            |         "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,`
+            }
+            |     }
+            |   }`if "position()!=last()" > ,`
         }
         | }
 
@@ -629,7 +629,7 @@
                     // otherwise produce nothing 
                 }
                 otherwise {
-                    | «$name»_elt: id("«$elt_id»"),
+                    |     «$name»_elt: id("«$elt_id»"),
                 }
             }
         }
@@ -638,38 +638,37 @@
 
     template "widget[@type='Display']", mode="widget_defs" {
         param "hmi_element";
-        | frequency: 5,
-        | dispatch: function(value) {
+        |     frequency: 5,
+        |     dispatch: function(value) {
         choose {
             when "$hmi_element[self::svg:text]"{
             // TODO : care about <tspan> ?
-        |   this.element.textContent = String(value);
+        |       this.element.textContent = String(value);
             }
             otherwise {
                 warning > Display widget as a group not implemented
             }
         }
-        | },
+        |     },
 
     }
     template "widget[@type='Meter']", mode="widget_defs" {
         param "hmi_element";
-        | frequency: 10,
+        |     frequency: 10,
         labels("value min max needle range");
-        | dispatch: function(value) {
-        |     this.value_elt.textContent = String(value);
-        |     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,
-        | range: undefined,
-        | init: function() {
-        |     this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
-        |     this.origin = this.needle_elt.getPointAtLength(0);
-        | },
+        |     dispatch: function(value) {
+        |         this.value_elt.textContent = String(value);
+        |         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);
+        |         this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
+        |     },
+        |     origin: undefined,
+        |     range: undefined,
+        |     init: function() {
+        |         this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
+        |         this.origin = this.needle_elt.getPointAtLength(0);
+        |     },
     }
 
     def "func:escape_quotes" {