# # WindBarb Class for Float Canvas which can be dropped right into FloatCanvas.py and added # to _makeFloatCanvasAddMethods() so you can call Canvas.AddWindBarb() # class WindBarb(DrawObject,XYObjectMixin,LineOnlyMixin): """ WindBarb(XY, # coords of center of wind barb (x,y) Speed, # knots Direction, # angle of arrow in degrees: zero is straight up (or left?) # angle is to the right LineColor = "Black", LineStyle = "Solid", LineWidth = 1, FillColor = "Black", FillStyle = "Solid", InForeground = False): It will draw a wind barb , starting at the point, (X,Y) pointing in Direction. """ def __init__(self, XY, Speed, Direction, LineColor = "Black", LineStyle = "Solid", LineWidth = 2, # pixels FillColor = "Black", FillStyle = "Solid", 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.Speed = Speed self.Direction = float(Direction) self.barbHeight = 24 self.barbSize = 8 self.CalcBarbPoints() self.CalcBoundingBox() self.LineColor = LineColor self.LineStyle = LineStyle self.LineWidth = LineWidth self.FillColor = FillColor self.FillStyle = FillStyle self.SetPen(LineColor,LineStyle,LineWidth) self.SetBrush(FillColor,FillStyle) ##fixme: How should the HitTest be drawn? self.HitLineWidth = max(LineWidth,self.MinHitLineWidth) def CalcBarbPoints(self): S = self.Speed theta = (self.Direction -90) * pi / 180 RotationMatrix = array( ( ( cos(theta), -sin(theta) ), ( sin(theta), cos(theta) ) ), Float) lines = [] polys = [] # the base line split across the point 0,0 lines.append(array( ( (-self.barbHeight/2,0), (self.barbHeight/2,0) ), Float) ) basepoint = self.barbHeight/2 while S > 0 : if S >= 100: S-=100 polys.append( array(((basepoint,0), (basepoint,self.barbSize), (basepoint+(self.barbSize/2),self.barbSize), (basepoint+(self.barbSize/2),0)), Float) ) basepoint -=self.barbSize if S >= 50: S-=50 polys.append( array(((basepoint,0), (basepoint+(self.barbSize/2),self.barbSize), (basepoint+(self.barbSize/2),0)), Float) ) basepoint -=(self.barbSize/2) if S >= 10 : S-=10 lines.append(array( ( (basepoint,0), # start at left center (basepoint+(self.barbSize/2),self.barbSize) ), # move right from left by barbSize/2 ,thn go up by barbsize Float) ) basepoint -=(self.barbSize/2) if S < 10 and S>=5: S=0 lines.append(array( ( (basepoint,0), (basepoint+(self.barbSize/4),(self.barbSize/2)) ), Float) ) basepoint -=(self.barbSize/2) if S<5: S=0 self.barbLines = [] self.polys = [] # now transpose the points for line in lines: newline = transpose(matrixmultiply(RotationMatrix,transpose(line))) self.barbLines.append(newline) for poly in polys: newpoly = transpose(matrixmultiply(RotationMatrix,transpose(poly))) self.polys.append(newpoly) def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None): dc.SetPen(self.Pen) dc.SetBrush(self.Brush) xy = WorldToPixel(self.XY) for line in self.barbLines: dc.DrawLines(xy + line) for poly in self.polys: dc.DrawPolygon(xy+poly) if HTdc and self.HitAble: HTdc.SetPen(self.HitPen) HTdc.DrawLines(ArrowPoints)