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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26