--- 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 @@
<xsl:stylesheet xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:exsl="http://exslt.org/common" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" extension-element-prefixes="ns" version="1.0" exclude-result-prefixes="ns">
<xsl:output method="xml"/>
<xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
+ <xsl:variable name="hmitree" select="ns:GetHMITree()"/> <xsl:template match="@* | node()">
<xsl:apply-templates select="@* | node()"/>
@@ -9,22 +10,48 @@
- <xsl:apply-templates mode="testgeo" select="$geometry"/>
+ <xsl:apply-templates mode="testgeo" select="$geometry"/> + <xsl:apply-templates mode="testtree" select="$hmitree"/> <xsl:apply-templates select="@* | node()"/>
<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>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:template mode="testtree" match="*"> + <xsl:param name="indent" select="''"/> + <xsl:value-of select="$indent"/> + <xsl:value-of select="local-name()"/> + <xsl:value-of select="@name"/> + <xsl:value-of select="@type"/> + <xsl:value-of select="@path"/> + <xsl:apply-templates mode="testtree" select="*"> + <xsl:with-param name="indent"> + <xsl:value-of select="concat($indent,'>')"/> --- 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 @@
* <bbox x="0" y="0" w="42" h="42">
variable "geometry", "ns:GetSVGGeometry()";
+ variable "hmitree", "ns:GetHMITree()"; * - copy every attributes
@@ -31,14 +32,26 @@
/* copy root node and add geometry as comment for a test */
- apply "$geometry", mode="testgeo";
+ apply "$geometry", mode="testgeo"; + apply "$hmitree", mode="testtree"; template "bbox", mode="testgeo"{
- > ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h»
+ | ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h» + template "*", mode="testtree"{ + | «$indent» «local-name()» «@name» «@type» «@path» + apply "*", mode="testtree" { + with "indent" value "concat($indent,'>')" --- 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
-from itertools import izip
+from itertools import izip, imap from pprint import pprint, pformat
@@ -71,12 +71,33 @@
self.children.append(node)
+ 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) +# 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 class SVGHMILibrary(POULibrary):
def GetLibraryPath(self):
return paths.AbsNeighbourFile(__file__, "pous.xml")
def Generate_C(self, buildpath, varlist, IECCFLAGS):
@@ -209,6 +230,11 @@
+ res = [hmi_tree_root.etree()] 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