Merge svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Mon, 22 Feb 2021 10:09:57 +0100
branchsvghmi
changeset 3160 cecfd6bb4593
parent 3156 76c0c0a524c9 (diff)
parent 3159 1d7c3d13a4df (current diff)
child 3161 edd558965f58
Merge
svghmi/svghmi.py
--- a/svghmi/gen_index_xhtml.xslt	Fri Feb 19 14:56:14 2021 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Mon Feb 22 10:09:57 2021 +0100
@@ -19,6 +19,7 @@
   <xsl:variable name="indexed_hmitree" select="exsl:node-set($_indexed_hmitree)"/>
   <preamble:hmi-tree/>
   <xsl:template match="preamble:hmi-tree">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -61,6 +62,7 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template mode="index" match="*">
     <xsl:param name="index" select="0"/>
@@ -278,6 +280,7 @@
   </xsl:template>
   <debug:hmi-tree/>
   <xsl:template match="debug:hmi-tree">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -302,10 +305,12 @@
     <xsl:apply-templates mode="testtree" select="$parsed_widgets"/>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
   <debug:geometry/>
   <xsl:template match="debug:geometry">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -332,6 +337,7 @@
     </xsl:for-each>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <func:function name="func:intersect_1d">
     <xsl:param name="a0"/>
@@ -407,6 +413,7 @@
   </xsl:variable>
   <preamble:default-page/>
   <xsl:template match="preamble:default-page">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -423,6 +430,7 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:variable name="keypads_descs" select="$parsed_widgets/widget[@type = 'Keypad']"/>
   <xsl:variable name="keypads" select="$hmi_elements[@id = $keypads_descs/@id]"/>
@@ -482,6 +490,7 @@
   <xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/>
   <declarations:detachable-elements/>
   <xsl:template match="declarations:detachable-elements">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -512,6 +521,7 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:variable name="forEach_widgets_ids" select="$parsed_widgets/widget[@type = 'ForEach']/@id"/>
   <xsl:variable name="forEach_widgets" select="$hmi_widgets[@id = $forEach_widgets_ids]"/>
@@ -627,6 +637,7 @@
   </xsl:template>
   <definitions:page-desc/>
   <xsl:template match="definitions:page-desc">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -644,10 +655,12 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template mode="per_page_widget_template" match="*"/>
   <debug:detachable-pages/>
   <xsl:template match="debug:detachable-pages">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -676,6 +689,7 @@
     </xsl:for-each>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
     <xsl:copy/>
@@ -895,6 +909,7 @@
   <xsl:variable name="result_svg_ns" select="exsl:node-set($result_svg)"/>
   <preamble:inline-svg/>
   <xsl:template match="preamble:inline-svg">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -911,9 +926,11 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <debug:clone-unlinking/>
   <xsl:template match="debug:clone-unlinking">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -940,6 +957,7 @@
     </xsl:for-each>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template mode="extract_i18n" match="svg:tspan">
     <xsl:if test="string-length(.) &gt; 0">
@@ -965,6 +983,7 @@
   </xsl:variable>
   <preamble:i18n/>
   <xsl:template match="preamble:i18n">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -1027,6 +1046,7 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template mode="hmi_widgets" match="svg:*">
     <xsl:variable name="widget" select="func:widget(@id)"/>
@@ -1129,6 +1149,7 @@
   </xsl:template>
   <preamble:local-variable-indexes/>
   <xsl:template match="preamble:local-variable-indexes">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -1272,9 +1293,11 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <preamble:widget-base-class/>
   <xsl:template match="preamble:widget-base-class">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -1669,11 +1692,13 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:variable name="excluded_types" select="str:split('Page VarInit VarInitPersistent')"/>
   <xsl:key name="TypesKey" match="widget" use="@type"/>
   <declarations:hmi-classes/>
   <xsl:template match="declarations:hmi-classes">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -1686,6 +1711,7 @@
     <xsl:apply-templates mode="widget_class" select="$used_widget_types"/>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template mode="widget_class" match="widget">
     <xsl:text>class </xsl:text>
@@ -1703,6 +1729,7 @@
   <xsl:variable name="hmi_widgets" select="$hmi_elements[@id = $included_ids]"/>
   <declarations:hmi-elements/>
   <xsl:template match="declarations:hmi-elements">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -1718,6 +1745,7 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template name="defs_by_labels">
     <xsl:param name="labels" select="''"/>
@@ -2967,6 +2995,7 @@
   </xsl:template>
   <preamble:display/>
   <xsl:template match="preamble:display">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -3443,6 +3472,7 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template mode="widget_class" match="widget[@type='DropDown']">
     <xsl:text>    function numb_event(e) {
@@ -4452,16 +4482,12 @@
     </xsl:if>
     <xsl:text>    dispatch: function(value) {
 </xsl:text>
-    <xsl:if test="$have_edit">
-      <xsl:text>        this.last_val = value;
-</xsl:text>
-    </xsl:if>
-    <xsl:if test="$have_value">
+    <xsl:if test="$have_value or $have_edit">
       <xsl:choose>
         <xsl:when test="count(arg) = 1">
           <xsl:text>        this.last_display = vsprintf("</xsl:text>
           <xsl:value-of select="arg[1]/@value"/>
-          <xsl:text>", value);
+          <xsl:text>", [value]);
 </xsl:text>
         </xsl:when>
         <xsl:otherwise>
@@ -4469,6 +4495,8 @@
 </xsl:text>
         </xsl:otherwise>
       </xsl:choose>
+    </xsl:if>
+    <xsl:if test="$have_value">
       <xsl:text>        this.request_animate();
 </xsl:text>
     </xsl:if>
@@ -4489,7 +4517,7 @@
       <xsl:value-of select="path/@value"/>
       <xsl:text>", "</xsl:text>
       <xsl:value-of select="path/@type"/>
-      <xsl:text>", this, this.last_val);
+      <xsl:text>", this, this.last_display);
 </xsl:text>
       <xsl:if test="$have_value">
         <xsl:text>        this.value_elt.style.pointerEvents = "none";
@@ -5155,6 +5183,7 @@
   </xsl:template>
   <declarations:jump/>
   <xsl:template match="declarations:jump">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -5181,9 +5210,11 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <declarations:keypad/>
   <xsl:template match="declarations:keypad">
+    <xsl:variable name="_unused" select="ns:ProgressStart(name())"/>
     <xsl:text>
 </xsl:text>
     <xsl:text>/* </xsl:text>
@@ -5216,6 +5247,7 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:variable name="__unused" select="ns:ProgressEnd(name())"/>
   </xsl:template>
   <xsl:template mode="widget_class" match="widget[@type='Keypad']">
     <xsl:text>class KeypadWidget extends Widget{
--- a/svghmi/gen_index_xhtml.ysl2	Fri Feb 19 14:56:14 2021 +0100
+++ b/svghmi/gen_index_xhtml.ysl2	Mon Feb 22 10:09:57 2021 +0100
@@ -7,11 +7,13 @@
 decl emit(*name) alias - {
     *name;
     template *name {
+        const "_unused", "ns:ProgressStart(name())";
         |
         | /* «local-name()» */
         |
         content;
         |
+        const "__unused", "ns:ProgressEnd(name())";
     }
 };
 
--- a/svghmi/svghmi.py	Fri Feb 19 14:56:14 2021 +0100
+++ b/svghmi/svghmi.py	Mon Feb 22 10:09:57 2021 +0100
@@ -14,6 +14,7 @@
 import hashlib
 import weakref
 import shlex
+import time
 
 import wx
 import wx.dataview as dv
@@ -544,6 +545,18 @@
 
         return TranslationToEtree(langs,translated_messages)
 
+    times = {}
+    def ProgressStart(self, _context, message):
+        t = time.time()
+        s = str(message)
+        self.times[s] = t
+
+    def ProgressEnd(self, _context, message):
+        t = time.time()
+        s = str(message)
+        self.GetCTRoot().logger.write("  %s: %.3f\n"%(message, t - self.times[s]))
+        self.times[s] = t
+
     def CTNGenerate_C(self, buildpath, locations):
 
         location_str = "_".join(map(str, self.GetCurrentLocation()))
@@ -558,18 +571,26 @@
         target_path = os.path.join(self._getBuildPath(), target_fname)
         target_file = open(target_path, 'wb')
 
+        self.GetCTRoot().logger.write("SVGHMI:\n")
+
         if os.path.exists(svgfile):
 
             # TODO : move to __init__
             transform = XSLTransform(os.path.join(ScriptDirectory, "gen_index_xhtml.xslt"),
                           [("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry()),
                            ("GetHMITree", lambda *_ignored:self.GetHMITree()),
-                           ("GetTranslations", self.GetTranslations)])
-
+                           ("GetTranslations", self.GetTranslations),
+                           ("ProgressStart", self.ProgressStart),
+                           ("ProgressEnd", self.ProgressEnd)])
+
+
+            t = time.time()
 
             # load svg as a DOM with Etree
             svgdom = etree.parse(svgfile)
 
+            self.GetCTRoot().logger.write("  Source SVG parsing: %.3f\n"%(time.time()-t))
+
             # call xslt transform on Inkscape's SVG to generate XHTML
             try: 
                 result = transform.transform(svgdom)
--- a/svghmi/widget_input.ysl2	Fri Feb 19 14:56:14 2021 +0100
+++ b/svghmi/widget_input.ysl2	Mon Feb 22 10:09:57 2021 +0100
@@ -41,18 +41,18 @@
 
     |     dispatch: function(value) {
 
-    if "$have_edit"
-    |         this.last_val = value;
 
-    if "$have_value" {
+    if "$have_value or $have_edit" {
         choose{
             when "count(arg) = 1" {
-    |         this.last_display = vsprintf("«arg[1]/@value»", value);
+    |         this.last_display = vsprintf("«arg[1]/@value»", [value]);
             }
             otherwise {
     |         this.last_display = value;
             }
         }
+    }
+    if "$have_value" {
     |         this.request_animate();
     }
     |     },
@@ -66,7 +66,7 @@
     |     init: function() {
 
     if "$have_edit" {
-    |         this.edit_elt.onclick = () => edit_value("«path/@value»", "«path/@type»", this, this.last_val);
+    |         this.edit_elt.onclick = () => edit_value("«path/@value»", "«path/@type»", this, this.last_display);
         if "$have_value" {
     |         this.value_elt.style.pointerEvents = "none";
         }