/[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 394 by jonathan, Mon Feb 10 15:27:13 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, \
21       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE
22    
23    from Thuban.Model.classification import Classification
24    
25    
26  class MapRenderer:  class MapRenderer:
27    
# Line 63  class MapRenderer: Line 67  class MapRenderer:
67          scale = self.scale          scale = self.scale
68          offx, offy = self.offset          offx, offy = self.offset
69    
         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)  
   
70          map_proj = self.map.projection          map_proj = self.map.projection
71          layer_proj = layer.projection          layer_proj = layer.projection
72    
73          shapetype = layer.ShapeType()          shapetype = layer.ShapeType()
74    
75          if shapetype == SHAPETYPE_POLYGON:          brush = wxTRANSPARENT_BRUSH
76              for i in self.layer_ids(layer):          pen   = wxTRANSPARENT_PEN
77    
78            old_prop = None
79            for i in self.layer_ids(layer):
80                value = None
81                shape = layer.Shape(i)
82                lc = layer.classification
83                field = lc.field
84    
85                if field is not None:
86                    record = layer.table.read_record(i)
87                    if record is not None:
88                        value = record[field]
89    
90                #
91                # if the above statements fail 'value' should
92                # be null, at which point this call will
93                # at least retreive the NullData
94                #
95                prop = lc.GetProperties(value)
96    
97                if prop != old_prop:
98                    old_prop = prop
99    
100                    if shapetype == SHAPETYPE_ARC:
101                        fill = None
102                    else:
103                        fill = prop.GetFill()
104        
105                    if fill is None:
106                        brush = wxTRANSPARENT_BRUSH
107                    else:
108                        color = wxColour(fill.red * 255,
109                                         fill.green * 255,
110                                         fill.blue * 255)
111                        brush = wxBrush(color, wxSOLID)
112        
113                    stroke = prop.GetStroke()
114                    stroke_width = prop.GetStrokeWidth()
115                    if stroke is None:
116                        pen = wxTRANSPARENT_PEN
117                    else:
118                        color = wxColour(stroke.red * 255,
119                                         stroke.green * 255,
120                                         stroke.blue * 255)
121                        pen = wxPen(color, stroke_width, wxSOLID)
122        
123                if shapetype == SHAPETYPE_POINT:
124                    self.dc.SetBrush(brush)
125                    self.dc.SetPen(pen)
126                    self.draw_point_shape(layer, i)
127                else:
128                  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)  
129    
130      def layer_ids(self, layer):      def layer_ids(self, layer):
131          """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 222  class ScreenRenderer(MapRenderer):
222      def RenderMap(self, map, region, selected_layer, selected_shape):      def RenderMap(self, map, region, selected_layer, selected_shape):
223          """Render the map.          """Render the map.
224    
225          Only the given region (a wxRect in window coordinates) needs to          Only the given region (a tuple in window coordinates as returned
226          be redrawn. Highlight the shape with id selected_shape in the          by a wxrect's asTuple method) needs to be redrawn. Highlight the
227          selected_layer.          shape with id selected_shape in the selected_layer.
228          """          """
229          self.update_region = region          self.update_region = region
230          self.selected_layer = selected_layer          self.selected_layer = selected_layer
# Line 216  class ScreenRenderer(MapRenderer): Line 241  class ScreenRenderer(MapRenderer):
241              index = self.selected_shape              index = self.selected_shape
242              if shapetype == SHAPETYPE_POLYGON:              if shapetype == SHAPETYPE_POLYGON:
243                  self.draw_polygon_shape(layer, index, pen, brush)                  self.draw_polygon_shape(layer, index, pen, brush)
244                elif shapetype == SHAPETYPE_ARC:
245                    self.draw_polygon_shape(layer, index, pen, None)
246              else:              else:
247                  self.dc.SetBrush(brush)                  self.dc.SetBrush(brush)
248                  self.dc.SetPen(pen)                  self.dc.SetPen(pen)
249                  if shapetype == SHAPETYPE_ARC:                  if shapetype == SHAPETYPE_POINT:
250                      f = self.draw_arc_shape                      self.draw_point_shape(layer, index)
251                  elif shapetype == SHAPETYPE_POINT:                  else:
252                      f = self.draw_point_shape                      raise TypeError(_("Unhandled shape type %s") % shapetype)
                 f(layer, index)  
253    
254      def layer_ids(self, layer):      def layer_ids(self, layer):
255          """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 272  class ScreenRenderer(MapRenderer):
272          offx, offy = self.offset          offx, offy = self.offset
273          xs = []          xs = []
274          ys = []          ys = []
275          x, y, width, height = self.update_region.asTuple()          x, y, width, height = self.update_region
276          for winx, winy in ((x, y), (x + width, y),          for winx, winy in ((x, y), (x + width, y),
277                             (x + width, y + height), (x, y + height)):                             (x + width, y + height), (x, y + height)):
278              px = (winx - offx) / scale              px = (winx - offx) / scale

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26