236 def DrawHighlightedText(dc, text, highlights, x, y): |
236 def DrawHighlightedText(dc, text, highlights, x, y): |
237 current_pen = dc.GetPen() |
237 current_pen = dc.GetPen() |
238 dc.SetPen(wx.TRANSPARENT_PEN) |
238 dc.SetPen(wx.TRANSPARENT_PEN) |
239 for start, end, highlight_type in highlights: |
239 for start, end, highlight_type in highlights: |
240 dc.SetBrush(wx.Brush(highlight_type[0])) |
240 dc.SetBrush(wx.Brush(highlight_type[0])) |
241 offset_width, offset_height = dc.GetTextExtent(text[:start[1]]) |
241 offset_width, _offset_height = dc.GetTextExtent(text[:start[1]]) |
242 part = text[start[1]:end[1] + 1] |
242 part = text[start[1]:end[1] + 1] |
243 part_width, part_height = dc.GetTextExtent(part) |
243 part_width, part_height = dc.GetTextExtent(part) |
244 dc.DrawRectangle(x + offset_width, y, part_width, part_height) |
244 dc.DrawRectangle(x + offset_width, y, part_width, part_height) |
245 dc.SetTextForeground(highlight_type[1]) |
245 dc.SetTextForeground(highlight_type[1]) |
246 dc.DrawText(part, x + offset_width, y) |
246 dc.DrawText(part, x + offset_width, y) |
955 max_movey = max(max_movey, movey) |
955 max_movey = max(max_movey, movey) |
956 return max_movex, max_movey |
956 return max_movex, max_movey |
957 |
957 |
958 # Refreshes the group elements to move defined and handle selected |
958 # Refreshes the group elements to move defined and handle selected |
959 def ProcessDragging(self, movex, movey, event, scaling): |
959 def ProcessDragging(self, movex, movey, event, scaling): |
960 handle_type, handle = self.Handle |
960 handle_type, _handle = self.Handle |
961 # If it is a move handle, Move this group elements |
961 # If it is a move handle, Move this group elements |
962 if handle_type == HANDLE_MOVE: |
962 if handle_type == HANDLE_MOVE: |
963 movex = max(-self.BoundingBox.x, movex) |
963 movex = max(-self.BoundingBox.x, movex) |
964 movey = max(-self.BoundingBox.y, movey) |
964 movey = max(-self.BoundingBox.y, movey) |
965 if scaling is not None: |
965 if scaling is not None: |
1053 self.Highlights = [] |
1053 self.Highlights = [] |
1054 self.RefreshNameSize() |
1054 self.RefreshNameSize() |
1055 |
1055 |
1056 def Flush(self): |
1056 def Flush(self): |
1057 self.ParentBlock = None |
1057 self.ParentBlock = None |
1058 for wire, handle in self.Wires: |
1058 for wire, _handle in self.Wires: |
1059 wire.Flush() |
1059 wire.Flush() |
1060 self.Wires = [] |
1060 self.Wires = [] |
1061 |
1061 |
1062 # Returns the RedrawRect |
1062 # Returns the RedrawRect |
1063 def GetRedrawRect(self, movex=0, movey=0): |
1063 def GetRedrawRect(self, movex=0, movey=0): |
1126 return self.Type |
1126 return self.Type |
1127 |
1127 |
1128 # Returns the connector type |
1128 # Returns the connector type |
1129 def GetConnectedRedrawRect(self, movex, movey): |
1129 def GetConnectedRedrawRect(self, movex, movey): |
1130 rect = None |
1130 rect = None |
1131 for wire, handle in self.Wires: |
1131 for wire, _handle in self.Wires: |
1132 if rect is None: |
1132 if rect is None: |
1133 rect = wire.GetRedrawRect() |
1133 rect = wire.GetRedrawRect() |
1134 else: |
1134 else: |
1135 rect = rect.Union(wire.GetRedrawRect()) |
1135 rect = rect.Union(wire.GetRedrawRect()) |
1136 return rect |
1136 return rect |
1141 return self.ParentBlock.IsOfType(type, reference) or self.ParentBlock.IsOfType(reference, type) |
1141 return self.ParentBlock.IsOfType(type, reference) or self.ParentBlock.IsOfType(reference, type) |
1142 |
1142 |
1143 # Changes the connector name |
1143 # Changes the connector name |
1144 def SetType(self, type): |
1144 def SetType(self, type): |
1145 self.Type = type |
1145 self.Type = type |
1146 for wire, handle in self.Wires: |
1146 for wire, _handle in self.Wires: |
1147 wire.SetValid(wire.IsConnectedCompatible()) |
1147 wire.SetValid(wire.IsConnectedCompatible()) |
1148 |
1148 |
1149 # Returns the connector name |
1149 # Returns the connector name |
1150 def GetName(self): |
1150 def GetName(self): |
1151 return self.Name |
1151 return self.Name |
1182 if self.ParentBlock.Visible: |
1182 if self.ParentBlock.Visible: |
1183 self.ParentBlock.Parent.ElementNeedRefresh(self) |
1183 self.ParentBlock.Parent.ElementNeedRefresh(self) |
1184 |
1184 |
1185 def RefreshForced(self): |
1185 def RefreshForced(self): |
1186 self.Forced = False |
1186 self.Forced = False |
1187 for wire, handle in self.Wires: |
1187 for wire, _handle in self.Wires: |
1188 self.Forced |= wire.IsForced() |
1188 self.Forced |= wire.IsForced() |
1189 |
1189 |
1190 def RefreshValue(self): |
1190 def RefreshValue(self): |
1191 self.Value = self.ReceivingCurrent() |
1191 self.Value = self.ReceivingCurrent() |
1192 |
1192 |
1193 def RefreshValid(self): |
1193 def RefreshValid(self): |
1194 self.Valid = True |
1194 self.Valid = True |
1195 for wire, handle in self.Wires: |
1195 for wire, _handle in self.Wires: |
1196 self.Valid &= wire.GetValid() |
1196 self.Valid &= wire.GetValid() |
1197 |
1197 |
1198 def ReceivingCurrent(self): |
1198 def ReceivingCurrent(self): |
1199 current = False |
1199 current = False |
1200 for wire, handle in self.Wires: |
1200 for wire, _handle in self.Wires: |
1201 value = wire.GetValue() |
1201 value = wire.GetValue() |
1202 if current != "undefined" and isinstance(value, BooleanType): |
1202 if current != "undefined" and isinstance(value, BooleanType): |
1203 current |= wire.GetValue() |
1203 current |= wire.GetValue() |
1204 elif value == "undefined": |
1204 elif value == "undefined": |
1205 current = "undefined" |
1205 current = "undefined" |
1206 return current |
1206 return current |
1207 |
1207 |
1208 def SpreadCurrent(self, spreading): |
1208 def SpreadCurrent(self, spreading): |
1209 for wire, handle in self.Wires: |
1209 for wire, _handle in self.Wires: |
1210 wire.SetValue(spreading) |
1210 wire.SetValue(spreading) |
1211 |
1211 |
1212 # Changes the connector name size |
1212 # Changes the connector name size |
1213 def RefreshNameSize(self): |
1213 def RefreshNameSize(self): |
1214 if self.Name != "": |
1214 if self.Name != "": |
1271 if refresh: |
1271 if refresh: |
1272 self.ParentBlock.RefreshModel(False) |
1272 self.ParentBlock.RefreshModel(False) |
1273 |
1273 |
1274 # Returns the index of the wire given in the list of connected |
1274 # Returns the index of the wire given in the list of connected |
1275 def GetWireIndex(self, wire): |
1275 def GetWireIndex(self, wire): |
1276 for i, (tmp_wire, handle) in enumerate(self.Wires): |
1276 for i, (tmp_wire, _handle) in enumerate(self.Wires): |
1277 if tmp_wire == wire: |
1277 if tmp_wire == wire: |
1278 return i |
1278 return i |
1279 return None |
1279 return None |
1280 |
1280 |
1281 # Unconnect a wire or all wires connected to the connector |
1281 # Unconnect a wire or all wires connected to the connector |
1425 dc.SetUserScale(scalex, scaley) |
1425 dc.SetUserScale(scalex, scaley) |
1426 |
1426 |
1427 # Adds an highlight to the connector |
1427 # Adds an highlight to the connector |
1428 def AddHighlight(self, infos, start, end, highlight_type): |
1428 def AddHighlight(self, infos, start, end, highlight_type): |
1429 if highlight_type == ERROR_HIGHLIGHT: |
1429 if highlight_type == ERROR_HIGHLIGHT: |
1430 for wire, handle in self.Wires: |
1430 for wire, _handle in self.Wires: |
1431 wire.SetValid(False) |
1431 wire.SetValid(False) |
1432 AddHighlight(self.Highlights, (start, end, highlight_type)) |
1432 AddHighlight(self.Highlights, (start, end, highlight_type)) |
1433 |
1433 |
1434 # Removes an highlight from the connector |
1434 # Removes an highlight from the connector |
1435 def RemoveHighlight(self, infos, start, end, highlight_type): |
1435 def RemoveHighlight(self, infos, start, end, highlight_type): |
1439 if highlight != (start, end, highlight_type): |
1439 if highlight != (start, end, highlight_type): |
1440 highlights.append(highlight) |
1440 highlights.append(highlight) |
1441 error |= highlight == ERROR_HIGHLIGHT |
1441 error |= highlight == ERROR_HIGHLIGHT |
1442 self.Highlights = highlights |
1442 self.Highlights = highlights |
1443 if not error: |
1443 if not error: |
1444 for wire, handle in self.Wires: |
1444 for wire, _handle in self.Wires: |
1445 wire.SetValid(wire.IsConnectedCompatible()) |
1445 wire.SetValid(wire.IsConnectedCompatible()) |
1446 |
1446 |
1447 # Removes all the highlights of one particular type from the connector |
1447 # Removes all the highlights of one particular type from the connector |
1448 def ClearHighlight(self, highlight_type=None): |
1448 def ClearHighlight(self, highlight_type=None): |
1449 error = False |
1449 error = False |
1455 if highlight[2] != highlight_type: |
1455 if highlight[2] != highlight_type: |
1456 highlights.append(highlight) |
1456 highlights.append(highlight) |
1457 error |= highlight == ERROR_HIGHLIGHT |
1457 error |= highlight == ERROR_HIGHLIGHT |
1458 self.Highlights = highlights |
1458 self.Highlights = highlights |
1459 if not error: |
1459 if not error: |
1460 for wire, handle in self.Wires: |
1460 for wire, _handle in self.Wires: |
1461 wire.SetValid(wire.IsConnectedCompatible()) |
1461 wire.SetValid(wire.IsConnectedCompatible()) |
1462 |
1462 |
1463 # Draws the connector |
1463 # Draws the connector |
1464 def Draw(self, dc): |
1464 def Draw(self, dc): |
1465 if self.Selected: |
1465 if self.Selected: |
1982 i = 0 |
1982 i = 0 |
1983 while i < len(self.Points) - 1: |
1983 while i < len(self.Points) - 1: |
1984 if verify and 0 < i < len(self.Points) - 2 and \ |
1984 if verify and 0 < i < len(self.Points) - 2 and \ |
1985 self.Points[i] == self.Points[i + 1] and \ |
1985 self.Points[i] == self.Points[i + 1] and \ |
1986 self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]): |
1986 self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]): |
1987 for j in xrange(2): |
1987 for dummy in xrange(2): |
1988 self.Points.pop(i) |
1988 self.Points.pop(i) |
1989 else: |
1989 else: |
1990 segment = vector(self.Points[i], self.Points[i + 1]) |
1990 segment = vector(self.Points[i], self.Points[i + 1]) |
1991 if is_null_vector(segment) and i > 0: |
1991 if is_null_vector(segment) and i > 0: |
1992 segment = (self.Segments[-1][1], self.Segments[-1][0]) |
1992 segment = (self.Segments[-1][1], self.Segments[-1][0]) |
2204 points = [point for point in self.Points] |
2204 points = [point for point in self.Points] |
2205 segments = [segment for segment in self.Segments] |
2205 segments = [segment for segment in self.Segments] |
2206 i = 1 |
2206 i = 1 |
2207 while i < len(points) - 1: |
2207 while i < len(points) - 1: |
2208 if points[i] == points[i + 1] and segments[i - 1] == segments[i + 1]: |
2208 if points[i] == points[i + 1] and segments[i - 1] == segments[i + 1]: |
2209 for j in xrange(2): |
2209 for dummy in xrange(2): |
2210 points.pop(i) |
2210 points.pop(i) |
2211 segments.pop(i) |
2211 segments.pop(i) |
2212 else: |
2212 else: |
2213 i += 1 |
2213 i += 1 |
2214 # If the wire isn't in a Ladder Diagram, save the new point list |
2214 # If the wire isn't in a Ladder Diagram, save the new point list |
2429 |
2429 |
2430 # Delete the handled segment by removing the two segment points |
2430 # Delete the handled segment by removing the two segment points |
2431 def DeleteSegment(self): |
2431 def DeleteSegment(self): |
2432 handle_type, handle = self.Handle |
2432 handle_type, handle = self.Handle |
2433 if handle_type == HANDLE_SEGMENT: |
2433 if handle_type == HANDLE_SEGMENT: |
2434 segment, dir = handle |
2434 segment, _dir = handle |
2435 for i in xrange(2): |
2435 for dummy in xrange(2): |
2436 self.Points.pop(segment) |
2436 self.Points.pop(segment) |
2437 self.Segments.pop(segment) |
2437 self.Segments.pop(segment) |
2438 self.GeneratePoints() |
2438 self.GeneratePoints() |
2439 self.RefreshModel() |
2439 self.RefreshModel() |
2440 |
2440 |