/[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 967 by jonathan, Wed May 21 17:24:54 2003 UTC revision 1111 by bh, Fri May 30 09:54:48 2003 UTC
# Line 271  class MapPrintout(wx.wxPrintout): Line 271  class MapPrintout(wx.wxPrintout):
271                                  (height/canvas_scale)*scale),                                  (height/canvas_scale)*scale),
272                                  mapregion,                                  mapregion,
273                             self.selected_layer, self.selected_shapes)                             self.selected_layer, self.selected_shapes)
274          return wx.true          return True
275    
276    
277  class MapCanvas(wxWindow, Publisher):  class MapCanvas(wxWindow, Publisher):
# Line 378  class MapCanvas(wxWindow, Publisher): Line 378  class MapCanvas(wxWindow, Publisher):
378          clear = self.map is None or not self.map.HasLayers()          clear = self.map is None or not self.map.HasLayers()
379    
380          wxBeginBusyCursor()          wxBeginBusyCursor()
381            try:
382          if not clear:              if not clear:
383              self.do_redraw()                  self.do_redraw()
384              try:                  try:
385                  pass                      pass
386              except:                  except:
387                  print "Error during drawing:", sys.exc_info()[0]                      print "Error during drawing:", sys.exc_info()[0]
388                  clear = True                      clear = True
389    
390          if clear:              if clear:
391              # If we've got no map or if the map is empty, simply clear                  # If we've got no map or if the map is empty, simply clear
392              # the screen.                  # the screen.
393    
394              # XXX it's probably possible to get rid of this. The                  # XXX it's probably possible to get rid of this. The
395              # background color of the window is already white and the                  # background color of the window is already white and the
396              # only thing we may have to do is to call self.Refresh()                  # only thing we may have to do is to call self.Refresh()
397              # with a true argument in the right places.                  # with a true argument in the right places.
398              dc.BeginDrawing()                  dc.BeginDrawing()
399              dc.Clear()                  dc.Clear()
400              dc.EndDrawing()                  dc.EndDrawing()
401            finally:
402          wxEndBusyCursor()              wxEndBusyCursor()
403    
404      def do_redraw(self):      def do_redraw(self):
405          # This should only be called if we have a non-empty map.          # This should only be called if we have a non-empty map.
# Line 492  class MapCanvas(wxWindow, Publisher): Line 492  class MapCanvas(wxWindow, Publisher):
492                    
493          printout = MapPrintout(self, self.map, (0, 0, width, height),          printout = MapPrintout(self, self.map, (0, 0, width, height),
494                                 selected_layer, selected_shapes)                                 selected_layer, selected_shapes)
495          printer.Print(self, printout, wx.true)          printer.Print(self, printout, True)
496          printout.Destroy()          printout.Destroy()
497    
498      def SetMap(self, map):      def SetMap(self, map):
# Line 531  class MapCanvas(wxWindow, Publisher): Line 531  class MapCanvas(wxWindow, Publisher):
531          self.full_redraw()          self.full_redraw()
532    
533      def set_view_transform(self, scale, offset):      def set_view_transform(self, scale, offset):
534            # width/height of the projected bbox
535            llx, lly, urx, ury = bbox = self.map.ProjectedBoundingBox()
536            pwidth = float(urx - llx)
537            pheight = float(ury - lly)
538    
539            # width/height of the window
540            wwidth, wheight = self.GetSizeTuple()
541    
542            # The window's center in projected coordinates assuming the new
543            # scale/offset
544            pcenterx = (wwidth/2 - offset[0]) / scale
545            pcentery = (offset[1] - wheight/2) / scale
546    
547            # The window coordinates used when drawing the shapes must fit
548            # into 16bit signed integers.
549            max_len = max(pwidth, pheight)
550            if max_len:
551                max_scale = 32000.0 / max_len
552            else:
553                # FIXME: What to do in this case? The bbox is effectively
554                # empty so any scale should work.
555                max_scale = scale
556    
557            # The minimal scale is somewhat arbitrarily set to half that of
558            # the bbox fit into the window
559            scales = []
560            if pwidth:
561                scales.append(wwidth / pwidth)
562            if pheight:
563                scales.append(wheight / pheight)
564            if scales:
565                min_scale = 0.5 * min(scales)
566            else:
567                min_scale = scale
568    
569            if scale > max_scale:
570                scale = max_scale
571            elif scale < min_scale:
572                scale = min_scale
573    
574          self.scale = scale          self.scale = scale
575    
576          self.offset = offset          # determine new offset to preserve the center
577            self.offset = (wwidth/2 - scale * pcenterx,
578                           wheight/2 + scale * pcentery)
579          self.full_redraw()          self.full_redraw()
580          self.issue(SCALE_CHANGED, scale)          self.issue(SCALE_CHANGED, scale)
581    
# Line 612  class MapCanvas(wxWindow, Publisher): Line 654  class MapCanvas(wxWindow, Publisher):
654                  bbox = proj.ForwardBBox(bbox)                  bbox = proj.ForwardBBox(bbox)
655    
656              if bbox is not None:              if bbox is not None:
657                  self.FitRectToWindow(bbox)                  if len(shapes) == 1 and layer.ShapeType() == SHAPETYPE_POINT:
658                        self.ZoomFactor(1, self.proj_to_win(bbox[0], bbox[1]))
659                    else:
660                        self.FitRectToWindow(bbox)
661    
662      def ZoomFactor(self, factor, center = None):      def ZoomFactor(self, factor, center = None):
663          """Multiply the zoom by factor and center on center.          """Multiply the zoom by factor and center on center.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26