15 |
|
|
16 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
17 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
18 |
|
from Thuban.Model.scalebar import ScaleBar |
19 |
from Thuban.Model.messages import * |
from Thuban.Model.messages import * |
20 |
from Thuban.Model.classification import ClassGroup |
from Thuban.Model.classification import ClassGroup |
21 |
|
|
78 |
shortHelpString=_("Edit Layer Properties")) |
shortHelpString=_("Edit Layer Properties")) |
79 |
|
|
80 |
self.toolBar.Realize() |
self.toolBar.Realize() |
81 |
panelBox.Add(self.toolBar, 0, wxALL, 0) |
panelBox.Add(self.toolBar, 0, wxGROW, 0) |
82 |
|
|
83 |
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
84 |
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
90 |
|
|
91 |
panelBox.Add(self.tree, 1, wxGROW, 0) |
panelBox.Add(self.tree, 1, wxGROW, 0) |
92 |
|
|
93 |
#panelBox.Fit(self) |
self.scalebarbitmap = ScaleBarBitmap(self, map, mainWindow) |
94 |
|
panelBox.Add(self.scalebarbitmap, 0, wxGROW, 0) |
95 |
|
|
96 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
97 |
self.SetSizer(panelBox) |
self.SetSizer(panelBox) |
98 |
panelBox.SetSizeHints(self) |
panelBox.SetSizeHints(self) |
99 |
|
|
|
print "legend: ", self.GetSize() |
|
100 |
|
|
101 |
self.panelBox = panelBox |
self.panelBox = panelBox |
102 |
|
|
112 |
|
|
113 |
def SetMap(self, map): |
def SetMap(self, map): |
114 |
self.tree.SetMap(map) |
self.tree.SetMap(map) |
115 |
|
self.scalebarbitmap.SetCanvas(self.mainWindow.canvas) |
116 |
|
|
117 |
def DoOnSelChanged(self, layer, group): |
def DoOnSelChanged(self, layer, group): |
118 |
|
|
221 |
#self._OnMsgMapsChanged) |
#self._OnMsgMapsChanged) |
222 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
223 |
|
|
|
|
|
224 |
def MoveCurrentItemUp(self): |
def MoveCurrentItemUp(self): |
225 |
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 |
|
226 |
|
|
227 |
if isinstance(cur_data, Layer): |
if layer is not None: |
228 |
self.map.RaiseLayer(cur_data) |
self.map.RaiseLayer(layer) |
|
elif isinstance(cur_data, ClassGroup): |
|
|
pass |
|
229 |
else: |
else: |
230 |
assert False, "Shouldn't be here." |
assert False, "Shouldn't be allowed." |
231 |
pass |
pass |
232 |
|
|
233 |
def MoveCurrentItemDown(self): |
def MoveCurrentItemDown(self): |
234 |
cur_id = self.GetSelection() |
layer, group = self.GetSelectedHierarchy() |
|
assert cur_id.IsOk() |
|
|
|
|
|
cur_data = self.GetPyData(cur_id) |
|
235 |
|
|
236 |
if isinstance(cur_data, Layer): |
if layer is not None: |
237 |
self.map.LowerLayer(cur_data) |
self.map.LowerLayer(layer) |
|
elif isinstance(cur_data, ClassGroup): |
|
|
pass |
|
238 |
else: |
else: |
239 |
assert False, "Shouldn't be here." |
assert False, "Shouldn't be allowed." |
240 |
pass |
pass |
241 |
|
|
|
|
|
242 |
def OnCompareItems(self, item1, item2): |
def OnCompareItems(self, item1, item2): |
243 |
|
|
244 |
data1 = self.GetPyData(item1) |
data1 = self.GetPyData(item1) |
338 |
|
|
339 |
def __FillTree(self, map): |
def __FillTree(self, map): |
340 |
|
|
|
assert isinstance(map, Map) |
|
|
|
|
341 |
self.Freeze() |
self.Freeze() |
342 |
|
|
343 |
self.__DeleteAllItems() |
self.__DeleteAllItems() |
405 |
self.Thaw() |
self.Thaw() |
406 |
|
|
407 |
def __BuildGroupImage(self, group, shapeType): |
def __BuildGroupImage(self, group, shapeType): |
|
assert isinstance(group, ClassGroup) |
|
408 |
|
|
409 |
bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H) |
bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H) |
410 |
#brush = wxBrush(Color2wxColour(item[1]), wxSOLID) |
#brush = wxBrush(Color2wxColour(item[1]), wxSOLID) |
455 |
self.__SetVisibilityStyle(visible, id) |
self.__SetVisibilityStyle(visible, id) |
456 |
id, cookie = self.GetNextChild(parent, cookie) |
id, cookie = self.GetNextChild(parent, cookie) |
457 |
|
|
458 |
|
class ScaleBarBitmap(wxBoxSizer): |
459 |
|
|
460 |
|
def __init__(self, parent, map, mainWindow): |
461 |
|
# While the width is fixed, get the height _now_. |
462 |
|
dc = wxMemoryDC() |
463 |
|
textwidth, textheight = dc.GetTextExtent("%d"%0) |
464 |
|
self.width = 200 |
465 |
|
self.height = textheight + 3*2 + 8 |
466 |
|
|
467 |
|
wxBoxSizer.__init__(self, wxVERTICAL) |
468 |
|
bmp=wxEmptyBitmap(self.width, self.height) |
469 |
|
self.scalebarBitmap = wxStaticBitmap(parent, -1, bmp) |
470 |
|
self.Add(self.scalebarBitmap, 0, wxALIGN_CENTER|wxLEFT|wxTOP|wxRIGHT, 1) |
471 |
|
|
472 |
|
self.mainWindow = mainWindow |
473 |
|
self.parent = parent |
474 |
|
self.canvas = None |
475 |
|
self.scalebar = ScaleBar(map) |
476 |
|
self.SetCanvas(self.mainWindow.canvas) |
477 |
|
|
478 |
|
def SetCanvas(self, canvas): |
479 |
|
sub_list = [(SCALE_CHANGED, self._OnMsgScaleChanged)] |
480 |
|
|
481 |
|
if self.canvas is not None: |
482 |
|
for msg, func in sub_list: self.canvas.Unsubscribe(msg, func) |
483 |
|
|
484 |
|
self.canvas = canvas |
485 |
|
|
486 |
|
if self.canvas is not None: |
487 |
|
for msg, func in sub_list: self.canvas.Subscribe(msg, func) |
488 |
|
self.__SetScale(self.canvas.scale) |
489 |
|
|
490 |
|
def _OnMsgScaleChanged(self, scale): |
491 |
|
self.__SetScale(scale) |
492 |
|
|
493 |
|
def __SetScale(self, scale): |
494 |
|
bmp = wxEmptyBitmap(self.width, self.height) |
495 |
|
dc = wxMemoryDC() |
496 |
|
dc.SelectObject(bmp) |
497 |
|
dc.Clear() |
498 |
|
|
499 |
|
self.scalebar.DrawScalebar(scale, dc) |
500 |
|
|
501 |
|
self.scalebarBitmap.SetBitmap(bmp) |
502 |
|
|