548 self.SelectedElement = right_wires[0] |
548 self.SelectedElement = right_wires[0] |
549 rung.RefreshBoundingBox() |
549 rung.RefreshBoundingBox() |
550 new_bbox = rung.GetBoundingBox() |
550 new_bbox = rung.GetBoundingBox() |
551 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
551 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
552 self.Refresh() |
552 self.Refresh() |
|
553 else: |
|
554 message = wxMessageDialog(self, "You must select the wire where a contact should be added!", "Error", wxOK|wxICON_ERROR) |
|
555 message.ShowModal() |
|
556 message.Destroy() |
553 |
557 |
554 def AddBranch(self): |
558 def AddBranch(self): |
555 blocks = [] |
559 blocks = [] |
556 if self.SelectedElement in self.Blocks: |
560 if self.SelectedElement in self.Blocks: |
557 blocks = [self.SelectedElement] |
561 blocks = [self.SelectedElement] |
643 if "LD_PowerRail" not in infos["lefts"]: |
647 if "LD_PowerRail" not in infos["lefts"]: |
644 infos["lefts"].append("LD_PowerRail") |
648 infos["lefts"].append("LD_PowerRail") |
645 right_elements = [element for element in infos["rights"]] |
649 right_elements = [element for element in infos["rights"]] |
646 for right_element in right_elements: |
650 for right_element in right_elements: |
647 if isinstance(right_element.GetParentBlock(), LD_PowerRail): |
651 if isinstance(right_element.GetParentBlock(), LD_PowerRail): |
648 infos["rights"].remove(tight_element) |
652 infos["rights"].remove(right_element) |
649 if "LD_PowerRail" not in infos["rights"]: |
653 if "LD_PowerRail" not in infos["rights"]: |
650 infos["rights"].append("LD_PowerRail") |
654 infos["rights"].append("LD_PowerRail") |
651 infos["lefts"].sort() |
655 infos["lefts"].sort() |
652 infos["rights"].sort() |
656 infos["rights"].sort() |
653 lefts = blocks_infos[0]["lefts"] |
657 lefts = blocks_infos[0]["lefts"] |
686 self.Wires.append(new_wire) |
690 self.Wires.append(new_wire) |
687 self.Elements.append(new_wire) |
691 self.Elements.append(new_wire) |
688 rung.SelectElement(new_wire) |
692 rung.SelectElement(new_wire) |
689 right_elements.reverse() |
693 right_elements.reverse() |
690 elif right_powerrail: |
694 elif right_powerrail: |
691 pass |
695 dialog = LDElementDialog(self.Parent, "coil") |
|
696 varlist = [] |
|
697 vars = self.Controler.GetCurrentElementEditingInterfaceVars() |
|
698 if vars: |
|
699 for var in vars: |
|
700 if var["Class"] != "Input" and var["Type"] == "BOOL": |
|
701 varlist.append(var["Name"]) |
|
702 returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType() |
|
703 if returntype == "BOOL": |
|
704 varlist.append(self.Controler.GetCurrentElementEditingName()) |
|
705 dialog.SetVariables(varlist) |
|
706 dialog.SetValues({"name":"","type":COIL_NORMAL}) |
|
707 if dialog.ShowModal() == wxID_OK: |
|
708 values = dialog.GetValues() |
|
709 powerrail = right_elements[0].GetParentBlock() |
|
710 index = 0 |
|
711 for right_element in right_elements: |
|
712 index = max(index, powerrail.GetConnectorIndex(right_element)) |
|
713 if powerrail.IsNullConnector(index + 1): |
|
714 powerrail.DeleteConnector(index + 1) |
|
715 powerrail.InsertConnector(index + 1) |
|
716 powerrail.RefreshModel() |
|
717 connectors = powerrail.GetConnectors() |
|
718 # Create Coil |
|
719 id = self.GetNewId() |
|
720 coil = LD_Coil(self, values["type"], values["name"], id) |
|
721 pos = blocks[0].GetPosition() |
|
722 coil.SetPosition(pos[0], pos[1] + LD_LINE_SIZE) |
|
723 self.Elements.append(coil) |
|
724 self.Blocks.append(coil) |
|
725 rung.SelectElement(coil) |
|
726 self.Controler.AddCurrentElementEditingCoil(id) |
|
727 coil_connectors = coil.GetConnectors() |
|
728 # Create Wire between LeftPowerRail and Coil |
|
729 wire = Wire(self) |
|
730 connectors[index + 1].Connect((wire, 0), False) |
|
731 coil_connectors["output"].Connect((wire, -1), False) |
|
732 wire.ConnectStartPoint(None, connectors[index + 1]) |
|
733 wire.ConnectEndPoint(None, coil_connectors["output"]) |
|
734 self.Wires.append(wire) |
|
735 self.Elements.append(wire) |
|
736 rung.SelectElement(wire) |
|
737 for i, left_element in enumerate(left_elements): |
|
738 # Create Wire between LeftPowerRail and Coil |
|
739 new_wire = Wire(self) |
|
740 coil_connectors["input"].Connect((new_wire, 0), False) |
|
741 left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False) |
|
742 new_wire.ConnectStartPoint(None, coil_connectors["input"]) |
|
743 new_wire.ConnectEndPoint(None, left_element) |
|
744 self.Wires.append(new_wire) |
|
745 self.Elements.append(new_wire) |
|
746 rung.SelectElement(new_wire) |
|
747 left_elements.reverse() |
|
748 self.RefreshPosition(coil) |
692 else: |
749 else: |
693 left_elements.reverse() |
750 left_elements.reverse() |
694 right_elements.reverse() |
751 right_elements.reverse() |
695 wires = [] |
752 wires = [] |
696 for i, left_element in enumerate(left_elements): |
753 for i, left_element in enumerate(left_elements): |
718 self.SelectedElement.RefreshBoundingBox() |
775 self.SelectedElement.RefreshBoundingBox() |
719 rung.RefreshBoundingBox() |
776 rung.RefreshBoundingBox() |
720 new_bbox = rung.GetBoundingBox() |
777 new_bbox = rung.GetBoundingBox() |
721 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
778 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
722 self.Refresh() |
779 self.Refresh() |
|
780 else: |
|
781 message = wxMessageDialog(self, "The group of block must be coherent!", "Error", wxOK|wxICON_ERROR) |
|
782 message.ShowModal() |
|
783 message.Destroy() |
|
784 else: |
|
785 message = wxMessageDialog(self, "You must select the block or group of blocks around which a branch should be added!", "Error", wxOK|wxICON_ERROR) |
|
786 message.ShowModal() |
|
787 message.Destroy() |
|
788 |
|
789 |
|
790 def AddBlock(self): |
|
791 message = wxMessageDialog(self, "This option isn't available yet!", "Warning", wxOK|wxICON_EXCLAMATION) |
|
792 message.ShowModal() |
|
793 message.Destroy() |
723 |
794 |
724 #------------------------------------------------------------------------------- |
795 #------------------------------------------------------------------------------- |
725 # Delete element functions |
796 # Delete element functions |
726 #------------------------------------------------------------------------------- |
797 #------------------------------------------------------------------------------- |
727 |
798 |