/[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 1219 by bh, Mon Jun 16 17:42:54 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 527  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
         if self.scale < 0.0001:  
             self.scale = 0.0001  
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 539  class MapCanvas(wxWindow, Publisher): Line 583  class MapCanvas(wxWindow, Publisher):
583          """\          """\
584          Return the point in  window coords given by projected coordinates x y          Return the point in  window coords given by projected coordinates x y
585          """          """
586            if self.scale == 0:
587                return (0, 0)
588    
589          offx, offy = self.offset          offx, offy = self.offset
590          return (self.scale * x + offx, -self.scale * y + offy)          return (self.scale * x + offx, -self.scale * y + offy)
591    
# Line 546  class MapCanvas(wxWindow, Publisher): Line 593  class MapCanvas(wxWindow, Publisher):
593          """\          """\
594          Return the point in projected coordinates given by window coords x y          Return the point in projected coordinates given by window coords x y
595          """          """
596            if self.scale == 0:
597                return (0, 0)
598    
599          offx, offy = self.offset          offx, offy = self.offset
600          return ((x - offx) / self.scale, (offy - y) / self.scale)          return ((x - offx) / self.scale, (offy - y) / self.scale)
601    
# Line 565  class MapCanvas(wxWindow, Publisher): Line 615  class MapCanvas(wxWindow, Publisher):
615          scale = min(scalex, scaley)          scale = min(scalex, scaley)
616          offx = 0.5 * (width - (urx + llx) * scale)          offx = 0.5 * (width - (urx + llx) * scale)
617          offy = 0.5 * (height + (ury + lly) * scale)          offy = 0.5 * (height + (ury + lly) * scale)
         print "scalex:", scalex, "scaley:", scaley  
618          self.set_view_transform(scale, (offx, offy))          self.set_view_transform(scale, (offx, offy))
619    
620      def FitMapToWindow(self):      def FitMapToWindow(self):
# Line 605  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.
# Line 614  class MapCanvas(wxWindow, Publisher): Line 666  class MapCanvas(wxWindow, Publisher):
666          that should be centered. If it is omitted, it defaults to the          that should be centered. If it is omitted, it defaults to the
667          center of the window          center of the window
668          """          """
669          width, height = self.GetSizeTuple()          if self.scale > 0:
670          scale = self.scale * factor              width, height = self.GetSizeTuple()
671          offx, offy = self.offset              scale = self.scale * factor
672          if center is not None:              offx, offy = self.offset
673              cx, cy = center              if center is not None:
674          else:                  cx, cy = center
675              cx = width / 2              else:
676              cy = height / 2                  cx = width / 2
677          offset = (factor * (offx - cx) + width / 2,                  cy = height / 2
678                    factor * (offy - cy) + height / 2)              offset = (factor * (offx - cx) + width / 2,
679          self.set_view_transform(scale, offset)                      factor * (offy - cy) + height / 2)
680                self.set_view_transform(scale, offset)
681    
682      def ZoomOutToRect(self, rect):      def ZoomOutToRect(self, rect):
683          """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 863  class MapCanvas(wxWindow, Publisher):
863              forward = None              forward = None
864    
865          scale = self.scale          scale = self.scale
866    
867            if scale == 0:
868                return None, None
869    
870          offx, offy = self.offset          offx, offy = self.offset
871    
872          if select_labels:          if select_labels:
# Line 888  class MapCanvas(wxWindow, Publisher): Line 945  class MapCanvas(wxWindow, Publisher):
945    
946              if shapetype == SHAPETYPE_POLYGON:              if shapetype == SHAPETYPE_POLYGON:
947                  for i in shape_ids:                  for i in shape_ids:
948                      result = point_in_polygon_shape(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
949                                                      i,                      result = point_in_polygon_shape(shapefile, i,
950                                                      filled, stroked,                                                      filled, stroked,
951                                                      map_proj, layer_proj,                                                      map_proj, layer_proj,
952                                                      scale, -scale, offx, offy,                                                      scale, -scale, offx, offy,
# Line 899  class MapCanvas(wxWindow, Publisher): Line 956  class MapCanvas(wxWindow, Publisher):
956                          break                          break
957              elif shapetype == SHAPETYPE_ARC:              elif shapetype == SHAPETYPE_ARC:
958                  for i in shape_ids:                  for i in shape_ids:
959                      result = point_in_polygon_shape(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
960                        result = point_in_polygon_shape(shapefile,
961                                                      i, 0, 1,                                                      i, 0, 1,
962                                                      map_proj, layer_proj,                                                      map_proj, layer_proj,
963                                                      scale, -scale, offx, offy,                                                      scale, -scale, offx, offy,
# Line 961  class MapCanvas(wxWindow, Publisher): Line 1019  class MapCanvas(wxWindow, Publisher):
1019              # a label was selected              # a label was selected
1020              label_layer.RemoveLabel(shape_index)              label_layer.RemoveLabel(shape_index)
1021          elif layer is not None:          elif layer is not None:
1022              text = labeldialog.run_label_dialog(self, layer.table, shape_index)              text = labeldialog.run_label_dialog(self,
1023                                                    layer.ShapeStore().Table(),
1024                                                    shape_index)
1025              if text:              if text:
1026                  proj = self.map.projection                  proj = self.map.projection
1027                  if proj is not None:                  if proj is not None:
# Line 976  class MapCanvas(wxWindow, Publisher): Line 1036  class MapCanvas(wxWindow, Publisher):
1036    
1037                  shapetype = layer.ShapeType()                  shapetype = layer.ShapeType()
1038                  if shapetype == SHAPETYPE_POLYGON:                  if shapetype == SHAPETYPE_POLYGON:
1039                      x, y = shape_centroid(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
1040                                            shape_index,                      x, y = shape_centroid(shapefile, shape_index,
1041                                            map_proj, layer_proj, 1, 1, 0, 0)                                            map_proj, layer_proj, 1, 1, 0, 0)
1042                      if map_proj is not None:                      if map_proj is not None:
1043                          x, y = map_proj.Inverse(x, y)                          x, y = map_proj.Inverse(x, y)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26