1 |
# Copyright (c) 2001 by Intevation GmbH |
# Copyright (c) 2001, 2002 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
63 |
scale = self.scale |
scale = self.scale |
64 |
offx, offy = self.offset |
offx, offy = self.offset |
65 |
|
|
|
fill = layer.fill |
|
|
if fill is None: |
|
|
brush = wxTRANSPARENT_BRUSH |
|
|
else: |
|
|
color = wxColour(fill.red * 255, |
|
|
fill.green * 255, |
|
|
fill.blue * 255) |
|
|
brush = wxBrush(color, wxSOLID) |
|
|
stroke = layer.stroke |
|
|
if stroke is None: |
|
|
pen = wxTRANSPARENT_PEN |
|
|
else: |
|
|
color = wxColour(stroke.red * 255, |
|
|
stroke.green * 255, |
|
|
stroke.blue * 255) |
|
|
pen = wxPen(color, 1, wxSOLID) |
|
|
|
|
66 |
map_proj = self.map.projection |
map_proj = self.map.projection |
67 |
layer_proj = layer.projection |
layer_proj = layer.projection |
68 |
|
|
69 |
shapetype = layer.ShapeType() |
shapetype = layer.ShapeType() |
70 |
|
|
71 |
if shapetype == SHAPETYPE_POLYGON: |
brush = wxTRANSPARENT_BRUSH |
72 |
for i in range(layer.NumShapes()): |
pen = wxTRANSPARENT_PEN |
73 |
|
|
74 |
|
old_prop = None |
75 |
|
for i in self.layer_ids(layer): |
76 |
|
value = None |
77 |
|
shape = layer.Shape(i) |
78 |
|
field = layer.classification.field |
79 |
|
|
80 |
|
if field is not None: |
81 |
|
record = layer.table.read_record(i) |
82 |
|
if record is not None: |
83 |
|
value = record[field] |
84 |
|
|
85 |
|
# |
86 |
|
# if the above statements fail 'value' should |
87 |
|
# be null, at which point this call will |
88 |
|
# at least retreive the NullData |
89 |
|
# |
90 |
|
prop = layer.classification.getProperties(value) |
91 |
|
|
92 |
|
if prop != old_prop: |
93 |
|
old_prop = prop |
94 |
|
|
95 |
|
if shapetype == SHAPETYPE_ARC: |
96 |
|
fill = None |
97 |
|
else: |
98 |
|
fill = prop['fill'] |
99 |
|
|
100 |
|
if fill is None: |
101 |
|
brush = wxTRANSPARENT_BRUSH |
102 |
|
else: |
103 |
|
color = wxColour(fill.red * 255, |
104 |
|
fill.green * 255, |
105 |
|
fill.blue * 255) |
106 |
|
brush = wxBrush(color, wxSOLID) |
107 |
|
|
108 |
|
stroke = prop['stroke'] |
109 |
|
stroke_width = prop['stroke_width'] |
110 |
|
if stroke is None: |
111 |
|
pen = wxTRANSPARENT_PEN |
112 |
|
else: |
113 |
|
color = wxColour(stroke.red * 255, |
114 |
|
stroke.green * 255, |
115 |
|
stroke.blue * 255) |
116 |
|
pen = wxPen(color, stroke_width, wxSOLID) |
117 |
|
|
118 |
|
if shapetype == SHAPETYPE_POINT: |
119 |
|
self.dc.SetBrush(brush) |
120 |
|
self.dc.SetPen(pen) |
121 |
|
self.draw_point_shape(layer, i) |
122 |
|
else: |
123 |
self.draw_polygon_shape(layer, i, pen, brush) |
self.draw_polygon_shape(layer, i, pen, brush) |
124 |
else: |
|
125 |
self.dc.SetBrush(brush) |
def layer_ids(self, layer): |
126 |
self.dc.SetPen(pen) |
"""Return the shape ids of the given layer that have to be drawn. |
127 |
if shapetype == SHAPETYPE_ARC: |
|
128 |
f = self.draw_arc_shape |
The default implementation simply returns all ids in the layer. |
129 |
elif shapetype == SHAPETYPE_POINT: |
Override in derived classes to be more precise. |
130 |
f = self.draw_point_shape |
""" |
131 |
for i in range(layer.NumShapes()): |
return range(layer.NumShapes()) |
|
f(layer, i) |
|
132 |
|
|
133 |
def draw_polygon_shape(self, layer, index, pen, brush): |
def draw_polygon_shape(self, layer, index, pen, brush): |
134 |
offx, offy = self.offset |
offx, offy = self.offset |
214 |
# On the screen we want to see only visible layers by default |
# On the screen we want to see only visible layers by default |
215 |
honor_visibility = 1 |
honor_visibility = 1 |
216 |
|
|
217 |
def RenderMap(self, map, selected_layer, selected_shape): |
def RenderMap(self, map, region, selected_layer, selected_shape): |
218 |
|
"""Render the map. |
219 |
|
|
220 |
|
Only the given region (a tuple in window coordinates as returned |
221 |
|
by a wxrect's asTuple method) needs to be redrawn. Highlight the |
222 |
|
shape with id selected_shape in the selected_layer. |
223 |
|
""" |
224 |
|
self.update_region = region |
225 |
self.selected_layer = selected_layer |
self.selected_layer = selected_layer |
226 |
self.selected_shape = selected_shape |
self.selected_shape = selected_shape |
227 |
self.render_map(map) |
self.render_map(map) |
236 |
index = self.selected_shape |
index = self.selected_shape |
237 |
if shapetype == SHAPETYPE_POLYGON: |
if shapetype == SHAPETYPE_POLYGON: |
238 |
self.draw_polygon_shape(layer, index, pen, brush) |
self.draw_polygon_shape(layer, index, pen, brush) |
239 |
|
elif shapetype == SHAPETYPE_ARC: |
240 |
|
self.draw_polygon_shape(layer, index, pen, None) |
241 |
else: |
else: |
242 |
self.dc.SetBrush(brush) |
self.dc.SetBrush(brush) |
243 |
self.dc.SetPen(pen) |
self.dc.SetPen(pen) |
244 |
if shapetype == SHAPETYPE_ARC: |
if shapetype == SHAPETYPE_POINT: |
245 |
f = self.draw_arc_shape |
self.draw_point_shape(layer, index) |
246 |
elif shapetype == SHAPETYPE_POINT: |
else: |
247 |
f = self.draw_point_shape |
raise TypeError("Unhandled shape type %s" % shapetype) |
248 |
f(layer, index) |
|
249 |
|
def layer_ids(self, layer): |
250 |
|
"""Return the shapeids covered by the region that has to be redrawn |
251 |
|
|
252 |
|
Call the layer's ShapesInRegion method to determine the ids so |
253 |
|
that it can use the quadtree. |
254 |
|
""" |
255 |
|
# FIXME: the quad-tree should be built from the projected |
256 |
|
# coordinates not the lat-long ones because it's not trivial to |
257 |
|
# determine an appropriate rectangle in lat-long for a given |
258 |
|
# rectangle in projected coordinates which we have to start from |
259 |
|
# here. |
260 |
|
proj = self.map.projection |
261 |
|
if proj is not None: |
262 |
|
inverse = proj.Inverse |
263 |
|
else: |
264 |
|
inverse = None |
265 |
|
|
266 |
|
scale = self.scale |
267 |
|
offx, offy = self.offset |
268 |
|
xs = [] |
269 |
|
ys = [] |
270 |
|
x, y, width, height = self.update_region |
271 |
|
for winx, winy in ((x, y), (x + width, y), |
272 |
|
(x + width, y + height), (x, y + height)): |
273 |
|
px = (winx - offx) / scale |
274 |
|
py = -(winy - offy) / scale |
275 |
|
if inverse: |
276 |
|
px, py = inverse(px, py) |
277 |
|
xs.append(px) |
278 |
|
ys.append(py) |
279 |
|
left = min(xs) |
280 |
|
right = max(xs) |
281 |
|
top = max(ys) |
282 |
|
bottom = min(ys) |
283 |
|
|
284 |
|
return layer.ShapesInRegion((left, bottom, right, top)) |
285 |
|
|
286 |
|
|
287 |
class PrinterRender(MapRenderer): |
class PrinterRender(MapRenderer): |