27 |
from Thuban.UI.classifier import ClassDataPreviewer |
from Thuban.UI.classifier import ClassDataPreviewer |
28 |
from Thuban.UI.scalebar import ScaleBar |
from Thuban.UI.scalebar import ScaleBar |
29 |
|
|
30 |
from Thuban.Model.layer import Layer, RasterLayer, \ |
from Thuban.Model.layer import Layer, RasterLayer |
31 |
SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT |
from Thuban.Model.data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT |
32 |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
33 |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
34 |
|
|
35 |
from Thuban.Model.classification import Classification |
from Thuban.Model.classification import Classification |
36 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Transparent |
37 |
import Thuban.Model.resource |
import Thuban.Model.resource |
38 |
|
|
39 |
if Thuban.Model.resource.has_gdal_support(): |
if Thuban.Model.resource.has_gdal_support(): |
75 |
self.map = map |
self.map = map |
76 |
seenRaster = True |
seenRaster = True |
77 |
|
|
78 |
if self.scale == 0: |
self.dc.BeginDrawing() |
|
return |
|
79 |
|
|
80 |
# |
# |
81 |
# This is only a good optimization if there is only one |
# This is only a good optimization if there is only one |
103 |
|
|
104 |
self.draw_label_layer(map.LabelLayer()) |
self.draw_label_layer(map.LabelLayer()) |
105 |
|
|
106 |
|
self.dc.EndDrawing() |
107 |
|
|
108 |
def draw_shape_layer(self, layer): |
def draw_shape_layer(self, layer): |
109 |
scale = self.scale |
scale = self.scale |
110 |
offx, offy = self.offset |
offx, offy = self.offset |
120 |
old_prop = None |
old_prop = None |
121 |
old_group = None |
old_group = None |
122 |
lc = layer.GetClassification() |
lc = layer.GetClassification() |
123 |
field = lc.GetField() |
field = layer.GetClassificationColumn() |
124 |
defaultGroup = lc.GetDefaultGroup() |
defaultGroup = lc.GetDefaultGroup() |
125 |
|
|
126 |
|
|
|
if shapetype != SHAPETYPE_POINT: |
|
|
polygon_render_param = self.polygon_render_param(layer) |
|
127 |
|
|
128 |
if shapetype == SHAPETYPE_POINT: |
if shapetype == SHAPETYPE_POINT: |
129 |
draw_func = lambda i: \ |
draw_func = self.draw_point_shape |
130 |
self.draw_point_shape(layer, i) |
draw_func_param = layer |
131 |
else: |
else: |
132 |
draw_func = lambda i: \ |
draw_func = draw_polygon_shape |
133 |
self.draw_polygon_shape(polygon_render_param, i, pen, brush) |
draw_func_param = self.polygon_render_param(layer) |
134 |
|
|
135 |
table = layer.ShapeStore().Table() |
table = layer.ShapeStore().Table() |
136 |
for i in self.layer_ids(layer): |
for i in self.layer_ids(layer): |
157 |
old_prop = prop |
old_prop = prop |
158 |
|
|
159 |
if shapetype == SHAPETYPE_ARC: |
if shapetype == SHAPETYPE_ARC: |
160 |
fill = Color.Transparent |
fill = Transparent |
161 |
else: |
else: |
162 |
fill = prop.GetFill() |
fill = prop.GetFill() |
163 |
|
|
164 |
|
|
165 |
if fill is Color.Transparent: |
if fill is Transparent: |
166 |
brush = wxTRANSPARENT_BRUSH |
brush = wxTRANSPARENT_BRUSH |
167 |
else: |
else: |
168 |
color = Color2wxColour(fill) |
color = Color2wxColour(fill) |
170 |
|
|
171 |
stroke = prop.GetLineColor() |
stroke = prop.GetLineColor() |
172 |
stroke_width = prop.GetLineWidth() |
stroke_width = prop.GetLineWidth() |
173 |
if stroke is Color.Transparent: |
if stroke is Transparent: |
174 |
pen = wxTRANSPARENT_PEN |
pen = wxTRANSPARENT_PEN |
175 |
else: |
else: |
176 |
color = Color2wxColour(stroke) |
color = Color2wxColour(stroke) |
177 |
pen = wxPen(color, stroke_width, wxSOLID) |
pen = wxPen(color, stroke_width, wxSOLID) |
178 |
|
|
179 |
if shapetype == SHAPETYPE_POINT: |
draw_func(draw_func_param, i, pen, brush) |
|
self.dc.SetBrush(brush) |
|
|
self.dc.SetPen(pen) |
|
|
|
|
|
draw_func(i) |
|
180 |
|
|
181 |
def draw_raster_layer(self, layer): |
def draw_raster_layer(self, layer): |
182 |
data = None |
data = None |
216 |
stream = cStringIO.StringIO(data) |
stream = cStringIO.StringIO(data) |
217 |
image = wxImageFromStream(stream, wxBITMAP_TYPE_BMP) |
image = wxImageFromStream(stream, wxBITMAP_TYPE_BMP) |
218 |
bitmap = wxBitmapFromImage(image) |
bitmap = wxBitmapFromImage(image) |
|
self.dc.BeginDrawing() |
|
219 |
self.dc.DrawBitmap(bitmap, 0, 0) |
self.dc.DrawBitmap(bitmap, 0, 0) |
|
self.dc.EndDrawing() |
|
220 |
|
|
221 |
def layer_ids(self, layer): |
def layer_ids(self, layer): |
222 |
"""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. |
266 |
points = self.projected_points(layer, index) |
points = self.projected_points(layer, index) |
267 |
self.dc.DrawLines(points) |
self.dc.DrawLines(points) |
268 |
|
|
269 |
def draw_point_shape(self, layer, index): |
def draw_point_shape(self, layer, index, pen, brush): |
270 |
pp = self.projected_points(layer, index) |
pp = self.projected_points(layer, index) |
271 |
|
|
272 |
if len(pp) == 0: return # ignore Null Shapes which have no points |
if len(pp) == 0: return # ignore Null Shapes which have no points |
273 |
|
|
274 |
p = pp[0] |
p = pp[0] |
275 |
radius = self.resolution * 5 |
radius = self.resolution * 5 |
276 |
|
self.dc.SetBrush(brush) |
277 |
|
self.dc.SetPen(pen) |
278 |
self.dc.DrawEllipse(p.x - radius, p.y - radius, 2*radius, 2*radius) |
self.dc.DrawEllipse(p.x - radius, p.y - radius, 2*radius, 2*radius) |
279 |
|
|
280 |
def draw_label_layer(self, layer): |
def draw_label_layer(self, layer): |
352 |
args = (pen, None) |
args = (pen, None) |
353 |
elif shapetype == SHAPETYPE_POINT: |
elif shapetype == SHAPETYPE_POINT: |
354 |
renderparam = layer |
renderparam = layer |
|
self.dc.SetBrush(brush) |
|
|
self.dc.SetPen(pen) |
|
355 |
func = self.draw_point_shape |
func = self.draw_point_shape |
356 |
args = () |
args = (pen, brush) |
357 |
else: |
else: |
358 |
raise TypeError(_("Unhandled shape type %s") % shapetype) |
raise TypeError(_("Unhandled shape type %s") % shapetype) |
359 |
|
|
360 |
for index in self.selected_shapes: |
for index in self.selected_shapes: |
361 |
func(renderparam, index, *args) |
func(renderparam, index, *args) |
362 |
|
|
|
|
|
363 |
def layer_ids(self, layer): |
def layer_ids(self, layer): |
364 |
"""Return the shapeids covered by the region that has to be redrawn |
"""Return the shapeids covered by the region that has to be redrawn |
365 |
|
|
507 |
# Render the legend |
# Render the legend |
508 |
dc.SetTextForeground(wxBLACK) |
dc.SetTextForeground(wxBLACK) |
509 |
if map.HasLayers(): |
if map.HasLayers(): |
510 |
for l in map.Layers(): |
layers = map.Layers() |
511 |
|
layers.reverse() |
512 |
|
for l in layers: |
513 |
if l.Visible(): |
if l.Visible(): |
514 |
# Render title |
# Render title |
515 |
dc.DrawText(l.Title(), posx, posy) |
dc.DrawText(l.Title(), posx, posy) |