/[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 1927 by bh, Mon Nov 10 16:57:35 2003 UTC revision 2551 by jonathan, Thu Jan 27 14:19:41 2005 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH  # Copyright (c) 2001-2004 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]> (2001-2003)
4  # Jonathan Coles <[email protected]>  # Jonathan Coles <[email protected]> (2003)
5  # Frank Koormann <[email protected]>  # Frank Koormann <[email protected]> (2003)
6    # Jan-Oliver Wagner <[email protected]> (2003, 2004)
7  #  #
8  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
9  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 20  from Thuban import _ Line 21  from Thuban import _
21  from wxPython.wx import wxPoint, wxRect, wxPen, wxBrush, wxFont, \  from wxPython.wx import wxPoint, wxRect, wxPen, wxBrush, wxFont, \
22      wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \      wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \
23      wxBLACK_PEN, wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL, \      wxBLACK_PEN, wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL, \
24      wxBitmapFromImage, wxImageFromStream, wxBITMAP_TYPE_BMP, wxBITMAP_TYPE_JPEG      wxBitmapFromImage, wxImageFromStream, wxBITMAP_TYPE_BMP, \
25        wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG, wxBITMAP_TYPE_TIF, \
26        wxBITMAP_TYPE_GIF, wxEmptyImage, wxMask
27    
28  from wxproj import draw_polygon_shape, draw_polygon_init  from wxproj import draw_polygon_shape, draw_polygon_init
29    
# Line 36  import Thuban.Model.resource Line 39  import Thuban.Model.resource
39    
40  from baserenderer import BaseRenderer  from baserenderer import BaseRenderer
41    
42    from math import floor
43    
44    from types import StringType
45    
46    
47  # Map the strings used for the format parameter of the draw_raster_data  # Map the strings used for the format parameter of the draw_raster_data
48  # method to the appropriate wxWindows constants  # method to the appropriate wxWindows constants
49  raster_format_map = {  raster_format_map = {
50      "BMP": wxBITMAP_TYPE_BMP,      "BMP": wxBITMAP_TYPE_BMP,
51      "JPEG": wxBITMAP_TYPE_JPEG,      "JPEG": wxBITMAP_TYPE_JPEG,
52        "PNG": wxBITMAP_TYPE_PNG,
53        "TIFF": wxBITMAP_TYPE_TIF,
54        "GIF": wxBITMAP_TYPE_GIF,
55      }      }
56    
57  class MapRenderer(BaseRenderer):  class MapRenderer(BaseRenderer):
# Line 51  class MapRenderer(BaseRenderer): Line 61  class MapRenderer(BaseRenderer):
61      TRANSPARENT_PEN = wxTRANSPARENT_PEN      TRANSPARENT_PEN = wxTRANSPARENT_PEN
62      TRANSPARENT_BRUSH = wxTRANSPARENT_BRUSH      TRANSPARENT_BRUSH = wxTRANSPARENT_BRUSH
63    
64      make_point = wxPoint      def make_point(self, x, y):
65            return wxPoint(int(round(x)), int(round(y)))
66    
67      def tools_for_property(self, prop):      def tools_for_property(self, prop):
68          fill = prop.GetFill()          fill = prop.GetFill()
# Line 90  class MapRenderer(BaseRenderer): Line 101  class MapRenderer(BaseRenderer):
101              return BaseRenderer.low_level_renderer(self, layer)              return BaseRenderer.low_level_renderer(self, layer)
102    
103      def label_font(self):      def label_font(self):
104          return wxFont(self.resolution * 10, wxSWISS, wxNORMAL, wxNORMAL)          return wxFont(int(round(self.resolution * 10)), wxSWISS, wxNORMAL,
105                          wxNORMAL)
106    
107        def draw_raster_data(self, x,y, data, format = 'BMP'):
108    
109            mask = None
110            if format == 'RAW':
111                image = wxEmptyImage(data[0], data[1])
112                image.SetData(data[2][0])
113                if data[2][1] is not None:
114                    mask = wxEmptyImage(data[0], data[1])
115                    mask.SetData(data[2][1])
116            else:
117                stream = cStringIO.StringIO(data[2][0])
118                image = wxImageFromStream(stream, raster_format_map[format])
119                if data[2][1] is not None:
120                    stream = cStringIO.StringIO(data[2][1])
121                    mask = wxImageFromStream(stream, raster_format_map[format])
122    
     def draw_raster_data(self, data, format = 'BMP'):  
         stream = cStringIO.StringIO(data)  
         image = wxImageFromStream(stream, raster_format_map[format])  
123          bitmap = wxBitmapFromImage(image)          bitmap = wxBitmapFromImage(image)
124          self.dc.DrawBitmap(bitmap, 0, 0)  
125            if mask is None:
126                self.dc.DrawBitmap(bitmap, int(round(x)), int(round(y)), False)
127            else:
128                # if we are given a mask object, try to pass it to SetMaskColour,
129                # otherwise assume it's a mask image
130                try:
131                    bitmap.SetMask(wxMask(wxBitmapFromImage(mask, 1)))
132                    self.dc.DrawBitmap(bitmap, int(round(x)), int(round(y)), True)
133                except (TypeError):
134                    # implement using a mask image
135                    raise NotImplementedError
136    
137    
138  class ScreenRenderer(MapRenderer):  class ScreenRenderer(MapRenderer):
# Line 127  class ScreenRenderer(MapRenderer): Line 163  class ScreenRenderer(MapRenderer):
163          return self.render_map_incrementally()          return self.render_map_incrementally()
164    
165      def draw_selection_incrementally(self, layer, selected_shapes):      def draw_selection_incrementally(self, layer, selected_shapes):
166            """Draw the selected shapes in a emphasized way (i.e.
167            with a special pen and brush.
168            The drawing is performed incrementally, that means every
169            n shapes, the user can have interactions with the map.
170            n is currently fixed to 500.
171    
172            layer -- the layer where the shapes belong to.
173            selected_shapes -- a list of the shape-ids representing the
174                               selected shapes for the given layer.
175            """
176          pen = wxPen(wxBLACK, 3, wxSOLID)          pen = wxPen(wxBLACK, 3, wxSOLID)
177          brush = wxBrush(wxBLACK, wxCROSS_HATCH)          brush = wxBrush(wxBLACK, wxCROSS_HATCH)
178    
179          shapetype = layer.ShapeType()          shapetype = layer.ShapeType()
180          useraw, func, param = self.low_level_renderer(layer)          useraw, func, param = self.low_level_renderer(layer)
181          args = (pen, brush)          args = (pen, brush)
182    
183            # for point shapes we need to find out the properties
184            # to determine the size. Based on table and field,
185            # we can find out the properties for object - see below.
186            if shapetype == SHAPETYPE_POINT:
187                lc = layer.GetClassification()
188                field = layer.GetClassificationColumn()
189                table = layer.ShapeStore().Table()
190    
191          count = 0          count = 0
192          for index in selected_shapes:          for index in selected_shapes:
193              count += 1              count += 1
194              shape = layer.Shape(index)              shape = layer.Shape(index)
195    
196                # Get the size of the specific property for this
197                # point
198                if shapetype == SHAPETYPE_POINT and field is not None:
199                    value = table.ReadValue(shape.ShapeID(), field)
200                    group = lc.FindGroup(value)
201                    size = group.GetProperties().GetSize()
202                    args = (pen, brush, size)
203    
204              if useraw:              if useraw:
205                  data = shape.RawData()                  data = shape.RawData()
206              else:              else:
# Line 233  class ExportRenderer(ScreenRenderer): Line 297  class ExportRenderer(ScreenRenderer):
297          self.shifty = (mmaxy - mminy)*0.5 - (ury - lly)*0.5          self.shifty = (mmaxy - mminy)*0.5 - (ury - lly)*0.5
298    
299          self.offset = (offx+self.shiftx, offy+self.shifty)          self.offset = (offx+self.shiftx, offy+self.shifty)
300            self.region = (llx + self.shiftx, lly + self.shifty, urx, ury)
301    
302          # Draw the map          # Draw the map
303          self.dc.BeginDrawing()          self.dc.BeginDrawing()

Legend:
Removed from v.1927  
changed lines
  Added in v.2551

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26