42 |
|
|
43 |
import labeldialog |
import labeldialog |
44 |
|
|
45 |
from viewport import ViewPort, PanTool |
from viewport import ViewPort, PanTool, output_transform |
46 |
|
|
47 |
class CanvasPanTool(PanTool): |
class CanvasPanTool(PanTool): |
48 |
|
|
87 |
|
|
88 |
def draw_on_dc(self, dc): |
def draw_on_dc(self, dc): |
89 |
width, height = self.GetPageSizePixels() |
width, height = self.GetPageSizePixels() |
90 |
scale, offset, mapregion = OutputTransform(self.canvas.scale, |
scale, offset, mapregion = output_transform(self.canvas.scale, |
91 |
self.canvas.offset, |
self.canvas.offset, |
92 |
self.canvas.GetSizeTuple(), |
self.canvas.GetSizeTuple(), |
93 |
self.GetPageSizePixels()) |
self.GetPageSizePixels()) |
94 |
resx, resy = self.GetPPIPrinter() |
resx, resy = self.GetPPIPrinter() |
95 |
renderer = PrinterRenderer(dc, scale, offset, resolution = resy) |
renderer = PrinterRenderer(dc, scale, offset, resolution = resy) |
96 |
x, y, width, height = self.region |
x, y, width, height = self.region |
232 |
self.export_path = os.path.dirname(dlg.GetPath()) |
self.export_path = os.path.dirname(dlg.GetPath()) |
233 |
dc = wxMetaFileDC(dlg.GetPath()) |
dc = wxMetaFileDC(dlg.GetPath()) |
234 |
|
|
235 |
scale, offset, mapregion = OutputTransform(self.scale, |
scale, offset, mapregion = output_transform(self.scale, |
236 |
self.offset, |
self.offset, |
237 |
self.GetSizeTuple(), |
self.GetSizeTuple(), |
238 |
dc.GetSizeTuple()) |
dc.GetSizeTuple()) |
239 |
|
|
240 |
selected_layer = self.selection.SelectedLayer() |
selected_layer = self.selection.SelectedLayer() |
241 |
selected_shapes = self.selection.SelectedShapes() |
selected_shapes = self.selection.SelectedShapes() |
347 |
|
|
348 |
def LabelShapeAt(self, x, y, text=None): |
def LabelShapeAt(self, x, y, text=None): |
349 |
"""Add or remove a label at window position x, y. |
"""Add or remove a label at window position x, y. |
350 |
|
|
351 |
If there's a label at the given position, remove it. Otherwise |
If there's a label at the given position, remove it. Otherwise |
352 |
determine the shape at the position, run the label dialog and |
determine the shape at the position, run the label dialog and |
353 |
unless the user cancels the dialog, add a label. |
unless the user cancels the dialog, add a label. |
361 |
layer.ShapeStore().Table(), |
layer.ShapeStore().Table(), |
362 |
shape_index) |
shape_index) |
363 |
ViewPort.LabelShapeAt(self, x, y, text) |
ViewPort.LabelShapeAt(self, x, y, text) |
|
|
|
|
def OutputTransform(canvas_scale, canvas_offset, canvas_size, device_extend): |
|
|
"""Calculate dimensions to transform canvas content to output device.""" |
|
|
width, height = device_extend |
|
|
|
|
|
# Only 80 % of the with are available for the map |
|
|
width = width * 0.8 |
|
|
|
|
|
# Define the distance of the map from DC border |
|
|
distance = 20 |
|
|
|
|
|
if height < width: |
|
|
# landscape |
|
|
map_height = height - 2*distance |
|
|
map_width = map_height |
|
|
else: |
|
|
# portrait, recalibrate width (usually the legend width is too |
|
|
# small |
|
|
width = width * 0.9 |
|
|
map_height = width - 2*distance |
|
|
map_width = map_height |
|
|
|
|
|
mapregion = (distance, distance, |
|
|
distance+map_width, distance+map_height) |
|
|
|
|
|
canvas_width, canvas_height = canvas_size |
|
|
|
|
|
scalex = map_width / (canvas_width/canvas_scale) |
|
|
scaley = map_height / (canvas_height/canvas_scale) |
|
|
scale = min(scalex, scaley) |
|
|
canvas_offx, canvas_offy = canvas_offset |
|
|
offx = scale*canvas_offx/canvas_scale |
|
|
offy = scale*canvas_offy/canvas_scale |
|
|
|
|
|
return scale, (offx, offy), mapregion |
|