/[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 686 by bh, Wed Apr 16 13:22:25 2003 UTC revision 798 by jonathan, Wed Apr 30 17:02:04 2003 UTC
# Line 25  from Thuban.Model.label import ALIGN_CEN Line 25  from Thuban.Model.label import ALIGN_CEN
25  from Thuban.Model.classification import Classification  from Thuban.Model.classification import Classification
26  from Thuban.Model.color import Color  from Thuban.Model.color import Color
27    
   
28  class MapRenderer:  class MapRenderer:
29    
30      """Class to render a map onto a wxDC"""      """Class to render a map onto a wxDC"""
# Line 49  class MapRenderer: Line 48  class MapRenderer:
48          """          """
49          # resolution in pixel/inch          # resolution in pixel/inch
50    
         assert scale > 0  
   
51          self.dc = dc          self.dc = dc
52          self.scale = scale          self.scale = scale
53          self.offset = offset          self.offset = offset
# Line 82  class MapRenderer: Line 79  class MapRenderer:
79          pen   = wxTRANSPARENT_PEN          pen   = wxTRANSPARENT_PEN
80    
81          old_prop = None          old_prop = None
82            old_group = None
83          lc = layer.GetClassification()          lc = layer.GetClassification()
84          field = lc.GetField()          field = lc.GetField()
85            defaultGroup = lc.GetDefaultGroup()
86    
87    
88          if shapetype != SHAPETYPE_POINT:          if shapetype != SHAPETYPE_POINT:
89              polygon_render_param = self.polygon_render_param(layer)              polygon_render_param = self.polygon_render_param(layer)
90    
91            if shapetype == SHAPETYPE_POINT:
92                draw_func = lambda i: \
93                       self.draw_point_shape(layer, i)
94            else:
95                draw_func = lambda i: \
96                       self.draw_polygon_shape(polygon_render_param, i, pen, brush)
97                
98          for i in self.layer_ids(layer):          for i in self.layer_ids(layer):
             value = None  
   
             if field is not None:  
                 try:  
                     record = layer.table.read_record(i)  
                     if record is not None:  
                         value = record[field]  
                 except:  
                     pass  
   
                 #  
                 # if the above statements fail 'value' should  
                 # be null, at which point this call will  
                 # at least retreive the NullData  
                 #  
   
                 group = lc.FindGroup(value)  
99    
100                  #prop = lc.GetProperties(value)              if field is None:
101                    group = defaultGroup
102              else:              else:
103                  group = lc.GetDefaultGroup()                  record = layer.table.read_record(i)
104                    assert record is not None
105                    group = lc.FindGroup(record[field])
106    
107    
108              if not group.IsVisible():              if not group.IsVisible():
109                  continue                  continue
110    
             prop = group.GetProperties()  
111    
112              # don't recreate new objects if they are the same as before              # don't recreate new objects if they are the same as before
113              if prop != old_prop:              if group is not old_group:
114                  old_prop = prop                  old_group = group
115    
116                  if shapetype == SHAPETYPE_ARC:                  prop = group.GetProperties()
117                      fill = Color.Transparent  
118                  else:                  if prop != old_prop:
119                      fill = prop.GetFill()                      old_prop = prop
120    
121                        if shapetype == SHAPETYPE_ARC:
122                  if fill is Color.Transparent:                          fill = Color.Transparent
123                      brush = wxTRANSPARENT_BRUSH                      else:
124                  else:                          fill = prop.GetFill()
125                      color = Color2wxColour(fill)  
126                      brush = wxBrush(color, wxSOLID)  
127                        if fill is Color.Transparent:
128                  stroke = prop.GetLineColor()                          brush = wxTRANSPARENT_BRUSH
129                  stroke_width = prop.GetLineWidth()                      else:
130                  if stroke is Color.Transparent:                          color = Color2wxColour(fill)
131                      pen = wxTRANSPARENT_PEN                          brush = wxBrush(color, wxSOLID)
132                  else:  
133                      color = Color2wxColour(stroke)                      stroke = prop.GetLineColor()
134                      pen = wxPen(color, stroke_width, wxSOLID)                      stroke_width = prop.GetLineWidth()
135                        if stroke is Color.Transparent:
136                            pen = wxTRANSPARENT_PEN
137              if shapetype == SHAPETYPE_POINT:                      else:
138                  self.dc.SetBrush(brush)                          color = Color2wxColour(stroke)
139                  self.dc.SetPen(pen)                          pen = wxPen(color, stroke_width, wxSOLID)
140                  self.draw_point_shape(layer, i)  
141              else:                      if shapetype == SHAPETYPE_POINT:
142                  self.draw_polygon_shape(polygon_render_param, i, pen, brush)                          self.dc.SetBrush(brush)
143                            self.dc.SetPen(pen)
144    
145                draw_func(i)
146    
147      def layer_ids(self, layer):      def layer_ids(self, layer):
148          """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 171  class MapRenderer: Line 165  class MapRenderer:
165          draw_polygon_shape(draw_polygon_info, index, pen, brush)          draw_polygon_shape(draw_polygon_info, index, pen, brush)
166    
167      def projected_points(self, layer, index):      def projected_points(self, layer, index):
168          proj = self.map.projection          proj = self.map.GetProjection()
169          if proj is not None:          if proj is not None:
170              forward = proj.Forward              forward = proj.Forward
171          else:          else:
172              forward = None              forward = None
173          proj = layer.projection          proj = layer.GetProjection()
174          if proj is not None:          if proj is not None:
175              inverse = proj.Inverse              inverse = proj.Inverse
176          else:          else:

Legend:
Removed from v.686  
changed lines
  Added in v.798

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26