184 |
sx, sy = self.start |
sx, sy = self.start |
185 |
cx, cy = self.current |
cx, cy = self.current |
186 |
self.view.Translate(cx - sx, cy - sy) |
self.view.Translate(cx - sx, cy - sy) |
187 |
|
|
188 |
class IdentifyTool(Tool): |
class IdentifyTool(Tool): |
189 |
|
|
190 |
"""The "Identify" Tool""" |
"""The "Identify" Tool""" |
191 |
|
|
192 |
def Name(self): |
def Name(self): |
193 |
return "IdentifyTool" |
return "IdentifyTool" |
194 |
|
|
242 |
renderer = PrinterRender(dc, scale, (offx, offy), resolution = resx) |
renderer = PrinterRender(dc, scale, (offx, offy), resolution = resx) |
243 |
renderer.RenderMap(self.map) |
renderer.RenderMap(self.map) |
244 |
return wx.true |
return wx.true |
245 |
|
|
246 |
|
|
247 |
class MapCanvas(wxWindow, Publisher): |
class MapCanvas(wxWindow, Publisher): |
248 |
|
|
314 |
else: |
else: |
315 |
# 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 |
316 |
# the screen. |
# the screen. |
317 |
|
|
318 |
# XXX it's probably possible to get rid of this. The |
# XXX it's probably possible to get rid of this. The |
319 |
# background color of the window is already white and the |
# background color of the window is already white and the |
320 |
# only thing we may have to do is to call self.Refresh() |
# only thing we may have to do is to call self.Refresh() |
321 |
# with a true argument in the right places. |
# with a true argument in the right places. |
322 |
dc.BeginDrawing() |
dc.BeginDrawing() |
323 |
dc.Clear() |
dc.Clear() |
324 |
dc.EndDrawing() |
dc.EndDrawing() |
325 |
|
|
326 |
# clear the region |
# clear the region |
383 |
printout = MapPrintout(self.map) |
printout = MapPrintout(self.map) |
384 |
printer.Print(self, printout, wx.true) |
printer.Print(self, printout, wx.true) |
385 |
printout.Destroy() |
printout.Destroy() |
386 |
|
|
387 |
def SetMap(self, map): |
def SetMap(self, map): |
388 |
redraw_channels = (LAYERS_CHANGED, LAYER_LEGEND_CHANGED, |
redraw_channels = (LAYERS_CHANGED, LAYER_LEGEND_CHANGED, |
389 |
LAYER_VISIBILITY_CHANGED) |
LAYER_VISIBILITY_CHANGED) |
552 |
self.tool.MouseDown(event) |
self.tool.MouseDown(event) |
553 |
self.tool.Show(self.drag_dc) |
self.tool.Show(self.drag_dc) |
554 |
self.dragging = 1 |
self.dragging = 1 |
555 |
|
|
556 |
def OnLeftUp(self, event): |
def OnLeftUp(self, event): |
557 |
self.ReleaseMouse() |
self.ReleaseMouse() |
558 |
self.set_current_position(event) |
self.set_current_position(event) |
629 |
ys.append(py) |
ys.append(py) |
630 |
return (min(xs), min(ys), max(xs), max(ys)) |
return (min(xs), min(ys), max(xs), max(ys)) |
631 |
|
|
632 |
def find_shape_at(self, px, py, select_labels = 0, selected_layer = 1): |
def find_shape_at(self, px, py, select_labels = 0, searched_layer = None): |
633 |
"""Determine the shape at point px, py in window coords |
"""Determine the shape at point px, py in window coords |
634 |
|
|
635 |
Return the shape and the corresponding layer as a tuple (layer, |
Return the shape and the corresponding layer as a tuple (layer, |
639 |
search through the labels. If a label is found return it's index |
search through the labels. If a label is found return it's index |
640 |
as the shape and None as the layer. |
as the shape and None as the layer. |
641 |
|
|
642 |
If the optional parameter selected_layer is true (default), only |
If the optional parameter searched_layer is given (or not None |
643 |
search in the currently selected layer. |
which it defaults to), only search in that layer. |
644 |
""" |
""" |
645 |
map_proj = self.map.projection |
map_proj = self.map.projection |
646 |
if map_proj is not None: |
if map_proj is not None: |
655 |
|
|
656 |
if select_labels: |
if select_labels: |
657 |
labels = self.map.LabelLayer().Labels() |
labels = self.map.LabelLayer().Labels() |
658 |
|
|
659 |
if labels: |
if labels: |
660 |
dc = wxClientDC(self) |
dc = wxClientDC(self) |
661 |
font = wxFont(10, wx.wxSWISS, wx.wxNORMAL, wx.wxNORMAL) |
font = wxFont(10, wx.wxSWISS, wx.wxNORMAL, wx.wxNORMAL) |
687 |
if x <= px < x + width and y <= py <= y + height: |
if x <= px < x + width and y <= py <= y + height: |
688 |
return None, i |
return None, i |
689 |
|
|
690 |
if selected_layer: |
if searched_layer: |
691 |
layer = self.interactor.SelectedLayer() |
layers = [searched_layer] |
|
if layer is not None: |
|
|
layers = [layer] |
|
|
else: |
|
|
# no layer selected. Use an empty list to effectively |
|
|
# ignore all layers. |
|
|
layers = [] |
|
692 |
else: |
else: |
693 |
layers = self.map.Layers() |
layers = self.map.Layers() |
694 |
|
|
701 |
|
|
702 |
filled = layer.fill is not None |
filled = layer.fill is not None |
703 |
stroked = layer.stroke is not None |
stroked = layer.stroke is not None |
704 |
|
|
705 |
layer_proj = layer.projection |
layer_proj = layer.projection |
706 |
if layer_proj is not None: |
if layer_proj is not None: |
707 |
inverse = layer_proj.Inverse |
inverse = layer_proj.Inverse |
708 |
else: |
else: |
709 |
inverse = None |
inverse = None |
710 |
|
|
711 |
shapetype = layer.ShapeType() |
shapetype = layer.ShapeType() |
712 |
|
|
713 |
select_shape = -1 |
select_shape = -1 |
754 |
return layer, select_shape |
return layer, select_shape |
755 |
return None, None |
return None, None |
756 |
|
|
757 |
def SelectShapeAt(self, x, y): |
def SelectShapeAt(self, x, y, layer = None): |
758 |
layer, shape = self.find_shape_at(x, y, selected_layer = 0) |
"""\ |
759 |
|
Select and return the shape and its layer at window position (x, y) |
760 |
|
|
761 |
|
If layer is given, only search in that layer. If no layer is |
762 |
|
given, search through all layers. |
763 |
|
|
764 |
|
Return a tuple (layer, shapeid). If no shape is found, return |
765 |
|
(None, None). |
766 |
|
""" |
767 |
|
layer, shape = result = self.find_shape_at(x, y, searched_layer=layer) |
768 |
# If layer is None, then shape will also be None. We don't want |
# If layer is None, then shape will also be None. We don't want |
769 |
# to deselect the currently selected layer, so we simply select |
# to deselect the currently selected layer, so we simply select |
770 |
# the already selected layer again. |
# the already selected layer again. |
771 |
if layer is None: |
if layer is None: |
772 |
layer = self.interactor.SelectedLayer() |
layer = self.interactor.SelectedLayer() |
773 |
self.interactor.SelectLayerAndShape(layer, shape) |
self.interactor.SelectLayerAndShape(layer, shape) |
774 |
|
return result |
775 |
|
|
776 |
def LabelShapeAt(self, x, y): |
def LabelShapeAt(self, x, y): |
777 |
ox = x; oy = y |
ox = x; oy = y |