/[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 822 by jonathan, Mon May 5 18:20:28 2003 UTC revision 1344 by jonathan, Tue Jul 1 16:11:26 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4    # Frank Koormann <[email protected]>
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 11  Classes for display of a map and interac Line 12  Classes for display of a map and interac
12    
13  __version__ = "$Revision$"  __version__ = "$Revision$"
14    
15    from Thuban import _
16    
17  import sys  import sys
18    import os.path
19    
20  from math import hypot  from math import hypot
21    
22  from wxPython.wx import wxWindow,\  from wxPython.wx import wxWindow, \
23       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\
24       EVT_PAINT, EVT_LEFT_DOWN, EVT_LEFT_UP, EVT_MOTION, EVT_LEAVE_WINDOW, \       EVT_PAINT, EVT_LEFT_DOWN, EVT_LEFT_UP, EVT_MOTION, EVT_LEAVE_WINDOW, \
25       wxBITMAP_TYPE_XPM, wxBeginBusyCursor, wxEndBusyCursor, wxCursor, \       wxBITMAP_TYPE_XPM, wxCursor, wxImageFromBitmap, wxPlatform, \
26       wxImageFromBitmap       wxBeginBusyCursor, wxEndBusyCursor
27    
28    
29    # Export related stuff
30    if wxPlatform == '__WXMSW__':
31        from wxPython.wx import wxMetaFileDC
32    from wxPython.wx import wxFileDialog, wxSAVE, wxOVERWRITE_PROMPT, wxID_OK
33    
34  from wxPython import wx  from wxPython import wx
35    
36  from wxproj import point_in_polygon_shape, shape_centroid  from wxproj import point_in_polygon_shape, shape_centroid
37    
   
38  from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \  from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \
39         LAYER_PROJECTION_CHANGED, \
40       MAP_LAYERS_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED       MAP_LAYERS_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED
41  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \
42       SHAPETYPE_POINT       SHAPETYPE_POINT
43  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
44       ALIGN_LEFT, ALIGN_RIGHT       ALIGN_LEFT, ALIGN_RIGHT
45  from Thuban.Lib.connector import Publisher  from Thuban.Lib.connector import Publisher
46  from Thuban.Model.color import Color  from Thuban.Model.color import Color, Transparent
47    
48  import resource  import resource
49    
50  from selection import Selection  from selection import Selection
51  from renderer import ScreenRenderer, PrinterRender  from renderer import ScreenRenderer, ExportRenderer, PrinterRenderer
52    
53  import labeldialog  import labeldialog
54    
55  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
56                         SCALE_CHANGED
57    
58    #from common import ThubanBeginBusyCursor, ThubanEndBusyCursor
59    
60  #  #
61  #   The tools  #   The tools
# Line 223  class LabelTool(Tool): Line 234  class LabelTool(Tool):
234          self.view.LabelShapeAt(event.m_x, event.m_y)          self.view.LabelShapeAt(event.m_x, event.m_y)
235    
236    
   
   
237  class MapPrintout(wx.wxPrintout):  class MapPrintout(wx.wxPrintout):
238    
239      """      """
240      wxPrintout class for printing Thuban maps      wxPrintout class for printing Thuban maps
241      """      """
242    
243      def __init__(self, map):      def __init__(self, canvas, map, region, selected_layer, selected_shapes):
244          wx.wxPrintout.__init__(self)          wx.wxPrintout.__init__(self)
245            self.canvas = canvas
246          self.map = map          self.map = map
247            self.region = region
248            self.selected_layer = selected_layer
249            self.selected_shapes = selected_shapes
250    
251      def GetPageInfo(self):      def GetPageInfo(self):
252          return (1, 1, 1, 1)          return (1, 1, 1, 1)
# Line 247  class MapPrintout(wx.wxPrintout): Line 260  class MapPrintout(wx.wxPrintout):
260    
261      def draw_on_dc(self, dc):      def draw_on_dc(self, dc):
262          width, height = self.GetPageSizePixels()          width, height = self.GetPageSizePixels()
263          llx, lly, urx, ury = self.map.ProjectedBoundingBox()          scale, offset, mapregion = OutputTransform(self.canvas.scale,
264          scalex = width / (urx - llx)                                                     self.canvas.offset,
265          scaley = height / (ury - lly)                                                     self.canvas.GetSizeTuple(),
266          scale = min(scalex, scaley)                                                     self.GetPageSizePixels())
         offx = 0.5 * (width - (urx + llx) * scale)  
         offy = 0.5 * (height + (ury + lly) * scale)  
   
267          resx, resy = self.GetPPIPrinter()          resx, resy = self.GetPPIPrinter()
268          renderer = PrinterRender(dc, scale, (offx, offy), resolution = resx)          renderer = PrinterRenderer(dc, scale, offset, resolution = resy)
269          renderer.RenderMap(self.map)          x, y, width, height = self.region
270          return wx.true          canvas_scale = self.canvas.scale
271            renderer.RenderMap(self.map,
272                               (0,0,
273                                    (width/canvas_scale)*scale,
274                                    (height/canvas_scale)*scale),
275                                    mapregion,
276                               self.selected_layer, self.selected_shapes)
277            return True
278    
279  class MapCanvas(wxWindow, Publisher):  class MapCanvas(wxWindow, Publisher):
280    
# Line 277  class MapCanvas(wxWindow, Publisher): Line 293  class MapCanvas(wxWindow, Publisher):
293      delegated_methods = {"SelectLayer": "selection",      delegated_methods = {"SelectLayer": "selection",
294                           "SelectShapes": "selection",                           "SelectShapes": "selection",
295                           "SelectedLayer": "selection",                           "SelectedLayer": "selection",
296                           "HasSelectedLayer": "selection"}                           "HasSelectedLayer": "selection",
297                             "HasSelectedShapes": "selection",
298                             "SelectedShapes": "selection"}
299    
300      def __init__(self, parent, winid):      def __init__(self, parent, winid):
301          wxWindow.__init__(self, parent, winid)          wxWindow.__init__(self, parent, winid)
# Line 286  class MapCanvas(wxWindow, Publisher): Line 304  class MapCanvas(wxWindow, Publisher):
304          # the map displayed in this canvas. Set with SetMap()          # the map displayed in this canvas. Set with SetMap()
305          self.map = None          self.map = None
306    
307            # current map projection. should only differ from map.projection
308            # when the map's projection is changing and we need access to the
309            # old projection.
310            self.current_map_proj = None
311    
312          # scale and offset describe the transformation from projected          # scale and offset describe the transformation from projected
313          # coordinates to window coordinates.          # coordinates to window coordinates.
314          self.scale = 1.0          self.scale = 1.0
# Line 314  class MapCanvas(wxWindow, Publisher): Line 337  class MapCanvas(wxWindow, Publisher):
337          self.last_selected_layer = None          self.last_selected_layer = None
338          self.last_selected_shape = None          self.last_selected_shape = None
339    
340            self.backgroundColor = wx.wxWHITE_BRUSH
341    
342          # subscribe the WX events we're interested in          # subscribe the WX events we're interested in
343          EVT_PAINT(self, self.OnPaint)          EVT_PAINT(self, self.OnPaint)
344          EVT_LEFT_DOWN(self, self.OnLeftDown)          EVT_LEFT_DOWN(self, self.OnLeftDown)
# Line 321  class MapCanvas(wxWindow, Publisher): Line 346  class MapCanvas(wxWindow, Publisher):
346          EVT_MOTION(self, self.OnMotion)          EVT_MOTION(self, self.OnMotion)
347          EVT_LEAVE_WINDOW(self, self.OnLeaveWindow)          EVT_LEAVE_WINDOW(self, self.OnLeaveWindow)
348          wx.EVT_SIZE(self, self.OnSize)          wx.EVT_SIZE(self, self.OnSize)
349            wx.EVT_IDLE(self, self.OnIdle)
350    
351      def __del__(self):      def __del__(self):
352          wxWindow.__del__(self)          wxWindow.__del__(self)
# Line 359  class MapCanvas(wxWindow, Publisher): Line 385  class MapCanvas(wxWindow, Publisher):
385    
386      def OnPaint(self, event):      def OnPaint(self, event):
387          dc = wxPaintDC(self)          dc = wxPaintDC(self)
         clear = self.map is None or not self.map.HasLayers()  
388    
389          #wxBeginBusyCursor()          if self.map is not None and self.map.HasLayers():
390                if self.bitmap in (None, -1):
391                    # set the flag that we should redraw the
392                    # bitmap in idle time
393                    self.bitmap = -1
394                    return
395    
396          if not clear:              # blit the bitmap to the screen
397              try:              dc.BeginDrawing()
398                  self.do_redraw()              dc.DrawBitmap(self.bitmap, 0, 0)
399              except:              dc.EndDrawing()
400                  print "Error during drawing:", sys.exc_info()[0]          else:
                 clear = True  
   
         if clear:  
401              # 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
402              # the screen.              # the screen.
403    
# Line 379  class MapCanvas(wxWindow, Publisher): Line 406  class MapCanvas(wxWindow, Publisher):
406              # only thing we may have to do is to call self.Refresh()              # only thing we may have to do is to call self.Refresh()
407              # with a true argument in the right places.              # with a true argument in the right places.
408              dc.BeginDrawing()              dc.BeginDrawing()
409                dc.SetBackground(self.backgroundColor)
410              dc.Clear()              dc.Clear()
411              dc.EndDrawing()              dc.EndDrawing()
412    
413          #wxEndBusyCursor()      def OnIdle(self, event):
414            # render the screen if necessary
415    
416      def do_redraw(self):          if self.bitmap != -1:
417          # This should only be called if we have a non-empty map.              return
418    
419          # Get the window size.          wxBeginBusyCursor()
420          width, height = self.GetSizeTuple()          try:
421                width, height = self.GetSizeTuple()
422    
         # If self.bitmap's still there, reuse it. Otherwise redraw it  
         if self.bitmap is not None:  
             bitmap = self.bitmap  
         else:  
423              bitmap = wx.wxEmptyBitmap(width, height)              bitmap = wx.wxEmptyBitmap(width, height)
424              dc = wx.wxMemoryDC()              dc = wx.wxMemoryDC()
425              dc.SelectObject(bitmap)              dc.SelectObject(bitmap)
426              dc.BeginDrawing()              dc.BeginDrawing()
427    
428              # clear the background              dc.SetBackground(self.backgroundColor)
             #dc.SetBrush(wx.wxWHITE_BRUSH)  
             #dc.SetPen(wx.wxTRANSPARENT_PEN)  
             #dc.DrawRectangle(0, 0, width, height)  
             dc.SetBackground(wx.wxWHITE_BRUSH)  
429              dc.Clear()              dc.Clear()
430    
431              selected_layer = self.selection.SelectedLayer()              selected_layer = self.selection.SelectedLayer()
# Line 419  class MapCanvas(wxWindow, Publisher): Line 441  class MapCanvas(wxWindow, Publisher):
441    
442              dc.EndDrawing()              dc.EndDrawing()
443              dc.SelectObject(wx.wxNullBitmap)              dc.SelectObject(wx.wxNullBitmap)
444    
445              self.bitmap = bitmap              self.bitmap = bitmap
446            finally:
447                wxEndBusyCursor()
448                pass
449    
450            # This causes a paint event that then draws the bitmap
451            self.redraw()
452    
453        def Export(self):
454            if self.scale == 0:
455                return
456    
457          # blit the bitmap to the screen          if hasattr(self, "export_path"):
458          dc = wx.wxMemoryDC()              export_path = self.export_path
459          dc.SelectObject(bitmap)          else:
460          clientdc = wxClientDC(self)              export_path="."
461          clientdc.BeginDrawing()          dlg = wxFileDialog(self, _("Export Map"), export_path, "",
462          clientdc.Blit(0, 0, width, height, dc, 0, 0)                             "Enhanced Metafile (*.wmf)|*.wmf",
463          clientdc.EndDrawing()                             wxSAVE|wxOVERWRITE_PROMPT)
464            if dlg.ShowModal() == wxID_OK:
465                self.export_path = os.path.dirname(dlg.GetPath())
466                dc = wxMetaFileDC(dlg.GetPath())
467        
468                scale, offset, mapregion = OutputTransform(self.scale,
469                                                           self.offset,
470                                                           self.GetSizeTuple(),
471                                                           dc.GetSizeTuple())
472    
473                selected_layer = self.selection.SelectedLayer()
474                selected_shapes = self.selection.SelectedShapes()
475    
476                renderer = ExportRenderer(dc, scale, offset)
477    
478                # Pass the entire bitmap as update region to the renderer.
479                # We're redrawing the whole bitmap, after all.
480                width, height = self.GetSizeTuple()
481                renderer.RenderMap(self.map,
482                                    (0,0,
483                                        (width/self.scale)*scale,
484                                        (height/self.scale)*scale),
485                                    mapregion,
486                                    selected_layer, selected_shapes)
487                dc.EndDrawing()
488                dc.Close()
489            dlg.Destroy()
490            
491      def Print(self):      def Print(self):
492          printer = wx.wxPrinter()          printer = wx.wxPrinter()
493          printout = MapPrintout(self.map)          width, height = self.GetSizeTuple()
494          printer.Print(self, printout, wx.true)          selected_layer = self.selection.SelectedLayer()
495            selected_shapes = self.selection.SelectedShapes()
496            
497            printout = MapPrintout(self, self.map, (0, 0, width, height),
498                                   selected_layer, selected_shapes)
499            printer.Print(self, printout, True)
500          printout.Destroy()          printout.Destroy()
501    
502      def SetMap(self, map):      def SetMap(self, map):
# Line 442  class MapCanvas(wxWindow, Publisher): Line 506  class MapCanvas(wxWindow, Publisher):
506              for channel in redraw_channels:              for channel in redraw_channels:
507                  self.map.Unsubscribe(channel, self.full_redraw)                  self.map.Unsubscribe(channel, self.full_redraw)
508              self.map.Unsubscribe(MAP_PROJECTION_CHANGED,              self.map.Unsubscribe(MAP_PROJECTION_CHANGED,
509                                   self.projection_changed)                                   self.map_projection_changed)
510                self.map.Unsubscribe(LAYER_PROJECTION_CHANGED,
511                                     self.layer_projection_changed)
512          self.map = map          self.map = map
513            self.current_map_proj = self.map.GetProjection()
514          self.selection.ClearSelection()          self.selection.ClearSelection()
515          if self.map is not None:          if self.map is not None:
516              for channel in redraw_channels:              for channel in redraw_channels:
517                  self.map.Subscribe(channel, self.full_redraw)                  self.map.Subscribe(channel, self.full_redraw)
518              self.map.Subscribe(MAP_PROJECTION_CHANGED, self.projection_changed)              self.map.Subscribe(MAP_PROJECTION_CHANGED, self.map_projection_changed)
519                self.map.Subscribe(LAYER_PROJECTION_CHANGED, self.layer_projection_changed)
520          self.FitMapToWindow()          self.FitMapToWindow()
521          # 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
522          # 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 460  class MapCanvas(wxWindow, Publisher): Line 528  class MapCanvas(wxWindow, Publisher):
528          return self.map          return self.map
529    
530      def redraw(self, *args):      def redraw(self, *args):
531          self.Refresh(0)          self.Refresh(False)
532    
533      def full_redraw(self, *args):      def full_redraw(self, *args):
534          self.bitmap = None          self.bitmap = None
535          self.redraw()          self.redraw()
536    
537      def projection_changed(self, *args):      def map_projection_changed(self, *args):
538          self.FitMapToWindow()  
539            proj = self.current_map_proj
540            self.current_map_proj = self.map.GetProjection()
541    
542            bbox = None
543    
544            if proj is not None and self.current_map_proj is not None:
545                width, height = self.GetSizeTuple()
546                llx, lly = self.win_to_proj(0, height)
547                urx, ury = self.win_to_proj(width, 0)
548                bbox = proj.Inverse(llx, lly) + proj.Inverse(urx, ury)
549                bbox = self.current_map_proj.ForwardBBox(bbox)
550    
551            if bbox is not None:
552                self.FitRectToWindow(bbox)
553            else:
554                self.FitMapToWindow()
555    
556            self.full_redraw()
557    
558        def layer_projection_changed(self, *args):
559          self.full_redraw()          self.full_redraw()
560    
561      def set_view_transform(self, scale, offset):      def set_view_transform(self, scale, offset):
562            # width/height of the projected bbox
563            llx, lly, urx, ury = bbox = self.map.ProjectedBoundingBox()
564            pwidth = float(urx - llx)
565            pheight = float(ury - lly)
566    
567            # width/height of the window
568            wwidth, wheight = self.GetSizeTuple()
569    
570            # The window's center in projected coordinates assuming the new
571            # scale/offset
572            pcenterx = (wwidth/2 - offset[0]) / scale
573            pcentery = (offset[1] - wheight/2) / scale
574    
575            # The window coordinates used when drawing the shapes must fit
576            # into 16bit signed integers.
577            max_len = max(pwidth, pheight)
578            if max_len:
579                max_scale = 32000.0 / max_len
580            else:
581                # FIXME: What to do in this case? The bbox is effectively
582                # empty so any scale should work.
583                max_scale = scale
584    
585            # The minimal scale is somewhat arbitrarily set to half that of
586            # the bbox fit into the window
587            scales = []
588            if pwidth:
589                scales.append(wwidth / pwidth)
590            if pheight:
591                scales.append(wheight / pheight)
592            if scales:
593                min_scale = 0.5 * min(scales)
594            else:
595                min_scale = scale
596    
597            if scale > max_scale:
598                scale = max_scale
599            elif scale < min_scale:
600                scale = min_scale
601    
602          self.scale = scale          self.scale = scale
603          self.offset = offset  
604            # determine new offset to preserve the center
605            self.offset = (wwidth/2 - scale * pcenterx,
606                           wheight/2 + scale * pcentery)
607          self.full_redraw()          self.full_redraw()
608            self.issue(SCALE_CHANGED, scale)
609    
610      def proj_to_win(self, x, y):      def proj_to_win(self, x, y):
611          """\          """\
612          Return the point in  window coords given by projected coordinates x y          Return the point in  window coords given by projected coordinates x y
613          """          """
614            if self.scale == 0:
615                return (0, 0)
616    
617          offx, offy = self.offset          offx, offy = self.offset
618          return (self.scale * x + offx, -self.scale * y + offy)          return (self.scale * x + offx, -self.scale * y + offy)
619    
# Line 486  class MapCanvas(wxWindow, Publisher): Line 621  class MapCanvas(wxWindow, Publisher):
621          """\          """\
622          Return the point in projected coordinates given by window coords x y          Return the point in projected coordinates given by window coords x y
623          """          """
624            if self.scale == 0:
625                return (0, 0)
626    
627          offx, offy = self.offset          offx, offy = self.offset
628          return ((x - offx) / self.scale, (offy - y) / self.scale)          return ((x - offx) / self.scale, (offy - y) / self.scale)
629    
# Line 513  class MapCanvas(wxWindow, Publisher): Line 651  class MapCanvas(wxWindow, Publisher):
651          Set the scale so that the map fits exactly into the window and          Set the scale so that the map fits exactly into the window and
652          center it in the window.          center it in the window.
653          """          """
654          bbox = self.map.ProjectedBoundingBox()          if self.map is not None:
655          if bbox is not None:              bbox = self.map.ProjectedBoundingBox()
656              self.FitRectToWindow(bbox)              if bbox is not None:
657                    self.FitRectToWindow(bbox)
658    
659      def FitLayerToWindow(self, layer):      def FitLayerToWindow(self, layer):
660          """Fit the given layer to the window.          """Fit the given layer to the window.
# Line 529  class MapCanvas(wxWindow, Publisher): Line 668  class MapCanvas(wxWindow, Publisher):
668              proj = self.map.GetProjection()              proj = self.map.GetProjection()
669              if proj is not None:              if proj is not None:
670                  bbox = proj.ForwardBBox(bbox)                  bbox = proj.ForwardBBox(bbox)
671                  if bbox is not None:  
672                if bbox is not None:
673                    self.FitRectToWindow(bbox)
674    
675        def FitSelectedToWindow(self):
676            layer = self.selection.SelectedLayer()
677            shapes = self.selection.SelectedShapes()
678    
679            bbox = layer.ShapesBoundingBox(shapes)
680            if bbox is not None:
681                proj = self.map.GetProjection()
682                if proj is not None:
683                    bbox = proj.ForwardBBox(bbox)
684    
685                if bbox is not None:
686                    if len(shapes) == 1 and layer.ShapeType() == SHAPETYPE_POINT:
687                        self.ZoomFactor(1, self.proj_to_win(bbox[0], bbox[1]))
688                    else:
689                      self.FitRectToWindow(bbox)                      self.FitRectToWindow(bbox)
690    
691      def ZoomFactor(self, factor, center = None):      def ZoomFactor(self, factor, center = None):
# Line 539  class MapCanvas(wxWindow, Publisher): Line 695  class MapCanvas(wxWindow, Publisher):
695          that should be centered. If it is omitted, it defaults to the          that should be centered. If it is omitted, it defaults to the
696          center of the window          center of the window
697          """          """
698          width, height = self.GetSizeTuple()          if self.scale > 0:
699          scale = self.scale * factor              width, height = self.GetSizeTuple()
700          offx, offy = self.offset              scale = self.scale * factor
701          if center is not None:              offx, offy = self.offset
702              cx, cy = center              if center is not None:
703          else:                  cx, cy = center
704              cx = width / 2              else:
705              cy = height / 2                  cx = width / 2
706          offset = (factor * (offx - cx) + width / 2,                  cy = height / 2
707                    factor * (offy - cy) + height / 2)              offset = (factor * (offx - cx) + width / 2,
708          self.set_view_transform(scale, offset)                      factor * (offy - cy) + height / 2)
709                self.set_view_transform(scale, offset)
710    
711      def ZoomOutToRect(self, rect):      def ZoomOutToRect(self, rect):
712          """Zoom out to fit the currently visible region into rect.          """Zoom out to fit the currently visible region into rect.
# Line 735  class MapCanvas(wxWindow, Publisher): Line 892  class MapCanvas(wxWindow, Publisher):
892              forward = None              forward = None
893    
894          scale = self.scale          scale = self.scale
895    
896            if scale == 0:
897                return None, None
898    
899          offx, offy = self.offset          offx, offy = self.offset
900    
901          if select_labels:          if select_labels:
# Line 780  class MapCanvas(wxWindow, Publisher): Line 941  class MapCanvas(wxWindow, Publisher):
941              layer = layers[layer_index]              layer = layers[layer_index]
942    
943              # search only in visible layers              # search only in visible layers
944              if not layer.Visible():              if not layer.Visible() or not layer.HasShapes():
945                  continue                  continue
946    
947              filled = layer.GetClassification().GetDefaultFill() \              filled = layer.GetClassification().GetDefaultFill() \
948                       is not Color.Transparent                       is not Transparent
949              stroked = layer.GetClassification().GetDefaultLineColor() \              stroked = layer.GetClassification().GetDefaultLineColor() \
950                        is not Color.Transparent                        is not Transparent
951    
952              layer_proj = layer.projection              layer_proj = layer.projection
953              if layer_proj is not None:              if layer_proj is not None:
# Line 813  class MapCanvas(wxWindow, Publisher): Line 974  class MapCanvas(wxWindow, Publisher):
974    
975              if shapetype == SHAPETYPE_POLYGON:              if shapetype == SHAPETYPE_POLYGON:
976                  for i in shape_ids:                  for i in shape_ids:
977                      result = point_in_polygon_shape(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
978                                                      i,                      result = point_in_polygon_shape(shapefile, i,
979                                                      filled, stroked,                                                      filled, stroked,
980                                                      map_proj, layer_proj,                                                      map_proj, layer_proj,
981                                                      scale, -scale, offx, offy,                                                      scale, -scale, offx, offy,
# Line 824  class MapCanvas(wxWindow, Publisher): Line 985  class MapCanvas(wxWindow, Publisher):
985                          break                          break
986              elif shapetype == SHAPETYPE_ARC:              elif shapetype == SHAPETYPE_ARC:
987                  for i in shape_ids:                  for i in shape_ids:
988                      result = point_in_polygon_shape(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
989                        result = point_in_polygon_shape(shapefile,
990                                                      i, 0, 1,                                                      i, 0, 1,
991                                                      map_proj, layer_proj,                                                      map_proj, layer_proj,
992                                                      scale, -scale, offx, offy,                                                      scale, -scale, offx, offy,
# Line 886  class MapCanvas(wxWindow, Publisher): Line 1048  class MapCanvas(wxWindow, Publisher):
1048              # a label was selected              # a label was selected
1049              label_layer.RemoveLabel(shape_index)              label_layer.RemoveLabel(shape_index)
1050          elif layer is not None:          elif layer is not None:
1051              text = labeldialog.run_label_dialog(self, layer.table, shape_index)              text = labeldialog.run_label_dialog(self,
1052                                                    layer.ShapeStore().Table(),
1053                                                    shape_index)
1054              if text:              if text:
1055                  proj = self.map.projection                  proj = self.map.projection
1056                  if proj is not None:                  if proj is not None:
# Line 901  class MapCanvas(wxWindow, Publisher): Line 1065  class MapCanvas(wxWindow, Publisher):
1065    
1066                  shapetype = layer.ShapeType()                  shapetype = layer.ShapeType()
1067                  if shapetype == SHAPETYPE_POLYGON:                  if shapetype == SHAPETYPE_POLYGON:
1068                      x, y = shape_centroid(layer.shapefile.cobject(),                      shapefile = layer.ShapeStore().Shapefile().cobject()
1069                                            shape_index,                      x, y = shape_centroid(shapefile, shape_index,
1070                                            map_proj, layer_proj, 1, 1, 0, 0)                                            map_proj, layer_proj, 1, 1, 0, 0)
1071                      if map_proj is not None:                      if map_proj is not None:
1072                          x, y = map_proj.Inverse(x, y)                          x, y = map_proj.Inverse(x, y)
# Line 927  class MapCanvas(wxWindow, Publisher): Line 1091  class MapCanvas(wxWindow, Publisher):
1091                      valign = ALIGN_CENTER                      valign = ALIGN_CENTER
1092                  label_layer.AddLabel(x, y, text,                  label_layer.AddLabel(x, y, text,
1093                                       halign = halign, valign = valign)                                       halign = halign, valign = valign)
1094    
1095    def OutputTransform(canvas_scale, canvas_offset, canvas_size, device_extend):
1096        """Calculate dimensions to transform canvas content to output device."""
1097        width, height = device_extend
1098    
1099        # Only 80 % of the with are available for the map
1100        width = width * 0.8
1101    
1102        # Define the distance of the map from DC border
1103        distance = 20
1104    
1105        if height < width:
1106            # landscape
1107            map_height = height - 2*distance
1108            map_width = map_height
1109        else:
1110            # portrait, recalibrate width (usually the legend width is too
1111            # small
1112            width = width * 0.9
1113            map_height = width - 2*distance
1114            map_width = map_height
1115        
1116        mapregion = (distance, distance,
1117                     distance+map_width, distance+map_height)
1118    
1119        canvas_width, canvas_height = canvas_size
1120        
1121        scalex = map_width / (canvas_width/canvas_scale)
1122        scaley = map_height / (canvas_height/canvas_scale)
1123        scale = min(scalex, scaley)
1124        canvas_offx, canvas_offy = canvas_offset
1125        offx = scale*canvas_offx/canvas_scale
1126        offy = scale*canvas_offy/canvas_scale
1127    
1128        return scale, (offx, offy), mapregion

Legend:
Removed from v.822  
changed lines
  Added in v.1344

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26