+class Arrow(DrawObject,XYObjectMixin,LineOnlyMixin):
+ """
+
+ Arrow(XY, # coords of origin of arrow (x,y)
+ Length, # length of arrow in pixels
+ theta, # angle of arrow in degrees: zero is straight up
+ # angle is to the right
+ LineColor = "Black",
+ LineStyle = "Solid",
+ LineWidth = 1,
+ ArrowHeadSize = 4,
+ ArrowHeadAngle = 45,
+ InForeground = False):
+
+ It will draw an arrow , starting at the point, (X,Y) pointing in
+ direction, theta.
+
+
+ """
+ def __init__(self,
+ XY,
+ Length,
+ Direction,
+ LineColor = "Black",
+ LineStyle = "Solid",
+ LineWidth = 2, # pixels
+ ArrowHeadSize = 8, # pixels
+ ArrowHeadAngle = 30, # degrees
+ InForeground = False):
+
+ DrawObject.__init__(self, InForeground)
+
+ self.XY = array(XY, Float)
+ self.XY.shape = (2,) # Make sure it is a 1X2 array, even if there is only one point
+ self.Length = Length
+ self.Direction = float(Direction)
+ self.ArrowHeadSize = ArrowHeadSize
+ self.ArrowHeadAngle = float(ArrowHeadAngle)
+
+ self.CalcArrowPoints()
+ self.CalcBoundingBox()
+
+ self.LineColor = LineColor
+ self.LineStyle = LineStyle
+ self.LineWidth = LineWidth
+
+ self.SetPen(LineColor,LineStyle,LineWidth)
+
+ ##fixme: How should the HitTest be drawn?
+ self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
+
+ def SetDirection(self, Direction):
+ self.Direction = float(Direction)
+ self.CalcArrowPoints()
+
+ def SetLength(self, Length):
+ self.Length = Length
+ self.CalcArrowPoints()
+
+ def SetLengthDirection(self, Length, Direction):
+ self.Direction = float(Direction)
+ self.Length = Length
+ self.CalcArrowPoints()
+
+ def SetLength(self, Length):
+ self.Length = Length
+ self.CalcArrowPoints()
+
+ def CalcArrowPoints(self):
+ L = self.Length
+ S = self.ArrowHeadSize
+ phi = self.ArrowHeadAngle * pi / 360
+ theta = (self.Direction-90.0) * pi / 180
+ ArrowPoints = array( ( (0, L, L - S*cos(phi),L, L - S*cos(phi) ),
+ (0, 0, S*sin(phi), 0, -S*sin(phi) ) ),
+ Float )
+ RotationMatrix = array( ( ( cos(theta), -sin(theta) ),
+ ( sin(theta), cos(theta) ) ),
+ Float
+ )
+ ArrowPoints = matrixmultiply(RotationMatrix, ArrowPoints)
+ self.ArrowPoints = transpose(ArrowPoints)
+
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
+ dc.SetPen(self.Pen)
+ xy = WorldToPixel(self.XY)
+ ArrowPoints = xy + self.ArrowPoints
+ dc.DrawLines(ArrowPoints)
+ if HTdc and self.HitAble:
+ HTdc.SetPen(self.HitPen)
+ HTdc.DrawLines(ArrowPoints)
+