editors/LDViewer.py
changeset 1740 b789b695b5c6
parent 1736 7e61baa047f0
child 1744 69dfdb26f600
equal deleted inserted replaced
1739:ec153828ded2 1740:b789b695b5c6
    58     for stop in stops:
    58     for stop in stops:
    59         ExtractNextBlocks(stop, stop_list)
    59         ExtractNextBlocks(stop, stop_list)
    60     element_tree = {}
    60     element_tree = {}
    61     for element in elements:
    61     for element in elements:
    62         if element not in element_tree:
    62         if element not in element_tree:
    63             element_tree[element] = {"parents":["start"], "children":[], "weight":None}
    63             element_tree[element] = {"parents": ["start"], "children": [], "weight": None}
    64             GenerateTree(element, element_tree, stop_list)
    64             GenerateTree(element, element_tree, stop_list)
    65         elif element_tree[element]:
    65         elif element_tree[element]:
    66             element_tree[element]["parents"].append("start")
    66             element_tree[element]["parents"].append("start")
    67     remove_stops = {"start":[], "stop":[]}
    67     remove_stops = {"start": [], "stop": []}
    68     for element, values in element_tree.items():
    68     for element, values in element_tree.items():
    69         if "stop" in values["children"]:
    69         if "stop" in values["children"]:
    70             removed = []
    70             removed = []
    71             for child in values["children"]:
    71             for child in values["children"]:
    72                 if child != "stop":
    72                 if child != "stop":
   127                 elif next not in element_tree or element_tree[next]:
   127                 elif next not in element_tree or element_tree[next]:
   128                     element_tree[element]["children"].append(next)
   128                     element_tree[element]["children"].append(next)
   129                     if next in element_tree:
   129                     if next in element_tree:
   130                         element_tree[next]["parents"].append(element)
   130                         element_tree[next]["parents"].append(element)
   131                     else:
   131                     else:
   132                         element_tree[next] = {"parents":[element], "children":[], "weight":None}
   132                         element_tree[next] = {"parents": [element], "children": [], "weight": None}
   133                         GenerateTree(next, element_tree, stop_list)
   133                         GenerateTree(next, element_tree, stop_list)
   134 
   134 
   135 
   135 
   136 def CalcWeight(element, element_tree):
   136 def CalcWeight(element, element_tree):
   137     weight = 0
   137     weight = 0
   492                     varlist.append(var.Name)
   492                     varlist.append(var.Name)
   493         returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug)
   493         returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug)
   494         if returntype == "BOOL":
   494         if returntype == "BOOL":
   495             varlist.append(self.Controler.GetEditedElementName(self.TagName))
   495             varlist.append(self.Controler.GetEditedElementName(self.TagName))
   496         dialog.SetVariables(varlist)
   496         dialog.SetVariables(varlist)
   497         dialog.SetValues({"name":"","type":COIL_NORMAL})
   497         dialog.SetValues({"name": "", "type": COIL_NORMAL})
   498         if dialog.ShowModal() == wx.ID_OK:
   498         if dialog.ShowModal() == wx.ID_OK:
   499             values = dialog.GetValues()
   499             values = dialog.GetValues()
   500             startx, starty = LD_OFFSET[0], 0
   500             startx, starty = LD_OFFSET[0], 0
   501             if len(self.Rungs) > 0:
   501             if len(self.Rungs) > 0:
   502                 bbox = self.Rungs[-1].GetBoundingBox()
   502                 bbox = self.Rungs[-1].GetBoundingBox()
   575         wires = []
   575         wires = []
   576         if self.IsWire(self.SelectedElement):
   576         if self.IsWire(self.SelectedElement):
   577             left_element = self.SelectedElement.EndConnected
   577             left_element = self.SelectedElement.EndConnected
   578             if not isinstance(left_element.GetParentBlock(), LD_Coil):
   578             if not isinstance(left_element.GetParentBlock(), LD_Coil):
   579                 wires.append(self.SelectedElement)
   579                 wires.append(self.SelectedElement)
   580         elif self.SelectedElement and isinstance(self.SelectedElement,Graphic_Group):
   580         elif self.SelectedElement and isinstance(self.SelectedElement, Graphic_Group):
   581             if False not in [self.IsWire(element) for element in self.SelectedElement.GetElements()]:
   581             if False not in [self.IsWire(element) for element in self.SelectedElement.GetElements()]:
   582                 for element in self.SelectedElement.GetElements():
   582                 for element in self.SelectedElement.GetElements():
   583                     wires.append(element)
   583                     wires.append(element)
   584         if len(wires) > 0:
   584         if len(wires) > 0:
   585             dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
   585             dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
   589             if vars:
   589             if vars:
   590                 for var in vars:
   590                 for var in vars:
   591                     if var.Class != "Output" and var.Type == "BOOL":
   591                     if var.Class != "Output" and var.Type == "BOOL":
   592                         varlist.append(var.Name)
   592                         varlist.append(var.Name)
   593             dialog.SetVariables(varlist)
   593             dialog.SetVariables(varlist)
   594             dialog.SetValues({"name":"","type":CONTACT_NORMAL})
   594             dialog.SetValues({"name": "", "type": CONTACT_NORMAL})
   595             if dialog.ShowModal() == wx.ID_OK:
   595             if dialog.ShowModal() == wx.ID_OK:
   596                 values = dialog.GetValues()
   596                 values = dialog.GetValues()
   597                 points = wires[0].GetSelectedSegmentPoints()
   597                 points = wires[0].GetSelectedSegmentPoints()
   598                 id = self.GetNewId()
   598                 id = self.GetNewId()
   599                 contact = LD_Contact(self, values["type"], values["name"], id)
   599                 contact = LD_Contact(self, values["type"], values["name"], id)
   684             left_index = []
   684             left_index = []
   685             right_elements = []
   685             right_elements = []
   686             right_index = []
   686             right_index = []
   687             for block in blocks:
   687             for block in blocks:
   688                 connectors = block.GetConnectors()
   688                 connectors = block.GetConnectors()
   689                 block_infos = {"lefts":[],"rights":[]}
   689                 block_infos = {"lefts": [], "rights": []}
   690                 block_infos.update(connectors)
   690                 block_infos.update(connectors)
   691                 for connector in block_infos["inputs"]:
   691                 for connector in block_infos["inputs"]:
   692                     for wire, handle in connector.GetWires():
   692                     for wire, handle in connector.GetWires():
   693                         found = False
   693                         found = False
   694                         for infos in blocks_infos:
   694                         for infos in blocks_infos:
   806                                     varlist.append(var.Name)
   806                                     varlist.append(var.Name)
   807                         returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug)
   807                         returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug)
   808                         if returntype == "BOOL":
   808                         if returntype == "BOOL":
   809                             varlist.append(self.Controler.GetEditedElementName(self.TagName))
   809                             varlist.append(self.Controler.GetEditedElementName(self.TagName))
   810                         dialog.SetVariables(varlist)
   810                         dialog.SetVariables(varlist)
   811                         dialog.SetValues({"name":"","type":COIL_NORMAL})
   811                         dialog.SetValues({"name": "", "type": COIL_NORMAL})
   812                         if dialog.ShowModal() == wx.ID_OK:
   812                         if dialog.ShowModal() == wx.ID_OK:
   813                             values = dialog.GetValues()
   813                             values = dialog.GetValues()
   814                             powerrail = right_elements[0].GetParentBlock()
   814                             powerrail = right_elements[0].GetParentBlock()
   815                             index = 0
   815                             index = 0
   816                             for right_element in right_elements:
   816                             for right_element in right_elements: