Since everything in the submodules is to appear in the pacakge

namespace rename the submodule to have a leading underscore to make it
easier to document it that way.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27634 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-06-04 20:12:01 +00:00
parent dcbafcc2df
commit b2f6eb0606
9 changed files with 70 additions and 63 deletions

View File

@@ -3,12 +3,20 @@ The Object Graphics Library provides for simple drawing and manipulation
of 2D objects. of 2D objects.
""" """
__all__ = ["basic", "diagram", "canvas", "lines", "bmpshape", "divided", "composit"] from _basic import *
from _diagram import *
from _canvas import *
from _lines import *
from _bmpshape import *
from _divided import *
from _composit import *
# Set things up for documenting with epydoc. The __docfilter__ will
# prevent some things from beign documented, and anything in __all__
# will appear to actually exist in this module.
import wx._core as _wx
__docfilter__ = _wx.__DocFilter(globals())
__all__ = [name for name in dir() if not name.startswith('_')]
from basic import *
from diagram import *
from canvas import *
from lines import *
from bmpshape import *
from divided import *
from composit import *

View File

@@ -14,9 +14,9 @@
from __future__ import division from __future__ import division
import wx import wx
from math import pi, sqrt, atan, sin, cos import math
from oglmisc import * from _oglmisc import *
DragOffsetX = 0.0 DragOffsetX = 0.0
DragOffsetY = 0.0 DragOffsetY = 0.0
@@ -484,7 +484,7 @@ class Shape(ShapeEvtHandler):
e = self.GetAttachmentPositionEdge(i) e = self.GetAttachmentPositionEdge(i)
if e: if e:
xp, yp = e xp, yp = e
l = 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
@@ -1841,11 +1841,11 @@ class Shape(ShapeEvtHandler):
""" """
if RoughlyEqual(self.GetRotation(), 0): if RoughlyEqual(self.GetRotation(), 0):
i = physicalAttachment i = physicalAttachment
elif RoughlyEqual(self.GetRotation(), pi / 2): elif RoughlyEqual(self.GetRotation(), math.pi / 2):
i = physicalAttachment - 1 i = physicalAttachment - 1
elif RoughlyEqual(self.GetRotation(), pi): elif RoughlyEqual(self.GetRotation(), math.pi):
i = physicalAttachment - 2 i = physicalAttachment - 2
elif RoughlyEqual(self.GetRotation(), 3 * pi / 2): elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2):
i = physicalAttachment - 3 i = physicalAttachment - 3
else: else:
# Can't handle -- assume the same # Can't handle -- assume the same
@@ -1862,11 +1862,11 @@ class Shape(ShapeEvtHandler):
""" """
if RoughlyEqual(self.GetRotation(), 0): if RoughlyEqual(self.GetRotation(), 0):
i = logicalAttachment i = logicalAttachment
elif RoughlyEqual(self.GetRotation(), pi / 2): elif RoughlyEqual(self.GetRotation(), math.pi / 2):
i = logicalAttachment + 1 i = logicalAttachment + 1
elif RoughlyEqual(self.GetRotation(), pi): elif RoughlyEqual(self.GetRotation(), math.pi):
i = logicalAttachment + 2 i = logicalAttachment + 2
elif RoughlyEqual(self.GetRotation(), 3 * pi / 2): elif RoughlyEqual(self.GetRotation(), 3 * math.pi / 2):
i = logicalAttachment + 3 i = logicalAttachment + 3
else: else:
return logicalAttachment return logicalAttachment
@@ -1880,9 +1880,9 @@ class Shape(ShapeEvtHandler):
"""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 * pi self._rotation += 2 * math.pi
elif self._rotation>2 * pi: elif self._rotation>2 * math.pi:
self._rotation -= 2 * pi self._rotation -= 2 * math.pi
def GetBackgroundPen(self): def GetBackgroundPen(self):
"""Return pen of the right colour for the background.""" """Return pen of the right colour for the background."""
@@ -2528,7 +2528,7 @@ class PolygonShape(Shape):
e = self.GetAttachmentPositionEdge(i) e = self.GetAttachmentPositionEdge(i)
if e: if e:
xp, yp = e xp, yp = e
l = 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
@@ -2700,8 +2700,8 @@ class PolygonShape(Shape):
actualTheta = theta - self._rotation actualTheta = theta - self._rotation
# Rotate attachment points # Rotate attachment points
sinTheta = sin(actualTheta) sinTheta = math.sin(actualTheta)
cosTheta = cos(actualTheta) cosTheta = math.cos(actualTheta)
for point in self._attachmentPoints: for point in self._attachmentPoints:
x1 = point._x x1 = point._x
@@ -2758,7 +2758,7 @@ class PolygonShape(Shape):
bound_x, bound_y = self.GetBoundingBoxMin() bound_x, bound_y = self.GetBoundingBoxMin()
dist = sqrt((x - self.GetX()) * (x - self.GetX()) + (y - self.GetY()) * (y - self.GetY())) dist = math.sqrt((x - self.GetX()) * (x - self.GetX()) + (y - self.GetY()) * (y - self.GetY()))
pt._originalDistance = dist pt._originalDistance = dist
pt._originalSize.x = bound_x pt._originalSize.x = bound_x
@@ -3153,7 +3153,7 @@ class PolygonControlPoint(ControlPoint):
# Calculate what new size would be, at end of resize # Calculate what new size would be, at end of resize
def CalculateNewSize(self, x, y): def CalculateNewSize(self, x, y):
bound_x, bound_y = self.GetShape().GetBoundingBoxMax() bound_x, bound_y = self.GetShape().GetBoundingBoxMax()
dist = sqrt((x - self._shape.GetX()) * (x - self._shape.GetX()) + (y - self._shape.GetY()) * (y - self._shape.GetY())) dist = math.sqrt((x - self._shape.GetX()) * (x - self._shape.GetX()) + (y - self._shape.GetY()) * (y - self._shape.GetY()))
self._newSize.x = dist / self._originalDistance * self._originalSize.x self._newSize.x = dist / self._originalDistance * self._originalSize.x
self._newSize.y = dist / self._originalDistance * self._originalSize.y self._newSize.y = dist / self._originalDistance * self._originalSize.y
@@ -3168,6 +3168,6 @@ class PolygonControlPoint(ControlPoint):
def OnEndDragLeft(self, x, y, keys = 0, attachment = 0): def OnEndDragLeft(self, x, y, keys = 0, attachment = 0):
self._shape.GetEventHandler().OnSizingEndDragLeft(self, x, y, keys, attachment) self._shape.GetEventHandler().OnSizingEndDragLeft(self, x, y, keys, attachment)
from canvas import * from _canvas import *
from lines import * from _lines import *
from composit import * from _composit import *

View File

@@ -13,7 +13,7 @@
from __future__ import division from __future__ import division
from basic import RectangleShape from _basic import RectangleShape
class BitmapShape(RectangleShape): class BitmapShape(RectangleShape):

View File

@@ -14,8 +14,8 @@
from __future__ import division from __future__ import division
import wx import wx
from lines import LineShape from _lines import LineShape
from composit import * from _composit import *
NoDragging, StartDraggingLeft, ContinueDraggingLeft, StartDraggingRight, ContinueDraggingRight = 0, 1, 2, 3, 4 NoDragging, StartDraggingLeft, ContinueDraggingLeft, StartDraggingRight, ContinueDraggingRight = 0, 1, 2, 3, 4

View File

@@ -16,8 +16,8 @@ from __future__ import division
import sys import sys
import wx import wx
from basic import RectangleShape, Shape, ControlPoint from _basic import RectangleShape, Shape, ControlPoint
from oglmisc import * from _oglmisc import *
KEY_SHIFT, KEY_CTRL = 1, 2 KEY_SHIFT, KEY_CTRL = 1, 2

View File

@@ -16,8 +16,8 @@ from __future__ import division
import sys import sys
import wx import wx
from basic import ControlPoint, RectangleShape, Shape from _basic import ControlPoint, RectangleShape, Shape
from oglmisc import * from _oglmisc import *

View File

@@ -14,11 +14,10 @@
from __future__ import division from __future__ import division
import sys import sys
import math
from math import sqrt from _basic import Shape, ShapeRegion, ControlPoint, RectangleShape
from _oglmisc import *
from basic import Shape, ShapeRegion, ControlPoint, RectangleShape
from oglmisc import *
# Line alignment flags # Line alignment flags
# Vertical by default # Vertical by default
@@ -555,7 +554,7 @@ class LineShape(Shape):
dx = point2[0]-point1[0] dx = point2[0]-point1[0]
dy = point2[1]-point1[1] dy = point2[1]-point1[1]
seg_len = 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 * ((x-point1[0]) * dy-(y-point1[1]) * dx) / (dy * dy + dx * dx)
@@ -613,7 +612,7 @@ class LineShape(Shape):
# will be on the line. # will be on the line.
realOffset = XOffset realOffset = XOffset
if proportionalOffset: if proportionalOffset:
totalLength = 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)
@@ -625,7 +624,7 @@ class LineShape(Shape):
# will be on the line. # will be on the line.
realOffset = XOffset realOffset = XOffset
if proportionalOffset: if proportionalOffset:
totalLength = 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)
@@ -641,7 +640,7 @@ class LineShape(Shape):
# will be on the line. # will be on the line.
realOffset = XOffset realOffset = XOffset
if proportionalOffset: if proportionalOffset:
totalLength = 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)
@@ -658,10 +657,10 @@ class LineShape(Shape):
# |d # |d
# | # |
# (x1, y1)--------------(x3, y3)------------------(x2, y2) # (x1, y1)--------------(x3, y3)------------------(x2, y2)
# x4 = x3 - d * sin(theta) # x4 = x3 - d * math.sin(theta)
# y4 = y3 + d * cos(theta) # y4 = y3 + d * math.cos(theta)
# #
# Where theta = 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 = positionOnLineX
@@ -671,10 +670,10 @@ class LineShape(Shape):
if x3 == x1: if x3 == x1:
theta = pi / 2 theta = pi / 2
else: else:
theta = atan((y3-y1) / (x3-x1)) theta = math.atan((y3-y1) / (x3-x1))
x4 = x3-d * sin(theta) x4 = x3-d * math.sin(theta)
y4 = y3 + d * cos(theta) y4 = y3 + d * math.cos(theta)
deltaX = x4-positionOnLineX deltaX = x4-positionOnLineX
deltaY = y4-positionOnLineY deltaY = y4-positionOnLineY
@@ -749,11 +748,11 @@ class LineShape(Shape):
elif x1 == x2 and y2>y1: elif x1 == x2 and y2>y1:
theta = pi / 2 theta = pi / 2
elif x2>x1 and y2 >= y1: elif x2>x1 and y2 >= y1:
theta = atan((y2-y1) / (x2-x1)) theta = math.atan((y2-y1) / (x2-x1))
elif x2<x1: elif x2<x1:
theta = pi + atan((y2-y1) / (x2-x1)) theta = pi + math.atan((y2-y1) / (x2-x1))
elif x2>x1 and y2<y1: elif x2>x1 and y2<y1:
theta = 2 * pi + atan((y2-y1) / (x2-x1)) theta = 2 * pi + math.atan((y2-y1) / (x2-x1))
else: else:
raise "Unknown arrowhead rotation case" raise "Unknown arrowhead rotation case"
@@ -1439,9 +1438,9 @@ 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 = 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 = sqrt((x-startX) * (x-startX) + (y-startY) * (y-startY)) startDistance = math.sqrt((x-startX) * (x-startX) + (y-startY) * (y-startY))
endDistance = 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

View File

@@ -12,7 +12,7 @@
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
from __future__ import division from __future__ import division
from math import * import math
import wx import wx
@@ -339,7 +339,7 @@ def GraphicsStraightenLine(point1, point2):
def GetPointOnLine(x1, y1, x2, y2, length): def GetPointOnLine(x1, y1, x2, y2, length):
l = 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
@@ -351,7 +351,7 @@ def GetPointOnLine(x1, y1, x2, y2, length):
def GetArrowPoints(x1, y1, x2, y2, length, width): def GetArrowPoints(x1, y1, x2, y2, length, width):
l = 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
@@ -374,9 +374,9 @@ def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):
if abs(x2 - x3)<0.05: if abs(x2 - x3)<0.05:
x4 = x2 x4 = x2
if y3>y2: if y3>y2:
y4 = y1 - 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 + 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))))
return x4, y4 return x4, y4
# Calculate the x and y coordinates of the point where arc intersects ellipse # Calculate the x and y coordinates of the point where arc intersects ellipse
@@ -393,10 +393,10 @@ def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):
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) + 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) - 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
@@ -408,7 +408,7 @@ def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):
def FindEndForCircle(radius, x1, y1, x2, y2): def FindEndForCircle(radius, x1, y1, x2, y2):
H = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) H = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
if H == 0: if H == 0:
return x1, y1 return x1, y1