/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/classification.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/classification.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 627 by jonathan, Wed Apr 9 10:08:47 2003 UTC revision 637 by jonathan, Thu Apr 10 14:35:03 2003 UTC
# Line 428  class ClassGroupProperties: Line 428  class ClassGroupProperties:
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)
# Line 508  class ClassGroupProperties: Line 508  class ClassGroupProperties:
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."""
# Line 544  class ClassGroup: Line 549  class ClassGroup:
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.
# Line 565  class ClassGroupSingleton(ClassGroup): Line 591  class ClassGroupSingleton(ClassGroup):
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(),
# Line 579  class ClassGroupSingleton(ClassGroup): Line 601  class ClassGroupSingleton(ClassGroup):
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."""
# Line 598  class ClassGroupSingleton(ClassGroup): Line 618  class ClassGroupSingleton(ClassGroup):
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    
# Line 622  class ClassGroupSingleton(ClassGroup): Line 626  class ClassGroupSingleton(ClassGroup):
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
# Line 643  class ClassGroupDefault(ClassGroup): Line 644  class ClassGroupDefault(ClassGroup):
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    
# Line 679  class ClassGroupDefault(ClassGroup): Line 663  class ClassGroupDefault(ClassGroup):
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.
# Line 704  class ClassGroupRange(ClassGroup): Line 686  class ClassGroupRange(ClassGroup):
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(),
# Line 721  class ClassGroupRange(ClassGroup): Line 701  class ClassGroupRange(ClassGroup):
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."""
# Line 776  class ClassGroupRange(ClassGroup): Line 755  class ClassGroupRange(ClassGroup):
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    
# Line 798  class ClassGroupRange(ClassGroup): Line 763  class ClassGroupRange(ClassGroup):
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    

Legend:
Removed from v.627  
changed lines
  Added in v.637

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26