1 |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jonathan Coles <[email protected]> |
# Jonathan Coles <[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. |
14 |
|
|
15 |
from wxPython.wx import * |
from wxPython.wx import * |
16 |
|
|
17 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import BaseLayer |
18 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
|
from Thuban.Model.messages import * |
|
19 |
from Thuban.Model.classification import ClassGroup |
from Thuban.Model.classification import ClassGroup |
20 |
|
|
21 |
from Thuban.UI.messages import * |
from Thuban.Model.messages import \ |
22 |
|
MAP_STACKING_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED, LAYER_CHANGED,\ |
23 |
|
LAYER_VISIBILITY_CHANGED, TITLE_CHANGED |
24 |
|
|
25 |
|
from Thuban.UI.messages import SCALE_CHANGED |
26 |
|
|
27 |
from Thuban.UI.classifier import ClassDataPreviewer |
from Thuban.UI.classifier import ClassDataPreviewer |
28 |
from Thuban.UI.dock import DockPanel |
from Thuban.UI.dock import DockPanel |
29 |
|
from Thuban.UI.scalebar import ScaleBar |
30 |
|
|
31 |
from Thuban.Lib.connector import ConnectorError |
from Thuban.Lib.connector import ConnectorError |
32 |
|
|
60 |
panelBox = wxBoxSizer(wxVERTICAL) |
panelBox = wxBoxSizer(wxVERTICAL) |
61 |
|
|
62 |
self.toolBar = wxToolBar(self, -1) |
self.toolBar = wxToolBar(self, -1) |
63 |
|
self.toolBar.SetToolBitmapSize(wxSize(24, 24)) |
64 |
|
|
65 |
bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM) |
bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM) |
66 |
self.toolBar.AddTool(ID_LEGEND_RAISE, bmp, |
self.toolBar.AddTool(ID_LEGEND_RAISE, bmp, |
83 |
shortHelpString=_("Edit Layer Properties")) |
shortHelpString=_("Edit Layer Properties")) |
84 |
|
|
85 |
self.toolBar.Realize() |
self.toolBar.Realize() |
86 |
panelBox.Add(self.toolBar, 0, wxALL, 0) |
panelBox.Add(self.toolBar, 0, wxGROW, 0) |
87 |
|
|
88 |
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
89 |
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
93 |
|
|
94 |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
95 |
|
|
96 |
panelBox.Add(self.tree, 1, wxGROW, 4) |
panelBox.Add(self.tree, 1, wxGROW, 0) |
97 |
|
|
98 |
panelBox.Fit(self) |
self.scalebarbitmap = ScaleBarBitmap(self, map, mainWindow) |
99 |
|
panelBox.Add(self.scalebarbitmap, 0, wxGROW, 0) |
100 |
|
|
101 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
102 |
self.SetSizer(panelBox) |
self.SetSizer(panelBox) |
103 |
panelBox.SetSizeHints(self) |
panelBox.SetSizeHints(self) |
104 |
|
|
105 |
|
|
106 |
self.panelBox = panelBox |
self.panelBox = panelBox |
107 |
|
|
108 |
self.__EnableButtons(False) |
self.__EnableButtons(False) |
109 |
|
|
110 |
|
self.Create() |
111 |
|
|
112 |
EVT_CLOSE(self, self._OnClose) |
EVT_CLOSE(self, self._OnClose) |
113 |
|
|
114 |
|
|
117 |
|
|
118 |
def SetMap(self, map): |
def SetMap(self, map): |
119 |
self.tree.SetMap(map) |
self.tree.SetMap(map) |
120 |
|
self.scalebarbitmap.SetCanvas(self.mainWindow.canvas) |
121 |
|
|
122 |
def DoOnSelChanged(self, layer, group): |
def DoOnSelChanged(self, layer, group): |
123 |
|
|
124 |
ok = isinstance(layer, Layer) |
ok = isinstance(layer, BaseLayer) |
125 |
self.__EnableButtons(ok) |
self.__EnableButtons(ok) |
126 |
|
|
127 |
self.mainWindow.SelectLayer(layer) |
self.mainWindow.SelectLayer(layer) |
129 |
def DoOnProperties(self): |
def DoOnProperties(self): |
130 |
list = self.tree.GetSelectedHierarchy() |
list = self.tree.GetSelectedHierarchy() |
131 |
|
|
132 |
ok = isinstance(list[0], Layer) |
ok = isinstance(list[0], BaseLayer) |
133 |
if ok: |
if ok: |
134 |
self.mainWindow.OpenLayerProperties(list[0], list[1]) |
self.mainWindow.OpenLayerProperties(list[0], list[1]) |
135 |
|
|
226 |
#self._OnMsgMapsChanged) |
#self._OnMsgMapsChanged) |
227 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
228 |
|
|
|
|
|
229 |
def MoveCurrentItemUp(self): |
def MoveCurrentItemUp(self): |
230 |
cur_id = self.GetSelection() |
layer, group = self.GetSelectedHierarchy() |
|
assert cur_id.IsOk() |
|
|
|
|
|
cur_data = self.GetPyData(cur_id) |
|
|
|
|
|
#prev_id = self.GetPrevSibling(cur_id) |
|
|
|
|
|
# |
|
|
# Get out if there's nowhere to go |
|
|
# |
|
|
#if prev_id == INVALID_TREE_ID: return |
|
231 |
|
|
232 |
if isinstance(cur_data, Layer): |
if layer is not None: |
233 |
self.map.RaiseLayer(cur_data) |
self.map.RaiseLayer(layer) |
|
elif isinstance(cur_data, ClassGroup): |
|
|
pass |
|
234 |
else: |
else: |
235 |
assert False, "Shouldn't be here." |
assert False, "Shouldn't be allowed." |
236 |
pass |
pass |
237 |
|
|
238 |
def MoveCurrentItemDown(self): |
def MoveCurrentItemDown(self): |
239 |
cur_id = self.GetSelection() |
layer, group = self.GetSelectedHierarchy() |
|
assert cur_id.IsOk() |
|
|
|
|
|
cur_data = self.GetPyData(cur_id) |
|
240 |
|
|
241 |
if isinstance(cur_data, Layer): |
if layer is not None: |
242 |
self.map.LowerLayer(cur_data) |
self.map.LowerLayer(layer) |
|
elif isinstance(cur_data, ClassGroup): |
|
|
pass |
|
243 |
else: |
else: |
244 |
assert False, "Shouldn't be here." |
assert False, "Shouldn't be allowed." |
245 |
pass |
pass |
246 |
|
|
|
|
|
247 |
def OnCompareItems(self, item1, item2): |
def OnCompareItems(self, item1, item2): |
248 |
|
|
249 |
data1 = self.GetPyData(item1) |
data1 = self.GetPyData(item1) |
250 |
data2 = self.GetPyData(item2) |
data2 = self.GetPyData(item2) |
251 |
|
|
252 |
if isinstance(data1, Layer): |
if isinstance(data1, BaseLayer): |
253 |
layers = self.map.Layers() |
layers = self.map.Layers() |
254 |
return layers.index(data2) - layers.index(data1) |
return layers.index(data2) - layers.index(data1) |
255 |
else: |
else: |
256 |
return wxTreeCtrl.OnCompareItems(self, item1, item2) |
return wxTreeCtrl.OnCompareItems(self, item1, item2) |
257 |
|
|
|
|
|
258 |
def DoOnShowLayer(self): |
def DoOnShowLayer(self): |
259 |
#self.__ShowHideLayer(True) |
#self.__ShowHideLayer(True) |
260 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
296 |
self.parent.DoOnProperties() |
self.parent.DoOnProperties() |
297 |
|
|
298 |
def _OnMsgLayerChanged(self, layer): |
def _OnMsgLayerChanged(self, layer): |
299 |
assert isinstance(layer, Layer) |
assert isinstance(layer, BaseLayer) |
300 |
|
|
301 |
id = self.layer2id[layer] |
id = self.layer2id[layer] |
302 |
assert id.IsOk() |
assert id.IsOk() |
324 |
self.__UpdateSelection() |
self.__UpdateSelection() |
325 |
|
|
326 |
def _OnMsgLayerVisibilityChanged(self, layer): |
def _OnMsgLayerVisibilityChanged(self, layer): |
327 |
assert isinstance(layer, Layer) |
assert isinstance(layer, BaseLayer) |
328 |
|
|
329 |
self.__ShowHideLayer(layer) |
self.__ShowHideLayer(layer) |
330 |
self.__UpdateSelection() |
self.__UpdateSelection() |
342 |
|
|
343 |
def __FillTree(self, map): |
def __FillTree(self, map): |
344 |
|
|
|
assert isinstance(map, Map) |
|
|
|
|
345 |
self.Freeze() |
self.Freeze() |
346 |
|
|
347 |
self.__DeleteAllItems() |
self.__DeleteAllItems() |
387 |
|
|
388 |
self.DeleteChildren(pid) |
self.DeleteChildren(pid) |
389 |
|
|
390 |
clazz = layer.GetClassification() |
if layer.HasClassification(): |
391 |
|
|
392 |
shapeType = layer.ShapeType() |
clazz = layer.GetClassification() |
393 |
|
|
394 |
show = layer.Visible() |
shapeType = layer.ShapeType() |
395 |
for g in clazz: |
|
396 |
if g.IsVisible(): |
show = layer.Visible() |
397 |
id = self.AppendItem(pid, g.GetDisplayText()) |
for g in clazz: |
398 |
self.SetPyData(id, g) |
if g.IsVisible(): |
399 |
self.__SetVisibilityStyle(show, id) |
id = self.AppendItem(pid, g.GetDisplayText()) |
400 |
|
self.SetPyData(id, g) |
401 |
bmp = self.__BuildGroupImage(g, shapeType) |
self.__SetVisibilityStyle(show, id) |
402 |
|
|
403 |
if bmp is None: |
bmp = self.__BuildGroupImage(g, shapeType) |
404 |
self.SetItemImage(id, self.emptyImageIndex) |
|
405 |
else: |
if bmp is None: |
406 |
i = self.image_list.Add(bmp) |
self.SetItemImage(id, self.emptyImageIndex) |
407 |
self.SetItemImage(id, i) |
else: |
408 |
|
i = self.image_list.Add(bmp) |
409 |
|
self.SetItemImage(id, i) |
410 |
|
|
411 |
self.Thaw() |
self.Thaw() |
412 |
|
|
413 |
def __BuildGroupImage(self, group, shapeType): |
def __BuildGroupImage(self, group, shapeType): |
|
assert isinstance(group, ClassGroup) |
|
414 |
|
|
415 |
bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H) |
bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H) |
416 |
#brush = wxBrush(Color2wxColour(item[1]), wxSOLID) |
#brush = wxBrush(Color2wxColour(item[1]), wxSOLID) |
441 |
font.SetStyle(wxNORMAL) |
font.SetStyle(wxNORMAL) |
442 |
color = wxBLACK |
color = wxBLACK |
443 |
else: |
else: |
444 |
font.SetStyle(wxITALIC) |
#font.SetStyle(wxITALIC) |
445 |
|
font.SetStyle(wxNORMAL) |
446 |
color = wxLIGHT_GREY |
color = wxLIGHT_GREY |
447 |
|
|
448 |
self.SetItemTextColour(id, color) |
self.SetItemTextColour(id, color) |
462 |
self.__SetVisibilityStyle(visible, id) |
self.__SetVisibilityStyle(visible, id) |
463 |
id, cookie = self.GetNextChild(parent, cookie) |
id, cookie = self.GetNextChild(parent, cookie) |
464 |
|
|
465 |
|
class ScaleBarBitmap(wxBoxSizer): |
466 |
|
|
467 |
|
def __init__(self, parent, map, mainWindow): |
468 |
|
# While the width is fixed, get the height _now_. |
469 |
|
dc = wxMemoryDC() |
470 |
|
textwidth, textheight = dc.GetTextExtent("%d"%0) |
471 |
|
self.width = 200 |
472 |
|
self.height = textheight + 3*2 + 8 |
473 |
|
|
474 |
|
wxBoxSizer.__init__(self, wxVERTICAL) |
475 |
|
bmp=wxEmptyBitmap(self.width, self.height) |
476 |
|
self.scalebarBitmap = wxStaticBitmap(parent, -1, bmp) |
477 |
|
self.Add(self.scalebarBitmap, 0, wxALIGN_CENTER|wxLEFT|wxTOP|wxRIGHT, 1) |
478 |
|
|
479 |
|
self.mainWindow = mainWindow |
480 |
|
self.parent = parent |
481 |
|
self.canvas = None |
482 |
|
self.SetCanvas(self.mainWindow.canvas) |
483 |
|
|
484 |
|
def SetCanvas(self, canvas): |
485 |
|
sub_list = [(SCALE_CHANGED, self._OnMsgScaleChanged)] |
486 |
|
|
487 |
|
if self.canvas is not None: |
488 |
|
for msg, func in sub_list: self.canvas.Unsubscribe(msg, func) |
489 |
|
|
490 |
|
self.canvas = canvas |
491 |
|
self.scalebar = ScaleBar(canvas.map) |
492 |
|
|
493 |
|
if self.canvas is not None: |
494 |
|
for msg, func in sub_list: self.canvas.Subscribe(msg, func) |
495 |
|
self.__SetScale(self.canvas.scale) |
496 |
|
|
497 |
|
def _OnMsgScaleChanged(self, scale): |
498 |
|
self.__SetScale(scale) |
499 |
|
|
500 |
|
def __SetScale(self, scale): |
501 |
|
bmp = wxEmptyBitmap(self.width, self.height) |
502 |
|
dc = wxMemoryDC() |
503 |
|
dc.SelectObject(bmp) |
504 |
|
dc.Clear() |
505 |
|
|
506 |
|
self.scalebar.DrawScaleBar(scale, dc, (0,0), dc.GetSizeTuple()) |
507 |
|
|
508 |
|
self.scalebarBitmap.SetBitmap(bmp) |
509 |
|
|