201 rung = Graphic_Group(self) |
202 rung = Graphic_Group(self) |
202 rung.SelectElement(element) |
203 rung.SelectElement(element) |
203 self.Rungs.append(rung) |
204 self.Rungs.append(rung) |
204 elif instance["type"] == "rightPowerRail": |
205 elif instance["type"] == "rightPowerRail": |
205 rungs = [] |
206 rungs = [] |
206 for connector in instance["connectors"]: |
207 for connector in instance["inputs"]: |
207 for link in connector["links"]: |
208 for link in connector["links"]: |
208 connected = self.FindElementById(link["refLocalId"]) |
209 connected = self.FindElementById(link["refLocalId"]) |
209 rung = self.FindRung(connected) |
210 rung = self.FindRung(connected) |
210 if rung not in rungs: |
211 if rung not in rungs: |
211 rungs.append(rung) |
212 rungs.append(rung) |
212 if len(rungs) > 1: |
213 if len(rungs) > 1: |
213 raise ValueError, _("Ladder element with id %d is on more than one rung.")%instance["id"] |
214 raise ValueError, _("Ladder element with id %d is on more than one rung.")%instance["id"] |
214 element = self.FindElementById(instance["id"]) |
215 element = self.FindElementById(instance["id"]) |
|
216 element_connectors = element.GetConnectors() |
215 self.Rungs[rungs[0]].SelectElement(element) |
217 self.Rungs[rungs[0]].SelectElement(element) |
216 for connector in element.GetConnectors(): |
218 for connector in element_connectors["inputs"]: |
217 for wire, num in connector.GetWires(): |
219 for wire, num in connector.GetWires(): |
218 self.Rungs[rungs[0]].SelectElement(wire) |
220 self.Rungs[rungs[0]].SelectElement(wire) |
219 self.RefreshPosition(element) |
221 wx.CallAfter(self.RefreshPosition, element) |
220 elif instance["type"] in ["contact", "coil"]: |
222 elif instance["type"] in ["contact", "coil"]: |
221 rungs = [] |
223 rungs = [] |
222 for link in instance["connectors"]["input"]["links"]: |
224 for link in instance["inputs"][0]["links"]: |
223 connected = self.FindElementById(link["refLocalId"]) |
225 connected = self.FindElementById(link["refLocalId"]) |
224 rung = self.FindRung(connected) |
226 rung = self.FindRung(connected) |
225 if rung not in rungs: |
227 if rung not in rungs: |
226 rungs.append(rung) |
228 rungs.append(rung) |
227 if len(rungs) > 1: |
229 if len(rungs) > 1: |
228 raise ValueError, _("Ladder element with id %d is on more than one rung.")%instance["id"] |
230 raise ValueError, _("Ladder element with id %d is on more than one rung.")%instance["id"] |
229 element = self.FindElementById(instance["id"]) |
231 element = self.FindElementById(instance["id"]) |
|
232 element_connectors = element.GetConnectors() |
230 self.Rungs[rungs[0]].SelectElement(element) |
233 self.Rungs[rungs[0]].SelectElement(element) |
231 for wire, num in element.GetConnectors()["input"].GetWires(): |
234 for wire, num in element_connectors["inputs"][0].GetWires(): |
232 self.Rungs[rungs[0]].SelectElement(wire) |
235 self.Rungs[rungs[0]].SelectElement(wire) |
233 self.RefreshPosition(element) |
236 wx.CallAfter(self.RefreshPosition, element) |
234 elif instance["type"] == "comment": |
237 elif instance["type"] == "comment": |
235 element = self.FindElementById(instance["id"]) |
238 element = self.FindElementById(instance["id"]) |
236 pos = element.GetPosition() |
239 pos = element.GetPosition() |
237 i = 0 |
240 i = 0 |
238 inserted = False |
241 inserted = False |
377 else: |
377 else: |
378 self.SelectedElement.SetSelected(True) |
378 self.SelectedElement.SetSelected(True) |
379 self.SelectedElement.OnRightUp(event, dc, self.Scaling) |
379 self.SelectedElement.OnRightUp(event, dc, self.Scaling) |
380 self.SelectedElement.Refresh() |
380 self.SelectedElement.Refresh() |
381 wx.CallAfter(self.SetCurrentCursor, 0) |
381 wx.CallAfter(self.SetCurrentCursor, 0) |
382 event.Skip() |
|
383 |
|
384 def OnViewerLeftDClick(self, event): |
|
385 if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
386 Viewer.OnViewerLeftDClick(self, event) |
|
387 elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
388 self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
|
389 self.SelectedElement.Refresh() |
|
390 event.Skip() |
|
391 |
|
392 def OnViewerMotion(self, event): |
|
393 if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
394 Viewer.OnViewerMotion(self, event) |
|
395 elif self.rubberBand.IsShown(): |
|
396 self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
397 event.Skip() |
382 event.Skip() |
398 |
383 |
399 #------------------------------------------------------------------------------- |
384 #------------------------------------------------------------------------------- |
400 # Keyboard event functions |
385 # Keyboard event functions |
401 #------------------------------------------------------------------------------- |
386 #------------------------------------------------------------------------------- |
511 if len(self.Rungs) > 0: |
496 if len(self.Rungs) > 0: |
512 bbox = self.Rungs[-1].GetBoundingBox() |
497 bbox = self.Rungs[-1].GetBoundingBox() |
513 starty = bbox.y + bbox.height |
498 starty = bbox.y + bbox.height |
514 starty += LD_OFFSET[1] |
499 starty += LD_OFFSET[1] |
515 rung = Graphic_Group(self) |
500 rung = Graphic_Group(self) |
|
501 |
516 # Create comment |
502 # Create comment |
517 id = self.GetNewId() |
503 id = self.GetNewId() |
518 comment = Comment(self, _("Comment"), id) |
504 comment = Comment(self, _("Comment"), id) |
519 comment.SetPosition(startx, starty) |
505 comment.SetPosition(startx, starty) |
520 comment.SetSize(LD_COMMENT_DEFAULTSIZE[0], LD_COMMENT_DEFAULTSIZE[1]) |
506 comment.SetSize(LD_COMMENT_DEFAULTSIZE[0], LD_COMMENT_DEFAULTSIZE[1]) |
521 self.AddComment(comment) |
507 self.AddComment(comment) |
522 self.RungComments.append(comment) |
508 self.RungComments.append(comment) |
523 self.Controler.AddEditedElementComment(self.TagName, id) |
509 self.Controler.AddEditedElementComment(self.TagName, id) |
524 self.RefreshCommentModel(comment) |
510 self.RefreshCommentModel(comment) |
525 starty += LD_COMMENT_DEFAULTSIZE[1] + LD_OFFSET[1] |
511 starty += LD_COMMENT_DEFAULTSIZE[1] + LD_OFFSET[1] |
|
512 |
526 # Create LeftPowerRail |
513 # Create LeftPowerRail |
527 id = self.GetNewId() |
514 id = self.GetNewId() |
528 leftpowerrail = LD_PowerRail(self, LEFTRAIL, id) |
515 leftpowerrail = LD_PowerRail(self, LEFTRAIL, id) |
529 leftpowerrail.SetPosition(startx, starty) |
516 leftpowerrail.SetPosition(startx, starty) |
|
517 leftpowerrail_connectors = leftpowerrail.GetConnectors() |
530 self.AddBlock(leftpowerrail) |
518 self.AddBlock(leftpowerrail) |
531 rung.SelectElement(leftpowerrail) |
519 rung.SelectElement(leftpowerrail) |
532 self.Controler.AddEditedElementPowerRail(self.TagName, id, LEFTRAIL) |
520 self.Controler.AddEditedElementPowerRail(self.TagName, id, LEFTRAIL) |
533 self.RefreshPowerRailModel(leftpowerrail) |
521 self.RefreshPowerRailModel(leftpowerrail) |
|
522 |
534 # Create Coil |
523 # Create Coil |
535 id = self.GetNewId() |
524 id = self.GetNewId() |
536 coil = LD_Coil(self, values["type"], values["name"], id) |
525 coil = LD_Coil(self, values["type"], values["name"], id) |
537 coil.SetPosition(startx, starty + (LD_LINE_SIZE - LD_ELEMENT_SIZE[1]) / 2) |
526 coil.SetPosition(startx, starty + (LD_LINE_SIZE - LD_ELEMENT_SIZE[1]) / 2) |
|
527 coil_connectors = coil.GetConnectors() |
538 self.AddBlock(coil) |
528 self.AddBlock(coil) |
539 rung.SelectElement(coil) |
529 rung.SelectElement(coil) |
540 self.Controler.AddEditedElementCoil(self.TagName, id) |
530 self.Controler.AddEditedElementCoil(self.TagName, id) |
|
531 |
541 # Create Wire between LeftPowerRail and Coil |
532 # Create Wire between LeftPowerRail and Coil |
542 wire = Wire(self) |
533 wire = Wire(self) |
543 start_connector = coil.GetConnectors()["input"] |
534 start_connector = coil_connectors["inputs"][0] |
544 end_connector = leftpowerrail.GetConnectors()[0] |
535 end_connector = leftpowerrail_connectors["outputs"][0] |
545 start_connector.Connect((wire, 0), False) |
536 start_connector.Connect((wire, 0), False) |
546 end_connector.Connect((wire, -1), False) |
537 end_connector.Connect((wire, -1), False) |
547 wire.ConnectStartPoint(None, start_connector) |
538 wire.ConnectStartPoint(None, start_connector) |
548 wire.ConnectEndPoint(None, end_connector) |
539 wire.ConnectEndPoint(None, end_connector) |
549 self.AddWire(wire) |
540 self.AddWire(wire) |
550 rung.SelectElement(wire) |
541 rung.SelectElement(wire) |
|
542 |
551 # Create RightPowerRail |
543 # Create RightPowerRail |
552 id = self.GetNewId() |
544 id = self.GetNewId() |
553 rightpowerrail = LD_PowerRail(self, RIGHTRAIL, id) |
545 rightpowerrail = LD_PowerRail(self, RIGHTRAIL, id) |
554 rightpowerrail.SetPosition(startx, starty) |
546 rightpowerrail.SetPosition(startx, starty) |
|
547 rightpowerrail_connectors = rightpowerrail.GetConnectors() |
555 self.AddBlock(rightpowerrail) |
548 self.AddBlock(rightpowerrail) |
556 rung.SelectElement(rightpowerrail) |
549 rung.SelectElement(rightpowerrail) |
557 self.Controler.AddEditedElementPowerRail(self.TagName, id, RIGHTRAIL) |
550 self.Controler.AddEditedElementPowerRail(self.TagName, id, RIGHTRAIL) |
|
551 |
558 # Create Wire between LeftPowerRail and Coil |
552 # Create Wire between LeftPowerRail and Coil |
559 wire = Wire(self) |
553 wire = Wire(self) |
560 start_connector = rightpowerrail.GetConnectors()[0] |
554 start_connector = rightpowerrail_connectors["inputs"][0] |
561 end_connector = coil.GetConnectors()["output"] |
555 end_connector = coil_connectors["outputs"][0] |
562 start_connector.Connect((wire, 0), False) |
556 start_connector.Connect((wire, 0), False) |
563 end_connector.Connect((wire, -1), False) |
557 end_connector.Connect((wire, -1), False) |
564 wire.ConnectStartPoint(None, start_connector) |
558 wire.ConnectStartPoint(None, start_connector) |
565 wire.ConnectEndPoint(None, end_connector) |
559 wire.ConnectEndPoint(None, end_connector) |
566 self.AddWire(wire) |
560 self.AddWire(wire) |
567 rung.SelectElement(wire) |
561 rung.SelectElement(wire) |
568 self.RefreshPosition(coil) |
562 self.RefreshPosition(coil) |
569 self.Rungs.append(rung) |
563 self.Rungs.append(rung) |
570 self.RefreshBuffer() |
564 self.RefreshBuffer() |
571 self.RefreshScrollBars() |
565 self.RefreshScrollBars() |
|
566 self.RefreshVisibleElements() |
572 self.Refresh(False) |
567 self.Refresh(False) |
573 |
568 |
574 def AddLadderContact(self): |
569 def AddLadderContact(self): |
575 wires = [] |
570 wires = [] |
576 if self.IsWire(self.SelectedElement): |
571 if self.IsWire(self.SelectedElement): |
629 wires = [] |
624 wires = [] |
630 right_wires = [] |
625 right_wires = [] |
631 for i, left_element in enumerate(left_elements): |
626 for i, left_element in enumerate(left_elements): |
632 wire = Wire(self) |
627 wire = Wire(self) |
633 wires.append(wire) |
628 wires.append(wire) |
634 connectors["input"].Connect((wire, 0), False) |
629 connectors["inputs"][0].Connect((wire, 0), False) |
635 left_element.InsertConnect(left_index[i], (wire, -1), False) |
630 left_element.InsertConnect(left_index[i], (wire, -1), False) |
636 wire.ConnectStartPoint(None, connectors["input"]) |
631 wire.ConnectStartPoint(None, connectors["inputs"][0]) |
637 wire.ConnectEndPoint(None, left_element) |
632 wire.ConnectEndPoint(None, left_element) |
638 for i, right_element in enumerate(right_elements): |
633 for i, right_element in enumerate(right_elements): |
639 wire = Wire(self) |
634 wire = Wire(self) |
640 wires.append(wire) |
635 wires.append(wire) |
641 right_wires.append(wire) |
636 right_wires.append(wire) |
642 right_element.InsertConnect(right_index[i], (wire, 0), False) |
637 right_element.InsertConnect(right_index[i], (wire, 0), False) |
643 connectors["output"].Connect((wire, -1), False) |
638 connectors["outputs"][0].Connect((wire, -1), False) |
644 wire.ConnectStartPoint(None, right_element) |
639 wire.ConnectStartPoint(None, right_element) |
645 wire.ConnectEndPoint(None, connectors["output"]) |
640 wire.ConnectEndPoint(None, connectors["outputs"][0]) |
646 right_wires.reverse() |
641 right_wires.reverse() |
647 for wire in wires: |
642 for wire in wires: |
648 self.AddWire(wire) |
643 self.AddWire(wire) |
649 rung.SelectElement(wire) |
644 rung.SelectElement(wire) |
650 self.RefreshPosition(contact) |
645 self.RefreshPosition(contact) |
787 if left_powerrail: |
776 if left_powerrail: |
788 powerrail = left_elements[0].GetParentBlock() |
777 powerrail = left_elements[0].GetParentBlock() |
789 index = 0 |
778 index = 0 |
790 for left_element in left_elements: |
779 for left_element in left_elements: |
791 index = max(index, powerrail.GetConnectorIndex(left_element)) |
780 index = max(index, powerrail.GetConnectorIndex(left_element)) |
792 if powerrail.IsNullConnector(index + 1): |
|
793 powerrail.DeleteConnector(index + 1) |
|
794 powerrail.InsertConnector(index + 1) |
781 powerrail.InsertConnector(index + 1) |
795 powerrail.RefreshModel() |
782 powerrail.RefreshModel() |
796 connectors = powerrail.GetConnectors() |
783 connectors = powerrail.GetConnectors() |
797 right_elements.reverse() |
784 right_elements.reverse() |
798 for i, right_element in enumerate(right_elements): |
785 for i, right_element in enumerate(right_elements): |
799 new_wire = Wire(self) |
786 new_wire = Wire(self) |
800 wires.append(new_wire) |
787 wires.append(new_wire) |
801 right_element.InsertConnect(right_index[i] + 1, (new_wire, 0), False) |
788 right_element.InsertConnect(right_index[i] + 1, (new_wire, 0), False) |
802 connectors[index + 1].Connect((new_wire, -1), False) |
789 connectors["outputs"][index + 1].Connect((new_wire, -1), False) |
803 new_wire.ConnectStartPoint(None, right_element) |
790 new_wire.ConnectStartPoint(None, right_element) |
804 new_wire.ConnectEndPoint(None, connectors[index + 1]) |
791 new_wire.ConnectEndPoint(None, connectors["outputs"][index + 1]) |
805 right_elements.reverse() |
792 right_elements.reverse() |
806 elif right_powerrail: |
793 elif right_powerrail: |
807 dialog = LDElementDialog(self.ParentWindow, "coil") |
794 dialog = LDElementDialog(self.ParentWindow, self.Controleur, "coil") |
808 dialog.SetPreviewFont(self.GetFont()) |
795 dialog.SetPreviewFont(self.GetFont()) |
809 varlist = [] |
796 varlist = [] |
810 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
797 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
811 if vars: |
798 if vars: |
812 for var in vars: |
799 for var in vars: |
821 values = dialog.GetValues() |
808 values = dialog.GetValues() |
822 powerrail = right_elements[0].GetParentBlock() |
809 powerrail = right_elements[0].GetParentBlock() |
823 index = 0 |
810 index = 0 |
824 for right_element in right_elements: |
811 for right_element in right_elements: |
825 index = max(index, powerrail.GetConnectorIndex(right_element)) |
812 index = max(index, powerrail.GetConnectorIndex(right_element)) |
826 if powerrail.IsNullConnector(index + 1): |
|
827 powerrail.DeleteConnector(index + 1) |
|
828 powerrail.InsertConnector(index + 1) |
813 powerrail.InsertConnector(index + 1) |
829 powerrail.RefreshModel() |
814 powerrail.RefreshModel() |
830 connectors = powerrail.GetConnectors() |
815 connectors = powerrail.GetConnectors() |
|
816 |
831 # Create Coil |
817 # Create Coil |
832 id = self.GetNewId() |
818 id = self.GetNewId() |
833 coil = LD_Coil(self, values["type"], values["name"], id) |
819 coil = LD_Coil(self, values["type"], values["name"], id) |
834 pos = blocks[0].GetPosition() |
820 pos = blocks[0].GetPosition() |
835 coil.SetPosition(pos[0], pos[1] + LD_LINE_SIZE) |
821 coil.SetPosition(pos[0], pos[1] + LD_LINE_SIZE) |
836 self.AddBlock(coil) |
822 self.AddBlock(coil) |
837 rung.SelectElement(coil) |
823 rung.SelectElement(coil) |
838 self.Controler.AddEditedElementCoil(self.TagName, id) |
824 self.Controler.AddEditedElementCoil(self.TagName, id) |
839 coil_connectors = coil.GetConnectors() |
825 coil_connectors = coil.GetConnectors() |
|
826 |
840 # Create Wire between LeftPowerRail and Coil |
827 # Create Wire between LeftPowerRail and Coil |
841 wire = Wire(self) |
828 wire = Wire(self) |
842 connectors[index + 1].Connect((wire, 0), False) |
829 connectors["inputs"][index + 1].Connect((wire, 0), False) |
843 coil_connectors["output"].Connect((wire, -1), False) |
830 coil_connectors["outputs"][0].Connect((wire, -1), False) |
844 wire.ConnectStartPoint(None, connectors[index + 1]) |
831 wire.ConnectStartPoint(None, connectors["inputs"][index + 1]) |
845 wire.ConnectEndPoint(None, coil_connectors["output"]) |
832 wire.ConnectEndPoint(None, coil_connectors["outputs"][0]) |
846 self.AddWire(wire) |
833 self.AddWire(wire) |
847 rung.SelectElement(wire) |
834 rung.SelectElement(wire) |
848 left_elements.reverse() |
835 left_elements.reverse() |
|
836 |
849 for i, left_element in enumerate(left_elements): |
837 for i, left_element in enumerate(left_elements): |
850 # Create Wire between LeftPowerRail and Coil |
838 # Create Wire between LeftPowerRail and Coil |
851 new_wire = Wire(self) |
839 new_wire = Wire(self) |
852 wires.append(new_wire) |
840 wires.append(new_wire) |
853 coil_connectors["input"].Connect((new_wire, 0), False) |
841 coil_connectors["inputs"][0].Connect((new_wire, 0), False) |
854 left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False) |
842 left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False) |
855 new_wire.ConnectStartPoint(None, coil_connectors["input"]) |
843 new_wire.ConnectStartPoint(None, coil_connectors["inputs"][0]) |
856 new_wire.ConnectEndPoint(None, left_element) |
844 new_wire.ConnectEndPoint(None, left_element) |
|
845 |
857 self.RefreshPosition(coil) |
846 self.RefreshPosition(coil) |
858 else: |
847 else: |
859 left_elements.reverse() |
848 left_elements.reverse() |
860 right_elements.reverse() |
849 right_elements.reverse() |
861 for i, left_element in enumerate(left_elements): |
850 for i, left_element in enumerate(left_elements): |
906 |
896 |
907 def DeleteContact(self, contact): |
897 def DeleteContact(self, contact): |
908 if self.GetDrawingMode() == FREEDRAWING_MODE: |
898 if self.GetDrawingMode() == FREEDRAWING_MODE: |
909 Viewer.DeleteContact(self, contact) |
899 Viewer.DeleteContact(self, contact) |
910 else: |
900 else: |
|
901 print "Delete" |
911 rungindex = self.FindRung(contact) |
902 rungindex = self.FindRung(contact) |
912 rung = self.Rungs[rungindex] |
903 rung = self.Rungs[rungindex] |
913 old_bbox = rung.GetBoundingBox() |
904 old_bbox = rung.GetBoundingBox() |
914 connectors = contact.GetConnectors() |
905 connectors = contact.GetConnectors() |
915 input_wires = [wire for wire, handle in connectors["input"].GetWires()] |
906 input_wires = [wire for wire, handle in connectors["inputs"][0].GetWires()] |
916 output_wires = [wire for wire, handle in connectors["output"].GetWires()] |
907 output_wires = [wire for wire, handle in connectors["outputs"][0].GetWires()] |
917 left_elements = [(wire.EndConnected, wire.EndConnected.GetWireIndex(wire)) for wire in input_wires] |
908 left_elements = [(wire.EndConnected, wire.EndConnected.GetWireIndex(wire)) for wire in input_wires] |
918 right_elements = [(wire.StartConnected, wire.StartConnected.GetWireIndex(wire)) for wire in output_wires] |
909 right_elements = [(wire.StartConnected, wire.StartConnected.GetWireIndex(wire)) for wire in output_wires] |
919 for wire in input_wires: |
910 for wire in input_wires: |
920 wire.Clean() |
911 wire.Clean() |
921 rung.SelectElement(wire) |
912 rung.SelectElement(wire) |
1096 #------------------------------------------------------------------------------- |
1082 #------------------------------------------------------------------------------- |
1097 # Refresh element position functions |
1083 # Refresh element position functions |
1098 #------------------------------------------------------------------------------- |
1084 #------------------------------------------------------------------------------- |
1099 |
1085 |
1100 def RefreshPosition(self, element, recursive=True): |
1086 def RefreshPosition(self, element, recursive=True): |
|
1087 # If element is LeftPowerRail, no need to update position |
1101 if isinstance(element, LD_PowerRail) and element.GetType() == LEFTRAIL: |
1088 if isinstance(element, LD_PowerRail) and element.GetType() == LEFTRAIL: |
1102 element.RefreshModel() |
1089 element.RefreshModel() |
1103 return |
1090 return |
|
1091 |
|
1092 # Extract max position of the elements connected to input |
1104 connectors = element.GetConnectors() |
1093 connectors = element.GetConnectors() |
1105 input_connectors = [] |
|
1106 output_connectors = [] |
|
1107 if isinstance(element, LD_PowerRail) and element.GetType() == RIGHTRAIL: |
|
1108 input_connectors = connectors |
|
1109 for i, connector in enumerate(input_connectors): |
|
1110 for j, (wire, handle) in enumerate(connector.GetWires()): |
|
1111 block = wire.EndConnected.GetParentBlock() |
|
1112 self.RefreshPosition(block, False) |
|
1113 else: |
|
1114 if "inputs" in connectors: |
|
1115 input_connectors = connectors["inputs"] |
|
1116 if "outputs" in connectors: |
|
1117 output_connectors = connectors["outputs"] |
|
1118 if "input" in connectors: |
|
1119 input_connectors = [connectors["input"]] |
|
1120 if "output" in connectors: |
|
1121 output_connectors = [connectors["output"]] |
|
1122 position = element.GetPosition() |
1094 position = element.GetPosition() |
1123 minx = 0 |
1095 maxx = 0 |
1124 onlyone = [] |
1096 onlyone = [] |
1125 for connector in input_connectors: |
1097 for connector in connectors["inputs"]: |
1126 onlyone.append(len(connector.GetWires()) == 1) |
1098 onlyone.append(len(connector.GetWires()) == 1) |
1127 for wire, handle in connector.GetWires(): |
1099 for wire, handle in connector.GetWires(): |
1128 onlyone[-1] &= len(wire.EndConnected.GetWires()) == 1 |
1100 onlyone[-1] &= len(wire.EndConnected.GetWires()) == 1 |
1129 leftblock = wire.EndConnected.GetParentBlock() |
1101 leftblock = wire.EndConnected.GetParentBlock() |
1130 pos = leftblock.GetPosition() |
1102 pos = leftblock.GetPosition() |
1131 size = leftblock.GetSize() |
1103 size = leftblock.GetSize() |
1132 minx = max(minx, pos[0] + size[0]) |
1104 maxx = max(maxx, pos[0] + size[0]) |
|
1105 |
|
1106 # Refresh position of element |
1133 if isinstance(element, LD_Coil): |
1107 if isinstance(element, LD_Coil): |
1134 interval = LD_WIRECOIL_SIZE |
1108 interval = LD_WIRECOIL_SIZE |
1135 else: |
1109 else: |
1136 interval = LD_WIRE_SIZE |
1110 interval = LD_WIRE_SIZE |
1137 if False in onlyone: |
1111 if False in onlyone: |
1138 interval += LD_WIRE_SIZE |
1112 interval += LD_WIRE_SIZE |
1139 movex = minx + interval - position[0] |
1113 movex = maxx + interval - position[0] |
1140 element.Move(movex, 0) |
1114 element.Move(movex, 0) |
1141 position = element.GetPosition() |
1115 position = element.GetPosition() |
|
1116 |
|
1117 # Extract blocks connected to inputs |
1142 blocks = [] |
1118 blocks = [] |
1143 for i, connector in enumerate(input_connectors): |
1119 for i, connector in enumerate(connectors["inputs"]): |
1144 for j, (wire, handle) in enumerate(connector.GetWires()): |
1120 for j, (wire, handle) in enumerate(connector.GetWires()): |
1145 blocks.append(wire.EndConnected.GetParentBlock()) |
1121 blocks.append(wire.EndConnected.GetParentBlock()) |
1146 for i, connector in enumerate(input_connectors): |
1122 |
|
1123 for i, connector in enumerate(connectors["inputs"]): |
1147 startpoint = connector.GetPosition(False) |
1124 startpoint = connector.GetPosition(False) |
1148 previous_blocks = [] |
1125 previous_blocks = [] |
1149 block_list = [] |
1126 block_list = [] |
1150 start_offset = 0 |
1127 start_offset = 0 |
1151 if not onlyone[i]: |
1128 if not onlyone[i]: |
1152 middlepoint = minx + LD_WIRE_SIZE |
1129 middlepoint = maxx + LD_WIRE_SIZE |
1153 for j, (wire, handle) in enumerate(connector.GetWires()): |
1130 for j, (wire, handle) in enumerate(connector.GetWires()): |
1154 block = wire.EndConnected.GetParentBlock() |
1131 block = wire.EndConnected.GetParentBlock() |
1155 if isinstance(element, LD_PowerRail): |
1132 if isinstance(element, LD_PowerRail): |
1156 pos = block.GetPosition() |
1133 pos = block.GetPosition() |
1157 size = leftblock.GetSize() |
1134 size = leftblock.GetSize() |
1172 wx.Point(endmiddlepoint, startpoint.y + offset), |
1149 wx.Point(endmiddlepoint, startpoint.y + offset), |
1173 wx.Point(endmiddlepoint, endpoint.y), endpoint] |
1150 wx.Point(endmiddlepoint, endpoint.y), endpoint] |
1174 else: |
1151 else: |
1175 if startpoint.y + offset != endpoint.y: |
1152 if startpoint.y + offset != endpoint.y: |
1176 if isinstance(element, LD_PowerRail): |
1153 if isinstance(element, LD_PowerRail): |
1177 diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE |
1154 element.MoveConnector(i, startpoint.y - endpoint.y) |
1178 for k in xrange(abs(diff)): |
|
1179 if diff < 0: |
|
1180 element.DeleteConnector(i - 1 - k) |
|
1181 else: |
|
1182 element.InsertConnector(i + k, False) |
|
1183 elif isinstance(block, LD_PowerRail): |
1155 elif isinstance(block, LD_PowerRail): |
1184 index = block.GetConnectorIndex(wire.EndConnected) |
1156 index = block.GetConnectorIndex(wire.EndConnected) |
1185 if index: |
1157 if index: |
1186 diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE |
1158 block.MoveConnector(index, startpoint.y - endpoint.y) |
1187 for k in xrange(abs(diff)): |
|
1188 if diff < 0: |
|
1189 block.DeleteConnector(index - 1 - k) |
|
1190 else: |
|
1191 block.InsertConnector(index + k, False) |
|
1192 else: |
1159 else: |
1193 block.Move(0, startpoint.y + offset - endpoint.y) |
1160 block.Move(0, startpoint.y + offset - endpoint.y) |
1194 self.RefreshPosition(block, False) |
1161 self.RefreshPosition(block, False) |
1195 endpoint = wire.EndConnected.GetPosition(False) |
1162 endpoint = wire.EndConnected.GetPosition(False) |
1196 if not onlyone[i]: |
1163 if not onlyone[i]: |
1197 points = [startpoint, wx.Point(middlepoint, startpoint.y), |
1164 points = [startpoint, wx.Point(middlepoint, startpoint.y), |
1198 wx.Point(middlepoint, endpoint.y), endpoint] |
1165 wx.Point(middlepoint, endpoint.y), endpoint] |
1199 else: |
1166 else: |
1200 points = [startpoint, endpoint] |
1167 points = [startpoint, endpoint] |
1201 wire.SetPoints(points) |
1168 wire.SetPoints(points, False) |
1202 previous_blocks.append(block) |
1169 previous_blocks.append(block) |
1203 blocks.remove(block) |
1170 blocks.remove(block) |
1204 ExtractNextBlocks(block, block_list) |
1171 ExtractNextBlocks(block, block_list) |
|
1172 |
1205 element.RefreshModel(False) |
1173 element.RefreshModel(False) |
1206 if recursive: |
1174 if recursive: |
1207 for connector in output_connectors: |
1175 for connector in connectors["outputs"]: |
1208 for wire, handle in connector.GetWires(): |
1176 for wire, handle in connector.GetWires(): |
1209 self.RefreshPosition(wire.StartConnected.GetParentBlock()) |
1177 self.RefreshPosition(wire.StartConnected.GetParentBlock()) |
1210 |
1178 |
1211 def RefreshRungs(self, movey, fromidx): |
1179 def RefreshRungs(self, movey, fromidx): |
1212 if movey != 0: |
1180 if movey != 0: |
1220 |
1188 |
1221 #------------------------------------------------------------------------------- |
1189 #------------------------------------------------------------------------------- |
1222 # Edit element content functions |
1190 # Edit element content functions |
1223 #------------------------------------------------------------------------------- |
1191 #------------------------------------------------------------------------------- |
1224 |
1192 |
1225 def EditContactContent(self, contact): |
|
1226 if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1227 Viewer.EditContactContent(self, contact) |
|
1228 else: |
|
1229 dialog = LDElementDialog(self.ParentWindow, "contact") |
|
1230 dialog.SetPreviewFont(self.GetFont()) |
|
1231 varlist = [] |
|
1232 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
1233 if vars: |
|
1234 for var in vars: |
|
1235 if var["Class"] != "Output" and var["Type"] == "BOOL": |
|
1236 varlist.append(var["Name"]) |
|
1237 dialog.SetVariables(varlist) |
|
1238 dialog.SetValues({"name":contact.GetName(),"type":contact.GetType()}) |
|
1239 if dialog.ShowModal() == wx.ID_OK: |
|
1240 values = dialog.GetValues() |
|
1241 contact.SetName(values["name"]) |
|
1242 contact.SetType(values["type"]) |
|
1243 contact.RefreshModel(False) |
|
1244 self.RefreshBuffer() |
|
1245 self.RefreshScrollBars() |
|
1246 contact.Refresh() |
|
1247 dialog.Destroy() |
|
1248 |
|
1249 def EditCoilContent(self, coil): |
|
1250 if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1251 Viewer.EditCoilContent(self, coil) |
|
1252 else: |
|
1253 dialog = LDElementDialog(self.ParentWindow, "coil") |
|
1254 dialog.SetPreviewFont(self.GetFont()) |
|
1255 varlist = [] |
|
1256 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
1257 if vars: |
|
1258 for var in vars: |
|
1259 if var["Class"] != "Input" and var["Type"] == "BOOL": |
|
1260 varlist.append(var["Name"]) |
|
1261 returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) |
|
1262 if returntype == "BOOL": |
|
1263 varlist.append(self.Controler.GetEditedElementName(self.TagName)) |
|
1264 dialog.SetVariables(varlist) |
|
1265 dialog.SetValues({"name":coil.GetName(),"type":coil.GetType()}) |
|
1266 if dialog.ShowModal() == wx.ID_OK: |
|
1267 values = dialog.GetValues() |
|
1268 coil.SetName(values["name"]) |
|
1269 coil.SetType(values["type"]) |
|
1270 coil.RefreshModel(False) |
|
1271 self.RefreshBuffer() |
|
1272 self.RefreshScrollBars() |
|
1273 coil.Refresh() |
|
1274 dialog.Destroy() |
|
1275 |
|
1276 def EditPowerRailContent(self, powerrail): |
1193 def EditPowerRailContent(self, powerrail): |
1277 if self.GetDrawingMode() == FREEDRAWING_MODE: |
1194 if self.GetDrawingMode() == FREEDRAWING_MODE: |
1278 Viewer.EditPowerRailContent(self, powerrail) |
1195 Viewer.EditPowerRailContent(self, powerrail) |
1279 |
1196 |
1280 #------------------------------------------------------------------------------- |
|
1281 # Model update functions |
|
1282 #------------------------------------------------------------------------------- |
|
1283 |
|
1284 def RefreshBlockModel(self, block): |
|
1285 blockid = block.GetId() |
|
1286 infos = {} |
|
1287 infos["type"] = block.GetType() |
|
1288 infos["name"] = block.GetName() |
|
1289 infos["x"], infos["y"] = block.GetPosition() |
|
1290 infos["width"], infos["height"] = block.GetSize() |
|
1291 infos["connectors"] = block.GetConnectors() |
|
1292 self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos) |
|