--- a/graphics/GraphicCommons.py Fri Jan 04 17:49:17 2008 +0100
+++ b/graphics/GraphicCommons.py Fri Jan 11 17:51:56 2008 +0100
@@ -379,7 +379,10 @@
return rect
def Refresh(self, rect = None):
- self.Parent.RefreshRect(self.Parent.GetScrolledRect(self.GetRedrawRect()))
+ if rect is not None:
+ self.Parent.RefreshRect(self.Parent.GetScrolledRect(rect))
+ else:
+ self.Parent.RefreshRect(self.Parent.GetScrolledRect(self.GetRedrawRect()))
# Change the variable that indicates if this element is selected
def SetSelected(self, selected):
@@ -445,11 +448,6 @@
def OnLeftUp(self, event, dc, scaling):
# If a dragging have been initiated
if self.Dragging and self.oldPos:
- # Calculate the movement of cursor and refreshes the element state
- pos = GetScaledEventPosition(event, dc, scaling)
- movex = pos.x - self.oldPos.x
- movey = pos.y - self.oldPos.y
- self.ProcessDragging(movex, movey)
self.RefreshModel()
self.Parent.RefreshBuffer()
if self.CurrentCursor != 0:
@@ -458,8 +456,18 @@
self.SetSelected(True)
self.oldPos = None
+ # Method called when a RightDown event have been generated
+ def OnRightDown(self, event, dc, scaling):
+ pass
+
# Method called when a RightUp event have been generated
def OnRightUp(self, event, dc, scaling):
+ if self.Dragging and self.oldPos:
+ self.RefreshModel()
+ self.Parent.RefreshBuffer()
+ if self.CurrentCursor != 0:
+ self.Parent.SetCursor(CURSORS[0])
+ self.CurrentCursor = 0
self.SetSelected(True)
self.oldPos = None
@@ -472,7 +480,7 @@
# If the cursor is dragging and the element have been clicked
if event.Dragging() and self.oldPos:
# Calculate the movement of cursor
- pos = GetScaledEventPosition(event, dc, scaling)
+ pos = event.GetLogicalPosition(dc)
movex = pos.x - self.oldPos.x
movey = pos.y - self.oldPos.y
# If movement is greater than MIN_MOVE then a dragging is initiated
@@ -480,7 +488,7 @@
self.Dragging = True
# If a dragging have been initiated, refreshes the element state
if self.Dragging:
- dragx, dragy = self.ProcessDragging(movex, movey)
+ dragx, dragy = self.ProcessDragging(movex, movey, scaling)
self.oldPos.x += dragx
self.oldPos.y += dragy
return dragx, dragy
@@ -510,21 +518,31 @@
self.SetSize(width, height)
# Refreshes the element state according to move defined and handle selected
- def ProcessDragging(self, movex, movey):
+ def ProcessDragging(self, movex, movey, scaling):
handle_type, handle = self.Handle
# If it is a resize handle, calculate the values from resizing
if handle_type == HANDLE_RESIZE:
x = y = start_x = start_y = 0
width, height = start_width, start_height = self.GetSize()
if handle[0] == 1:
- x = movex = max(-self.BoundingBox.x, movex)
+ movex = max(-self.BoundingBox.x, movex)
+ if scaling is not None:
+ movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
+ x = movex
width -= movex
elif handle[0] == 3:
+ if scaling is not None:
+ movex = round(float(self.Pos.x + width + movex) / float(scaling[0])) * scaling[0] - self.Pos.x - width
width += movex
if handle[1] == 1:
- y = movey = max(-self.BoundingBox.y, movey)
+ movey = max(-self.BoundingBox.y, movey)
+ if scaling is not None:
+ movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y
+ y = movey
height -= movey
elif handle[1] == 3:
+ if scaling is not None:
+ movey = round(float(self.Pos.y + height + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - height
height += movey
# Verify that new size is not lesser than minimum
min_width, min_height = self.GetMinSize()
@@ -545,6 +563,9 @@
elif handle_type == HANDLE_MOVE:
movex = max(-self.BoundingBox.x, movex)
movey = max(-self.BoundingBox.y, movey)
+ if scaling is not None:
+ movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
+ movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y
self.Move(movex, movey)
return movex, movey
return 0, 0
@@ -1189,6 +1210,12 @@
return self.EndConnected.GetType()
return None
+ def GetOtherConnected(self, connector):
+ if self.StartConnected == connector:
+ return self.EndConnected
+ else:
+ return self.StartConnected
+
def GetOtherConnectedType(self, handle):
if handle == 0:
return self.GetEndConnectedType()
@@ -1677,6 +1704,7 @@
if point:
self.MoveStartPoint(point)
self.StartConnected = connector
+ self.RefreshBoundingBox()
# Unconnects wire start point
def UnConnectStartPoint(self, delete = False):
@@ -1686,6 +1714,7 @@
elif self.StartConnected:
self.StartConnected.UnConnect(self, unconnect = False)
self.StartConnected = None
+ self.RefreshBoundingBox()
# Moves the wire end point and update the wire points
def MoveEndPoint(self, point):
@@ -1710,6 +1739,7 @@
if point:
self.MoveEndPoint(point)
self.EndConnected = connector
+ self.RefreshBoundingBox()
# Unconnects wire end point
def UnConnectEndPoint(self, delete = False):
@@ -1719,12 +1749,15 @@
elif self.EndConnected:
self.EndConnected.UnConnect(self, unconnect = False)
self.EndConnected = None
+ self.RefreshBoundingBox()
# Moves the wire segment given by its index
- def MoveSegment(self, idx, movex, movey):
+ def MoveSegment(self, idx, movex, movey, scaling):
if 0 < idx < len(self.Segments) - 1:
if self.Segments[idx] in (NORTH, SOUTH):
start_x = self.Points[idx].x
+ if scaling is not None:
+ movex = round(float(self.Points[idx].x + movex) / float(scaling[0])) * scaling[0] - self.Points[idx].x
self.Points[idx].x += movex
self.Points[idx + 1].x += movex
self.GeneratePoints()
@@ -1732,6 +1765,8 @@
return self.Points[idx].x - start_x, 0
elif self.Segments[idx] in (EAST, WEST):
start_y = self.Points[idx].y
+ if scaling is not None:
+ movey = round(float(self.Points[idx].y + movey) / float(scaling[1])) * scaling[1] - self.Points[idx].y
self.Points[idx].y += movey
self.Points[idx + 1].y += movey
self.GeneratePoints()
@@ -1836,10 +1871,12 @@
self.MoveEndPoint(wx.Point(avgx, self.EndPoint[0].y))
self.Parent.RefreshBuffer()
else:
+ rect = self.GetRedrawRect()
self.ResetPoints()
self.GeneratePoints()
self.RefreshModel()
self.Parent.RefreshBuffer()
+ self.Parent.RefreshRect(self.Parent.GetScrolledRect(rect))
# Method called when a Motion event has been generated
def OnMotion(self, event, dc, scaling):
@@ -1875,12 +1912,15 @@
return Graphic_Element.OnMotion(self, event, dc, scaling)
# Refreshes the wire state according to move defined and handle selected
- def ProcessDragging(self, movex, movey):
+ def ProcessDragging(self, movex, movey, scaling):
handle_type, handle = self.Handle
# A point has been handled
if handle_type == HANDLE_POINT:
movex = max(-self.Points[handle].x + POINT_RADIUS, movex)
movey = max(-self.Points[handle].y + POINT_RADIUS, movey)
+ if scaling is not None:
+ movex = round(float(self.Points[handle].x + movex) / float(scaling[0])) * scaling[0] - self.Points[handle].x
+ movey = round(float(self.Points[handle].y + movey) / float(scaling[1])) * scaling[1] - self.Points[handle].y
# Try to connect point to a connector
new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey)
connector = self.Parent.FindBlockConnector(new_pos)
@@ -1921,10 +1961,10 @@
return movex, movey
# A segment has been handled, move a segment
elif handle_type == HANDLE_SEGMENT:
- return self.MoveSegment(handle[0], movex, movey)
+ return self.MoveSegment(handle[0], movex, movey, scaling)
# Execute the default method for a graphic element
else:
- return Graphic_Element.ProcessDragging(self, movex, movey)
+ return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
# Refreshes the wire model
def RefreshModel(self, move=True):
@@ -1949,11 +1989,13 @@
width = abs(self.Points[i + 1].x - self.Points[i].x) + 5
height = abs(self.Points[i + 1].y - self.Points[i].y) + 5
dc.DrawRectangle(posx, posy, width, height)
+ dc.SetLogicalFunction(wx.COPY)
if self.StartConnected is not None:
self.StartConnected.DrawHighlightment(dc)
+ self.StartConnected.Draw(dc)
if self.EndConnected is not None:
self.EndConnected.DrawHighlightment(dc)
- dc.SetLogicalFunction(wx.COPY)
+ self.EndConnected.Draw(dc)
# Draws the wire lines and points
def Draw(self, dc):
@@ -1996,8 +2038,10 @@
self.Size = wx.Size(0, 0)
# Make a clone of this comment
- def Clone(self, id = None):
+ def Clone(self, id = None, pos = None):
comment = Comment(self.Parent, self.Content, id)
+ if pos is not None:
+ comment.SetPosition(pos.x, pos.y)
comment.SetSize(self.Size[0], self.Size[1])
return comment