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 |
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 |
|
|
277 |
delegated_methods = {"SelectLayer": "selection", |
delegated_methods = {"SelectLayer": "selection", |
278 |
"SelectShapes": "selection", |
"SelectShapes": "selection", |
279 |
"SelectedLayer": "selection", |
"SelectedLayer": "selection", |
280 |
"HasSelectedLayer": "selection"} |
"HasSelectedLayer": "selection", |
281 |
|
"HasSelectedShapes": "selection"} |
282 |
|
|
283 |
def __init__(self, parent, winid): |
def __init__(self, parent, winid): |
284 |
wxWindow.__init__(self, parent, winid) |
wxWindow.__init__(self, parent, winid) |
360 |
|
|
361 |
def OnPaint(self, event): |
def OnPaint(self, event): |
362 |
dc = wxPaintDC(self) |
dc = wxPaintDC(self) |
363 |
if self.map is not None and self.map.HasLayers(): |
clear = self.map is None or not self.map.HasLayers() |
364 |
self.do_redraw() |
|
365 |
else: |
#wxBeginBusyCursor() |
366 |
|
|
367 |
|
if not clear: |
368 |
|
try: |
369 |
|
self.do_redraw() |
370 |
|
except: |
371 |
|
print "Error during drawing:", sys.exc_info()[0] |
372 |
|
clear = True |
373 |
|
|
374 |
|
if clear: |
375 |
# 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 |
376 |
# the screen. |
# the screen. |
377 |
|
|
383 |
dc.Clear() |
dc.Clear() |
384 |
dc.EndDrawing() |
dc.EndDrawing() |
385 |
|
|
386 |
|
#wxEndBusyCursor() |
387 |
|
|
388 |
def do_redraw(self): |
def do_redraw(self): |
389 |
# This should only be called if we have a non-empty map. |
# This should only be called if we have a non-empty map. |
390 |
|
|
401 |
dc.BeginDrawing() |
dc.BeginDrawing() |
402 |
|
|
403 |
# clear the background |
# clear the background |
404 |
dc.SetBrush(wx.wxWHITE_BRUSH) |
#dc.SetBrush(wx.wxWHITE_BRUSH) |
405 |
dc.SetPen(wx.wxTRANSPARENT_PEN) |
#dc.SetPen(wx.wxTRANSPARENT_PEN) |
406 |
dc.DrawRectangle(0, 0, width, height) |
#dc.DrawRectangle(0, 0, width, height) |
407 |
|
dc.SetBackground(wx.wxWHITE_BRUSH) |
408 |
|
dc.Clear() |
409 |
|
|
410 |
selected_layer = self.selection.SelectedLayer() |
selected_layer = self.selection.SelectedLayer() |
411 |
selected_shapes = self.selection.SelectedShapes() |
selected_shapes = self.selection.SelectedShapes() |
499 |
width, height = self.GetSizeTuple() |
width, height = self.GetSizeTuple() |
500 |
llx, lly, urx, ury = rect |
llx, lly, urx, ury = rect |
501 |
if llx == urx or lly == ury: |
if llx == urx or lly == ury: |
502 |
# zero with or zero height. Do Nothing |
# zero width or zero height. Do Nothing |
503 |
return |
return |
504 |
scalex = width / (urx - llx) |
scalex = width / (urx - llx) |
505 |
scaley = height / (ury - lly) |
scaley = height / (ury - lly) |
518 |
if bbox is not None: |
if bbox is not None: |
519 |
self.FitRectToWindow(bbox) |
self.FitRectToWindow(bbox) |
520 |
|
|
521 |
|
def FitLayerToWindow(self, layer): |
522 |
|
"""Fit the given layer to the window. |
523 |
|
|
524 |
|
Set the scale so that the layer fits exactly into the window and |
525 |
|
center it in the window. |
526 |
|
""" |
527 |
|
|
528 |
|
bbox = layer.LatLongBoundingBox() |
529 |
|
if bbox is not None: |
530 |
|
proj = self.map.GetProjection() |
531 |
|
if proj is not None: |
532 |
|
bbox = proj.ForwardBBox(bbox) |
533 |
|
|
534 |
|
if bbox is not None: |
535 |
|
self.FitRectToWindow(bbox) |
536 |
|
|
537 |
|
def FitSelectedToWindow(self): |
538 |
|
layer = self.selection.SelectedLayer() |
539 |
|
shapes = self.selection.SelectedShapes() |
540 |
|
|
541 |
|
bbox = layer.ShapesBoundingBox(shapes) |
542 |
|
if bbox is not None: |
543 |
|
proj = self.map.GetProjection() |
544 |
|
if proj is not None: |
545 |
|
bbox = proj.ForwardBBox(bbox) |
546 |
|
|
547 |
|
if bbox is not None: |
548 |
|
self.FitRectToWindow(bbox) |
549 |
|
|
550 |
def ZoomFactor(self, factor, center = None): |
def ZoomFactor(self, factor, center = None): |
551 |
"""Multiply the zoom by factor and center on center. |
"""Multiply the zoom by factor and center on center. |
552 |
|
|
610 |
def PanTool(self): |
def PanTool(self): |
611 |
"""Start the pan tool""" |
"""Start the pan tool""" |
612 |
self.SelectTool(PanTool(self)) |
self.SelectTool(PanTool(self)) |
613 |
|
#img = resource.GetImageResource("pan", wxBITMAP_TYPE_XPM) |
614 |
|
#bmp = resource.GetBitmapResource("pan", wxBITMAP_TYPE_XPM) |
615 |
|
#print bmp |
616 |
|
#img = wxImageFromBitmap(bmp) |
617 |
|
#print img |
618 |
|
#cur = wxCursor(img) |
619 |
|
#print cur |
620 |
|
#self.SetCursor(cur) |
621 |
|
|
622 |
def IdentifyTool(self): |
def IdentifyTool(self): |
623 |
"""Start the identify tool""" |
"""Start the identify tool""" |
696 |
# Even when the window becomes larger some parts of the bitmap |
# Even when the window becomes larger some parts of the bitmap |
697 |
# could be reused. |
# could be reused. |
698 |
self.full_redraw() |
self.full_redraw() |
699 |
|
pass |
700 |
|
|
701 |
def shape_selected(self, layer, shape): |
def shape_selected(self, layer, shape): |
702 |
"""Receiver for the SHAPES_SELECTED messages. Redraw the map.""" |
"""Receiver for the SHAPES_SELECTED messages. Redraw the map.""" |