# HG changeset patch # User Edouard Tisserant # Date 1617702427 -7200 # Node ID 061796d9855e35ccbdb04a7bcc9f455fb62dc0f4 # Parent 6adeeb16ac3ef7e90f18a31e8301ade240813bf1 SVGHMI: Widget transform before DnD now should have HMI path as a parameter, but this path isn't computed for some reason... WIP. diff -r 6adeeb16ac3e -r 061796d9855e svghmi/gen_dnd_widget_svg.xslt --- a/svghmi/gen_dnd_widget_svg.xslt Mon Apr 05 18:22:30 2021 +0200 +++ b/svghmi/gen_dnd_widget_svg.xslt Tue Apr 06 11:47:07 2021 +0200 @@ -1,6 +1,7 @@ + @@ -121,9 +122,17 @@ + + + + + + + + @@ -135,9 +144,6 @@ Widget dropped in Inkscape from Beremiz - - - @@ -151,12 +157,15 @@ - Widget incopatible with selected HMI tree node + Widget incompatible with selected HMI tree node + + + diff -r 6adeeb16ac3e -r 061796d9855e svghmi/gen_dnd_widget_svg.ysl2 --- a/svghmi/gen_dnd_widget_svg.ysl2 Mon Apr 05 18:22:30 2021 +0200 +++ b/svghmi/gen_dnd_widget_svg.ysl2 Tue Apr 06 11:47:07 2021 +0200 @@ -19,6 +19,7 @@ extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn" { + param "hmi_path"; const "svg", "/svg:svg"; const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; const "subhmitree", "ns:GetSubHMITree()"; @@ -28,8 +29,18 @@ const "_parsed_widgets" apply "$hmi_elements", mode="parselabel"; const "parsed_widgets","exsl:node-set($_parsed_widgets)"; + const "selected_node_type","local-name($subhmitree)"; + const "svg_widget", "$parsed_widgets/widget[1]"; + const "svg_widget_type", "$svg_widget/@type"; + const "svg_widget_path", "$svg_widget/@path"; + const "svg_widget_count", "count($parsed_widgets/widget)"; + svgtmpl "@*", mode="inline_svg" xsl:copy; + svgtmpl "@inkscape:label[starts-with(., 'HMI:')]", mode="inline_svg" { + xsl:copy; + } + template "node()", mode="inline_svg" { xsl:copy apply "@* | node()", mode="inline_svg"; } @@ -40,10 +51,6 @@ 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 @@ -51,9 +58,11 @@ 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 + error > Widget incompatible with selected HMI tree node } + const "testmsg" { + msg value "$hmi_path"; msg value "$selected_node_type"; msg value "$svg_widget_type"; } diff -r 6adeeb16ac3e -r 061796d9855e svghmi/hmi_tree.py --- a/svghmi/hmi_tree.py Mon Apr 05 18:22:30 2021 +0200 +++ b/svghmi/hmi_tree.py Tue Apr 06 11:47:07 2021 +0200 @@ -9,6 +9,7 @@ from __future__ import absolute_import from itertools import izip, imap from pprint import pformat +import weakref import hashlib from lxml import etree @@ -29,6 +30,7 @@ self.name = name self.nodetype = nodetype self.hmiclass = hmiclass + self.parent = None if iectype is not None: self.iectype = iectype @@ -84,6 +86,7 @@ if prev.path[:-1] == node.path[:-1]: return "Late_HMI_NODE",prev + node.parent = weakref.ref(self) self.children.append(node) return None @@ -132,6 +135,13 @@ for yoodl in c.traverse(): yield yoodl + def hmi_path(self): + if self.parent is None: + return "/" + p = self.parent() + if p.parent is None: + return "/" + self.name + return p.hmi_path() + "/" + self.name def hash(self): """ Produce a hash, any change in HMI tree structure change that hash """ diff -r 6adeeb16ac3e -r 061796d9855e svghmi/ui.py --- a/svghmi/ui.py Mon Apr 05 18:22:30 2021 +0200 +++ b/svghmi/ui.py Tue Apr 06 11:47:07 2021 +0200 @@ -315,7 +315,8 @@ svgdom = etree.parse(self.selected_SVG) - result = transform.transform(svgdom) + result = transform.transform( + svgdom, hmi_path = self.hmitree_node.hmi_path()) for entry in transform.get_error_log(): self.msg += "XSLT: " + entry.message + "\n"