/[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 2537 by jonathan, Fri Jan 21 14:01:25 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
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', mask = None):
108            if format == 'RAW':
109                image = wxEmptyImage(data[0], data[1])
110                image.SetData(data[2])
111            else:
112                stream = cStringIO.StringIO(data[2])
113                image = wxImageFromStream(stream, raster_format_map[format])
114    
     def draw_raster_data(self, data, format = 'BMP'):  
         stream = cStringIO.StringIO(data)  
         image = wxImageFromStream(stream, raster_format_map[format])  
115          bitmap = wxBitmapFromImage(image)          bitmap = wxBitmapFromImage(image)
116          self.dc.DrawBitmap(bitmap, 0, 0)  
117            if mask is None:
118                self.dc.DrawBitmap(bitmap, int(round(x)), int(round(y)), False)
119            else:
120                # if we are given a mask object, try to pass it to SetMaskColour,
121                # otherwise assume it's a mask image
122                try:
123                    bitmap.SetMaskColour(mask);
124                    self.dc.DrawBitmap(bitmap, int(round(x)), int(round(y)), True)
125                except (TypeError):
126                    # implement using a mask image
127                    raise NotImplementedError
128    
129    
130  class ScreenRenderer(MapRenderer):  class ScreenRenderer(MapRenderer):
# Line 127  class ScreenRenderer(MapRenderer): Line 155  class ScreenRenderer(MapRenderer):
155          return self.render_map_incrementally()          return self.render_map_incrementally()
156    
157      def draw_selection_incrementally(self, layer, selected_shapes):      def draw_selection_incrementally(self, layer, selected_shapes):
158            """Draw the selected shapes in a emphasized way (i.e.
159            with a special pen and brush.
160            The drawing is performed incrementally, that means every
161            n shapes, the user can have interactions with the map.
162            n is currently fixed to 500.
163    
164            layer -- the layer where the shapes belong to.
165            selected_shapes -- a list of the shape-ids representing the
166                               selected shapes for the given layer.
167            """
168          pen = wxPen(wxBLACK, 3, wxSOLID)          pen = wxPen(wxBLACK, 3, wxSOLID)
169          brush = wxBrush(wxBLACK, wxCROSS_HATCH)          brush = wxBrush(wxBLACK, wxCROSS_HATCH)
170    
171          shapetype = layer.ShapeType()          shapetype = layer.ShapeType()
172          useraw, func, param = self.low_level_renderer(layer)          useraw, func, param = self.low_level_renderer(layer)
173          args = (pen, brush)          args = (pen, brush)
174    
175            # for point shapes we need to find out the properties
176            # to determine the size. Based on table and field,
177            # we can find out the properties for object - see below.
178            if shapetype == SHAPETYPE_POINT:
179                lc = layer.GetClassification()
180                field = layer.GetClassificationColumn()
181                table = layer.ShapeStore().Table()
182    
183          count = 0          count = 0
184          for index in selected_shapes:          for index in selected_shapes:
185              count += 1              count += 1
186              shape = layer.Shape(index)              shape = layer.Shape(index)
187    
188                # Get the size of the specific property for this
189                # point
190                if shapetype == SHAPETYPE_POINT and field is not None:
191                    value = table.ReadValue(shape.ShapeID(), field)
192                    group = lc.FindGroup(value)
193                    size = group.GetProperties().GetSize()
194                    args = (pen, brush, size)
195    
196              if useraw:              if useraw:
197                  data = shape.RawData()                  data = shape.RawData()
198              else:              else:
# Line 233  class ExportRenderer(ScreenRenderer): Line 289  class ExportRenderer(ScreenRenderer):
289          self.shifty = (mmaxy - mminy)*0.5 - (ury - lly)*0.5          self.shifty = (mmaxy - mminy)*0.5 - (ury - lly)*0.5
290    
291          self.offset = (offx+self.shiftx, offy+self.shifty)          self.offset = (offx+self.shiftx, offy+self.shifty)
292            self.region = (llx + self.shiftx, lly + self.shifty, urx, ury)
293    
294          # Draw the map          # Draw the map
295          self.dc.BeginDrawing()          self.dc.BeginDrawing()

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26