60 |
self.fieldType = None |
self.fieldType = None |
61 |
self.groups = [] |
self.groups = [] |
62 |
|
|
63 |
|
self.__setLayerLock = False |
64 |
|
|
65 |
self.SetDefaultGroup(ClassGroupDefault()) |
self.SetDefaultGroup(ClassGroupDefault()) |
66 |
|
|
67 |
self.SetLayer(layer) |
self.SetLayer(layer) |
139 |
field type mismatch the information in the layer's table. |
field type mismatch the information in the layer's table. |
140 |
""" |
""" |
141 |
|
|
142 |
|
# prevent infinite recursion when calling SetClassification() |
143 |
|
if self.__setLayerLock: return |
144 |
|
|
145 |
|
self.__setLayerLock = True |
146 |
|
|
147 |
if layer is None: |
if layer is None: |
148 |
if self.layer is not None: |
if self.layer is not None: |
149 |
l = self.layer |
l = self.layer |
150 |
self.layer = None |
self.layer = None |
151 |
l.SetClassification(None) |
l.SetClassification(None) |
152 |
else: |
else: |
153 |
assert(isinstance(layer, Thuban.Model.layer.Layer)) |
assert isinstance(layer, Thuban.Model.layer.Layer) |
154 |
|
|
|
# prevent infinite recursion when calling SetClassification() |
|
|
if layer == self.layer: |
|
|
return |
|
|
|
|
155 |
old_layer = self.layer |
old_layer = self.layer |
156 |
|
|
157 |
self.layer = layer |
self.layer = layer |
160 |
self.SetField(self.GetField()) # this sync's the fieldType |
self.SetField(self.GetField()) # this sync's the fieldType |
161 |
except ValueError: |
except ValueError: |
162 |
self.layer = old_layer |
self.layer = old_layer |
163 |
|
self.__setLayerLock = False |
164 |
raise ValueError |
raise ValueError |
165 |
else: |
else: |
166 |
self.layer.SetClassification(self) |
self.layer.SetClassification(self) |
167 |
|
|
168 |
|
self.__setLayerLock = False |
169 |
|
|
170 |
def GetLayer(self): |
def GetLayer(self): |
171 |
"""Return the parent layer.""" |
"""Return the parent layer.""" |
172 |
return self.layer |
return self.layer |
177 |
group -- group that the value maps to. |
group -- group that the value maps to. |
178 |
""" |
""" |
179 |
|
|
180 |
assert(isinstance(group, ClassGroupDefault)) |
assert isinstance(group, ClassGroupDefault) |
181 |
self.AddGroup(group) |
self.AddGroup(group) |
182 |
|
|
183 |
def GetDefaultGroup(self): |
def GetDefaultGroup(self): |
195 |
|
|
196 |
fill -- a Color object. |
fill -- a Color object. |
197 |
""" |
""" |
198 |
assert(isinstance(fill, Color)) |
assert isinstance(fill, Color) |
199 |
self.GetDefaultGroup().GetProperties().SetFill(fill) |
self.GetDefaultGroup().GetProperties().SetFill(fill) |
200 |
self.__SendNotification() |
self.__SendNotification() |
201 |
|
|
208 |
|
|
209 |
color -- a Color object. |
color -- a Color object. |
210 |
""" |
""" |
211 |
assert(isinstance(color, Color)) |
assert isinstance(color, Color) |
212 |
self.GetDefaultGroup().GetProperties().SetLineColor(color) |
self.GetDefaultGroup().GetProperties().SetLineColor(color) |
213 |
self.__SendNotification() |
self.__SendNotification() |
214 |
|
|
221 |
|
|
222 |
lineWidth -- an integer > 0. |
lineWidth -- an integer > 0. |
223 |
""" |
""" |
224 |
assert(isinstance(lineWidth, IntType)) |
assert isinstance(lineWidth, IntType) |
225 |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
226 |
self.__SendNotification() |
self.__SendNotification() |
227 |
|
|
235 |
item -- this must be a valid ClassGroup object |
item -- this must be a valid ClassGroup object |
236 |
""" |
""" |
237 |
|
|
238 |
assert(isinstance(item, ClassGroup)) |
assert isinstance(item, ClassGroup) |
239 |
|
|
240 |
if len(self.groups) > 0 and isinstance(item, ClassGroupDefault): |
if len(self.groups) > 0 and isinstance(item, ClassGroupDefault): |
241 |
self.groups[0] = item |
self.groups[0] = item |
390 |
def SetProperties(self, props): |
def SetProperties(self, props): |
391 |
"""Set this class's properties to those in class props.""" |
"""Set this class's properties to those in class props.""" |
392 |
|
|
393 |
assert(isinstance(props, ClassGroupProperties)) |
assert isinstance(props, ClassGroupProperties) |
394 |
self.SetLineColor(props.GetLineColor()) |
self.SetLineColor(props.GetLineColor()) |
395 |
self.SetLineWidth(props.GetLineWidth()) |
self.SetLineWidth(props.GetLineWidth()) |
396 |
self.SetFill(props.GetFill()) |
self.SetFill(props.GetFill()) |
405 |
color -- the color of the line. This must be a Color object. |
color -- the color of the line. This must be a Color object. |
406 |
""" |
""" |
407 |
|
|
408 |
assert(isinstance(color, Color)) |
assert isinstance(color, Color) |
409 |
self.stroke = color |
#self.stroke = Color(color.red, color.green, color.blue) |
410 |
|
self.stroke = copy.copy(color) |
411 |
|
|
412 |
def GetLineWidth(self): |
def GetLineWidth(self): |
413 |
"""Return the line width.""" |
"""Return the line width.""" |
418 |
|
|
419 |
lineWidth -- the new line width. This must be > 0. |
lineWidth -- the new line width. This must be > 0. |
420 |
""" |
""" |
421 |
assert(isinstance(lineWidth, IntType)) |
assert isinstance(lineWidth, IntType) |
422 |
if (lineWidth < 1): |
if (lineWidth < 1): |
423 |
raise ValueError(_("lineWidth < 1")) |
raise ValueError(_("lineWidth < 1")) |
424 |
|
|
434 |
fill -- the color of the fill. This must be a Color object. |
fill -- the color of the fill. This must be a Color object. |
435 |
""" |
""" |
436 |
|
|
437 |
assert(isinstance(fill, Color)) |
assert isinstance(fill, Color) |
438 |
self.fill = fill |
self.fill = copy.copy(fill) |
439 |
|
#self.fill = Color(fill.red, fill.green, fill.blue) |
440 |
|
|
441 |
def __eq__(self, other): |
def __eq__(self, other): |
442 |
"""Return true if 'props' has the same attributes as this class""" |
"""Return true if 'props' has the same attributes as this class""" |
452 |
def __copy__(self): |
def __copy__(self): |
453 |
return ClassGroupProperties(self) |
return ClassGroupProperties(self) |
454 |
|
|
455 |
|
def __deepcopy__(self): |
456 |
|
return ClassGroupProperties(self) |
457 |
|
|
458 |
class ClassGroup: |
class ClassGroup: |
459 |
"""A base class for all Groups within a Classification""" |
"""A base class for all Groups within a Classification""" |
460 |
|
|
478 |
label -- a string representing the Group's label. This must |
label -- a string representing the Group's label. This must |
479 |
not be None. |
not be None. |
480 |
""" |
""" |
481 |
assert(isinstance(label, StringType)) |
assert isinstance(label, StringType) |
482 |
self.label = label |
self.label = label |
483 |
|
|
484 |
|
def GetDisplayText(self): |
485 |
|
assert False, "GetDisplay must be overridden by subclass!" |
486 |
|
return "" |
487 |
|
|
488 |
def Matches(self, value): |
def Matches(self, value): |
489 |
"""Determines if this Group is associated with the given value. |
"""Determines if this Group is associated with the given value. |
490 |
|
|
491 |
Returns False. This needs to be overridden by all subclasses. |
Returns False. This needs to be overridden by all subclasses. |
492 |
""" |
""" |
493 |
|
assert False, "GetMatches must be overridden by subclass!" |
494 |
return False |
return False |
495 |
|
|
496 |
def GetProperties(self): |
def GetProperties(self): |
498 |
|
|
499 |
Returns None. This needs to be overridden by all subclasses. |
Returns None. This needs to be overridden by all subclasses. |
500 |
""" |
""" |
501 |
|
assert False, "GetProperties must be overridden by subclass!" |
502 |
return None |
return None |
503 |
|
|
504 |
|
|
561 |
""" |
""" |
562 |
|
|
563 |
if prop is None: prop = ClassGroupProperties() |
if prop is None: prop = ClassGroupProperties() |
564 |
assert(isinstance(prop, ClassGroupProperties)) |
assert isinstance(prop, ClassGroupProperties) |
565 |
self.prop = prop |
self.prop = prop |
566 |
|
|
567 |
|
def GetDisplayText(self): |
568 |
|
label = self.GetLabel() |
569 |
|
|
570 |
|
if label != "": return label |
571 |
|
|
572 |
|
return str(self.GetValue()) |
573 |
|
|
574 |
def __eq__(self, other): |
def __eq__(self, other): |
575 |
return isinstance(other, ClassGroupSingleton) \ |
return isinstance(other, ClassGroupSingleton) \ |
576 |
and self.GetProperties() == other.GetProperties() \ |
and self.GetProperties() == other.GetProperties() \ |
618 |
""" |
""" |
619 |
|
|
620 |
if prop is None: prop = ClassGroupProperties() |
if prop is None: prop = ClassGroupProperties() |
621 |
assert(isinstance(prop, ClassGroupProperties)) |
assert isinstance(prop, ClassGroupProperties) |
622 |
self.prop = prop |
self.prop = prop |
623 |
|
|
624 |
|
def GetDisplayText(self): |
625 |
|
label = self.GetLabel() |
626 |
|
|
627 |
|
if label != "": return label |
628 |
|
|
629 |
|
return "DEFAULT" |
630 |
|
|
631 |
def __eq__(self, other): |
def __eq__(self, other): |
632 |
return isinstance(other, ClassGroupDefault) \ |
return isinstance(other, ClassGroupDefault) \ |
633 |
and self.GetProperties() == other.GetProperties() |
and self.GetProperties() == other.GetProperties() |
737 |
a default set of properties is created. |
a default set of properties is created. |
738 |
""" |
""" |
739 |
if prop is None: prop = ClassGroupProperties() |
if prop is None: prop = ClassGroupProperties() |
740 |
assert(isinstance(prop, ClassGroupProperties)) |
assert isinstance(prop, ClassGroupProperties) |
741 |
self.prop = prop |
self.prop = prop |
742 |
|
|
743 |
|
def GetDisplayText(self): |
744 |
|
label = self.GetLabel() |
745 |
|
|
746 |
|
if label != "": return label |
747 |
|
|
748 |
|
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
749 |
|
|
750 |
def __eq__(self, other): |
def __eq__(self, other): |
751 |
return isinstance(other, ClassGroupRange) \ |
return isinstance(other, ClassGroupRange) \ |
752 |
and self.GetProperties() == other.GetProperties() \ |
and self.GetProperties() == other.GetProperties() \ |
778 |
def GetPropertiesFromValue(self, value): |
def GetPropertiesFromValue(self, value): |
779 |
pass |
pass |
780 |
|
|
781 |
|
def GetDisplayText(self): |
782 |
|
return "Map: " + self.map_type |
783 |
|
|
784 |
# |
# |
785 |
# built-in mappings |
# built-in mappings |
786 |
# |
# |