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 |
52 |
53 |
|
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: |
57 ExtractNextBlocks(stop, stop_list) |
59 ExtractNextBlocks(stop, stop_list) |
58 element_tree = {} |
60 element_tree = {} |
59 for element in elements: |
61 for element in elements: |
60 if element not in element_tree: |
62 if element not in element_tree: |
61 element_tree[element] = {"parents":["start"], "children":[], "weight":None} |
63 element_tree[element] = {"parents": ["start"], "children": [], "weight": None} |
62 GenerateTree(element, element_tree, stop_list) |
64 GenerateTree(element, element_tree, stop_list) |
63 elif element_tree[element]: |
65 elif element_tree[element]: |
64 element_tree[element]["parents"].append("start") |
66 element_tree[element]["parents"].append("start") |
65 remove_stops = {"start":[], "stop":[]} |
67 remove_stops = {"start": [], "stop": []} |
66 for element, values in element_tree.items(): |
68 for element, values in element_tree.items(): |
67 if "stop" in values["children"]: |
69 if "stop" in values["children"]: |
68 removed = [] |
70 removed = [] |
69 for child in values["children"]: |
71 for child in values["children"]: |
70 if child != "stop": |
72 if child != "stop": |
71 ## if child in elements: |
73 # if child in elements: |
72 ## RemoveElement(child, element_tree) |
74 # RemoveElement(child, element_tree) |
73 ## removed.append(child) |
75 # removed.append(child) |
74 if "start" in element_tree[child]["parents"]: |
76 if "start" in element_tree[child]["parents"]: |
75 if element not in remove_stops["stop"]: |
77 if element not in remove_stops["stop"]: |
76 remove_stops["stop"].append(element) |
78 remove_stops["stop"].append(element) |
77 if child not in remove_stops["start"]: |
79 if child not in remove_stops["start"]: |
78 remove_stops["start"].append(child) |
80 remove_stops["start"].append(child) |
87 CalcWeight(element, element_tree) |
89 CalcWeight(element, element_tree) |
88 if values["weight"]: |
90 if values["weight"]: |
89 branch_size += values["weight"] |
91 branch_size += values["weight"] |
90 else: |
92 else: |
91 return 1 |
93 return 1 |
92 #print branch_size |
|
93 return branch_size |
94 return branch_size |
|
95 |
94 |
96 |
95 def RemoveElement(remove, element_tree): |
97 def RemoveElement(remove, element_tree): |
96 if remove in element_tree and element_tree[remove]: |
98 if remove in element_tree and element_tree[remove]: |
97 for child in element_tree[remove]["children"]: |
99 for child in element_tree[remove]["children"]: |
98 if child != "stop": |
100 if child != "stop": |
99 RemoveElement(child, element_tree) |
101 RemoveElement(child, element_tree) |
100 element_tree.pop(remove) |
102 element_tree.pop(remove) |
101 ## element_tree[remove] = None |
103 # element_tree[remove] = None |
|
104 |
102 |
105 |
103 def GenerateTree(element, element_tree, stop_list): |
106 def GenerateTree(element, element_tree, stop_list): |
104 if element in element_tree: |
107 if element in element_tree: |
105 connectors = element.GetConnectors() |
108 connectors = element.GetConnectors() |
106 input_connectors = [] |
109 input_connectors = [] |
113 input_connectors = [connectors["input"]] |
116 input_connectors = [connectors["input"]] |
114 for connector in input_connectors: |
117 for connector in input_connectors: |
115 for wire, handle in connector.GetWires(): |
118 for wire, handle in connector.GetWires(): |
116 next = wire.EndConnected.GetParentBlock() |
119 next = wire.EndConnected.GetParentBlock() |
117 if isinstance(next, LD_PowerRail) and next.GetType() == LEFTRAIL or next in stop_list: |
120 if isinstance(next, LD_PowerRail) and next.GetType() == LEFTRAIL or next in stop_list: |
118 ## for remove in element_tree[element]["children"]: |
121 # for remove in element_tree[element]["children"]: |
119 ## RemoveElement(remove, element_tree) |
122 # RemoveElement(remove, element_tree) |
120 ## element_tree[element]["children"] = ["stop"] |
123 # element_tree[element]["children"] = ["stop"] |
121 element_tree[element]["children"].append("stop") |
124 element_tree[element]["children"].append("stop") |
122 ## elif element_tree[element]["children"] == ["stop"]: |
125 # elif element_tree[element]["children"] == ["stop"]: |
123 ## element_tree[next] = None |
126 # element_tree[next] = None |
124 elif next not in element_tree or element_tree[next]: |
127 elif next not in element_tree or element_tree[next]: |
125 element_tree[element]["children"].append(next) |
128 element_tree[element]["children"].append(next) |
126 if next in element_tree: |
129 if next in element_tree: |
127 element_tree[next]["parents"].append(element) |
130 element_tree[next]["parents"].append(element) |
128 else: |
131 else: |
129 element_tree[next] = {"parents":[element], "children":[], "weight":None} |
132 element_tree[next] = {"parents": [element], "children": [], "weight": None} |
130 GenerateTree(next, element_tree, stop_list) |
133 GenerateTree(next, element_tree, stop_list) |
|
134 |
131 |
135 |
132 def CalcWeight(element, element_tree): |
136 def CalcWeight(element, element_tree): |
133 weight = 0 |
137 weight = 0 |
134 parts = None |
138 parts = None |
135 if element in element_tree: |
139 if element in element_tree: |
154 if not parts: |
158 if not parts: |
155 parts = 1 |
159 parts = 1 |
156 element_tree[element]["weight"] = max(1, weight / parts) |
160 element_tree[element]["weight"] = max(1, weight / parts) |
157 |
161 |
158 |
162 |
159 #------------------------------------------------------------------------------- |
163 # ------------------------------------------------------------------------------- |
160 # Ladder Diagram Graphic elements Viewer class |
164 # Ladder Diagram Graphic elements Viewer class |
161 #------------------------------------------------------------------------------- |
165 # ------------------------------------------------------------------------------- |
162 |
166 |
163 |
|
164 """ |
|
165 Class derived from Viewer class that implements a Viewer of Ladder Diagram |
|
166 """ |
|
167 |
167 |
168 class LD_Viewer(Viewer): |
168 class LD_Viewer(Viewer): |
169 |
169 """ |
170 def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
170 Class derived from Viewer class that implements a Viewer of Ladder Diagram |
|
171 """ |
|
172 |
|
173 def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""): |
171 Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
174 Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
172 self.Rungs = [] |
175 self.Rungs = [] |
173 self.RungComments = [] |
176 self.RungComments = [] |
174 self.CurrentLanguage = "LD" |
177 self.CurrentLanguage = "LD" |
175 |
178 |
176 #------------------------------------------------------------------------------- |
179 # ------------------------------------------------------------------------------- |
177 # Refresh functions |
180 # Refresh functions |
178 #------------------------------------------------------------------------------- |
181 # ------------------------------------------------------------------------------- |
179 |
182 |
180 def ResetView(self): |
183 def ResetView(self): |
181 self.Rungs = [] |
184 self.Rungs = [] |
182 self.RungComments = [] |
185 self.RungComments = [] |
183 Viewer.ResetView(self) |
186 Viewer.ResetView(self) |
226 connected = self.FindElementById(link["refLocalId"]) |
232 connected = self.FindElementById(link["refLocalId"]) |
227 rung = self.FindRung(connected) |
233 rung = self.FindRung(connected) |
228 if rung not in rungs: |
234 if rung not in rungs: |
229 rungs.append(rung) |
235 rungs.append(rung) |
230 if len(rungs) > 1: |
236 if len(rungs) > 1: |
231 raise ValueError, _("Ladder element with id %d is on more than one rung.")%instance["id"] |
237 raise ValueError( |
|
238 _("Ladder element with id %d is on more than one rung.") |
|
239 % instance["id"]) |
|
240 |
232 element = self.FindElementById(instance["id"]) |
241 element = self.FindElementById(instance["id"]) |
233 element_connectors = element.GetConnectors() |
242 element_connectors = element.GetConnectors() |
234 self.Rungs[rungs[0]].SelectElement(element) |
243 self.Rungs[rungs[0]].SelectElement(element) |
235 for wire, num in element_connectors["inputs"][0].GetWires(): |
244 for wire, num in element_connectors["inputs"][0].GetWires(): |
236 self.Rungs[rungs[0]].SelectElement(wire) |
245 self.Rungs[rungs[0]].SelectElement(wire) |
237 wx.CallAfter(self.RefreshPosition, element) |
246 wx.CallAfter(self.RefreshPosition, element) |
238 elif instance["type"] == "comment": |
247 elif instance["type"] == "comment": |
239 element = self.FindElementById(instance["id"]) |
248 element = self.FindElementById(instance["id"]) |
240 pos = element.GetPosition() |
249 pos = element.GetPosition() |
241 i = 0 |
250 i = 0 |
242 inserted = False |
251 inserted = False |
243 while i < len(self.RungComments) and not inserted: |
252 while i < len(self.RungComments) and not inserted: |
244 ipos = self.RungComments[i].GetPosition() |
253 ipos = self.RungComments[i].GetPosition() |
245 if pos[1] < ipos[1]: |
254 if pos[1] < ipos[1]: |
246 self.RungComments.insert(i, element) |
255 self.RungComments.insert(i, element) |
247 inserted = True |
256 inserted = True |
248 i += 1 |
257 i += 1 |
249 if not inserted: |
258 if not inserted: |
250 self.RungComments.append(element) |
259 self.RungComments.append(element) |
251 |
260 |
252 #------------------------------------------------------------------------------- |
261 # ------------------------------------------------------------------------------- |
253 # Search Element functions |
262 # Search Element functions |
254 #------------------------------------------------------------------------------- |
263 # ------------------------------------------------------------------------------- |
255 |
264 |
256 def FindRung(self, element): |
265 def FindRung(self, element): |
257 for i, rung in enumerate(self.Rungs): |
266 for i, rung in enumerate(self.Rungs): |
258 if rung.IsElementIn(element): |
267 if rung.IsElementIn(element): |
259 return i |
268 return i |
260 return None |
269 return None |
261 |
270 |
262 def FindElement(self, event, exclude_group = False, connectors = True): |
271 def FindElement(self, event, exclude_group=False, connectors=True): |
263 if self.GetDrawingMode() == FREEDRAWING_MODE: |
272 if self.GetDrawingMode() == FREEDRAWING_MODE: |
264 return Viewer.FindElement(self, event, exclude_group, connectors) |
273 return Viewer.FindElement(self, event, exclude_group, connectors) |
265 |
274 |
266 dc = self.GetLogicalDC() |
275 dc = self.GetLogicalDC() |
267 pos = event.GetLogicalPosition(dc) |
276 pos = event.GetLogicalPosition(dc) |
268 if self.SelectedElement and not isinstance(self.SelectedElement, (Graphic_Group, Wire)): |
277 if self.SelectedElement and not isinstance(self.SelectedElement, (Graphic_Group, Wire)): |
269 if self.SelectedElement.HitTest(pos, connectors) or self.SelectedElement.TestHandle(pos) != (0, 0): |
278 if self.SelectedElement.HitTest(pos, connectors) or self.SelectedElement.TestHandle(pos) != (0, 0): |
270 return self.SelectedElement |
279 return self.SelectedElement |
284 return None |
293 return None |
285 |
294 |
286 def SearchElements(self, bbox): |
295 def SearchElements(self, bbox): |
287 if self.GetDrawingMode() == FREEDRAWING_MODE: |
296 if self.GetDrawingMode() == FREEDRAWING_MODE: |
288 return Viewer.SearchElements(self, bbox) |
297 return Viewer.SearchElements(self, bbox) |
289 |
298 |
290 elements = [] |
299 elements = [] |
291 for element in self.Blocks.values() + self.Comments.values(): |
300 for element in self.Blocks.values() + self.Comments.values(): |
292 if element.IsInSelection(bbox): |
301 if element.IsInSelection(bbox): |
293 elements.append(element) |
302 elements.append(element) |
294 return elements |
303 return elements |
295 |
304 |
296 #------------------------------------------------------------------------------- |
305 # ------------------------------------------------------------------------------- |
297 # Mouse event functions |
306 # Mouse event functions |
298 #------------------------------------------------------------------------------- |
307 # ------------------------------------------------------------------------------- |
299 |
308 |
300 def OnViewerLeftDown(self, event): |
309 def OnViewerLeftDown(self, event): |
301 if self.GetDrawingMode() == FREEDRAWING_MODE: |
310 if self.GetDrawingMode() == FREEDRAWING_MODE: |
302 Viewer.OnViewerLeftDown(self, event) |
311 Viewer.OnViewerLeftDown(self, event) |
303 elif self.Mode == MODE_SELECTION: |
312 elif self.Mode == MODE_SELECTION: |
489 varlist.append(var.Name) |
498 varlist.append(var.Name) |
490 returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug) |
499 returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug) |
491 if returntype == "BOOL": |
500 if returntype == "BOOL": |
492 varlist.append(self.Controler.GetEditedElementName(self.TagName)) |
501 varlist.append(self.Controler.GetEditedElementName(self.TagName)) |
493 dialog.SetVariables(varlist) |
502 dialog.SetVariables(varlist) |
494 dialog.SetValues({"name":"","type":COIL_NORMAL}) |
503 dialog.SetValues({"name": "", "type": COIL_NORMAL}) |
495 if dialog.ShowModal() == wx.ID_OK: |
504 if dialog.ShowModal() == wx.ID_OK: |
496 values = dialog.GetValues() |
505 values = dialog.GetValues() |
497 startx, starty = LD_OFFSET[0], 0 |
506 startx, starty = LD_OFFSET[0], 0 |
498 if len(self.Rungs) > 0: |
507 if len(self.Rungs) > 0: |
499 bbox = self.Rungs[-1].GetBoundingBox() |
508 bbox = self.Rungs[-1].GetBoundingBox() |
500 starty = bbox.y + bbox.height |
509 starty = bbox.y + bbox.height |
501 starty += LD_OFFSET[1] |
510 starty += LD_OFFSET[1] |
502 rung = Graphic_Group(self) |
511 rung = Graphic_Group(self) |
503 |
512 |
504 # Create comment |
513 # Create comment |
505 id = self.GetNewId() |
514 id = self.GetNewId() |
506 comment = Comment(self, _("Comment"), id) |
515 comment = Comment(self, _("Comment"), id) |
507 comment.SetPosition(startx, starty) |
516 comment.SetPosition(startx, starty) |
508 comment.SetSize(LD_COMMENT_DEFAULTSIZE[0], LD_COMMENT_DEFAULTSIZE[1]) |
517 comment.SetSize(LD_COMMENT_DEFAULTSIZE[0], LD_COMMENT_DEFAULTSIZE[1]) |
509 self.AddComment(comment) |
518 self.AddComment(comment) |
510 self.RungComments.append(comment) |
519 self.RungComments.append(comment) |
511 self.Controler.AddEditedElementComment(self.TagName, id) |
520 self.Controler.AddEditedElementComment(self.TagName, id) |
512 self.RefreshCommentModel(comment) |
521 self.RefreshCommentModel(comment) |
513 starty += LD_COMMENT_DEFAULTSIZE[1] + LD_OFFSET[1] |
522 starty += LD_COMMENT_DEFAULTSIZE[1] + LD_OFFSET[1] |
514 |
523 |
515 # Create LeftPowerRail |
524 # Create LeftPowerRail |
516 id = self.GetNewId() |
525 id = self.GetNewId() |
517 leftpowerrail = LD_PowerRail(self, LEFTRAIL, id) |
526 leftpowerrail = LD_PowerRail(self, LEFTRAIL, id) |
518 leftpowerrail.SetPosition(startx, starty) |
527 leftpowerrail.SetPosition(startx, starty) |
519 leftpowerrail_connectors = leftpowerrail.GetConnectors() |
528 leftpowerrail_connectors = leftpowerrail.GetConnectors() |
520 self.AddBlock(leftpowerrail) |
529 self.AddBlock(leftpowerrail) |
521 rung.SelectElement(leftpowerrail) |
530 rung.SelectElement(leftpowerrail) |
522 self.Controler.AddEditedElementPowerRail(self.TagName, id, LEFTRAIL) |
531 self.Controler.AddEditedElementPowerRail(self.TagName, id, LEFTRAIL) |
523 self.RefreshPowerRailModel(leftpowerrail) |
532 self.RefreshPowerRailModel(leftpowerrail) |
524 |
533 |
525 # Create Coil |
534 # Create Coil |
526 id = self.GetNewId() |
535 id = self.GetNewId() |
527 coil = LD_Coil(self, values["type"], values["name"], id) |
536 coil = LD_Coil(self, values["type"], values["name"], id) |
528 coil.SetPosition(startx, starty + (LD_LINE_SIZE - LD_ELEMENT_SIZE[1]) / 2) |
537 coil.SetPosition(startx, starty + (LD_LINE_SIZE - LD_ELEMENT_SIZE[1]) / 2) |
529 coil_connectors = coil.GetConnectors() |
538 coil_connectors = coil.GetConnectors() |
530 self.AddBlock(coil) |
539 self.AddBlock(coil) |
531 rung.SelectElement(coil) |
540 rung.SelectElement(coil) |
532 self.Controler.AddEditedElementCoil(self.TagName, id) |
541 self.Controler.AddEditedElementCoil(self.TagName, id) |
533 |
542 |
534 # Create Wire between LeftPowerRail and Coil |
543 # Create Wire between LeftPowerRail and Coil |
535 wire = Wire(self) |
544 wire = Wire(self) |
536 start_connector = coil_connectors["inputs"][0] |
545 start_connector = coil_connectors["inputs"][0] |
537 end_connector = leftpowerrail_connectors["outputs"][0] |
546 end_connector = leftpowerrail_connectors["outputs"][0] |
538 start_connector.Connect((wire, 0), False) |
547 start_connector.Connect((wire, 0), False) |
539 end_connector.Connect((wire, -1), False) |
548 end_connector.Connect((wire, -1), False) |
540 wire.ConnectStartPoint(None, start_connector) |
549 wire.ConnectStartPoint(None, start_connector) |
541 wire.ConnectEndPoint(None, end_connector) |
550 wire.ConnectEndPoint(None, end_connector) |
542 self.AddWire(wire) |
551 self.AddWire(wire) |
543 rung.SelectElement(wire) |
552 rung.SelectElement(wire) |
544 |
553 |
545 # Create RightPowerRail |
554 # Create RightPowerRail |
546 id = self.GetNewId() |
555 id = self.GetNewId() |
547 rightpowerrail = LD_PowerRail(self, RIGHTRAIL, id) |
556 rightpowerrail = LD_PowerRail(self, RIGHTRAIL, id) |
548 rightpowerrail.SetPosition(startx, starty) |
557 rightpowerrail.SetPosition(startx, starty) |
549 rightpowerrail_connectors = rightpowerrail.GetConnectors() |
558 rightpowerrail_connectors = rightpowerrail.GetConnectors() |
550 self.AddBlock(rightpowerrail) |
559 self.AddBlock(rightpowerrail) |
551 rung.SelectElement(rightpowerrail) |
560 rung.SelectElement(rightpowerrail) |
552 self.Controler.AddEditedElementPowerRail(self.TagName, id, RIGHTRAIL) |
561 self.Controler.AddEditedElementPowerRail(self.TagName, id, RIGHTRAIL) |
553 |
562 |
554 # Create Wire between LeftPowerRail and Coil |
563 # Create Wire between LeftPowerRail and Coil |
555 wire = Wire(self) |
564 wire = Wire(self) |
556 start_connector = rightpowerrail_connectors["inputs"][0] |
565 start_connector = rightpowerrail_connectors["inputs"][0] |
557 end_connector = coil_connectors["outputs"][0] |
566 end_connector = coil_connectors["outputs"][0] |
558 start_connector.Connect((wire, 0), False) |
567 start_connector.Connect((wire, 0), False) |
803 varlist.append(var.Name) |
812 varlist.append(var.Name) |
804 returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug) |
813 returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug) |
805 if returntype == "BOOL": |
814 if returntype == "BOOL": |
806 varlist.append(self.Controler.GetEditedElementName(self.TagName)) |
815 varlist.append(self.Controler.GetEditedElementName(self.TagName)) |
807 dialog.SetVariables(varlist) |
816 dialog.SetVariables(varlist) |
808 dialog.SetValues({"name":"","type":COIL_NORMAL}) |
817 dialog.SetValues({"name": "", "type": COIL_NORMAL}) |
809 if dialog.ShowModal() == wx.ID_OK: |
818 if dialog.ShowModal() == wx.ID_OK: |
810 values = dialog.GetValues() |
819 values = dialog.GetValues() |
811 powerrail = right_elements[0].GetParentBlock() |
820 powerrail = right_elements[0].GetParentBlock() |
812 index = 0 |
821 index = 0 |
813 for right_element in right_elements: |
822 for right_element in right_elements: |
814 index = max(index, powerrail.GetConnectorIndex(right_element)) |
823 index = max(index, powerrail.GetConnectorIndex(right_element)) |
815 powerrail.InsertConnector(index + 1) |
824 powerrail.InsertConnector(index + 1) |
816 powerrail.RefreshModel() |
825 powerrail.RefreshModel() |
817 connectors = powerrail.GetConnectors() |
826 connectors = powerrail.GetConnectors() |
818 |
827 |
819 # Create Coil |
828 # Create Coil |
820 id = self.GetNewId() |
829 id = self.GetNewId() |
821 coil = LD_Coil(self, values["type"], values["name"], id) |
830 coil = LD_Coil(self, values["type"], values["name"], id) |
822 pos = blocks[0].GetPosition() |
831 pos = blocks[0].GetPosition() |
823 coil.SetPosition(pos[0], pos[1] + LD_LINE_SIZE) |
832 coil.SetPosition(pos[0], pos[1] + LD_LINE_SIZE) |
824 self.AddBlock(coil) |
833 self.AddBlock(coil) |
825 rung.SelectElement(coil) |
834 rung.SelectElement(coil) |
826 self.Controler.AddEditedElementCoil(self.TagName, id) |
835 self.Controler.AddEditedElementCoil(self.TagName, id) |
827 coil_connectors = coil.GetConnectors() |
836 coil_connectors = coil.GetConnectors() |
828 |
837 |
829 # Create Wire between LeftPowerRail and Coil |
838 # Create Wire between LeftPowerRail and Coil |
830 wire = Wire(self) |
839 wire = Wire(self) |
831 connectors["inputs"][index + 1].Connect((wire, 0), False) |
840 connectors["inputs"][index + 1].Connect((wire, 0), False) |
832 coil_connectors["outputs"][0].Connect((wire, -1), False) |
841 coil_connectors["outputs"][0].Connect((wire, -1), False) |
833 wire.ConnectStartPoint(None, connectors["inputs"][index + 1]) |
842 wire.ConnectStartPoint(None, connectors["inputs"][index + 1]) |
834 wire.ConnectEndPoint(None, coil_connectors["outputs"][0]) |
843 wire.ConnectEndPoint(None, coil_connectors["outputs"][0]) |
835 self.AddWire(wire) |
844 self.AddWire(wire) |
836 rung.SelectElement(wire) |
845 rung.SelectElement(wire) |
837 left_elements.reverse() |
846 left_elements.reverse() |
838 |
847 |
839 for i, left_element in enumerate(left_elements): |
848 for i, left_element in enumerate(left_elements): |
840 # Create Wire between LeftPowerRail and Coil |
849 # Create Wire between LeftPowerRail and Coil |
841 new_wire = Wire(self) |
850 new_wire = Wire(self) |
842 wires.append(new_wire) |
851 wires.append(new_wire) |
843 coil_connectors["inputs"][0].Connect((new_wire, 0), False) |
852 coil_connectors["inputs"][0].Connect((new_wire, 0), False) |
844 left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False) |
853 left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False) |
845 new_wire.ConnectStartPoint(None, coil_connectors["inputs"][0]) |
854 new_wire.ConnectStartPoint(None, coil_connectors["inputs"][0]) |
846 new_wire.ConnectEndPoint(None, left_element) |
855 new_wire.ConnectEndPoint(None, left_element) |
847 |
856 |
848 self.RefreshPosition(coil) |
857 self.RefreshPosition(coil) |
849 else: |
858 else: |
850 left_elements.reverse() |
859 left_elements.reverse() |
851 right_elements.reverse() |
860 right_elements.reverse() |
852 for i, left_element in enumerate(left_elements): |
861 for i, left_element in enumerate(left_elements): |
877 self.RefreshBuffer() |
886 self.RefreshBuffer() |
878 self.RefreshScrollBars() |
887 self.RefreshScrollBars() |
879 self.RefreshVisibleElements() |
888 self.RefreshVisibleElements() |
880 self.Refresh(False) |
889 self.Refresh(False) |
881 else: |
890 else: |
882 message = wx.MessageDialog(self, _("The group of block must be coherent!"), _("Error"), wx.OK|wx.ICON_ERROR) |
891 message = wx.MessageDialog(self, _("The group of block must be coherent!"), _("Error"), wx.OK | wx.ICON_ERROR) |
883 message.ShowModal() |
892 message.ShowModal() |
884 message.Destroy() |
893 message.Destroy() |
885 else: |
894 else: |
886 message = wx.MessageDialog(self, _("You must select the block or group of blocks around which a branch should be added!"), _("Error"), wx.OK|wx.ICON_ERROR) |
895 message = wx.MessageDialog(self, _("You must select the block or group of blocks around which a branch should be added!"), _("Error"), wx.OK | wx.ICON_ERROR) |
887 message.ShowModal() |
896 message.ShowModal() |
888 message.Destroy() |
897 message.Destroy() |
889 |
898 |
890 def AddLadderBlock(self): |
899 def AddLadderBlock(self): |
891 message = wx.MessageDialog(self, _("This option isn't available yet!"), _("Warning"), wx.OK|wx.ICON_EXCLAMATION) |
900 message = wx.MessageDialog(self, _("This option isn't available yet!"), _("Warning"), wx.OK | wx.ICON_EXCLAMATION) |
892 message.ShowModal() |
901 message.ShowModal() |
893 message.Destroy() |
902 message.Destroy() |
894 |
903 |
895 #------------------------------------------------------------------------------- |
904 # ------------------------------------------------------------------------------- |
896 # Delete element functions |
905 # Delete element functions |
897 #------------------------------------------------------------------------------- |
906 # ------------------------------------------------------------------------------- |
898 |
907 |
899 def DeleteContact(self, contact): |
908 def DeleteContact(self, contact): |
900 if self.GetDrawingMode() == FREEDRAWING_MODE: |
909 if self.GetDrawingMode() == FREEDRAWING_MODE: |
901 Viewer.DeleteContact(self, contact) |
910 Viewer.DeleteContact(self, contact) |
902 else: |
911 else: |
1078 rung.RefreshBoundingBox() |
1087 rung.RefreshBoundingBox() |
1079 new_bbox = rung.GetBoundingBox() |
1088 new_bbox = rung.GetBoundingBox() |
1080 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
1089 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
1081 self.SelectedElement = None |
1090 self.SelectedElement = None |
1082 |
1091 |
1083 #------------------------------------------------------------------------------- |
1092 # ------------------------------------------------------------------------------- |
1084 # Refresh element position functions |
1093 # Refresh element position functions |
1085 #------------------------------------------------------------------------------- |
1094 # ------------------------------------------------------------------------------- |
1086 |
1095 |
1087 def RefreshPosition(self, element, recursive=True): |
1096 def RefreshPosition(self, element, recursive=True): |
1088 # If element is LeftPowerRail, no need to update position |
1097 # If element is LeftPowerRail, no need to update position |
1089 if isinstance(element, LD_PowerRail) and element.GetType() == LEFTRAIL: |
1098 if isinstance(element, LD_PowerRail) and element.GetType() == LEFTRAIL: |
1090 element.RefreshModel() |
1099 element.RefreshModel() |
1091 return |
1100 return |
1092 |
1101 |
1093 # Extract max position of the elements connected to input |
1102 # Extract max position of the elements connected to input |
1094 connectors = element.GetConnectors() |
1103 connectors = element.GetConnectors() |
1095 position = element.GetPosition() |
1104 position = element.GetPosition() |
1096 maxx = 0 |
1105 maxx = 0 |
1097 onlyone = [] |
1106 onlyone = [] |
1101 onlyone[-1] &= len(wire.EndConnected.GetWires()) == 1 |
1110 onlyone[-1] &= len(wire.EndConnected.GetWires()) == 1 |
1102 leftblock = wire.EndConnected.GetParentBlock() |
1111 leftblock = wire.EndConnected.GetParentBlock() |
1103 pos = leftblock.GetPosition() |
1112 pos = leftblock.GetPosition() |
1104 size = leftblock.GetSize() |
1113 size = leftblock.GetSize() |
1105 maxx = max(maxx, pos[0] + size[0]) |
1114 maxx = max(maxx, pos[0] + size[0]) |
1106 |
1115 |
1107 # Refresh position of element |
1116 # Refresh position of element |
1108 if isinstance(element, LD_Coil): |
1117 if isinstance(element, LD_Coil): |
1109 interval = LD_WIRECOIL_SIZE |
1118 interval = LD_WIRECOIL_SIZE |
1110 else: |
1119 else: |
1111 interval = LD_WIRE_SIZE |
1120 interval = LD_WIRE_SIZE |
1112 if False in onlyone: |
1121 if False in onlyone: |
1113 interval += LD_WIRE_SIZE |
1122 interval += LD_WIRE_SIZE |
1114 movex = maxx + interval - position[0] |
1123 movex = maxx + interval - position[0] |
1115 element.Move(movex, 0) |
1124 element.Move(movex, 0) |
1116 position = element.GetPosition() |
1125 position = element.GetPosition() |
1117 |
1126 |
1118 # Extract blocks connected to inputs |
1127 # Extract blocks connected to inputs |
1119 blocks = [] |
1128 blocks = [] |
1120 for i, connector in enumerate(connectors["inputs"]): |
1129 for i, connector in enumerate(connectors["inputs"]): |
1121 for j, (wire, handle) in enumerate(connector.GetWires()): |
1130 for j, (wire, handle) in enumerate(connector.GetWires()): |
1122 blocks.append(wire.EndConnected.GetParentBlock()) |
1131 blocks.append(wire.EndConnected.GetParentBlock()) |
1123 |
1132 |
1124 for i, connector in enumerate(connectors["inputs"]): |
1133 for i, connector in enumerate(connectors["inputs"]): |
1125 startpoint = connector.GetPosition(False) |
1134 startpoint = connector.GetPosition(False) |
1126 previous_blocks = [] |
1135 previous_blocks = [] |
1127 block_list = [] |
1136 block_list = [] |
1128 start_offset = 0 |
1137 start_offset = 0 |
1166 points = [startpoint, endpoint] |
1175 points = [startpoint, endpoint] |
1167 wire.SetPoints(points, False) |
1176 wire.SetPoints(points, False) |
1168 previous_blocks.append(block) |
1177 previous_blocks.append(block) |
1169 blocks.remove(block) |
1178 blocks.remove(block) |
1170 ExtractNextBlocks(block, block_list) |
1179 ExtractNextBlocks(block, block_list) |
1171 |
1180 |
1172 element.RefreshModel(False) |
1181 element.RefreshModel(False) |
1173 if recursive: |
1182 if recursive: |
1174 for connector in connectors["outputs"]: |
1183 for connector in connectors["outputs"]: |
1175 for wire, handle in connector.GetWires(): |
1184 for wire, handle in connector.GetWires(): |
1176 self.RefreshPosition(wire.StartConnected.GetParentBlock()) |
1185 self.RefreshPosition(wire.StartConnected.GetParentBlock()) |
1177 |
1186 |
1178 def RefreshRungs(self, movey, fromidx): |
1187 def RefreshRungs(self, movey, fromidx): |
1179 if movey != 0: |
1188 if movey != 0: |
1180 for i in xrange(fromidx, len(self.Rungs)): |
1189 for i in xrange(fromidx, len(self.Rungs)): |
1181 self.RungComments[i].Move(0, movey) |
1190 self.RungComments[i].Move(0, movey) |
1182 self.RungComments[i].RefreshModel() |
1191 self.RungComments[i].RefreshModel() |
1183 self.Rungs[i].Move(0, movey) |
1192 self.Rungs[i].Move(0, movey) |
1184 for element in self.Rungs[i].GetElements(): |
1193 for element in self.Rungs[i].GetElements(): |
1185 if self.IsBlock(element): |
1194 if self.IsBlock(element): |
1186 self.RefreshPosition(element) |
1195 self.RefreshPosition(element) |
1187 |
1196 |
1188 #------------------------------------------------------------------------------- |
1197 # ------------------------------------------------------------------------------- |
1189 # Edit element content functions |
1198 # Edit element content functions |
1190 #------------------------------------------------------------------------------- |
1199 # ------------------------------------------------------------------------------- |
1191 |
1200 |
1192 def EditPowerRailContent(self, powerrail): |
1201 def EditPowerRailContent(self, powerrail): |
1193 if self.GetDrawingMode() == FREEDRAWING_MODE: |
1202 if self.GetDrawingMode() == FREEDRAWING_MODE: |
1194 Viewer.EditPowerRailContent(self, powerrail) |
1203 Viewer.EditPowerRailContent(self, powerrail) |
1195 |
|