/[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 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 self.layer_ids(layer):          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)
         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)  
126    
127      def layer_ids(self, layer):      def layer_ids(self, layer):
128          """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 219  class ScreenRenderer(MapRenderer):
219      def RenderMap(self, map, region, selected_layer, selected_shape):      def RenderMap(self, map, region, selected_layer, selected_shape):
220          """Render the map.          """Render the map.
221    
222          Only the given region (a wxRect in window coordinates) needs to          Only the given region (a tuple in window coordinates as returned
223          be redrawn. Highlight the shape with id selected_shape in the          by a wxrect's asTuple method) needs to be redrawn. Highlight the
224          selected_layer.          shape with id selected_shape in the selected_layer.
225          """          """
226          self.update_region = region          self.update_region = region
227          self.selected_layer = selected_layer          self.selected_layer = selected_layer
# Line 216  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)
                 f(layer, index)  
250    
251      def layer_ids(self, layer):      def layer_ids(self, layer):
252          """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 269  class ScreenRenderer(MapRenderer):
269          offx, offy = self.offset          offx, offy = self.offset
270          xs = []          xs = []
271          ys = []          ys = []
272          x, y, width, height = self.update_region.asTuple()          x, y, width, height = self.update_region
273          for winx, winy in ((x, y), (x + width, y),          for winx, winy in ((x, y), (x + width, y),
274                             (x + width, y + height), (x, y + height)):                             (x + width, y + height), (x, y + height)):
275              px = (winx - offx) / scale              px = (winx - offx) / scale

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26