1 |
# Copyright (C) 2001, 2002, 2003, 2004 by Intevation GmbH |
# Copyright (C) 2001, 2002, 2003, 2004, 2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jan-Oliver Wagner <[email protected]> |
# Jan-Oliver Wagner <[email protected]> |
4 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
23 |
import Thuban |
import Thuban |
24 |
|
|
25 |
from Thuban import _ |
from Thuban import _ |
26 |
from Thuban.Model.messages import TITLE_CHANGED |
from Thuban.Model.messages import TITLE_CHANGED, LAYER_PROJECTION_CHANGED, \ |
27 |
|
MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED |
28 |
|
|
29 |
from Thuban.Model.session import create_empty_session |
from Thuban.Model.session import create_empty_session |
30 |
from Thuban.Model.layer import Layer, RasterLayer |
from Thuban.Model.layer import Layer, RasterLayer |
31 |
from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support |
from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support |
54 |
|
|
55 |
import projdialog |
import projdialog |
56 |
|
|
57 |
|
from Thuban.UI.classifier import Classifier |
58 |
|
from Thuban.UI.rasterlayerproperties import RasterLayerProperties |
59 |
|
from Thuban.Model.layer import RasterLayer |
60 |
|
|
61 |
from Thuban.Lib.classmapper import ClassMapper |
from Thuban.Lib.classmapper import ClassMapper |
62 |
|
|
63 |
layer_properties_dialogs = ClassMapper() |
layer_properties_dialogs = ClassMapper() |
64 |
|
layer_properties_dialogs.add(RasterLayer, RasterLayerProperties) |
65 |
|
layer_properties_dialogs.add(Layer, Classifier) |
66 |
|
|
67 |
class MainWindow(DockFrame): |
class MainWindow(DockFrame): |
68 |
|
|
83 |
"SelectedShapes": "canvas", |
"SelectedShapes": "canvas", |
84 |
} |
} |
85 |
|
|
86 |
|
# Messages from the canvas that may require a status bar update. |
87 |
|
# The update_status_bar method will be subscribed to these messages. |
88 |
|
update_status_bar_messages = (VIEW_POSITION, LAYER_PROJECTION_CHANGED, |
89 |
|
MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED, |
90 |
|
MAP_LAYERS_REMOVED) |
91 |
|
|
92 |
def __init__(self, parent, ID, title, application, interactor, |
def __init__(self, parent, ID, title, application, interactor, |
93 |
initial_message = None, size = wxSize(-1, -1)): |
initial_message = None, size = wxSize(-1, -1)): |
94 |
DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
115 |
|
|
116 |
# Create the map canvas |
# Create the map canvas |
117 |
canvas = view.MapCanvas(self, -1) |
canvas = view.MapCanvas(self, -1) |
|
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
|
118 |
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
119 |
self.canvas = canvas |
self.canvas = canvas |
120 |
self.canvas.Subscribe(TITLE_CHANGED, self.title_changed) |
self.canvas.Subscribe(TITLE_CHANGED, self.title_changed) |
121 |
|
|
122 |
|
for channel in self.update_status_bar_messages: |
123 |
|
self.canvas.Subscribe(channel, self.update_status_bar) |
124 |
|
|
125 |
self.SetMainWindow(self.canvas) |
self.SetMainWindow(self.canvas) |
126 |
|
|
127 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
350 |
def get_open_dialog(self, name): |
def get_open_dialog(self, name): |
351 |
return self.dialogs.get(name) |
return self.dialogs.get(name) |
352 |
|
|
353 |
def view_position_changed(self): |
def update_status_bar(self, *args): |
354 |
|
"""Handler for a bunch of messages that may require a status bar update |
355 |
|
|
356 |
|
Currently this handles the canvas' VIEW_POSITION_CHANGED |
357 |
|
messages as well as several messages about changes in the map |
358 |
|
which may affect whether and how projections are used. |
359 |
|
|
360 |
|
These messages affect the text in the status bar in the following way: |
361 |
|
|
362 |
|
When VIEW_POSITION_CHANGED messages are sent and the mouse is |
363 |
|
actually in the canvas window, display the current mouse |
364 |
|
coordinates as defined by the canvas' CurrentPosition method. |
365 |
|
|
366 |
|
If there is no current position to show, check whether there is |
367 |
|
a potential problem with the map and layer projections and |
368 |
|
display a message about it. Otherwise the status bar will |
369 |
|
become empty. |
370 |
|
|
371 |
|
The text is displayed in the status bar using the |
372 |
|
set_position_text method. |
373 |
|
""" |
374 |
|
# Implementation note: We do not really have to know which |
375 |
|
# message was sent. We can simply call the canvas' |
376 |
|
# CurrentPosition method and if that returns a tuple, it was a |
377 |
|
# VIEW_POSITION_CHANGED message and we have to display it. |
378 |
|
# Otherwise it was a VIEW_POSITION_CHANGED message where the |
379 |
|
# mouse has left the canvas or it was a message about a change |
380 |
|
# to the map, in which case we check the projections. |
381 |
|
# |
382 |
|
# When changing this method, keep in mind that the |
383 |
|
# VIEW_POSITION_CHANGED message are sent for every mouse move in |
384 |
|
# the canvas window, that is they happen very often, so the path |
385 |
|
# taken in that case has to be fast. |
386 |
|
text = "" |
387 |
pos = self.canvas.CurrentPosition() |
pos = self.canvas.CurrentPosition() |
388 |
if pos is not None: |
if pos is not None: |
389 |
text = "(%10.10g, %10.10g)" % pos |
text = "(%10.10g, %10.10g)" % pos |
390 |
else: |
else: |
391 |
text = "" |
for layer in self.canvas.Map().Layers(): |
392 |
|
bbox = layer.LatLongBoundingBox() |
393 |
|
if bbox: |
394 |
|
left, bottom, right, top = bbox |
395 |
|
if not (-180 <= left <= 180 and |
396 |
|
-180 <= right <= 180 and |
397 |
|
-90 <= top <= 90 and |
398 |
|
-90 <= bottom <= 90): |
399 |
|
text = _("Select layer '%s' and pick a projection " |
400 |
|
"using Layer/Projection...") % layer.title |
401 |
|
break |
402 |
|
|
403 |
self.set_position_text(text) |
self.set_position_text(text) |
404 |
|
|
405 |
def set_position_text(self, text): |
def set_position_text(self, text): |
406 |
"""Set the statusbar text showing the current position. |
"""Set the statusbar text to that created by update_status_bar |
407 |
|
|
408 |
By default the text is shown in field 0 of the status bar. |
By default the text is shown in field 0 of the status bar. |
409 |
Override this method in derived classes to put it into a |
Override this method in derived classes to put it into a |
410 |
different field of the statusbar. |
different field of the statusbar. |
411 |
""" |
|
412 |
|
For historical reasons this method is called set_position_text |
413 |
|
because at first the text was always either the current position |
414 |
|
or the empty string. Now it can contain other messages as well. |
415 |
|
The method will be renamed at one point. |
416 |
|
""" |
417 |
|
# Note: If this method is renamed we should perhaps think about |
418 |
|
# some backwards compatibility measures for projects like |
419 |
|
# GREAT-ER which override this method. |
420 |
self.SetStatusText(text) |
self.SetStatusText(text) |
421 |
|
|
422 |
def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw): |
def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw): |
508 |
# FIXME: it would be better to tie the unsubscription to |
# FIXME: it would be better to tie the unsubscription to |
509 |
# wx's destroy event, but that isn't implemented for wxGTK |
# wx's destroy event, but that isn't implemented for wxGTK |
510 |
# yet. |
# yet. |
511 |
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
for channel in self.update_status_bar_messages: |
512 |
|
self.canvas.Unsubscribe(channel, self.update_status_bar) |
513 |
|
|
514 |
DockFrame.OnClose(self, event) |
DockFrame.OnClose(self, event) |
515 |
for dlg in self.dialogs.values(): |
for dlg in self.dialogs.values(): |
516 |
dlg.Destroy() |
dlg.Destroy() |
723 |
layer.ShapeStore(), |
layer.ShapeStore(), |
724 |
projection = layer.GetProjection()) |
projection = layer.GetProjection()) |
725 |
new_classification = copy.deepcopy(layer.GetClassification()) |
new_classification = copy.deepcopy(layer.GetClassification()) |
726 |
new_layer.SetClassificationColumn( |
new_layer.SetClassificationColumn( |
727 |
layer.GetClassificationColumn()) |
layer.GetClassificationColumn()) |
728 |
new_layer.SetClassification(new_classification) |
new_layer.SetClassification(new_classification) |
729 |
self.Map().AddLayer(new_layer) |
self.Map().AddLayer(new_layer) |
730 |
|
|