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.scalebar import ScaleBar |
|
|
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 |
|
|
33 |
ID_LEGEND_RAISE = 4001 |
ID_LEGEND_TOP = 4001 |
34 |
ID_LEGEND_LOWER = 4002 |
ID_LEGEND_RAISE = 4002 |
35 |
ID_LEGEND_TREE = 4003 |
ID_LEGEND_LOWER = 4003 |
36 |
ID_LEGEND_PROPS = 4004 |
ID_LEGEND_BOTTOM = 4004 |
37 |
ID_LEGEND_SHOWLAYER = 4005 |
ID_LEGEND_TREE = 4005 |
38 |
ID_LEGEND_HIDELAYER = 4006 |
ID_LEGEND_PROPS = 4006 |
39 |
|
ID_LEGEND_SHOWLAYER = 4007 |
40 |
|
ID_LEGEND_HIDELAYER = 4008 |
41 |
|
|
42 |
BMP_SIZE_W = 30 |
BMP_SIZE_W = 15 |
43 |
BMP_SIZE_H = 15 |
BMP_SIZE_H = 15 |
44 |
|
|
45 |
|
TOP_BMP = "top_layer" |
46 |
RAISE_BMP = "raise_layer" |
RAISE_BMP = "raise_layer" |
47 |
LOWER_BMP = "lower_layer" |
LOWER_BMP = "lower_layer" |
48 |
|
BOTTOM_BMP = "bottom_layer" |
49 |
SHOW_BMP = "show_layer" |
SHOW_BMP = "show_layer" |
50 |
HIDE_BMP = "hide_layer" |
HIDE_BMP = "hide_layer" |
51 |
PROPS_BMP = "layer_properties" |
PROPS_BMP = "layer_properties" |
66 |
self.toolBar = wxToolBar(self, -1) |
self.toolBar = wxToolBar(self, -1) |
67 |
self.toolBar.SetToolBitmapSize(wxSize(24, 24)) |
self.toolBar.SetToolBitmapSize(wxSize(24, 24)) |
68 |
|
|
69 |
|
bmp = resource.GetBitmapResource(TOP_BMP, wxBITMAP_TYPE_XPM) |
70 |
|
self.toolBar.AddTool(ID_LEGEND_TOP, bmp, |
71 |
|
shortHelpString=_("Top Layer")) |
72 |
|
|
73 |
bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM) |
bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM) |
74 |
self.toolBar.AddTool(ID_LEGEND_RAISE, bmp, |
self.toolBar.AddTool(ID_LEGEND_RAISE, bmp, |
75 |
shortHelpString=_("Raise Layer")) |
shortHelpString=_("Raise Layer")) |
78 |
self.toolBar.AddTool(ID_LEGEND_LOWER, bmp, |
self.toolBar.AddTool(ID_LEGEND_LOWER, bmp, |
79 |
shortHelpString=_("Lower Layer")) |
shortHelpString=_("Lower Layer")) |
80 |
|
|
81 |
|
bmp = resource.GetBitmapResource(BOTTOM_BMP, wxBITMAP_TYPE_XPM) |
82 |
|
self.toolBar.AddTool(ID_LEGEND_BOTTOM, bmp, |
83 |
|
shortHelpString=_("Bottom Layer")) |
84 |
|
|
85 |
bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM) |
bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM) |
86 |
self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp, |
self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp, |
87 |
shortHelpString=_("Show Layer")) |
shortHelpString=_("Show Layer")) |
97 |
self.toolBar.Realize() |
self.toolBar.Realize() |
98 |
panelBox.Add(self.toolBar, 0, wxGROW, 0) |
panelBox.Add(self.toolBar, 0, wxGROW, 0) |
99 |
|
|
100 |
|
EVT_TOOL(self, ID_LEGEND_TOP, self._OnMoveTop) |
101 |
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
102 |
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
103 |
|
EVT_TOOL(self, ID_LEGEND_BOTTOM, self._OnMoveBottom) |
104 |
EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties) |
EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties) |
105 |
EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
106 |
EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
135 |
|
|
136 |
def DoOnSelChanged(self, layer, group): |
def DoOnSelChanged(self, layer, group): |
137 |
|
|
138 |
ok = isinstance(layer, Layer) |
ok = isinstance(layer, BaseLayer) |
139 |
self.__EnableButtons(ok) |
self.__EnableButtons(ok) |
140 |
|
|
141 |
self.mainWindow.SelectLayer(layer) |
self.mainWindow.SelectLayer(layer) |
143 |
def DoOnProperties(self): |
def DoOnProperties(self): |
144 |
list = self.tree.GetSelectedHierarchy() |
list = self.tree.GetSelectedHierarchy() |
145 |
|
|
146 |
ok = isinstance(list[0], Layer) |
ok = isinstance(list[0], BaseLayer) |
147 |
if ok: |
if ok: |
148 |
self.mainWindow.OpenLayerProperties(list[0], list[1]) |
self.mainWindow.OpenLayerProperties(list[0], list[1]) |
149 |
|
|
153 |
def _OnProperties(self, event): |
def _OnProperties(self, event): |
154 |
self.DoOnProperties() |
self.DoOnProperties() |
155 |
|
|
156 |
|
def _OnMoveTop(self, event): |
157 |
|
self.tree.MoveCurrentItemTop() |
158 |
|
|
159 |
def _OnMoveUp(self, event): |
def _OnMoveUp(self, event): |
160 |
self.tree.MoveCurrentItemUp() |
self.tree.MoveCurrentItemUp() |
161 |
|
|
162 |
def _OnMoveDown(self, event): |
def _OnMoveDown(self, event): |
163 |
self.tree.MoveCurrentItemDown() |
self.tree.MoveCurrentItemDown() |
164 |
|
|
165 |
|
def _OnMoveBottom(self, event): |
166 |
|
self.tree.MoveCurrentItemBottom() |
167 |
|
|
168 |
def _OnShowLayer(self, event): |
def _OnShowLayer(self, event): |
169 |
self.tree.DoOnShowLayer() |
self.tree.DoOnShowLayer() |
170 |
pass |
pass |
180 |
pass |
pass |
181 |
|
|
182 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
183 |
|
self.toolBar.EnableTool(ID_LEGEND_TOP, on) |
184 |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
185 |
self.toolBar.EnableTool(ID_LEGEND_LOWER, on) |
self.toolBar.EnableTool(ID_LEGEND_LOWER, on) |
186 |
|
self.toolBar.EnableTool(ID_LEGEND_BOTTOM, on) |
187 |
self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER, on) |
self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER, on) |
188 |
self.toolBar.EnableTool(ID_LEGEND_HIDELAYER, on) |
self.toolBar.EnableTool(ID_LEGEND_HIDELAYER, on) |
189 |
self.toolBar.EnableTool(ID_LEGEND_PROPS, on) |
self.toolBar.EnableTool(ID_LEGEND_PROPS, on) |
248 |
#self._OnMsgMapsChanged) |
#self._OnMsgMapsChanged) |
249 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
250 |
|
|
251 |
|
def MoveCurrentItemTop(self): |
252 |
|
layer, group = self.GetSelectedHierarchy() |
253 |
|
|
254 |
|
if layer is not None: |
255 |
|
self.map.TopLayer(layer) |
256 |
|
else: |
257 |
|
assert False, "Shouldn't be allowed." |
258 |
|
pass |
259 |
|
|
260 |
def MoveCurrentItemUp(self): |
def MoveCurrentItemUp(self): |
261 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
262 |
|
|
275 |
assert False, "Shouldn't be allowed." |
assert False, "Shouldn't be allowed." |
276 |
pass |
pass |
277 |
|
|
278 |
|
def MoveCurrentItemBottom(self): |
279 |
|
layer, group = self.GetSelectedHierarchy() |
280 |
|
|
281 |
|
if layer is not None: |
282 |
|
self.map.BottomLayer(layer) |
283 |
|
else: |
284 |
|
assert False, "Shouldn't be allowed." |
285 |
|
pass |
286 |
|
|
287 |
def OnCompareItems(self, item1, item2): |
def OnCompareItems(self, item1, item2): |
288 |
|
|
289 |
data1 = self.GetPyData(item1) |
data1 = self.GetPyData(item1) |
290 |
data2 = self.GetPyData(item2) |
data2 = self.GetPyData(item2) |
291 |
|
|
292 |
if isinstance(data1, Layer): |
if isinstance(data1, BaseLayer): |
293 |
layers = self.map.Layers() |
layers = self.map.Layers() |
294 |
return layers.index(data2) - layers.index(data1) |
return layers.index(data2) - layers.index(data1) |
295 |
else: |
else: |
296 |
return wxTreeCtrl.OnCompareItems(self, item1, item2) |
return wxTreeCtrl.OnCompareItems(self, item1, item2) |
297 |
|
|
|
|
|
298 |
def DoOnShowLayer(self): |
def DoOnShowLayer(self): |
299 |
#self.__ShowHideLayer(True) |
#self.__ShowHideLayer(True) |
300 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
336 |
self.parent.DoOnProperties() |
self.parent.DoOnProperties() |
337 |
|
|
338 |
def _OnMsgLayerChanged(self, layer): |
def _OnMsgLayerChanged(self, layer): |
339 |
assert isinstance(layer, Layer) |
assert isinstance(layer, BaseLayer) |
340 |
|
|
341 |
id = self.layer2id[layer] |
id = self.layer2id[layer] |
342 |
assert id.IsOk() |
assert id.IsOk() |
364 |
self.__UpdateSelection() |
self.__UpdateSelection() |
365 |
|
|
366 |
def _OnMsgLayerVisibilityChanged(self, layer): |
def _OnMsgLayerVisibilityChanged(self, layer): |
367 |
assert isinstance(layer, Layer) |
assert isinstance(layer, BaseLayer) |
368 |
|
|
369 |
self.__ShowHideLayer(layer) |
self.__ShowHideLayer(layer) |
370 |
self.__UpdateSelection() |
self.__UpdateSelection() |
400 |
self.emptyImageIndex = \ |
self.emptyImageIndex = \ |
401 |
self.image_list.AddWithColourMask(bmp, wxColour(0, 0, 0)) |
self.image_list.AddWithColourMask(bmp, wxColour(0, 0, 0)) |
402 |
|
|
403 |
|
bmp = resource.GetBitmapResource("legend_icon_map", |
404 |
|
wxBITMAP_TYPE_XPM) |
405 |
|
self.mapImageIndex = \ |
406 |
|
self.image_list.Add(bmp) |
407 |
|
|
408 |
self.AssignImageList(self.image_list) |
self.AssignImageList(self.image_list) |
409 |
|
|
410 |
root = self.AddRoot("") |
root = self.AddRoot("") |
411 |
|
|
412 |
for l in map.Layers(): |
for l in map.Layers(): |
413 |
id = self.PrependItem(root, l.Title()) |
id = self.PrependItem(root, l.Title()) |
414 |
|
self.SetItemImage(id, self.mapImageIndex) |
415 |
|
self.SetItemSelectedImage(id, self.mapImageIndex) |
416 |
|
|
417 |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
418 |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
419 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
435 |
|
|
436 |
self.DeleteChildren(pid) |
self.DeleteChildren(pid) |
437 |
|
|
438 |
clazz = layer.GetClassification() |
if layer.HasClassification(): |
439 |
|
|
440 |
|
clazz = layer.GetClassification() |
441 |
|
|
442 |
shapeType = layer.ShapeType() |
shapeType = layer.ShapeType() |
443 |
|
|
444 |
show = layer.Visible() |
show = layer.Visible() |
445 |
for g in clazz: |
for g in clazz: |
446 |
if g.IsVisible(): |
if g.IsVisible(): |
447 |
id = self.AppendItem(pid, g.GetDisplayText()) |
id = self.AppendItem(pid, g.GetDisplayText()) |
448 |
self.SetPyData(id, g) |
self.SetPyData(id, g) |
449 |
self.__SetVisibilityStyle(show, id) |
self.__SetVisibilityStyle(show, id) |
450 |
|
|
451 |
bmp = self.__BuildGroupImage(g, shapeType) |
bmp = self.__BuildGroupImage(g, shapeType) |
452 |
|
|
453 |
if bmp is None: |
if bmp is None: |
454 |
self.SetItemImage(id, self.emptyImageIndex) |
self.SetItemImage(id, -1) |
455 |
else: |
self.SetItemSelectedImage(id, -1) |
456 |
i = self.image_list.Add(bmp) |
else: |
457 |
self.SetItemImage(id, i) |
i = self.image_list.Add(bmp) |
458 |
|
self.SetItemImage(id, i) |
459 |
|
self.SetItemSelectedImage(id, i) |
460 |
|
|
461 |
self.Thaw() |
self.Thaw() |
462 |
|
|
491 |
font.SetStyle(wxNORMAL) |
font.SetStyle(wxNORMAL) |
492 |
color = wxBLACK |
color = wxBLACK |
493 |
else: |
else: |
494 |
font.SetStyle(wxITALIC) |
#font.SetStyle(wxITALIC) |
495 |
|
font.SetStyle(wxNORMAL) |
496 |
color = wxLIGHT_GREY |
color = wxLIGHT_GREY |
497 |
|
|
498 |
self.SetItemTextColour(id, color) |
self.SetItemTextColour(id, color) |
518 |
# While the width is fixed, get the height _now_. |
# While the width is fixed, get the height _now_. |
519 |
dc = wxMemoryDC() |
dc = wxMemoryDC() |
520 |
textwidth, textheight = dc.GetTextExtent("%d"%0) |
textwidth, textheight = dc.GetTextExtent("%d"%0) |
521 |
self.width = 200 |
self.width = 210 |
522 |
self.height = textheight + 3*2 + 8 |
self.height = textheight + 3*2 + 8 |
523 |
|
|
524 |
wxBoxSizer.__init__(self, wxVERTICAL) |
wxBoxSizer.__init__(self, wxVERTICAL) |
529 |
self.mainWindow = mainWindow |
self.mainWindow = mainWindow |
530 |
self.parent = parent |
self.parent = parent |
531 |
self.canvas = None |
self.canvas = None |
|
self.scalebar = ScaleBar(map) |
|
532 |
self.SetCanvas(self.mainWindow.canvas) |
self.SetCanvas(self.mainWindow.canvas) |
533 |
|
|
534 |
def SetCanvas(self, canvas): |
def SetCanvas(self, canvas): |
538 |
for msg, func in sub_list: self.canvas.Unsubscribe(msg, func) |
for msg, func in sub_list: self.canvas.Unsubscribe(msg, func) |
539 |
|
|
540 |
self.canvas = canvas |
self.canvas = canvas |
541 |
|
self.scalebar = ScaleBar(canvas.map) |
542 |
|
|
543 |
if self.canvas is not None: |
if self.canvas is not None: |
544 |
for msg, func in sub_list: self.canvas.Subscribe(msg, func) |
for msg, func in sub_list: self.canvas.Subscribe(msg, func) |
553 |
dc.SelectObject(bmp) |
dc.SelectObject(bmp) |
554 |
dc.Clear() |
dc.Clear() |
555 |
|
|
556 |
self.scalebar.DrawScalebar(scale, dc) |
self.scalebar.DrawScaleBar(scale, dc, (0,0), dc.GetSizeTuple()) |
557 |
|
|
558 |
self.scalebarBitmap.SetBitmap(bmp) |
self.scalebarBitmap.SetBitmap(bmp) |
559 |
|
|