/[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 1866 by bh, Mon Oct 27 13:01:58 2003 UTC revision 2431 by joey, Sun Dec 5 15:05:02 2004 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      wxBitmapFromImage, wxImageFromStream, wxBITMAP_TYPE_BMP, \
25        wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG, wxBITMAP_TYPE_TIF, wxBITMAP_TYPE_GIF
26    
27  from wxproj import draw_polygon_shape, draw_polygon_init  from wxproj import draw_polygon_shape, draw_polygon_init
28    
# Line 36  import Thuban.Model.resource Line 38  import Thuban.Model.resource
38    
39  from baserenderer import BaseRenderer  from baserenderer import BaseRenderer
40    
41    
42    # Map the strings used for the format parameter of the draw_raster_data
43    # method to the appropriate wxWindows constants
44    raster_format_map = {
45        "BMP": wxBITMAP_TYPE_BMP,
46        "JPEG": wxBITMAP_TYPE_JPEG,
47        "PNG": wxBITMAP_TYPE_PNG,
48        "TIFF": wxBITMAP_TYPE_TIF,
49        "GIF": wxBITMAP_TYPE_GIF,
50        }
51    
52  class MapRenderer(BaseRenderer):  class MapRenderer(BaseRenderer):
53    
54      """Class to render a map onto a wxDC"""      """Class to render a map onto a wxDC"""
# Line 43  class MapRenderer(BaseRenderer): Line 56  class MapRenderer(BaseRenderer):
56      TRANSPARENT_PEN = wxTRANSPARENT_PEN      TRANSPARENT_PEN = wxTRANSPARENT_PEN
57      TRANSPARENT_BRUSH = wxTRANSPARENT_BRUSH      TRANSPARENT_BRUSH = wxTRANSPARENT_BRUSH
58    
59      make_point = wxPoint      def make_point(self, x, y):
60            return wxPoint(int(round(x)), int(round(y)))
61    
62      def tools_for_property(self, prop):      def tools_for_property(self, prop):
63          fill = prop.GetFill()          fill = prop.GetFill()
# Line 82  class MapRenderer(BaseRenderer): Line 96  class MapRenderer(BaseRenderer):
96              return BaseRenderer.low_level_renderer(self, layer)              return BaseRenderer.low_level_renderer(self, layer)
97    
98      def label_font(self):      def label_font(self):
99          return wxFont(self.resolution * 10, wxSWISS, wxNORMAL, wxNORMAL)          return wxFont(int(round(self.resolution * 10)), wxSWISS, wxNORMAL,
100                          wxNORMAL)
101    
102      def draw_raster_data(self, data):      def draw_raster_data(self, data, format = 'BMP'):
103          stream = cStringIO.StringIO(data)          stream = cStringIO.StringIO(data)
104          image = wxImageFromStream(stream, wxBITMAP_TYPE_BMP)          image = wxImageFromStream(stream, raster_format_map[format])
105          bitmap = wxBitmapFromImage(image)          bitmap = wxBitmapFromImage(image)
106          self.dc.DrawBitmap(bitmap, 0, 0)          self.dc.DrawBitmap(bitmap, 0, 0)
107    
# Line 119  class ScreenRenderer(MapRenderer): Line 134  class ScreenRenderer(MapRenderer):
134          return self.render_map_incrementally()          return self.render_map_incrementally()
135    
136      def draw_selection_incrementally(self, layer, selected_shapes):      def draw_selection_incrementally(self, layer, selected_shapes):
137            """Draw the selected shapes in a emphasized way (i.e.
138            with a special pen and brush.
139            The drawing is performed incrementally, that means every
140            n shapes, the user can have interactions with the map.
141            n is currently fixed to 500.
142    
143            layer -- the layer where the shapes belong to.
144            selected_shapes -- a list of the shape-ids representing the
145                               selected shapes for the given layer.
146            """
147          pen = wxPen(wxBLACK, 3, wxSOLID)          pen = wxPen(wxBLACK, 3, wxSOLID)
148          brush = wxBrush(wxBLACK, wxCROSS_HATCH)          brush = wxBrush(wxBLACK, wxCROSS_HATCH)
149    
150          shapetype = layer.ShapeType()          shapetype = layer.ShapeType()
151          useraw, func, param = self.low_level_renderer(layer)          useraw, func, param = self.low_level_renderer(layer)
152          args = (pen, brush)          args = (pen, brush)
153    
154            # for point shapes we need to find out the properties
155            # to determine the size. Based on table and field,
156            # we can find out the properties for object - see below.
157            if shapetype == SHAPETYPE_POINT:
158                lc = layer.GetClassification()
159                field = layer.GetClassificationColumn()
160                table = layer.ShapeStore().Table()
161    
162          count = 0          count = 0
163          for index in selected_shapes:          for index in selected_shapes:
164              count += 1              count += 1
165              shape = layer.Shape(index)              shape = layer.Shape(index)
166    
167                # Get the size of the specific property for this
168                # point
169                if shapetype == SHAPETYPE_POINT:
170                    value = table.ReadValue(shape.ShapeID(), field)
171                    group = lc.FindGroup(value)
172                    size = group.GetProperties().GetSize()
173                    args = (pen, brush, size)
174    
175              if useraw:              if useraw:
176                  data = shape.RawData()                  data = shape.RawData()
177              else:              else:

Legend:
Removed from v.1866  
changed lines
  Added in v.2431

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26