/[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 2394 by jan, Wed Nov 17 22:02:29 2004 UTC revision 2551 by jonathan, Thu Jan 27 14:19:41 2005 UTC
# Line 21  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 37  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 95  class MapRenderer(BaseRenderer): Line 104  class MapRenderer(BaseRenderer):
104          return wxFont(int(round(self.resolution * 10)), wxSWISS, wxNORMAL,          return wxFont(int(round(self.resolution * 10)), wxSWISS, wxNORMAL,
105                        wxNORMAL)                        wxNORMAL)
106    
107      def draw_raster_data(self, data, format = 'BMP'):      def draw_raster_data(self, x,y, data, format = 'BMP'):
108          stream = cStringIO.StringIO(data)  
109          image = wxImageFromStream(stream, raster_format_map[format])          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    
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 162  class ScreenRenderer(MapRenderer): Line 195  class ScreenRenderer(MapRenderer):
195    
196              # Get the size of the specific property for this              # Get the size of the specific property for this
197              # point              # point
198              if shapetype == SHAPETYPE_POINT:              if shapetype == SHAPETYPE_POINT and field is not None:
199                  value = table.ReadValue(shape.ShapeID(), field)                  value = table.ReadValue(shape.ShapeID(), field)
200                  group = lc.FindGroup(value)                  group = lc.FindGroup(value)
201                  size = group.GetProperties().GetSize()                  size = group.GetProperties().GetSize()
# Line 264  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.2394  
changed lines
  Added in v.2551

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26