25 |
from string import join |
from string import join |
26 |
# We need to determine some object types |
# We need to determine some object types |
27 |
from types import ListType |
from types import ListType |
28 |
|
|
29 |
|
from Thuban import _ |
30 |
# VirtualDC extends XMLWriter |
# VirtualDC extends XMLWriter |
31 |
from Thuban.Model.xmlwriter import XMLWriter, escape |
from Thuban.Model.xmlwriter import XMLWriter, escape |
32 |
# Color related classes from the model of thuban |
# Color related classes from the model of thuban |
149 |
# Instantiate a solid pattern. |
# Instantiate a solid pattern. |
150 |
SOLID = Pattern() |
SOLID = Pattern() |
151 |
|
|
152 |
|
class SVGMapWriterError(Exception): |
153 |
|
"""Get raised for problems when writing map-svg files. |
154 |
|
|
155 |
|
Occasion when this exception is raised: |
156 |
|
Two layers have the same name to be used as BaseId: Name Clash |
157 |
|
""" |
158 |
|
|
159 |
|
|
160 |
class SVGRenderer(BaseRenderer): |
class SVGRenderer(BaseRenderer): |
161 |
"""Class to render a map onto a VirtualDC. |
"""Class to render a map onto a VirtualDC. |
162 |
|
|
173 |
resolution, honor_visibility) |
resolution, honor_visibility) |
174 |
# |
# |
175 |
self.factor = (abs(region[2]) + abs(region[3])) / (2.0 * 1000.0) |
self.factor = (abs(region[2]) + abs(region[3])) / (2.0 * 1000.0) |
176 |
|
self.used_baseids=[] # needed for name clash check |
177 |
|
|
178 |
def make_point(self, x, y): |
def make_point(self, x, y): |
179 |
"""Return a Point object from two values.""" |
"""Return a Point object from two values.""" |
180 |
return Point(x, y) |
return Point(x, y) |
242 |
dc = self.dc |
dc = self.dc |
243 |
brush = TRANSPARENT_BRUSH |
brush = TRANSPARENT_BRUSH |
244 |
pen = TRANSPARENT_PEN |
pen = TRANSPARENT_PEN |
245 |
|
|
246 |
value = None |
value = None |
247 |
field = None |
field = None |
248 |
lc = layer.GetClassification() |
lc = layer.GetClassification() |
262 |
self.low_level_renderer(layer) |
self.low_level_renderer(layer) |
263 |
tool_cache = {} |
tool_cache = {} |
264 |
|
|
265 |
# Set baseid - prefix of a shape id to be unique |
if layer.title in self.used_baseids: |
266 |
|
raise SVGMapWriterError(_("Clash of layer names!\n")+ \ |
267 |
|
_("Two layers probably have the same name, try renaming one.")) |
268 |
|
# prefix of a shape id to be unique |
269 |
dc.SetBaseID(layer.title) |
dc.SetBaseID(layer.title) |
270 |
|
self.used_baseids.append(layer.title) |
271 |
# Titel of current layer to the groups meta informations |
# Titel of current layer to the groups meta informations |
272 |
dc.BeginGroup(meta={'Layer':layer.Title(), }) |
dc.BeginGroup(meta={'Layer':layer.Title(), }) |
273 |
# Delete all MetaData |
# Delete all MetaData |
573 |
return 'meta="%s"' % (join(result, '; ')) |
return 'meta="%s"' % (join(result, '; ')) |
574 |
|
|
575 |
def make_id(self): |
def make_id(self): |
576 |
"""Get the ID for the next object - if current ID is valid.""" |
"""Return id= string for object out of currently set baseid and id. |
577 |
|
|
578 |
|
Return the empty string if no id was set. |
579 |
|
""" |
580 |
if self.id < 0: |
if self.id < 0: |
581 |
return '' |
return '' |
582 |
else: return 'id="%s%s"' % (self.baseid, self.id) |
return 'id="%s-%s"' % (self.baseid, self.id) |
583 |
|
|
584 |
def DrawEllipse(self, x, y, dx, dy): |
def DrawEllipse(self, x, y, dx, dy): |
585 |
"""Draw an ellipse.""" |
"""Draw an ellipse.""" |