/[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 145 by bh, Tue May 7 14:58:05 2002 UTC revision 174 by bh, Wed May 15 13:30:00 2002 UTC
# Line 167  class PanTool(Tool): Line 167  class PanTool(Tool):
167    
168      def MouseMove(self, event):      def MouseMove(self, event):
169          if self.dragging:          if self.dragging:
             x0, y0 = self.current  
170              Tool.MouseMove(self, event)              Tool.MouseMove(self, event)
171                sx, sy = self.start
172              x, y = self.current              x, y = self.current
173              width, height = self.view.GetSizeTuple()              width, height = self.view.GetSizeTuple()
174    
175                bitmapdc = wx.wxMemoryDC()
176                bitmapdc.SelectObject(self.view.bitmap)
177    
178              dc = self.view.drag_dc              dc = self.view.drag_dc
179              dc.Blit(0, 0, width, height, dc, x0 - x, y0 - y)              dc.Blit(0, 0, width, height, bitmapdc, sx - x, sy - y)
180    
181      def MouseUp(self, event):      def MouseUp(self, event):
182          if self.dragging:          if self.dragging:
# Line 282  class MapCanvas(wxWindow, Publisher): Line 286  class MapCanvas(wxWindow, Publisher):
286          self.interactor = interactor          self.interactor = interactor
287          self.interactor.Subscribe(SELECTED_SHAPE, self.shape_selected)          self.interactor.Subscribe(SELECTED_SHAPE, self.shape_selected)
288    
289            # keep track of which layers/shapes are selected to make sure we
290            # only redraw when necessary
291            self.last_selected_layer = None
292            self.last_selected_shape = None
293    
294          # subscribe the WX events we're interested in          # subscribe the WX events we're interested in
295          EVT_PAINT(self, self.OnPaint)          EVT_PAINT(self, self.OnPaint)
296          EVT_LEFT_DOWN(self, self.OnLeftDown)          EVT_LEFT_DOWN(self, self.OnLeftDown)
# Line 320  class MapCanvas(wxWindow, Publisher): Line 329  class MapCanvas(wxWindow, Publisher):
329      def do_redraw(self):      def do_redraw(self):
330          # This should only be called if we have a non-empty map.          # This should only be called if we have a non-empty map.
331    
332          # get the update region and reset it.          # get the update region and reset it. We're not actually using
333            # it anymore, though.
334          update_box = self.update_region.GetBox()          update_box = self.update_region.GetBox()
335          self.update_region = wx.wxRegion()          self.update_region = wx.wxRegion()
336    
# Line 350  class MapCanvas(wxWindow, Publisher): Line 360  class MapCanvas(wxWindow, Publisher):
360    
361              # draw the map into the bitmap              # draw the map into the bitmap
362              renderer = ScreenRenderer(dc, self.scale, self.offset)              renderer = ScreenRenderer(dc, self.scale, self.offset)
363              renderer.RenderMap(self.map, update_box,  
364                # Pass the entire bitmap as update_region to the renderer.
365                # We're redrawing the whole bitmap, after all.
366                renderer.RenderMap(self.map, (0, 0, width, height),
367                                 selected_layer, selected_shape)                                 selected_layer, selected_shape)
368    
369              dc.EndDrawing()              dc.EndDrawing()
# Line 574  class MapCanvas(wxWindow, Publisher): Line 587  class MapCanvas(wxWindow, Publisher):
587          self.full_redraw()          self.full_redraw()
588    
589      def shape_selected(self, layer, shape):      def shape_selected(self, layer, shape):
590          self.full_redraw()          """Redraw the map.
591    
592            Receiver for the SELECTED_SHAPE messages. Try to redraw only
593            when necessary.
594            """
595            # A redraw is necessary when the display has to change, which
596            # means that either the status changes from having no selection
597            # to having a selection shape or vice versa, or when the fact
598            # whether there is a selection at all doesn't change, when the
599            # shape which is selected has changed (which means that layer or
600            # shapeid changes).
601            print "MapCanvas.shape_selected:", layer, shape
602            if ((shape is not None or self.last_selected_shape is not None)
603                and (shape != self.last_selected_shape
604                     or layer != self.last_selected_layer)):
605                print "MapCanvas.shape_selected: redraw",
606                self.full_redraw()
607            else:
608                print "MapCanvas.shape_selected: no redraw"
609            self.last_selected_layer = layer
610            self.last_selected_shape = shape
611    
612        def unprojected_rect_around_point(self, x, y):
613            """return a rect a few pixels around (x, y) in unprojected corrdinates
614    
615            The return value is a tuple (minx, miny, maxx, maxy) suitable a
616            parameter to a layer's ShapesInRegion method.
617            """
618            map_proj = self.map.projection
619            if map_proj is not None:
620                inverse = map_proj.Inverse
621            else:
622                inverse = None
623    
624            xs = []
625            ys = []
626            for dx, dy in ((-1, -1), (1, -1), (1, 1), (-1, 1)):
627                px, py = self.win_to_proj(x + dx, y + dy)
628                if inverse:
629                    px, py = inverse(px, py)
630                xs.append(px)
631                ys.append(py)
632            return (min(xs), min(ys), max(xs), max(ys))
633    
634      def find_shape_at(self, px, py, select_labels = 0, selected_layer = 1):      def find_shape_at(self, px, py, select_labels = 0, selected_layer = 1):
635          """Determine the shape at point px, py in window coords          """Determine the shape at point px, py in window coords
# Line 598  class MapCanvas(wxWindow, Publisher): Line 653  class MapCanvas(wxWindow, Publisher):
653          scale = self.scale          scale = self.scale
654          offx, offy = self.offset          offx, offy = self.offset
655    
656            box = self.unprojected_rect_around_point(px, py)
657    
658          if select_labels:          if select_labels:
659              labels = self.map.LabelLayer().Labels()              labels = self.map.LabelLayer().Labels()
660                            
# Line 662  class MapCanvas(wxWindow, Publisher): Line 719  class MapCanvas(wxWindow, Publisher):
719              shapetype = layer.ShapeType()              shapetype = layer.ShapeType()
720    
721              select_shape = -1              select_shape = -1
722    
723                shape_ids = layer.ShapesInRegion(box)
724                shape_ids.reverse()
725    
726              if shapetype == SHAPETYPE_POLYGON:              if shapetype == SHAPETYPE_POLYGON:
727                  for i in range(layer.NumShapes() - 1, -1, -1):                  for i in shape_ids:
728                      result = point_in_polygon_shape(layer.shapefile.cobject(),                      result = point_in_polygon_shape(layer.shapefile.cobject(),
729                                                      i,                                                      i,
730                                                      filled, stroked,                                                      filled, stroked,
# Line 674  class MapCanvas(wxWindow, Publisher): Line 735  class MapCanvas(wxWindow, Publisher):
735                          select_shape = i                          select_shape = i
736                          break                          break
737              elif shapetype == SHAPETYPE_ARC:              elif shapetype == SHAPETYPE_ARC:
738                  for i in range(layer.NumShapes() - 1, -1, -1):                  for i in shape_ids:
739                      result = point_in_polygon_shape(layer.shapefile.cobject(),                      result = point_in_polygon_shape(layer.shapefile.cobject(),
740                                                      i, 0, 1,                                                      i, 0, 1,
741                                                      map_proj, layer_proj,                                                      map_proj, layer_proj,
# Line 684  class MapCanvas(wxWindow, Publisher): Line 745  class MapCanvas(wxWindow, Publisher):
745                          select_shape = i                          select_shape = i
746                          break                          break
747              elif shapetype == SHAPETYPE_POINT:              elif shapetype == SHAPETYPE_POINT:
748                  for i in range(layer.NumShapes() - 1, -1, -1):                  for i in shape_ids:
749                      shape = layer.Shape(i)                      shape = layer.Shape(i)
750                      x, y = shape.Points()[0]                      x, y = shape.Points()[0]
751                      if inverse:                      if inverse:

Legend:
Removed from v.145  
changed lines
  Added in v.174

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26