SVGHMI: Widget transform before DnD now should have HMI path as a parameter, but this path isn't computed for some reason... WIP.
--- 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 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn">
<xsl:output method="xml"/>
+ <xsl:param name="hmi_path"/>
<xsl:variable name="svg" select="/svg:svg"/>
<xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
<xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
@@ -121,9 +122,17 @@
<xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
</xsl:variable>
<xsl:variable name="parsed_widgets" select="exsl:node-set($_parsed_widgets)"/>
+ <xsl:variable name="selected_node_type" select="local-name($subhmitree)"/>
+ <xsl:variable name="svg_widget" select="$parsed_widgets/widget[1]"/>
+ <xsl:variable name="svg_widget_type" select="$svg_widget/@type"/>
+ <xsl:variable name="svg_widget_path" select="$svg_widget/@path"/>
+ <xsl:variable name="svg_widget_count" select="count($parsed_widgets/widget)"/>
<xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
<xsl:copy/>
</xsl:template>
+ <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@inkscape:label[starts-with(., 'HMI:')]">
+ <xsl:copy/>
+ </xsl:template>
<xsl:template mode="inline_svg" match="node()">
<xsl:copy>
<xsl:apply-templates mode="inline_svg" select="@* | node()"/>
@@ -135,9 +144,6 @@
<xsl:comment>
<xsl:text>Widget dropped in Inkscape from Beremiz</xsl:text>
</xsl:comment>
- <xsl:variable name="selected_node_type" select="local-name($subhmitree)"/>
- <xsl:variable name="svg_widget_type" select="$parsed_widgets/widget[1]/@type"/>
- <xsl:variable name="svg_widget_count" select="count($parsed_widgets/widget)"/>
<xsl:choose>
<xsl:when test="$svg_widget_count < 1">
<xsl:message terminate="yes">
@@ -151,12 +157,15 @@
</xsl:when>
<xsl:when test="$selected_node_type = $NODES_TYPES and not($svg_widget_type = $HMI_NODES_COMPAT)">
<xsl:message terminate="yes">
- <xsl:text>Widget incopatible with selected HMI tree node</xsl:text>
+ <xsl:text>Widget incompatible with selected HMI tree node</xsl:text>
</xsl:message>
</xsl:when>
</xsl:choose>
<xsl:variable name="testmsg">
<msg>
+ <xsl:value-of select="$hmi_path"/>
+ </msg>
+ <msg>
<xsl:value-of select="$selected_node_type"/>
</msg>
<msg>
--- 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";
}
--- 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 """
--- 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"