11 |
|
|
12 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
13 |
|
|
14 |
|
import sys |
15 |
|
|
16 |
from math import hypot |
from math import hypot |
17 |
|
|
18 |
from wxPython.wx import wxWindow,\ |
from wxPython.wx import wxWindow,\ |
19 |
wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\ |
wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\ |
20 |
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, \ |
21 |
|
wxBITMAP_TYPE_XPM, wxBeginBusyCursor, wxEndBusyCursor, wxCursor, \ |
22 |
|
wxImageFromBitmap |
23 |
|
|
24 |
|
|
25 |
from wxPython import wx |
from wxPython import wx |
28 |
|
|
29 |
|
|
30 |
from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \ |
from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \ |
31 |
LAYERS_CHANGED, LAYER_LEGEND_CHANGED, LAYER_VISIBILITY_CHANGED |
MAP_LAYERS_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED |
32 |
from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \ |
from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \ |
33 |
SHAPETYPE_POINT |
SHAPETYPE_POINT |
34 |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
36 |
from Thuban.Lib.connector import Publisher |
from Thuban.Lib.connector import Publisher |
37 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
38 |
|
|
39 |
|
import resource |
40 |
|
|
41 |
from selection import Selection |
from selection import Selection |
42 |
from renderer import ScreenRenderer, PrinterRender |
from renderer import ScreenRenderer, PrinterRender |
43 |
|
|
265 |
"""A widget that displays a map and offers some interaction""" |
"""A widget that displays a map and offers some interaction""" |
266 |
|
|
267 |
# Some messages that can be subscribed/unsubscribed directly through |
# Some messages that can be subscribed/unsubscribed directly through |
268 |
# the MapCanvas come in fact from other objects. This is a map to |
# the MapCanvas come in fact from other objects. This is a dict |
269 |
# map those messages to the names of the instance variables they |
# mapping those messages to the names of the instance variables they |
270 |
# actually come from. This delegation is implemented in the |
# actually come from. The delegation is implemented in the Subscribe |
271 |
# Subscribe and unsubscribed methods |
# and Unsubscribe methods |
272 |
delegated_messages = {LAYER_SELECTED: "selection", |
delegated_messages = {LAYER_SELECTED: "selection", |
273 |
SHAPES_SELECTED: "selection"} |
SHAPES_SELECTED: "selection"} |
274 |
|
|
359 |
|
|
360 |
def OnPaint(self, event): |
def OnPaint(self, event): |
361 |
dc = wxPaintDC(self) |
dc = wxPaintDC(self) |
362 |
if self.map is not None and self.map.HasLayers(): |
clear = self.map is None or not self.map.HasLayers() |
363 |
self.do_redraw() |
|
364 |
else: |
#wxBeginBusyCursor() |
365 |
|
|
366 |
|
if not clear: |
367 |
|
try: |
368 |
|
self.do_redraw() |
369 |
|
except: |
370 |
|
print "Error during drawing:", sys.exc_info()[0] |
371 |
|
clear = True |
372 |
|
|
373 |
|
if clear: |
374 |
# 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 |
375 |
# the screen. |
# the screen. |
376 |
|
|
382 |
dc.Clear() |
dc.Clear() |
383 |
dc.EndDrawing() |
dc.EndDrawing() |
384 |
|
|
385 |
|
#wxEndBusyCursor() |
386 |
|
|
387 |
def do_redraw(self): |
def do_redraw(self): |
388 |
# This should only be called if we have a non-empty map. |
# This should only be called if we have a non-empty map. |
389 |
|
|
400 |
dc.BeginDrawing() |
dc.BeginDrawing() |
401 |
|
|
402 |
# clear the background |
# clear the background |
403 |
dc.SetBrush(wx.wxWHITE_BRUSH) |
#dc.SetBrush(wx.wxWHITE_BRUSH) |
404 |
dc.SetPen(wx.wxTRANSPARENT_PEN) |
#dc.SetPen(wx.wxTRANSPARENT_PEN) |
405 |
dc.DrawRectangle(0, 0, width, height) |
#dc.DrawRectangle(0, 0, width, height) |
406 |
|
dc.SetBackground(wx.wxWHITE_BRUSH) |
407 |
|
dc.Clear() |
408 |
|
|
409 |
selected_layer = self.selection.SelectedLayer() |
selected_layer = self.selection.SelectedLayer() |
410 |
selected_shapes = self.selection.SelectedShapes() |
selected_shapes = self.selection.SelectedShapes() |
436 |
printout.Destroy() |
printout.Destroy() |
437 |
|
|
438 |
def SetMap(self, map): |
def SetMap(self, map): |
439 |
redraw_channels = (LAYERS_CHANGED, LAYER_LEGEND_CHANGED, |
redraw_channels = (MAP_LAYERS_CHANGED, LAYER_CHANGED, |
440 |
LAYER_VISIBILITY_CHANGED) |
LAYER_VISIBILITY_CHANGED) |
441 |
if self.map is not None: |
if self.map is not None: |
442 |
for channel in redraw_channels: |
for channel in redraw_channels: |
498 |
width, height = self.GetSizeTuple() |
width, height = self.GetSizeTuple() |
499 |
llx, lly, urx, ury = rect |
llx, lly, urx, ury = rect |
500 |
if llx == urx or lly == ury: |
if llx == urx or lly == ury: |
501 |
# zero with or zero height. Do Nothing |
# zero width or zero height. Do Nothing |
502 |
return |
return |
503 |
scalex = width / (urx - llx) |
scalex = width / (urx - llx) |
504 |
scaley = height / (ury - lly) |
scaley = height / (ury - lly) |
517 |
if bbox is not None: |
if bbox is not None: |
518 |
self.FitRectToWindow(bbox) |
self.FitRectToWindow(bbox) |
519 |
|
|
520 |
|
def FitLayerToWindow(self, layer): |
521 |
|
"""Fit the given layer to the window. |
522 |
|
|
523 |
|
Set the scale so that the layer fits exactly into the window and |
524 |
|
center it in the window. |
525 |
|
""" |
526 |
|
|
527 |
|
bbox = layer.LatLongBoundingBox() |
528 |
|
if bbox is not None: |
529 |
|
proj = self.map.GetProjection() |
530 |
|
if proj is not None: |
531 |
|
bbox = proj.ForwardBBox(bbox) |
532 |
|
|
533 |
|
if bbox is not None: |
534 |
|
self.FitRectToWindow(bbox) |
535 |
|
|
536 |
def ZoomFactor(self, factor, center = None): |
def ZoomFactor(self, factor, center = None): |
537 |
"""Multiply the zoom by factor and center on center. |
"""Multiply the zoom by factor and center on center. |
538 |
|
|
596 |
def PanTool(self): |
def PanTool(self): |
597 |
"""Start the pan tool""" |
"""Start the pan tool""" |
598 |
self.SelectTool(PanTool(self)) |
self.SelectTool(PanTool(self)) |
599 |
|
#img = resource.GetImageResource("pan", wxBITMAP_TYPE_XPM) |
600 |
|
#bmp = resource.GetBitmapResource("pan", wxBITMAP_TYPE_XPM) |
601 |
|
#print bmp |
602 |
|
#img = wxImageFromBitmap(bmp) |
603 |
|
#print img |
604 |
|
#cur = wxCursor(img) |
605 |
|
#print cur |
606 |
|
#self.SetCursor(cur) |
607 |
|
|
608 |
def IdentifyTool(self): |
def IdentifyTool(self): |
609 |
"""Start the identify tool""" |
"""Start the identify tool""" |
682 |
# Even when the window becomes larger some parts of the bitmap |
# Even when the window becomes larger some parts of the bitmap |
683 |
# could be reused. |
# could be reused. |
684 |
self.full_redraw() |
self.full_redraw() |
685 |
|
pass |
686 |
|
|
687 |
def shape_selected(self, layer, shape): |
def shape_selected(self, layer, shape): |
688 |
"""Receiver for the SHAPES_SELECTED messages. Redraw the map.""" |
"""Receiver for the SHAPES_SELECTED messages. Redraw the map.""" |
785 |
continue |
continue |
786 |
|
|
787 |
filled = layer.GetClassification().GetDefaultFill() \ |
filled = layer.GetClassification().GetDefaultFill() \ |
788 |
is not Color.None |
is not Color.Transparent |
789 |
stroked = layer.GetClassification().GetDefaultLineColor() \ |
stroked = layer.GetClassification().GetDefaultLineColor() \ |
790 |
is not Color.None |
is not Color.Transparent |
791 |
|
|
792 |
layer_proj = layer.projection |
layer_proj = layer.projection |
793 |
if layer_proj is not None: |
if layer_proj is not None: |