svghmi/gen_dnd_widget_svg.ysl2
branchsvghmi
changeset 3222 6adeeb16ac3e
parent 3221 3d307ad803ea
child 3223 061796d9855e
--- 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";
     }
 }