svghmi/svghmi.py
branchsvghmi
changeset 2762 282500e03dbc
parent 2758 5f79b194fa63
child 2763 ce04d79b8e57
equal deleted inserted replaced
2761:2684d643f60f 2762:282500e03dbc
    53         return res
    53         return res
    54 
    54 
    55     def place_node(self, node):
    55     def place_node(self, node):
    56         best_child = None
    56         best_child = None
    57         known_best_match = 0
    57         known_best_match = 0
    58         for child in self.children:
    58         for child in self.children : 
    59             in_common = 0
    59             if child.path is not None:
    60             for child_path_item, node_path_item in izip(child.path, node.path):
    60                 in_common = 0
    61                 if child_path_item == node_path_item:
    61                 for child_path_item, node_path_item in izip(child.path, node.path):
    62                     in_common +=1
    62                     if child_path_item == node_path_item:
    63                 else:
    63                         in_common +=1
    64                     break
    64                     else:
    65             if in_common > known_best_match:
    65                         break
    66                 known_best_match = in_common
    66                 if in_common > known_best_match:
    67                 best_child = child
    67                     known_best_match = in_common
       
    68                     best_child = child
    68         if best_child is not None and best_child.nodetype == "HMI_LABEL":
    69         if best_child is not None and best_child.nodetype == "HMI_LABEL":
    69             best_child.place_node(node)
    70             best_child.place_node(node)
    70         else:
    71         else:
    71             self.children.append(node)
    72             self.children.append(node)
    72             
    73             
   114         # Filter known HMI types
   115         # Filter known HMI types
   115         hmi_types_instances = [v for v in varlist if v["derived"] in HMI_TYPES]
   116         hmi_types_instances = [v for v in varlist if v["derived"] in HMI_TYPES]
   116 
   117 
   117         hmi_tree_root = HMITreeNode(None, "/", "HMI_ROOT")
   118         hmi_tree_root = HMITreeNode(None, "/", "HMI_ROOT")
   118 
   119 
   119         # TODO add always available variables here ?
   120         # add special nodes 
   120         #    - plc status
   121         map(lambda (n,t): hmi_tree_root.children.append(HMITreeNode(None,n,t)), [
   121         #    - current page
   122                 ("plc_status", "HMI_PLC_STATUS"),
   122         #    - ...
   123                 ("current_page", "HMI_CURRENT_PAGE")])
   123 
   124 
   124         # deduce HMI tree from PLC HMI_* instances
   125         # deduce HMI tree from PLC HMI_* instances
   125         for v in hmi_types_instances:
   126         for v in hmi_types_instances:
   126             path = v["IEC_path"].split(".")
   127             path = v["IEC_path"].split(".")
   127             # ignores variables starting with _TMP_
   128             # ignores variables starting with _TMP_