/[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 882 by jonathan, Fri May 9 16:34:28 2003 UTC
# Line 8  Line 8 
8    
9  __version__ = "$Revision$"  __version__ = "$Revision$"
10    
11    from Thuban import _
12    
13  from wxPython.wx import wxPoint, wxPen, wxBrush, wxFont, \  from wxPython.wx import wxPoint, wxPen, wxBrush, wxFont, \
14       wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \       wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \
15       wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL       wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL
16    
17  from wxproj import draw_polygon_shape, draw_polygon_init  from wxproj import draw_polygon_shape, draw_polygon_init
18    
19  from Thuban import _  from Thuban.UI.common import Color2wxColour
 from Thuban.UI.common import *  
20    
21  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \
22       SHAPETYPE_POINT       SHAPETYPE_POINT
# Line 25  from Thuban.Model.label import ALIGN_CEN Line 26  from Thuban.Model.label import ALIGN_CEN
26  from Thuban.Model.classification import Classification  from Thuban.Model.classification import Classification
27  from Thuban.Model.color import Color  from Thuban.Model.color import Color
28    
   
29  class MapRenderer:  class MapRenderer:
30    
31      """Class to render a map onto a wxDC"""      """Class to render a map onto a wxDC"""
# Line 49  class MapRenderer: Line 49  class MapRenderer:
49          """          """
50          # resolution in pixel/inch          # resolution in pixel/inch
51    
         assert scale > 0  
   
52          self.dc = dc          self.dc = dc
53          self.scale = scale          self.scale = scale
54          self.offset = offset          self.offset = offset
# Line 82  class MapRenderer: Line 80  class MapRenderer:
80          pen   = wxTRANSPARENT_PEN          pen   = wxTRANSPARENT_PEN
81    
82          old_prop = None          old_prop = None
83            old_group = None
84          lc = layer.GetClassification()          lc = layer.GetClassification()
85          field = lc.GetField()          field = lc.GetField()
86            defaultGroup = lc.GetDefaultGroup()
87    
88    
89          if shapetype != SHAPETYPE_POINT:          if shapetype != SHAPETYPE_POINT:
90              polygon_render_param = self.polygon_render_param(layer)              polygon_render_param = self.polygon_render_param(layer)
91    
92            if shapetype == SHAPETYPE_POINT:
93                draw_func = lambda i: \
94                       self.draw_point_shape(layer, i)
95            else:
96                draw_func = lambda i: \
97                       self.draw_polygon_shape(polygon_render_param, i, pen, brush)
98                
99          for i in self.layer_ids(layer):          for i in self.layer_ids(layer):
             value = None  
100    
101              if field is not None:              if field is None:
102                  try:                  group = defaultGroup
                     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)  
   
                 #prop = lc.GetProperties(value)  
103              else:              else:
104                  group = lc.GetDefaultGroup()                  record = layer.table.ReadRowAsDict(i)
105                    assert record is not None
106                    group = lc.FindGroup(record[field])
107    
108    
109              if not group.IsVisible():              if not group.IsVisible():
110                  continue                  continue
111    
             prop = group.GetProperties()  
112    
113              # don't recreate new objects if they are the same as before              # don't recreate new objects if they are the same as before
114              if prop != old_prop:              if group is not old_group:
115                  old_prop = prop                  old_group = group
116    
117                  if shapetype == SHAPETYPE_ARC:                  prop = group.GetProperties()
118                      fill = Color.Transparent  
119                  else:                  if prop != old_prop:
120                      fill = prop.GetFill()                      old_prop = prop
121    
122                        if shapetype == SHAPETYPE_ARC:
123                  if fill is Color.Transparent:                          fill = Color.Transparent
124                      brush = wxTRANSPARENT_BRUSH                      else:
125                  else:                          fill = prop.GetFill()
126                      color = Color2wxColour(fill)  
127                      brush = wxBrush(color, wxSOLID)  
128                        if fill is Color.Transparent:
129                  stroke = prop.GetLineColor()                          brush = wxTRANSPARENT_BRUSH
130                  stroke_width = prop.GetLineWidth()                      else:
131                  if stroke is Color.Transparent:                          color = Color2wxColour(fill)
132                      pen = wxTRANSPARENT_PEN                          brush = wxBrush(color, wxSOLID)
133                  else:  
134                      color = Color2wxColour(stroke)                      stroke = prop.GetLineColor()
135                      pen = wxPen(color, stroke_width, wxSOLID)                      stroke_width = prop.GetLineWidth()
136                        if stroke is Color.Transparent:
137                            pen = wxTRANSPARENT_PEN
138              if shapetype == SHAPETYPE_POINT:                      else:
139                  self.dc.SetBrush(brush)                          color = Color2wxColour(stroke)
140                  self.dc.SetPen(pen)                          pen = wxPen(color, stroke_width, wxSOLID)
141                  self.draw_point_shape(layer, i)  
142              else:                      if shapetype == SHAPETYPE_POINT:
143                  self.draw_polygon_shape(polygon_render_param, i, pen, brush)                          self.dc.SetBrush(brush)
144                            self.dc.SetPen(pen)
145    
146                draw_func(i)
147    
148      def layer_ids(self, layer):      def layer_ids(self, layer):
149          """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 166  class MapRenderer:
166          draw_polygon_shape(draw_polygon_info, index, pen, brush)          draw_polygon_shape(draw_polygon_info, index, pen, brush)
167    
168      def projected_points(self, layer, index):      def projected_points(self, layer, index):
169          proj = self.map.projection          proj = self.map.GetProjection()
170          if proj is not None:          if proj is not None:
171              forward = proj.Forward              forward = proj.Forward
172          else:          else:
173              forward = None              forward = None
174          proj = layer.projection          proj = layer.GetProjection()
175          if proj is not None:          if proj is not None:
176              inverse = proj.Inverse              inverse = proj.Inverse
177          else:          else:

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26