# HG changeset patch
# User Edouard Tisserant
# Date 1566289954 -7200
# Node ID ce04d79b8e5795bc3c5f5771d9aadda9f8649fd1
# Parent 282500e03dbccf5313f80ca2530adfb08c13b1a0
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
diff -r 282500e03dbc -r ce04d79b8e57 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Tue Aug 20 10:30:59 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt Tue Aug 20 10:32:34 2019 +0200
@@ -2,6 +2,7 @@
+
@@ -9,22 +10,48 @@
-
+
+
+
+
+ blah
+
+
+
-
- ID:
-
- x:
-
- y:
-
- w:
-
- h:
-
-
+ ID:
+
+ x:
+
+ y:
+
+ w:
+
+ h:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 282500e03dbc -r ce04d79b8e57 svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.ysl2 Tue Aug 20 10:30:59 2019 +0200
+++ b/svghmi/gen_index_xhtml.ysl2 Tue Aug 20 10:32:34 2019 +0200
@@ -18,6 +18,7 @@
*
*/
variable "geometry", "ns:GetSVGGeometry()";
+ variable "hmitree", "ns:GetHMITree()";
/* Identity template :
* - copy every attributes
@@ -31,14 +32,26 @@
/* copy root node and add geometry as comment for a test */
template "/" {
xsl:copy {
- apply "$geometry", mode="testgeo";
+ comment {
+ apply "$geometry", mode="testgeo";
+ }
+ comment {
+ | blah
+ apply "$hmitree", mode="testtree";
+ }
apply "@* | node()";
}
}
template "bbox", mode="testgeo"{
- comment {
- > ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h»
- }
+ | ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h»
+ }
+
+ template "*", mode="testtree"{
+ param "indent", "''";
+ | «$indent» «local-name()» «@name» «@type» «@path»
+ apply "*", mode="testtree" {
+ with "indent" value "concat($indent,'>')"
+ };
}
}
diff -r 282500e03dbc -r ce04d79b8e57 svghmi/svghmi.py
--- a/svghmi/svghmi.py Tue Aug 20 10:30:59 2019 +0200
+++ b/svghmi/svghmi.py Tue Aug 20 10:32:34 2019 +0200
@@ -9,7 +9,7 @@
from __future__ import absolute_import
import os
import shutil
-from itertools import izip
+from itertools import izip, imap
from pprint import pprint, pformat
import wx
@@ -71,12 +71,33 @@
else:
self.children.append(node)
+ def etree(self):
+
+ attribs = dict(name=self.name)
+ if self.path is not None:
+ attribs["path"]=".".join(self.path)
+
+ res = etree.Element(self.nodetype, **attribs)
+
+ if hasattr(self, "children"):
+ for child_etree in imap(lambda c:c.etree(), self.children):
+ res.append(child_etree)
+
+ return res
+
+# module scope for HMITree root
+# so that CTN can use HMITree deduced in Library
+# note: this only works because library's Generate_C is
+# systematicaly invoked before CTN's CTNGenerate_C
+
+hmi_tree_root = None
class SVGHMILibrary(POULibrary):
def GetLibraryPath(self):
return paths.AbsNeighbourFile(__file__, "pous.xml")
def Generate_C(self, buildpath, varlist, IECCFLAGS):
+ global hmi_tree_root
"""
PLC Instance Tree:
@@ -209,6 +230,11 @@
return res
+ def GetHMITree(self):
+ global hmi_tree_root
+ res = [hmi_tree_root.etree()]
+ return res
+
def CTNGenerate_C(self, buildpath, locations):
"""
Return C code generated by iec2c compiler
@@ -224,7 +250,8 @@
# TODO : move to __init__
transform = XSLTransform(os.path.join(ScriptDirectory, "gen_index_xhtml.xslt"),
- [("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry())])
+ [("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry()),
+ ("GetHMITree", lambda *_ignored:self.GetHMITree())])
# load svg as a DOM with Etree