859 rung.RefreshBoundingBox() |
857 rung.RefreshBoundingBox() |
860 new_bbox = rung.GetBoundingBox() |
858 new_bbox = rung.GetBoundingBox() |
861 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
859 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
862 self.SelectedElement = None |
860 self.SelectedElement = None |
863 |
861 |
|
862 def RecursiveDeletion(self, element, rung): |
|
863 connectors = element.GetConnectors() |
|
864 input_wires = [wire for wire, handle in connectors["input"].GetWires()] |
|
865 left_elements = [wire.EndConnected for wire in input_wires] |
|
866 rung.SelectElement(element) |
|
867 element.Clean() |
|
868 for wire in input_wires: |
|
869 wire.Clean() |
|
870 self.Wires.remove(wire) |
|
871 self.Elements.remove(wire) |
|
872 rung.SelectElement(wire) |
|
873 self.Blocks.remove(element) |
|
874 self.Elements.remove(element) |
|
875 self.Controler.RemoveCurrentElementEditingInstance(element.GetId()) |
|
876 for left_element in left_elements: |
|
877 block = left_element.GetParentBlock() |
|
878 if len(left_element.GetWires()) == 0: |
|
879 self.RecursiveDeletion(block, rung) |
|
880 else: |
|
881 self.RefreshPosition(block) |
|
882 |
864 def DeleteCoil(self, coil): |
883 def DeleteCoil(self, coil): |
865 rungindex = self.FindRung(coil) |
884 rungindex = self.FindRung(coil) |
866 rung = self.Rungs[rungindex] |
885 rung = self.Rungs[rungindex] |
867 bbox = rung.GetBoundingBox() |
886 old_bbox = rung.GetBoundingBox() |
|
887 nbcoils = 0 |
868 for element in rung.GetElements(): |
888 for element in rung.GetElements(): |
869 if element in self.Wires: |
889 if isinstance(element, LD_Coil): |
870 element.Clean() |
890 nbcoils += 1 |
871 self.Wires.remove(element) |
891 if nbcoils > 1: |
872 self.Elements.remove(element) |
892 connectors = coil.GetConnectors() |
873 for element in rung.GetElements(): |
893 output_wires = [wire for wire, handle in connectors["output"].GetWires()] |
874 if element in self.Blocks: |
894 right_elements = [wire.StartConnected for wire in output_wires] |
875 self.Controler.RemoveCurrentElementEditingInstance(element.GetId()) |
895 for wire in output_wires: |
876 self.Blocks.remove(element) |
896 wire.Clean() |
877 self.Elements.remove(element) |
897 self.Wires.remove(wire) |
878 self.Controler.RemoveCurrentElementEditingInstance(self.Comments[rungindex].GetId()) |
898 self.Elements.remove(wire) |
879 self.Elements.remove(self.Comments[rungindex]) |
899 rung.SelectElement(wire) |
880 self.Comments.pop(rungindex) |
900 for right_element in right_elements: |
881 self.Rungs.pop(rungindex) |
901 right_block = right_element.GetParentBlock() |
882 if rungindex < len(self.Rungs): |
902 if isinstance(right_block, LD_PowerRail): |
883 next_bbox = self.Rungs[rungindex].GetBoundingBox() |
903 if len(right_element.GetWires()) == 0: |
884 self.RefreshRungs(bbox.y - next_bbox.y, rungindex) |
904 index = right_block.GetConnectorIndex(right_element) |
|
905 right_block.DeleteConnector(index) |
|
906 powerrail_connectors = right_block.GetConnectors() |
|
907 for connector in powerrail_connectors: |
|
908 for wire, handle in connector.GetWires(): |
|
909 block = wire.EndConnected.GetParentBlock() |
|
910 endpoint = wire.EndConnected.GetPosition(False) |
|
911 startpoint = connector.GetPosition(False) |
|
912 block.Move(0, startpoint.y - endpoint.y) |
|
913 self.RefreshPosition(block) |
|
914 self.RecursiveDeletion(coil, rung) |
|
915 else: |
|
916 for element in rung.GetElements(): |
|
917 if element in self.Wires: |
|
918 element.Clean() |
|
919 self.Wires.remove(element) |
|
920 self.Elements.remove(element) |
|
921 for element in rung.GetElements(): |
|
922 if element in self.Blocks: |
|
923 self.Controler.RemoveCurrentElementEditingInstance(element.GetId()) |
|
924 self.Blocks.remove(element) |
|
925 self.Elements.remove(element) |
|
926 self.Controler.RemoveCurrentElementEditingInstance(self.Comments[rungindex].GetId()) |
|
927 self.Elements.remove(self.Comments[rungindex]) |
|
928 self.Comments.pop(rungindex) |
|
929 self.Rungs.pop(rungindex) |
|
930 if rungindex < len(self.Rungs): |
|
931 next_bbox = self.Rungs[rungindex].GetBoundingBox() |
|
932 self.RefreshRungs(old_bbox.y - next_bbox.y, rungindex) |
885 self.SelectedElement = None |
933 self.SelectedElement = None |
886 |
934 |
887 def DeleteWire(self, wire): |
935 def DeleteWire(self, wire): |
888 wires = [] |
936 wires = [] |
889 left_elements = [] |
937 left_elements = [] |
938 |
986 |
939 #------------------------------------------------------------------------------- |
987 #------------------------------------------------------------------------------- |
940 # Refresh element position functions |
988 # Refresh element position functions |
941 #------------------------------------------------------------------------------- |
989 #------------------------------------------------------------------------------- |
942 |
990 |
943 def RefreshPosition(self, element): |
991 def RefreshPosition(self, element, recursive=True): |
944 if isinstance(element, LD_PowerRail) and element.GetType() == LEFTRAIL: |
992 if isinstance(element, LD_PowerRail) and element.GetType() == LEFTRAIL: |
945 element.RefreshModel() |
993 element.RefreshModel() |
946 return |
994 return |
947 connectors = element.GetConnectors() |
995 connectors = element.GetConnectors() |
948 input_connectors = [] |
996 input_connectors = [] |
949 output_connectors = [] |
997 output_connectors = [] |
950 if isinstance(element, LD_PowerRail) and element.GetType() == RIGHTRAIL: |
998 if isinstance(element, LD_PowerRail) and element.GetType() == RIGHTRAIL: |
951 input_connectors = connectors |
999 input_connectors = connectors |
|
1000 for i, connector in enumerate(input_connectors): |
|
1001 for j, (wire, handle) in enumerate(connector.GetWires()): |
|
1002 block = wire.EndConnected.GetParentBlock() |
|
1003 self.RefreshPosition(block, False) |
952 else: |
1004 else: |
953 if "inputs" in connectors: |
1005 if "inputs" in connectors: |
954 input_connectors = connectors["inputs"] |
1006 input_connectors = connectors["inputs"] |
955 if "outputs" in connectors: |
1007 if "outputs" in connectors: |
956 output_connectors = connectors["outputs"] |
1008 output_connectors = connectors["outputs"] |
975 interval = LD_WIRE_SIZE |
1027 interval = LD_WIRE_SIZE |
976 if False in onlyone: |
1028 if False in onlyone: |
977 interval += LD_WIRE_SIZE |
1029 interval += LD_WIRE_SIZE |
978 movex = minx + interval - position[0] |
1030 movex = minx + interval - position[0] |
979 element.Move(movex, 0) |
1031 element.Move(movex, 0) |
|
1032 position = element.GetPosition() |
980 for i, connector in enumerate(input_connectors): |
1033 for i, connector in enumerate(input_connectors): |
981 startpoint = connector.GetPosition(False) |
1034 startpoint = connector.GetPosition(False) |
982 previous_blocks = [] |
1035 previous_blocks = [] |
983 block_list = [] |
1036 block_list = [] |
984 start_offset = 0 |
1037 start_offset = 0 |
985 if not onlyone[i]: |
1038 if not onlyone[i]: |
986 middlepoint = minx + LD_WIRE_SIZE |
1039 middlepoint = minx + LD_WIRE_SIZE |
987 for j, (wire, handle) in enumerate(connector.GetWires()): |
1040 for j, (wire, handle) in enumerate(connector.GetWires()): |
988 block = wire.EndConnected.GetParentBlock() |
1041 block = wire.EndConnected.GetParentBlock() |
|
1042 if isinstance(element, LD_PowerRail): |
|
1043 pos = block.GetPosition() |
|
1044 size = leftblock.GetSize() |
|
1045 movex = position[0] - LD_WIRE_SIZE - size[0] - pos[0] |
|
1046 block.Move(movex, 0) |
989 endpoint = wire.EndConnected.GetPosition(False) |
1047 endpoint = wire.EndConnected.GetPosition(False) |
990 if j == 0: |
1048 if j == 0: |
991 if not onlyone[i] and wire.EndConnected.GetWireIndex(wire) > 0: |
1049 if not onlyone[i] and wire.EndConnected.GetWireIndex(wire) > 0: |
992 start_offset = endpoint.y - startpoint.y |
1050 start_offset = endpoint.y - startpoint.y |
993 offset = start_offset |
1051 offset = start_offset |
1000 wxPoint(middlepoint, startpoint.y + offset), |
1058 wxPoint(middlepoint, startpoint.y + offset), |
1001 wxPoint(endmiddlepoint, startpoint.y + offset), |
1059 wxPoint(endmiddlepoint, startpoint.y + offset), |
1002 wxPoint(endmiddlepoint, endpoint.y), endpoint] |
1060 wxPoint(endmiddlepoint, endpoint.y), endpoint] |
1003 else: |
1061 else: |
1004 if startpoint.y + offset != endpoint.y: |
1062 if startpoint.y + offset != endpoint.y: |
1005 if isinstance(block, LD_PowerRail): |
1063 if isinstance(element, LD_PowerRail): |
|
1064 diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE |
|
1065 for k in xrange(abs(diff)): |
|
1066 if diff < 0: |
|
1067 element.DeleteConnector(i - 1 - k) |
|
1068 else: |
|
1069 element.InsertConnector(i + k, False) |
|
1070 elif isinstance(block, LD_PowerRail): |
1006 index = block.GetConnectorIndex(wire.EndConnected) |
1071 index = block.GetConnectorIndex(wire.EndConnected) |
1007 if index: |
1072 if index: |
1008 diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE |
1073 diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE |
1009 for k in xrange(abs(diff)): |
1074 for k in xrange(abs(diff)): |
1010 if diff < 0: |
1075 if diff < 0: |
1011 block.DeleteConnector(index - 1 - k) |
1076 block.DeleteConnector(index - 1 - k) |
1012 else: |
1077 else: |
1013 block.InsertConnector(index + k, False) |
1078 block.InsertConnector(index + k, False) |
1014 else: |
1079 else: |
1015 block.Move(0, startpoint.y + offset - endpoint.y) |
1080 block.Move(0, startpoint.y + offset - endpoint.y) |
1016 self.RefreshPosition(block) |
1081 self.RefreshPosition(block, False) |
1017 endpoint = wire.EndConnected.GetPosition(False) |
1082 endpoint = wire.EndConnected.GetPosition(False) |
1018 if not onlyone[i]: |
1083 if not onlyone[i]: |
1019 points = [startpoint, wxPoint(middlepoint, startpoint.y), |
1084 points = [startpoint, wxPoint(middlepoint, startpoint.y), |
1020 wxPoint(middlepoint, endpoint.y), endpoint] |
1085 wxPoint(middlepoint, endpoint.y), endpoint] |
1021 else: |
1086 else: |
1022 points = [startpoint, endpoint] |
1087 points = [startpoint, endpoint] |
1023 wire.SetPoints(points) |
1088 wire.SetPoints(points) |
1024 previous_blocks.append(block) |
1089 previous_blocks.append(block) |
1025 ExtractNextBlocks(block, block_list) |
1090 ExtractNextBlocks(block, block_list) |
1026 element.RefreshModel(False) |
1091 element.RefreshModel(False) |
1027 for connector in output_connectors: |
1092 if recursive: |
1028 for wire, handle in connector.GetWires(): |
1093 for connector in output_connectors: |
1029 self.RefreshPosition(wire.StartConnected.GetParentBlock()) |
1094 for wire, handle in connector.GetWires(): |
|
1095 self.RefreshPosition(wire.StartConnected.GetParentBlock()) |
1030 |
1096 |
1031 def RefreshRungs(self, movey, fromidx): |
1097 def RefreshRungs(self, movey, fromidx): |
1032 if movey != 0: |
1098 if movey != 0: |
1033 for i in xrange(fromidx, len(self.Rungs)): |
1099 for i in xrange(fromidx, len(self.Rungs)): |
1034 self.Comments[i].Move(0, movey) |
1100 self.Comments[i].Move(0, movey) |