# HG changeset patch # User Edouard Tisserant # Date 1565608195 -7200 # Node ID f94bc35a023e639a6ea8aeda5aebf4d3b6bda173 # Parent 4efc509e9a1a6e2d273c806e86d2ac401adcfa7d SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable. diff -r 4efc509e9a1a -r f94bc35a023e svghmi/gen_index_xhtml.xslt --- 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 @@ ID: - + x: y: diff -r 4efc509e9a1a -r f94bc35a023e svghmi/gen_index_xhtml.ysl2 --- 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» } } } diff -r 4efc509e9a1a -r f94bc35a023e svghmi/svghmi.py --- 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): """