Patch from Pierre Hjälm.
""" It removes "from __future__ import division", fixes a couple of bugs and adds a lot of whitespace. Since I also removed an instance of [::-1] for list reversing, I think this ought to work on older pythons (I have not tested though). """ git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27884 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -14,7 +14,7 @@ from _composit import *
|
|||||||
|
|
||||||
|
|
||||||
# Set things up for documenting with epydoc. The __docfilter__ will
|
# Set things up for documenting with epydoc. The __docfilter__ will
|
||||||
# prevent some things from beign documented, and anything in __all__
|
# prevent some things from being documented, and anything in __all__
|
||||||
# will appear to actually exist in this module.
|
# will appear to actually exist in this module.
|
||||||
import wx._core as _wx
|
import wx._core as _wx
|
||||||
__docfilter__ = _wx.__DocFilter(globals())
|
__docfilter__ = _wx.__DocFilter(globals())
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import math
|
import math
|
||||||
|
|
||||||
@@ -254,7 +252,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
self._shadowBrush = wx.BLACK_BRUSH
|
self._shadowBrush = wx.BLACK_BRUSH
|
||||||
self._textMarginX = 5
|
self._textMarginX = 5
|
||||||
self._textMarginY = 5
|
self._textMarginY = 5
|
||||||
self._regionName="0"
|
self._regionName = "0"
|
||||||
self._centreResize = True
|
self._centreResize = True
|
||||||
self._maintainAspectRatio = False
|
self._maintainAspectRatio = False
|
||||||
self._highlighted = False
|
self._highlighted = False
|
||||||
@@ -431,8 +429,8 @@ class Shape(ShapeEvtHandler):
|
|||||||
def ClearText(self, regionId = 0):
|
def ClearText(self, regionId = 0):
|
||||||
"""Clear the text from the specified text region."""
|
"""Clear the text from the specified text region."""
|
||||||
if regionId == 0:
|
if regionId == 0:
|
||||||
self._text=""
|
self._text = ""
|
||||||
if regionId<len(self._regions):
|
if regionId < len(self._regions):
|
||||||
self._regions[regionId].ClearText()
|
self._regions[regionId].ClearText()
|
||||||
|
|
||||||
def ClearRegions(self):
|
def ClearRegions(self):
|
||||||
@@ -456,18 +454,18 @@ class Shape(ShapeEvtHandler):
|
|||||||
the given point and target.
|
the given point and target.
|
||||||
"""
|
"""
|
||||||
width, height = self.GetBoundingBoxMax()
|
width, height = self.GetBoundingBoxMax()
|
||||||
if abs(width)<4:
|
if abs(width) < 4:
|
||||||
width = 4.0
|
width = 4.0
|
||||||
if abs(height)<4:
|
if abs(height) < 4:
|
||||||
height = 4.0
|
height = 4.0
|
||||||
|
|
||||||
width += 4 # Allowance for inaccurate mousing
|
width += 4 # Allowance for inaccurate mousing
|
||||||
height += 4
|
height += 4
|
||||||
|
|
||||||
left = self._xpos - (width / 2)
|
left = self._xpos - width / 2.0
|
||||||
top = self._ypos - (height / 2)
|
top = self._ypos - height / 2.0
|
||||||
right = self._xpos + (width / 2)
|
right = self._xpos + width / 2.0
|
||||||
bottom = self._ypos + (height / 2)
|
bottom = self._ypos + height / 2.0
|
||||||
|
|
||||||
nearest_attachment = 0
|
nearest_attachment = 0
|
||||||
|
|
||||||
@@ -485,7 +483,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
if e:
|
if e:
|
||||||
xp, yp = e
|
xp, yp = e
|
||||||
l = math.sqrt(((xp - x) * (xp - x)) + (yp - y) * (yp - y))
|
l = math.sqrt(((xp - x) * (xp - x)) + (yp - y) * (yp - y))
|
||||||
if l<nearest:
|
if l < nearest:
|
||||||
nearest = l
|
nearest = l
|
||||||
nearest_attachment = i
|
nearest_attachment = i
|
||||||
|
|
||||||
@@ -504,7 +502,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
if not self._regions:
|
if not self._regions:
|
||||||
return
|
return
|
||||||
|
|
||||||
if i>len(self._regions):
|
if i > len(self._regions):
|
||||||
return
|
return
|
||||||
|
|
||||||
region = self._regions[i]
|
region = self._regions[i]
|
||||||
@@ -595,7 +593,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
def SetFont(self, the_font, regionId = 0):
|
def SetFont(self, the_font, regionId = 0):
|
||||||
"""Set the font for the specified text region."""
|
"""Set the font for the specified text region."""
|
||||||
self._font = the_font
|
self._font = the_font
|
||||||
if regionId<len(self._regions):
|
if regionId < len(self._regions):
|
||||||
self._regions[regionId].SetFont(the_font)
|
self._regions[regionId].SetFont(the_font)
|
||||||
|
|
||||||
def GetFont(self, regionId = 0):
|
def GetFont(self, regionId = 0):
|
||||||
@@ -615,7 +613,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
FORMAT_CENTRE_VERT
|
FORMAT_CENTRE_VERT
|
||||||
Vertical centring.
|
Vertical centring.
|
||||||
"""
|
"""
|
||||||
if regionId<len(self._regions):
|
if regionId < len(self._regions):
|
||||||
self._regions[regionId].SetFormatMode(mode)
|
self._regions[regionId].SetFormatMode(mode)
|
||||||
|
|
||||||
def GetFormatMode(self, regionId = 0):
|
def GetFormatMode(self, regionId = 0):
|
||||||
@@ -628,7 +626,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
self._textColour = wx.TheColourDatabase.Find(the_colour)
|
self._textColour = wx.TheColourDatabase.Find(the_colour)
|
||||||
self._textColourName = the_colour
|
self._textColourName = the_colour
|
||||||
|
|
||||||
if regionId<len(self._regions):
|
if regionId < len(self._regions):
|
||||||
self._regions[regionId].SetColour(the_colour)
|
self._regions[regionId].SetColour(the_colour)
|
||||||
|
|
||||||
def GetTextColour(self, regionId = 0):
|
def GetTextColour(self, regionId = 0):
|
||||||
@@ -642,7 +640,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
The name for a region is unique within the scope of the whole
|
The name for a region is unique within the scope of the whole
|
||||||
composite, whereas a region id is unique only for a single image.
|
composite, whereas a region id is unique only for a single image.
|
||||||
"""
|
"""
|
||||||
if regionId<len(self._regions):
|
if regionId < len(self._regions):
|
||||||
self._regions[regionId].SetName(name)
|
self._regions[regionId].SetName(name)
|
||||||
|
|
||||||
def GetRegionName(self, regionId = 0):
|
def GetRegionName(self, regionId = 0):
|
||||||
@@ -688,7 +686,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
for the given region name.
|
for the given region name.
|
||||||
"""
|
"""
|
||||||
id = self.GetRegionId(name)
|
id = self.GetRegionId(name)
|
||||||
if id>-1:
|
if id > -1:
|
||||||
return self, id
|
return self, id
|
||||||
|
|
||||||
for child in self._children:
|
for child in self._children:
|
||||||
@@ -696,7 +694,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
if actualImage:
|
if actualImage:
|
||||||
return actualImage, regionId
|
return actualImage, regionId
|
||||||
|
|
||||||
return None,-1
|
return None, -1
|
||||||
|
|
||||||
# Finds all region names for this image (composite or simple).
|
# Finds all region names for this image (composite or simple).
|
||||||
def FindRegionNames(self):
|
def FindRegionNames(self):
|
||||||
@@ -782,8 +780,8 @@ class Shape(ShapeEvtHandler):
|
|||||||
minX, minY = self.GetBoundingBoxMin()
|
minX, minY = self.GetBoundingBoxMin()
|
||||||
maxX, maxY = self.GetBoundingBoxMax()
|
maxX, maxY = self.GetBoundingBoxMax()
|
||||||
|
|
||||||
topLeftX = xp - maxX / 2 - 2
|
topLeftX = xp - maxX / 2.0 - 2
|
||||||
topLeftY = yp - maxY / 2 - 2
|
topLeftY = yp - maxY / 2.0 - 2
|
||||||
|
|
||||||
penWidth = 0
|
penWidth = 0
|
||||||
if self._pen:
|
if self._pen:
|
||||||
@@ -794,7 +792,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
|
|
||||||
dc.DrawRectangle(topLeftX - penWidth, topLeftY - penWidth, maxX + penWidth * 2 + 4, maxY + penWidth * 2 + 4)
|
dc.DrawRectangle(topLeftX - penWidth, topLeftY - penWidth, maxX + penWidth * 2 + 4, maxY + penWidth * 2 + 4)
|
||||||
|
|
||||||
def EraseLinks(self, dc, attachment=-1, recurse = False):
|
def EraseLinks(self, dc, attachment = -1, recurse = False):
|
||||||
"""Erase links attached to this shape, but do not repair damage
|
"""Erase links attached to this shape, but do not repair damage
|
||||||
caused to other shapes.
|
caused to other shapes.
|
||||||
"""
|
"""
|
||||||
@@ -802,20 +800,20 @@ class Shape(ShapeEvtHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for line in self._lines:
|
for line in self._lines:
|
||||||
if attachment==-1 or (line.GetTo() == self and line.GetAttachmentTo() == attachment or line.GetFrom() == self and line.GetAttachmentFrom() == attachment):
|
if attachment == -1 or (line.GetTo() == self and line.GetAttachmentTo() == attachment or line.GetFrom() == self and line.GetAttachmentFrom() == attachment):
|
||||||
line.GetEventHandler().OnErase(dc)
|
line.GetEventHandler().OnErase(dc)
|
||||||
|
|
||||||
if recurse:
|
if recurse:
|
||||||
for child in self._children:
|
for child in self._children:
|
||||||
child.EraseLinks(dc, attachment, recurse)
|
child.EraseLinks(dc, attachment, recurse)
|
||||||
|
|
||||||
def DrawLinks(self, dc, attachment=-1, recurse = False):
|
def DrawLinks(self, dc, attachment = -1, recurse = False):
|
||||||
"""Draws any lines linked to this shape."""
|
"""Draws any lines linked to this shape."""
|
||||||
if not self._visible:
|
if not self._visible:
|
||||||
return
|
return
|
||||||
|
|
||||||
for line in self._lines:
|
for line in self._lines:
|
||||||
if attachment==-1 or (line.GetTo() == self and line.GetAttachmentTo() == attachment or line.GetFrom() == self and line.GetAttachmentFrom() == attachment):
|
if attachment == -1 or (line.GetTo() == self and line.GetAttachmentTo() == attachment or line.GetFrom() == self and line.GetAttachmentFrom() == attachment):
|
||||||
line.GetEventHandler().Draw(dc)
|
line.GetEventHandler().Draw(dc)
|
||||||
|
|
||||||
if recurse:
|
if recurse:
|
||||||
@@ -878,8 +876,8 @@ class Shape(ShapeEvtHandler):
|
|||||||
# it to another position in the list
|
# it to another position in the list
|
||||||
del newOrdering[newOrdering.index(to_move)]
|
del newOrdering[newOrdering.index(to_move)]
|
||||||
|
|
||||||
old_x=-99999.9
|
old_x = -99999.9
|
||||||
old_y=-99999.9
|
old_y = -99999.9
|
||||||
|
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
@@ -1048,7 +1046,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
hit = self._parent.HitTest(x, y)
|
hit = self._parent.HitTest(x, y)
|
||||||
if hit:
|
if hit:
|
||||||
attachment, dist = hit
|
attachment, dist = hit
|
||||||
self._parent.GetEventHandler().OnEndDragLeft(x, y, keys, attachment)
|
self._parent.GetEventHandler().OnEndDragLeft(x, y, keys, attachment)
|
||||||
return
|
return
|
||||||
|
|
||||||
dc = wx.ClientDC(self.GetCanvas())
|
dc = wx.ClientDC(self.GetCanvas())
|
||||||
@@ -1088,14 +1086,13 @@ class Shape(ShapeEvtHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def OnDrawOutline(self, dc, x, y, w, h):
|
def OnDrawOutline(self, dc, x, y, w, h):
|
||||||
points = [[x - w / 2, y - h / 2],
|
points = [[x - w / 2.0, y - h / 2.0],
|
||||||
[x + w / 2, y - h / 2],
|
[x + w / 2.0, y - h / 2.0],
|
||||||
[x + w / 2, y + h / 2],
|
[x + w / 2.0, y + h / 2.0],
|
||||||
[x - w / 2, y + h / 2],
|
[x - w / 2.0, y + h / 2.0],
|
||||||
[x - w / 2, y - h / 2],
|
[x - w / 2.0, y - h / 2.0],
|
||||||
]
|
]
|
||||||
|
|
||||||
#dc.DrawLines([[round(x), round(y)] for x, y in points])
|
|
||||||
dc.DrawLines(points)
|
dc.DrawLines(points)
|
||||||
|
|
||||||
def Attach(self, can):
|
def Attach(self, can):
|
||||||
@@ -1197,18 +1194,18 @@ class Shape(ShapeEvtHandler):
|
|||||||
if width == 0:
|
if width == 0:
|
||||||
scaleX = 1.0
|
scaleX = 1.0
|
||||||
else:
|
else:
|
||||||
scaleX = long(w) / width
|
scaleX = float(w) / width
|
||||||
if height == 0:
|
if height == 0:
|
||||||
scaleY = 1.0
|
scaleY = 1.0
|
||||||
else:
|
else:
|
||||||
scaleY = long(h) / height
|
scaleY = float(h) / height
|
||||||
|
|
||||||
for point in self._attachmentPoints:
|
for point in self._attachmentPoints:
|
||||||
point._x = point._x * scaleX
|
point._x = point._x * scaleX
|
||||||
point._y = point._y * scaleY
|
point._y = point._y * scaleY
|
||||||
|
|
||||||
# Add line FROM this object
|
# Add line FROM this object
|
||||||
def AddLine(self, line, other, attachFrom = 0, attachTo = 0, positionFrom=-1, positionTo=-1):
|
def AddLine(self, line, other, attachFrom = 0, attachTo = 0, positionFrom = -1, positionTo = -1):
|
||||||
"""Add a line between this shape and the given other shape, at the
|
"""Add a line between this shape and the given other shape, at the
|
||||||
specified attachment points.
|
specified attachment points.
|
||||||
|
|
||||||
@@ -1216,7 +1213,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
so that the line will be drawn at a particular point on its attachment
|
so that the line will be drawn at a particular point on its attachment
|
||||||
point.
|
point.
|
||||||
"""
|
"""
|
||||||
if positionFrom==-1:
|
if positionFrom == -1:
|
||||||
if not line in self._lines:
|
if not line in self._lines:
|
||||||
self._lines.append(line)
|
self._lines.append(line)
|
||||||
else:
|
else:
|
||||||
@@ -1225,12 +1222,12 @@ class Shape(ShapeEvtHandler):
|
|||||||
self._lines.remove(line)
|
self._lines.remove(line)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if positionFrom<len(self._lines):
|
if positionFrom < len(self._lines):
|
||||||
self._lines.insert(positionFrom, line)
|
self._lines.insert(positionFrom, line)
|
||||||
else:
|
else:
|
||||||
self._lines.append(line)
|
self._lines.append(line)
|
||||||
|
|
||||||
if positionTo==-1:
|
if positionTo == -1:
|
||||||
if not other in other._lines:
|
if not other in other._lines:
|
||||||
other._lines.append(line)
|
other._lines.append(line)
|
||||||
else:
|
else:
|
||||||
@@ -1239,7 +1236,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
other._lines.remove(line)
|
other._lines.remove(line)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if positionTo<len(other._lines):
|
if positionTo < len(other._lines):
|
||||||
other._lines.insert(positionTo, line)
|
other._lines.insert(positionTo, line)
|
||||||
else:
|
else:
|
||||||
other._lines.append(line)
|
other._lines.append(line)
|
||||||
@@ -1273,10 +1270,10 @@ class Shape(ShapeEvtHandler):
|
|||||||
heightMin = minY + CONTROL_POINT_SIZE + 2
|
heightMin = minY + CONTROL_POINT_SIZE + 2
|
||||||
|
|
||||||
# Offsets from main object
|
# Offsets from main object
|
||||||
top=-heightMin / 2
|
top = -heightMin / 2.0
|
||||||
bottom = heightMin / 2 + (maxY - minY)
|
bottom = heightMin / 2.0 + (maxY - minY)
|
||||||
left=-widthMin / 2
|
left = -widthMin / 2.0
|
||||||
right = widthMin / 2 + (maxX - minX)
|
right = widthMin / 2.0 + (maxX - minX)
|
||||||
|
|
||||||
control = ControlPoint(self._canvas, self, CONTROL_POINT_SIZE, left, top, CONTROL_POINT_DIAGONAL)
|
control = ControlPoint(self._canvas, self, CONTROL_POINT_SIZE, left, top, CONTROL_POINT_DIAGONAL)
|
||||||
self._canvas.AddShape(control)
|
self._canvas.AddShape(control)
|
||||||
@@ -1341,10 +1338,10 @@ class Shape(ShapeEvtHandler):
|
|||||||
heightMin = minY + CONTROL_POINT_SIZE + 2
|
heightMin = minY + CONTROL_POINT_SIZE + 2
|
||||||
|
|
||||||
# Offsets from main object
|
# Offsets from main object
|
||||||
top=-heightMin / 2
|
top = -heightMin / 2.0
|
||||||
bottom = heightMin / 2 + (maxY - minY)
|
bottom = heightMin / 2.0 + (maxY - minY)
|
||||||
left=-widthMin / 2
|
left = -widthMin / 2.0
|
||||||
right = widthMin / 2 + (maxX - minX)
|
right = widthMin / 2.0 + (maxX - minX)
|
||||||
|
|
||||||
self._controlPoints[0]._xoffset = left
|
self._controlPoints[0]._xoffset = left
|
||||||
self._controlPoints[0]._yoffset = top
|
self._controlPoints[0]._yoffset = top
|
||||||
@@ -1458,7 +1455,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
else:
|
else:
|
||||||
maxN = 3
|
maxN = 3
|
||||||
for point in self._attachmentPoints:
|
for point in self._attachmentPoints:
|
||||||
if point._id>maxN:
|
if point._id > maxN:
|
||||||
maxN = point._id
|
maxN = point._id
|
||||||
return maxN + 1
|
return maxN + 1
|
||||||
|
|
||||||
@@ -1492,10 +1489,10 @@ class Shape(ShapeEvtHandler):
|
|||||||
else:
|
else:
|
||||||
# Assume is rectangular
|
# Assume is rectangular
|
||||||
w, h = self.GetBoundingBoxMax()
|
w, h = self.GetBoundingBoxMax()
|
||||||
top = self._ypos + h / 2
|
top = self._ypos + h / 2.0
|
||||||
bottom = self._ypos - h / 2
|
bottom = self._ypos - h / 2.0
|
||||||
left = self._xpos - w / 2
|
left = self._xpos - w / 2.0
|
||||||
right = self._xpos + w / 2
|
right = self._xpos + w / 2.0
|
||||||
|
|
||||||
# wtf?
|
# wtf?
|
||||||
line and line.IsEnd(self)
|
line and line.IsEnd(self)
|
||||||
@@ -1583,7 +1580,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
isHorizontal = RoughlyEqual(pt1[1], pt2[1])
|
isHorizontal = RoughlyEqual(pt1[1], pt2[1])
|
||||||
|
|
||||||
if isHorizontal:
|
if isHorizontal:
|
||||||
if pt1[0]>pt2[0]:
|
if pt1[0] > pt2[0]:
|
||||||
firstPoint = pt2
|
firstPoint = pt2
|
||||||
secondPoint = pt1
|
secondPoint = pt1
|
||||||
else:
|
else:
|
||||||
@@ -1594,21 +1591,21 @@ class Shape(ShapeEvtHandler):
|
|||||||
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
||||||
# Align line according to the next handle along
|
# Align line according to the next handle along
|
||||||
point = line.GetNextControlPoint(self)
|
point = line.GetNextControlPoint(self)
|
||||||
if point[0]<firstPoint[0]:
|
if point[0] < firstPoint[0]:
|
||||||
x = firstPoint[0]
|
x = firstPoint[0]
|
||||||
elif point[0]>secondPoint[0]:
|
elif point[0] > secondPoint[0]:
|
||||||
x = secondPoint[0]
|
x = secondPoint[0]
|
||||||
else:
|
else:
|
||||||
x = point[0]
|
x = point[0]
|
||||||
else:
|
else:
|
||||||
x = firstPoint[0] + (nth + 1) * (secondPoint[0] - firstPoint[0]) / (noArcs + 1)
|
x = firstPoint[0] + (nth + 1) * (secondPoint[0] - firstPoint[0]) / (noArcs + 1.0)
|
||||||
else:
|
else:
|
||||||
x = (secondPoint[0] - firstPoint[0]) / 2 # Midpoint
|
x = (secondPoint[0] - firstPoint[0]) / 2.0 # Midpoint
|
||||||
y = pt1[1]
|
y = pt1[1]
|
||||||
else:
|
else:
|
||||||
assert RoughlyEqual(pt1[0], pt2[0])
|
assert RoughlyEqual(pt1[0], pt2[0])
|
||||||
|
|
||||||
if pt1[1]>pt2[1]:
|
if pt1[1] > pt2[1]:
|
||||||
firstPoint = pt2
|
firstPoint = pt2
|
||||||
secondPoint = pt1
|
secondPoint = pt1
|
||||||
else:
|
else:
|
||||||
@@ -1619,16 +1616,16 @@ class Shape(ShapeEvtHandler):
|
|||||||
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
||||||
# Align line according to the next handle along
|
# Align line according to the next handle along
|
||||||
point = line.GetNextControlPoint(self)
|
point = line.GetNextControlPoint(self)
|
||||||
if point[1]<firstPoint[1]:
|
if point[1] < firstPoint[1]:
|
||||||
y = firstPoint[1]
|
y = firstPoint[1]
|
||||||
elif point[1]>secondPoint[1]:
|
elif point[1] > secondPoint[1]:
|
||||||
y = secondPoint[1]
|
y = secondPoint[1]
|
||||||
else:
|
else:
|
||||||
y = point[1]
|
y = point[1]
|
||||||
else:
|
else:
|
||||||
y = firstPoint[1] + (nth + 1) * (secondPoint[1] - firstPoint[1]) / (noArcs + 1)
|
y = firstPoint[1] + (nth + 1) * (secondPoint[1] - firstPoint[1]) / (noArcs + 1.0)
|
||||||
else:
|
else:
|
||||||
y = (secondPoint[1] - firstPoint[1]) / 2 # Midpoint
|
y = (secondPoint[1] - firstPoint[1]) / 2.0 # Midpoint
|
||||||
x = pt1[0]
|
x = pt1[0]
|
||||||
|
|
||||||
return x, y
|
return x, y
|
||||||
@@ -1676,8 +1673,8 @@ class Shape(ShapeEvtHandler):
|
|||||||
neck.x = self.GetX()
|
neck.x = self.GetX()
|
||||||
neck.y = root.y - self._branchNeckLength
|
neck.y = root.y - self._branchNeckLength
|
||||||
|
|
||||||
shoulder1.x = root.x - totalBranchLength / 2
|
shoulder1.x = root.x - totalBranchLength / 2.0
|
||||||
shoulder2.x = root.x + totalBranchLength / 2
|
shoulder2.x = root.x + totalBranchLength / 2.0
|
||||||
|
|
||||||
shoulder1.y = neck.y
|
shoulder1.y = neck.y
|
||||||
shoulder2.y = neck.y
|
shoulder2.y = neck.y
|
||||||
@@ -1688,14 +1685,14 @@ class Shape(ShapeEvtHandler):
|
|||||||
shoulder1.x = neck.x
|
shoulder1.x = neck.x
|
||||||
shoulder2.x = neck.x
|
shoulder2.x = neck.x
|
||||||
|
|
||||||
shoulder1.y = neck.y - totalBranchLength / 2
|
shoulder1.y = neck.y - totalBranchLength / 2.0
|
||||||
shoulder1.y = neck.y + totalBranchLength / 2
|
shoulder1.y = neck.y + totalBranchLength / 2.0
|
||||||
elif physicalAttachment == 2:
|
elif physicalAttachment == 2:
|
||||||
neck.x = self.GetX()
|
neck.x = self.GetX()
|
||||||
neck.y = root.y + self._branchNeckLength
|
neck.y = root.y + self._branchNeckLength
|
||||||
|
|
||||||
shoulder1.x = root.x - totalBranchLength / 2
|
shoulder1.x = root.x - totalBranchLength / 2.0
|
||||||
shoulder2.x = root.x + totalBranchLength / 2
|
shoulder2.x = root.x + totalBranchLength / 2.0
|
||||||
|
|
||||||
shoulder1.y = neck.y
|
shoulder1.y = neck.y
|
||||||
shoulder2.y = neck.y
|
shoulder2.y = neck.y
|
||||||
@@ -1706,8 +1703,8 @@ class Shape(ShapeEvtHandler):
|
|||||||
shoulder1.x = neck.x
|
shoulder1.x = neck.x
|
||||||
shoulder2.x = neck.x
|
shoulder2.x = neck.x
|
||||||
|
|
||||||
shoulder1.y = neck.y - totalBranchLength / 2
|
shoulder1.y = neck.y - totalBranchLength / 2.0
|
||||||
shoulder2.y = neck.y + totalBranchLength / 2
|
shoulder2.y = neck.y + totalBranchLength / 2.0
|
||||||
else:
|
else:
|
||||||
raise "Unrecognised attachment point in GetBranchingAttachmentInfo"
|
raise "Unrecognised attachment point in GetBranchingAttachmentInfo"
|
||||||
return root, neck, shoulder1, shoulder2
|
return root, neck, shoulder1, shoulder2
|
||||||
@@ -1769,15 +1766,15 @@ class Shape(ShapeEvtHandler):
|
|||||||
# Assume that we have attachment points 0 to 3: top, right, bottom, left
|
# Assume that we have attachment points 0 to 3: top, right, bottom, left
|
||||||
if physicalAttachment == 0:
|
if physicalAttachment == 0:
|
||||||
root.x = self.GetX()
|
root.x = self.GetX()
|
||||||
root.y = self.GetY() - height / 2
|
root.y = self.GetY() - height / 2.0
|
||||||
elif physicalAttachment == 1:
|
elif physicalAttachment == 1:
|
||||||
root.x = self.GetX() + width / 2
|
root.x = self.GetX() + width / 2.0
|
||||||
root.y = self.GetY()
|
root.y = self.GetY()
|
||||||
elif physicalAttachment == 2:
|
elif physicalAttachment == 2:
|
||||||
root.x = self.GetX()
|
root.x = self.GetX()
|
||||||
root.y = self.GetY() + height / 2
|
root.y = self.GetY() + height / 2.0
|
||||||
elif physicalAttachment == 3:
|
elif physicalAttachment == 3:
|
||||||
root.x = self.GetX() - width / 2
|
root.x = self.GetX() - width / 2.0
|
||||||
root.y = self.GetY()
|
root.y = self.GetY()
|
||||||
else:
|
else:
|
||||||
raise "Unrecognised attachment point in GetBranchingAttachmentRoot"
|
raise "Unrecognised attachment point in GetBranchingAttachmentRoot"
|
||||||
@@ -1802,7 +1799,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
# Draw neck
|
# Draw neck
|
||||||
dc.DrawLine(root, neck)
|
dc.DrawLine(root, neck)
|
||||||
|
|
||||||
if count>1:
|
if count > 1:
|
||||||
# Draw shoulder-to-shoulder line
|
# Draw shoulder-to-shoulder line
|
||||||
dc.DrawLine(shoulder1, shoulder2)
|
dc.DrawLine(shoulder1, shoulder2)
|
||||||
# Draw all the little branches
|
# Draw all the little branches
|
||||||
@@ -1810,9 +1807,9 @@ class Shape(ShapeEvtHandler):
|
|||||||
pt, stemPt = self.GetBranchingAttachmentPoint(attachment, i)
|
pt, stemPt = self.GetBranchingAttachmentPoint(attachment, i)
|
||||||
dc.DrawLine(stemPt, pt)
|
dc.DrawLine(stemPt, pt)
|
||||||
|
|
||||||
if self.GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB and count>1:
|
if self.GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB and count > 1:
|
||||||
blobSize = 6
|
blobSize = 6.0
|
||||||
dc.DrawEllipse(stemPt.x - blobSize / 2, stemPt.y - blobSize / 2, blobSize, blobSize)
|
dc.DrawEllipse(stemPt.x - blobSize / 2.0, stemPt.y - blobSize / 2.0, blobSize, blobSize)
|
||||||
|
|
||||||
def OnDrawBranches(self, dc, erase = False):
|
def OnDrawBranches(self, dc, erase = False):
|
||||||
if self._attachmentMode != ATTACHMENT_MODE_BRANCHING:
|
if self._attachmentMode != ATTACHMENT_MODE_BRANCHING:
|
||||||
@@ -1841,17 +1838,17 @@ class Shape(ShapeEvtHandler):
|
|||||||
"""
|
"""
|
||||||
if RoughlyEqual(self.GetRotation(), 0):
|
if RoughlyEqual(self.GetRotation(), 0):
|
||||||
i = physicalAttachment
|
i = physicalAttachment
|
||||||
elif RoughlyEqual(self.GetRotation(), math.pi / 2):
|
elif RoughlyEqual(self.GetRotation(), math.pi / 2.0):
|
||||||
i = physicalAttachment - 1
|
i = physicalAttachment - 1
|
||||||
elif RoughlyEqual(self.GetRotation(), math.pi):
|
elif RoughlyEqual(self.GetRotation(), math.pi):
|
||||||
i = physicalAttachment - 2
|
i = physicalAttachment - 2
|
||||||
elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2):
|
elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2.0):
|
||||||
i = physicalAttachment - 3
|
i = physicalAttachment - 3
|
||||||
else:
|
else:
|
||||||
# Can't handle -- assume the same
|
# Can't handle -- assume the same
|
||||||
return physicalAttachment
|
return physicalAttachment
|
||||||
|
|
||||||
if i<0:
|
if i < 0:
|
||||||
i += 4
|
i += 4
|
||||||
|
|
||||||
return i
|
return i
|
||||||
@@ -1862,16 +1859,16 @@ class Shape(ShapeEvtHandler):
|
|||||||
"""
|
"""
|
||||||
if RoughlyEqual(self.GetRotation(), 0):
|
if RoughlyEqual(self.GetRotation(), 0):
|
||||||
i = logicalAttachment
|
i = logicalAttachment
|
||||||
elif RoughlyEqual(self.GetRotation(), math.pi / 2):
|
elif RoughlyEqual(self.GetRotation(), math.pi / 2.0):
|
||||||
i = logicalAttachment + 1
|
i = logicalAttachment + 1
|
||||||
elif RoughlyEqual(self.GetRotation(), math.pi):
|
elif RoughlyEqual(self.GetRotation(), math.pi):
|
||||||
i = logicalAttachment + 2
|
i = logicalAttachment + 2
|
||||||
elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2):
|
elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2.0):
|
||||||
i = logicalAttachment + 3
|
i = logicalAttachment + 3
|
||||||
else:
|
else:
|
||||||
return logicalAttachment
|
return logicalAttachment
|
||||||
|
|
||||||
if i>3:
|
if i > 3:
|
||||||
i -= 4
|
i -= 4
|
||||||
|
|
||||||
return i
|
return i
|
||||||
@@ -1879,9 +1876,9 @@ class Shape(ShapeEvtHandler):
|
|||||||
def Rotate(self, x, y, theta):
|
def Rotate(self, x, y, theta):
|
||||||
"""Rotate about the given axis by the given amount in radians."""
|
"""Rotate about the given axis by the given amount in radians."""
|
||||||
self._rotation = theta
|
self._rotation = theta
|
||||||
if self._rotation<0:
|
if self._rotation < 0:
|
||||||
self._rotation += 2 * math.pi
|
self._rotation += 2 * math.pi
|
||||||
elif self._rotation>2 * math.pi:
|
elif self._rotation > 2 * math.pi:
|
||||||
self._rotation -= 2 * math.pi
|
self._rotation -= 2 * math.pi
|
||||||
|
|
||||||
def GetBackgroundPen(self):
|
def GetBackgroundPen(self):
|
||||||
@@ -2128,14 +2125,14 @@ class Shape(ShapeEvtHandler):
|
|||||||
newX1 = pt._controlPointDragStartX
|
newX1 = pt._controlPointDragStartX
|
||||||
newX2 = newX1 + pt._controlPointDragStartWidth
|
newX2 = newX1 + pt._controlPointDragStartWidth
|
||||||
elif pt._type == CONTROL_POINT_DIAGONAL and (keys & KEY_SHIFT or self.GetMaintainAspectRatio()):
|
elif pt._type == CONTROL_POINT_DIAGONAL and (keys & KEY_SHIFT or self.GetMaintainAspectRatio()):
|
||||||
newH = (newX2 - newX1) * (pt._controlPointDragStartHeight / pt._controlPointDragStartWidth)
|
newH = (newX2 - newX1) * (float(pt._controlPointDragStartHeight) / pt._controlPointDragStartWidth)
|
||||||
if self.GetY()>pt._controlPointDragStartY:
|
if self.GetY() > pt._controlPointDragStartY:
|
||||||
newY2 = newY1 + newH
|
newY2 = newY1 + newH
|
||||||
else:
|
else:
|
||||||
newY1 = newY2 - newH
|
newY1 = newY2 - newH
|
||||||
|
|
||||||
newWidth = newX2 - newX1
|
newWidth = float(newX2 - newX1)
|
||||||
newHeight = newY2 - newY1
|
newHeight = float(newY2 - newY1)
|
||||||
|
|
||||||
if pt._type == CONTROL_POINT_VERTICAL and self.GetMaintainAspectRatio():
|
if pt._type == CONTROL_POINT_VERTICAL and self.GetMaintainAspectRatio():
|
||||||
newWidth = bound_x * (newHeight / bound_y)
|
newWidth = bound_x * (newHeight / bound_y)
|
||||||
@@ -2143,8 +2140,8 @@ class Shape(ShapeEvtHandler):
|
|||||||
if pt._type == CONTROL_POINT_HORIZONTAL and self.GetMaintainAspectRatio():
|
if pt._type == CONTROL_POINT_HORIZONTAL and self.GetMaintainAspectRatio():
|
||||||
newHeight = bound_y * (newWidth / bound_x)
|
newHeight = bound_y * (newWidth / bound_x)
|
||||||
|
|
||||||
pt._controlPointDragPosX = newX1 + newWidth / 2
|
pt._controlPointDragPosX = newX1 + newWidth / 2.0
|
||||||
pt._controlPointDragPosY = newY1 + newHeight / 2
|
pt._controlPointDragPosY = newY1 + newHeight / 2.0
|
||||||
if self.GetFixedWidth():
|
if self.GetFixedWidth():
|
||||||
newWidth = bound_x
|
newWidth = bound_x
|
||||||
|
|
||||||
@@ -2168,20 +2165,20 @@ class Shape(ShapeEvtHandler):
|
|||||||
|
|
||||||
# Choose the 'opposite corner' of the object as the stationary
|
# Choose the 'opposite corner' of the object as the stationary
|
||||||
# point in case this is non-centring resizing.
|
# point in case this is non-centring resizing.
|
||||||
if pt.GetX()<self.GetX():
|
if pt.GetX() < self.GetX():
|
||||||
pt._controlPointDragStartX = self.GetX() + bound_x / 2
|
pt._controlPointDragStartX = self.GetX() + bound_x / 2.0
|
||||||
else:
|
else:
|
||||||
pt._controlPointDragStartX = self.GetX() - bound_x / 2
|
pt._controlPointDragStartX = self.GetX() - bound_x / 2.0
|
||||||
|
|
||||||
if pt.GetY()<self.GetY():
|
if pt.GetY() < self.GetY():
|
||||||
pt._controlPointDragStartY = self.GetY() + bound_y / 2
|
pt._controlPointDragStartY = self.GetY() + bound_y / 2.0
|
||||||
else:
|
else:
|
||||||
pt._controlPointDragStartY = self.GetY() - bound_y / 2
|
pt._controlPointDragStartY = self.GetY() - bound_y / 2.0
|
||||||
|
|
||||||
if pt._type == CONTROL_POINT_HORIZONTAL:
|
if pt._type == CONTROL_POINT_HORIZONTAL:
|
||||||
pt._controlPointDragStartY = self.GetY() - bound_y / 2
|
pt._controlPointDragStartY = self.GetY() - bound_y / 2.0
|
||||||
elif pt._type == CONTROL_POINT_VERTICAL:
|
elif pt._type == CONTROL_POINT_VERTICAL:
|
||||||
pt._controlPointDragStartX = self.GetX() - bound_x / 2
|
pt._controlPointDragStartX = self.GetX() - bound_x / 2.0
|
||||||
|
|
||||||
# We may require the old width and height
|
# We may require the old width and height
|
||||||
pt._controlPointDragStartWidth = bound_x
|
pt._controlPointDragStartWidth = bound_x
|
||||||
@@ -2231,14 +2228,14 @@ class Shape(ShapeEvtHandler):
|
|||||||
newX1 = pt._controlPointDragStartX
|
newX1 = pt._controlPointDragStartX
|
||||||
newX2 = newX1 + pt._controlPointDragStartWidth
|
newX2 = newX1 + pt._controlPointDragStartWidth
|
||||||
elif pt._type == CONTROL_POINT_DIAGONAL and (keys & KEYS or self.GetMaintainAspectRatio()):
|
elif pt._type == CONTROL_POINT_DIAGONAL and (keys & KEYS or self.GetMaintainAspectRatio()):
|
||||||
newH = (newX2 - newX1) * (pt._controlPointDragStartHeight / pt._controlPointDragStartWidth)
|
newH = (newX2 - newX1) * (float(pt._controlPointDragStartHeight) / pt._controlPointDragStartWidth)
|
||||||
if pt.GetY()>pt._controlPointDragStartY:
|
if pt.GetY() > pt._controlPointDragStartY:
|
||||||
newY2 = newY1 + newH
|
newY2 = newY1 + newH
|
||||||
else:
|
else:
|
||||||
newY1 = newY2 - newH
|
newY1 = newY2 - newH
|
||||||
|
|
||||||
newWidth = newX2 - newX1
|
newWidth = float(newX2 - newX1)
|
||||||
newHeight = newY2 - newY1
|
newHeight = float(newY2 - newY1)
|
||||||
|
|
||||||
if pt._type == CONTROL_POINT_VERTICAL and self.GetMaintainAspectRatio():
|
if pt._type == CONTROL_POINT_VERTICAL and self.GetMaintainAspectRatio():
|
||||||
newWidth = bound_x * (newHeight / bound_y)
|
newWidth = bound_x * (newHeight / bound_y)
|
||||||
@@ -2246,8 +2243,8 @@ class Shape(ShapeEvtHandler):
|
|||||||
if pt._type == CONTROL_POINT_HORIZONTAL and self.GetMaintainAspectRatio():
|
if pt._type == CONTROL_POINT_HORIZONTAL and self.GetMaintainAspectRatio():
|
||||||
newHeight = bound_y * (newWidth / bound_x)
|
newHeight = bound_y * (newWidth / bound_x)
|
||||||
|
|
||||||
pt._controlPointDragPosX = newX1 + newWidth / 2
|
pt._controlPointDragPosX = newX1 + newWidth / 2.0
|
||||||
pt._controlPointDragPosY = newY1 + newHeight / 2
|
pt._controlPointDragPosY = newY1 + newHeight / 2.0
|
||||||
if self.GetFixedWidth():
|
if self.GetFixedWidth():
|
||||||
newWidth = bound_x
|
newWidth = bound_x
|
||||||
|
|
||||||
@@ -2285,7 +2282,7 @@ class Shape(ShapeEvtHandler):
|
|||||||
|
|
||||||
# Recursively redraw links if we have a composite
|
# Recursively redraw links if we have a composite
|
||||||
if len(self.GetChildren()):
|
if len(self.GetChildren()):
|
||||||
self.DrawLinks(dc,-1, True)
|
self.DrawLinks(dc, -1, True)
|
||||||
|
|
||||||
width, height = self.GetBoundingBoxMax()
|
width, height = self.GetBoundingBoxMax()
|
||||||
self.GetEventHandler().OnEndSize(width, height)
|
self.GetEventHandler().OnEndSize(width, height)
|
||||||
@@ -2310,8 +2307,8 @@ class RectangleShape(Shape):
|
|||||||
self.SetDefaultRegionSize()
|
self.SetDefaultRegionSize()
|
||||||
|
|
||||||
def OnDraw(self, dc):
|
def OnDraw(self, dc):
|
||||||
x1 = self._xpos - self._width / 2
|
x1 = self._xpos - self._width / 2.0
|
||||||
y1 = self._ypos - self._height / 2
|
y1 = self._ypos - self._height / 2.0
|
||||||
|
|
||||||
if self._shadowMode != SHADOW_NONE:
|
if self._shadowMode != SHADOW_NONE:
|
||||||
if self._shadowBrush:
|
if self._shadowBrush:
|
||||||
@@ -2440,19 +2437,19 @@ class PolygonShape(Shape):
|
|||||||
def CalculateBoundingBox(self):
|
def CalculateBoundingBox(self):
|
||||||
# Calculate bounding box at construction (and presumably resize) time
|
# Calculate bounding box at construction (and presumably resize) time
|
||||||
left = 10000
|
left = 10000
|
||||||
right=-10000
|
right = -10000
|
||||||
top = 10000
|
top = 10000
|
||||||
bottom=-10000
|
bottom = -10000
|
||||||
|
|
||||||
for point in self._points:
|
for point in self._points:
|
||||||
if point.x<left:
|
if point.x < left:
|
||||||
left = point.x
|
left = point.x
|
||||||
if point.x>right:
|
if point.x > right:
|
||||||
right = point.x
|
right = point.x
|
||||||
|
|
||||||
if point.y<top:
|
if point.y < top:
|
||||||
top = point.y
|
top = point.y
|
||||||
if point.y>bottom:
|
if point.y > bottom:
|
||||||
bottom = point.y
|
bottom = point.y
|
||||||
|
|
||||||
self._boundWidth = right - left
|
self._boundWidth = right - left
|
||||||
@@ -2466,26 +2463,26 @@ class PolygonShape(Shape):
|
|||||||
box.
|
box.
|
||||||
"""
|
"""
|
||||||
left = 10000
|
left = 10000
|
||||||
right=-10000
|
right = -10000
|
||||||
top = 10000
|
top = 10000
|
||||||
bottom=-10000
|
bottom = -10000
|
||||||
|
|
||||||
for point in self._points:
|
for point in self._points:
|
||||||
if point.x<left:
|
if point.x < left:
|
||||||
left = point.x
|
left = point.x
|
||||||
if point.x>right:
|
if point.x > right:
|
||||||
right = point.x
|
right = point.x
|
||||||
|
|
||||||
if point.y<top:
|
if point.y < top:
|
||||||
top = point.y
|
top = point.y
|
||||||
if point.y>bottom:
|
if point.y > bottom:
|
||||||
bottom = point.y
|
bottom = point.y
|
||||||
|
|
||||||
bwidth = right - left
|
bwidth = right - left
|
||||||
bheight = bottom - top
|
bheight = bottom - top
|
||||||
|
|
||||||
newCentreX = left + bwidth / 2
|
newCentreX = left + bwidth / 2.0
|
||||||
newCentreY = top + bheight / 2
|
newCentreY = top + bheight / 2.0
|
||||||
|
|
||||||
for point in self._points:
|
for point in self._points:
|
||||||
point.x -= newCentreX
|
point.x -= newCentreX
|
||||||
@@ -2529,7 +2526,7 @@ class PolygonShape(Shape):
|
|||||||
if e:
|
if e:
|
||||||
xp, yp = e
|
xp, yp = e
|
||||||
l = math.sqrt((xp - x) * (xp - x) + (yp - y) * (yp - y))
|
l = math.sqrt((xp - x) * (xp - x) + (yp - y) * (yp - y))
|
||||||
if l<nearest:
|
if l < nearest:
|
||||||
nearest = l
|
nearest = l
|
||||||
nearest_attachment = i
|
nearest_attachment = i
|
||||||
|
|
||||||
@@ -2541,8 +2538,8 @@ class PolygonShape(Shape):
|
|||||||
self.SetAttachmentSize(new_width, new_height)
|
self.SetAttachmentSize(new_width, new_height)
|
||||||
|
|
||||||
# Multiply all points by proportion of new size to old size
|
# Multiply all points by proportion of new size to old size
|
||||||
x_proportion = abs(new_width / self._originalWidth)
|
x_proportion = abs(float(new_width) / self._originalWidth)
|
||||||
y_proportion = abs(new_height / self._originalHeight)
|
y_proportion = abs(float(new_height) / self._originalHeight)
|
||||||
|
|
||||||
for i in range(max(len(self._points), len(self._originalPoints))):
|
for i in range(max(len(self._points), len(self._originalPoints))):
|
||||||
self._points[i].x = self._originalPoints[i][0] * x_proportion
|
self._points[i].x = self._originalPoints[i][0] * x_proportion
|
||||||
@@ -2579,8 +2576,8 @@ class PolygonShape(Shape):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
secondPoint = self._points[0]
|
secondPoint = self._points[0]
|
||||||
|
|
||||||
x = (secondPoint.x - firstPoint.x) / 2 + firstPoint.x
|
x = (secondPoint.x - firstPoint.x) / 2.0 + firstPoint.x
|
||||||
y = (secondPoint.y - firstPoint.y) / 2 + firstPoint.y
|
y = (secondPoint.y - firstPoint.y) / 2.0 + firstPoint.y
|
||||||
point = wx.RealPoint(x, y)
|
point = wx.RealPoint(x, y)
|
||||||
|
|
||||||
if pos >= len(self._points) - 1:
|
if pos >= len(self._points) - 1:
|
||||||
@@ -2596,7 +2593,7 @@ class PolygonShape(Shape):
|
|||||||
|
|
||||||
def DeletePolygonPoint(self, pos):
|
def DeletePolygonPoint(self, pos):
|
||||||
"""Delete the given control point."""
|
"""Delete the given control point."""
|
||||||
if pos<len(self._points):
|
if pos < len(self._points):
|
||||||
del self._points[pos]
|
del self._points[pos]
|
||||||
self.UpdateOriginalPoints()
|
self.UpdateOriginalPoints()
|
||||||
if self._selected:
|
if self._selected:
|
||||||
@@ -2614,9 +2611,9 @@ class PolygonShape(Shape):
|
|||||||
# a heuristic...
|
# a heuristic...
|
||||||
for point in self._points:
|
for point in self._points:
|
||||||
if point.x == 0:
|
if point.x == 0:
|
||||||
if y2>y1 and point.y>0:
|
if y2 > y1 and point.y > 0:
|
||||||
return point.x + self._xpos, point.y + self._ypos
|
return point.x + self._xpos, point.y + self._ypos
|
||||||
elif y2<y1 and point.y<0:
|
elif y2 < y1 and point.y < 0:
|
||||||
return point.x + self._xpos, point.y + self._ypos
|
return point.x + self._xpos, point.y + self._ypos
|
||||||
|
|
||||||
xpoints = []
|
xpoints = []
|
||||||
@@ -2647,8 +2644,8 @@ class PolygonShape(Shape):
|
|||||||
def OnDrawOutline(self, dc, x, y, w, h):
|
def OnDrawOutline(self, dc, x, y, w, h):
|
||||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
# Multiply all points by proportion of new size to old size
|
# Multiply all points by proportion of new size to old size
|
||||||
x_proportion = abs(w / self._originalWidth)
|
x_proportion = abs(float(w) / self._originalWidth)
|
||||||
y_proportion = abs(h / self._originalHeight)
|
y_proportion = abs(float(h) / self._originalHeight)
|
||||||
|
|
||||||
intPoints = []
|
intPoints = []
|
||||||
for point in self._originalPoints:
|
for point in self._originalPoints:
|
||||||
@@ -2672,12 +2669,12 @@ class PolygonShape(Shape):
|
|||||||
def GetNumberOfAttachments(self):
|
def GetNumberOfAttachments(self):
|
||||||
maxN = max(len(self._points) - 1, 0)
|
maxN = max(len(self._points) - 1, 0)
|
||||||
for point in self._attachmentPoints:
|
for point in self._attachmentPoints:
|
||||||
if point._id>maxN:
|
if point._id > maxN:
|
||||||
maxN = point._id
|
maxN = point._id
|
||||||
return maxN + 1
|
return maxN + 1
|
||||||
|
|
||||||
def GetAttachmentPosition(self, attachment, nth = 0, no_arcs = 1, line = None):
|
def GetAttachmentPosition(self, attachment, nth = 0, no_arcs = 1, line = None):
|
||||||
if self._attachmentMode == ATTACHMENT_MODE_EDGE and self._points and attachment<len(self._points):
|
if self._attachmentMode == ATTACHMENT_MODE_EDGE and self._points and attachment < len(self._points):
|
||||||
point = self._points[0]
|
point = self._points[0]
|
||||||
return point.x + self._xpos, point.y + self._ypos
|
return point.x + self._xpos, point.y + self._ypos
|
||||||
return Shape.GetAttachmentPosition(self, attachment, nth, no_arcs, line)
|
return Shape.GetAttachmentPosition(self, attachment, nth, no_arcs, line)
|
||||||
@@ -2686,7 +2683,7 @@ class PolygonShape(Shape):
|
|||||||
if not self._points:
|
if not self._points:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if attachment >= 0 and attachment<len(self._points):
|
if attachment >= 0 and attachment < len(self._points):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
for point in self._attachmentPoints:
|
for point in self._attachmentPoints:
|
||||||
@@ -2840,8 +2837,8 @@ class EllipseShape(Shape):
|
|||||||
if self._shadowBrush:
|
if self._shadowBrush:
|
||||||
dc.SetBrush(self._shadowBrush)
|
dc.SetBrush(self._shadowBrush)
|
||||||
dc.SetPen(TransparentPen)
|
dc.SetPen(TransparentPen)
|
||||||
dc.DrawEllipse(self._xpos - self.GetWidth() / 2 + self._shadowOffsetX,
|
dc.DrawEllipse(self._xpos - self.GetWidth() / 2.0 + self._shadowOffsetX,
|
||||||
self._ypos - self.GetHeight() / 2 + self._shadowOffsetY,
|
self._ypos - self.GetHeight() / 2.0 + self._shadowOffsetY,
|
||||||
self.GetWidth(), self.GetHeight())
|
self.GetWidth(), self.GetHeight())
|
||||||
|
|
||||||
if self._pen:
|
if self._pen:
|
||||||
@@ -2851,7 +2848,7 @@ class EllipseShape(Shape):
|
|||||||
dc.SetPen(self._pen)
|
dc.SetPen(self._pen)
|
||||||
if self._brush:
|
if self._brush:
|
||||||
dc.SetBrush(self._brush)
|
dc.SetBrush(self._brush)
|
||||||
dc.DrawEllipse(self._xpos - self.GetWidth() / 2, self._ypos - self.GetHeight() / 2, self.GetWidth(), self.GetHeight())
|
dc.DrawEllipse(self._xpos - self.GetWidth() / 2.0, self._ypos - self.GetHeight() / 2.0, self.GetWidth(), self.GetHeight())
|
||||||
|
|
||||||
def SetSize(self, x, y, recursive = True):
|
def SetSize(self, x, y, recursive = True):
|
||||||
self.SetAttachmentSize(x, y)
|
self.SetAttachmentSize(x, y)
|
||||||
@@ -2869,16 +2866,16 @@ class EllipseShape(Shape):
|
|||||||
return Shape.GetAttachmentPosition(self, attachment, nth, no_arcs, line)
|
return Shape.GetAttachmentPosition(self, attachment, nth, no_arcs, line)
|
||||||
|
|
||||||
if self._attachmentMode != ATTACHMENT_MODE_NONE:
|
if self._attachmentMode != ATTACHMENT_MODE_NONE:
|
||||||
top = self._ypos + self._height / 2
|
top = self._ypos + self._height / 2.0
|
||||||
bottom = self._ypos - self._height / 2
|
bottom = self._ypos - self._height / 2.0
|
||||||
left = self._xpos - self._width / 2
|
left = self._xpos - self._width / 2.0
|
||||||
right = self._xpos + self._width / 2
|
right = self._xpos + self._width / 2.0
|
||||||
|
|
||||||
physicalAttachment = self.LogicalToPhysicalAttachment(attachment)
|
physicalAttachment = self.LogicalToPhysicalAttachment(attachment)
|
||||||
|
|
||||||
if physicalAttachment == 0:
|
if physicalAttachment == 0:
|
||||||
if self._spaceAttachments:
|
if self._spaceAttachments:
|
||||||
x = left + (nth + 1) * self._width / (no_arcs + 1)
|
x = left + (nth + 1) * self._width / (no_arcs + 1.0)
|
||||||
else:
|
else:
|
||||||
x = self._xpos
|
x = self._xpos
|
||||||
y = top
|
y = top
|
||||||
@@ -2891,13 +2888,13 @@ class EllipseShape(Shape):
|
|||||||
elif physicalAttachment == 1:
|
elif physicalAttachment == 1:
|
||||||
x = right
|
x = right
|
||||||
if self._spaceAttachments:
|
if self._spaceAttachments:
|
||||||
y = bottom + (nth + 1) * self._height / (no_arcs + 1)
|
y = bottom + (nth + 1) * self._height / (no_arcs + 1.0)
|
||||||
else:
|
else:
|
||||||
y = self._ypos
|
y = self._ypos
|
||||||
return DrawArcToEllipse(self._xpos, self._ypos, self._width, self._height, self._xpos + self._width + 500, y, self._xpos, y)
|
return DrawArcToEllipse(self._xpos, self._ypos, self._width, self._height, self._xpos + self._width + 500, y, self._xpos, y)
|
||||||
elif physicalAttachment == 2:
|
elif physicalAttachment == 2:
|
||||||
if self._spaceAttachments:
|
if self._spaceAttachments:
|
||||||
x = left + (nth + 1) * self._width / (no_arcs + 1)
|
x = left + (nth + 1) * self._width / (no_arcs + 1.0)
|
||||||
else:
|
else:
|
||||||
x = self._xpos
|
x = self._xpos
|
||||||
y = bottom
|
y = bottom
|
||||||
@@ -2905,7 +2902,7 @@ class EllipseShape(Shape):
|
|||||||
elif physicalAttachment == 3:
|
elif physicalAttachment == 3:
|
||||||
x = left
|
x = left
|
||||||
if self._spaceAttachments:
|
if self._spaceAttachments:
|
||||||
y = bottom + (nth + 1) * self._height / (no_arcs + 1)
|
y = bottom + (nth + 1) * self._height / (no_arcs + 1.0)
|
||||||
else:
|
else:
|
||||||
y = self._ypos
|
y = self._ypos
|
||||||
return DrawArcToEllipse(self._xpos, self._ypos, self._width, self._height, self._xpos - self._width - 500, y, self._xpos, y)
|
return DrawArcToEllipse(self._xpos, self._ypos, self._width, self._height, self._xpos - self._width - 500, y, self._xpos, y)
|
||||||
@@ -2923,7 +2920,7 @@ class CircleShape(EllipseShape):
|
|||||||
self.SetMaintainAspectRatio(True)
|
self.SetMaintainAspectRatio(True)
|
||||||
|
|
||||||
def GetPerimeterPoint(self, x1, y1, x2, y2):
|
def GetPerimeterPoint(self, x1, y1, x2, y2):
|
||||||
return FindEndForCircle(self._width / 2, self._xpos, self._ypos, x2, y2)
|
return FindEndForCircle(self._width / 2.0, self._xpos, self._ypos, x2, y2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2966,7 +2963,7 @@ class ShapeRegion(object):
|
|||||||
new_line = ShapeTextLine(line.GetX(), line.GetY(), line.GetText())
|
new_line = ShapeTextLine(line.GetX(), line.GetY(), line.GetText())
|
||||||
self._formattedText.append(new_line)
|
self._formattedText.append(new_line)
|
||||||
else:
|
else:
|
||||||
self._regionText=""
|
self._regionText = ""
|
||||||
self._font = NormalFont
|
self._font = NormalFont
|
||||||
self._minHeight = 5.0
|
self._minHeight = 5.0
|
||||||
self._minWidth = 5.0
|
self._minWidth = 5.0
|
||||||
@@ -2975,12 +2972,12 @@ class ShapeRegion(object):
|
|||||||
self._x = 0.0
|
self._x = 0.0
|
||||||
self._y = 0.0
|
self._y = 0.0
|
||||||
|
|
||||||
self._regionProportionX=-1.0
|
self._regionProportionX = -1.0
|
||||||
self._regionProportionY=-1.0
|
self._regionProportionY = -1.0
|
||||||
self._formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT
|
self._formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT
|
||||||
self._regionName=""
|
self._regionName = ""
|
||||||
self._textColour="BLACK"
|
self._textColour = "BLACK"
|
||||||
self._penColour="BLACK"
|
self._penColour = "BLACK"
|
||||||
self._penStyle = wx.SOLID
|
self._penStyle = wx.SOLID
|
||||||
self._actualColourObject = wx.TheColourDatabase.Find("BLACK")
|
self._actualColourObject = wx.TheColourDatabase.Find("BLACK")
|
||||||
self._actualPenObject = None
|
self._actualPenObject = None
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
from _basic import RectangleShape
|
from _basic import RectangleShape
|
||||||
|
|
||||||
|
|
||||||
@@ -20,14 +18,14 @@ class BitmapShape(RectangleShape):
|
|||||||
"""Draws a bitmap (non-resizable)."""
|
"""Draws a bitmap (non-resizable)."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
RectangleShape.__init__(self, 100, 50)
|
RectangleShape.__init__(self, 100, 50)
|
||||||
self._filename=""
|
self._filename = ""
|
||||||
|
|
||||||
def OnDraw(self, dc):
|
def OnDraw(self, dc):
|
||||||
if not self._bitmap.Ok():
|
if not self._bitmap.Ok():
|
||||||
return
|
return
|
||||||
|
|
||||||
x = self._xpos-self._bitmap.GetWidth() / 2
|
x = self._xpos - self._bitmap.GetWidth() / 2.0
|
||||||
y = self._ypos-self._bitmap.GetHeight() / 2
|
y = self._ypos - self._bitmap.GetHeight() / 2.0
|
||||||
dc.DrawBitmap(self._bitmap, x, y, True)
|
dc.DrawBitmap(self._bitmap, x, y, True)
|
||||||
|
|
||||||
def SetSize(self, w, h, recursive = True):
|
def SetSize(self, w, h, recursive = True):
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
from _lines import LineShape
|
from _lines import LineShape
|
||||||
from _composit import *
|
from _composit import *
|
||||||
@@ -31,13 +29,13 @@ def WhollyContains(contains, contained):
|
|||||||
w1, h1 = contains.GetBoundingBoxMax()
|
w1, h1 = contains.GetBoundingBoxMax()
|
||||||
w2, h2 = contained.GetBoundingBoxMax()
|
w2, h2 = contained.GetBoundingBoxMax()
|
||||||
|
|
||||||
left1 = xp1-w1 / 2.0
|
left1 = xp1 - w1 / 2.0
|
||||||
top1 = yp1-h1 / 2.0
|
top1 = yp1 - h1 / 2.0
|
||||||
right1 = xp1 + w1 / 2.0
|
right1 = xp1 + w1 / 2.0
|
||||||
bottom1 = yp1 + h1 / 2.0
|
bottom1 = yp1 + h1 / 2.0
|
||||||
|
|
||||||
left2 = xp2-w2 / 2.0
|
left2 = xp2 - w2 / 2.0
|
||||||
top2 = yp2-h2 / 2.0
|
top2 = yp2 - h2 / 2.0
|
||||||
right2 = xp2 + w2 / 2.0
|
right2 = xp2 + w2 / 2.0
|
||||||
bottom2 = yp2 + h2 / 2.0
|
bottom2 = yp2 + h2 / 2.0
|
||||||
|
|
||||||
@@ -46,7 +44,7 @@ def WhollyContains(contains, contained):
|
|||||||
|
|
||||||
|
|
||||||
class ShapeCanvas(wx.ScrolledWindow):
|
class ShapeCanvas(wx.ScrolledWindow):
|
||||||
def __init__(self, parent = None, id=-1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.BORDER, name="ShapeCanvas"):
|
def __init__(self, parent = None, id = -1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.BORDER, name = "ShapeCanvas"):
|
||||||
wx.ScrolledWindow.__init__(self, parent, id, pos, size, style, name)
|
wx.ScrolledWindow.__init__(self, parent, id, pos, size, style, name)
|
||||||
|
|
||||||
self._shapeDiagram = None
|
self._shapeDiagram = None
|
||||||
@@ -95,8 +93,8 @@ class ShapeCanvas(wx.ScrolledWindow):
|
|||||||
# If we're very close to the position we started dragging
|
# If we're very close to the position we started dragging
|
||||||
# from, this may not be an intentional drag at all.
|
# from, this may not be an intentional drag at all.
|
||||||
if dragging:
|
if dragging:
|
||||||
dx = abs(dc.LogicalToDeviceX(x-self._firstDragX))
|
dx = abs(dc.LogicalToDeviceX(x - self._firstDragX))
|
||||||
dy = abs(dc.LogicalToDeviceY(y-self._firstDragY))
|
dy = abs(dc.LogicalToDeviceY(y - self._firstDragY))
|
||||||
if self._checkTolerance and (dx <= self.GetDiagram().GetMouseTolerance()) and (dy <= self.GetDiagram().GetMouseTolerance()):
|
if self._checkTolerance and (dx <= self.GetDiagram().GetMouseTolerance()) and (dy <= self.GetDiagram().GetMouseTolerance()):
|
||||||
return
|
return
|
||||||
# If we've ignored the tolerance once, then ALWAYS ignore
|
# If we've ignored the tolerance once, then ALWAYS ignore
|
||||||
@@ -270,7 +268,9 @@ class ShapeCanvas(wx.ScrolledWindow):
|
|||||||
# the other objects
|
# the other objects
|
||||||
# (b) to find the control points FIRST if they exist
|
# (b) to find the control points FIRST if they exist
|
||||||
|
|
||||||
for object in self.GetDiagram().GetShapeList()[::-1]:
|
rl = self.GetDiagram().GetShapeList()[:]
|
||||||
|
rl.reverse()
|
||||||
|
for object in rl:
|
||||||
# First pass for lines, which might be inside a container, so we
|
# First pass for lines, which might be inside a container, so we
|
||||||
# want lines to take priority over containers. This first loop
|
# want lines to take priority over containers. This first loop
|
||||||
# could fail if we clickout side a line, so then we'll
|
# could fail if we clickout side a line, so then we'll
|
||||||
@@ -288,12 +288,12 @@ class ShapeCanvas(wx.ScrolledWindow):
|
|||||||
# to specify the nearest point to the centre of the line
|
# to specify the nearest point to the centre of the line
|
||||||
# as our hit criterion, to give the user some room for
|
# as our hit criterion, to give the user some room for
|
||||||
# manouevre.
|
# manouevre.
|
||||||
if dist<nearest:
|
if dist < nearest:
|
||||||
nearest = dist
|
nearest = dist
|
||||||
nearest_object = object
|
nearest_object = object
|
||||||
nearest_attachment = temp_attachment
|
nearest_attachment = temp_attachment
|
||||||
|
|
||||||
for object in self.GetDiagram().GetShapeList()[::-1]:
|
for object in rl:
|
||||||
# On second pass, only ever consider non-composites or
|
# On second pass, only ever consider non-composites or
|
||||||
# divisions. If children want to pass up control to
|
# divisions. If children want to pass up control to
|
||||||
# the composite, that's up to them.
|
# the composite, that's up to them.
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
@@ -138,7 +136,7 @@ class Constraint(object):
|
|||||||
self._constraintingObject = constraining
|
self._constraintingObject = constraining
|
||||||
|
|
||||||
self._constraintId = 0
|
self._constraintId = 0
|
||||||
self._constraintName="noname"
|
self._constraintName = "noname"
|
||||||
|
|
||||||
self._constrainedObjects = constrained[:]
|
self._constrainedObjects = constrained[:]
|
||||||
|
|
||||||
@@ -156,7 +154,7 @@ class Constraint(object):
|
|||||||
"""
|
"""
|
||||||
marg = 0.5
|
marg = 0.5
|
||||||
|
|
||||||
return b <= a + marg and b >= a-marg
|
return b <= a + marg and b >= a - marg
|
||||||
|
|
||||||
def Evaluate(self):
|
def Evaluate(self):
|
||||||
"""Evaluate this constraint and return TRUE if anything changed."""
|
"""Evaluate this constraint and return TRUE if anything changed."""
|
||||||
@@ -177,21 +175,21 @@ class Constraint(object):
|
|||||||
|
|
||||||
# Check if within the constraining object...
|
# Check if within the constraining object...
|
||||||
if totalObjectHeight + (n + 1) * self._ySpacing <= minHeight:
|
if totalObjectHeight + (n + 1) * self._ySpacing <= minHeight:
|
||||||
spacingY = (minHeight-totalObjectHeight) / (n + 1)
|
spacingY = (minHeight - totalObjectHeight) / (n + 1.0)
|
||||||
startY = y-minHeight / 2
|
startY = y - minHeight / 2.0
|
||||||
else: # Otherwise, use default spacing
|
else: # Otherwise, use default spacing
|
||||||
spacingY = self._ySpacing
|
spacingY = self._ySpacing
|
||||||
startY = y-(totalObjectHeight + (n + 1) * spacingY) / 2
|
startY = y - (totalObjectHeight + (n + 1) * spacingY) / 2.0
|
||||||
|
|
||||||
# Now position the objects
|
# Now position the objects
|
||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
startY += spacingY + height2 / 2
|
startY += spacingY + height2 / 2.0
|
||||||
if not self.Equals(startY, constrainedObject.GetY()):
|
if not self.Equals(startY, constrainedObject.GetY()):
|
||||||
constrainedObject.Move(dc, constrainedObject.GetX(), startY, False)
|
constrainedObject.Move(dc, constrainedObject.GetX(), startY, False)
|
||||||
changed = True
|
changed = True
|
||||||
startY += height2 / 2
|
startY += height2 / 2.0
|
||||||
return changed
|
return changed
|
||||||
elif self._constraintType == CONSTRAINT_CENTRED_HORIZONTALLY:
|
elif self._constraintType == CONSTRAINT_CENTRED_HORIZONTALLY:
|
||||||
n = len(self._constrainedObjects)
|
n = len(self._constrainedObjects)
|
||||||
@@ -201,22 +199,22 @@ class Constraint(object):
|
|||||||
totalObjectWidth += width2
|
totalObjectWidth += width2
|
||||||
|
|
||||||
# Check if within the constraining object...
|
# Check if within the constraining object...
|
||||||
if totalObjectWidth + (n + 1) * self._xSpacing<minWidth:
|
if totalObjectWidth + (n + 1) * self._xSpacing <= minWidth:
|
||||||
spacingX = (minWidth-totalObjectWidth) / (n + 1)
|
spacingX = (minWidth - totalObjectWidth) / (n + 1.0)
|
||||||
startX = x-minWidth / 2
|
startX = x - minWidth / 2.0
|
||||||
else: # Otherwise, use default spacing
|
else: # Otherwise, use default spacing
|
||||||
spacingX = self._xSpacing
|
spacingX = self._xSpacing
|
||||||
startX = x-(totalObjectWidth + (n + 1) * spacingX) / 2
|
startX = x - (totalObjectWidth + (n + 1) * spacingX) / 2.0
|
||||||
|
|
||||||
# Now position the objects
|
# Now position the objects
|
||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
startX += spacingX + width2 / 2
|
startX += spacingX + width2 / 2.0
|
||||||
if not self.Equals(startX, constrainedObject.GetX()):
|
if not self.Equals(startX, constrainedObject.GetX()):
|
||||||
constrainedObject.Move(dc, startX, constrainedObject.GetY(), False)
|
constrainedObject.Move(dc, startX, constrainedObject.GetY(), False)
|
||||||
changed = True
|
changed = True
|
||||||
startX += width2 / 2
|
startX += width2 / 2.0
|
||||||
return changed
|
return changed
|
||||||
elif self._constraintType == CONSTRAINT_CENTRED_BOTH:
|
elif self._constraintType == CONSTRAINT_CENTRED_BOTH:
|
||||||
n = len(self._constrainedObjects)
|
n = len(self._constrainedObjects)
|
||||||
@@ -230,40 +228,40 @@ class Constraint(object):
|
|||||||
|
|
||||||
# Check if within the constraining object...
|
# Check if within the constraining object...
|
||||||
if totalObjectHeight + (n + 1) * self._xSpacing <= minWidth:
|
if totalObjectHeight + (n + 1) * self._xSpacing <= minWidth:
|
||||||
spacingX = (minWidth-totalObjectWidth) / (n + 1)
|
spacingX = (minWidth - totalObjectWidth) / (n + 1.0)
|
||||||
startX = x-minWidth / 2
|
startX = x - minWidth / 2.0
|
||||||
else: # Otherwise, use default spacing
|
else: # Otherwise, use default spacing
|
||||||
spacingX = self._xSpacing
|
spacingX = self._xSpacing
|
||||||
startX = x-(totalObjectWidth + (n + 1) * spacingX) / 2
|
startX = x - (totalObjectWidth + (n + 1) * spacingX) / 2.0
|
||||||
|
|
||||||
# Check if within the constraining object...
|
# Check if within the constraining object...
|
||||||
if totalObjectHeight + (n + 1) * self._ySpacing <= minHeight:
|
if totalObjectHeight + (n + 1) * self._ySpacing <= minHeight:
|
||||||
spacingY = (minHeight-totalObjectHeight) / (n + 1)
|
spacingY = (minHeight - totalObjectHeight) / (n + 1.0)
|
||||||
startY = y-minHeight / 2
|
startY = y - minHeight / 2.0
|
||||||
else: # Otherwise, use default spacing
|
else: # Otherwise, use default spacing
|
||||||
spacingY = self._ySpacing
|
spacingY = self._ySpacing
|
||||||
startY = y-(totalObjectHeight + (n + 1) * spacingY) / 2
|
startY = y - (totalObjectHeight + (n + 1) * spacingY) / 2.0
|
||||||
|
|
||||||
# Now position the objects
|
# Now position the objects
|
||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
startX += spacingX + width2 / 2
|
startX += spacingX + width2 / 2.0
|
||||||
startY += spacingY + height2 / 2
|
startY += spacingY + height2 / 2.0
|
||||||
|
|
||||||
if not self.Equals(startX, constrainedObject.GetX()) or not self.Equals(startY, constrainedObject.GetY()):
|
if not self.Equals(startX, constrainedObject.GetX()) or not self.Equals(startY, constrainedObject.GetY()):
|
||||||
constrainedObject.Move(dc, startX, startY, False)
|
constrainedObject.Move(dc, startX, startY, False)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
startX += width2 / 2
|
startX += width2 / 2.0
|
||||||
startY += height2 / 2
|
startY += height2 / 2.0
|
||||||
return changed
|
return changed
|
||||||
elif self._constraintType == CONSTRAINT_LEFT_OF:
|
elif self._constraintType == CONSTRAINT_LEFT_OF:
|
||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
|
|
||||||
x3 = x-minWidth / 2-width2 / 2-self._xSpacing
|
x3 = x - minWidth / 2.0 - width2 / 2.0 - self._xSpacing
|
||||||
if not self.Equals(x3, constrainedObject.GetX()):
|
if not self.Equals(x3, constrainedObject.GetX()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
||||||
@@ -273,7 +271,7 @@ class Constraint(object):
|
|||||||
|
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
x3 = x + minWidth / 2 + width2 / 2 + self._xSpacing
|
x3 = x + minWidth / 2.0 + width2 / 2.0 + self._xSpacing
|
||||||
if not self.Equals(x3, constrainedObject.GetX()):
|
if not self.Equals(x3, constrainedObject.GetX()):
|
||||||
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
||||||
changed = True
|
changed = True
|
||||||
@@ -284,7 +282,7 @@ class Constraint(object):
|
|||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
|
|
||||||
y3 = y-minHeight / 2-height2 / 2-self._ySpacing
|
y3 = y - minHeight / 2.0 - height2 / 2.0 - self._ySpacing
|
||||||
if not self.Equals(y3, constrainedObject.GetY()):
|
if not self.Equals(y3, constrainedObject.GetY()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
||||||
@@ -295,7 +293,7 @@ class Constraint(object):
|
|||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
|
|
||||||
y3 = y + minHeight / 2 + height2 / 2 + self._ySpacing
|
y3 = y + minHeight / 2.0 + height2 / 2.0 + self._ySpacing
|
||||||
if not self.Equals(y3, constrainedObject.GetY()):
|
if not self.Equals(y3, constrainedObject.GetY()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
||||||
@@ -304,7 +302,7 @@ class Constraint(object):
|
|||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
x3 = x-minWidth / 2 + width2 / 2 + self._xSpacing
|
x3 = x - minWidth / 2.0 + width2 / 2.0 + self._xSpacing
|
||||||
if not self.Equals(x3, constrainedObject.GetX()):
|
if not self.Equals(x3, constrainedObject.GetX()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
||||||
@@ -313,7 +311,7 @@ class Constraint(object):
|
|||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
x3 = x + minWidth / 2-width2 / 2-self._xSpacing
|
x3 = x + minWidth / 2.0 - width2 / 2.0 - self._xSpacing
|
||||||
if not self.Equals(x3, constrainedObject.GetX()):
|
if not self.Equals(x3, constrainedObject.GetX()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
||||||
@@ -322,7 +320,7 @@ class Constraint(object):
|
|||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
y3 = y-minHeight / 2 + height2 / 2 + self._ySpacing
|
y3 = y - minHeight / 2.0 + height2 / 2.0 + self._ySpacing
|
||||||
if not self.Equals(y3, constrainedObject.GetY()):
|
if not self.Equals(y3, constrainedObject.GetY()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
||||||
@@ -331,7 +329,7 @@ class Constraint(object):
|
|||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
width2, height2 = constrainedObject.GetBoundingBoxMax()
|
||||||
y3 = y + minHeight / 2-height2 / 2-self._ySpacing
|
y3 = y + minHeight / 2.0 - height2 / 2.0 - self._ySpacing
|
||||||
if not self.Equals(y3, constrainedObject.GetY()):
|
if not self.Equals(y3, constrainedObject.GetY()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
||||||
@@ -339,7 +337,7 @@ class Constraint(object):
|
|||||||
elif self._constraintType == CONSTRAINT_MIDALIGNED_LEFT:
|
elif self._constraintType == CONSTRAINT_MIDALIGNED_LEFT:
|
||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
x3 = x-minWidth / 2
|
x3 = x - minWidth / 2.0
|
||||||
if not self.Equals(x3, constrainedObject.GetX()):
|
if not self.Equals(x3, constrainedObject.GetX()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
||||||
@@ -347,7 +345,7 @@ class Constraint(object):
|
|||||||
elif self._constraintType == CONSTRAINT_MIDALIGNED_RIGHT:
|
elif self._constraintType == CONSTRAINT_MIDALIGNED_RIGHT:
|
||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
x3 = x + minWidth / 2
|
x3 = x + minWidth / 2.0
|
||||||
if not self.Equals(x3, constrainedObject.GetX()):
|
if not self.Equals(x3, constrainedObject.GetX()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
constrainedObject.Move(dc, x3, constrainedObject.GetY(), False)
|
||||||
@@ -355,7 +353,7 @@ class Constraint(object):
|
|||||||
elif self._constraintType == CONSTRAINT_MIDALIGNED_TOP:
|
elif self._constraintType == CONSTRAINT_MIDALIGNED_TOP:
|
||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
y3 = y-minHeight / 2
|
y3 = y - minHeight / 2.0
|
||||||
if not self.Equals(y3, constrainedObject.GetY()):
|
if not self.Equals(y3, constrainedObject.GetY()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
||||||
@@ -363,7 +361,7 @@ class Constraint(object):
|
|||||||
elif self._constraintType == CONSTRAINT_MIDALIGNED_BOTTOM:
|
elif self._constraintType == CONSTRAINT_MIDALIGNED_BOTTOM:
|
||||||
changed = False
|
changed = False
|
||||||
for constrainedObject in self._constrainedObjects:
|
for constrainedObject in self._constrainedObjects:
|
||||||
y3 = y + minHeight / 2
|
y3 = y + minHeight / 2.0
|
||||||
if not self.Equals(y3, constrainedObject.GetY()):
|
if not self.Equals(y3, constrainedObject.GetY()):
|
||||||
changed = True
|
changed = True
|
||||||
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
constrainedObject.Move(dc, constrainedObject.GetX(), y3, False)
|
||||||
@@ -392,8 +390,8 @@ class CompositeShape(RectangleShape):
|
|||||||
self._divisions = [] # In case it's a container
|
self._divisions = [] # In case it's a container
|
||||||
|
|
||||||
def OnDraw(self, dc):
|
def OnDraw(self, dc):
|
||||||
x1 = self._xpos-self._width / 2
|
x1 = self._xpos - self._width / 2.0
|
||||||
y1 = self._ypos-self._height / 2
|
y1 = self._ypos - self._height / 2.0
|
||||||
|
|
||||||
if self._shadowMode != SHADOW_NONE:
|
if self._shadowMode != SHADOW_NONE:
|
||||||
if self._shadowBrush:
|
if self._shadowBrush:
|
||||||
@@ -416,8 +414,8 @@ class CompositeShape(RectangleShape):
|
|||||||
Shape.OnDrawContents(self, dc)
|
Shape.OnDrawContents(self, dc)
|
||||||
|
|
||||||
def OnMovePre(self, dc, x, y, old_x, old_y, display = True):
|
def OnMovePre(self, dc, x, y, old_x, old_y, display = True):
|
||||||
diffX = x-old_x
|
diffX = x - old_x
|
||||||
diffY = y-old_y
|
diffY = y - old_y
|
||||||
|
|
||||||
for object in self._children:
|
for object in self._children:
|
||||||
object.Erase(dc)
|
object.Erase(dc)
|
||||||
@@ -507,8 +505,8 @@ class CompositeShape(RectangleShape):
|
|||||||
def SetSize(self, w, h, recursive = True):
|
def SetSize(self, w, h, recursive = True):
|
||||||
self.SetAttachmentSize(w, h)
|
self.SetAttachmentSize(w, h)
|
||||||
|
|
||||||
xScale = w / max(1, self.GetWidth())
|
xScale = float(w) / max(1, self.GetWidth())
|
||||||
yScale = h / max(1, self.GetHeight())
|
yScale = float(h) / max(1, self.GetHeight())
|
||||||
|
|
||||||
self._width = w
|
self._width = w
|
||||||
self._height = h
|
self._height = h
|
||||||
@@ -521,8 +519,8 @@ class CompositeShape(RectangleShape):
|
|||||||
|
|
||||||
for object in self._children:
|
for object in self._children:
|
||||||
# Scale the position first
|
# Scale the position first
|
||||||
newX = (object.GetX()-self.GetX()) * xScale + self.GetX()
|
newX = (object.GetX() - self.GetX()) * xScale + self.GetX()
|
||||||
newY = (object.GetY()-self.GetY()) * yScale + self.GetY()
|
newY = (object.GetY() - self.GetY()) * yScale + self.GetY()
|
||||||
object.Show(False)
|
object.Show(False)
|
||||||
object.Move(dc, newX, newY)
|
object.Move(dc, newX, newY)
|
||||||
object.Show(True)
|
object.Show(True)
|
||||||
@@ -628,8 +626,8 @@ class CompositeShape(RectangleShape):
|
|||||||
"""Calculates the size and position of the composite based on
|
"""Calculates the size and position of the composite based on
|
||||||
child sizes and positions.
|
child sizes and positions.
|
||||||
"""
|
"""
|
||||||
maxX=-999999.9
|
maxX = -999999.9
|
||||||
maxY=-999999.9
|
maxY = -999999.9
|
||||||
minX = 999999.9
|
minX = 999999.9
|
||||||
minY = 999999.9
|
minY = 999999.9
|
||||||
|
|
||||||
@@ -640,19 +638,19 @@ class CompositeShape(RectangleShape):
|
|||||||
child.CalculateSize()
|
child.CalculateSize()
|
||||||
|
|
||||||
w, h = child.GetBoundingBoxMax()
|
w, h = child.GetBoundingBoxMax()
|
||||||
if child.GetX() + w / 2>maxX:
|
if child.GetX() + w / 2.0 > maxX:
|
||||||
maxX = child.GetX() + w / 2
|
maxX = child.GetX() + w / 2.0
|
||||||
if child.GetX()-w / 2<minX:
|
if child.GetX() - w / 2.0 < minX:
|
||||||
minX = child.GetX()-w / 2
|
minX = child.GetX() - w / 2.0
|
||||||
if child.GetY() + h / 2>maxY:
|
if child.GetY() + h / 2.0 > maxY:
|
||||||
maxY = child.GetY() + h / 2
|
maxY = child.GetY() + h / 2.0
|
||||||
if child.GetY()-h / 2<minY:
|
if child.GetY() - h / 2.0 < minY:
|
||||||
minY = child.GetY()-h / 2
|
minY = child.GetY() - h / 2.0
|
||||||
|
|
||||||
self._width = maxX-minX
|
self._width = maxX - minX
|
||||||
self._height = maxY-minY
|
self._height = maxY - minY
|
||||||
self._xpos = self._width / 2 + minX
|
self._xpos = self._width / 2.0 + minX
|
||||||
self._ypos = self._height / 2 + minY
|
self._ypos = self._height / 2.0 + minY
|
||||||
|
|
||||||
def Recompute(self):
|
def Recompute(self):
|
||||||
"""Recomputes any constraints associated with the object. If FALSE is
|
"""Recomputes any constraints associated with the object. If FALSE is
|
||||||
@@ -661,7 +659,7 @@ class CompositeShape(RectangleShape):
|
|||||||
"""
|
"""
|
||||||
noIterations = 0
|
noIterations = 0
|
||||||
changed = True
|
changed = True
|
||||||
while changed and noIterations<500:
|
while changed and noIterations < 500:
|
||||||
changed = self.Constrain()
|
changed = self.Constrain()
|
||||||
noIterations += 1
|
noIterations += 1
|
||||||
|
|
||||||
@@ -783,17 +781,17 @@ class DivisionControlPoint(ControlPoint):
|
|||||||
divisionParent = division.GetParent()
|
divisionParent = division.GetParent()
|
||||||
|
|
||||||
# Need to check it's within the bounds of the parent composite
|
# Need to check it's within the bounds of the parent composite
|
||||||
x1 = divisionParent.GetX()-divisionParent.GetWidth() / 2
|
x1 = divisionParent.GetX() - divisionParent.GetWidth() / 2.0
|
||||||
y1 = divisionParent.GetY()-divisionParent.GetHeight() / 2
|
y1 = divisionParent.GetY() - divisionParent.GetHeight() / 2.0
|
||||||
x2 = divisionParent.GetX() + divisionParent.GetWidth() / 2
|
x2 = divisionParent.GetX() + divisionParent.GetWidth() / 2.0
|
||||||
y2 = divisionParent.GetY() + divisionParent.GetHeight() / 2
|
y2 = divisionParent.GetY() + divisionParent.GetHeight() / 2.0
|
||||||
|
|
||||||
# Need to check it has not made the division zero or negative
|
# Need to check it has not made the division zero or negative
|
||||||
# width / height
|
# width / height
|
||||||
dx1 = division.GetX()-division.GetWidth() / 2
|
dx1 = division.GetX() - division.GetWidth() / 2.0
|
||||||
dy1 = division.GetY()-division.GetHeight() / 2
|
dy1 = division.GetY() - division.GetHeight() / 2.0
|
||||||
dx2 = division.GetX() + division.GetWidth() / 2
|
dx2 = division.GetX() + division.GetWidth() / 2.0
|
||||||
dy2 = division.GetY() + division.GetHeight() / 2
|
dy2 = division.GetY() + division.GetHeight() / 2.0
|
||||||
|
|
||||||
success = True
|
success = True
|
||||||
if division.GetHandleSide() == DIVISION_SIDE_LEFT:
|
if division.GetHandleSide() == DIVISION_SIDE_LEFT:
|
||||||
@@ -895,10 +893,10 @@ class DivisionShape(CompositeShape):
|
|||||||
self._handleSide = DIVISION_SIDE_NONE
|
self._handleSide = DIVISION_SIDE_NONE
|
||||||
self._leftSidePen = wx.BLACK_PEN
|
self._leftSidePen = wx.BLACK_PEN
|
||||||
self._topSidePen = wx.BLACK_PEN
|
self._topSidePen = wx.BLACK_PEN
|
||||||
self._leftSideColour="BLACK"
|
self._leftSideColour = "BLACK"
|
||||||
self._topSideColour="BLACK"
|
self._topSideColour = "BLACK"
|
||||||
self._leftSideStyle="Solid"
|
self._leftSideStyle = "Solid"
|
||||||
self._topSideStyle="Solid"
|
self._topSideStyle = "Solid"
|
||||||
self.ClearRegions()
|
self.ClearRegions()
|
||||||
|
|
||||||
def SetLeftSide(self, shape):
|
def SetLeftSide(self, shape):
|
||||||
@@ -994,13 +992,13 @@ class DivisionShape(CompositeShape):
|
|||||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
dc.SetBackgroundMode(wx.TRANSPARENT)
|
dc.SetBackgroundMode(wx.TRANSPARENT)
|
||||||
|
|
||||||
x1 = self.GetX()-self.GetWidth() / 2
|
x1 = self.GetX() - self.GetWidth() / 2.0
|
||||||
y1 = self.GetY()-self.GetHeight() / 2
|
y1 = self.GetY() - self.GetHeight() / 2.0
|
||||||
x2 = self.GetX() + self.GetWidth() / 2
|
x2 = self.GetX() + self.GetWidth() / 2.0
|
||||||
y2 = self.GetY() + self.GetHeight() / 2
|
y2 = self.GetY() + self.GetHeight() / 2.0
|
||||||
|
|
||||||
# Should subtract 1 pixel if drawing under Windows
|
# Should subtract 1 pixel if drawing under Windows
|
||||||
if sys.platform[:3]=="win":
|
if sys.platform[:3] == "win":
|
||||||
y2 -= 1
|
y2 -= 1
|
||||||
|
|
||||||
if self._leftSide:
|
if self._leftSide:
|
||||||
@@ -1020,8 +1018,8 @@ class DivisionShape(CompositeShape):
|
|||||||
CompositeShape.OnDrawContents(self, dc)
|
CompositeShape.OnDrawContents(self, dc)
|
||||||
|
|
||||||
def OnMovePre(self, dc, x, y, oldx, oldy, display = True):
|
def OnMovePre(self, dc, x, y, oldx, oldy, display = True):
|
||||||
diffX = x-oldx
|
diffX = x - oldx
|
||||||
diffY = y-oldy
|
diffY = y - oldy
|
||||||
for object in self._children:
|
for object in self._children:
|
||||||
object.Erase(dc)
|
object.Erase(dc)
|
||||||
object.Move(dc, object.GetX() + diffX, object.GetY() + diffY, display)
|
object.Move(dc, object.GetX() + diffX, object.GetY() + diffY, display)
|
||||||
@@ -1100,8 +1098,8 @@ class DivisionShape(CompositeShape):
|
|||||||
vertically (direction is wxVERTICAL).
|
vertically (direction is wxVERTICAL).
|
||||||
"""
|
"""
|
||||||
# Calculate existing top-left, bottom-right
|
# Calculate existing top-left, bottom-right
|
||||||
x1 = self.GetX()-self.GetWidth() / 2
|
x1 = self.GetX() - self.GetWidth() / 2.0
|
||||||
y1 = self.GetY()-self.GetHeight() / 2
|
y1 = self.GetY() - self.GetHeight() / 2.0
|
||||||
|
|
||||||
compositeParent = self.GetParent()
|
compositeParent = self.GetParent()
|
||||||
oldWidth = self.GetWidth()
|
oldWidth = self.GetWidth()
|
||||||
@@ -1117,9 +1115,9 @@ class DivisionShape(CompositeShape):
|
|||||||
# line through it.
|
# line through it.
|
||||||
# Break existing piece into two.
|
# Break existing piece into two.
|
||||||
newXPos1 = self.GetX()
|
newXPos1 = self.GetX()
|
||||||
newYPos1 = y1 + self.GetHeight() / 4
|
newYPos1 = y1 + self.GetHeight() / 4.0
|
||||||
newXPos2 = self.GetX()
|
newXPos2 = self.GetX()
|
||||||
newYPos2 = y1 + 3 * self.GetHeight() / 4
|
newYPos2 = y1 + 3 * self.GetHeight() / 4.0
|
||||||
newDivision = compositeParent.OnCreateDivision()
|
newDivision = compositeParent.OnCreateDivision()
|
||||||
newDivision.Show(True)
|
newDivision.Show(True)
|
||||||
|
|
||||||
@@ -1153,18 +1151,18 @@ class DivisionShape(CompositeShape):
|
|||||||
self._handleSide = DIVISION_SIDE_BOTTOM
|
self._handleSide = DIVISION_SIDE_BOTTOM
|
||||||
newDivision.SetHandleSide(DIVISION_SIDE_TOP)
|
newDivision.SetHandleSide(DIVISION_SIDE_TOP)
|
||||||
|
|
||||||
self.SetSize(oldWidth, oldHeight / 2)
|
self.SetSize(oldWidth, oldHeight / 2.0)
|
||||||
self.Move(dc, newXPos1, newYPos1)
|
self.Move(dc, newXPos1, newYPos1)
|
||||||
|
|
||||||
newDivision.SetSize(oldWidth, oldHeight / 2)
|
newDivision.SetSize(oldWidth, oldHeight / 2.0)
|
||||||
newDivision.Move(dc, newXPos2, newYPos2)
|
newDivision.Move(dc, newXPos2, newYPos2)
|
||||||
else:
|
else:
|
||||||
# Dividing horizontally means notionally putting a vertical line
|
# Dividing horizontally means notionally putting a vertical line
|
||||||
# through it.
|
# through it.
|
||||||
# Break existing piece into two.
|
# Break existing piece into two.
|
||||||
newXPos1 = x1 + self.GetWidth() / 4
|
newXPos1 = x1 + self.GetWidth() / 4.0
|
||||||
newYPos1 = self.GetY()
|
newYPos1 = self.GetY()
|
||||||
newXPos2 = x1 + 3 * self.GetWidth() / 4
|
newXPos2 = x1 + 3 * self.GetWidth() / 4.0
|
||||||
newYPos2 = self.GetY()
|
newYPos2 = self.GetY()
|
||||||
newDivision = compositeParent.OnCreateDivision()
|
newDivision = compositeParent.OnCreateDivision()
|
||||||
newDivision.Show(True)
|
newDivision.Show(True)
|
||||||
@@ -1189,10 +1187,10 @@ class DivisionShape(CompositeShape):
|
|||||||
self._handleSide = DIVISION_SIDE_RIGHT
|
self._handleSide = DIVISION_SIDE_RIGHT
|
||||||
newDivision.SetHandleSide(DIVISION_SIDE_LEFT)
|
newDivision.SetHandleSide(DIVISION_SIDE_LEFT)
|
||||||
|
|
||||||
self.SetSize(oldWidth / 2, oldHeight)
|
self.SetSize(oldWidth / 2.0, oldHeight)
|
||||||
self.Move(dc, newXPos1, newYPos1)
|
self.Move(dc, newXPos1, newYPos1)
|
||||||
|
|
||||||
newDivision.SetSize(oldWidth / 2, oldHeight)
|
newDivision.SetSize(oldWidth / 2.0, oldHeight)
|
||||||
newDivision.Move(dc, newXPos2, newYPos2)
|
newDivision.Move(dc, newXPos2, newYPos2)
|
||||||
|
|
||||||
if compositeParent.Selected():
|
if compositeParent.Selected():
|
||||||
@@ -1212,16 +1210,16 @@ class DivisionShape(CompositeShape):
|
|||||||
direction = 0
|
direction = 0
|
||||||
|
|
||||||
if self._handleSide == DIVISION_SIDE_LEFT:
|
if self._handleSide == DIVISION_SIDE_LEFT:
|
||||||
x=-maxX / 2
|
x = -maxX / 2.0
|
||||||
direction = CONTROL_POINT_HORIZONTAL
|
direction = CONTROL_POINT_HORIZONTAL
|
||||||
elif self._handleSide == DIVISION_SIDE_TOP:
|
elif self._handleSide == DIVISION_SIDE_TOP:
|
||||||
y=-maxY / 2
|
y = -maxY / 2.0
|
||||||
direction = CONTROL_POINT_VERTICAL
|
direction = CONTROL_POINT_VERTICAL
|
||||||
elif self._handleSide == DIVISION_SIDE_RIGHT:
|
elif self._handleSide == DIVISION_SIDE_RIGHT:
|
||||||
x = maxX / 2
|
x = maxX / 2.0
|
||||||
direction = CONTROL_POINT_HORIZONTAL
|
direction = CONTROL_POINT_HORIZONTAL
|
||||||
elif self._handleSide == DIVISION_SIDE_BOTTOM:
|
elif self._handleSide == DIVISION_SIDE_BOTTOM:
|
||||||
y = maxY / 2
|
y = maxY / 2.0
|
||||||
direction = CONTROL_POINT_VERTICAL
|
direction = CONTROL_POINT_VERTICAL
|
||||||
|
|
||||||
if self._handleSide != DIVISION_SIDE_NONE:
|
if self._handleSide != DIVISION_SIDE_NONE:
|
||||||
@@ -1241,20 +1239,20 @@ class DivisionShape(CompositeShape):
|
|||||||
node = self._controlPoints[0]
|
node = self._controlPoints[0]
|
||||||
|
|
||||||
if self._handleSide == DIVISION_SIDE_LEFT and node:
|
if self._handleSide == DIVISION_SIDE_LEFT and node:
|
||||||
node._xoffset=-maxX / 2
|
node._xoffset = -maxX / 2.0
|
||||||
node._yoffset = 0.0
|
node._yoffset = 0.0
|
||||||
|
|
||||||
if self._handleSide == DIVISION_SIDE_TOP and node:
|
if self._handleSide == DIVISION_SIDE_TOP and node:
|
||||||
node._xoffset = 0.0
|
node._xoffset = 0.0
|
||||||
node._yoffset=-maxY / 2
|
node._yoffset = -maxY / 2.0
|
||||||
|
|
||||||
if self._handleSide == DIVISION_SIDE_RIGHT and node:
|
if self._handleSide == DIVISION_SIDE_RIGHT and node:
|
||||||
node._xoffset = maxX / 2
|
node._xoffset = maxX / 2.0
|
||||||
node._yoffset = 0.0
|
node._yoffset = 0.0
|
||||||
|
|
||||||
if self._handleSide == DIVISION_SIDE_BOTTOM and node:
|
if self._handleSide == DIVISION_SIDE_BOTTOM and node:
|
||||||
node._xoffset = 0.0
|
node._xoffset = 0.0
|
||||||
node._yoffset = maxY / 2
|
node._yoffset = maxY / 2.0
|
||||||
|
|
||||||
def AdjustLeft(self, left, test):
|
def AdjustLeft(self, left, test):
|
||||||
"""Adjust a side.
|
"""Adjust a side.
|
||||||
@@ -1262,7 +1260,7 @@ class DivisionShape(CompositeShape):
|
|||||||
Returns FALSE if it's not physically possible to adjust it to
|
Returns FALSE if it's not physically possible to adjust it to
|
||||||
this point.
|
this point.
|
||||||
"""
|
"""
|
||||||
x2 = self.GetX() + self.GetWidth() / 2
|
x2 = self.GetX() + self.GetWidth() / 2.0
|
||||||
|
|
||||||
if left >= x2:
|
if left >= x2:
|
||||||
return False
|
return False
|
||||||
@@ -1270,8 +1268,8 @@ class DivisionShape(CompositeShape):
|
|||||||
if test:
|
if test:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
newW = x2-left
|
newW = x2 - left
|
||||||
newX = left + newW / 2
|
newX = left + newW / 2.0
|
||||||
self.SetSize(newW, self.GetHeight())
|
self.SetSize(newW, self.GetHeight())
|
||||||
|
|
||||||
dc = wx.ClientDC(self.GetCanvas())
|
dc = wx.ClientDC(self.GetCanvas())
|
||||||
@@ -1286,7 +1284,7 @@ class DivisionShape(CompositeShape):
|
|||||||
Returns FALSE if it's not physically possible to adjust it to
|
Returns FALSE if it's not physically possible to adjust it to
|
||||||
this point.
|
this point.
|
||||||
"""
|
"""
|
||||||
y2 = self.GetY() + self.GetHeight() / 2
|
y2 = self.GetY() + self.GetHeight() / 2.0
|
||||||
|
|
||||||
if top >= y2:
|
if top >= y2:
|
||||||
return False
|
return False
|
||||||
@@ -1294,8 +1292,8 @@ class DivisionShape(CompositeShape):
|
|||||||
if test:
|
if test:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
newH = y2-top
|
newH = y2 - top
|
||||||
newY = top + newH / 2
|
newY = top + newH / 2.0
|
||||||
self.SetSize(self.GetWidth(), newH)
|
self.SetSize(self.GetWidth(), newH)
|
||||||
|
|
||||||
dc = wx.ClientDC(self.GetCanvas())
|
dc = wx.ClientDC(self.GetCanvas())
|
||||||
@@ -1310,7 +1308,7 @@ class DivisionShape(CompositeShape):
|
|||||||
Returns FALSE if it's not physically possible to adjust it to
|
Returns FALSE if it's not physically possible to adjust it to
|
||||||
this point.
|
this point.
|
||||||
"""
|
"""
|
||||||
x1 = self.GetX()-self.GetWidth() / 2
|
x1 = self.GetX() - self.GetWidth() / 2.0
|
||||||
|
|
||||||
if right <= x1:
|
if right <= x1:
|
||||||
return False
|
return False
|
||||||
@@ -1318,8 +1316,8 @@ class DivisionShape(CompositeShape):
|
|||||||
if test:
|
if test:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
newW = right-x1
|
newW = right - x1
|
||||||
newX = x1 + newW / 2
|
newX = x1 + newW / 2.0
|
||||||
self.SetSize(newW, self.GetHeight())
|
self.SetSize(newW, self.GetHeight())
|
||||||
|
|
||||||
dc = wx.ClientDC(self.GetCanvas())
|
dc = wx.ClientDC(self.GetCanvas())
|
||||||
@@ -1334,7 +1332,7 @@ class DivisionShape(CompositeShape):
|
|||||||
Returns FALSE if it's not physically possible to adjust it to
|
Returns FALSE if it's not physically possible to adjust it to
|
||||||
this point.
|
this point.
|
||||||
"""
|
"""
|
||||||
y1 = self.GetY()-self.GetHeight() / 2
|
y1 = self.GetY() - self.GetHeight() / 2.0
|
||||||
|
|
||||||
if bottom <= y1:
|
if bottom <= y1:
|
||||||
return False
|
return False
|
||||||
@@ -1342,8 +1340,8 @@ class DivisionShape(CompositeShape):
|
|||||||
if test:
|
if test:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
newH = bottom-y1
|
newH = bottom - y1
|
||||||
newY = y1 + newH / 2
|
newY = y1 + newH / 2.0
|
||||||
self.SetSize(self.GetWidth(), newH)
|
self.SetSize(self.GetWidth(), newH)
|
||||||
|
|
||||||
dc = wx.ClientDC(self.GetCanvas())
|
dc = wx.ClientDC(self.GetCanvas())
|
||||||
@@ -1422,8 +1420,8 @@ class DivisionShape(CompositeShape):
|
|||||||
dc = wx.ClientDC(self.GetCanvas())
|
dc = wx.ClientDC(self.GetCanvas())
|
||||||
self.GetCanvas().PrepareDC(dc)
|
self.GetCanvas().PrepareDC(dc)
|
||||||
|
|
||||||
mouse_x = dc.LogicalToDeviceX(x-x1 * unit_x)
|
mouse_x = dc.LogicalToDeviceX(x - x1 * unit_x)
|
||||||
mouse_y = dc.LogicalToDeviceY(y-y1 * unit_y)
|
mouse_y = dc.LogicalToDeviceY(y - y1 * unit_y)
|
||||||
|
|
||||||
self._canvas.PopupMenu(menu, (mouse_x, mouse_y))
|
self._canvas.PopupMenu(menu, (mouse_x, mouse_y))
|
||||||
|
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
DEFAULT_MOUSE_TOLERANCE = 3
|
DEFAULT_MOUSE_TOLERANCE = 3
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
@@ -37,9 +35,9 @@ class DividedShapeControlPoint(ControlPoint):
|
|||||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
|
|
||||||
dividedObject = self._shape
|
dividedObject = self._shape
|
||||||
x1 = dividedObject.GetX()-dividedObject.GetWidth() / 2
|
x1 = dividedObject.GetX() - dividedObject.GetWidth() / 2.0
|
||||||
y1 = y
|
y1 = y
|
||||||
x2 = dividedObject.GetX() + dividedObject.GetWidth() / 2
|
x2 = dividedObject.GetX() + dividedObject.GetWidth() / 2.0
|
||||||
y2 = y
|
y2 = y
|
||||||
|
|
||||||
dc.DrawLine(x1, y1, x2, y2)
|
dc.DrawLine(x1, y1, x2, y2)
|
||||||
@@ -55,9 +53,9 @@ class DividedShapeControlPoint(ControlPoint):
|
|||||||
|
|
||||||
dividedObject = self._shape
|
dividedObject = self._shape
|
||||||
|
|
||||||
x1 = dividedObject.GetX()-dividedObject.GetWidth() / 2
|
x1 = dividedObject.GetX() - dividedObject.GetWidth() / 2.0
|
||||||
y1 = y
|
y1 = y
|
||||||
x2 = dividedObject.GetX() + dividedObject.GetWidth() / 2
|
x2 = dividedObject.GetX() + dividedObject.GetWidth() / 2.0
|
||||||
y2 = y
|
y2 = y
|
||||||
|
|
||||||
dc.DrawLine(x1, y1, x2, y2)
|
dc.DrawLine(x1, y1, x2, y2)
|
||||||
@@ -82,8 +80,8 @@ class DividedShapeControlPoint(ControlPoint):
|
|||||||
# Find the old top and bottom of this region,
|
# Find the old top and bottom of this region,
|
||||||
# and calculate the new proportion for this region
|
# and calculate the new proportion for this region
|
||||||
# if legal.
|
# if legal.
|
||||||
currentY = dividedObject.GetY()-dividedObject.GetHeight() / 2
|
currentY = dividedObject.GetY() - dividedObject.GetHeight() / 2.0
|
||||||
maxY = dividedObject.GetY() + dividedObject.GetHeight() / 2
|
maxY = dividedObject.GetY() + dividedObject.GetHeight() / 2.0
|
||||||
|
|
||||||
# Save values
|
# Save values
|
||||||
theRegionTop = 0
|
theRegionTop = 0
|
||||||
@@ -98,7 +96,7 @@ class DividedShapeControlPoint(ControlPoint):
|
|||||||
if region == thisRegion:
|
if region == thisRegion:
|
||||||
thisRegionTop = currentY
|
thisRegionTop = currentY
|
||||||
|
|
||||||
if i + 1<len(dividedObject.GetRegions()):
|
if i + 1 < len(dividedObject.GetRegions()):
|
||||||
nextRegion = dividedObject.GetRegions()[i + 1]
|
nextRegion = dividedObject.GetRegions()[i + 1]
|
||||||
if region == nextRegion:
|
if region == nextRegion:
|
||||||
nextRegionBottom = actualY
|
nextRegionBottom = actualY
|
||||||
@@ -116,12 +114,12 @@ class DividedShapeControlPoint(ControlPoint):
|
|||||||
dividedObject.EraseLinks(dc)
|
dividedObject.EraseLinks(dc)
|
||||||
|
|
||||||
# Now calculate the new proportions of this region and the next region
|
# Now calculate the new proportions of this region and the next region
|
||||||
thisProportion = (y-thisRegionTop) / dividedObject.GetHeight()
|
thisProportion = float(y - thisRegionTop) / dividedObject.GetHeight()
|
||||||
nextProportion = (nextRegionBottom-y) / dividedObject.GetHeight()
|
nextProportion = float(nextRegionBottom - y) / dividedObject.GetHeight()
|
||||||
|
|
||||||
thisRegion.SetProportions(0, thisProportion)
|
thisRegion.SetProportions(0, thisProportion)
|
||||||
nextRegion.SetProportions(0, nextProportion)
|
nextRegion.SetProportions(0, nextProportion)
|
||||||
self._yoffset = y-dividedObject.GetY()
|
self._yoffset = y - dividedObject.GetY()
|
||||||
|
|
||||||
# Now reformat text
|
# Now reformat text
|
||||||
for i, region in enumerate(dividedObject.GetRegions()):
|
for i, region in enumerate(dividedObject.GetRegions()):
|
||||||
@@ -152,14 +150,14 @@ class DividedShape(RectangleShape):
|
|||||||
|
|
||||||
def OnDrawContents(self, dc):
|
def OnDrawContents(self, dc):
|
||||||
if self.GetRegions():
|
if self.GetRegions():
|
||||||
defaultProportion = 1 / len(self.GetRegions())
|
defaultProportion = 1.0 / len(self.GetRegions())
|
||||||
else:
|
else:
|
||||||
defaultProportion = 0
|
defaultProportion = 0.0
|
||||||
currentY = self._ypos-self._height / 2
|
currentY = self._ypos - self._height / 2.0
|
||||||
maxY = self._ypos + self._height / 2
|
maxY = self._ypos + self._height / 2.0
|
||||||
|
|
||||||
leftX = self._xpos-self._width / 2
|
leftX = self._xpos - self._width / 2.0
|
||||||
rightX = self._xpos + self._width / 2
|
rightX = self._xpos + self._width / 2.0
|
||||||
|
|
||||||
if self._pen:
|
if self._pen:
|
||||||
dc.SetPen(self._pen)
|
dc.SetPen(self._pen)
|
||||||
@@ -168,7 +166,7 @@ class DividedShape(RectangleShape):
|
|||||||
|
|
||||||
# For efficiency, don't do this under X - doesn't make
|
# For efficiency, don't do this under X - doesn't make
|
||||||
# any visible difference for our purposes.
|
# any visible difference for our purposes.
|
||||||
if sys.platform[:3]=="win":
|
if sys.platform[:3] == "win":
|
||||||
dc.SetTextBackground(self._brush.GetColour())
|
dc.SetTextBackground(self._brush.GetColour())
|
||||||
|
|
||||||
if self.GetDisableLabel():
|
if self.GetDisableLabel():
|
||||||
@@ -183,7 +181,7 @@ class DividedShape(RectangleShape):
|
|||||||
dc.SetFont(region.GetFont())
|
dc.SetFont(region.GetFont())
|
||||||
dc.SetTextForeground(region.GetActualColourObject())
|
dc.SetTextForeground(region.GetActualColourObject())
|
||||||
|
|
||||||
if region._regionProportionY<0:
|
if region._regionProportionY < 0:
|
||||||
proportion = defaultProportion
|
proportion = defaultProportion
|
||||||
else:
|
else:
|
||||||
proportion = region._regionProportionY
|
proportion = region._regionProportionY
|
||||||
@@ -192,9 +190,9 @@ class DividedShape(RectangleShape):
|
|||||||
actualY = min(maxY, y)
|
actualY = min(maxY, y)
|
||||||
|
|
||||||
centreX = self._xpos
|
centreX = self._xpos
|
||||||
centreY = currentY + (actualY-currentY) / 2
|
centreY = currentY + (actualY - currentY) / 2.0
|
||||||
|
|
||||||
DrawFormattedText(dc, region._formattedText, centreX, centreY, self._width-2 * xMargin, actualY-currentY-2 * yMargin, region._formatMode)
|
DrawFormattedText(dc, region._formattedText, centreX, centreY, self._width - 2 * xMargin, actualY - currentY - 2 * yMargin, region._formatMode)
|
||||||
|
|
||||||
if y <= maxY and region != self.GetRegions()[-1]:
|
if y <= maxY and region != self.GetRegions()[-1]:
|
||||||
regionPen = region.GetActualPen()
|
regionPen = region.GetActualPen()
|
||||||
@@ -218,11 +216,11 @@ class DividedShape(RectangleShape):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.GetRegions():
|
if self.GetRegions():
|
||||||
defaultProportion = 1 / len(self.GetRegions())
|
defaultProportion = 1.0 / len(self.GetRegions())
|
||||||
else:
|
else:
|
||||||
defaultProportion = 0
|
defaultProportion = 0.0
|
||||||
currentY = self._ypos-self._height / 2
|
currentY = self._ypos - self._height / 2.0
|
||||||
maxY = self._ypos + self._height / 2
|
maxY = self._ypos + self._height / 2.0
|
||||||
|
|
||||||
for region in self.GetRegions():
|
for region in self.GetRegions():
|
||||||
if region._regionProportionY <= 0:
|
if region._regionProportionY <= 0:
|
||||||
@@ -234,10 +232,10 @@ class DividedShape(RectangleShape):
|
|||||||
y = currentY + sizeY
|
y = currentY + sizeY
|
||||||
actualY = min(maxY, y)
|
actualY = min(maxY, y)
|
||||||
|
|
||||||
centreY = currentY + (actualY-currentY) / 2
|
centreY = currentY + (actualY - currentY) / 2.0
|
||||||
|
|
||||||
region.SetSize(self._width, sizeY)
|
region.SetSize(self._width, sizeY)
|
||||||
region.SetPosition(0, centreY-self._ypos)
|
region.SetPosition(0, centreY - self._ypos)
|
||||||
|
|
||||||
currentY = actualY
|
currentY = actualY
|
||||||
|
|
||||||
@@ -250,10 +248,10 @@ class DividedShape(RectangleShape):
|
|||||||
n = len(self.GetRegions())
|
n = len(self.GetRegions())
|
||||||
isEnd = line and line.IsEnd(self)
|
isEnd = line and line.IsEnd(self)
|
||||||
|
|
||||||
left = self._xpos-self._width / 2
|
left = self._xpos - self._width / 2.0
|
||||||
right = self._xpos + self._width / 2
|
right = self._xpos + self._width / 2.0
|
||||||
top = self._ypos-self._height / 2
|
top = self._ypos - self._height / 2.0
|
||||||
bottom = self._ypos + self._height / 2
|
bottom = self._ypos + self._height / 2.0
|
||||||
|
|
||||||
# Zero is top, n + 1 is bottom
|
# Zero is top, n + 1 is bottom
|
||||||
if attachment == 0:
|
if attachment == 0:
|
||||||
@@ -262,14 +260,14 @@ class DividedShape(RectangleShape):
|
|||||||
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
||||||
# Align line according to the next handle along
|
# Align line according to the next handle along
|
||||||
point = line.GetNextControlPoint(self)
|
point = line.GetNextControlPoint(self)
|
||||||
if point.x<left:
|
if point.x < left:
|
||||||
x = left
|
x = left
|
||||||
elif point.x>right:
|
elif point.x > right:
|
||||||
x = right
|
x = right
|
||||||
else:
|
else:
|
||||||
x = point.x
|
x = point.x
|
||||||
else:
|
else:
|
||||||
x = left + (nth + 1) * self._width / (no_arcs + 1)
|
x = left + (nth + 1) * self._width / (no_arcs + 1.0)
|
||||||
else:
|
else:
|
||||||
x = self._xpos
|
x = self._xpos
|
||||||
elif attachment == n + 1:
|
elif attachment == n + 1:
|
||||||
@@ -278,22 +276,22 @@ class DividedShape(RectangleShape):
|
|||||||
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
||||||
# Align line according to the next handle along
|
# Align line according to the next handle along
|
||||||
point = line.GetNextControlPoint(self)
|
point = line.GetNextControlPoint(self)
|
||||||
if point.x<left:
|
if point.x < left:
|
||||||
x = left
|
x = left
|
||||||
elif point.x>right:
|
elif point.x > right:
|
||||||
x = right
|
x = right
|
||||||
else:
|
else:
|
||||||
x = point.x
|
x = point.x
|
||||||
else:
|
else:
|
||||||
x = left + (nth + 1) * self._width / (no_arcs + 1)
|
x = left + (nth + 1) * self._width / (no_arcs + 1.0)
|
||||||
else:
|
else:
|
||||||
x = self._xpos
|
x = self._xpos
|
||||||
else: # Left or right
|
else: # Left or right
|
||||||
isLeft = not attachment<(n + 1)
|
isLeft = not attachment < (n + 1)
|
||||||
if isLeft:
|
if isLeft:
|
||||||
i = totalNumberAttachments-attachment-1
|
i = totalNumberAttachments - attachment - 1
|
||||||
else:
|
else:
|
||||||
i = attachment-1
|
i = attachment - 1
|
||||||
|
|
||||||
region = self.GetRegions()[i]
|
region = self.GetRegions()[i]
|
||||||
if region:
|
if region:
|
||||||
@@ -303,8 +301,8 @@ class DividedShape(RectangleShape):
|
|||||||
x = right
|
x = right
|
||||||
|
|
||||||
# Calculate top and bottom of region
|
# Calculate top and bottom of region
|
||||||
top = self._ypos + region._y-region._height / 2
|
top = self._ypos + region._y - region._height / 2.0
|
||||||
bottom = self._ypos + region._y + region._height / 2
|
bottom = self._ypos + region._y + region._height / 2.0
|
||||||
|
|
||||||
# Assuming we can trust the absolute size and
|
# Assuming we can trust the absolute size and
|
||||||
# position of these regions
|
# position of these regions
|
||||||
@@ -312,14 +310,14 @@ class DividedShape(RectangleShape):
|
|||||||
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
if line and line.GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE:
|
||||||
# Align line according to the next handle along
|
# Align line according to the next handle along
|
||||||
point = line.GetNextControlPoint(self)
|
point = line.GetNextControlPoint(self)
|
||||||
if point.y<bottom:
|
if point.y < bottom:
|
||||||
y = bottom
|
y = bottom
|
||||||
elif point.y>top:
|
elif point.y > top:
|
||||||
y = top
|
y = top
|
||||||
else:
|
else:
|
||||||
y = point.y
|
y = point.y
|
||||||
else:
|
else:
|
||||||
y = top + (nth + 1) * region._height / (no_arcs + 1)
|
y = top + (nth + 1) * region._height / (no_arcs + 1.0)
|
||||||
else:
|
else:
|
||||||
y = self._ypos + region._y
|
y = self._ypos + region._y
|
||||||
else:
|
else:
|
||||||
@@ -331,9 +329,9 @@ class DividedShape(RectangleShape):
|
|||||||
# plus one on the top and one on the bottom.
|
# plus one on the top and one on the bottom.
|
||||||
n = len(self.GetRegions()) * 2 + 2
|
n = len(self.GetRegions()) * 2 + 2
|
||||||
|
|
||||||
maxN = n-1
|
maxN = n - 1
|
||||||
for point in self._attachmentPoints:
|
for point in self._attachmentPoints:
|
||||||
if point._id>maxN:
|
if point._id > maxN:
|
||||||
maxN = point._id
|
maxN = point._id
|
||||||
|
|
||||||
return maxN + 1
|
return maxN + 1
|
||||||
@@ -350,8 +348,8 @@ class DividedShape(RectangleShape):
|
|||||||
self.MakeMandatoryControlPoints()
|
self.MakeMandatoryControlPoints()
|
||||||
|
|
||||||
def MakeMandatoryControlPoints(self):
|
def MakeMandatoryControlPoints(self):
|
||||||
currentY = self.GetY()-self._height / 2
|
currentY = self.GetY() - self._height / 2.0
|
||||||
maxY = self.GetY() + self._height / 2
|
maxY = self.GetY() + self._height / 2.0
|
||||||
|
|
||||||
for i, region in enumerate(self.GetRegions()):
|
for i, region in enumerate(self.GetRegions()):
|
||||||
proportion = region._regionProportionY
|
proportion = region._regionProportionY
|
||||||
@@ -360,7 +358,7 @@ class DividedShape(RectangleShape):
|
|||||||
actualY = min(maxY, y)
|
actualY = min(maxY, y)
|
||||||
|
|
||||||
if region != self.GetRegions()[-1]:
|
if region != self.GetRegions()[-1]:
|
||||||
controlPoint = DividedShapeControlPoint(self._canvas, self, i, CONTROL_POINT_SIZE, 0, actualY-self.GetY(), 0)
|
controlPoint = DividedShapeControlPoint(self._canvas, self, i, CONTROL_POINT_SIZE, 0, actualY - self.GetY(), 0)
|
||||||
self._canvas.AddShape(controlPoint)
|
self._canvas.AddShape(controlPoint)
|
||||||
self._controlPoints.append(controlPoint)
|
self._controlPoints.append(controlPoint)
|
||||||
|
|
||||||
@@ -368,14 +366,14 @@ class DividedShape(RectangleShape):
|
|||||||
|
|
||||||
def ResetControlPoints(self):
|
def ResetControlPoints(self):
|
||||||
# May only have the region handles, (n - 1) of them
|
# May only have the region handles, (n - 1) of them
|
||||||
if len(self._controlPoints)>len(self.GetRegions())-1:
|
if len(self._controlPoints) > len(self.GetRegions()) - 1:
|
||||||
RectangleShape.ResetControlPoints(self)
|
RectangleShape.ResetControlPoints(self)
|
||||||
|
|
||||||
self.ResetMandatoryControlPoints()
|
self.ResetMandatoryControlPoints()
|
||||||
|
|
||||||
def ResetMandatoryControlPoints(self):
|
def ResetMandatoryControlPoints(self):
|
||||||
currentY = self.GetY()-self._height / 2
|
currentY = self.GetY() - self._height / 2.0
|
||||||
maxY = self.GetY() + self._height / 2
|
maxY = self.GetY() + self._height / 2.0
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for controlPoint in self._controlPoints:
|
for controlPoint in self._controlPoints:
|
||||||
@@ -387,7 +385,7 @@ class DividedShape(RectangleShape):
|
|||||||
actualY = min(maxY, y)
|
actualY = min(maxY, y)
|
||||||
|
|
||||||
controlPoint._xoffset = 0
|
controlPoint._xoffset = 0
|
||||||
controlPoint._yoffset = actualY-self.GetY()
|
controlPoint._yoffset = actualY - self.GetY()
|
||||||
|
|
||||||
currentY = actualY
|
currentY = actualY
|
||||||
|
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import math
|
import math
|
||||||
|
|
||||||
@@ -21,10 +19,10 @@ from _oglmisc import *
|
|||||||
|
|
||||||
# Line alignment flags
|
# Line alignment flags
|
||||||
# Vertical by default
|
# Vertical by default
|
||||||
LINE_ALIGNMENT_HORIZ= 1
|
LINE_ALIGNMENT_HORIZ = 1
|
||||||
LINE_ALIGNMENT_VERT= 0
|
LINE_ALIGNMENT_VERT = 0
|
||||||
LINE_ALIGNMENT_TO_NEXT_HANDLE= 2
|
LINE_ALIGNMENT_TO_NEXT_HANDLE = 2
|
||||||
LINE_ALIGNMENT_NONE= 0
|
LINE_ALIGNMENT_NONE = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -53,7 +51,7 @@ class LineControlPoint(ControlPoint):
|
|||||||
|
|
||||||
|
|
||||||
class ArrowHead(object):
|
class ArrowHead(object):
|
||||||
def __init__(self, type = 0, end = 0, size = 0.0, dist = 0.0, name="",mf = None, arrowId=-1):
|
def __init__(self, type = 0, end = 0, size = 0.0, dist = 0.0, name = "", mf = None, arrowId = -1):
|
||||||
if isinstance(type, ArrowHead):
|
if isinstance(type, ArrowHead):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -67,7 +65,7 @@ class ArrowHead(object):
|
|||||||
self._arrowName = name
|
self._arrowName = name
|
||||||
self._metaFile = mf
|
self._metaFile = mf
|
||||||
self._id = arrowId
|
self._id = arrowId
|
||||||
if self._id==-1:
|
if self._id == -1:
|
||||||
self._id = wx.NewId()
|
self._id = wx.NewId()
|
||||||
|
|
||||||
def _GetType(self):
|
def _GetType(self):
|
||||||
@@ -98,7 +96,7 @@ class ArrowHead(object):
|
|||||||
if oldWidth == 0:
|
if oldWidth == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
scale = size / oldWidth
|
scale = float(size) / oldWidth
|
||||||
if scale != 1:
|
if scale != 1:
|
||||||
self._metaFile.Scale(scale, scale)
|
self._metaFile.Scale(scale, scale)
|
||||||
|
|
||||||
@@ -139,8 +137,8 @@ class LabelShape(RectangleShape):
|
|||||||
if self._lineShape and not self._lineShape.GetDrawHandles():
|
if self._lineShape and not self._lineShape.GetDrawHandles():
|
||||||
return
|
return
|
||||||
|
|
||||||
x1 = self._xpos-self._width / 2
|
x1 = self._xpos - self._width / 2.0
|
||||||
y1 = self._ypos-self._height / 2
|
y1 = self._ypos - self._height / 2.0
|
||||||
|
|
||||||
if self._pen:
|
if self._pen:
|
||||||
if self._pen.GetWidth() == 0:
|
if self._pen.GetWidth() == 0:
|
||||||
@@ -149,7 +147,7 @@ class LabelShape(RectangleShape):
|
|||||||
dc.SetPen(self._pen)
|
dc.SetPen(self._pen)
|
||||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
|
|
||||||
if self._cornerRadius>0:
|
if self._cornerRadius > 0:
|
||||||
dc.DrawRoundedRectangle(x1, y1, self._width, self._height, self._cornerRadius)
|
dc.DrawRoundedRectangle(x1, y1, self._width, self._height, self._cornerRadius)
|
||||||
else:
|
else:
|
||||||
dc.DrawRectangle(x1, y1, self._width, self._height)
|
dc.DrawRectangle(x1, y1, self._width, self._height)
|
||||||
@@ -296,7 +294,7 @@ class LineShape(Shape):
|
|||||||
self._lineControlPoints = []
|
self._lineControlPoints = []
|
||||||
|
|
||||||
for _ in range(n):
|
for _ in range(n):
|
||||||
point = wx.RealPoint(-999,-999)
|
point = wx.RealPoint(-999, -999)
|
||||||
self._lineControlPoints.append(point)
|
self._lineControlPoints.append(point)
|
||||||
|
|
||||||
def InsertLineControlPoint(self, dc = None):
|
def InsertLineControlPoint(self, dc = None):
|
||||||
@@ -307,15 +305,15 @@ class LineShape(Shape):
|
|||||||
last_point = self._lineControlPoints[-1]
|
last_point = self._lineControlPoints[-1]
|
||||||
second_last_point = self._lineControlPoints[-2]
|
second_last_point = self._lineControlPoints[-2]
|
||||||
|
|
||||||
line_x = (last_point[0] + second_last_point[0]) / 2
|
line_x = (last_point[0] + second_last_point[0]) / 2.0
|
||||||
line_y = (last_point[1] + second_last_point[1]) / 2
|
line_y = (last_point[1] + second_last_point[1]) / 2.0
|
||||||
|
|
||||||
point = wx.RealPoint(line_x, line_y)
|
point = wx.RealPoint(line_x, line_y)
|
||||||
self._lineControlPoints.insert(len(self._lineControlPoints), point)
|
self._lineControlPoints.insert(len(self._lineControlPoints), point)
|
||||||
|
|
||||||
def DeleteLineControlPoint(self):
|
def DeleteLineControlPoint(self):
|
||||||
"""Delete an arbitary point on the line."""
|
"""Delete an arbitary point on the line."""
|
||||||
if len(self._lineControlPoints)<3:
|
if len(self._lineControlPoints) < 3:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
del self._lineControlPoints[-2]
|
del self._lineControlPoints[-2]
|
||||||
@@ -333,21 +331,21 @@ class LineShape(Shape):
|
|||||||
# and the last.
|
# and the last.
|
||||||
|
|
||||||
for point in self._lineControlPoints[1:]:
|
for point in self._lineControlPoints[1:]:
|
||||||
if point[0]==-999:
|
if point[0] == -999:
|
||||||
if first_point[0]<last_point[0]:
|
if first_point[0] < last_point[0]:
|
||||||
x1 = first_point[0]
|
x1 = first_point[0]
|
||||||
x2 = last_point[0]
|
x2 = last_point[0]
|
||||||
else:
|
else:
|
||||||
x2 = first_point[0]
|
x2 = first_point[0]
|
||||||
x1 = last_point[0]
|
x1 = last_point[0]
|
||||||
if first_point[1]<last_point[1]:
|
if first_point[1] < last_point[1]:
|
||||||
y1 = first_point[1]
|
y1 = first_point[1]
|
||||||
y2 = last_point[1]
|
y2 = last_point[1]
|
||||||
else:
|
else:
|
||||||
y2 = first_point[1]
|
y2 = first_point[1]
|
||||||
y1 = last_point[1]
|
y1 = last_point[1]
|
||||||
point[0] = (x2-x1) / 2 + x1
|
point[0] = (x2 - x1) / 2.0 + x1
|
||||||
point[1] = (y2-y1) / 2 + y1
|
point[1] = (y2 - y1) / 2.0 + y1
|
||||||
|
|
||||||
def FormatText(self, dc, s, i):
|
def FormatText(self, dc, s, i):
|
||||||
"""Format a text string according to the region size, adding
|
"""Format a text string according to the region size, adding
|
||||||
@@ -368,7 +366,7 @@ class LineShape(Shape):
|
|||||||
w, h = 100, 50
|
w, h = 100, 50
|
||||||
region.SetSize(w, h)
|
region.SetSize(w, h)
|
||||||
|
|
||||||
string_list = FormatText(dc, s, w-5, h-5, region.GetFormatMode())
|
string_list = FormatText(dc, s, w - 5, h - 5, region.GetFormatMode())
|
||||||
for s in string_list:
|
for s in string_list:
|
||||||
line = ShapeTextLine(0.0, 0.0, s)
|
line = ShapeTextLine(0.0, 0.0, s)
|
||||||
region.GetFormattedText().append(line)
|
region.GetFormattedText().append(line)
|
||||||
@@ -380,14 +378,14 @@ class LineShape(Shape):
|
|||||||
if actualW != w or actualH != h:
|
if actualW != w or actualH != h:
|
||||||
xx, yy = self.GetLabelPosition(i)
|
xx, yy = self.GetLabelPosition(i)
|
||||||
self.EraseRegion(dc, region, xx, yy)
|
self.EraseRegion(dc, region, xx, yy)
|
||||||
if len(self._labelObjects)<i:
|
if len(self._labelObjects) < i:
|
||||||
self._labelObjects[i].Select(False, dc)
|
self._labelObjects[i].Select(False, dc)
|
||||||
self._labelObjects[i].Erase(dc)
|
self._labelObjects[i].Erase(dc)
|
||||||
self._labelObjects[i].SetSize(actualW, actualH)
|
self._labelObjects[i].SetSize(actualW, actualH)
|
||||||
|
|
||||||
region.SetSize(actualW, actualH)
|
region.SetSize(actualW, actualH)
|
||||||
|
|
||||||
if len(self._labelObjects)<i:
|
if len(self._labelObjects) < i:
|
||||||
self._labelObjects[i].Select(True, dc)
|
self._labelObjects[i].Select(True, dc)
|
||||||
self._labelObjects[i].Draw(dc)
|
self._labelObjects[i].Draw(dc)
|
||||||
|
|
||||||
@@ -415,7 +413,7 @@ class LineShape(Shape):
|
|||||||
# Now draw the text
|
# Now draw the text
|
||||||
if region.GetFont():
|
if region.GetFont():
|
||||||
dc.SetFont(region.GetFont())
|
dc.SetFont(region.GetFont())
|
||||||
dc.DrawRectangle(xp-w / 2, yp-h / 2, w, h)
|
dc.DrawRectangle(xp - w / 2.0, yp - h / 2.0, w, h)
|
||||||
|
|
||||||
if self._pen:
|
if self._pen:
|
||||||
dc.SetPen(self._pen)
|
dc.SetPen(self._pen)
|
||||||
@@ -440,7 +438,7 @@ class LineShape(Shape):
|
|||||||
dc.SetPen(self.GetBackgroundPen())
|
dc.SetPen(self.GetBackgroundPen())
|
||||||
dc.SetBrush(self.GetBackgroundBrush())
|
dc.SetBrush(self.GetBackgroundBrush())
|
||||||
|
|
||||||
dc.DrawRectangle(xp-w / 2, yp-h / 2, w, h)
|
dc.DrawRectangle(xp - w / 2.0, yp - h / 2.0, w, h)
|
||||||
|
|
||||||
def GetLabelPosition(self, position):
|
def GetLabelPosition(self, position):
|
||||||
"""Get the reference point for a label.
|
"""Get the reference point for a label.
|
||||||
@@ -450,16 +448,16 @@ class LineShape(Shape):
|
|||||||
"""
|
"""
|
||||||
if position == 0:
|
if position == 0:
|
||||||
# Want to take the middle section for the label
|
# Want to take the middle section for the label
|
||||||
half_way = int(len(self._lineControlPoints) / 2)
|
half_way = int(len(self._lineControlPoints) / 2.0)
|
||||||
|
|
||||||
# Find middle of this line
|
# Find middle of this line
|
||||||
point = self._lineControlPoints[half_way-1]
|
point = self._lineControlPoints[half_way - 1]
|
||||||
next_point = self._lineControlPoints[half_way]
|
next_point = self._lineControlPoints[half_way]
|
||||||
|
|
||||||
dx = next_point[0]-point[0]
|
dx = next_point[0] - point[0]
|
||||||
dy = next_point[1]-point[1]
|
dy = next_point[1] - point[1]
|
||||||
|
|
||||||
return point[0] + dx / 2, point[1] + dy / 2
|
return point[0] + dx / 2.0, point[1] + dy / 2.0
|
||||||
elif position == 1:
|
elif position == 1:
|
||||||
return self._lineControlPoints[0][0], self._lineControlPoints[0][1]
|
return self._lineControlPoints[0][0], self._lineControlPoints[0][1]
|
||||||
elif position == 2:
|
elif position == 2:
|
||||||
@@ -467,7 +465,7 @@ class LineShape(Shape):
|
|||||||
|
|
||||||
def Straighten(self, dc = None):
|
def Straighten(self, dc = None):
|
||||||
"""Straighten verticals and horizontals."""
|
"""Straighten verticals and horizontals."""
|
||||||
if len(self._lineControlPoints)<3:
|
if len(self._lineControlPoints) < 3:
|
||||||
return
|
return
|
||||||
|
|
||||||
if dc:
|
if dc:
|
||||||
@@ -475,7 +473,7 @@ class LineShape(Shape):
|
|||||||
|
|
||||||
GraphicsStraightenLine(self._lineControlPoints[-1], self._lineControlPoints[-2])
|
GraphicsStraightenLine(self._lineControlPoints[-1], self._lineControlPoints[-2])
|
||||||
|
|
||||||
for i in range(len(self._lineControlPoints)-2):
|
for i in range(len(self._lineControlPoints) - 2):
|
||||||
GraphicsStraightenLine(self._lineControlPoints[i], self._lineControlPoints[i + 1])
|
GraphicsStraightenLine(self._lineControlPoints[i], self._lineControlPoints[i + 1])
|
||||||
|
|
||||||
if dc:
|
if dc:
|
||||||
@@ -501,8 +499,8 @@ class LineShape(Shape):
|
|||||||
last_point[0] = x2
|
last_point[0] = x2
|
||||||
last_point[1] = y2
|
last_point[1] = y2
|
||||||
|
|
||||||
self._xpos = (x1 + x2) / 2
|
self._xpos = (x1 + x2) / 2.0
|
||||||
self._ypos = (y1 + y2) / 2
|
self._ypos = (y1 + y2) / 2.0
|
||||||
|
|
||||||
# Get absolute positions of ends
|
# Get absolute positions of ends
|
||||||
def GetEnds(self):
|
def GetEnds(self):
|
||||||
@@ -532,35 +530,35 @@ class LineShape(Shape):
|
|||||||
xp, yp = self.GetLabelPosition(i)
|
xp, yp = self.GetLabelPosition(i)
|
||||||
# Offset region from default label position
|
# Offset region from default label position
|
||||||
cx, cy = region.GetPosition()
|
cx, cy = region.GetPosition()
|
||||||
cw, ch = region.GetSize()
|
cw, ch = region.GetSize()
|
||||||
cx += xp
|
cx += xp
|
||||||
cy += yp
|
cy += yp
|
||||||
|
|
||||||
rLeft = cx-cw / 2
|
rLeft = cx - cw / 2.0
|
||||||
rTop = cy-ch / 2
|
rTop = cy - ch / 2.0
|
||||||
rRight = cx + cw / 2
|
rRight = cx + cw / 2.0
|
||||||
rBottom = cy + ch / 2
|
rBottom = cy + ch / 2.0
|
||||||
if x>rLeft and x<rRight and y>rTop and y<rBottom:
|
if x > rLeft and x < rRight and y > rTop and y < rBottom:
|
||||||
inLabelRegion = True
|
inLabelRegion = True
|
||||||
break
|
break
|
||||||
|
|
||||||
for i in range(len(self._lineControlPoints)-1):
|
for i in range(len(self._lineControlPoints) - 1):
|
||||||
point1 = self._lineControlPoints[i]
|
point1 = self._lineControlPoints[i]
|
||||||
point2 = self._lineControlPoints[i + 1]
|
point2 = self._lineControlPoints[i + 1]
|
||||||
|
|
||||||
# For inaccurate mousing allow 8 pixel corridor
|
# For inaccurate mousing allow 8 pixel corridor
|
||||||
extra = 4
|
extra = 4
|
||||||
|
|
||||||
dx = point2[0]-point1[0]
|
dx = point2[0] - point1[0]
|
||||||
dy = point2[1]-point1[1]
|
dy = point2[1] - point1[1]
|
||||||
|
|
||||||
seg_len = math.sqrt(dx * dx + dy * dy)
|
seg_len = math.sqrt(dx * dx + dy * dy)
|
||||||
if dy == 0 or dx == 0:
|
if dy == 0 or dx == 0:
|
||||||
return False
|
return False
|
||||||
distance_from_seg = seg_len * ((x-point1[0]) * dy-(y-point1[1]) * dx) / (dy * dy + dx * dx)
|
distance_from_seg = seg_len * float((x - point1[0]) * dy - (y - point1[1]) * dx) / (dy * dy + dx * dx)
|
||||||
distance_from_prev = seg_len * ((y-point1[1]) * dy + (x-point1[0]) * dx) / (dy * dy + dx * dx)
|
distance_from_prev = seg_len * float((y - point1[1]) * dy + (x - point1[0]) * dx) / (dy * dy + dx * dx)
|
||||||
|
|
||||||
if abs(distance_from_seg)<extra and distance_from_prev >= 0 and distance_from_prev <= seg_len or inLabelRegion:
|
if abs(distance_from_seg) < extra and distance_from_prev >= 0 and distance_from_prev <= seg_len or inLabelRegion:
|
||||||
return 0, distance_from_seg
|
return 0, distance_from_seg
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@@ -612,7 +610,7 @@ class LineShape(Shape):
|
|||||||
# will be on the line.
|
# will be on the line.
|
||||||
realOffset = XOffset
|
realOffset = XOffset
|
||||||
if proportionalOffset:
|
if proportionalOffset:
|
||||||
totalLength = math.sqrt((second_line_point[0]-first_line_point[0]) * (second_line_point[0]-first_line_point[0]) + (second_line_point[1]-first_line_point[1]) * (second_line_point[1]-first_line_point[1]))
|
totalLength = math.sqrt((second_line_point[0] - first_line_point[0]) * (second_line_point[0] - first_line_point[0]) + (second_line_point[1] - first_line_point[1]) * (second_line_point[1] - first_line_point[1]))
|
||||||
realOffset = XOffset * totalLength
|
realOffset = XOffset * totalLength
|
||||||
|
|
||||||
positionOnLineX, positionOnLineY = GetPointOnLine(second_line_point[0], second_line_point[1], first_line_point[0], first_line_point[1], realOffset)
|
positionOnLineX, positionOnLineY = GetPointOnLine(second_line_point[0], second_line_point[1], first_line_point[0], first_line_point[1], realOffset)
|
||||||
@@ -624,7 +622,7 @@ class LineShape(Shape):
|
|||||||
# will be on the line.
|
# will be on the line.
|
||||||
realOffset = XOffset
|
realOffset = XOffset
|
||||||
if proportionalOffset:
|
if proportionalOffset:
|
||||||
totalLength = math.sqrt((second_last_line_point[0]-last_line_point[0]) * (second_last_line_point[0]-last_line_point[0]) + (second_last_line_point[1]-last_line_point[1]) * (second_last_line_point[1]-last_line_point[1]));
|
totalLength = math.sqrt((second_last_line_point[0] - last_line_point[0]) * (second_last_line_point[0] - last_line_point[0]) + (second_last_line_point[1] - last_line_point[1]) * (second_last_line_point[1] - last_line_point[1]));
|
||||||
realOffset = XOffset * totalLength
|
realOffset = XOffset * totalLength
|
||||||
|
|
||||||
positionOnLineX, positionOnLineY = GetPointOnLine(second_last_line_point[0], second_last_line_point[1], last_line_point[0], last_line_point[1], realOffset)
|
positionOnLineX, positionOnLineY = GetPointOnLine(second_last_line_point[0], second_last_line_point[1], last_line_point[0], last_line_point[1], realOffset)
|
||||||
@@ -633,14 +631,14 @@ class LineShape(Shape):
|
|||||||
startPositionY = second_last_line_point[1]
|
startPositionY = second_last_line_point[1]
|
||||||
elif ap == ARROW_POSITION_MIDDLE:
|
elif ap == ARROW_POSITION_MIDDLE:
|
||||||
# Choose a point half way between the last and penultimate points
|
# Choose a point half way between the last and penultimate points
|
||||||
x = (last_line_point[0] + second_last_line_point[0]) / 2
|
x = (last_line_point[0] + second_last_line_point[0]) / 2.0
|
||||||
y = (last_line_point[1] + second_last_line_point[1]) / 2
|
y = (last_line_point[1] + second_last_line_point[1]) / 2.0
|
||||||
|
|
||||||
# If we're using a proportional offset, calculate just where this
|
# If we're using a proportional offset, calculate just where this
|
||||||
# will be on the line.
|
# will be on the line.
|
||||||
realOffset = XOffset
|
realOffset = XOffset
|
||||||
if proportionalOffset:
|
if proportionalOffset:
|
||||||
totalLength = math.sqrt((second_last_line_point[0]-x) * (second_last_line_point[0]-x) + (second_last_line_point[1]-y) * (second_last_line_point[1]-y));
|
totalLength = math.sqrt((second_last_line_point[0] - x) * (second_last_line_point[0] - x) + (second_last_line_point[1] - y) * (second_last_line_point[1] - y));
|
||||||
realOffset = XOffset * totalLength
|
realOffset = XOffset * totalLength
|
||||||
|
|
||||||
positionOnLineX, positionOnLineY = GetPointOnLine(second_last_line_point[0], second_last_line_point[1], x, y, realOffset)
|
positionOnLineX, positionOnLineY = GetPointOnLine(second_last_line_point[0], second_last_line_point[1], x, y, realOffset)
|
||||||
@@ -663,25 +661,25 @@ class LineShape(Shape):
|
|||||||
# Where theta = math.tan(-1) of (y3-y1) / (x3-x1)
|
# Where theta = math.tan(-1) of (y3-y1) / (x3-x1)
|
||||||
x1 = startPositionX
|
x1 = startPositionX
|
||||||
y1 = startPositionY
|
y1 = startPositionY
|
||||||
x3 = positionOnLineX
|
x3 = float(positionOnLineX)
|
||||||
y3 = positionOnLineY
|
y3 = float(positionOnLineY)
|
||||||
d=-arrow.GetYOffset() # Negate so +offset is above line
|
d = -arrow.GetYOffset() # Negate so +offset is above line
|
||||||
|
|
||||||
if x3 == x1:
|
if x3 == x1:
|
||||||
theta = math.pi / 2
|
theta = math.pi / 2.0
|
||||||
else:
|
else:
|
||||||
theta = math.atan((y3-y1) / (x3-x1))
|
theta = math.atan((y3 - y1) / (x3 - x1))
|
||||||
|
|
||||||
x4 = x3-d * math.sin(theta)
|
x4 = x3 - d * math.sin(theta)
|
||||||
y4 = y3 + d * math.cos(theta)
|
y4 = y3 + d * math.cos(theta)
|
||||||
|
|
||||||
deltaX = x4-positionOnLineX
|
deltaX = x4 - positionOnLineX
|
||||||
deltaY = y4-positionOnLineY
|
deltaY = y4 - positionOnLineY
|
||||||
|
|
||||||
at = arrow._GetType()
|
at = arrow._GetType()
|
||||||
if at == ARROW_ARROW:
|
if at == ARROW_ARROW:
|
||||||
arrowLength = arrow.GetSize()
|
arrowLength = arrow.GetSize()
|
||||||
arrowWidth = arrowLength / 3
|
arrowWidth = arrowLength / 3.0
|
||||||
|
|
||||||
tip_x, tip_y, side1_x, side1_y, side2_x, side2_y = GetArrowPoints(startPositionX + deltaX, startPositionY + deltaY, positionOnLineX + deltaX, positionOnLineY + deltaY, arrowLength, arrowWidth)
|
tip_x, tip_y, side1_x, side1_y, side2_x, side2_y = GetArrowPoints(startPositionX + deltaX, startPositionY + deltaY, positionOnLineX + deltaX, positionOnLineY + deltaY, arrowLength, arrowWidth)
|
||||||
|
|
||||||
@@ -699,9 +697,9 @@ class LineShape(Shape):
|
|||||||
diameter = arrow.GetSize()
|
diameter = arrow.GetSize()
|
||||||
x, y = GetPointOnLine(startPositionX + deltaX, startPositionY + deltaY,
|
x, y = GetPointOnLine(startPositionX + deltaX, startPositionY + deltaY,
|
||||||
positionOnLineX + deltaX, positionOnLineY + deltaY,
|
positionOnLineX + deltaX, positionOnLineY + deltaY,
|
||||||
diameter / 2)
|
diameter / 2.0)
|
||||||
x1 = x-diameter / 2
|
x1 = x - diameter / 2.0
|
||||||
y1 = y-diameter / 2
|
y1 = y - diameter / 2.0
|
||||||
dc.SetPen(self._pen)
|
dc.SetPen(self._pen)
|
||||||
if arrow._GetType() == ARROW_HOLLOW_CIRCLE:
|
if arrow._GetType() == ARROW_HOLLOW_CIRCLE:
|
||||||
dc.SetBrush(self.GetBackgroundBrush())
|
dc.SetBrush(self.GetBackgroundBrush())
|
||||||
@@ -724,7 +722,7 @@ class LineShape(Shape):
|
|||||||
#
|
#
|
||||||
x, y = GetPointOnLine(startPositionX, startPositionY,
|
x, y = GetPointOnLine(startPositionX, startPositionY,
|
||||||
positionOnLineX, positionOnLineY,
|
positionOnLineX, positionOnLineY,
|
||||||
arrow.GetMetaFile()._width / 2)
|
arrow.GetMetaFile()._width / 2.0)
|
||||||
# Calculate theta for rotating the metafile.
|
# Calculate theta for rotating the metafile.
|
||||||
#
|
#
|
||||||
# |
|
# |
|
||||||
@@ -738,21 +736,21 @@ class LineShape(Shape):
|
|||||||
theta = 0.0
|
theta = 0.0
|
||||||
x1 = startPositionX
|
x1 = startPositionX
|
||||||
y1 = startPositionY
|
y1 = startPositionY
|
||||||
x2 = positionOnLineX
|
x2 = float(positionOnLineX)
|
||||||
y2 = positionOnLineY
|
y2 = float(positionOnLineY)
|
||||||
|
|
||||||
if x1 == x2 and y1 == y2:
|
if x1 == x2 and y1 == y2:
|
||||||
theta = 0.0
|
theta = 0.0
|
||||||
elif x1 == x2 and y1>y2:
|
elif x1 == x2 and y1 > y2:
|
||||||
theta = 3.0 * math.pi / 2
|
theta = 3.0 * math.pi / 2.0
|
||||||
elif x1 == x2 and y2>y1:
|
elif x1 == x2 and y2 > y1:
|
||||||
theta = math.pi / 2
|
theta = math.pi / 2.0
|
||||||
elif x2>x1 and y2 >= y1:
|
elif x2 > x1 and y2 >= y1:
|
||||||
theta = math.atan((y2-y1) / (x2-x1))
|
theta = math.atan((y2 - y1) / (x2 - x1))
|
||||||
elif x2<x1:
|
elif x2 < x1:
|
||||||
theta = math.pi + math.atan((y2-y1) / (x2-x1))
|
theta = math.pi + math.atan((y2 - y1) / (x2 - x1))
|
||||||
elif x2>x1 and y2<y1:
|
elif x2 > x1 and y2 < y1:
|
||||||
theta = 2 * math.pi + math.atan((y2-y1) / (x2-x1))
|
theta = 2 * math.pi + math.atan((y2 - y1) / (x2 - x1))
|
||||||
else:
|
else:
|
||||||
raise "Unknown arrowhead rotation case"
|
raise "Unknown arrowhead rotation case"
|
||||||
|
|
||||||
@@ -766,7 +764,7 @@ class LineShape(Shape):
|
|||||||
minX, minY, maxX, maxY = arrow.GetMetaFile().GetBounds()
|
minX, minY, maxX, maxY = arrow.GetMetaFile().GetBounds()
|
||||||
# Make erasing rectangle slightly bigger or you get droppings
|
# Make erasing rectangle slightly bigger or you get droppings
|
||||||
extraPixels = 4
|
extraPixels = 4
|
||||||
dc.DrawRectangle(deltaX + x + minX-extraPixels / 2, deltaY + y + minY-extraPixels / 2, maxX-minX + extraPixels, maxY-minY + extraPixels)
|
dc.DrawRectangle(deltaX + x + minX - extraPixels / 2.0, deltaY + y + minY - extraPixels / 2.0, maxX - minX + extraPixels, maxY - minY + extraPixels)
|
||||||
else:
|
else:
|
||||||
arrow.GetMetaFile().Draw(dc, x + deltaX, y + deltaY)
|
arrow.GetMetaFile().Draw(dc, x + deltaX, y + deltaY)
|
||||||
|
|
||||||
@@ -795,8 +793,8 @@ class LineShape(Shape):
|
|||||||
|
|
||||||
# Drawing over the line only seems to work if the line has a thickness
|
# Drawing over the line only seems to work if the line has a thickness
|
||||||
# of 1.
|
# of 1.
|
||||||
if old_pen and old_pen.GetWidth()>1:
|
if old_pen and old_pen.GetWidth() > 1:
|
||||||
dc.DrawRectangle(self._xpos-bound_x / 2-2, self._ypos-bound_y / 2-2,
|
dc.DrawRectangle(self._xpos - bound_x / 2.0 - 2, self._ypos - bound_y / 2.0 - 2,
|
||||||
bound_x + 4, bound_y + 4)
|
bound_x + 4, bound_y + 4)
|
||||||
else:
|
else:
|
||||||
self._erasing = True
|
self._erasing = True
|
||||||
@@ -811,19 +809,19 @@ class LineShape(Shape):
|
|||||||
|
|
||||||
def GetBoundingBoxMin(self):
|
def GetBoundingBoxMin(self):
|
||||||
x1, y1 = 10000, 10000
|
x1, y1 = 10000, 10000
|
||||||
x2, y2=-10000,-10000
|
x2, y2 = -10000, -10000
|
||||||
|
|
||||||
for point in self._lineControlPoints:
|
for point in self._lineControlPoints:
|
||||||
if point[0]<x1:
|
if point[0] < x1:
|
||||||
x1 = point[0]
|
x1 = point[0]
|
||||||
if point[1]<y1:
|
if point[1] < y1:
|
||||||
y1 = point[1]
|
y1 = point[1]
|
||||||
if point[0]>x2:
|
if point[0] > x2:
|
||||||
x2 = point[0]
|
x2 = point[0]
|
||||||
if point[1]>y2:
|
if point[1] > y2:
|
||||||
y2 = point[1]
|
y2 = point[1]
|
||||||
|
|
||||||
return x2-x1, y2-y1
|
return x2 - x1, y2 - y1
|
||||||
|
|
||||||
# For a node image of interest, finds the position of this arc
|
# For a node image of interest, finds the position of this arc
|
||||||
# amongst all the arcs which are attached to THIS SIDE of the node image,
|
# amongst all the arcs which are attached to THIS SIDE of the node image,
|
||||||
@@ -834,7 +832,7 @@ class LineShape(Shape):
|
|||||||
Specify whether incoming or outgoing lines are being considered
|
Specify whether incoming or outgoing lines are being considered
|
||||||
with incoming.
|
with incoming.
|
||||||
"""
|
"""
|
||||||
n=-1
|
n = -1
|
||||||
num = 0
|
num = 0
|
||||||
|
|
||||||
if image == self._to:
|
if image == self._to:
|
||||||
@@ -884,8 +882,8 @@ class LineShape(Shape):
|
|||||||
self.SetBrush(None)
|
self.SetBrush(None)
|
||||||
|
|
||||||
def OnMovePre(self, dc, x, y, old_x, old_y, display = True):
|
def OnMovePre(self, dc, x, y, old_x, old_y, display = True):
|
||||||
x_offset = x-old_x
|
x_offset = x - old_x
|
||||||
y_offset = y-old_y
|
y_offset = y - old_y
|
||||||
|
|
||||||
if self._lineControlPoints and not (x_offset == 0 and y_offset == 0):
|
if self._lineControlPoints and not (x_offset == 0 and y_offset == 0):
|
||||||
for point in self._lineControlPoints:
|
for point in self._lineControlPoints:
|
||||||
@@ -897,7 +895,7 @@ class LineShape(Shape):
|
|||||||
if self._labelObjects[i]:
|
if self._labelObjects[i]:
|
||||||
self._labelObjects[i].Erase(dc)
|
self._labelObjects[i].Erase(dc)
|
||||||
xp, yp = self.GetLabelPosition(i)
|
xp, yp = self.GetLabelPosition(i)
|
||||||
if i<len(self._regions):
|
if i < len(self._regions):
|
||||||
xr, yr = self._regions[i].GetPosition()
|
xr, yr = self._regions[i].GetPosition()
|
||||||
else:
|
else:
|
||||||
xr, yr = 0, 0
|
xr, yr = 0, 0
|
||||||
@@ -911,7 +909,7 @@ class LineShape(Shape):
|
|||||||
if not self._from or not self._to:
|
if not self._from or not self._to:
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(self._lineControlPoints)>2:
|
if len(self._lineControlPoints) > 2:
|
||||||
self.Initialise()
|
self.Initialise()
|
||||||
|
|
||||||
# Do each end - nothing in the middle. User has to move other points
|
# Do each end - nothing in the middle. User has to move other points
|
||||||
@@ -930,8 +928,8 @@ class LineShape(Shape):
|
|||||||
self.SetEnds(end_x, end_y, other_end_x, other_end_y)
|
self.SetEnds(end_x, end_y, other_end_x, other_end_y)
|
||||||
|
|
||||||
# Try to move control points with the arc
|
# Try to move control points with the arc
|
||||||
x_offset = self._xpos-oldX
|
x_offset = self._xpos - oldX
|
||||||
y_offset = self._ypos-oldY
|
y_offset = self._ypos - oldY
|
||||||
|
|
||||||
# Only move control points if it's a self link. And only works
|
# Only move control points if it's a self link. And only works
|
||||||
# if attachment mode is ON
|
# if attachment mode is ON
|
||||||
@@ -957,7 +955,7 @@ class LineShape(Shape):
|
|||||||
second_point = self._lineControlPoints[1]
|
second_point = self._lineControlPoints[1]
|
||||||
second_last_point = self._lineControlPoints[-2]
|
second_last_point = self._lineControlPoints[-2]
|
||||||
|
|
||||||
if len(self._lineControlPoints)>2:
|
if len(self._lineControlPoints) > 2:
|
||||||
if self._from.GetAttachmentMode() != ATTACHMENT_MODE_NONE:
|
if self._from.GetAttachmentMode() != ATTACHMENT_MODE_NONE:
|
||||||
nth, no_arcs = self.FindNth(self._from, False) # Not incoming
|
nth, no_arcs = self.FindNth(self._from, False) # Not incoming
|
||||||
end_x, end_y = self._from.GetAttachmentPosition(self._attachmentFrom, nth, no_arcs, self)
|
end_x, end_y = self._from.GetAttachmentPosition(self._attachmentFrom, nth, no_arcs, self)
|
||||||
@@ -1015,7 +1013,7 @@ class LineShape(Shape):
|
|||||||
else:
|
else:
|
||||||
dc.DrawLines(points)
|
dc.DrawLines(points)
|
||||||
|
|
||||||
if sys.platform[:3]=="win":
|
if sys.platform[:3] == "win":
|
||||||
# For some reason, last point isn't drawn under Windows
|
# For some reason, last point isn't drawn under Windows
|
||||||
pt = points[-1]
|
pt = points[-1]
|
||||||
dc.DrawPoint(pt.x, pt.y)
|
dc.DrawPoint(pt.x, pt.y)
|
||||||
@@ -1256,7 +1254,7 @@ class LineShape(Shape):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def AddArrow(self, type, end = ARROW_POSITION_END, size = 10.0, xOffset = 0.0, name="",mf = None, arrowId=-1):
|
def AddArrow(self, type, end = ARROW_POSITION_END, size = 10.0, xOffset = 0.0, name = "", mf = None, arrowId = -1):
|
||||||
"""Add an arrow (or annotation) to the line.
|
"""Add an arrow (or annotation) to the line.
|
||||||
|
|
||||||
type may currently be one of:
|
type may currently be one of:
|
||||||
@@ -1326,7 +1324,7 @@ class LineShape(Shape):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
i1 = i2 = 0
|
i1 = i2 = 0
|
||||||
while i1<len(referenceList) and i2<len(self._arcArrows):
|
while i1 < len(referenceList) and i2 < len(self._arcArrows):
|
||||||
refArrow = referenceList[i1]
|
refArrow = referenceList[i1]
|
||||||
currArrow = self._arcArrows[i2]
|
currArrow = self._arcArrows[i2]
|
||||||
|
|
||||||
@@ -1337,7 +1335,7 @@ class LineShape(Shape):
|
|||||||
# Check if we're at the correct position in the
|
# Check if we're at the correct position in the
|
||||||
# reference list
|
# reference list
|
||||||
if targetName == refArrow.GetName():
|
if targetName == refArrow.GetName():
|
||||||
if i2<len(self._arcArrows):
|
if i2 < len(self._arcArrows):
|
||||||
self._arcArrows.insert(i2, arrow)
|
self._arcArrows.insert(i2, arrow)
|
||||||
else:
|
else:
|
||||||
self._arcArrows.append(arrow)
|
self._arcArrows.append(arrow)
|
||||||
@@ -1351,7 +1349,7 @@ class LineShape(Shape):
|
|||||||
"""Delete the arrows at the specified position, or at any position
|
"""Delete the arrows at the specified position, or at any position
|
||||||
if position is -1.
|
if position is -1.
|
||||||
"""
|
"""
|
||||||
if end==-1:
|
if end == -1:
|
||||||
self._arcArrows = []
|
self._arcArrows = []
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -1373,7 +1371,7 @@ class LineShape(Shape):
|
|||||||
if position is -1, matches any position.
|
if position is -1, matches any position.
|
||||||
"""
|
"""
|
||||||
for arrow in self._arcArrows:
|
for arrow in self._arcArrows:
|
||||||
if (position==-1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
|
if (position == -1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
|
||||||
return arow
|
return arow
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@@ -1392,7 +1390,7 @@ class LineShape(Shape):
|
|||||||
if position is -1, matches any position.
|
if position is -1, matches any position.
|
||||||
"""
|
"""
|
||||||
for arrow in self._arcArrows:
|
for arrow in self._arcArrows:
|
||||||
if (position==-1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
|
if (position == -1 or position == arrow.GetArrowEnd()) and arrow.GetName() == name:
|
||||||
self._arcArrows.remove(arrow)
|
self._arcArrows.remove(arrow)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@@ -1420,7 +1418,7 @@ class LineShape(Shape):
|
|||||||
# We have ABSOLUTE minimum now. So
|
# We have ABSOLUTE minimum now. So
|
||||||
# scale it to give it reasonable aesthetics
|
# scale it to give it reasonable aesthetics
|
||||||
# when drawing with line.
|
# when drawing with line.
|
||||||
if minWidth>0:
|
if minWidth > 0:
|
||||||
minWidth = minWidth * 1.4
|
minWidth = minWidth * 1.4
|
||||||
else:
|
else:
|
||||||
minWidth = 20.0
|
minWidth = 20.0
|
||||||
@@ -1438,13 +1436,13 @@ class LineShape(Shape):
|
|||||||
startX, startY, endX, endY = self.GetEnds()
|
startX, startY, endX, endY = self.GetEnds()
|
||||||
|
|
||||||
# Find distances from centre, start and end. The smallest wins
|
# Find distances from centre, start and end. The smallest wins
|
||||||
centreDistance = math.sqrt((x-self._xpos) * (x-self._xpos) + (y-self._ypos) * (y-self._ypos))
|
centreDistance = math.sqrt((x - self._xpos) * (x - self._xpos) + (y - self._ypos) * (y - self._ypos))
|
||||||
startDistance = math.sqrt((x-startX) * (x-startX) + (y-startY) * (y-startY))
|
startDistance = math.sqrt((x - startX) * (x - startX) + (y - startY) * (y - startY))
|
||||||
endDistance = math.sqrt((x-endX) * (x-endX) + (y-endY) * (y-endY))
|
endDistance = math.sqrt((x - endX) * (x - endX) + (y - endY) * (y - endY))
|
||||||
|
|
||||||
if centreDistance<startDistance and centreDistance<endDistance:
|
if centreDistance < startDistance and centreDistance < endDistance:
|
||||||
return ARROW_POSITION_MIDDLE
|
return ARROW_POSITION_MIDDLE
|
||||||
elif startDistance<endDistance:
|
elif startDistance < endDistance:
|
||||||
return ARROW_POSITION_START
|
return ARROW_POSITION_START
|
||||||
else:
|
else:
|
||||||
return ARROW_POSITION_END
|
return ARROW_POSITION_END
|
||||||
@@ -1495,10 +1493,10 @@ class LineShape(Shape):
|
|||||||
if self._to == shape:
|
if self._to == shape:
|
||||||
# Must be END of line, so we want (n - 1)th control point.
|
# Must be END of line, so we want (n - 1)th control point.
|
||||||
# But indexing ends at n-1, so subtract 2.
|
# But indexing ends at n-1, so subtract 2.
|
||||||
nn = n-2
|
nn = n - 2
|
||||||
else:
|
else:
|
||||||
nn = 1
|
nn = 1
|
||||||
if nn<len(self._lineControlPoints):
|
if nn < len(self._lineControlPoints):
|
||||||
return self._lineControlPoints[nn]
|
return self._lineControlPoints[nn]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -1520,7 +1518,7 @@ class LineShape(Shape):
|
|||||||
xx, yy = self.GetLabelPosition(i)
|
xx, yy = self.GetLabelPosition(i)
|
||||||
# Set the region's offset, relative to the default position for
|
# Set the region's offset, relative to the default position for
|
||||||
# each region.
|
# each region.
|
||||||
labelShape._shapeRegion.SetPosition(x-xx, y-yy)
|
labelShape._shapeRegion.SetPosition(x - xx, y - yy)
|
||||||
labelShape.SetX(x)
|
labelShape.SetX(x)
|
||||||
labelShape.SetY(y)
|
labelShape.SetY(y)
|
||||||
|
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
@@ -79,28 +78,28 @@ LINE_ALIGNMENT_NONE = 0
|
|||||||
# Interpret %n and 10 or 13 as a new line.
|
# Interpret %n and 10 or 13 as a new line.
|
||||||
def FormatText(dc, text, width, height, formatMode):
|
def FormatText(dc, text, width, height, formatMode):
|
||||||
i = 0
|
i = 0
|
||||||
word=""
|
word = ""
|
||||||
word_list = []
|
word_list = []
|
||||||
end_word = False
|
end_word = False
|
||||||
new_line = False
|
new_line = False
|
||||||
while i<len(text):
|
while i < len(text):
|
||||||
if text[i]=="%":
|
if text[i] == "%":
|
||||||
i += 1
|
i += 1
|
||||||
if i == len(text):
|
if i == len(text):
|
||||||
word+="%"
|
word += "%"
|
||||||
else:
|
else:
|
||||||
if text[i]=="n":
|
if text[i] == "n":
|
||||||
new_line = True
|
new_line = True
|
||||||
end_word = True
|
end_word = True
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
word+="%"+text[i]
|
word += "%" + text[i]
|
||||||
i += 1
|
i += 1
|
||||||
elif text[i] in ["\012","\015"]:
|
elif text[i] in ["\012","\015"]:
|
||||||
new_line = True
|
new_line = True
|
||||||
end_word = True
|
end_word = True
|
||||||
i += 1
|
i += 1
|
||||||
elif text[i]==" ":
|
elif text[i] == " ":
|
||||||
end_word = True
|
end_word = True
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
@@ -112,7 +111,7 @@ def FormatText(dc, text, width, height, formatMode):
|
|||||||
|
|
||||||
if end_word:
|
if end_word:
|
||||||
word_list.append(word)
|
word_list.append(word)
|
||||||
word=""
|
word = ""
|
||||||
end_word = False
|
end_word = False
|
||||||
if new_line:
|
if new_line:
|
||||||
word_list.append(None)
|
word_list.append(None)
|
||||||
@@ -120,23 +119,23 @@ def FormatText(dc, text, width, height, formatMode):
|
|||||||
|
|
||||||
# Now, make a list of strings which can fit in the box
|
# Now, make a list of strings which can fit in the box
|
||||||
string_list = []
|
string_list = []
|
||||||
buffer=""
|
buffer = ""
|
||||||
for s in word_list:
|
for s in word_list:
|
||||||
oldBuffer = buffer
|
oldBuffer = buffer
|
||||||
if s is None:
|
if s is None:
|
||||||
# FORCE NEW LINE
|
# FORCE NEW LINE
|
||||||
if len(buffer)>0:
|
if len(buffer) > 0:
|
||||||
string_list.append(buffer)
|
string_list.append(buffer)
|
||||||
buffer=""
|
buffer = ""
|
||||||
else:
|
else:
|
||||||
if len(buffer):
|
if len(buffer):
|
||||||
buffer+=" "
|
buffer += " "
|
||||||
buffer += s
|
buffer += s
|
||||||
x, y = dc.GetTextExtent(buffer)
|
x, y = dc.GetTextExtent(buffer)
|
||||||
|
|
||||||
# Don't fit within the bounding box if we're fitting
|
# Don't fit within the bounding box if we're fitting
|
||||||
# shape to contents
|
# shape to contents
|
||||||
if (x>width) and not (formatMode & FORMAT_SIZE_TO_CONTENTS):
|
if (x > width) and not (formatMode & FORMAT_SIZE_TO_CONTENTS):
|
||||||
# Deal with first word being wider than box
|
# Deal with first word being wider than box
|
||||||
if len(oldBuffer):
|
if len(oldBuffer):
|
||||||
string_list.append(oldBuffer)
|
string_list.append(oldBuffer)
|
||||||
@@ -155,7 +154,7 @@ def GetCentredTextExtent(dc, text_list, xpos = 0, ypos = 0, width = 0, height =
|
|||||||
max_width = 0
|
max_width = 0
|
||||||
for line in text_list:
|
for line in text_list:
|
||||||
current_width, char_height = dc.GetTextExtent(line)
|
current_width, char_height = dc.GetTextExtent(line)
|
||||||
if current_width>max_width:
|
if current_width > max_width:
|
||||||
max_width = current_width
|
max_width = current_width
|
||||||
|
|
||||||
return max_width, len(text_list) * char_height
|
return max_width, len(text_list) * char_height
|
||||||
@@ -176,31 +175,31 @@ def CentreText(dc, text_list, xpos, ypos, width, height, formatMode):
|
|||||||
for line in text_list:
|
for line in text_list:
|
||||||
current_width, char_height = dc.GetTextExtent(line.GetText())
|
current_width, char_height = dc.GetTextExtent(line.GetText())
|
||||||
widths.append(current_width)
|
widths.append(current_width)
|
||||||
if current_width>max_width:
|
if current_width > max_width:
|
||||||
max_width = current_width
|
max_width = current_width
|
||||||
|
|
||||||
max_height = len(text_list) * char_height
|
max_height = len(text_list) * char_height
|
||||||
|
|
||||||
if formatMode & FORMAT_CENTRE_VERT:
|
if formatMode & FORMAT_CENTRE_VERT:
|
||||||
if max_height<height:
|
if max_height < height:
|
||||||
yoffset = ypos - height / 2 + (height - max_height) / 2
|
yoffset = ypos - height / 2.0 + (height - max_height) / 2.0
|
||||||
else:
|
else:
|
||||||
yoffset = ypos - height / 2
|
yoffset = ypos - height / 2.0
|
||||||
yOffset = ypos
|
yOffset = ypos
|
||||||
else:
|
else:
|
||||||
yoffset = 0.0
|
yoffset = 0.0
|
||||||
yOffset = 0.0
|
yOffset = 0.0
|
||||||
|
|
||||||
if formatMode & FORMAT_CENTRE_HORIZ:
|
if formatMode & FORMAT_CENTRE_HORIZ:
|
||||||
xoffset = xpos - width / 2
|
xoffset = xpos - width / 2.0
|
||||||
xOffset = xpos
|
xOffset = xpos
|
||||||
else:
|
else:
|
||||||
xoffset = 0.0
|
xoffset = 0.0
|
||||||
xOffset = 0.0
|
xOffset = 0.0
|
||||||
|
|
||||||
for i, line in enumerate(text_list):
|
for i, line in enumerate(text_list):
|
||||||
if formatMode & FORMAT_CENTRE_HORIZ and widths[i]<width:
|
if formatMode & FORMAT_CENTRE_HORIZ and widths[i] < width:
|
||||||
x = (width - widths[i]) / 2 + xoffset
|
x = (width - widths[i]) / 2.0 + xoffset
|
||||||
else:
|
else:
|
||||||
x = xoffset
|
x = xoffset
|
||||||
y = i * char_height + yoffset
|
y = i * char_height + yoffset
|
||||||
@@ -214,15 +213,15 @@ def DrawFormattedText(dc, text_list, xpos, ypos, width, height, formatMode):
|
|||||||
if formatMode & FORMAT_CENTRE_HORIZ:
|
if formatMode & FORMAT_CENTRE_HORIZ:
|
||||||
xoffset = xpos
|
xoffset = xpos
|
||||||
else:
|
else:
|
||||||
xoffset = xpos - width / 2
|
xoffset = xpos - width / 2.0
|
||||||
|
|
||||||
if formatMode & FORMAT_CENTRE_VERT:
|
if formatMode & FORMAT_CENTRE_VERT:
|
||||||
yoffset = ypos
|
yoffset = ypos
|
||||||
else:
|
else:
|
||||||
yoffset = ypos - height / 2
|
yoffset = ypos - height / 2.0
|
||||||
|
|
||||||
# +1 to allow for rounding errors
|
# +1 to allow for rounding errors
|
||||||
dc.SetClippingRegion(xpos - width / 2, ypos - height / 2, width + 1, height + 1)
|
dc.SetClippingRegion(xpos - width / 2.0, ypos - height / 2.0, width + 1, height + 1)
|
||||||
|
|
||||||
for line in text_list:
|
for line in text_list:
|
||||||
dc.DrawText(line.GetText(), xoffset + line.GetX(), yoffset + line.GetY())
|
dc.DrawText(line.GetText(), xoffset + line.GetX(), yoffset + line.GetY())
|
||||||
@@ -232,14 +231,14 @@ def DrawFormattedText(dc, text_list, xpos, ypos, width, height, formatMode):
|
|||||||
|
|
||||||
|
|
||||||
def RoughlyEqual(val1, val2, tol = 0.00001):
|
def RoughlyEqual(val1, val2, tol = 0.00001):
|
||||||
return val1<(val2 + tol) and val1>(val2 - tol) and \
|
return val1 < (val2 + tol) and val1 > (val2 - tol) and \
|
||||||
val2<(val1 + tol) and val2>(val1 - tol)
|
val2 < (val1 + tol) and val2 > (val1 - tol)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def FindEndForBox(width, height, x1, y1, x2, y2):
|
def FindEndForBox(width, height, x1, y1, x2, y2):
|
||||||
xvec = [x1 - width / 2, x1 - width / 2, x1 + width / 2, x1 + width / 2, x1 - width / 2]
|
xvec = [x1 - width / 2.0, x1 - width / 2.0, x1 + width / 2.0, x1 + width / 2.0, x1 - width / 2.0]
|
||||||
yvec = [y1 - height / 2, y1 + height / 2, y1 + height / 2, y1 - height / 2, y1 - height / 2]
|
yvec = [y1 - height / 2.0, y1 + height / 2.0, y1 + height / 2.0, y1 - height / 2.0, y1 - height / 2.0]
|
||||||
|
|
||||||
return FindEndForPolyline(xvec, yvec, x2, y2, x1, y1)
|
return FindEndForPolyline(xvec, yvec, x2, y2, x1, y1)
|
||||||
|
|
||||||
@@ -253,19 +252,19 @@ def CheckLineIntersection(x1, y1, x2, y2, x3, y3, x4, y4):
|
|||||||
k_line = 1.0
|
k_line = 1.0
|
||||||
|
|
||||||
# Check for parallel lines
|
# Check for parallel lines
|
||||||
if denominator_term<0.005 and denominator_term>-0.005:
|
if denominator_term < 0.005 and denominator_term > -0.005:
|
||||||
line_constant=-1.0
|
line_constant = -1.0
|
||||||
else:
|
else:
|
||||||
line_constant = float(numerator_term) / denominator_term
|
line_constant = float(numerator_term) / denominator_term
|
||||||
|
|
||||||
# Check for intersection
|
# Check for intersection
|
||||||
if line_constant<1.0 and line_constant>0.0:
|
if line_constant < 1.0 and line_constant > 0.0:
|
||||||
# Now must check that other line hits
|
# Now must check that other line hits
|
||||||
if (y4 - y3)<0.005 and (y4 - y3)>-0.005:
|
if (y4 - y3) < 0.005 and (y4 - y3) > -0.005:
|
||||||
k_line = (x1 - x3 + line_constant * (x2 - x1)) / (x4 - x3)
|
k_line = (x1 - x3 + line_constant * (x2 - x1)) / (x4 - x3)
|
||||||
else:
|
else:
|
||||||
k_line = (y1 - y3 + line_constant * (y2 - y1)) / (y4 - y3)
|
k_line = (y1 - y3 + line_constant * (y2 - y1)) / (y4 - y3)
|
||||||
if k_line >= 0 and k_line<1:
|
if k_line >= 0 and k_line < 1:
|
||||||
length_ratio = line_constant
|
length_ratio = line_constant
|
||||||
else:
|
else:
|
||||||
k_line = 1
|
k_line = 1
|
||||||
@@ -285,13 +284,13 @@ def FindEndForPolyline(xvec, yvec, x1, y1, x2, y2):
|
|||||||
lastx = xvec[i]
|
lastx = xvec[i]
|
||||||
lasty = yvec[i]
|
lasty = yvec[i]
|
||||||
|
|
||||||
if line_ratio<min_ratio:
|
if line_ratio < min_ratio:
|
||||||
min_ratio = line_ratio
|
min_ratio = line_ratio
|
||||||
|
|
||||||
# Do last (implicit) line if last and first doubles are not identical
|
# Do last (implicit) line if last and first doubles are not identical
|
||||||
if not (xvec[0] == lastx and yvec[0] == lasty):
|
if not (xvec[0] == lastx and yvec[0] == lasty):
|
||||||
line_ratio, other_ratio = CheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[0], yvec[0])
|
line_ratio, other_ratio = CheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[0], yvec[0])
|
||||||
if line_ratio<min_ratio:
|
if line_ratio < min_ratio:
|
||||||
min_ratio = line_ratio
|
min_ratio = line_ratio
|
||||||
|
|
||||||
return x1 + (x2 - x1) * min_ratio, y1 + (y2 - y1) * min_ratio
|
return x1 + (x2 - x1) * min_ratio, y1 + (y2 - y1) * min_ratio
|
||||||
@@ -312,7 +311,7 @@ def PolylineHitTest(xvec, yvec, x1, y1, x2, y2):
|
|||||||
lastx = xvec[i]
|
lastx = xvec[i]
|
||||||
lasty = yvec[i]
|
lasty = yvec[i]
|
||||||
|
|
||||||
if line_ratio<min_ratio:
|
if line_ratio < min_ratio:
|
||||||
min_ratio = line_ratio
|
min_ratio = line_ratio
|
||||||
|
|
||||||
# Do last (implicit) line if last and first doubles are not identical
|
# Do last (implicit) line if last and first doubles are not identical
|
||||||
@@ -331,7 +330,7 @@ def GraphicsStraightenLine(point1, point2):
|
|||||||
|
|
||||||
if dx == 0:
|
if dx == 0:
|
||||||
return
|
return
|
||||||
elif abs(dy / dx)>1:
|
elif abs(float(dy) / dx) > 1:
|
||||||
point2[0] = point1[0]
|
point2[0] = point1[0]
|
||||||
else:
|
else:
|
||||||
point2[1] = point1[0]
|
point2[1] = point1[0]
|
||||||
@@ -340,40 +339,40 @@ def GraphicsStraightenLine(point1, point2):
|
|||||||
|
|
||||||
def GetPointOnLine(x1, y1, x2, y2, length):
|
def GetPointOnLine(x1, y1, x2, y2, length):
|
||||||
l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
|
l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
|
||||||
if l<0.01:
|
if l < 0.01:
|
||||||
l = 0.01
|
l = 0.01
|
||||||
|
|
||||||
i_bar = (x2 - x1) / l
|
i_bar = (x2 - x1) / l
|
||||||
j_bar = (y2 - y1) / l
|
j_bar = (y2 - y1) / l
|
||||||
|
|
||||||
return -length * i_bar + x2,-length * j_bar + y2
|
return -length * i_bar + x2, -length * j_bar + y2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def GetArrowPoints(x1, y1, x2, y2, length, width):
|
def GetArrowPoints(x1, y1, x2, y2, length, width):
|
||||||
l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
|
l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
|
||||||
|
|
||||||
if l<0.01:
|
if l < 0.01:
|
||||||
l = 0.01
|
l = 0.01
|
||||||
|
|
||||||
i_bar = (x2 - x1) / l
|
i_bar = (x2 - x1) / l
|
||||||
j_bar = (y2 - y1) / l
|
j_bar = (y2 - y1) / l
|
||||||
|
|
||||||
x3=-length * i_bar + x2
|
x3 = -length * i_bar + x2
|
||||||
y3=-length * j_bar + y2
|
y3 = -length * j_bar + y2
|
||||||
|
|
||||||
return x2, y2, width*-j_bar + x3, width * i_bar + y3,-width*-j_bar + x3,-width * i_bar + y3
|
return x2, y2, width * -j_bar + x3, width * i_bar + y3, -width * -j_bar + x3, -width * i_bar + y3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):
|
def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):
|
||||||
a1 = width1 / 2
|
a1 = width1 / 2.0
|
||||||
b1 = height1 / 2
|
b1 = height1 / 2.0
|
||||||
|
|
||||||
# Check that x2 != x3
|
# Check that x2 != x3
|
||||||
if abs(x2 - x3)<0.05:
|
if abs(x2 - x3) < 0.05:
|
||||||
x4 = x2
|
x4 = x2
|
||||||
if y3>y2:
|
if y3 > y2:
|
||||||
y4 = y1 - math.sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1))))
|
y4 = y1 - math.sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1))))
|
||||||
else:
|
else:
|
||||||
y4 = y1 + math.sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1))))
|
y4 = y1 + math.sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1))))
|
||||||
@@ -387,16 +386,16 @@ def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):
|
|||||||
E = (A + B)
|
E = (A + B)
|
||||||
F = (C - (2 * A * x1) - (2 * B * x2))
|
F = (C - (2 * A * x1) - (2 * B * x2))
|
||||||
G = ((A * x1 * x1) + (B * x2 * x2) - (C * x2) + D - 1)
|
G = ((A * x1 * x1) + (B * x2 * x2) - (C * x2) + D - 1)
|
||||||
H = ((y3 - y2) / (x2 - x2))
|
H = (float(y3 - y2) / (x2 - x2))
|
||||||
K = ((F * F) - (4 * E * G))
|
K = ((F * F) - (4 * E * G))
|
||||||
|
|
||||||
if K >= 0:
|
if K >= 0:
|
||||||
# In this case the line intersects the ellipse, so calculate intersection
|
# In this case the line intersects the ellipse, so calculate intersection
|
||||||
if x2 >= x1:
|
if x2 >= x1:
|
||||||
ellipse1_x = ((F*-1) + math.sqrt(K)) / (2 * E)
|
ellipse1_x = ((F * -1) + math.sqrt(K)) / (2 * E)
|
||||||
ellipse1_y = ((H * (ellipse1_x - x2)) + y2)
|
ellipse1_y = ((H * (ellipse1_x - x2)) + y2)
|
||||||
else:
|
else:
|
||||||
ellipse1_x = (((F*-1) - math.sqrt(K)) / (2 * E))
|
ellipse1_x = (((F * -1) - math.sqrt(K)) / (2 * E))
|
||||||
ellipse1_y = ((H * (ellipse1_x - x2)) + y2)
|
ellipse1_y = ((H * (ellipse1_x - x2)) + y2)
|
||||||
else:
|
else:
|
||||||
# in this case, arc does not intersect ellipse, so just draw arc
|
# in this case, arc does not intersect ellipse, so just draw arc
|
||||||
|
Reference in New Issue
Block a user