# HG changeset patch # User Edouard Tisserant # Date 1617639750 -7200 # Node ID 6adeeb16ac3ef7e90f18a31e8301ade240813bf1 # Parent 3d307ad803eab8c89679d854b5d30f229aea7a14 SVGHMI: Widget DnD to Inkscape : Added source SVG widget label parsing and pass selecte HMI subtree to XSLT tranform, so that SVG containing multiple widgets can later be matched against hmi tree fragments, in order to DnD complex groups of widgets. diff -r 3d307ad803ea -r 6adeeb16ac3e svghmi/gen_dnd_widget_svg.xslt --- a/svghmi/gen_dnd_widget_svg.xslt Fri Apr 02 21:16:18 2021 +0200 +++ b/svghmi/gen_dnd_widget_svg.xslt Mon Apr 05 18:22:30 2021 +0200 @@ -3,6 +3,8 @@ + + @@ -115,6 +117,10 @@ + + + + @@ -123,10 +129,41 @@ + + Widget dropped in Inkscape from Beremiz + + + + + + + No widget detected on selected SVG + + + + + Multiple widget DnD not yet supported + + + + + Widget incopatible with selected HMI tree node + + + + + + + + + + + + diff -r 3d307ad803ea -r 6adeeb16ac3e svghmi/gen_dnd_widget_svg.ysl2 --- a/svghmi/gen_dnd_widget_svg.ysl2 Fri Apr 02 21:16:18 2021 +0200 +++ b/svghmi/gen_dnd_widget_svg.ysl2 Mon Apr 05 18:22:30 2021 +0200 @@ -21,8 +21,12 @@ const "svg", "/svg:svg"; const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; + const "subhmitree", "ns:GetSubHMITree()"; + const "indexed_hmitree", "/.."; // compatibility with parse_labels.ysl2 include parse_labels.ysl2 + const "_parsed_widgets" apply "$hmi_elements", mode="parselabel"; + const "parsed_widgets","exsl:node-set($_parsed_widgets)"; svgtmpl "@*", mode="inline_svg" xsl:copy; @@ -30,9 +34,32 @@ xsl:copy apply "@* | node()", mode="inline_svg"; } + + const "NODES_TYPES","str:split('HMI_ROOT HMI_NODE')"; + const "HMI_NODES_COMPAT","str:split('Page Jump Foreach')"; template "/" { comment > Widget dropped in Inkscape from Beremiz + const "selected_node_type","local-name($subhmitree)"; + const "svg_widget_type", "$parsed_widgets/widget[1]/@type"; + const "svg_widget_count", "count($parsed_widgets/widget)"; + + choose { + when "$svg_widget_count < 1" + error > No widget detected on selected SVG + when "$svg_widget_count > 1" + error > Multiple widget DnD not yet supported + when """$selected_node_type = $NODES_TYPES and \ + not($svg_widget_type = $HMI_NODES_COMPAT)""" + error > Widget incopatible with selected HMI tree node + } + const "testmsg" { + msg value "$selected_node_type"; + msg value "$svg_widget_type"; + } + + value "ns:GiveDetails($testmsg)"; + apply "/", mode="inline_svg"; } } diff -r 3d307ad803ea -r 6adeeb16ac3e svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Fri Apr 02 21:16:18 2021 +0200 +++ b/svghmi/gen_index_xhtml.xslt Mon Apr 05 18:22:30 2021 +0200 @@ -1,6 +1,6 @@ - - + + @@ -1713,7 +1713,7 @@ - + @@ -6838,9 +6838,9 @@ Made with SVGHMI. https://beremiz.org - + - diff -r 3d307ad803ea -r 6adeeb16ac3e svghmi/ui.py --- a/svghmi/ui.py Fri Apr 02 21:16:18 2021 +0200 +++ b/svghmi/ui.py Mon Apr 05 18:22:30 2021 +0200 @@ -290,8 +290,11 @@ def GiveDetails(self, _context, msgs): for msg in msgs: - self.msg += msg+"\n" + self.msg += msg.text + "\n" + def GetSubHMITree(self, _context): + return [self.hmitree_node.etree()] + def ValidateWidget(self): self.msg = "" @@ -307,13 +310,12 @@ transform = XSLTransform( os.path.join(ScriptDirectory, "gen_dnd_widget_svg.xslt"), - [("GiveDetails", self.GiveDetails)]) + [("GetSubHMITree", self.GetSubHMITree), + ("GiveDetails", self.GiveDetails)]) svgdom = etree.parse(self.selected_SVG) - result = transform.transform(svgdom) - # hmi_path=self.hmitree_node.path, - # hmi_type=self.hmitree_node.nodetype) + result = transform.transform(svgdom) for entry in transform.get_error_log(): self.msg += "XSLT: " + entry.message + "\n"