/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/view.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/view.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1111 by bh, Fri May 30 09:54:48 2003 UTC revision 1221 by jonathan, Tue Jun 17 15:24:45 2003 UTC
# Line 35  from wxPython import wx Line 35  from wxPython import wx
35  from wxproj import point_in_polygon_shape, shape_centroid  from wxproj import point_in_polygon_shape, shape_centroid
36    
37  from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \  from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \
38         LAYER_PROJECTION_CHANGED, \
39       MAP_LAYERS_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED       MAP_LAYERS_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED
40  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \
41       SHAPETYPE_POINT       SHAPETYPE_POINT
# Line 302  class MapCanvas(wxWindow, Publisher): Line 303  class MapCanvas(wxWindow, Publisher):
303          # the map displayed in this canvas. Set with SetMap()          # the map displayed in this canvas. Set with SetMap()
304          self.map = None          self.map = None
305    
306            # current map projection. should only differ from map.projection
307            # when the map's projection is changing and we need access to the
308            # old projection.
309            self.current_map_proj = None
310    
311          # scale and offset describe the transformation from projected          # scale and offset describe the transformation from projected
312          # coordinates to window coordinates.          # coordinates to window coordinates.
313          self.scale = 1.0          self.scale = 1.0
# Line 502  class MapCanvas(wxWindow, Publisher): Line 508  class MapCanvas(wxWindow, Publisher):
508              for channel in redraw_channels:              for channel in redraw_channels:
509                  self.map.Unsubscribe(channel, self.full_redraw)                  self.map.Unsubscribe(channel, self.full_redraw)
510              self.map.Unsubscribe(MAP_PROJECTION_CHANGED,              self.map.Unsubscribe(MAP_PROJECTION_CHANGED,
511                                   self.projection_changed)                                   self.map_projection_changed)
512                self.map.Unsubscribe(LAYER_PROJECTION_CHANGED,
513                                     self.layer_projection_changed)
514          self.map = map          self.map = map
515            self.current_map_proj = self.map.GetProjection()
516          self.selection.ClearSelection()          self.selection.ClearSelection()
517          if self.map is not None:          if self.map is not None:
518              for channel in redraw_channels:              for channel in redraw_channels:
519                  self.map.Subscribe(channel, self.full_redraw)                  self.map.Subscribe(channel, self.full_redraw)
520              self.map.Subscribe(MAP_PROJECTION_CHANGED, self.projection_changed)              self.map.Subscribe(MAP_PROJECTION_CHANGED, self.map_projection_changed)
521                self.map.Subscribe(LAYER_PROJECTION_CHANGED, self.layer_projection_changed)
522          self.FitMapToWindow()          self.FitMapToWindow()
523          # force a redraw. If map is not empty, it's already been called          # force a redraw. If map is not empty, it's already been called
524          # by FitMapToWindow but if map is empty it hasn't been called          # by FitMapToWindow but if map is empty it hasn't been called
# Line 526  class MapCanvas(wxWindow, Publisher): Line 536  class MapCanvas(wxWindow, Publisher):
536          self.bitmap = None          self.bitmap = None
537          self.redraw()          self.redraw()
538    
539      def projection_changed(self, *args):      def map_projection_changed(self, *args):
540          self.FitMapToWindow()  
541            proj = self.current_map_proj
542            self.current_map_proj = self.map.GetProjection()
543    
544            bbox = None
545    
546            if proj is not None and self.current_map_proj is not None:
547                width, height = self.GetSizeTuple()
548                llx, lly = self.win_to_proj(0, height)
549                urx, ury = self.win_to_proj(width, 0)
550                bbox = proj.Inverse(llx, lly) + proj.Inverse(urx, ury)
551                bbox = self.current_map_proj.ForwardBBox(bbox)
552    
553            if bbox is not None:
554                self.FitRectToWindow(bbox)
555            else:
556                self.FitMapToWindow()
557    
558            self.full_redraw()
559    
560        def layer_projection_changed(self, *args):
561          self.full_redraw()          self.full_redraw()
562    
563      def set_view_transform(self, scale, offset):      def set_view_transform(self, scale, offset):
# Line 945  class MapCanvas(wxWindow, Publisher): Line 975  class MapCanvas(wxWindow, Publisher):
975    
976              if shapetype == SHAPETYPE_POLYGON:              if shapetype == SHAPETYPE_POLYGON:
977                  for i in shape_ids:                  for i in shape_ids:
978                      result = point_in_polygon_shape(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
979                                                      i,                      result = point_in_polygon_shape(shapefile, i,
980                                                      filled, stroked,                                                      filled, stroked,
981                                                      map_proj, layer_proj,                                                      map_proj, layer_proj,
982                                                      scale, -scale, offx, offy,                                                      scale, -scale, offx, offy,
# Line 956  class MapCanvas(wxWindow, Publisher): Line 986  class MapCanvas(wxWindow, Publisher):
986                          break                          break
987              elif shapetype == SHAPETYPE_ARC:              elif shapetype == SHAPETYPE_ARC:
988                  for i in shape_ids:                  for i in shape_ids:
989                      result = point_in_polygon_shape(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
990                        result = point_in_polygon_shape(shapefile,
991                                                      i, 0, 1,                                                      i, 0, 1,
992                                                      map_proj, layer_proj,                                                      map_proj, layer_proj,
993                                                      scale, -scale, offx, offy,                                                      scale, -scale, offx, offy,
# Line 1018  class MapCanvas(wxWindow, Publisher): Line 1049  class MapCanvas(wxWindow, Publisher):
1049              # a label was selected              # a label was selected
1050              label_layer.RemoveLabel(shape_index)              label_layer.RemoveLabel(shape_index)
1051          elif layer is not None:          elif layer is not None:
1052              text = labeldialog.run_label_dialog(self, layer.table, shape_index)              text = labeldialog.run_label_dialog(self,
1053                                                    layer.ShapeStore().Table(),
1054                                                    shape_index)
1055              if text:              if text:
1056                  proj = self.map.projection                  proj = self.map.projection
1057                  if proj is not None:                  if proj is not None:
# Line 1033  class MapCanvas(wxWindow, Publisher): Line 1066  class MapCanvas(wxWindow, Publisher):
1066    
1067                  shapetype = layer.ShapeType()                  shapetype = layer.ShapeType()
1068                  if shapetype == SHAPETYPE_POLYGON:                  if shapetype == SHAPETYPE_POLYGON:
1069                      x, y = shape_centroid(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
1070                                            shape_index,                      x, y = shape_centroid(shapefile, shape_index,
1071                                            map_proj, layer_proj, 1, 1, 0, 0)                                            map_proj, layer_proj, 1, 1, 0, 0)
1072                      if map_proj is not None:                      if map_proj is not None:
1073                          x, y = map_proj.Inverse(x, y)                          x, y = map_proj.Inverse(x, y)

Legend:
Removed from v.1111  
changed lines
  Added in v.1221

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26