428 |
and fill color = Color.Transparent |
and fill color = Color.Transparent |
429 |
""" |
""" |
430 |
|
|
431 |
self.stroke = None |
#self.stroke = None |
432 |
self.strokeWidth = 0 |
#self.strokeWidth = 0 |
433 |
self.fill = None |
#self.fill = None |
434 |
|
|
435 |
if props is not None: |
if props is not None: |
436 |
self.SetProperties(props) |
self.SetProperties(props) |
508 |
class ClassGroup: |
class ClassGroup: |
509 |
"""A base class for all Groups within a Classification""" |
"""A base class for all Groups within a Classification""" |
510 |
|
|
511 |
def __init__(self, label = ""): |
def __init__(self, label = "", props = None, group = None): |
512 |
"""Constructor. |
"""Constructor. |
513 |
|
|
514 |
label -- A string representing the Group's label |
label -- A string representing the Group's label |
515 |
""" |
""" |
516 |
|
|
517 |
self.label = None |
if group is not None: |
518 |
|
self.SetLabel(copy.copy(group.GetLabel())) |
519 |
self.SetLabel(label) |
self.SetProperties(copy.copy(group.GetProperties())) |
520 |
|
self.SetVisible(group.IsVisible()) |
521 |
|
else: |
522 |
|
self.SetLabel(label) |
523 |
|
self.SetProperties(props) |
524 |
|
self.SetVisible(True) |
525 |
|
|
526 |
def GetLabel(self): |
def GetLabel(self): |
527 |
"""Return the Group's label.""" |
"""Return the Group's label.""" |
549 |
return False |
return False |
550 |
|
|
551 |
def GetProperties(self): |
def GetProperties(self): |
552 |
"""Return the properties associated with the given value. |
"""Return the properties associated with the given value.""" |
553 |
|
|
554 |
Returns None. This needs to be overridden by all subclasses. |
return self.prop |
|
""" |
|
|
assert False, "GetProperties must be overridden by subclass!" |
|
|
return None |
|
555 |
|
|
556 |
|
def SetProperties(self, prop): |
557 |
|
"""Set the properties associated with this Group. |
558 |
|
|
559 |
|
prop -- a ClassGroupProperties object. if prop is None, |
560 |
|
a default set of properties is created. |
561 |
|
""" |
562 |
|
|
563 |
|
if prop is None: prop = ClassGroupProperties() |
564 |
|
assert isinstance(prop, ClassGroupProperties) |
565 |
|
self.prop = prop |
566 |
|
|
567 |
|
def IsVisible(self): |
568 |
|
return self.visible |
569 |
|
|
570 |
|
def SetVisible(self, visible): |
571 |
|
self.visible = visible |
572 |
|
|
573 |
|
def __eq__(self, other): |
574 |
|
return isinstance(other, ClassGroup) \ |
575 |
|
and self.GetProperties() == other.GetProperties() |
576 |
|
|
577 |
|
def __ne__(self, other): |
578 |
|
return not self.__eq__(other) |
579 |
|
|
580 |
|
|
581 |
class ClassGroupSingleton(ClassGroup): |
class ClassGroupSingleton(ClassGroup): |
582 |
"""A Group that is associated with a single value.""" |
"""A Group that is associated with a single value.""" |
583 |
|
|
584 |
def __init__(self, value = 0, prop = None, label = ""): |
def __init__(self, value = 0, props = None, label = "", group = None): |
585 |
"""Constructor. |
"""Constructor. |
586 |
|
|
587 |
value -- the associated value. |
value -- the associated value. |
591 |
|
|
592 |
label -- a label for this group. |
label -- a label for this group. |
593 |
""" |
""" |
594 |
ClassGroup.__init__(self, label) |
ClassGroup.__init__(self, label, props, group) |
|
|
|
|
self.prop = None |
|
|
self.value = None |
|
595 |
|
|
596 |
self.SetValue(value) |
self.SetValue(value) |
|
self.SetProperties(prop) |
|
597 |
|
|
598 |
def __copy__(self): |
def __copy__(self): |
599 |
return ClassGroupSingleton(self.GetValue(), |
return ClassGroupSingleton(self.GetValue(), |
601 |
self.GetLabel()) |
self.GetLabel()) |
602 |
|
|
603 |
def __deepcopy__(self, memo): |
def __deepcopy__(self, memo): |
604 |
return ClassGroupSingleton(copy.copy(self.GetValue()), |
return ClassGroupSingleton(self.GetValue(), group = self) |
|
copy.copy(self.GetProperties()), |
|
|
copy.copy(self.GetLabel())) |
|
605 |
|
|
606 |
def GetValue(self): |
def GetValue(self): |
607 |
"""Return the associated value.""" |
"""Return the associated value.""" |
618 |
|
|
619 |
return self.value == value |
return self.value == value |
620 |
|
|
|
def GetProperties(self): |
|
|
"""Return the Properties associated with this Group.""" |
|
|
|
|
|
return self.prop |
|
|
|
|
|
def SetProperties(self, prop): |
|
|
"""Set the properties associated with this Group. |
|
|
|
|
|
prop -- a ClassGroupProperties object. if prop is None, |
|
|
a default set of properties is created. |
|
|
""" |
|
|
|
|
|
if prop is None: prop = ClassGroupProperties() |
|
|
assert isinstance(prop, ClassGroupProperties) |
|
|
self.prop = prop |
|
|
|
|
621 |
def GetDisplayText(self): |
def GetDisplayText(self): |
622 |
label = self.GetLabel() |
label = self.GetLabel() |
623 |
|
|
626 |
return str(self.GetValue()) |
return str(self.GetValue()) |
627 |
|
|
628 |
def __eq__(self, other): |
def __eq__(self, other): |
629 |
return isinstance(other, ClassGroupSingleton) \ |
return ClassGroup.__eq__(self, other) \ |
630 |
and self.GetProperties() == other.GetProperties() \ |
and isinstance(other, ClassGroupSingleton) \ |
631 |
and self.GetValue() == other.GetValue() |
and self.GetValue() == other.GetValue() |
632 |
|
|
|
def __ne__(self, other): |
|
|
return not self.__eq__(other) |
|
|
|
|
633 |
class ClassGroupDefault(ClassGroup): |
class ClassGroupDefault(ClassGroup): |
634 |
"""The default Group. When values do not match any other |
"""The default Group. When values do not match any other |
635 |
Group within a Classification, the properties from this |
Group within a Classification, the properties from this |
636 |
class are used.""" |
class are used.""" |
637 |
|
|
638 |
def __init__(self, prop = None, label = ""): |
def __init__(self, props = None, label = "", group = None): |
639 |
"""Constructor. |
"""Constructor. |
640 |
|
|
641 |
prop -- a ClassGroupProperites object. If prop is None a default |
prop -- a ClassGroupProperites object. If prop is None a default |
644 |
label -- a label for this group. |
label -- a label for this group. |
645 |
""" |
""" |
646 |
|
|
647 |
ClassGroup.__init__(self, label) |
ClassGroup.__init__(self, label, props, group) |
|
self.SetProperties(prop) |
|
648 |
|
|
649 |
def __copy__(self): |
def __copy__(self): |
650 |
return ClassGroupDefault(self.GetProperties(), self.GetLabel()) |
return ClassGroupDefault(self.GetProperties(), self.GetLabel()) |
651 |
|
|
652 |
def __deepcopy__(self, memo): |
def __deepcopy__(self, memo): |
653 |
return ClassGroupDefault(copy.copy(self.GetProperties()), |
return ClassGroupDefault(label = self.GetLabel(), group = self) |
|
copy.copy(self.GetLabel())) |
|
654 |
|
|
655 |
def Matches(self, value): |
def Matches(self, value): |
656 |
return True |
return True |
657 |
|
|
|
def GetProperties(self): |
|
|
"""Return the Properties associated with this Group.""" |
|
|
return self.prop |
|
|
|
|
|
def SetProperties(self, prop): |
|
|
"""Set the properties associated with this Group. |
|
|
|
|
|
prop -- a ClassGroupProperties object. if prop is None, |
|
|
a default set of properties is created. |
|
|
""" |
|
|
|
|
|
if prop is None: prop = ClassGroupProperties() |
|
|
assert isinstance(prop, ClassGroupProperties) |
|
|
self.prop = prop |
|
|
|
|
658 |
def GetDisplayText(self): |
def GetDisplayText(self): |
659 |
label = self.GetLabel() |
label = self.GetLabel() |
660 |
|
|
663 |
return _("DEFAULT") |
return _("DEFAULT") |
664 |
|
|
665 |
def __eq__(self, other): |
def __eq__(self, other): |
666 |
return isinstance(other, ClassGroupDefault) \ |
return ClassGroup.__eq__(self, other) \ |
667 |
|
and isinstance(other, ClassGroupDefault) \ |
668 |
and self.GetProperties() == other.GetProperties() |
and self.GetProperties() == other.GetProperties() |
669 |
|
|
|
def __ne__(self, other): |
|
|
return not self.__eq__(other) |
|
|
|
|
670 |
class ClassGroupRange(ClassGroup): |
class ClassGroupRange(ClassGroup): |
671 |
"""A Group that represents a range of values that map to the same |
"""A Group that represents a range of values that map to the same |
672 |
set of properties.""" |
set of properties.""" |
673 |
|
|
674 |
def __init__(self, min = 0, max = 1, prop = None, label = ""): |
def __init__(self, min = 0, max = 1, props = None, label = "", group=None): |
675 |
"""Constructor. |
"""Constructor. |
676 |
|
|
677 |
The minumum value must be strictly less than the maximum. |
The minumum value must be strictly less than the maximum. |
686 |
label -- a label for this group. |
label -- a label for this group. |
687 |
""" |
""" |
688 |
|
|
689 |
ClassGroup.__init__(self, label) |
ClassGroup.__init__(self, label, props, None) |
690 |
|
|
691 |
self.min = self.max = 0 |
self.min = self.max = 0 |
|
self.prop = None |
|
692 |
|
|
693 |
self.SetRange(min, max) |
self.SetRange(min, max) |
|
self.SetProperties(prop) |
|
694 |
|
|
695 |
def __copy__(self): |
def __copy__(self): |
696 |
return ClassGroupRange(self.GetMin(), |
return ClassGroupRange(self.GetMin(), |
701 |
def __deepcopy__(self, memo): |
def __deepcopy__(self, memo): |
702 |
return ClassGroupRange(copy.copy(self.GetMin()), |
return ClassGroupRange(copy.copy(self.GetMin()), |
703 |
copy.copy(self.GetMax()), |
copy.copy(self.GetMax()), |
704 |
copy.copy(self.GetProperties()), |
group = self) |
|
copy.copy(self.GetLabel())) |
|
705 |
|
|
706 |
def GetMin(self): |
def GetMin(self): |
707 |
"""Return the range's minimum value.""" |
"""Return the range's minimum value.""" |
755 |
|
|
756 |
return self.min <= value < self.max |
return self.min <= value < self.max |
757 |
|
|
|
def GetProperties(self): |
|
|
"""Return the Properties associated with this Group.""" |
|
|
return self.prop |
|
|
|
|
|
def SetProperties(self, prop): |
|
|
"""Set the properties associated with this Group. |
|
|
|
|
|
prop -- a ClassGroupProperties object. if prop is None, |
|
|
a default set of properties is created. |
|
|
""" |
|
|
if prop is None: prop = ClassGroupProperties() |
|
|
assert isinstance(prop, ClassGroupProperties) |
|
|
self.prop = prop |
|
|
|
|
758 |
def GetDisplayText(self): |
def GetDisplayText(self): |
759 |
label = self.GetLabel() |
label = self.GetLabel() |
760 |
|
|
763 |
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
764 |
|
|
765 |
def __eq__(self, other): |
def __eq__(self, other): |
766 |
return isinstance(other, ClassGroupRange) \ |
return ClassGroup.__eq__(self, other) \ |
767 |
and self.GetProperties() == other.GetProperties() \ |
and isinstance(other, ClassGroupRange) \ |
768 |
and self.GetRange() == other.GetRange() |
and self.GetRange() == other.GetRange() |
769 |
|
|
|
def __ne__(self, other): |
|
|
return not self.__eq__(other) |
|
|
|
|
770 |
class ClassGroupMap(ClassGroup): |
class ClassGroupMap(ClassGroup): |
771 |
"""Currently, this class is not used.""" |
"""Currently, this class is not used.""" |
772 |
|
|