/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/baserenderer.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/baserenderer.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1554 by bh, Wed Aug 6 17:24:30 2003 UTC revision 1591 by bh, Fri Aug 15 14:00:53 2003 UTC
# Line 160  class BaseRenderer: Line 160  class BaseRenderer:
160          table = layer.ShapeStore().Table()          table = layer.ShapeStore().Table()
161    
162          # Determine which render function to use.          # Determine which render function to use.
163          draw_func, draw_func_param = self.low_level_renderer(layer)          useraw, draw_func, draw_func_param = self.low_level_renderer(layer)
164    
165          # Iterate through all shapes that have to be drawn.          # Iterate through all shapes that have to be drawn.
166          for i in self.layer_ids(layer):          for i in self.layer_ids(layer):
167                shape = layer.Shape(i)
168    
169              if field is None:              if field is None:
170                  group = defaultGroup                  group = defaultGroup
# Line 184  class BaseRenderer: Line 185  class BaseRenderer:
185                  if prop != old_prop:                  if prop != old_prop:
186                      pen, brush = self.tools_for_property(prop)                      pen, brush = self.tools_for_property(prop)
187    
188              draw_func(draw_func_param, i, pen, brush)              if useraw:
189                    data = shape.RawData()
190                else:
191                    data = shape.Points()
192                draw_func(draw_func_param, data, pen, brush)
193    
194      def layer_ids(self, layer):      def layer_ids(self, layer):
195          """Return the shape ids of the given layer that have to be drawn.          """Return the shape ids of the given layer that have to be drawn.
# Line 198  class BaseRenderer: Line 203  class BaseRenderer:
203          """Return the low-level renderer for the layer for draw_shape_layer          """Return the low-level renderer for the layer for draw_shape_layer
204    
205          The low level renderer to be returned by this method is a tuple          The low level renderer to be returned by this method is a tuple
206          (func, param) where func is a callable object and param is          (useraw, func, param) where useraw is a boolean indicating
207          passed as the first parameter to func. The draw_shape_layer          whether the function uses the raw shape data, func is a callable
208          method will call func like this:          object and param is passed as the first parameter to func. The
209            draw_shape_layer method will call func like this:
210              func(param, rawshape, pen, brush)  
211                func(param, shapedata, pen, brush)
212          where rawshape is currently the shapeid. pen and brush are the  
213          pen and brush to use to draw the shape on the dc.          where shapedata is the return value of the RawData method of the
214            shape object if useraw is true or the return value of the Points
215            method if it's false. pen and brush are the pen and brush to use
216            to draw the shape on the dc.
217    
218          The default implementation returns one of          The default implementation returns one of
219          self.draw_polygon_shape, self.draw_arc_shape or          self.draw_polygon_shape, self.draw_arc_shape or
220          self.draw_point_shape as func and layer as param. Derived          self.draw_point_shape as func and layer as param. None of the
221          classes can override this method to return more efficient low          method use the raw shape data. Derived classes can override this
222          level renderers.          method to return more efficient low level renderers.
223          """          """
224          shapetype = layer.ShapeType()          shapetype = layer.ShapeType()
225          if shapetype == SHAPETYPE_POINT:          if shapetype == SHAPETYPE_POINT:
# Line 220  class BaseRenderer: Line 228  class BaseRenderer:
228              func = self.draw_arc_shape              func = self.draw_arc_shape
229          else:          else:
230              func = self.draw_polygon_shape              func = self.draw_polygon_shape
231          return func, layer          return False, func, layer
232    
233      def make_point(self, x, y):      def make_point(self, x, y):
234          """Convert (x, y) to a point object.          """Convert (x, y) to a point object.
# Line 229  class BaseRenderer: Line 237  class BaseRenderer:
237          """          """
238          raise NotImplementedError          raise NotImplementedError
239    
240      def projected_points(self, layer, shapeid):      def projected_points(self, layer, points):
241          """Return the projected coordinates of shape shapeid in layer.          """Return the projected coordinates of the points taken from layer.
242    
243          Read the shape from the layer through its Shape method and          Transform all the points in the list of lists of coordinate
244          transform all the points in the list of lists of coordinate          pairs in points.
         pairs returned by the shape's Points method.  
245    
246          The transformation applies the inverse of the layer's projection          The transformation applies the inverse of the layer's projection
247          if any, then the map's projection if any and finally applies          if any, then the map's projection if any and finally applies
# Line 253  class BaseRenderer: Line 260  class BaseRenderer:
260              inverse = proj.Inverse              inverse = proj.Inverse
261          else:          else:
262              inverse = None              inverse = None
263          shape = layer.Shape(shapeid)          result = []
         points = []  
264          scale = self.scale          scale = self.scale
265          offx, offy = self.offset          offx, offy = self.offset
266          make_point = self.make_point          make_point = self.make_point
267          for part in shape.Points():          for part in points:
268              points.append([])              result.append([])
269              for x, y in part:              for x, y in part:
270                  if inverse:                  if inverse:
271                      x, y = inverse(x, y)                      x, y = inverse(x, y)
272                  if forward:                  if forward:
273                      x, y = forward(x, y)                      x, y = forward(x, y)
274                  points[-1].append(make_point(x * scale + offx,                  result[-1].append(make_point(x * scale + offx,
275                                               -y * scale + offy))                                               -y * scale + offy))
276          return points          return result
277    
278      def draw_polygon_shape(self, layer, index, pen, brush):      def draw_polygon_shape(self, layer, points, pen, brush):
279          """Draw a polygon shape with the given brush and pen          """Draw a polygon shape from layer with the given brush and pen
280    
281          The shape is indicated by its id (index) and the layer. The          The shape is given by points argument which is a the return
282          coordinates in the DC's coordinate system are determined with          value of the shape's Points() method. The coordinates in the
283            DC's coordinate system are determined with
284          self.projected_points.          self.projected_points.
285          """          """
286          points = self.projected_points(layer, index)          points = self.projected_points(layer, points)
287    
288          if brush is not self.TRANSPARENT_BRUSH:          if brush is not self.TRANSPARENT_BRUSH:
289              polygon = []              polygon = []
# Line 298  class BaseRenderer: Line 305  class BaseRenderer:
305              for part in points:              for part in points:
306                  self.dc.DrawLines(part)                  self.dc.DrawLines(part)
307    
308      def draw_arc_shape(self, layer, index, pen, brush):      def draw_arc_shape(self, layer, points, pen, brush):
309          """Draw an arc shape with the given brush and pen          """Draw an arc shape from layer with the given brush and pen
310    
311          The shape is indicated by its id (index) and the layer. The          The shape is given by points argument which is a the return
312          coordinates in the DC's coordinate system are determined with          value of the shape's Points() method. The coordinates in the
313            DC's coordinate system are determined with
314          self.projected_points.          self.projected_points.
315          """          """
316          points = self.projected_points(layer, index)          points = self.projected_points(layer, points)
317          self.dc.SetBrush(brush)          self.dc.SetBrush(brush)
318          self.dc.SetPen(pen)          self.dc.SetPen(pen)
319          for part in points:          for part in points:
320              self.dc.DrawLines(part)              self.dc.DrawLines(part)
321    
322      def draw_point_shape(self, layer, index, pen, brush):      def draw_point_shape(self, layer, points, pen, brush):
323          """Draw a point shape with the given brush and pen          """Draw a point shape from layer with the given brush and pen
324    
325          The shape is indicated by its id (index) and the layer. The          The shape is given by points argument which is a the return
326          coordinates in the DC's coordinate system are determined with          value of the shape's Points() method. The coordinates in the
327            DC's coordinate system are determined with
328          self.projected_points.          self.projected_points.
329    
330          The point is drawn as a circle centered on the point.          The point is drawn as a circle centered on the point.
331          """          """
332          points = self.projected_points(layer, index)          points = self.projected_points(layer, points)
333          if not points:          if not points:
334              return              return
335    

Legend:
Removed from v.1554  
changed lines
  Added in v.1591

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26