20 # |
20 # |
21 #You should have received a copy of the GNU General Public |
21 #You should have received a copy of the GNU General Public |
22 #License along with this library; if not, write to the Free Software |
22 #License along with this library; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 from wxPython.wx import * |
|
26 import wx |
25 import wx |
27 from math import * |
26 from math import * |
28 |
27 |
29 |
28 |
30 #------------------------------------------------------------------------------- |
29 #------------------------------------------------------------------------------- |
89 CURSORS = None |
88 CURSORS = None |
90 |
89 |
91 def ResetCursors(): |
90 def ResetCursors(): |
92 global CURSORS |
91 global CURSORS |
93 if CURSORS == None: |
92 if CURSORS == None: |
94 CURSORS = [wxNullCursor, |
93 CURSORS = [wx.NullCursor, |
95 wxStockCursor(wxCURSOR_HAND), |
94 wx.StockCursor(wx.CURSOR_HAND), |
96 wxStockCursor(wxCURSOR_SIZENWSE), |
95 wx.StockCursor(wx.CURSOR_SIZENWSE), |
97 wxStockCursor(wxCURSOR_SIZENESW), |
96 wx.StockCursor(wx.CURSOR_SIZENESW), |
98 wxStockCursor(wxCURSOR_SIZEWE), |
97 wx.StockCursor(wx.CURSOR_SIZEWE), |
99 wxStockCursor(wxCURSOR_SIZENS)] |
98 wx.StockCursor(wx.CURSOR_SIZENS)] |
100 |
99 |
101 HANDLE_CURSORS = { |
100 HANDLE_CURSORS = { |
102 (1, 1) : 2, |
101 (1, 1) : 2, |
103 (3, 3) : 2, |
102 (3, 3) : 2, |
104 (1, 3) : 3, |
103 (1, 3) : 3, |
195 # Method called when a new box starts to be edited |
194 # Method called when a new box starts to be edited |
196 def OnLeftDown(self, event, dc, scaling): |
195 def OnLeftDown(self, event, dc, scaling): |
197 pos = GetScaledEventPosition(event, dc, scaling) |
196 pos = GetScaledEventPosition(event, dc, scaling) |
198 # Save the point for calculate the box position and size |
197 # Save the point for calculate the box position and size |
199 self.startPoint = pos |
198 self.startPoint = pos |
200 self.currentBox = wxRect(pos.x, pos.y, 0, 0) |
199 self.currentBox = wx.Rect(pos.x, pos.y, 0, 0) |
201 self.drawingSurface.SetCursor(wxStockCursor(wxCURSOR_CROSS)) |
200 self.drawingSurface.SetCursor(wx.StockCursor(wx.CURSOR_CROSS)) |
202 self.Redraw() |
201 self.Redraw() |
203 |
202 |
204 # Method called when dragging with a box edited |
203 # Method called when dragging with a box edited |
205 def OnMotion(self, event, dc, scaling): |
204 def OnMotion(self, event, dc, scaling): |
206 pos = GetScaledEventPosition(event, dc, scaling) |
205 pos = GetScaledEventPosition(event, dc, scaling) |
207 # Save the last position and size of the box for erasing it |
206 # Save the last position and size of the box for erasing it |
208 self.lastBox = wxRect(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
207 self.lastBox = wx.Rect(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
209 self.currentBox.height) |
208 self.currentBox.height) |
210 # Calculate new position and size of the box |
209 # Calculate new position and size of the box |
211 if pos.x >= self.startPoint.x: |
210 if pos.x >= self.startPoint.x: |
212 self.currentBox.x = self.startPoint.x |
211 self.currentBox.x = self.startPoint.x |
213 self.currentBox.width = pos.x - self.startPoint.x + 1 |
212 self.currentBox.width = pos.x - self.startPoint.x + 1 |
222 self.currentBox.height = self.startPoint.y - pos.y + 1 |
221 self.currentBox.height = self.startPoint.y - pos.y + 1 |
223 self.Redraw() |
222 self.Redraw() |
224 |
223 |
225 # Method called when dragging is stopped |
224 # Method called when dragging is stopped |
226 def OnLeftUp(self, event, dc, scaling): |
225 def OnLeftUp(self, event, dc, scaling): |
227 self.drawingSurface.SetCursor(wxNullCursor) |
226 self.drawingSurface.SetCursor(wx.NullCursor) |
228 self.lastBox = self.currentBox |
227 self.lastBox = self.currentBox |
229 self.currentBox = None |
228 self.currentBox = None |
230 self.Redraw() |
229 self.Redraw() |
231 |
230 |
232 # Method that erase the last box and draw the new box |
231 # Method that erase the last box and draw the new box |
233 def Redraw(self): |
232 def Redraw(self): |
234 dc = self.drawingSurface.GetLogicalDC() |
233 dc = self.drawingSurface.GetLogicalDC() |
235 dc.SetPen(wxPen(wxWHITE, 1, wxDOT)) |
234 dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT)) |
236 dc.SetBrush(wxTRANSPARENT_BRUSH) |
235 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
237 dc.SetLogicalFunction(wxXOR) |
236 dc.SetLogicalFunction(wx.XOR) |
238 if self.lastBox: |
237 if self.lastBox: |
239 # Erase last box |
238 # Erase last box |
240 dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width, |
239 dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width, |
241 self.lastBox.height) |
240 self.lastBox.height) |
242 if self.currentBox: |
241 if self.currentBox: |
245 self.currentBox.height) |
244 self.currentBox.height) |
246 |
245 |
247 # Erase last box |
246 # Erase last box |
248 def Erase(self): |
247 def Erase(self): |
249 dc = self.drawingSurface.GetLogicalDC() |
248 dc = self.drawingSurface.GetLogicalDC() |
250 dc.SetPen(wxPen(wxWHITE, 1, wxDOT)) |
249 dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT)) |
251 dc.SetBrush(wxTRANSPARENT_BRUSH) |
250 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
252 dc.SetLogicalFunction(wxXOR) |
251 dc.SetLogicalFunction(wx.XOR) |
253 if self.lastBox: |
252 if self.lastBox: |
254 dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width, |
253 dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width, |
255 self.lastBox.height) |
254 self.lastBox.height) |
256 |
255 |
257 # Draw current box |
256 # Draw current box |
258 def Draw(self): |
257 def Draw(self): |
259 dc = self.drawingSurface.GetLogicalDC() |
258 dc = self.drawingSurface.GetLogicalDC() |
260 dc.SetPen(wxPen(wxWHITE, 1, wxDOT)) |
259 dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT)) |
261 dc.SetBrush(wxTRANSPARENT_BRUSH) |
260 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
262 dc.SetLogicalFunction(wxXOR) |
261 dc.SetLogicalFunction(wx.XOR) |
263 if self.currentBox: |
262 if self.currentBox: |
264 # Draw current box |
263 # Draw current box |
265 dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
264 dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
266 self.currentBox.height) |
265 self.currentBox.height) |
267 |
266 |
282 self.Id = id |
281 self.Id = id |
283 self.oldPos = None |
282 self.oldPos = None |
284 self.Handle = False |
283 self.Handle = False |
285 self.Dragging = False |
284 self.Dragging = False |
286 self.Selected = False |
285 self.Selected = False |
287 self.Pos = wxPoint(0, 0) |
286 self.Pos = wx.Point(0, 0) |
288 self.Size = wxSize(0, 0) |
287 self.Size = wx.Size(0, 0) |
289 self.BoundingBox = wxRect(0, 0, 0, 0) |
288 self.BoundingBox = wx.Rect(0, 0, 0, 0) |
290 self.CurrentCursor = 0 |
289 self.CurrentCursor = 0 |
291 ResetCursors() |
290 ResetCursors() |
292 |
291 |
293 # Make a clone of this element |
292 # Make a clone of this element |
294 def Clone(self): |
293 def Clone(self): |
316 def GetSize(self): |
315 def GetSize(self): |
317 return self.Size.GetWidth(), self.Size.GetHeight() |
316 return self.Size.GetWidth(), self.Size.GetHeight() |
318 |
317 |
319 # Refresh the element Bounding Box |
318 # Refresh the element Bounding Box |
320 def RefreshBoundingBox(self): |
319 def RefreshBoundingBox(self): |
321 self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]) |
320 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]) |
322 |
321 |
323 # Refresh the element connectors position |
322 # Refresh the element connectors position |
324 def RefreshConnectors(self): |
323 def RefreshConnectors(self): |
325 pass |
324 pass |
326 |
325 |
361 def SetSelected(self, selected): |
360 def SetSelected(self, selected): |
362 self.Selected = selected |
361 self.Selected = selected |
363 |
362 |
364 # Test if the point is on a handle of this element |
363 # Test if the point is on a handle of this element |
365 def TestHandle(self, pt): |
364 def TestHandle(self, pt): |
366 extern_rect = wxRect(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, |
365 extern_rect = wx.Rect(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, |
367 self.BoundingBox.width + 2 * HANDLE_SIZE + 4, self.BoundingBox.height + 2 * HANDLE_SIZE + 4) |
366 self.BoundingBox.width + 2 * HANDLE_SIZE + 4, self.BoundingBox.height + 2 * HANDLE_SIZE + 4) |
368 intern_rect = wxRect(self.BoundingBox.x - 2, self.BoundingBox.y - 2, |
367 intern_rect = wx.Rect(self.BoundingBox.x - 2, self.BoundingBox.y - 2, |
369 self.BoundingBox.width + 4, self.BoundingBox.height + 4) |
368 self.BoundingBox.width + 4, self.BoundingBox.height + 4) |
370 # Verify that this element is selected |
369 # Verify that this element is selected |
371 if self.Selected and extern_rect.InsideXY(pt.x, pt.y) and not intern_rect.InsideXY(pt.x, pt.y): |
370 if self.Selected and extern_rect.InsideXY(pt.x, pt.y) and not intern_rect.InsideXY(pt.x, pt.y): |
372 # Find if point is on a handle horizontally |
371 # Find if point is on a handle horizontally |
373 if self.BoundingBox.x - HANDLE_SIZE - 2 <= pt.x < self.BoundingBox.x - 2: |
372 if self.BoundingBox.x - HANDLE_SIZE - 2 <= pt.x < self.BoundingBox.x - 2: |
505 pass |
504 pass |
506 |
505 |
507 # Draws the handles of this element if it is selected |
506 # Draws the handles of this element if it is selected |
508 def Draw(self, dc): |
507 def Draw(self, dc): |
509 if self.Selected: |
508 if self.Selected: |
510 dc.SetPen(wxBLACK_PEN) |
509 dc.SetPen(wx.BLACK_PEN) |
511 dc.SetBrush(wxBLACK_BRUSH) |
510 dc.SetBrush(wx.BLACK_BRUSH) |
512 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
511 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
513 dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, |
512 dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, |
514 self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
513 self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
515 dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, |
514 dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, |
516 self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
515 self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
520 self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
519 self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
521 dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, |
520 dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, |
522 self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
521 self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
523 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
522 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
524 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE) |
523 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE) |
525 dc.SetBrush(wxWHITE_BRUSH) |
524 dc.SetBrush(wx.WHITE_BRUSH) |
526 |
525 |
527 |
526 |
528 #------------------------------------------------------------------------------- |
527 #------------------------------------------------------------------------------- |
529 # Group of graphic elements |
528 # Group of graphic elements |
530 #------------------------------------------------------------------------------- |
529 #------------------------------------------------------------------------------- |
630 bbox = element.GetBoundingBox() |
629 bbox = element.GetBoundingBox() |
631 minx = min(minx, bbox.x) |
630 minx = min(minx, bbox.x) |
632 miny = min(miny, bbox.y) |
631 miny = min(miny, bbox.y) |
633 maxx = max(maxx, bbox.x + bbox.width) |
632 maxx = max(maxx, bbox.x + bbox.width) |
634 maxy = max(maxy, bbox.y + bbox.height) |
633 maxy = max(maxy, bbox.y + bbox.height) |
635 self.BoundingBox = wxRect(minx, miny, maxx - minx, maxy - miny) |
634 self.BoundingBox = wx.Rect(minx, miny, maxx - minx, maxy - miny) |
636 else: |
635 else: |
637 self.BoundingBox = wxRect(0, 0, 0, 0) |
636 self.BoundingBox = wx.Rect(0, 0, 0, 0) |
638 |
637 |
639 # Forbids to change the group position |
638 # Forbids to change the group position |
640 def SetPosition(x, y): |
639 def SetPosition(x, y): |
641 pass |
640 pass |
642 |
641 |
682 self.Direction = direction |
681 self.Direction = direction |
683 self.Wires = [] |
682 self.Wires = [] |
684 self.Negated = negated |
683 self.Negated = negated |
685 self.Edge = edge |
684 self.Edge = edge |
686 self.OneConnected = onlyone |
685 self.OneConnected = onlyone |
687 self.Pen = wxBLACK_PEN |
686 self.Pen = wx.BLACK_PEN |
688 self.RefreshNameSize() |
687 self.RefreshNameSize() |
689 |
688 |
690 # Change the connector pen |
689 # Change the connector pen |
691 def SetPen(self, pen): |
690 def SetPen(self, pen): |
692 self.Pen = pen |
691 self.Pen = pen |
693 |
692 |
694 # Make a clone of the connector |
693 # Make a clone of the connector |
695 def Clone(self): |
694 def Clone(self): |
696 return Connector(self.ParentBlock, self.Name, self.Type, wxPoint(self.Pos[0], self.Pos[1]), |
695 return Connector(self.ParentBlock, self.Name, self.Type, wx.Point(self.Pos[0], self.Pos[1]), |
697 self.Direction, self.Negated) |
696 self.Direction, self.Negated) |
698 |
697 |
699 # Returns the connector parent block |
698 # Returns the connector parent block |
700 def GetParentBlock(self): |
699 def GetParentBlock(self): |
701 return self.ParentBlock |
700 return self.ParentBlock |
749 x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE |
748 x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE |
750 y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE |
749 y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE |
751 else: |
750 else: |
752 x = parent_pos[0] + self.Pos.x |
751 x = parent_pos[0] + self.Pos.x |
753 y = parent_pos[1] + self.Pos.y |
752 y = parent_pos[1] + self.Pos.y |
754 return wxPoint(x, y) |
753 return wx.Point(x, y) |
755 |
754 |
756 # Change the connector relative position |
755 # Change the connector relative position |
757 def SetPosition(self, pos): |
756 def SetPosition(self, pos): |
758 self.Pos = pos |
757 self.Pos = pos |
759 |
758 |
818 y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE |
817 y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE |
819 # Move the corresponding point on all the wires connected |
818 # Move the corresponding point on all the wires connected |
820 for wire, index in self.Wires: |
819 for wire, index in self.Wires: |
821 if wire not in exclude: |
820 if wire not in exclude: |
822 if index == 0: |
821 if index == 0: |
823 wire.MoveStartPoint(wxPoint(x, y)) |
822 wire.MoveStartPoint(wx.Point(x, y)) |
824 else: |
823 else: |
825 wire.MoveEndPoint(wxPoint(x, y)) |
824 wire.MoveEndPoint(wx.Point(x, y)) |
826 |
825 |
827 # Refreshes the model of all the wires connected |
826 # Refreshes the model of all the wires connected |
828 def RefreshWires(self): |
827 def RefreshWires(self): |
829 for wire in self.Wires: |
828 for wire in self.Wires: |
830 wire[0].RefreshModel() |
829 wire[0].RefreshModel() |
837 def GetConnectedBlocks(self): |
836 def GetConnectedBlocks(self): |
838 blocks = [] |
837 blocks = [] |
839 for wire, handle in self.Wires: |
838 for wire, handle in self.Wires: |
840 # Get other connector connected to each wire |
839 # Get other connector connected to each wire |
841 if handle == 0: |
840 if handle == 0: |
842 connector = blocks.GetEndConnected() |
841 connector = wire.GetEndConnected() |
843 else: |
842 else: |
844 connector = blocks.GetStartConnected() |
843 connector = wire.GetStartConnected() |
845 # Get parent block for this connector |
844 # Get parent block for this connector |
846 if connector: |
845 if connector: |
847 block = connector.GetParentBlock() |
846 block = connector.GetParentBlock() |
848 if block not in blocks: |
847 if block not in blocks: |
849 blocks.append(block) |
848 blocks.append(block) |
874 # Calculate a square around the end point of this connector |
873 # Calculate a square around the end point of this connector |
875 x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE |
874 x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE |
876 y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE |
875 y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE |
877 width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE |
876 width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE |
878 height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE |
877 height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE |
879 rect = wxRect(x, y, width, height) |
878 rect = wx.Rect(x, y, width, height) |
880 return rect.InsideXY(pt.x, pt.y) |
879 return rect.InsideXY(pt.x, pt.y) |
881 return False |
880 return False |
882 |
881 |
883 # Draws the connector |
882 # Draws the connector |
884 def Draw(self, dc): |
883 def Draw(self, dc): |
885 dc.SetPen(self.Pen) |
884 dc.SetPen(self.Pen) |
886 dc.SetBrush(wxWHITE_BRUSH) |
885 dc.SetBrush(wx.WHITE_BRUSH) |
887 parent_pos = self.ParentBlock.GetPosition() |
886 parent_pos = self.ParentBlock.GetPosition() |
888 if self.Negated: |
887 if self.Negated: |
889 # If connector is negated, draw a circle |
888 # If connector is negated, draw a circle |
890 xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) / 2 |
889 xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) / 2 |
891 ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) / 2 |
890 ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) / 2 |
986 if segment == -1: |
985 if segment == -1: |
987 segment = len(self.Segments) - 1 |
986 segment = len(self.Segments) - 1 |
988 # The selected segment is reinitialised |
987 # The selected segment is reinitialised |
989 if segment == None: |
988 if segment == None: |
990 if self.StartConnected: |
989 if self.StartConnected: |
991 self.StartConnected.SetPen(wxBLACK_PEN) |
990 self.StartConnected.SetPen(wx.BLACK_PEN) |
992 if self.EndConnected: |
991 if self.EndConnected: |
993 self.EndConnected.SetPen(wxBLACK_PEN) |
992 self.EndConnected.SetPen(wx.BLACK_PEN) |
994 # The segment selected is the first |
993 # The segment selected is the first |
995 elif segment == 0: |
994 elif segment == 0: |
996 if self.StartConnected: |
995 if self.StartConnected: |
997 self.StartConnected.SetPen(wxRED_PEN) |
996 self.StartConnected.SetPen(wx.RED_PEN) |
998 if self.EndConnected: |
997 if self.EndConnected: |
999 # There is only one segment |
998 # There is only one segment |
1000 if len(self.Segments) == 1: |
999 if len(self.Segments) == 1: |
1001 self.EndConnected.SetPen(wxRED_PEN) |
1000 self.EndConnected.SetPen(wx.RED_PEN) |
1002 else: |
1001 else: |
1003 self.EndConnected.SetPen(wxBLACK_PEN) |
1002 self.EndConnected.SetPen(wx.BLACK_PEN) |
1004 # The segment selected is the last |
1003 # The segment selected is the last |
1005 elif segment == len(self.Segments) - 1: |
1004 elif segment == len(self.Segments) - 1: |
1006 if self.StartConnected: |
1005 if self.StartConnected: |
1007 self.StartConnected.SetPen(wxBLACK_PEN) |
1006 self.StartConnected.SetPen(wx.BLACK_PEN) |
1008 if self.EndConnected: |
1007 if self.EndConnected: |
1009 self.EndConnected.SetPen(wxRED_PEN) |
1008 self.EndConnected.SetPen(wx.RED_PEN) |
1010 self.SelectedSegment = segment |
1009 self.SelectedSegment = segment |
1011 |
1010 |
1012 # Reinitialize the wire points |
1011 # Reinitialize the wire points |
1013 def ResetPoints(self): |
1012 def ResetPoints(self): |
1014 if self.StartPoint and self.EndPoint: |
1013 if self.StartPoint and self.EndPoint: |
1041 if len(self.Points) > 1: |
1040 if len(self.Points) > 1: |
1042 minx, minbbxx = min(minx, self.Points[-1].x), min(minbbxx, self.Points[-1].x - end_radius) |
1041 minx, minbbxx = min(minx, self.Points[-1].x), min(minbbxx, self.Points[-1].x - end_radius) |
1043 maxx, maxbbxx = max(maxx, self.Points[-1].x), max(maxbbxx, self.Points[-1].x + end_radius) |
1042 maxx, maxbbxx = max(maxx, self.Points[-1].x), max(maxbbxx, self.Points[-1].x + end_radius) |
1044 miny, minbbxy = min(miny, self.Points[-1].y), min(minbbxy, self.Points[-1].y - end_radius) |
1043 miny, minbbxy = min(miny, self.Points[-1].y), min(minbbxy, self.Points[-1].y - end_radius) |
1045 maxy, maxbbxy = max(maxy, self.Points[-1].y), max(maxbbxy, self.Points[-1].y + end_radius) |
1044 maxy, maxbbxy = max(maxy, self.Points[-1].y), max(maxbbxy, self.Points[-1].y + end_radius) |
1046 self.Pos = wxPoint(minx, miny) |
1045 self.Pos = wx.Point(minx, miny) |
1047 self.Size = wxSize(maxx -minx + 1, maxy - miny + 1) |
1046 self.Size = wx.Size(maxx -minx + 1, maxy - miny + 1) |
1048 self.BoundingBox = wxRect(minbbxx, minbbxy, maxbbxx - minbbxx + 1, maxbbxy - minbbxy + 1) |
1047 self.BoundingBox = wx.Rect(minbbxx, minbbxy, maxbbxx - minbbxx + 1, maxbbxy - minbbxy + 1) |
1049 |
1048 |
1050 # Refresh the realpoints that permits to keep the proportionality in wire during resizing |
1049 # Refresh the realpoints that permits to keep the proportionality in wire during resizing |
1051 def RefreshRealPoints(self): |
1050 def RefreshRealPoints(self): |
1052 if len(self.Points) > 0: |
1051 if len(self.Points) > 0: |
1053 self.RealPoints = [] |
1052 self.RealPoints = [] |
1080 |
1079 |
1081 # Returns if the point given is on one of the wire segments |
1080 # Returns if the point given is on one of the wire segments |
1082 def HitTest(self, pt): |
1081 def HitTest(self, pt): |
1083 test = False |
1082 test = False |
1084 for i in xrange(len(self.Points) - 1): |
1083 for i in xrange(len(self.Points) - 1): |
1085 rect = wxRect(0, 0, 0, 0) |
1084 rect = wx.Rect(0, 0, 0, 0) |
1086 x1, y1 = self.Points[i].x, self.Points[i].y |
1085 x1, y1 = self.Points[i].x, self.Points[i].y |
1087 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
1086 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
1088 # Calculate a rectangle around the segment |
1087 # Calculate a rectangle around the segment |
1089 rect = wxRect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE, |
1088 rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE, |
1090 abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE) |
1089 abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE) |
1091 test |= rect.InsideXY(pt.x, pt.y) |
1090 test |= rect.InsideXY(pt.x, pt.y) |
1092 return test |
1091 return test |
1093 |
1092 |
1094 # Returns the wire start or end point if the point given is on one of them |
1093 # Returns the wire start or end point if the point given is on one of them |
1095 def TestPoint(self, pt): |
1094 def TestPoint(self, pt): |
1096 # Test the wire start point |
1095 # Test the wire start point |
1097 rect = wxRect(self.Points[0].x - ANCHOR_DISTANCE, self.Points[0].y - ANCHOR_DISTANCE, |
1096 rect = wx.Rect(self.Points[0].x - ANCHOR_DISTANCE, self.Points[0].y - ANCHOR_DISTANCE, |
1098 2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE) |
1097 2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE) |
1099 if rect.InsideXY(pt.x, pt.y): |
1098 if rect.InsideXY(pt.x, pt.y): |
1100 return 0 |
1099 return 0 |
1101 # Test the wire end point |
1100 # Test the wire end point |
1102 if len(self.Points) > 1: |
1101 if len(self.Points) > 1: |
1103 rect = wxRect(self.Points[-1].x - ANCHOR_DISTANCE, self.Points[-1].y - ANCHOR_DISTANCE, |
1102 rect = wx.Rect(self.Points[-1].x - ANCHOR_DISTANCE, self.Points[-1].y - ANCHOR_DISTANCE, |
1104 2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE) |
1103 2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE) |
1105 if rect.InsideXY(pt.x, pt.y): |
1104 if rect.InsideXY(pt.x, pt.y): |
1106 return -1 |
1105 return -1 |
1107 return None |
1106 return None |
1108 |
1107 |
1112 # If wire is not in a Ladder Diagram, first and last segments are excluded |
1111 # If wire is not in a Ladder Diagram, first and last segments are excluded |
1113 if 0 < i < len(self.Segments) - 1 or all: |
1112 if 0 < i < len(self.Segments) - 1 or all: |
1114 x1, y1 = self.Points[i].x, self.Points[i].y |
1113 x1, y1 = self.Points[i].x, self.Points[i].y |
1115 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
1114 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
1116 # Calculate a rectangle around the segment |
1115 # Calculate a rectangle around the segment |
1117 rect = wxRect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE, |
1116 rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE, |
1118 abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE) |
1117 abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE) |
1119 if rect.InsideXY(pt.x, pt.y): |
1118 if rect.InsideXY(pt.x, pt.y): |
1120 return i, self.Segments[i] |
1119 return i, self.Segments[i] |
1121 return None |
1120 return None |
1122 |
1121 |
1123 # Define the wire points |
1122 # Define the wire points |
1124 def SetPoints(self, points): |
1123 def SetPoints(self, points): |
1125 if len(points) > 1: |
1124 if len(points) > 1: |
1126 self.Points = [wxPoint(x, y) for x, y in points] |
1125 self.Points = [wx.Point(x, y) for x, y in points] |
1127 # Calculate the start and end directions |
1126 # Calculate the start and end directions |
1128 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1127 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1129 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1128 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1130 # Calculate the start and end points |
1129 # Calculate the start and end points |
1131 self.StartPoint[0] = wxPoint(self.Points[0].x + CONNECTOR_SIZE * self.StartPoint[1][0], |
1130 self.StartPoint[0] = wx.Point(self.Points[0].x + CONNECTOR_SIZE * self.StartPoint[1][0], |
1132 self.Points[0].y + CONNECTOR_SIZE * self.StartPoint[1][1]) |
1131 self.Points[0].y + CONNECTOR_SIZE * self.StartPoint[1][1]) |
1133 self.EndPoint[0] = wxPoint(self.Points[-1].x + CONNECTOR_SIZE * self.EndPoint[1][0], |
1132 self.EndPoint[0] = wx.Point(self.Points[-1].x + CONNECTOR_SIZE * self.EndPoint[1][0], |
1134 self.Points[-1].y + CONNECTOR_SIZE * self.EndPoint[1][1]) |
1133 self.Points[-1].y + CONNECTOR_SIZE * self.EndPoint[1][1]) |
1135 self.Points[0] = self.StartPoint[0] |
1134 self.Points[0] = self.StartPoint[0] |
1136 self.Points[-1] = self.EndPoint[0] |
1135 self.Points[-1] = self.EndPoint[0] |
1137 # Calculate the segments directions |
1136 # Calculate the segments directions |
1138 self.Segments = [] |
1137 self.Segments = [] |
1148 return None |
1147 return None |
1149 |
1148 |
1150 # Returns a list of the position of all wire points |
1149 # Returns a list of the position of all wire points |
1151 def GetPoints(self, invert = False): |
1150 def GetPoints(self, invert = False): |
1152 points = self.VerifyPoints() |
1151 points = self.VerifyPoints() |
1153 points[0] = wxPoint(points[0].x - CONNECTOR_SIZE * self.StartPoint[1][0], |
1152 points[0] = wx.Point(points[0].x - CONNECTOR_SIZE * self.StartPoint[1][0], |
1154 points[0].y - CONNECTOR_SIZE * self.StartPoint[1][1]) |
1153 points[0].y - CONNECTOR_SIZE * self.StartPoint[1][1]) |
1155 points[-1] = wxPoint(points[-1].x - CONNECTOR_SIZE * self.EndPoint[1][0], |
1154 points[-1] = wx.Point(points[-1].x - CONNECTOR_SIZE * self.EndPoint[1][0], |
1156 points[-1].y - CONNECTOR_SIZE * self.EndPoint[1][1]) |
1155 points[-1].y - CONNECTOR_SIZE * self.EndPoint[1][1]) |
1157 # An inversion of the list is asked |
1156 # An inversion of the list is asked |
1158 if invert: |
1157 if invert: |
1159 points.reverse() |
1158 points.reverse() |
1160 return points |
1159 return points |
1190 |
1189 |
1191 # Update the wire points position by keeping at most possible the current positions |
1190 # Update the wire points position by keeping at most possible the current positions |
1192 def GeneratePoints(self, realpoints = True): |
1191 def GeneratePoints(self, realpoints = True): |
1193 i = 0 |
1192 i = 0 |
1194 # Calculate the start enad end points with the minimum segment size in the right direction |
1193 # Calculate the start enad end points with the minimum segment size in the right direction |
1195 end = wxPoint(self.EndPoint[0].x + self.EndPoint[1][0] * MIN_SEGMENT_SIZE, |
1194 end = wx.Point(self.EndPoint[0].x + self.EndPoint[1][0] * MIN_SEGMENT_SIZE, |
1196 self.EndPoint[0].y + self.EndPoint[1][1] * MIN_SEGMENT_SIZE) |
1195 self.EndPoint[0].y + self.EndPoint[1][1] * MIN_SEGMENT_SIZE) |
1197 start = wxPoint(self.StartPoint[0].x + self.StartPoint[1][0] * MIN_SEGMENT_SIZE, |
1196 start = wx.Point(self.StartPoint[0].x + self.StartPoint[1][0] * MIN_SEGMENT_SIZE, |
1198 self.StartPoint[0].y + self.StartPoint[1][1] * MIN_SEGMENT_SIZE) |
1197 self.StartPoint[0].y + self.StartPoint[1][1] * MIN_SEGMENT_SIZE) |
1199 # Evaluate the point till it's the last |
1198 # Evaluate the point till it's the last |
1200 while i < len(self.Points) - 1: |
1199 while i < len(self.Points) - 1: |
1201 # The next point is the last |
1200 # The next point is the last |
1202 if i + 1 == len(self.Points) - 1: |
1201 if i + 1 == len(self.Points) - 1: |
1204 v_end = vector(self.Points[i], end) |
1203 v_end = vector(self.Points[i], end) |
1205 # The current point is the first |
1204 # The current point is the first |
1206 if i == 0: |
1205 if i == 0: |
1207 # If the end point is not in the start direction, a point is added |
1206 # If the end point is not in the start direction, a point is added |
1208 if v_end != self.Segments[0] or v_end == self.EndPoint[1]: |
1207 if v_end != self.Segments[0] or v_end == self.EndPoint[1]: |
1209 self.Points.insert(1, wxPoint(start.x, start.y)) |
1208 self.Points.insert(1, wx.Point(start.x, start.y)) |
1210 self.Segments.insert(1, DirectionChoice((self.Segments[0][1], |
1209 self.Segments.insert(1, DirectionChoice((self.Segments[0][1], |
1211 self.Segments[0][0]), v_end, self.EndPoint[1])) |
1210 self.Segments[0][0]), v_end, self.EndPoint[1])) |
1212 # The current point is the second |
1211 # The current point is the second |
1213 elif i == 1: |
1212 elif i == 1: |
1214 # The previous direction and the target direction are mainly opposed, a point is added |
1213 # The previous direction and the target direction are mainly opposed, a point is added |
1215 if product(v_end, self.Segments[0]) < 0: |
1214 if product(v_end, self.Segments[0]) < 0: |
1216 self.Points.insert(2, wxPoint(self.Points[1].x, self.Points[1].y)) |
1215 self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) |
1217 self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
1216 self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
1218 self.Segments[1][0]), v_end, self.EndPoint[1])) |
1217 self.Segments[1][0]), v_end, self.EndPoint[1])) |
1219 # The previous direction and the end direction are the same or they are |
1218 # The previous direction and the end direction are the same or they are |
1220 # perpendiculars and the end direction points towards current segment |
1219 # perpendiculars and the end direction points towards current segment |
1221 elif product(self.Segments[0], self.EndPoint[1]) >= 0 and product(self.Segments[1], self.EndPoint[1]) <= 0: |
1220 elif product(self.Segments[0], self.EndPoint[1]) >= 0 and product(self.Segments[1], self.EndPoint[1]) <= 0: |
1224 self.Points[1].x = end.x |
1223 self.Points[1].x = end.x |
1225 if self.Segments[0][1] != 0: |
1224 if self.Segments[0][1] != 0: |
1226 self.Points[1].y = end.y |
1225 self.Points[1].y = end.y |
1227 # If the previous direction and the end direction are the same, a point is added |
1226 # If the previous direction and the end direction are the same, a point is added |
1228 if product(self.Segments[0], self.EndPoint[1]) > 0: |
1227 if product(self.Segments[0], self.EndPoint[1]) > 0: |
1229 self.Points.insert(2, wxPoint(self.Points[1].x, self.Points[1].y)) |
1228 self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) |
1230 self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
1229 self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
1231 self.Segments[1][0]), v_end, self.EndPoint[1])) |
1230 self.Segments[1][0]), v_end, self.EndPoint[1])) |
1232 else: |
1231 else: |
1233 # Current point is positioned in the middle of start point |
1232 # Current point is positioned in the middle of start point |
1234 # and end point on the current direction and a point is added |
1233 # and end point on the current direction and a point is added |
1235 if self.Segments[0][0] != 0: |
1234 if self.Segments[0][0] != 0: |
1236 self.Points[1].x = (end.x + start.x) / 2 |
1235 self.Points[1].x = (end.x + start.x) / 2 |
1237 if self.Segments[0][1] != 0: |
1236 if self.Segments[0][1] != 0: |
1238 self.Points[1].y = (end.y + start.y) / 2 |
1237 self.Points[1].y = (end.y + start.y) / 2 |
1239 self.Points.insert(2, wxPoint(self.Points[1].x, self.Points[1].y)) |
1238 self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) |
1240 self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
1239 self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
1241 self.Segments[1][0]), v_end, self.EndPoint[1])) |
1240 self.Segments[1][0]), v_end, self.EndPoint[1])) |
1242 else: |
1241 else: |
1243 # The previous direction and the end direction are perpendiculars |
1242 # The previous direction and the end direction are perpendiculars |
1244 if product(self.Segments[i - 1], self.EndPoint[1]) == 0: |
1243 if product(self.Segments[i - 1], self.EndPoint[1]) == 0: |
1255 else: |
1254 else: |
1256 test = True |
1255 test = True |
1257 # If the current point is the third, test if the second |
1256 # If the current point is the third, test if the second |
1258 # point can be aligned with the end point |
1257 # point can be aligned with the end point |
1259 if i == 2: |
1258 if i == 2: |
1260 test_point = wxPoint(self.Points[1].x, self.Points[1].y) |
1259 test_point = wx.Point(self.Points[1].x, self.Points[1].y) |
1261 if self.Segments[1][0] != 0: |
1260 if self.Segments[1][0] != 0: |
1262 test_point.y = end.y |
1261 test_point.y = end.y |
1263 if self.Segments[1][1] != 0: |
1262 if self.Segments[1][1] != 0: |
1264 test_point.x = end.x |
1263 test_point.x = end.x |
1265 test = norm(vector(self.Points[0], test_point, False)) > MIN_SEGMENT_SIZE |
1264 vector_test = vector(self.Points[0], test_point, False) |
|
1265 test = norm(vector_test) > MIN_SEGMENT_SIZE and product(self.Segments[0], vector_test) > 0 |
1266 # The previous point can be aligned |
1266 # The previous point can be aligned |
1267 if test: |
1267 if test: |
1268 self.Points[i].x, self.Points[i].y = end.x, end.y |
1268 self.Points[i].x, self.Points[i].y = end.x, end.y |
1269 if self.Segments[i - 1][0] != 0: |
1269 if self.Segments[i - 1][0] != 0: |
1270 self.Points[i - 1].y = end.y |
1270 self.Points[i - 1].y = end.y |
1276 # and end point on the current direction and a point is added |
1276 # and end point on the current direction and a point is added |
1277 if self.Segments[1][0] != 0: |
1277 if self.Segments[1][0] != 0: |
1278 self.Points[2].x = (self.Points[1].x + end.x) / 2 |
1278 self.Points[2].x = (self.Points[1].x + end.x) / 2 |
1279 if self.Segments[1][1] != 0: |
1279 if self.Segments[1][1] != 0: |
1280 self.Points[2].y = (self.Points[1].y + end.y) / 2 |
1280 self.Points[2].y = (self.Points[1].y + end.y) / 2 |
1281 self.Points.insert(3, wxPoint(self.Points[2].x, self.Points[2].y)) |
1281 self.Points.insert(3, wx.Point(self.Points[2].x, self.Points[2].y)) |
1282 self.Segments.insert(3, DirectionChoice((self.Segments[2][1], |
1282 self.Segments.insert(3, DirectionChoice((self.Segments[2][1], |
1283 self.Segments[2][0]), v_end, self.EndPoint[1])) |
1283 self.Segments[2][0]), v_end, self.EndPoint[1])) |
1284 else: |
1284 else: |
1285 # Current point is aligned with end point |
1285 # Current point is aligned with end point |
1286 if self.Segments[i - 1][0] != 0: |
1286 if self.Segments[i - 1][0] != 0: |
1297 if self.Segments[i - 1][0] != 0: |
1297 if self.Segments[i - 1][0] != 0: |
1298 self.Points[i].x = (end.x + self.Points[i - 1].x) / 2 |
1298 self.Points[i].x = (end.x + self.Points[i - 1].x) / 2 |
1299 if self.Segments[i - 1][1] != 0: |
1299 if self.Segments[i - 1][1] != 0: |
1300 self.Points[i].y = (end.y + self.Points[i - 1].y) / 2 |
1300 self.Points[i].y = (end.y + self.Points[i - 1].y) / 2 |
1301 # A point is added |
1301 # A point is added |
1302 self.Points.insert(i + 1, wxPoint(self.Points[i].x, self.Points[i].y)) |
1302 self.Points.insert(i + 1, wx.Point(self.Points[i].x, self.Points[i].y)) |
1303 self.Segments.insert(i + 1, DirectionChoice((self.Segments[i][1], |
1303 self.Segments.insert(i + 1, DirectionChoice((self.Segments[i][1], |
1304 self.Segments[i][0]), v_end, self.EndPoint[1])) |
1304 self.Segments[i][0]), v_end, self.EndPoint[1])) |
1305 else: |
1305 else: |
1306 # Current point is the first, and second is not mainly in the first direction |
1306 # Current point is the first, and second is not mainly in the first direction |
1307 if i == 0 and product(vector(start, self.Points[1]), self.Segments[0]) < 0: |
1307 if i == 0 and product(vector(start, self.Points[1]), self.Segments[0]) < 0: |
1308 # If first and second directions aren't perpendiculars, a point is added |
1308 # If first and second directions aren't perpendiculars, a point is added |
1309 if product(self.Segments[0], self.Segments[1]) != 0: |
1309 if product(self.Segments[0], self.Segments[1]) != 0: |
1310 self.Points.insert(1, wxPoint(start.x, start.y)) |
1310 self.Points.insert(1, wx.Point(start.x, start.y)) |
1311 self.Segments.insert(1, DirectionChoice((self.Segments[0][1], |
1311 self.Segments.insert(1, DirectionChoice((self.Segments[0][1], |
1312 self.Segments[0][0]), vector(start, self.Points[1]), self.Segments[1])) |
1312 self.Segments[0][0]), vector(start, self.Points[1]), self.Segments[1])) |
1313 else: |
1313 else: |
1314 self.Points[1].x, self.Points[1].y = start.x, start.y |
1314 self.Points[1].x, self.Points[1].y = start.x, start.y |
1315 else: |
1315 else: |
1373 dir = (0, 0) |
1373 dir = (0, 0) |
1374 pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * (width - 1) / float(lastwidth - 1))), |
1374 pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * (width - 1) / float(lastwidth - 1))), |
1375 width - dir[0] * MIN_SEGMENT_SIZE - 1)) |
1375 width - dir[0] * MIN_SEGMENT_SIZE - 1)) |
1376 pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * (height - 1) / float(lastheight - 1))), |
1376 pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * (height - 1) / float(lastheight - 1))), |
1377 height - dir[1] * MIN_SEGMENT_SIZE - 1)) |
1377 height - dir[1] * MIN_SEGMENT_SIZE - 1)) |
1378 self.Points[i] = wxPoint(minx + x + pointx, miny + y + pointy) |
1378 self.Points[i] = wx.Point(minx + x + pointx, miny + y + pointy) |
1379 self.StartPoint[0] = self.Points[0] |
1379 self.StartPoint[0] = self.Points[0] |
1380 self.EndPoint[0] = self.Points[-1] |
1380 self.EndPoint[0] = self.Points[-1] |
1381 self.GeneratePoints(False) |
1381 self.GeneratePoints(False) |
1382 # Test if the wire position or size have changed |
1382 # Test if the wire position or size have changed |
1383 if x != 0 and minx == self.Pos.x: |
1383 if x != 0 and minx == self.Pos.x: |
1408 dir = (0, 0) |
1408 dir = (0, 0) |
1409 realpointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0])), |
1409 realpointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0])), |
1410 width - dir[0] * MIN_SEGMENT_SIZE - 1)) |
1410 width - dir[0] * MIN_SEGMENT_SIZE - 1)) |
1411 realpointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1])), |
1411 realpointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1])), |
1412 height - dir[1] * MIN_SEGMENT_SIZE - 1)) |
1412 height - dir[1] * MIN_SEGMENT_SIZE - 1)) |
1413 self.Points[i] = wxPoint(minx + x + realpointx, miny + y + realpointy) |
1413 self.Points[i] = wx.Point(minx + x + realpointx, miny + y + realpointy) |
1414 self.StartPoint[0] = self.Points[0] |
1414 self.StartPoint[0] = self.Points[0] |
1415 self.EndPoint[0] = self.Points[-1] |
1415 self.EndPoint[0] = self.Points[-1] |
1416 self.GeneratePoints(False) |
1416 self.GeneratePoints(False) |
1417 |
1417 |
1418 # Moves the wire start point and update the wire points |
1418 # Moves the wire start point and update the wire points |
1502 pointy = self.Points[segment].y |
1502 pointy = self.Points[segment].y |
1503 if dir[0] != 0: |
1503 if dir[0] != 0: |
1504 pointx = (self.Points[segment].x + self.Points[segment + 1].x) / 2 |
1504 pointx = (self.Points[segment].x + self.Points[segment + 1].x) / 2 |
1505 if dir[1] != 0: |
1505 if dir[1] != 0: |
1506 pointy = (self.Points[segment].y + self.Points[segment + 1].y) / 2 |
1506 pointy = (self.Points[segment].y + self.Points[segment + 1].y) / 2 |
1507 self.Points.insert(segment + 1, wxPoint(pointx, pointy)) |
1507 self.Points.insert(segment + 1, wx.Point(pointx, pointy)) |
1508 self.Segments.insert(segment + 1, (dir[1], dir[0])) |
1508 self.Segments.insert(segment + 1, (dir[1], dir[0])) |
1509 self.Points.insert(segment + 2, wxPoint(pointx, pointy)) |
1509 self.Points.insert(segment + 2, wx.Point(pointx, pointy)) |
1510 self.Segments.insert(segment + 2, dir) |
1510 self.Segments.insert(segment + 2, dir) |
1511 self.GeneratePoints() |
1511 self.GeneratePoints() |
1512 |
1512 |
1513 # Delete the handled segment by removing the two segment points |
1513 # Delete the handled segment by removing the two segment points |
1514 def DeleteSegment(self): |
1514 def DeleteSegment(self): |
1526 pos = GetScaledEventPosition(event, dc, scaling) |
1526 pos = GetScaledEventPosition(event, dc, scaling) |
1527 # Test if a point have been handled |
1527 # Test if a point have been handled |
1528 #result = self.TestPoint(pos) |
1528 #result = self.TestPoint(pos) |
1529 #if result != None: |
1529 #if result != None: |
1530 # self.Handle = (HANDLE_POINT, result) |
1530 # self.Handle = (HANDLE_POINT, result) |
1531 # self.Parent.SetCursor(wxStockCursor(wxCURSOR_HAND)) |
1531 # self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
1532 #else: |
1532 #else: |
1533 # Test if a segment have been handled |
1533 # Test if a segment have been handled |
1534 result = self.TestSegment(pos) |
1534 result = self.TestSegment(pos) |
1535 if result != None: |
1535 if result != None: |
1536 if result[1] in (NORTH, SOUTH): |
1536 if result[1] in (NORTH, SOUTH): |
1537 self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZEWE)) |
1537 self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_SIZEWE)) |
1538 elif result[1] in (EAST, WEST): |
1538 elif result[1] in (EAST, WEST): |
1539 self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZENS)) |
1539 self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
1540 self.Handle = (HANDLE_SEGMENT, result) |
1540 self.Handle = (HANDLE_SEGMENT, result) |
1541 # Execute the default method for a graphic element |
1541 # Execute the default method for a graphic element |
1542 else: |
1542 else: |
1543 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
1543 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
1544 self.oldPos = pos |
1544 self.oldPos = pos |
1558 |
1558 |
1559 # Method called when a LeftDClick event have been generated |
1559 # Method called when a LeftDClick event have been generated |
1560 def OnLeftDClick(self, event, dc, scaling): |
1560 def OnLeftDClick(self, event, dc, scaling): |
1561 self.ResetPoints() |
1561 self.ResetPoints() |
1562 self.GeneratePoints() |
1562 self.GeneratePoints() |
|
1563 self.RefreshModel() |
|
1564 self.Parent.RefreshBuffer() |
1563 |
1565 |
1564 # Method called when a Motion event have been generated |
1566 # Method called when a Motion event have been generated |
1565 def OnMotion(self, event, dc, scaling): |
1567 def OnMotion(self, event, dc, scaling): |
1566 pos = GetScaledEventPosition(event, dc, scaling) |
1568 pos = GetScaledEventPosition(event, dc, scaling) |
1567 if not event.Dragging(): |
1569 if not event.Dragging(): |
1568 # Test if a segment has been handled |
1570 # Test if a segment has been handled |
1569 result = self.TestSegment(pos) |
1571 result = self.TestSegment(pos) |
1570 if result: |
1572 if result: |
1571 if result[1] in (NORTH, SOUTH): |
1573 if result[1] in (NORTH, SOUTH): |
1572 wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZEWE)) |
1574 if self.CurrentCursor != 4: |
|
1575 self.CurrentCursor = 4 |
|
1576 wx.CallAfter(self.Parent.SetCursor, CURSORS[4]) |
1573 elif result[1] in (EAST, WEST): |
1577 elif result[1] in (EAST, WEST): |
1574 wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZENS)) |
1578 if self.CurrentCursor != 5: |
|
1579 self.CurrentCursor = 5 |
|
1580 wx.CallAfter(self.Parent.SetCursor, CURSORS[5]) |
1575 else: |
1581 else: |
1576 # Test if a point has been handled |
1582 # Test if a point has been handled |
1577 #result = self.TestPoint(pos) |
1583 #result = self.TestPoint(pos) |
1578 #if result != None: |
1584 #if result != None: |
1579 # if result == 0 and self.StartConnected: |
1585 # if result == 0 and self.StartConnected: |
1593 def ProcessDragging(self, movex, movey): |
1599 def ProcessDragging(self, movex, movey): |
1594 handle_type, handle = self.Handle |
1600 handle_type, handle = self.Handle |
1595 # A point has been handled |
1601 # A point has been handled |
1596 if handle_type == HANDLE_POINT: |
1602 if handle_type == HANDLE_POINT: |
1597 # Try to connect point to a connector |
1603 # Try to connect point to a connector |
1598 new_pos = wxPoint(self.Points[handle].x + movex, self.Points[handle].y + movey) |
1604 new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey) |
1599 connector = self.Parent.FindBlockConnector(new_pos) |
1605 connector = self.Parent.FindBlockConnector(new_pos) |
1600 if connector: |
1606 if connector: |
1601 if handle == 0 and self.EndConnected != connector: |
1607 if handle == 0 and self.EndConnected != connector: |
1602 connector.Connect((self, handle)) |
1608 connector.Connect((self, handle)) |
1603 self.SetStartPointDirection(connector.GetDirection()) |
1609 self.SetStartPointDirection(connector.GetDirection()) |
1637 if self.EndConnected and self.EndPoint[1] in [WEST, NORTH]: |
1643 if self.EndConnected and self.EndPoint[1] in [WEST, NORTH]: |
1638 self.EndConnected.RefreshParentBlock() |
1644 self.EndConnected.RefreshParentBlock() |
1639 |
1645 |
1640 # Draws the wire lines and points |
1646 # Draws the wire lines and points |
1641 def Draw(self, dc): |
1647 def Draw(self, dc): |
1642 dc.SetPen(wxBLACK_PEN) |
1648 dc.SetPen(wx.BLACK_PEN) |
1643 dc.SetBrush(wxBLACK_BRUSH) |
1649 dc.SetBrush(wx.BLACK_BRUSH) |
1644 # Draw the start and end points if they are not connected or the mouse is over them |
1650 # Draw the start and end points if they are not connected or the mouse is over them |
1645 if len(self.Points) > 0 and (not self.StartConnected or self.OverStart): |
1651 if len(self.Points) > 0 and (not self.StartConnected or self.OverStart): |
1646 dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS) |
1652 dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS) |
1647 if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd): |
1653 if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd): |
1648 dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS) |
1654 dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS) |
1649 # Draw the wire lines and the last point (it seems that DrawLines stop before the last point) |
1655 # Draw the wire lines and the last point (it seems that DrawLines stop before the last point) |
1650 dc.DrawLines(self.Points) |
1656 dc.DrawLines(self.Points) |
1651 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
1657 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
1652 # Draw the segment selected in red |
1658 # Draw the segment selected in red |
1653 if self.SelectedSegment != None: |
1659 if self.SelectedSegment != None: |
1654 dc.SetPen(wxRED_PEN) |
1660 dc.SetPen(wx.RED_PEN) |
1655 dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y, |
1661 dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y, |
1656 self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y) |
1662 self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y) |
1657 if self.SelectedSegment == len(self.Segments) - 1: |
1663 if self.SelectedSegment == len(self.Segments) - 1: |
1658 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
1664 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
1659 Graphic_Element.Draw(self, dc) |
1665 Graphic_Element.Draw(self, dc) |
1672 # Create a new comment |
1678 # Create a new comment |
1673 def __init__(self, parent, content, id = None): |
1679 def __init__(self, parent, content, id = None): |
1674 Graphic_Element.__init__(self, parent) |
1680 Graphic_Element.__init__(self, parent) |
1675 self.Id = id |
1681 self.Id = id |
1676 self.Content = content |
1682 self.Content = content |
1677 self.Pos = wxPoint(0, 0) |
1683 self.Pos = wx.Point(0, 0) |
1678 self.Size = wxSize(0, 0) |
1684 self.Size = wx.Size(0, 0) |
1679 |
1685 |
1680 # Method for keeping compatibility with others |
1686 # Method for keeping compatibility with others |
1681 def Clean(self): |
1687 def Clean(self): |
1682 pass |
1688 pass |
1683 |
1689 |
1685 def Delete(self): |
1691 def Delete(self): |
1686 self.Parent.DeleteComment(self) |
1692 self.Parent.DeleteComment(self) |
1687 |
1693 |
1688 # Refresh the comment bounding box |
1694 # Refresh the comment bounding box |
1689 def RefreshBoundingBox(self): |
1695 def RefreshBoundingBox(self): |
1690 self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1696 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1691 |
1697 |
1692 # Changes the comment size |
1698 # Changes the comment size |
1693 def SetSize(self, width, height): |
1699 def SetSize(self, width, height): |
1694 self.Size.SetWidth(width) |
1700 self.Size.SetWidth(width) |
1695 self.Size.SetHeight(height) |
1701 self.Size.SetHeight(height) |
1699 def GetSize(self): |
1705 def GetSize(self): |
1700 return self.Size.GetWidth(), self.Size.GetHeight() |
1706 return self.Size.GetWidth(), self.Size.GetHeight() |
1701 |
1707 |
1702 # Returns the comment minimum size |
1708 # Returns the comment minimum size |
1703 def GetMinSize(self): |
1709 def GetMinSize(self): |
1704 dc = wxClientDC(self.Parent) |
1710 dc = wx.ClientDC(self.Parent) |
1705 min_width = 0 |
1711 min_width = 0 |
1706 min_height = 0 |
1712 min_height = 0 |
1707 # The comment minimum size is the maximum size of words in the content |
1713 # The comment minimum size is the maximum size of words in the content |
1708 for line in self.Content.splitlines(): |
1714 for line in self.Content.splitlines(): |
1709 for word in line.split(" "): |
1715 for word in line.split(" "): |
1759 # Edit the comment content |
1765 # Edit the comment content |
1760 self.Parent.EditCommentContent(self) |
1766 self.Parent.EditCommentContent(self) |
1761 |
1767 |
1762 # Draws the comment and its content |
1768 # Draws the comment and its content |
1763 def Draw(self, dc): |
1769 def Draw(self, dc): |
1764 dc.SetPen(wxBLACK_PEN) |
1770 dc.SetPen(wx.BLACK_PEN) |
1765 dc.SetBrush(wxWHITE_BRUSH) |
1771 dc.SetBrush(wx.WHITE_BRUSH) |
1766 # Draws the comment shape |
1772 # Draws the comment shape |
1767 polygon = [wxPoint(self.Pos.x, self.Pos.y), |
1773 polygon = [wx.Point(self.Pos.x, self.Pos.y), |
1768 wxPoint(self.Pos.x + self.Size[0] - 10, self.Pos.y), |
1774 wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y), |
1769 wxPoint(self.Pos.x + self.Size[0], self.Pos.y + 10), |
1775 wx.Point(self.Pos.x + self.Size[0], self.Pos.y + 10), |
1770 wxPoint(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] + 1), |
1776 wx.Point(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] + 1), |
1771 wxPoint(self.Pos.x, self.Pos.y + self.Size[1] + 1)] |
1777 wx.Point(self.Pos.x, self.Pos.y + self.Size[1] + 1)] |
1772 dc.DrawPolygon(polygon) |
1778 dc.DrawPolygon(polygon) |
1773 lines = [wxPoint(self.Pos.x + self.Size[0] - 10, self.Pos.y), |
1779 lines = [wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y), |
1774 wxPoint(self.Pos.x + self.Size[0] - 10, self.Pos.y + 10), |
1780 wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y + 10), |
1775 wxPoint(self.Pos.x + self.Size[0], self.Pos.y + 10)] |
1781 wx.Point(self.Pos.x + self.Size[0], self.Pos.y + 10)] |
1776 dc.DrawLines(lines) |
1782 dc.DrawLines(lines) |
1777 # Draws the comment content |
1783 # Draws the comment content |
1778 y = self.Pos.y + 10 |
1784 y = self.Pos.y + 10 |
1779 for line in self.Content.splitlines(): |
1785 for line in self.Content.splitlines(): |
1780 first = True |
1786 first = True |