SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
--- a/svghmi/gen_index_xhtml.xslt Mon Aug 12 13:06:11 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt Mon Aug 12 13:09:55 2019 +0200
@@ -16,7 +16,7 @@
<xsl:template mode="testgeo" match="bbox">
<xsl:comment>
<xsl:text>ID: </xsl:text>
- <xsl:value-of select="@id"/>
+ <xsl:value-of select="@Id"/>
<xsl:text> x: </xsl:text>
<xsl:value-of select="@x"/>
<xsl:text> y: </xsl:text>
--- a/svghmi/gen_index_xhtml.ysl2 Mon Aug 12 13:06:11 2019 +0200
+++ b/svghmi/gen_index_xhtml.ysl2 Mon Aug 12 13:09:55 2019 +0200
@@ -38,7 +38,7 @@
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»
}
}
}
--- a/svghmi/svghmi.py Mon Aug 12 13:06:11 2019 +0200
+++ b/svghmi/svghmi.py Mon Aug 12 13:09:55 2019 +0200
@@ -14,9 +14,11 @@
import util.paths as paths
from POULibrary import POULibrary
-from docutil import open_svg
+from docutil import open_svg, get_inkscape_path
from lxml import etree
+from util.ProcessLogger import ProcessLogger
+
HMI_TYPES_DESC = {
"HMI_CLASS":{},
"HMI_LABEL":{},
@@ -98,9 +100,25 @@
return True
def GetSVGGeometry(self):
- # TODO : invoke inskscape -S, csv-parse output, produce elements
- return [etree.Element("bbox", id="blah0", x="1", y="2", w="3", h="4"),
- etree.Element("bbox", id="blah1", x="5", y="6", w="7", h="8")]
+ # invoke inskscape -S, csv-parse output, produce elements
+ InkscapeGeomColumns = ["Id", "x", "y", "w", "h"]
+
+ # TODO : move following line to __init__
+ inkpath = get_inkscape_path()
+ svgpath = self._getSVGpath()
+ _status, result, _err_result = ProcessLogger(None,
+ inkpath + " -S " + svgpath,
+ no_stdout=True,
+ no_stderr=True).spin()
+ res = []
+ for line in result.split():
+ strippedline = line.strip()
+ attrs = dict(
+ zip(InkscapeGeomColumns, line.strip().split(',')))
+
+ res.append(etree.Element("bbox", **attrs))
+
+ return res
def CTNGenerate_C(self, buildpath, locations):
"""