/[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 678 by jonathan, Tue Apr 15 19:21:26 2003 UTC revision 1176 by jonathan, Thu Jun 12 15:46:22 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  import copy, operator
27    
28  from Thuban import _  from Thuban import _
29    
30  from types import *  import types
31    
32  from messages import \  from messages import \
33      LAYER_PROJECTION_CHANGED, \      LAYER_PROJECTION_CHANGED, \
# Line 35  from messages import \ Line 35  from messages import \
35      LAYER_VISIBILITY_CHANGED      LAYER_VISIBILITY_CHANGED
36    
37  from Thuban.Model.color import Color  from Thuban.Model.color import Color
38    from Thuban.Model.range import Range
39    
40  import Thuban.Model.layer  import Thuban.Model.layer
41    
# Line 196  class Classification: Line 197  class Classification:
197    
198          fill -- a Color object.          fill -- a Color object.
199          """          """
         assert isinstance(fill, Color)  
200          self.GetDefaultGroup().GetProperties().SetFill(fill)          self.GetDefaultGroup().GetProperties().SetFill(fill)
201          self.__SendNotification()          self.__SendNotification()
202                    
# Line 209  class Classification: Line 209  class Classification:
209    
210          color -- a Color object.          color -- a Color object.
211          """          """
         assert isinstance(color, Color)  
212          self.GetDefaultGroup().GetProperties().SetLineColor(color)          self.GetDefaultGroup().GetProperties().SetLineColor(color)
213          self.__SendNotification()          self.__SendNotification()
214                    
# Line 222  class Classification: Line 221  class Classification:
221    
222          lineWidth -- an integer > 0.          lineWidth -- an integer > 0.
223          """          """
224          assert isinstance(lineWidth, IntType)          assert isinstance(lineWidth, types.IntType)
225          self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)          self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)
226          self.__SendNotification()          self.__SendNotification()
227                    
# Line 457  class ClassGroupProperties: Line 456  class ClassGroupProperties:
456          color -- the color of the line. This must be a Color object.          color -- the color of the line. This must be a Color object.
457          """          """
458    
         assert isinstance(color, Color)  
459          self.__stroke = color          self.__stroke = color
460    
461      def GetLineWidth(self):      def GetLineWidth(self):
# Line 469  class ClassGroupProperties: Line 467  class ClassGroupProperties:
467    
468          lineWidth -- the new line width. This must be > 0.          lineWidth -- the new line width. This must be > 0.
469          """          """
470          assert isinstance(lineWidth, IntType)          assert isinstance(lineWidth, types.IntType)
471          if (lineWidth < 1):          if (lineWidth < 1):
472              raise ValueError(_("lineWidth < 1"))              raise ValueError(_("lineWidth < 1"))
473    
# Line 485  class ClassGroupProperties: Line 483  class ClassGroupProperties:
483          fill -- the color of the fill. This must be a Color object.          fill -- the color of the fill. This must be a Color object.
484          """          """
485    
         assert isinstance(fill, Color)  
486          self.__fill = fill          self.__fill = fill
487    
488      def __eq__(self, other):      def __eq__(self, other):
# Line 511  class ClassGroupProperties: Line 508  class ClassGroupProperties:
508      def __deepcopy__(self):      def __deepcopy__(self):
509          return ClassGroupProperties(self)          return ClassGroupProperties(self)
510    
511        def __repr__(self):
512            return repr((self.__stroke, self.__strokeWidth, self.__fill))
513    
514  class ClassGroup:  class ClassGroup:
515      """A base class for all Groups within a Classification"""      """A base class for all Groups within a Classification"""
516    
# Line 539  class ClassGroup: Line 539  class ClassGroup:
539          label -- a string representing the Group's label. This must          label -- a string representing the Group's label. This must
540                   not be None.                   not be None.
541          """          """
542          assert isinstance(label, StringType)          assert isinstance(label, types.StringTypes)
543          self.label = label          self.label = label
544    
545      def GetDisplayText(self):      def GetDisplayText(self):
# Line 578  class ClassGroup: Line 578  class ClassGroup:
578    
579      def __eq__(self, other):      def __eq__(self, other):
580          return isinstance(other, ClassGroup) \          return isinstance(other, ClassGroup) \
581                and self.label == other.label \
582              and self.GetProperties() == other.GetProperties()              and self.GetProperties() == other.GetProperties()
583    
584      def __ne__(self, other):      def __ne__(self, other):
585          return not self.__eq__(other)          return not self.__eq__(other)
586    
587        def __repr__(self):
588            return repr(self.label) + ", " + repr(self.GetProperties())
589            
590  class ClassGroupSingleton(ClassGroup):  class ClassGroupSingleton(ClassGroup):
591      """A Group that is associated with a single value."""      """A Group that is associated with a single value."""
# Line 636  class ClassGroupSingleton(ClassGroup): Line 639  class ClassGroupSingleton(ClassGroup):
639              and isinstance(other, ClassGroupSingleton) \              and isinstance(other, ClassGroupSingleton) \
640              and self.__value == other.__value              and self.__value == other.__value
641    
642        def __repr__(self):
643            return "(" + repr(self.__value) + ", " + ClassGroup.__repr__(self) + ")"
644    
645  class ClassGroupDefault(ClassGroup):  class ClassGroupDefault(ClassGroup):
646      """The default Group. When values do not match any other      """The default Group. When values do not match any other
647         Group within a Classification, the properties from this         Group within a Classification, the properties from this
# Line 673  class ClassGroupDefault(ClassGroup): Line 679  class ClassGroupDefault(ClassGroup):
679              and isinstance(other, ClassGroupDefault) \              and isinstance(other, ClassGroupDefault) \
680              and self.GetProperties() == other.GetProperties()              and self.GetProperties() == other.GetProperties()
681    
682        def __repr__(self):
683            return "(" + ClassGroup.__repr__(self) + ")"
684    
685  class ClassGroupRange(ClassGroup):  class ClassGroupRange(ClassGroup):
686      """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
687         set of properties."""         set of properties."""
# Line 694  class ClassGroupRange(ClassGroup): Line 703  class ClassGroupRange(ClassGroup):
703    
704          ClassGroup.__init__(self, label, props, group)          ClassGroup.__init__(self, label, props, group)
705    
706          self.__min = self.__max = 0          #self.__min = self.__max = 0
707            #self.__range = Range("[" + repr(float(min)) + ";" +
708                                       #repr(float(max)) + "[")
709          self.SetRange(min, max)          self.SetRange(min, max)
710    
711      def __copy__(self):      def __copy__(self):
712          return ClassGroupRange(self.GetMin(),          return ClassGroupRange(min = self.__range,
713                                 self.GetMax(),                                 max = None,
714                                 self.GetProperties(),                                 props = self.GetProperties(),
715                                 self.GetLabel())                                 label = self.GetLabel())
716    
717      def __deepcopy__(self, memo):      def __deepcopy__(self, memo):
718          return ClassGroupRange(copy.copy(self.GetMin()),          return ClassGroupRange(min = copy.copy(self.__range),
719                                 copy.copy(self.GetMax()),                                 max = copy.copy(self.GetMax()),
720                                 group = self)                                 group = self)
721    
722      def GetMin(self):      def GetMin(self):
723          """Return the range's minimum value."""          """Return the range's minimum value."""
724          return self.__min          return self.__range.GetRange()[1]
725    
726      def SetMin(self, min):      def SetMin(self, min):
727          """Set the range's minimum value.          """Set the range's minimum value.
# Line 720  class ClassGroupRange(ClassGroup): Line 730  class ClassGroupRange(ClassGroup):
730                 maximum value. Use SetRange() to change both min and max values.                 maximum value. Use SetRange() to change both min and max values.
731          """          """
732            
733          self.SetRange(min, self.__max)          self.SetRange(min, self.__range.GetRange()[2])
734    
735      def GetMax(self):      def GetMax(self):
736          """Return the range's maximum value."""          """Return the range's maximum value."""
737          return self.max          return self.__range.GetRange()[2]
738    
739      def SetMax(self, max):      def SetMax(self, max):
740          """Set the range's maximum value.          """Set the range's maximum value.
# Line 732  class ClassGroupRange(ClassGroup): Line 742  class ClassGroupRange(ClassGroup):
742          max -- the new maximum. Note that this must be greater than the current          max -- the new maximum. Note that this must be greater than the current
743                 minimum value. Use SetRange() to change both min and max values.                 minimum value. Use SetRange() to change both min and max values.
744          """          """
745          self.SetRange(self.__min, max)          self.SetRange(self.__range.GetRange()[1], max)
746    
747      def SetRange(self, min, max):      def SetRange(self, min, max = None):
748          """Set a new range.          """Set a new range.
749    
750          Note that min must be strictly less than max.          Note that min must be strictly less than max.
# Line 743  class ClassGroupRange(ClassGroup): Line 753  class ClassGroupRange(ClassGroup):
753          min -- the new maximum value          min -- the new maximum value
754          """          """
755    
756          if min >= max:          if isinstance(min, Range):
757              raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") %              self.__range = min
758                               (min, max))          else:
759          self.__min = min              if max is None:
760          self.__max = max                  raise ValueError()
761    
762                self.__range = Range(("[", min, max, "["))
763    
764      def GetRange(self):      def GetRange(self):
765          """Return the range as a tuple (min, max)"""          """Return the range as a string"""
766          return (self.__min, self.__max)          #return (self.__min, self.__max)
767            return self.__range.string(self.__range.GetRange())
768    
769      def Matches(self, value):      def Matches(self, value):
770          """Determine if the given value lies with the current range.          """Determine if the given value lies with the current range.
# Line 759  class ClassGroupRange(ClassGroup): Line 772  class ClassGroupRange(ClassGroup):
772          The following check is used: min <= value < max.          The following check is used: min <= value < max.
773          """          """
774    
775          return self.__min <= value < self.__max          return operator.contains(self.__range, value)
776            #return self.__min <= value < self.__max
777    
778      def GetDisplayText(self):      def GetDisplayText(self):
779          label = self.GetLabel()          label = self.GetLabel()
780    
781          if label != "": return label          if label != "": return label
782    
783          return _("%s - %s") % (self.GetMin(), self.GetMax())          #return _("%s - %s") % (self.GetMin(), self.GetMax())
784            #return repr(self.__range)
785            return self.__range.string(self.__range.GetRange())
786    
787      def __eq__(self, other):      def __eq__(self, other):
788          return ClassGroup.__eq__(self, other) \          return ClassGroup.__eq__(self, other) \
789              and isinstance(other, ClassGroupRange) \              and isinstance(other, ClassGroupRange) \
790              and self.__min == other.__min \              and self.__range == other.__range
791              and self.__max == other.__max              #and self.__min == other.__min \
792                #and self.__max == other.__max
793    
794        def __repr__(self):
795            return "(" + str(self.__range) + ClassGroup.__repr__(self) + ")"
796            #return "(" + repr(self.__min) + ", " + repr(self.__max) + ", " + \
797                   #ClassGroup.__repr__(self) + ")"
798    
799  class ClassGroupMap(ClassGroup):  class ClassGroupMap(ClassGroup):
800      """Currently, this class is not used."""      """Currently, this class is not used."""

Legend:
Removed from v.678  
changed lines
  Added in v.1176

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26