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