/[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 484 by jonathan, Fri Mar 7 18:20:10 2003 UTC
# Line 23  on the mapping algorithm. Line 23  on the mapping algorithm.
23  # fix for people using python2.1  # fix for people using python2.1
24  from __future__ import nested_scopes  from __future__ import nested_scopes
25    
26    import copy
27    
28  from types import *  from types import *
29    
30  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \
# Line 33  from Thuban.Model.color import Color Line 35  from Thuban.Model.color import Color
35    
36  import Thuban.Model.layer  import Thuban.Model.layer
37    
   
38  # constants  # constants
39  RANGE_MIN  = 0  RANGE_MIN  = 0
40  RANGE_MAX  = 1  RANGE_MAX  = 1
# Line 81  class Classification: Line 82  class Classification:
82      def SetField(self, field = None):      def SetField(self, field = None):
83          """Set the name of the data table field to use.          """Set the name of the data table field to use.
84                    
85               If there is no layer then the field type is set to None,
86               otherwise the layer is queried to find the type of the
87               field data
88    
89             field -- if None then all values map to the default data             field -- if None then all values map to the default data
90          """          """
91    
# Line 118  class Classification: Line 123  class Classification:
123              if layer is not None:              if layer is not None:
124                  assert(isinstance(layer, Thuban.Model.layer.Layer))                  assert(isinstance(layer, Thuban.Model.layer.Layer))
125    
126            # prevent infinite recursion when calling SetClassification()
127            if self.layer is not None and layer == self.layer:
128                return
129    
130          self.layer = layer          self.layer = layer
131          self.SetField(self.GetField()) # XXX: this sync's the fieldType          self.SetField(self.GetField()) # XXX: this sync's the fieldType
132    
133          self.__SendMessage(LAYER_LEGEND_CHANGED)          if self.layer is not None:
134                self.layer.SetClassification(self)
135    
136            #self.__SendMessage(LAYER_LEGEND_CHANGED)
137    
138      def GetLayer(self):      def GetLayer(self):
139          """Return the parent layer."""          """Return the parent layer."""
# Line 208  class Classification: Line 220  class Classification:
220             Classification.             Classification.
221    
222             value -- the value to classify. If there is no mapping,             value -- the value to classify. If there is no mapping,
223                      or value is None, return the default properties                      the field is None or value is None,
224                        return the default properties
225          """          """
226    
227          if self.field is not None and value is not None:          if self.GetField() is not None and value is not None:
228    
229              for i in range(1, len(self.groups)):              for i in range(1, len(self.groups)):
230                  group = self.groups[i]                  group = self.groups[i]
# Line 328  class ClassGroupProperties: Line 341  class ClassGroupProperties:
341    
342          props -- a ClassGroupProperties object. The class is copied if          props -- a ClassGroupProperties object. The class is copied if
343                   prop is not None. Otherwise, a default set of properties                   prop is not None. Otherwise, a default set of properties
344                   is created.                   is created such that: line color = Color.Black, line width = 1,
345                     and fill color = Color.None
346          """          """
347    
348          self.stroke = None          self.stroke = None
# Line 338  class ClassGroupProperties: Line 352  class ClassGroupProperties:
352          if props is not None:          if props is not None:
353              self.SetProperties(props)              self.SetProperties(props)
354          else:          else:
355              self.SetLineColor(Color.None)              self.SetLineColor(Color.Black)
356              self.SetLineWidth(1)              self.SetLineWidth(1)
357              self.SetFill(Color.None)              self.SetFill(Color.None)
358    
# Line 391  class ClassGroupProperties: Line 405  class ClassGroupProperties:
405          assert(isinstance(fill, Color))          assert(isinstance(fill, Color))
406          self.fill = fill          self.fill = fill
407    
408        def __eq__(self, other):
409            """Return true if 'props' has the same attributes as this class"""
410    
411            return isinstance(other, ClassGroupProperties)   \
412                and self.stroke      == other.GetLineColor() \
413                and self.strokeWidth == other.GetLineWidth() \
414                and self.fill        == other.GetFill()
415    
416        def __ne__(self, other):
417            return not self.__eq__(other)
418    
419        def __copy__(self):
420            return ClassGroupProperties(self)
421    
422  class ClassGroup:  class ClassGroup:
423      """A base class for all Groups within a Classification"""      """A base class for all Groups within a Classification"""
# Line 421  class ClassGroup: Line 448  class ClassGroup:
448      def Matches(self, value):      def Matches(self, value):
449          """Determines if this Group is associated with the given value.          """Determines if this Group is associated with the given value.
450    
451          Returns True or False. This needs to be implemented by all subclasses.          Returns False. This needs to be overridden by all subclasses.
452          """          """
453          pass          return False
454    
455      def GetProperties(self):      def GetProperties(self):
456          """Return the properties associated with the given value.          """Return the properties associated with the given value.
457    
458          This needs to be implemented by all subclasses.          Returns None. This needs to be overridden by all subclasses.
459          """          """
460          pass          return None
461    
462            
463  class ClassGroupSingleton(ClassGroup):  class ClassGroupSingleton(ClassGroup):
# Line 455  class ClassGroupSingleton(ClassGroup): Line 482  class ClassGroupSingleton(ClassGroup):
482          self.SetProperties(prop)          self.SetProperties(prop)
483    
484      def __copy__(self):      def __copy__(self):
485          return ClassGroupSingleton(self.value, self.prop, self.label)          return ClassGroupSingleton(self.GetValue(),
486                                       self.GetProperties(),
487                                       self.GetLabel())
488    
489        def __deepcopy__(self, memo):
490            return ClassGroupSingleton(copy.copy(self.GetValue()),
491                                       copy.copy(self.GetProperties()),
492                                       copy.copy(self.GetLabel()))
493    
494      def GetValue(self):      def GetValue(self):
495          """Return the associated value."""          """Return the associated value."""
# Line 488  class ClassGroupSingleton(ClassGroup): Line 522  class ClassGroupSingleton(ClassGroup):
522          assert(isinstance(prop, ClassGroupProperties))          assert(isinstance(prop, ClassGroupProperties))
523          self.prop = prop          self.prop = prop
524    
525        def __eq__(self, other):
526            return isinstance(other, ClassGroupSingleton) \
527                and self.GetProperties() == other.GetProperties() \
528                and self.GetValue() == other.GetValue()
529    
530        def __ne__(self, other):
531            return not self.__eq__(other)
532    
533  class ClassGroupDefault(ClassGroupSingleton):  class ClassGroupDefault(ClassGroup):
534      """The default Group. When values do not match any other      """The default Group. When values do not match any other
535         Group within a Classification, the properties from this         Group within a Classification, the properties from this
536         class are used."""         class are used."""
# Line 503  class ClassGroupDefault(ClassGroupSingle Line 544  class ClassGroupDefault(ClassGroupSingle
544          label -- a label for this group.          label -- a label for this group.
545          """          """
546    
547          ClassGroupSingleton.__init__(self, 0, prop, label)          ClassGroup.__init__(self, label)
548            self.SetProperties(prop)
549    
550      def __copy__(self):      def __copy__(self):
551          return ClassGroupDefault(self.prop, self.label)          return ClassGroupDefault(self.GetProperties(), self.GetLabel())
552    
553        def __deepcopy__(self, memo):
554            return ClassGroupDefault(copy.copy(self.GetProperties()),
555                                     copy.copy(self.GetLabel()))
556    
557        def Matches(self, value):
558            return True
559    
560      def GetProperties(self):      def GetProperties(self):
561          """Return the Properties associated with this Group."""          """Return the Properties associated with this Group."""
562          return self.prop          return self.prop
563    
564        def SetProperties(self, prop):
565            """Set the properties associated with this Group.
566    
567            prop -- a ClassGroupProperties object. if prop is None,
568                    a default set of properties is created.
569            """
570    
571            if prop is None: prop = ClassGroupProperties()
572            assert(isinstance(prop, ClassGroupProperties))
573            self.prop = prop
574    
575        def __eq__(self, other):
576            return isinstance(other, ClassGroupDefault) \
577                and self.GetProperties() == other.GetProperties()
578    
579        def __ne__(self, other):
580            return not self.__eq__(other)
581    
582  class ClassGroupRange(ClassGroup):  class ClassGroupRange(ClassGroup):
583      """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
584         set of properties."""         set of properties."""
# Line 540  class ClassGroupRange(ClassGroup): Line 607  class ClassGroupRange(ClassGroup):
607          self.SetProperties(prop)          self.SetProperties(prop)
608    
609      def __copy__(self):      def __copy__(self):
610          return ClassGroupRange(self.min, self.max, self.prop, self.label)          return ClassGroupRange(self.GetMin(),
611                                   self.GetMax(),
612                                   self.GetProperties(),
613                                   self.GetLabel())
614    
615        def __deepcopy__(self, memo):
616            return ClassGroupRange(copy.copy(self.GetMin()),
617                                   copy.copy(self.GetMax()),
618                                   copy.copy(self.GetProperties()),
619                                   copy.copy(self.GetLabel()))
620    
621      def GetMin(self):      def GetMin(self):
622          """Return the range's minimum value."""          """Return the range's minimum value."""
# Line 608  class ClassGroupRange(ClassGroup): Line 684  class ClassGroupRange(ClassGroup):
684          assert(isinstance(prop, ClassGroupProperties))          assert(isinstance(prop, ClassGroupProperties))
685          self.prop = prop          self.prop = prop
686    
687        def __eq__(self, other):
688            return isinstance(other, ClassGroupRange) \
689                and self.GetProperties() == other.GetProperties() \
690                and self.GetRange() == other.GetRange()
691    
692        def __ne__(self, other):
693            return not self.__eq__(other)
694    
695  class ClassGroupMap(ClassGroup):  class ClassGroupMap(ClassGroup):
696      """Currently, this class is not used."""      """Currently, this class is not used."""
697    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26