svghmi/hmi_tree.py
branchsvghmi
changeset 3223 061796d9855e
parent 3197 0f41c1e2c121
child 3224 507dd7bc8cb5
equal deleted inserted replaced
3222:6adeeb16ac3e 3223:061796d9855e
     7 # See COPYING file for copyrights details.
     7 # See COPYING file for copyrights details.
     8 
     8 
     9 from __future__ import absolute_import
     9 from __future__ import absolute_import
    10 from itertools import izip, imap
    10 from itertools import izip, imap
    11 from pprint import pformat
    11 from pprint import pformat
       
    12 import weakref
    12 import hashlib
    13 import hashlib
    13 
    14 
    14 from lxml import etree
    15 from lxml import etree
    15 
    16 
    16 HMI_TYPES_DESC = {
    17 HMI_TYPES_DESC = {
    27     def __init__(self, path, name, nodetype, iectype = None, vartype = None, cpath = None, hmiclass = None):
    28     def __init__(self, path, name, nodetype, iectype = None, vartype = None, cpath = None, hmiclass = None):
    28         self.path = path
    29         self.path = path
    29         self.name = name
    30         self.name = name
    30         self.nodetype = nodetype
    31         self.nodetype = nodetype
    31         self.hmiclass = hmiclass
    32         self.hmiclass = hmiclass
       
    33         self.parent = None
    32 
    34 
    33         if iectype is not None:
    35         if iectype is not None:
    34             self.iectype = iectype
    36             self.iectype = iectype
    35             self.vartype = vartype
    37             self.vartype = vartype
    36             self.cpath = cpath
    38             self.cpath = cpath
    82             if node.nodetype == "HMI_NODE" and len(self.children) > 0:
    84             if node.nodetype == "HMI_NODE" and len(self.children) > 0:
    83                 prev = self.children[-1]
    85                 prev = self.children[-1]
    84                 if prev.path[:-1] == node.path[:-1]:
    86                 if prev.path[:-1] == node.path[:-1]:
    85                     return "Late_HMI_NODE",prev
    87                     return "Late_HMI_NODE",prev
    86 
    88 
       
    89             node.parent = weakref.ref(self)
    87             self.children.append(node)
    90             self.children.append(node)
    88             return None
    91             return None
    89 
    92 
    90     def etree(self, add_hash=False):
    93     def etree(self, add_hash=False):
    91 
    94 
   130         if hasattr(self, "children"):
   133         if hasattr(self, "children"):
   131             for c in self.children:
   134             for c in self.children:
   132                 for yoodl in c.traverse():
   135                 for yoodl in c.traverse():
   133                     yield yoodl
   136                     yield yoodl
   134 
   137 
       
   138     def hmi_path(self):
       
   139         if self.parent is None:
       
   140             return "/"
       
   141         p = self.parent()
       
   142         if p.parent is None:
       
   143             return "/" + self.name
       
   144         return p.hmi_path() + "/" + self.name
   135 
   145 
   136     def hash(self):
   146     def hash(self):
   137         """ Produce a hash, any change in HMI tree structure change that hash """
   147         """ Produce a hash, any change in HMI tree structure change that hash """
   138         s = hashlib.new('md5')
   148         s = hashlib.new('md5')
   139         self._hash(s)
   149         self._hash(s)