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.
include yslt_noindent.yml2
in xsl decl svgtmpl(match, xmlns="http://www.w3.org/2000/svg") alias template;
istylesheet
/* From Inkscape */
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"
/* Namespace to invoke python code */
xmlns:ns="beremiz"
extension-element-prefixes="ns func exsl regexp str dyn"
exclude-result-prefixes="ns func exsl regexp str dyn" {
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;
template "node()", mode="inline_svg" {
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";
}
}