25 |
from Thuban.Model.classification import Classification |
from Thuban.Model.classification import Classification |
26 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
27 |
|
|
|
import time |
|
|
|
|
28 |
|
|
29 |
class MapRenderer: |
class MapRenderer: |
30 |
|
|
85 |
lc = layer.GetClassification() |
lc = layer.GetClassification() |
86 |
field = lc.GetField() |
field = lc.GetField() |
87 |
|
|
|
#print "drawing layer: ", layer.Title(), |
|
|
#start = time.clock() |
|
|
#count = 0 |
|
88 |
|
|
89 |
if shapetype != SHAPETYPE_POINT: |
if shapetype != SHAPETYPE_POINT: |
90 |
offx, offy = self.offset |
polygon_render_param = self.polygon_render_param(layer) |
|
draw_polygon_init(layer.shapefile.cobject(), |
|
|
self.dc, |
|
|
self.map.projection, layer.projection, |
|
|
self.scale, -self.scale, offx, offy) |
|
91 |
|
|
92 |
for i in self.layer_ids(layer): |
for i in self.layer_ids(layer): |
93 |
value = None |
value = None |
119 |
prop = group.GetProperties() |
prop = group.GetProperties() |
120 |
|
|
121 |
# don't recreate new objects if they are the same as before |
# don't recreate new objects if they are the same as before |
122 |
if prop != old_prop: |
if prop != old_prop: |
123 |
old_prop = prop |
old_prop = prop |
124 |
|
|
125 |
if shapetype == SHAPETYPE_ARC: |
if shapetype == SHAPETYPE_ARC: |
127 |
else: |
else: |
128 |
fill = prop.GetFill() |
fill = prop.GetFill() |
129 |
|
|
130 |
|
|
131 |
if fill is Color.Transparent: |
if fill is Color.Transparent: |
132 |
brush = wxTRANSPARENT_BRUSH |
brush = wxTRANSPARENT_BRUSH |
133 |
else: |
else: |
134 |
color = Color2wxColour(fill) |
color = Color2wxColour(fill) |
135 |
brush = wxBrush(color, wxSOLID) |
brush = wxBrush(color, wxSOLID) |
136 |
|
|
137 |
stroke = prop.GetLineColor() |
stroke = prop.GetLineColor() |
138 |
stroke_width = prop.GetLineWidth() |
stroke_width = prop.GetLineWidth() |
139 |
if stroke is Color.Transparent: |
if stroke is Color.Transparent: |
142 |
color = Color2wxColour(stroke) |
color = Color2wxColour(stroke) |
143 |
pen = wxPen(color, stroke_width, wxSOLID) |
pen = wxPen(color, stroke_width, wxSOLID) |
144 |
|
|
145 |
|
|
146 |
|
if shapetype == SHAPETYPE_POINT: |
147 |
self.dc.SetBrush(brush) |
self.dc.SetBrush(brush) |
148 |
self.dc.SetPen(pen) |
self.dc.SetPen(pen) |
|
|
|
|
if shapetype == SHAPETYPE_POINT: |
|
149 |
self.draw_point_shape(layer, i) |
self.draw_point_shape(layer, i) |
150 |
else: |
else: |
151 |
self.draw_polygon_shape(layer, i, pen, brush) |
self.draw_polygon_shape(polygon_render_param, i, pen, brush) |
|
|
|
|
#count += 1 |
|
|
|
|
|
#end = time.clock() |
|
|
#print (end-start), "seconds -- ", count |
|
|
|
|
152 |
|
|
153 |
def layer_ids(self, layer): |
def layer_ids(self, layer): |
154 |
"""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. |
155 |
|
|
156 |
The default implementation simply returns all ids in the layer. |
The default implementation simply returns all ids in the layer. |
157 |
Override in derived classes to be more precise. |
Override in derived classes to be more precise. |
158 |
""" |
""" |
159 |
return range(layer.NumShapes()) |
return range(layer.NumShapes()) |
160 |
|
|
161 |
def draw_polygon_shape(self, layer, index, pen, brush): |
def polygon_render_param(self, layer): |
162 |
draw_polygon_shape(index, pen, brush) |
"""Return the low-lever render parameter for the layer""" |
163 |
|
offx, offy = self.offset |
164 |
|
return draw_polygon_init(layer.shapefile, self.dc, |
165 |
|
self.map.projection, |
166 |
|
layer.projection, |
167 |
|
self.scale, -self.scale, |
168 |
|
offx, offy) |
169 |
|
|
170 |
|
def draw_polygon_shape(self, draw_polygon_info, index, pen, brush): |
171 |
|
draw_polygon_shape(draw_polygon_info, index, pen, brush) |
172 |
|
|
173 |
def projected_points(self, layer, index): |
def projected_points(self, layer, index): |
174 |
proj = self.map.projection |
proj = self.map.projection |
272 |
|
|
273 |
shapetype = layer.ShapeType() |
shapetype = layer.ShapeType() |
274 |
if shapetype == SHAPETYPE_POLYGON: |
if shapetype == SHAPETYPE_POLYGON: |
275 |
|
offx, offy = self.offset |
276 |
|
renderparam = self.polygon_render_param(layer) |
277 |
func = self.draw_polygon_shape |
func = self.draw_polygon_shape |
278 |
args = (pen, brush) |
args = (pen, brush) |
279 |
elif shapetype == SHAPETYPE_ARC: |
elif shapetype == SHAPETYPE_ARC: |
280 |
|
renderparam = self.polygon_render_param(layer) |
281 |
func = self.draw_polygon_shape |
func = self.draw_polygon_shape |
282 |
args = (pen, None) |
args = (pen, None) |
283 |
elif shapetype == SHAPETYPE_POINT: |
elif shapetype == SHAPETYPE_POINT: |
284 |
|
renderparam = layer |
285 |
self.dc.SetBrush(brush) |
self.dc.SetBrush(brush) |
286 |
self.dc.SetPen(pen) |
self.dc.SetPen(pen) |
287 |
func = self.draw_point_shape |
func = self.draw_point_shape |
290 |
raise TypeError(_("Unhandled shape type %s") % shapetype) |
raise TypeError(_("Unhandled shape type %s") % shapetype) |
291 |
|
|
292 |
for index in self.selected_shapes: |
for index in self.selected_shapes: |
293 |
func(layer, index, *args) |
func(renderparam, index, *args) |
294 |
|
|
295 |
|
|
296 |
def layer_ids(self, layer): |
def layer_ids(self, layer): |
297 |
"""Return the shapeids covered by the region that has to be redrawn |
"""Return the shapeids covered by the region that has to be redrawn |