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

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

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

revision 76 by bh, Mon Feb 4 19:23:30 2002 UTC revision 374 by jan, Mon Jan 27 14:20:02 2003 UTC
# Line 13  from wxPython.wx import wxPoint, wxColou Line 13  from wxPython.wx import wxPoint, wxColou
13    
14  from wxproj import draw_polygon_shape  from wxproj import draw_polygon_shape
15    
16    from Thuban import _
17    
18  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \
19       SHAPETYPE_POINT       SHAPETYPE_POINT
20  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
# Line 63  class MapRenderer: Line 65  class MapRenderer:
65          scale = self.scale          scale = self.scale
66          offx, offy = self.offset          offx, offy = self.offset
67    
         fill = layer.fill  
         if fill is None:  
             brush = wxTRANSPARENT_BRUSH  
         else:  
             color = wxColour(fill.red * 255,  
                              fill.green * 255,  
                              fill.blue * 255)  
             brush = wxBrush(color, wxSOLID)  
         stroke = layer.stroke  
         stroke_width = layer.stroke_width  
         if stroke is None:  
             pen = wxTRANSPARENT_PEN  
         else:  
             color = wxColour(stroke.red * 255,  
                              stroke.green * 255,  
                              stroke.blue * 255)  
             pen = wxPen(color, stroke_width, wxSOLID)  
   
68          map_proj = self.map.projection          map_proj = self.map.projection
69          layer_proj = layer.projection          layer_proj = layer.projection
70    
71          shapetype = layer.ShapeType()          shapetype = layer.ShapeType()
72    
73          if shapetype == SHAPETYPE_POLYGON:          brush = wxTRANSPARENT_BRUSH
74              for i in range(layer.NumShapes()):          pen   = wxTRANSPARENT_PEN
75    
76            old_prop = None
77            for i in self.layer_ids(layer):
78                value = None
79                shape = layer.Shape(i)
80                field = layer.classification.field
81    
82                if field is not None:
83                    record = layer.table.read_record(i)
84                    if record is not None:
85                        value = record[field]
86    
87                #
88                # if the above statements fail 'value' should
89                # be null, at which point this call will
90                # at least retreive the NullData
91                #
92                prop = layer.classification.getProperties(value)
93    
94                if prop != old_prop:
95                    old_prop = prop
96    
97                    if shapetype == SHAPETYPE_ARC:
98                        fill = None
99                    else:
100                        fill = prop['fill']
101        
102                    if fill is None:
103                        brush = wxTRANSPARENT_BRUSH
104                    else:
105                        color = wxColour(fill.red * 255,
106                                         fill.green * 255,
107                                         fill.blue * 255)
108                        brush = wxBrush(color, wxSOLID)
109        
110                    stroke = prop['stroke']
111                    stroke_width = prop['stroke_width']
112                    if stroke is None:
113                        pen = wxTRANSPARENT_PEN
114                    else:
115                        color = wxColour(stroke.red * 255,
116                                         stroke.green * 255,
117                                         stroke.blue * 255)
118                        pen = wxPen(color, stroke_width, wxSOLID)
119        
120                if shapetype == SHAPETYPE_POINT:
121                    self.dc.SetBrush(brush)
122                    self.dc.SetPen(pen)
123                    self.draw_point_shape(layer, i)
124                else:
125                  self.draw_polygon_shape(layer, i, pen, brush)                  self.draw_polygon_shape(layer, i, pen, brush)
126          else:  
127              self.dc.SetBrush(brush)      def layer_ids(self, layer):
128              self.dc.SetPen(pen)          """Return the shape ids of the given layer that have to be drawn.
129              if shapetype == SHAPETYPE_ARC:          
130                  f = self.draw_arc_shape          The default implementation simply returns all ids in the layer.
131              elif shapetype == SHAPETYPE_POINT:          Override in derived classes to be more precise.
132                  f = self.draw_point_shape          """
133              for i in range(layer.NumShapes()):          return range(layer.NumShapes())
                 f(layer, i)  
134    
135      def draw_polygon_shape(self, layer, index, pen, brush):      def draw_polygon_shape(self, layer, index, pen, brush):
136          offx, offy = self.offset                  offx, offy = self.offset        
# Line 183  class ScreenRenderer(MapRenderer): Line 216  class ScreenRenderer(MapRenderer):
216      # On the screen we want to see only visible layers by default      # On the screen we want to see only visible layers by default
217      honor_visibility = 1      honor_visibility = 1
218            
219      def RenderMap(self, map, selected_layer, selected_shape):      def RenderMap(self, map, region, selected_layer, selected_shape):
220            """Render the map.
221    
222            Only the given region (a tuple in window coordinates as returned
223            by a wxrect's asTuple method) needs to be redrawn. Highlight the
224            shape with id selected_shape in the selected_layer.
225            """
226            self.update_region = region
227          self.selected_layer = selected_layer          self.selected_layer = selected_layer
228          self.selected_shape = selected_shape          self.selected_shape = selected_shape
229          self.render_map(map)          self.render_map(map)
# Line 198  class ScreenRenderer(MapRenderer): Line 238  class ScreenRenderer(MapRenderer):
238              index = self.selected_shape              index = self.selected_shape
239              if shapetype == SHAPETYPE_POLYGON:              if shapetype == SHAPETYPE_POLYGON:
240                  self.draw_polygon_shape(layer, index, pen, brush)                  self.draw_polygon_shape(layer, index, pen, brush)
241                elif shapetype == SHAPETYPE_ARC:
242                    self.draw_polygon_shape(layer, index, pen, None)
243              else:              else:
244                  self.dc.SetBrush(brush)                  self.dc.SetBrush(brush)
245                  self.dc.SetPen(pen)                  self.dc.SetPen(pen)
246                  if shapetype == SHAPETYPE_ARC:                  if shapetype == SHAPETYPE_POINT:
247                      f = self.draw_arc_shape                      self.draw_point_shape(layer, index)
248                  elif shapetype == SHAPETYPE_POINT:                  else:
249                      f = self.draw_point_shape                      raise TypeError(_("Unhandled shape type %s") % shapetype)
250                  f(layer, index)  
251        def layer_ids(self, layer):
252            """Return the shapeids covered by the region that has to be redrawn
253    
254            Call the layer's ShapesInRegion method to determine the ids so
255            that it can use the quadtree.
256            """
257            # FIXME: the quad-tree should be built from the projected
258            # coordinates not the lat-long ones because it's not trivial to
259            # determine an appropriate rectangle in lat-long for a given
260            # rectangle in projected coordinates which we have to start from
261            # here.
262            proj = self.map.projection
263            if proj is not None:
264                inverse = proj.Inverse
265            else:
266                inverse = None
267    
268            scale = self.scale
269            offx, offy = self.offset
270            xs = []
271            ys = []
272            x, y, width, height = self.update_region
273            for winx, winy in ((x, y), (x + width, y),
274                               (x + width, y + height), (x, y + height)):
275                px = (winx - offx) / scale
276                py = -(winy - offy) / scale
277                if inverse:
278                    px, py = inverse(px, py)
279                xs.append(px)
280                ys.append(py)
281            left = min(xs)
282            right = max(xs)
283            top = max(ys)
284            bottom = min(ys)
285    
286            return layer.ShapesInRegion((left, bottom, right, top))
287    
288    
289  class PrinterRender(MapRenderer):  class PrinterRender(MapRenderer):

Legend:
Removed from v.76  
changed lines
  Added in v.374

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26