/[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 689 by jonathan, Wed Apr 16 13:47:07 2003 UTC revision 1249 by jonathan, Fri Jun 20 09:27:19 2003 UTC
# Line 20  See the description of FindGroup() for m Line 20  See the description of FindGroup() for m
20  on the mapping algorithm.  on the mapping algorithm.
21  """  """
22        
23  # fix for people using python2.1  import copy, operator, types
 from __future__ import nested_scopes  
   
 import copy  
24    
25  from Thuban import _  from Thuban import _
26    
 from types import *  
   
27  from messages import \  from messages import \
28      LAYER_PROJECTION_CHANGED, \      LAYER_PROJECTION_CHANGED, \
29      LAYER_LEGEND_CHANGED, \      LAYER_LEGEND_CHANGED, \
30      LAYER_VISIBILITY_CHANGED      LAYER_VISIBILITY_CHANGED
31    
32  from Thuban.Model.color import Color  from Thuban.Model.color import Color
33    from Thuban.Model.range import Range
34    
35  import Thuban.Model.layer  import Thuban.Model.layer
36    
# Line 196  class Classification: Line 192  class Classification:
192    
193          fill -- a Color object.          fill -- a Color object.
194          """          """
         assert isinstance(fill, Color)  
195          self.GetDefaultGroup().GetProperties().SetFill(fill)          self.GetDefaultGroup().GetProperties().SetFill(fill)
196          self.__SendNotification()          self.__SendNotification()
197                    
# Line 209  class Classification: Line 204  class Classification:
204    
205          color -- a Color object.          color -- a Color object.
206          """          """
         assert isinstance(color, Color)  
207          self.GetDefaultGroup().GetProperties().SetLineColor(color)          self.GetDefaultGroup().GetProperties().SetLineColor(color)
208          self.__SendNotification()          self.__SendNotification()
209                    
# Line 222  class Classification: Line 216  class Classification:
216    
217          lineWidth -- an integer > 0.          lineWidth -- an integer > 0.
218          """          """
219          assert isinstance(lineWidth, IntType)          assert isinstance(lineWidth, types.IntType)
220          self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)          self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)
221          self.__SendNotification()          self.__SendNotification()
222                    
# Line 457  class ClassGroupProperties: Line 451  class ClassGroupProperties:
451          color -- the color of the line. This must be a Color object.          color -- the color of the line. This must be a Color object.
452          """          """
453    
         assert isinstance(color, Color)  
454          self.__stroke = color          self.__stroke = color
455    
456      def GetLineWidth(self):      def GetLineWidth(self):
# Line 469  class ClassGroupProperties: Line 462  class ClassGroupProperties:
462    
463          lineWidth -- the new line width. This must be > 0.          lineWidth -- the new line width. This must be > 0.
464          """          """
465          assert isinstance(lineWidth, IntType)          assert isinstance(lineWidth, types.IntType)
466          if (lineWidth < 1):          if (lineWidth < 1):
467              raise ValueError(_("lineWidth < 1"))              raise ValueError(_("lineWidth < 1"))
468    
# Line 485  class ClassGroupProperties: Line 478  class ClassGroupProperties:
478          fill -- the color of the fill. This must be a Color object.          fill -- the color of the fill. This must be a Color object.
479          """          """
480    
         assert isinstance(fill, Color)  
481          self.__fill = fill          self.__fill = fill
482    
483      def __eq__(self, other):      def __eq__(self, other):
# Line 542  class ClassGroup: Line 534  class ClassGroup:
534          label -- a string representing the Group's label. This must          label -- a string representing the Group's label. This must
535                   not be None.                   not be None.
536          """          """
537          assert isinstance(label, StringTypes)          assert isinstance(label, types.StringTypes)
538          self.label = label          self.label = label
539    
540      def GetDisplayText(self):      def GetDisplayText(self):
# Line 706  class ClassGroupRange(ClassGroup): Line 698  class ClassGroupRange(ClassGroup):
698    
699          ClassGroup.__init__(self, label, props, group)          ClassGroup.__init__(self, label, props, group)
700    
701          self.__min = self.__max = 0          #self.__min = self.__max = 0
702            #self.__range = Range("[" + repr(float(min)) + ";" +
703                                       #repr(float(max)) + "[")
704          self.SetRange(min, max)          self.SetRange(min, max)
705    
706      def __copy__(self):      def __copy__(self):
707          return ClassGroupRange(self.GetMin(),          return ClassGroupRange(min = self.__range,
708                                 self.GetMax(),                                 max = None,
709                                 self.GetProperties(),                                 props = self.GetProperties(),
710                                 self.GetLabel())                                 label = self.GetLabel())
711    
712      def __deepcopy__(self, memo):      def __deepcopy__(self, memo):
713          return ClassGroupRange(copy.copy(self.GetMin()),          return ClassGroupRange(min = copy.copy(self.__range),
714                                 copy.copy(self.GetMax()),                                 max = copy.copy(self.GetMax()),
715                                 group = self)                                 group = self)
716    
717      def GetMin(self):      def GetMin(self):
718          """Return the range's minimum value."""          """Return the range's minimum value."""
719          return self.__min          return self.__range.GetRange()[1]
720    
721      def SetMin(self, min):      def SetMin(self, min):
722          """Set the range's minimum value.          """Set the range's minimum value.
# Line 732  class ClassGroupRange(ClassGroup): Line 725  class ClassGroupRange(ClassGroup):
725                 maximum value. Use SetRange() to change both min and max values.                 maximum value. Use SetRange() to change both min and max values.
726          """          """
727            
728          self.SetRange(min, self.__max)          self.SetRange(min, self.__range.GetRange()[2])
729    
730      def GetMax(self):      def GetMax(self):
731          """Return the range's maximum value."""          """Return the range's maximum value."""
732          return self.__max          return self.__range.GetRange()[2]
733    
734      def SetMax(self, max):      def SetMax(self, max):
735          """Set the range's maximum value.          """Set the range's maximum value.
# Line 744  class ClassGroupRange(ClassGroup): Line 737  class ClassGroupRange(ClassGroup):
737          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
738                 minimum value. Use SetRange() to change both min and max values.                 minimum value. Use SetRange() to change both min and max values.
739          """          """
740          self.SetRange(self.__min, max)          self.SetRange(self.__range.GetRange()[1], max)
741    
742      def SetRange(self, min, max):      def SetRange(self, min, max = None):
743          """Set a new range.          """Set a new range.
744    
745          Note that min must be strictly less than max.          Note that min must be strictly less than max.
# Line 755  class ClassGroupRange(ClassGroup): Line 748  class ClassGroupRange(ClassGroup):
748          min -- the new maximum value          min -- the new maximum value
749          """          """
750    
751          if min >= max:          if isinstance(min, Range):
752              raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") %              self.__range = min
753                               (min, max))          else:
754          self.__min = min              if max is None:
755          self.__max = max                  raise ValueError()
756    
757                self.__range = Range(("[", min, max, "["))
758    
759      def GetRange(self):      def GetRange(self):
760          """Return the range as a tuple (min, max)"""          """Return the range as a string"""
761          return (self.__min, self.__max)          #return (self.__min, self.__max)
762            return self.__range.string(self.__range.GetRange())
763    
764      def Matches(self, value):      def Matches(self, value):
765          """Determine if the given value lies with the current range.          """Determine if the given value lies with the current range.
# Line 771  class ClassGroupRange(ClassGroup): Line 767  class ClassGroupRange(ClassGroup):
767          The following check is used: min <= value < max.          The following check is used: min <= value < max.
768          """          """
769    
770          return self.__min <= value < self.__max          return operator.contains(self.__range, value)
771            #return self.__min <= value < self.__max
772    
773      def GetDisplayText(self):      def GetDisplayText(self):
774          label = self.GetLabel()          label = self.GetLabel()
775    
776          if label != "": return label          if label != "": return label
777    
778          return _("%s - %s") % (self.GetMin(), self.GetMax())          #return _("%s - %s") % (self.GetMin(), self.GetMax())
779            #return repr(self.__range)
780            return self.__range.string(self.__range.GetRange())
781    
782      def __eq__(self, other):      def __eq__(self, other):
783          return ClassGroup.__eq__(self, other) \          return ClassGroup.__eq__(self, other) \
784              and isinstance(other, ClassGroupRange) \              and isinstance(other, ClassGroupRange) \
785              and self.__min == other.__min \              and self.__range == other.__range
786              and self.__max == other.__max              #and self.__min == other.__min \
787                #and self.__max == other.__max
788    
789      def __repr__(self):      def __repr__(self):
790          return "(" + repr(self.__min) + ", " + repr(self.__max) + ", " + \          return "(" + str(self.__range) + ClassGroup.__repr__(self) + ")"
791                 ClassGroup.__repr__(self) + ")"          #return "(" + repr(self.__min) + ", " + repr(self.__max) + ", " + \
792                   #ClassGroup.__repr__(self) + ")"
793    
794  class ClassGroupMap(ClassGroup):  class ClassGroupMap(ClassGroup):
795      """Currently, this class is not used."""      """Currently, this class is not used."""

Legend:
Removed from v.689  
changed lines
  Added in v.1249

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26