160 |
table = layer.ShapeStore().Table() |
table = layer.ShapeStore().Table() |
161 |
|
|
162 |
# Determine which render function to use. |
# Determine which render function to use. |
163 |
draw_func, draw_func_param = self.low_level_renderer(layer) |
useraw, draw_func, draw_func_param = self.low_level_renderer(layer) |
164 |
|
|
165 |
# Iterate through all shapes that have to be drawn. |
# Iterate through all shapes that have to be drawn. |
166 |
for i in self.layer_ids(layer): |
for i in self.layer_ids(layer): |
167 |
|
shape = layer.Shape(i) |
168 |
|
|
169 |
if field is None: |
if field is None: |
170 |
group = defaultGroup |
group = defaultGroup |
185 |
if prop != old_prop: |
if prop != old_prop: |
186 |
pen, brush = self.tools_for_property(prop) |
pen, brush = self.tools_for_property(prop) |
187 |
|
|
188 |
draw_func(draw_func_param, i, pen, brush) |
if useraw: |
189 |
|
data = shape.RawData() |
190 |
|
else: |
191 |
|
data = shape.Points() |
192 |
|
draw_func(draw_func_param, data, pen, brush) |
193 |
|
|
194 |
def layer_ids(self, layer): |
def layer_ids(self, layer): |
195 |
"""Return the shape ids of the given layer that have to be drawn. |
"""Return the shape ids of the given layer that have to be drawn. |
203 |
"""Return the low-level renderer for the layer for draw_shape_layer |
"""Return the low-level renderer for the layer for draw_shape_layer |
204 |
|
|
205 |
The low level renderer to be returned by this method is a tuple |
The low level renderer to be returned by this method is a tuple |
206 |
(func, param) where func is a callable object and param is |
(useraw, func, param) where useraw is a boolean indicating |
207 |
passed as the first parameter to func. The draw_shape_layer |
whether the function uses the raw shape data, func is a callable |
208 |
method will call func like this: |
object and param is passed as the first parameter to func. The |
209 |
|
draw_shape_layer method will call func like this: |
210 |
func(param, rawshape, pen, brush) |
|
211 |
|
func(param, shapedata, pen, brush) |
212 |
where rawshape is currently the shapeid. pen and brush are the |
|
213 |
pen and brush to use to draw the shape on the dc. |
where shapedata is the return value of the RawData method of the |
214 |
|
shape object if useraw is true or the return value of the Points |
215 |
|
method if it's false. pen and brush are the pen and brush to use |
216 |
|
to draw the shape on the dc. |
217 |
|
|
218 |
The default implementation returns one of |
The default implementation returns one of |
219 |
self.draw_polygon_shape, self.draw_arc_shape or |
self.draw_polygon_shape, self.draw_arc_shape or |
220 |
self.draw_point_shape as func and layer as param. Derived |
self.draw_point_shape as func and layer as param. None of the |
221 |
classes can override this method to return more efficient low |
method use the raw shape data. Derived classes can override this |
222 |
level renderers. |
method to return more efficient low level renderers. |
223 |
""" |
""" |
224 |
shapetype = layer.ShapeType() |
shapetype = layer.ShapeType() |
225 |
if shapetype == SHAPETYPE_POINT: |
if shapetype == SHAPETYPE_POINT: |
228 |
func = self.draw_arc_shape |
func = self.draw_arc_shape |
229 |
else: |
else: |
230 |
func = self.draw_polygon_shape |
func = self.draw_polygon_shape |
231 |
return func, layer |
return False, func, layer |
232 |
|
|
233 |
def make_point(self, x, y): |
def make_point(self, x, y): |
234 |
"""Convert (x, y) to a point object. |
"""Convert (x, y) to a point object. |
237 |
""" |
""" |
238 |
raise NotImplementedError |
raise NotImplementedError |
239 |
|
|
240 |
def projected_points(self, layer, shapeid): |
def projected_points(self, layer, points): |
241 |
"""Return the projected coordinates of shape shapeid in layer. |
"""Return the projected coordinates of the points taken from layer. |
242 |
|
|
243 |
Read the shape from the layer through its Shape method and |
Transform all the points in the list of lists of coordinate |
244 |
transform all the points in the list of lists of coordinate |
pairs in points. |
|
pairs returned by the shape's Points method. |
|
245 |
|
|
246 |
The transformation applies the inverse of the layer's projection |
The transformation applies the inverse of the layer's projection |
247 |
if any, then the map's projection if any and finally applies |
if any, then the map's projection if any and finally applies |
260 |
inverse = proj.Inverse |
inverse = proj.Inverse |
261 |
else: |
else: |
262 |
inverse = None |
inverse = None |
263 |
shape = layer.Shape(shapeid) |
result = [] |
|
points = [] |
|
264 |
scale = self.scale |
scale = self.scale |
265 |
offx, offy = self.offset |
offx, offy = self.offset |
266 |
make_point = self.make_point |
make_point = self.make_point |
267 |
for part in shape.Points(): |
for part in points: |
268 |
points.append([]) |
result.append([]) |
269 |
for x, y in part: |
for x, y in part: |
270 |
if inverse: |
if inverse: |
271 |
x, y = inverse(x, y) |
x, y = inverse(x, y) |
272 |
if forward: |
if forward: |
273 |
x, y = forward(x, y) |
x, y = forward(x, y) |
274 |
points[-1].append(make_point(x * scale + offx, |
result[-1].append(make_point(x * scale + offx, |
275 |
-y * scale + offy)) |
-y * scale + offy)) |
276 |
return points |
return result |
277 |
|
|
278 |
def draw_polygon_shape(self, layer, index, pen, brush): |
def draw_polygon_shape(self, layer, points, pen, brush): |
279 |
"""Draw a polygon shape with the given brush and pen |
"""Draw a polygon shape from layer with the given brush and pen |
280 |
|
|
281 |
The shape is indicated by its id (index) and the layer. The |
The shape is given by points argument which is a the return |
282 |
coordinates in the DC's coordinate system are determined with |
value of the shape's Points() method. The coordinates in the |
283 |
|
DC's coordinate system are determined with |
284 |
self.projected_points. |
self.projected_points. |
285 |
""" |
""" |
286 |
points = self.projected_points(layer, index) |
points = self.projected_points(layer, points) |
287 |
|
|
288 |
if brush is not self.TRANSPARENT_BRUSH: |
if brush is not self.TRANSPARENT_BRUSH: |
289 |
polygon = [] |
polygon = [] |
305 |
for part in points: |
for part in points: |
306 |
self.dc.DrawLines(part) |
self.dc.DrawLines(part) |
307 |
|
|
308 |
def draw_arc_shape(self, layer, index, pen, brush): |
def draw_arc_shape(self, layer, points, pen, brush): |
309 |
"""Draw an arc shape with the given brush and pen |
"""Draw an arc shape from layer with the given brush and pen |
310 |
|
|
311 |
The shape is indicated by its id (index) and the layer. The |
The shape is given by points argument which is a the return |
312 |
coordinates in the DC's coordinate system are determined with |
value of the shape's Points() method. The coordinates in the |
313 |
|
DC's coordinate system are determined with |
314 |
self.projected_points. |
self.projected_points. |
315 |
""" |
""" |
316 |
points = self.projected_points(layer, index) |
points = self.projected_points(layer, points) |
317 |
self.dc.SetBrush(brush) |
self.dc.SetBrush(brush) |
318 |
self.dc.SetPen(pen) |
self.dc.SetPen(pen) |
319 |
for part in points: |
for part in points: |
320 |
self.dc.DrawLines(part) |
self.dc.DrawLines(part) |
321 |
|
|
322 |
def draw_point_shape(self, layer, index, pen, brush): |
def draw_point_shape(self, layer, points, pen, brush): |
323 |
"""Draw a point shape with the given brush and pen |
"""Draw a point shape from layer with the given brush and pen |
324 |
|
|
325 |
The shape is indicated by its id (index) and the layer. The |
The shape is given by points argument which is a the return |
326 |
coordinates in the DC's coordinate system are determined with |
value of the shape's Points() method. The coordinates in the |
327 |
|
DC's coordinate system are determined with |
328 |
self.projected_points. |
self.projected_points. |
329 |
|
|
330 |
The point is drawn as a circle centered on the point. |
The point is drawn as a circle centered on the point. |
331 |
""" |
""" |
332 |
points = self.projected_points(layer, index) |
points = self.projected_points(layer, points) |
333 |
if not points: |
if not points: |
334 |
return |
return |
335 |
|
|