/[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 462 by jonathan, Wed Mar 5 18:17:17 2003 UTC revision 479 by jonathan, Thu Mar 6 16:46:07 2003 UTC
# Line 33  from Thuban.Model.color import Color Line 33  from Thuban.Model.color import Color
33    
34  import Thuban.Model.layer  import Thuban.Model.layer
35    
   
36  # constants  # constants
37  RANGE_MIN  = 0  RANGE_MIN  = 0
38  RANGE_MAX  = 1  RANGE_MAX  = 1
# Line 81  class Classification: Line 80  class Classification:
80      def SetField(self, field = None):      def SetField(self, field = None):
81          """Set the name of the data table field to use.          """Set the name of the data table field to use.
82                    
83               If there is no layer then the field type is set to None,
84               otherwise the layer is queried to find the type of the
85               field data
86    
87             field -- if None then all values map to the default data             field -- if None then all values map to the default data
88          """          """
89    
# Line 118  class Classification: Line 121  class Classification:
121              if layer is not None:              if layer is not None:
122                  assert(isinstance(layer, Thuban.Model.layer.Layer))                  assert(isinstance(layer, Thuban.Model.layer.Layer))
123    
124            # prevent infinite recursion when calling SetClassification()
125            if self.layer is not None and layer == self.layer:
126                return
127    
128          self.layer = layer          self.layer = layer
129          self.SetField(self.GetField()) # XXX: this sync's the fieldType          self.SetField(self.GetField()) # XXX: this sync's the fieldType
130    
131          self.__SendMessage(LAYER_LEGEND_CHANGED)          if self.layer is not None:
132                self.layer.SetClassification(self)
133    
134            #self.__SendMessage(LAYER_LEGEND_CHANGED)
135    
136      def GetLayer(self):      def GetLayer(self):
137          """Return the parent layer."""          """Return the parent layer."""
# Line 208  class Classification: Line 218  class Classification:
218             Classification.             Classification.
219    
220             value -- the value to classify. If there is no mapping,             value -- the value to classify. If there is no mapping,
221                      or value is None, return the default properties                      the field is None or value is None,
222                        return the default properties
223          """          """
224    
225          if self.field is not None and value is not None:          if self.GetField() is not None and value is not None:
226    
227              for i in range(1, len(self.groups)):              for i in range(1, len(self.groups)):
228                  group = self.groups[i]                  group = self.groups[i]
# Line 328  class ClassGroupProperties: Line 339  class ClassGroupProperties:
339    
340          props -- a ClassGroupProperties object. The class is copied if          props -- a ClassGroupProperties object. The class is copied if
341                   prop is not None. Otherwise, a default set of properties                   prop is not None. Otherwise, a default set of properties
342                   is created.                   is created such that: line color = Color.Black, line width = 1,
343                     and fill color = Color.None
344          """          """
345    
346          self.stroke = None          self.stroke = None
# Line 391  class ClassGroupProperties: Line 403  class ClassGroupProperties:
403          assert(isinstance(fill, Color))          assert(isinstance(fill, Color))
404          self.fill = fill          self.fill = fill
405    
406        def __eq__(self, other):
407            """Return true if 'props' has the same attributes as this class"""
408    
409            return isinstance(other, ClassGroupProperties)   \
410                and self.stroke      == other.GetLineColor() \
411                and self.strokeWidth == other.GetLineWidth() \
412                and self.fill        == other.GetFill()
413    
414        def __ne__(self, other):
415            return not self.__eq__(other)
416    
417  class ClassGroup:  class ClassGroup:
418      """A base class for all Groups within a Classification"""      """A base class for all Groups within a Classification"""
# Line 421  class ClassGroup: Line 443  class ClassGroup:
443      def Matches(self, value):      def Matches(self, value):
444          """Determines if this Group is associated with the given value.          """Determines if this Group is associated with the given value.
445    
446          Returns True or False. This needs to be implemented by all subclasses.          Returns False. This needs to be overridden by all subclasses.
447          """          """
448          pass          return False
449    
450      def GetProperties(self):      def GetProperties(self):
451          """Return the properties associated with the given value.          """Return the properties associated with the given value.
452    
453          This needs to be implemented by all subclasses.          Returns None. This needs to be overridden by all subclasses.
454          """          """
455          pass          return None
456    
457            
458  class ClassGroupSingleton(ClassGroup):  class ClassGroupSingleton(ClassGroup):
# Line 455  class ClassGroupSingleton(ClassGroup): Line 477  class ClassGroupSingleton(ClassGroup):
477          self.SetProperties(prop)          self.SetProperties(prop)
478    
479      def __copy__(self):      def __copy__(self):
480          return ClassGroupSingleton(self.value, self.prop, self.label)          return ClassGroupSingleton(self.GetValue(),
481                                       self.GetProperties(),
482                                       self.GetLabel())
483    
484      def GetValue(self):      def GetValue(self):
485          """Return the associated value."""          """Return the associated value."""
# Line 488  class ClassGroupSingleton(ClassGroup): Line 512  class ClassGroupSingleton(ClassGroup):
512          assert(isinstance(prop, ClassGroupProperties))          assert(isinstance(prop, ClassGroupProperties))
513          self.prop = prop          self.prop = prop
514    
515        def __eq__(self, other):
516            return isinstance(other, ClassGroupSingleton) \
517                and self.GetProperties() == other.GetProperties() \
518                and self.GetValue() == other.GetValue()
519    
520        def __ne__(self, other):
521            return not self.__eq__(other)
522    
523  class ClassGroupDefault(ClassGroupSingleton):  class ClassGroupDefault(ClassGroup):
524      """The default Group. When values do not match any other      """The default Group. When values do not match any other
525         Group within a Classification, the properties from this         Group within a Classification, the properties from this
526         class are used."""         class are used."""
# Line 503  class ClassGroupDefault(ClassGroupSingle Line 534  class ClassGroupDefault(ClassGroupSingle
534          label -- a label for this group.          label -- a label for this group.
535          """          """
536    
537          ClassGroupSingleton.__init__(self, 0, prop, label)          ClassGroup.__init__(self, label)
538            self.SetProperties(prop)
539    
540      def __copy__(self):      def __copy__(self):
541          return ClassGroupDefault(self.prop, self.label)          return ClassGroupDefault(self.GetProperties(), self.GetLabel())
542    
543        def Matches(self, value):
544            return True
545    
546      def GetProperties(self):      def GetProperties(self):
547          """Return the Properties associated with this Group."""          """Return the Properties associated with this Group."""
548          return self.prop          return self.prop
549    
550        def SetProperties(self, prop):
551            """Set the properties associated with this Group.
552    
553            prop -- a ClassGroupProperties object. if prop is None,
554                    a default set of properties is created.
555            """
556    
557            if prop is None: prop = ClassGroupProperties()
558            assert(isinstance(prop, ClassGroupProperties))
559            self.prop = prop
560    
561        def __eq__(self, other):
562            return isinstance(other, ClassGroupDefault) \
563                and self.GetProperties() == other.GetProperties()
564    
565        def __ne__(self, other):
566            return not self.__eq__(other)
567    
568  class ClassGroupRange(ClassGroup):  class ClassGroupRange(ClassGroup):
569      """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
570         set of properties."""         set of properties."""
# Line 540  class ClassGroupRange(ClassGroup): Line 593  class ClassGroupRange(ClassGroup):
593          self.SetProperties(prop)          self.SetProperties(prop)
594    
595      def __copy__(self):      def __copy__(self):
596          return ClassGroupRange(self.min, self.max, self.prop, self.label)          return ClassGroupRange(self.GetMin(),
597                                   self.GetMax(),
598                                   self.GetProperties(),
599                                   self.GetLabel())
600    
601      def GetMin(self):      def GetMin(self):
602          """Return the range's minimum value."""          """Return the range's minimum value."""
# Line 608  class ClassGroupRange(ClassGroup): Line 664  class ClassGroupRange(ClassGroup):
664          assert(isinstance(prop, ClassGroupProperties))          assert(isinstance(prop, ClassGroupProperties))
665          self.prop = prop          self.prop = prop
666    
667        def __eq__(self, other):
668            return isinstance(other, ClassGroupRange) \
669                and self.GetProperties() == other.GetProperties() \
670                and self.GetRange() == other.GetRange()
671    
672        def __ne__(self, other):
673            return not self.__eq__(other)
674    
675  class ClassGroupMap(ClassGroup):  class ClassGroupMap(ClassGroup):
676      """Currently, this class is not used."""      """Currently, this class is not used."""
677    

Legend:
Removed from v.462  
changed lines
  Added in v.479

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26