editors/LDViewer.py
changeset 1736 7e61baa047f0
parent 1734 750eeb7230a1
child 1740 b789b695b5c6
equal deleted inserted replaced
1735:c02818d7e29f 1736:7e61baa047f0
    25 import wx
    25 import wx
    26 import time
    26 import time
    27 from types import *
    27 from types import *
    28 
    28 
    29 from Viewer import *
    29 from Viewer import *
       
    30 
    30 
    31 
    31 def ExtractNextBlocks(block, block_list):
    32 def ExtractNextBlocks(block, block_list):
    32     current_list = [block]
    33     current_list = [block]
    33     while len(current_list) > 0:
    34     while len(current_list) > 0:
    34         next_list = []
    35         next_list = []
    47                     next = wire.EndConnected.GetParentBlock()
    48                     next = wire.EndConnected.GetParentBlock()
    48                     if not isinstance(next, LD_PowerRail) and next not in block_list:
    49                     if not isinstance(next, LD_PowerRail) and next not in block_list:
    49                         block_list.append(next)
    50                         block_list.append(next)
    50                         next_list.append(next)
    51                         next_list.append(next)
    51         current_list = next_list
    52         current_list = next_list
       
    53 
    52 
    54 
    53 def CalcBranchSize(elements, stops):
    55 def CalcBranchSize(elements, stops):
    54     branch_size = 0
    56     branch_size = 0
    55     stop_list = stops
    57     stop_list = stops
    56     for stop in stops:
    58     for stop in stops:
    89                 branch_size += values["weight"]
    91                 branch_size += values["weight"]
    90             else:
    92             else:
    91                 return 1
    93                 return 1
    92     return branch_size
    94     return branch_size
    93 
    95 
       
    96 
    94 def RemoveElement(remove, element_tree):
    97 def RemoveElement(remove, element_tree):
    95     if remove in element_tree and element_tree[remove]:
    98     if remove in element_tree and element_tree[remove]:
    96         for child in element_tree[remove]["children"]:
    99         for child in element_tree[remove]["children"]:
    97             if child != "stop":
   100             if child != "stop":
    98                 RemoveElement(child, element_tree)
   101                 RemoveElement(child, element_tree)
    99         element_tree.pop(remove)
   102         element_tree.pop(remove)
   100 ##        element_tree[remove] = None
   103 ##        element_tree[remove] = None
       
   104 
   101 
   105 
   102 def GenerateTree(element, element_tree, stop_list):
   106 def GenerateTree(element, element_tree, stop_list):
   103     if element in element_tree:
   107     if element in element_tree:
   104         connectors = element.GetConnectors()
   108         connectors = element.GetConnectors()
   105         input_connectors = []
   109         input_connectors = []
   126                         element_tree[next]["parents"].append(element)
   130                         element_tree[next]["parents"].append(element)
   127                     else:
   131                     else:
   128                         element_tree[next] = {"parents":[element], "children":[], "weight":None}
   132                         element_tree[next] = {"parents":[element], "children":[], "weight":None}
   129                         GenerateTree(next, element_tree, stop_list)
   133                         GenerateTree(next, element_tree, stop_list)
   130 
   134 
       
   135 
   131 def CalcWeight(element, element_tree):
   136 def CalcWeight(element, element_tree):
   132     weight = 0
   137     weight = 0
   133     parts = None
   138     parts = None
   134     if element in element_tree:
   139     if element in element_tree:
   135         for parent in element_tree[element]["parents"]:
   140         for parent in element_tree[element]["parents"]:
   158 #-------------------------------------------------------------------------------
   163 #-------------------------------------------------------------------------------
   159 #                     Ladder Diagram Graphic elements Viewer class
   164 #                     Ladder Diagram Graphic elements Viewer class
   160 #-------------------------------------------------------------------------------
   165 #-------------------------------------------------------------------------------
   161 
   166 
   162 
   167 
   163 """
       
   164 Class derived from Viewer class that implements a Viewer of Ladder Diagram
       
   165 """
       
   166 
       
   167 class LD_Viewer(Viewer):
   168 class LD_Viewer(Viewer):
       
   169     """
       
   170     Class derived from Viewer class that implements a Viewer of Ladder Diagram
       
   171     """
   168 
   172 
   169     def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
   173     def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
   170         Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath)
   174         Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath)
   171         self.Rungs = []
   175         self.Rungs = []
   172         self.RungComments = []
   176         self.RungComments = []