/[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 144 by bh, Tue May 7 14:54:02 2002 UTC revision 432 by jonathan, Mon Feb 24 18:47:36 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 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  
         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)  
   
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 self.layer_ids(layer):          pen   = wxTRANSPARENT_PEN
79    
80            old_prop = None
81            for i in self.layer_ids(layer):
82                value = None
83                lc = layer.GetClassification()
84                field = lc.field
85    
86                if field is not None:
87                    record = layer.table.read_record(i)
88                    if record is not None:
89                        value = record[field]
90    
91                #
92                # if the above statements fail 'value' should
93                # be null, at which point this call will
94                # at least retreive the NullData
95                #
96                prop = lc.GetClassData(value)
97    
98                if prop != old_prop:
99                    old_prop = prop
100    
101                    if shapetype == SHAPETYPE_ARC:
102                        fill = Color.None
103                    else:
104                        fill = prop.GetFill()
105        
106                    if fill is Color.None:
107                        brush = wxTRANSPARENT_BRUSH
108                    else:
109                        color = wxColour(fill.red * 255,
110                                         fill.green * 255,
111                                         fill.blue * 255)
112                        brush = wxBrush(color, wxSOLID)
113        
114                    stroke = prop.GetStroke()
115                    stroke_width = prop.GetStrokeWidth()
116                    if stroke is Color.None:
117                        pen = wxTRANSPARENT_PEN
118                    else:
119                        color = wxColour(stroke.red * 255,
120                                         stroke.green * 255,
121                                         stroke.blue * 255)
122                        pen = wxPen(color, stroke_width, wxSOLID)
123        
124                if shapetype == SHAPETYPE_POINT:
125                    self.dc.SetBrush(brush)
126                    self.dc.SetPen(pen)
127                    self.draw_point_shape(layer, i)
128                else:
129                  self.draw_polygon_shape(layer, i, pen, brush)                  self.draw_polygon_shape(layer, i, pen, brush)
         elif shapetype == SHAPETYPE_ARC:  
             for i in self.layer_ids(layer):  
                 self.draw_polygon_shape(layer, i, pen, None)  
         else:  
             self.dc.SetBrush(brush)  
             self.dc.SetPen(pen)  
             if shapetype == SHAPETYPE_ARC:  
                 f = self.draw_arc_shape  
             elif shapetype == SHAPETYPE_POINT:  
                 f = self.draw_point_shape  
             for i in self.layer_ids(layer):  
                 f(layer, i)  
130    
131      def layer_ids(self, layer):      def layer_ids(self, layer):
132          """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 197  class ScreenRenderer(MapRenderer): Line 223  class ScreenRenderer(MapRenderer):
223      def RenderMap(self, map, region, selected_layer, selected_shape):      def RenderMap(self, map, region, selected_layer, selected_shape):
224          """Render the map.          """Render the map.
225    
226          Only the given region (a wxRect in window coordinates) needs to          Only the given region (a tuple in window coordinates as returned
227          be redrawn. Highlight the shape with id selected_shape in the          by a wxrect's asTuple method) needs to be redrawn. Highlight the
228          selected_layer.          shape with id selected_shape in the selected_layer.
229          """          """
230          self.update_region = region          self.update_region = region
231          self.selected_layer = selected_layer          self.selected_layer = selected_layer
# Line 216  class ScreenRenderer(MapRenderer): Line 242  class ScreenRenderer(MapRenderer):
242              index = self.selected_shape              index = self.selected_shape
243              if shapetype == SHAPETYPE_POLYGON:              if shapetype == SHAPETYPE_POLYGON:
244                  self.draw_polygon_shape(layer, index, pen, brush)                  self.draw_polygon_shape(layer, index, pen, brush)
245                elif shapetype == SHAPETYPE_ARC:
246                    self.draw_polygon_shape(layer, index, pen, None)
247              else:              else:
248                  self.dc.SetBrush(brush)                  self.dc.SetBrush(brush)
249                  self.dc.SetPen(pen)                  self.dc.SetPen(pen)
250                  if shapetype == SHAPETYPE_ARC:                  if shapetype == SHAPETYPE_POINT:
251                      f = self.draw_arc_shape                      self.draw_point_shape(layer, index)
252                  elif shapetype == SHAPETYPE_POINT:                  else:
253                      f = self.draw_point_shape                      raise TypeError(_("Unhandled shape type %s") % shapetype)
                 f(layer, index)  
254    
255      def layer_ids(self, layer):      def layer_ids(self, layer):
256          """Return the shapeids covered by the region that has to be redrawn          """Return the shapeids covered by the region that has to be redrawn
# Line 246  class ScreenRenderer(MapRenderer): Line 273  class ScreenRenderer(MapRenderer):
273          offx, offy = self.offset          offx, offy = self.offset
274          xs = []          xs = []
275          ys = []          ys = []
276          x, y, width, height = self.update_region.asTuple()          x, y, width, height = self.update_region
277          for winx, winy in ((x, y), (x + width, y),          for winx, winy in ((x, y), (x + width, y),
278                             (x + width, y + height), (x, y + height)):                             (x + width, y + height), (x, y + height)):
279              px = (winx - offx) / scale              px = (winx - offx) / scale

Legend:
Removed from v.144  
changed lines
  Added in v.432

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26