--- a/svghmi/svghmi.py Mon Aug 12 13:09:55 2019 +0200
+++ b/svghmi/svghmi.py Tue Aug 13 14:04:13 2019 +0200
@@ -9,6 +9,8 @@
from __future__ import absolute_import
+from itertools import izip +from pprint import pprint, pformat @@ -33,16 +35,100 @@
ScriptDirectory = paths.AbsDir(__file__)
+class HMITreeNode(object): + def __init__(self, path, name, nodetype): + self.nodetype = nodetype + if nodetype in ["HMI_LABEL", "HMI_ROOT"]: + def pprint(self, indent = 0): + res = ">"*indent + pformat(self.__dict__, indent = indent, depth = 1) + "\n" + if hasattr(self, "children"): + res += "\n".join([child.pprint(indent = indent + 1) + for child in self.children]) + def place_node(self, node): + for child in self.children: + for child_path_item, node_path_item in izip(child.path, node.path): + if child_path_item == node_path_item: + if in_common > known_best_match: + known_best_match = in_common + if best_child is not None and best_child.nodetype == "HMI_LABEL": + best_child.place_node(node) + self.children.append(node) class SVGHMILibrary(POULibrary):
def GetLibraryPath(self):
return paths.AbsNeighbourFile(__file__, "pous.xml")
def Generate_C(self, buildpath, varlist, IECCFLAGS):
hmi_types_instances = [v for v in varlist if v["derived"] in HMI_TYPES]
+ # TODO XXX !!! filter intermediate variables added for FBD feedback loop
+ hmi_tree_root = HMITreeNode(None, "hmi0", "HMI_ROOT") + # TODO add always available variables here ? + # deduce HMI tree from PLC HMI_* instances + for v in hmi_types_instances: + path = v["IEC_path"].split(".") + new_node = HMITreeNode(path, path[-1], v["derived"]) + hmi_tree_root.place_node(new_node) + print(hmi_tree_root.pprint()) # TODO generate C code to observe/access HMI tree variables
svghmi_c_filepath = paths.AbsNeighbourFile(__file__, "svghmi.c")
--- a/tests/svghmi/plc.xml Mon Aug 12 13:09:55 2019 +0200
+++ b/tests/svghmi/plc.xml Tue Aug 13 14:04:13 2019 +0200
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201">
<fileHeader companyName="Unknown" productName="Unnamed" productVersion="1" creationDateTime="2019-08-06T14:23:42"/>
- <contentHeader name="Unnamed" modificationDateTime="2019-08-09T11:20:07">
+ <contentHeader name="Unnamed" modificationDateTime="2019-08-13T10:34:09"> @@ -22,7 +22,12 @@
<variable name="LocalVar0">
+ <derived name="HMI_INT"/> + <variable name="Pump0"> @@ -85,7 +90,93 @@
<relPosition x="60" y="10"/>
- <expression>DINT#1</expression>
+ <expression>1</expression> + <block localId="4" typeName="Pump" instanceName="Pump0" executionOrderId="0" height="20" width="45"> + <position x="595" y="50"/> + <pou name="Pump" pouType="functionBlock"> + <derived name="HMI_LABEL"/> + <variable name="Pressure"> + <derived name="HMI_INT"/> + <inOutVariable localId="1" executionOrderId="0" height="30" width="75" negatedOut="false" negatedIn="false"> + <position x="285" y="105"/> + <relPosition x="0" y="15"/> + <connection refLocalId="2" formalParameter="OUT"> + <position x="285" y="120"/> + <position x="275" y="120"/> + <position x="275" y="95"/> + <position x="550" y="95"/> + <position x="550" y="135"/> + <position x="540" y="135"/> + <relPosition x="75" y="15"/> + <expression>Pressure</expression> + <block localId="2" typeName="ADD" executionOrderId="0" height="60" width="65"> + <position x="475" y="105"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="30"/> + <connection refLocalId="1"> + <position x="475" y="135"/> + <position x="417" y="135"/> + <position x="417" y="120"/> + <position x="360" y="120"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="50"/> + <connection refLocalId="3"> + <position x="475" y="155"/> + <position x="432" y="155"/> + <position x="432" y="150"/> + <position x="410" y="150"/> + <variable formalParameter="OUT"> + <relPosition x="65" y="30"/> + <inVariable localId="3" executionOrderId="0" height="25" width="30" negated="false"> + <position x="380" y="140"/> + <relPosition x="30" y="10"/> + <expression>23</expression>