7 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
8 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
9 |
|
|
10 |
|
from __future__ import generators |
11 |
|
|
12 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
13 |
|
# $Source$ |
14 |
|
# $Id$ |
15 |
|
|
16 |
import cStringIO |
import cStringIO |
17 |
|
|
96 |
# On the screen we want to see only visible layers by default |
# On the screen we want to see only visible layers by default |
97 |
honor_visibility = 1 |
honor_visibility = 1 |
98 |
|
|
99 |
def RenderMap(self, map, region, selected_layer, selected_shapes): |
def RenderMap(self, selected_layer, selected_shapes): |
100 |
"""Render the map. |
"""Render the map. |
101 |
|
|
102 |
Only the given region (a tuple in window coordinates as returned |
Only the given region (a tuple in window coordinates as returned |
104 |
shapes given by the ids in selected_shapes in the |
shapes given by the ids in selected_shapes in the |
105 |
selected_layer. |
selected_layer. |
106 |
""" |
""" |
|
self.update_region = region |
|
107 |
self.selected_layer = selected_layer |
self.selected_layer = selected_layer |
108 |
self.selected_shapes = selected_shapes |
self.selected_shapes = selected_shapes |
109 |
self.render_map(map) |
self.render_map() |
110 |
|
|
111 |
|
def RenderMapIncrementally(self): |
112 |
|
"""Render the map. |
113 |
|
|
114 |
|
Only the given region (a tuple in window coordinates as returned |
115 |
|
by a wxrect's asTuple method) needs to be redrawn. Highlight the |
116 |
|
shapes given by the ids in selected_shapes in the |
117 |
|
selected_layer. |
118 |
|
""" |
119 |
|
return self.render_map_incrementally() |
120 |
|
|
121 |
def draw_shape_layer(self, layer): |
def draw_selection_incrementally(self, layer, selected_shapes): |
122 |
MapRenderer.draw_shape_layer(self, layer) |
pen = wxPen(wxBLACK, 3, wxSOLID) |
123 |
if layer is self.selected_layer and self.selected_shapes: |
brush = wxBrush(wxBLACK, wxCROSS_HATCH) |
124 |
pen = wxPen(wxBLACK, 3, wxSOLID) |
|
125 |
brush = wxBrush(wxBLACK, wxCROSS_HATCH) |
shapetype = layer.ShapeType() |
126 |
|
useraw, func, param = self.low_level_renderer(layer) |
127 |
shapetype = layer.ShapeType() |
args = (pen, brush) |
128 |
useraw, func, param = self.low_level_renderer(layer) |
count = 0 |
129 |
args = (pen, brush) |
for index in selected_shapes: |
130 |
for index in self.selected_shapes: |
count += 1 |
131 |
shape = layer.Shape(index) |
shape = layer.Shape(index) |
132 |
if useraw: |
if useraw: |
133 |
data = shape.RawData() |
data = shape.RawData() |
134 |
else: |
else: |
135 |
data = shape.Points() |
data = shape.Points() |
136 |
func(param, data, *args) |
func(param, data, *args) |
137 |
|
if count % 500 == 0: |
138 |
|
yield True |
139 |
|
|
140 |
def layer_shapes(self, layer): |
def layer_shapes(self, layer): |
141 |
"""Return the shapeids covered by the region that has to be redrawn |
"""Return the shapeids covered by the region that has to be redrawn |
158 |
offx, offy = self.offset |
offx, offy = self.offset |
159 |
xs = [] |
xs = [] |
160 |
ys = [] |
ys = [] |
161 |
x, y, width, height = self.update_region |
x, y, width, height = self.region |
162 |
for winx, winy in ((x, y), (x + width, y), |
for winx, winy in ((x, y), (x + width, y), |
163 |
(x + width, y + height), (x, y + height)): |
(x + width, y + height), (x, y + height)): |
164 |
px = (winx - offx) / scale |
px = (winx - offx) / scale |
179 |
|
|
180 |
honor_visibility = 1 |
honor_visibility = 1 |
181 |
|
|
182 |
def RenderMap(self, map, region, mapregion, |
def __init__(self, *args, **kw): |
183 |
selected_layer, selected_shapes ): |
"""Initialize the ExportRenderer. |
184 |
|
|
185 |
|
In addition to all parameters of the the ScreenRender |
186 |
|
constructor, this class requires and additional keyword argument |
187 |
|
destination_region with a tuple (minx, miny, maxx, maxy) giving |
188 |
|
the region in dc coordinates which is to contain the map. |
189 |
|
""" |
190 |
|
self.destination_region = kw["destination_region"] |
191 |
|
del kw["destination_region"] |
192 |
|
ScreenRenderer.__init__(self, *args, **kw) |
193 |
|
|
194 |
|
def RenderMap(self, selected_layer, selected_shapes): |
195 |
"""Render the map. |
"""Render the map. |
196 |
|
|
197 |
The rendering device has been specified during initialisation. |
The rendering device has been specified during initialisation. |
198 |
The device border distance was set in Thuban.UI.view.OutputTranform(). |
The device border distance was set in |
199 |
|
Thuban.UI.viewport.output_transform(). |
200 |
|
|
201 |
RenderMap renders a frame set (one page frame, one around |
RenderMap renders a frame set (one page frame, one around |
202 |
legend/scalebar and one around the map), the map, the legend and the |
legend/scalebar and one around the map), the map, the legend and |
203 |
scalebar on the given DC. The map is rendered with the region displayed |
the scalebar on the given DC. The map is rendered with the |
204 |
in the canvas view, centered on the area available for map display. |
region displayed in the canvas view, centered on the area |
205 |
|
available for map display. |
206 |
""" |
""" |
207 |
|
|
|
self.update_region = region |
|
208 |
self.selected_layer = selected_layer |
self.selected_layer = selected_layer |
209 |
self.selected_shapes = selected_shapes |
self.selected_shapes = selected_shapes |
210 |
|
|
211 |
# Get some dimensions |
# Get some dimensions |
212 |
llx, lly, urx, ury = region |
llx, lly, urx, ury = self.region |
213 |
self.mapregion = mapregion |
mminx, mminy, mmaxx, mmaxy = self.destination_region |
|
mminx, mminy, mmaxx, mmaxy = self.mapregion |
|
214 |
|
|
215 |
# Manipulate the offset to position the map |
# Manipulate the offset to position the map |
216 |
offx, offy = self.offset |
offx, offy = self.offset |
231 |
self.dc.DestroyClippingRegion() |
self.dc.DestroyClippingRegion() |
232 |
self.dc.SetClippingRegion(mminx+self.shiftx, mminy+self.shifty, |
self.dc.SetClippingRegion(mminx+self.shiftx, mminy+self.shifty, |
233 |
urx, ury) |
urx, ury) |
234 |
self.render_map(map) |
self.render_map() |
235 |
self.dc.EndDrawing() |
self.dc.EndDrawing() |
236 |
|
|
237 |
# Draw the rest (frames, legend, scalebar) |
# Draw the rest (frames, legend, scalebar) |
242 |
font = wxFont(self.resolution * 10, wxSWISS, wxNORMAL, wxNORMAL) |
font = wxFont(self.resolution * 10, wxSWISS, wxNORMAL, wxNORMAL) |
243 |
self.dc.SetFont(font) |
self.dc.SetFont(font) |
244 |
|
|
245 |
self.render_frame(region) |
self.render_frame() |
246 |
self.render_legend(map) |
self.render_legend() |
247 |
self.render_scalebar(map) |
self.render_scalebar() |
248 |
self.dc.EndDrawing() |
self.dc.EndDrawing() |
249 |
|
|
250 |
def render_frame(self, region): |
def render_frame(self): |
251 |
"""Render the frames for map and legend/scalebar.""" |
"""Render the frames for map and legend/scalebar.""" |
252 |
|
|
253 |
dc = self.dc |
dc = self.dc |
256 |
|
|
257 |
# Dimension stuff |
# Dimension stuff |
258 |
width, height = dc.GetSizeTuple() |
width, height = dc.GetSizeTuple() |
259 |
mminx, mminy, mmaxx, mmaxy = self.mapregion |
mminx, mminy, mmaxx, mmaxy = self.destination_region |
260 |
|
|
261 |
# Page Frame |
# Page Frame |
262 |
dc.DrawRectangle(15,15,width-30, (mmaxy-mminy)+10) |
dc.DrawRectangle(15,15,width-30, (mmaxy-mminy)+10) |
263 |
|
|
264 |
# Map Frame |
# Map Frame |
265 |
llx, lly, urx, ury = region |
llx, lly, urx, ury = self.region |
266 |
dc.DrawRectangle(mminx + self.shiftx, mminy + self.shifty, urx, ury) |
dc.DrawRectangle(mminx + self.shiftx, mminy + self.shifty, urx, ury) |
267 |
|
|
268 |
# Legend Frame |
# Legend Frame |
272 |
dc.SetClippingRegion(mmaxx+10,mminy, |
dc.SetClippingRegion(mmaxx+10,mminy, |
273 |
(width-20) - (mmaxx+10), mmaxy-mminy) |
(width-20) - (mmaxx+10), mmaxy-mminy) |
274 |
|
|
275 |
def render_legend(self, map): |
def render_legend(self): |
276 |
"""Render the legend on the Map.""" |
"""Render the legend on the Map.""" |
277 |
|
|
278 |
previewer = ClassDataPreviewer() |
previewer = ClassDataPreviewer() |
282 |
|
|
283 |
# Dimension stuff |
# Dimension stuff |
284 |
width, height = dc.GetSizeTuple() |
width, height = dc.GetSizeTuple() |
285 |
mminx, mminy, mmaxx, mmaxy = self.mapregion |
mminx, mminy, mmaxx, mmaxy = self.destination_region |
286 |
textwidth, textheight = dc.GetTextExtent("0") |
textwidth, textheight = dc.GetTextExtent("0") |
287 |
iconwidth = textheight |
iconwidth = textheight |
288 |
iconheight = textheight |
iconheight = textheight |
294 |
|
|
295 |
# Render the legend |
# Render the legend |
296 |
dc.SetTextForeground(wxBLACK) |
dc.SetTextForeground(wxBLACK) |
297 |
if map.HasLayers(): |
if self.map.HasLayers(): |
298 |
layers = map.Layers()[:] |
layers = self.map.Layers()[:] |
299 |
layers.reverse() |
layers.reverse() |
300 |
for l in layers: |
for l in layers: |
301 |
if l.Visible(): |
if l.Visible(): |
316 |
posx+2*dx+iconwidth, posy) |
posx+2*dx+iconwidth, posy) |
317 |
posy+=stepy |
posy+=stepy |
318 |
|
|
319 |
def render_scalebar(self, map): |
def render_scalebar(self): |
320 |
"""Render the scalebar.""" |
"""Render the scalebar.""" |
321 |
|
|
322 |
scalebar = ScaleBar(map) |
scalebar = ScaleBar(self.map) |
323 |
|
|
324 |
# Dimension stuff |
# Dimension stuff |
325 |
width, height = self.dc.GetSizeTuple() |
width, height = self.dc.GetSizeTuple() |
326 |
mminx, mminy, mmaxx, mmaxy = self.mapregion |
mminx, mminy, mmaxx, mmaxy = self.destination_region |
327 |
|
|
328 |
# Render the scalebar |
# Render the scalebar |
329 |
scalebar.DrawScaleBar(self.scale, self.dc, |
scalebar.DrawScaleBar(self.scale, self.dc, |