/[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 643 by jonathan, Thu Apr 10 17:55:57 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 449  class ClassGroupProperties: Line 448  class ClassGroupProperties:
448                    
449      def GetLineColor(self):      def GetLineColor(self):
450          """Return the line color as a Color object."""          """Return the line color as a Color object."""
451          return self.stroke          return self.__stroke
452    
453      def SetLineColor(self, color):      def SetLineColor(self, color):
454          """Set the line color.          """Set the line color.
# 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    
459          assert isinstance(color, Color)          self.__stroke = color
         self.stroke = color  
460    
461      def GetLineWidth(self):      def GetLineWidth(self):
462          """Return the line width."""          """Return the line width."""
463          return self.strokeWidth          return self.__strokeWidth
464    
465      def SetLineWidth(self, lineWidth):      def SetLineWidth(self, lineWidth):
466          """Set the line width.          """Set the line width.
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    
474          self.strokeWidth = lineWidth          self.__strokeWidth = lineWidth
475    
476      def GetFill(self):      def GetFill(self):
477          """Return the fill color as a Color object."""          """Return the fill color as a Color object."""
478          return self.fill          return self.__fill
479    
480      def SetFill(self, fill):      def SetFill(self, fill):
481          """Set the fill color.          """Set the fill color.
# 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    
486          assert isinstance(fill, Color)          self.__fill = fill
         self.fill = fill  
487    
488      def __eq__(self, other):      def __eq__(self, other):
489          """Return true if 'props' has the same attributes as this class"""          """Return true if 'props' has the same attributes as this class"""
490    
491            #
492            # using 'is' over '==' results in a huge performance gain
493            # in the renderer
494            #
495          return isinstance(other, ClassGroupProperties)   \          return isinstance(other, ClassGroupProperties)   \
496              and self.stroke      == other.GetLineColor() \              and (self.__stroke is other.__stroke or      \
497              and self.strokeWidth == other.GetLineWidth() \                   self.__stroke == other.__stroke)        \
498              and self.fill        == other.GetFill()              and (self.__fill is other.__fill or          \
499                     self.__fill == other.__fill)            \
500                and self.__strokeWidth == other.__strokeWidth
501    
502      def __ne__(self, other):      def __ne__(self, other):
503          return not self.__eq__(other)          return not self.__eq__(other)
# Line 505  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 533  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 572  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 605  class ClassGroupSingleton(ClassGroup): Line 614  class ClassGroupSingleton(ClassGroup):
614    
615      def GetValue(self):      def GetValue(self):
616          """Return the associated value."""          """Return the associated value."""
617          return self.value          return self.__value
618    
619      def SetValue(self, value):      def SetValue(self, value):
620          """Associate this Group with the given value."""          """Associate this Group with the given value."""
621          self.value = value          self.__value = value
622    
623      def Matches(self, value):      def Matches(self, value):
624          """Determine if the given value matches the associated Group value."""          """Determine if the given value matches the associated Group value."""
625    
626          """Returns True if the value matches, False otherwise."""          """Returns True if the value matches, False otherwise."""
627    
628          return self.value == value          return self.__value == value
629    
630      def GetDisplayText(self):      def GetDisplayText(self):
631          label = self.GetLabel()          label = self.GetLabel()
# Line 628  class ClassGroupSingleton(ClassGroup): Line 637  class ClassGroupSingleton(ClassGroup):
637      def __eq__(self, other):      def __eq__(self, other):
638          return ClassGroup.__eq__(self, other) \          return ClassGroup.__eq__(self, other) \
639              and isinstance(other, ClassGroupSingleton) \              and isinstance(other, ClassGroupSingleton) \
640              and self.GetValue() == other.GetValue()              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
# Line 667  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 688  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 714  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 726  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 737  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 753  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.GetRange() == other.GetRange()              and self.__range == other.__range
791                #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.643  
changed lines
  Added in v.1176

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26