/[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 940 by jonathan, Tue May 20 15:25:33 2003 UTC revision 1105 by jonathan, Fri May 30 06:30:15 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:
             try:  
383                  self.do_redraw()                  self.do_redraw()
384              except:                  try:
385                  print "Error during drawing:", sys.exc_info()[0]                      pass
386                  clear = True                  except:
387                        print "Error during drawing:", sys.exc_info()[0]
388          if clear:                      clear = True
389              # If we've got no map or if the map is empty, simply clear  
390              # the screen.              if clear:
391                    # If we've got no map or if the map is empty, simply clear
392              # XXX it's probably possible to get rid of this. The                  # the screen.
393              # background color of the window is already white and the  
394              # only thing we may have to do is to call self.Refresh()                  # XXX it's probably possible to get rid of this. The
395              # with a true argument in the right places.                  # background color of the window is already white and the
396              dc.BeginDrawing()                  # only thing we may have to do is to call self.Refresh()
397              dc.Clear()                  # with a true argument in the right places.
398              dc.EndDrawing()                  dc.BeginDrawing()
399                    dc.Clear()
400          wxEndBusyCursor()                  dc.EndDrawing()
401            finally:
402                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 446  class MapCanvas(wxWindow, Publisher): Line 447  class MapCanvas(wxWindow, Publisher):
447          clientdc.EndDrawing()          clientdc.EndDrawing()
448    
449      def Export(self):      def Export(self):
450            if self.scale == 0:
451                return
452    
453          if hasattr(self, "export_path"):          if hasattr(self, "export_path"):
454              export_path = self.export_path              export_path = self.export_path
455          else:          else:
# Line 488  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 528  class MapCanvas(wxWindow, Publisher): Line 532  class MapCanvas(wxWindow, Publisher):
532    
533      def set_view_transform(self, scale, offset):      def set_view_transform(self, scale, offset):
534          self.scale = scale          self.scale = scale
         if self.scale < 0.0001:  
             self.scale = 0.0001  
535    
536          self.offset = offset          self.offset = offset
537          self.full_redraw()          self.full_redraw()
# Line 539  class MapCanvas(wxWindow, Publisher): Line 541  class MapCanvas(wxWindow, Publisher):
541          """\          """\
542          Return the point in  window coords given by projected coordinates x y          Return the point in  window coords given by projected coordinates x y
543          """          """
544            if self.scale == 0:
545                return (0, 0)
546    
547          offx, offy = self.offset          offx, offy = self.offset
548          return (self.scale * x + offx, -self.scale * y + offy)          return (self.scale * x + offx, -self.scale * y + offy)
549    
# Line 546  class MapCanvas(wxWindow, Publisher): Line 551  class MapCanvas(wxWindow, Publisher):
551          """\          """\
552          Return the point in projected coordinates given by window coords x y          Return the point in projected coordinates given by window coords x y
553          """          """
554            if self.scale == 0:
555                return (0, 0)
556    
557          offx, offy = self.offset          offx, offy = self.offset
558          return ((x - offx) / self.scale, (offy - y) / self.scale)          return ((x - offx) / self.scale, (offy - y) / self.scale)
559    
# Line 565  class MapCanvas(wxWindow, Publisher): Line 573  class MapCanvas(wxWindow, Publisher):
573          scale = min(scalex, scaley)          scale = min(scalex, scaley)
574          offx = 0.5 * (width - (urx + llx) * scale)          offx = 0.5 * (width - (urx + llx) * scale)
575          offy = 0.5 * (height + (ury + lly) * scale)          offy = 0.5 * (height + (ury + lly) * scale)
         print "scalex:", scalex, "scaley:", scaley  
576          self.set_view_transform(scale, (offx, offy))          self.set_view_transform(scale, (offx, offy))
577    
578      def FitMapToWindow(self):      def FitMapToWindow(self):
# Line 605  class MapCanvas(wxWindow, Publisher): Line 612  class MapCanvas(wxWindow, Publisher):
612                  bbox = proj.ForwardBBox(bbox)                  bbox = proj.ForwardBBox(bbox)
613    
614              if bbox is not None:              if bbox is not None:
615                  self.FitRectToWindow(bbox)                  if len(shapes) == 1 and layer.ShapeType() == SHAPETYPE_POINT:
616                        self.ZoomFactor(1, self.proj_to_win(bbox[0], bbox[1]))
617                    else:
618                        self.FitRectToWindow(bbox)
619    
620      def ZoomFactor(self, factor, center = None):      def ZoomFactor(self, factor, center = None):
621          """Multiply the zoom by factor and center on center.          """Multiply the zoom by factor and center on center.
# Line 614  class MapCanvas(wxWindow, Publisher): Line 624  class MapCanvas(wxWindow, Publisher):
624          that should be centered. If it is omitted, it defaults to the          that should be centered. If it is omitted, it defaults to the
625          center of the window          center of the window
626          """          """
627          width, height = self.GetSizeTuple()          if self.scale > 0:
628          scale = self.scale * factor              width, height = self.GetSizeTuple()
629          offx, offy = self.offset              scale = self.scale * factor
630          if center is not None:              offx, offy = self.offset
631              cx, cy = center              if center is not None:
632          else:                  cx, cy = center
633              cx = width / 2              else:
634              cy = height / 2                  cx = width / 2
635          offset = (factor * (offx - cx) + width / 2,                  cy = height / 2
636                    factor * (offy - cy) + height / 2)              offset = (factor * (offx - cx) + width / 2,
637          self.set_view_transform(scale, offset)                      factor * (offy - cy) + height / 2)
638                self.set_view_transform(scale, offset)
639    
640      def ZoomOutToRect(self, rect):      def ZoomOutToRect(self, rect):
641          """Zoom out to fit the currently visible region into rect.          """Zoom out to fit the currently visible region into rect.
# Line 810  class MapCanvas(wxWindow, Publisher): Line 821  class MapCanvas(wxWindow, Publisher):
821              forward = None              forward = None
822    
823          scale = self.scale          scale = self.scale
824    
825            if scale == 0:
826                return None, None
827    
828          offx, offy = self.offset          offx, offy = self.offset
829    
830          if select_labels:          if select_labels:

Legend:
Removed from v.940  
changed lines
  Added in v.1105

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26