/[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 6 by bh, Tue Aug 28 15:41:52 2001 UTC revision 416 by jonathan, Wed Feb 19 16:53:08 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001 by Intevation GmbH  # Copyright (c) 2001, 2002 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4    # Jonathan Coles <[email protected]>
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 13  from wxPython.wx import wxPoint, wxColou Line 14  from wxPython.wx import wxPoint, wxColou
14    
15  from wxproj import draw_polygon_shape  from wxproj import draw_polygon_shape
16    
17    from Thuban import _
18    
19  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \
20       SHAPETYPE_POINT       SHAPETYPE_POINT
21  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
22       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE
23    
24    from Thuban.Model.classification import Classification
25    from Thuban.Model.color import Color
26    
27    
28  class MapRenderer:  class MapRenderer:
29    
# Line 63  class MapRenderer: Line 69  class MapRenderer:
69          scale = self.scale          scale = self.scale
70          offx, offy = self.offset          offx, offy = self.offset
71    
         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  
         if stroke is None:  
             pen = wxTRANSPARENT_PEN  
         else:  
             color = wxColour(stroke.red * 255,  
                              stroke.green * 255,  
                              stroke.blue * 255)  
             pen = wxPen(color, 1, wxSOLID)  
   
72          map_proj = self.map.projection          map_proj = self.map.projection
73          layer_proj = layer.projection          layer_proj = layer.projection
74    
75          shapetype = layer.ShapeType()          shapetype = layer.ShapeType()
76    
77          if shapetype == SHAPETYPE_POLYGON:          brush = wxTRANSPARENT_BRUSH
78              for i in range(layer.NumShapes()):          pen   = wxTRANSPARENT_PEN
79    
80            old_prop = None
81            for i in self.layer_ids(layer):
82                value = None
83                shape = layer.Shape(i)
84                lc = layer.GetClassification()
85                field = lc.field
86    
87                if field is not None:
88                    record = layer.table.read_record(i)
89                    if record is not None:
90                        value = record[field]
91    
92                #
93                # if the above statements fail 'value' should
94                # be null, at which point this call will
95                # at least retreive the NullData
96                #
97                prop = lc.GetProperties(value)
98    
99                if prop != old_prop:
100                    old_prop = prop
101    
102                    if shapetype == SHAPETYPE_ARC:
103                        fill = Color.None
104                    else:
105                        fill = prop.GetFill()
106        
107                    if fill is Color.None:
108                        brush = wxTRANSPARENT_BRUSH
109                    else:
110                        color = wxColour(fill.red * 255,
111                                         fill.green * 255,
112                                         fill.blue * 255)
113                        brush = wxBrush(color, wxSOLID)
114        
115                    stroke = prop.GetStroke()
116                    stroke_width = prop.GetStrokeWidth()
117                    if stroke is Color.None:
118                        pen = wxTRANSPARENT_PEN
119                    else:
120                        color = wxColour(stroke.red * 255,
121                                         stroke.green * 255,
122                                         stroke.blue * 255)
123                        pen = wxPen(color, stroke_width, wxSOLID)
124        
125                if shapetype == SHAPETYPE_POINT:
126                    self.dc.SetBrush(brush)
127                    self.dc.SetPen(pen)
128                    self.draw_point_shape(layer, i)
129                else:
130                  self.draw_polygon_shape(layer, i, pen, brush)                  self.draw_polygon_shape(layer, i, pen, brush)
131          else:  
132              self.dc.SetBrush(brush)      def layer_ids(self, layer):
133              self.dc.SetPen(pen)          """Return the shape ids of the given layer that have to be drawn.
134              if shapetype == SHAPETYPE_ARC:          
135                  f = self.draw_arc_shape          The default implementation simply returns all ids in the layer.
136              elif shapetype == SHAPETYPE_POINT:          Override in derived classes to be more precise.
137                  f = self.draw_point_shape          """
138              for i in range(layer.NumShapes()):          return range(layer.NumShapes())
                 f(layer, i)  
139    
140      def draw_polygon_shape(self, layer, index, pen, brush):      def draw_polygon_shape(self, layer, index, pen, brush):
141          offx, offy = self.offset                  offx, offy = self.offset        
# Line 182  class ScreenRenderer(MapRenderer): Line 221  class ScreenRenderer(MapRenderer):
221      # On the screen we want to see only visible layers by default      # On the screen we want to see only visible layers by default
222      honor_visibility = 1      honor_visibility = 1
223            
224      def RenderMap(self, map, selected_layer, selected_shape):      def RenderMap(self, map, region, selected_layer, selected_shape):
225            """Render the map.
226    
227            Only the given region (a tuple in window coordinates as returned
228            by a wxrect's asTuple method) needs to be redrawn. Highlight the
229            shape with id selected_shape in the selected_layer.
230            """
231            self.update_region = region
232          self.selected_layer = selected_layer          self.selected_layer = selected_layer
233          self.selected_shape = selected_shape          self.selected_shape = selected_shape
234          self.render_map(map)          self.render_map(map)
# Line 197  class ScreenRenderer(MapRenderer): Line 243  class ScreenRenderer(MapRenderer):
243              index = self.selected_shape              index = self.selected_shape
244              if shapetype == SHAPETYPE_POLYGON:              if shapetype == SHAPETYPE_POLYGON:
245                  self.draw_polygon_shape(layer, index, pen, brush)                  self.draw_polygon_shape(layer, index, pen, brush)
246                elif shapetype == SHAPETYPE_ARC:
247                    self.draw_polygon_shape(layer, index, pen, None)
248              else:              else:
249                  self.dc.SetBrush(brush)                  self.dc.SetBrush(brush)
250                  self.dc.SetPen(pen)                  self.dc.SetPen(pen)
251                  if shapetype == SHAPETYPE_ARC:                  if shapetype == SHAPETYPE_POINT:
252                      f = self.draw_arc_shape                      self.draw_point_shape(layer, index)
253                  elif shapetype == SHAPETYPE_POINT:                  else:
254                      f = self.draw_point_shape                      raise TypeError(_("Unhandled shape type %s") % shapetype)
255                  f(layer, index)  
256        def layer_ids(self, layer):
257            """Return the shapeids covered by the region that has to be redrawn
258    
259            Call the layer's ShapesInRegion method to determine the ids so
260            that it can use the quadtree.
261            """
262            # FIXME: the quad-tree should be built from the projected
263            # coordinates not the lat-long ones because it's not trivial to
264            # determine an appropriate rectangle in lat-long for a given
265            # rectangle in projected coordinates which we have to start from
266            # here.
267            proj = self.map.projection
268            if proj is not None:
269                inverse = proj.Inverse
270            else:
271                inverse = None
272    
273            scale = self.scale
274            offx, offy = self.offset
275            xs = []
276            ys = []
277            x, y, width, height = self.update_region
278            for winx, winy in ((x, y), (x + width, y),
279                               (x + width, y + height), (x, y + height)):
280                px = (winx - offx) / scale
281                py = -(winy - offy) / scale
282                if inverse:
283                    px, py = inverse(px, py)
284                xs.append(px)
285                ys.append(py)
286            left = min(xs)
287            right = max(xs)
288            top = max(ys)
289            bottom = min(ys)
290    
291            return layer.ShapesInRegion((left, bottom, right, top))
292    
293    
294  class PrinterRender(MapRenderer):  class PrinterRender(MapRenderer):

Legend:
Removed from v.6  
changed lines
  Added in v.416

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26