1 |
# Copyright (c) 2001, 2003 by Intevation GmbH |
# Copyright (c) 2001, 2003, 2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jonathan Coles <[email protected]> |
# Jonathan Coles <[email protected]> |
4 |
|
# Jan-Oliver Wagner <[email protected]> (2005) |
5 |
# |
# |
6 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
7 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
308 |
i.append(build_color_item(_("Line Color"), v)) |
i.append(build_color_item(_("Line Color"), v)) |
309 |
v = props.GetLineWidth() |
v = props.GetLineWidth() |
310 |
i.append(_("Line Width: %s") % v) |
i.append(_("Line Width: %s") % v) |
311 |
|
|
312 |
|
# Note: Size is owned by all properties, so |
313 |
|
# a size will also appear where it does not |
314 |
|
# make sense like for lines and polygons. |
315 |
|
v = props.GetSize() |
316 |
|
i.append(_("Size: %s") % v) |
317 |
|
|
318 |
v = props.GetFill() |
v = props.GetFill() |
319 |
i.append(build_color_item(_("Fill"), v)) |
i.append(build_color_item(_("Fill"), v)) |
320 |
return (label, i) |
return (label, i) |
323 |
items.append(build_item(p, p.GetDisplayText())) |
items.append(build_item(p, p.GetDisplayText())) |
324 |
|
|
325 |
return (_("Classification"), items) |
return (_("Classification"), items) |
326 |
|
|
327 |
class ClassIterator: |
class ClassIterator: |
328 |
"""Allows the Groups in a Classifcation to be interated over. |
"""Allows the Groups in a Classifcation to be interated over. |
329 |
|
|
335 |
"""Constructor. |
"""Constructor. |
336 |
|
|
337 |
default -- the default group |
default -- the default group |
338 |
|
|
339 |
points -- a list of singleton groups |
points -- a list of singleton groups |
340 |
|
|
341 |
ranges -- a list of range groups |
ranges -- a list of range groups |
342 |
|
|
343 |
maps -- a list of map groups |
maps -- a list of map groups |
344 |
""" |
""" |
345 |
|
|
358 |
d = self.data[self.data_index] |
d = self.data[self.data_index] |
359 |
self.data_index += 1 |
self.data_index += 1 |
360 |
return d |
return d |
361 |
|
|
362 |
class ClassGroupProperties: |
class ClassGroupProperties: |
363 |
"""Represents the properties of a single Classification Group. |
"""Represents the properties of a single Classification Group. |
364 |
|
|
365 |
These are used when rendering a layer.""" |
These are used when rendering a layer.""" |
366 |
|
|
367 |
|
# TODO: Actually, size is only relevant for point objects. |
368 |
|
# Eventually it should be spearated, e.g. when introducing symbols. |
369 |
|
|
370 |
def __init__(self, props = None): |
def __init__(self, props = None): |
371 |
"""Constructor. |
"""Constructor. |
372 |
|
|
373 |
props -- a ClassGroupProperties object. The class is copied if |
props -- a ClassGroupProperties object. The class is copied if |
374 |
prop is not None. Otherwise, a default set of properties |
prop is not None. Otherwise, a default set of properties |
375 |
is created such that: line color = Black, line width = 1, |
is created such that: line color = Black, line width = 1, |
376 |
and fill color = Transparent |
size = 5 and fill color = Transparent |
377 |
""" |
""" |
378 |
|
|
379 |
if props is not None: |
if props is not None: |
381 |
else: |
else: |
382 |
self.SetLineColor(Black) |
self.SetLineColor(Black) |
383 |
self.SetLineWidth(1) |
self.SetLineWidth(1) |
384 |
|
self.SetSize(5) |
385 |
self.SetFill(Transparent) |
self.SetFill(Transparent) |
386 |
|
|
387 |
def SetProperties(self, props): |
def SetProperties(self, props): |
390 |
assert isinstance(props, ClassGroupProperties) |
assert isinstance(props, ClassGroupProperties) |
391 |
self.SetLineColor(props.GetLineColor()) |
self.SetLineColor(props.GetLineColor()) |
392 |
self.SetLineWidth(props.GetLineWidth()) |
self.SetLineWidth(props.GetLineWidth()) |
393 |
|
self.SetSize(props.GetSize()) |
394 |
self.SetFill(props.GetFill()) |
self.SetFill(props.GetFill()) |
395 |
|
|
396 |
def GetLineColor(self): |
def GetLineColor(self): |
397 |
"""Return the line color as a Color object.""" |
"""Return the line color as a Color object.""" |
398 |
return self.__stroke |
return self.__stroke |
420 |
|
|
421 |
self.__strokeWidth = lineWidth |
self.__strokeWidth = lineWidth |
422 |
|
|
423 |
|
def GetSize(self): |
424 |
|
"""Return the size.""" |
425 |
|
return self.__size |
426 |
|
|
427 |
|
def SetSize(self, size): |
428 |
|
"""Set the size. |
429 |
|
|
430 |
|
size -- the new size. This must be > 0. |
431 |
|
""" |
432 |
|
assert isinstance(size, types.IntType) |
433 |
|
if (size < 1): |
434 |
|
raise ValueError(_("size < 1")) |
435 |
|
|
436 |
|
self.__size = size |
437 |
|
|
438 |
def GetFill(self): |
def GetFill(self): |
439 |
"""Return the fill color as a Color object.""" |
"""Return the fill color as a Color object.""" |
440 |
return self.__fill |
return self.__fill |
441 |
|
|
442 |
def SetFill(self, fill): |
def SetFill(self, fill): |
443 |
"""Set the fill color. |
"""Set the fill color. |
444 |
|
|
459 |
self.__stroke == other.__stroke) \ |
self.__stroke == other.__stroke) \ |
460 |
and (self.__fill is other.__fill or \ |
and (self.__fill is other.__fill or \ |
461 |
self.__fill == other.__fill) \ |
self.__fill == other.__fill) \ |
462 |
and self.__strokeWidth == other.__strokeWidth |
and self.__strokeWidth == other.__strokeWidth\ |
463 |
|
and self.__size == other.__size |
464 |
|
|
465 |
def __ne__(self, other): |
def __ne__(self, other): |
466 |
return not self.__eq__(other) |
return not self.__eq__(other) |
472 |
return ClassGroupProperties(self) |
return ClassGroupProperties(self) |
473 |
|
|
474 |
def __repr__(self): |
def __repr__(self): |
475 |
return repr((self.__stroke, self.__strokeWidth, self.__fill)) |
return repr((self.__stroke, self.__strokeWidth, self.__size, |
476 |
|
self.__fill)) |
477 |
|
|
478 |
class ClassGroup: |
class ClassGroup: |
479 |
"""A base class for all Groups within a Classification""" |
"""A base class for all Groups within a Classification""" |
496 |
def GetLabel(self): |
def GetLabel(self): |
497 |
"""Return the Group's label.""" |
"""Return the Group's label.""" |
498 |
return self.label |
return self.label |
499 |
|
|
500 |
def SetLabel(self, label): |
def SetLabel(self, label): |
501 |
"""Set the Group's label. |
"""Set the Group's label. |
502 |
|
|