/[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 613 by jonathan, Mon Apr 7 08:55:55 2003 UTC revision 681 by jonathan, Tue Apr 15 21:54:32 2003 UTC
# Line 73  class Classification: Line 73  class Classification:
73      def __deepcopy__(self, memo):      def __deepcopy__(self, memo):
74          clazz = Classification()          clazz = Classification()
75    
76            # note: the only thing that isn't copied is the layer reference
77            clazz.field = self.field
78            clazz.fieldType = self.fieldType
79          clazz.__groups[0] = copy.deepcopy(self.__groups[0])          clazz.__groups[0] = copy.deepcopy(self.__groups[0])
80    
81          for i in range(1, len(self.__groups)):          for i in range(1, len(self.__groups)):
82              clazz.__groups.append(copy.deepcopy(self.__groups[i]))              clazz.__groups.append(copy.deepcopy(self.__groups[i]))
83    
         print "Classification.__deepcopy__"  
84          return clazz          return clazz
85    
86      def __SendNotification(self):      def __SendNotification(self):
# Line 426  class ClassGroupProperties: Line 428  class ClassGroupProperties:
428                   and fill color = Color.Transparent                   and fill color = Color.Transparent
429          """          """
430    
431          self.stroke = None          #self.stroke = None
432          self.strokeWidth = 0          #self.strokeWidth = 0
433          self.fill = None          #self.fill = None
434    
435          if props is not None:          if props is not None:
436              self.SetProperties(props)              self.SetProperties(props)
# Line 447  class ClassGroupProperties: Line 449  class ClassGroupProperties:
449                    
450      def GetLineColor(self):      def GetLineColor(self):
451          """Return the line color as a Color object."""          """Return the line color as a Color object."""
452          return self.stroke          return self.__stroke
453    
454      def SetLineColor(self, color):      def SetLineColor(self, color):
455          """Set the line color.          """Set the line color.
# Line 456  class ClassGroupProperties: Line 458  class ClassGroupProperties:
458          """          """
459    
460          assert isinstance(color, Color)          assert isinstance(color, Color)
461          self.stroke = color          self.__stroke = color
462    
463      def GetLineWidth(self):      def GetLineWidth(self):
464          """Return the line width."""          """Return the line width."""
465          return self.strokeWidth          return self.__strokeWidth
466    
467      def SetLineWidth(self, lineWidth):      def SetLineWidth(self, lineWidth):
468          """Set the line width.          """Set the line width.
# Line 471  class ClassGroupProperties: Line 473  class ClassGroupProperties:
473          if (lineWidth < 1):          if (lineWidth < 1):
474              raise ValueError(_("lineWidth < 1"))              raise ValueError(_("lineWidth < 1"))
475    
476          self.strokeWidth = lineWidth          self.__strokeWidth = lineWidth
477    
478      def GetFill(self):      def GetFill(self):
479          """Return the fill color as a Color object."""          """Return the fill color as a Color object."""
480          return self.fill          return self.__fill
481    
482      def SetFill(self, fill):      def SetFill(self, fill):
483          """Set the fill color.          """Set the fill color.
# Line 484  class ClassGroupProperties: Line 486  class ClassGroupProperties:
486          """          """
487    
488          assert isinstance(fill, Color)          assert isinstance(fill, Color)
489          self.fill = fill          self.__fill = fill
490    
491      def __eq__(self, other):      def __eq__(self, other):
492          """Return true if 'props' has the same attributes as this class"""          """Return true if 'props' has the same attributes as this class"""
493    
494            #
495            # using 'is' over '==' results in a huge performance gain
496            # in the renderer
497            #
498          return isinstance(other, ClassGroupProperties)   \          return isinstance(other, ClassGroupProperties)   \
499              and self.stroke      == other.GetLineColor() \              and (self.__stroke is other.__stroke or      \
500              and self.strokeWidth == other.GetLineWidth() \                   self.__stroke == other.__stroke)        \
501              and self.fill        == other.GetFill()              and (self.__fill is other.__fill or          \
502                     self.__fill == other.__fill)            \
503                and self.__strokeWidth == other.__strokeWidth
504    
505      def __ne__(self, other):      def __ne__(self, other):
506          return not self.__eq__(other)          return not self.__eq__(other)
# Line 503  class ClassGroupProperties: Line 511  class ClassGroupProperties:
511      def __deepcopy__(self):      def __deepcopy__(self):
512          return ClassGroupProperties(self)          return ClassGroupProperties(self)
513    
514        def __repr__(self):
515            return repr((self.__stroke, self.__strokeWidth, self.__fill))
516    
517  class ClassGroup:  class ClassGroup:
518      """A base class for all Groups within a Classification"""      """A base class for all Groups within a Classification"""
519    
520      def __init__(self, label = ""):      def __init__(self, label = "", props = None, group = None):
521          """Constructor.          """Constructor.
522    
523          label -- A string representing the Group's label          label -- A string representing the Group's label
524          """          """
525    
526          self.label = None          if group is not None:
527                self.SetLabel(copy.copy(group.GetLabel()))
528          self.SetLabel(label)              self.SetProperties(copy.copy(group.GetProperties()))
529                self.SetVisible(group.IsVisible())
530            else:
531                self.SetLabel(label)
532                self.SetProperties(props)
533                self.SetVisible(True)
534    
535      def GetLabel(self):      def GetLabel(self):
536          """Return the Group's label."""          """Return the Group's label."""
# Line 526  class ClassGroup: Line 542  class ClassGroup:
542          label -- a string representing the Group's label. This must          label -- a string representing the Group's label. This must
543                   not be None.                   not be None.
544          """          """
545          assert isinstance(label, StringType)          assert isinstance(label, StringTypes)
546          self.label = label          self.label = label
547    
548      def GetDisplayText(self):      def GetDisplayText(self):
# Line 542  class ClassGroup: Line 558  class ClassGroup:
558          return False          return False
559    
560      def GetProperties(self):      def GetProperties(self):
561          """Return the properties associated with the given value.          """Return the properties associated with the given value."""
562    
563          Returns None. This needs to be overridden by all subclasses.          return self.prop
         """  
         assert False, "GetProperties must be overridden by subclass!"  
         return None  
564    
565        def SetProperties(self, prop):
566            """Set the properties associated with this Group.
567    
568            prop -- a ClassGroupProperties object. if prop is None,
569                    a default set of properties is created.
570            """
571    
572            if prop is None: prop = ClassGroupProperties()
573            assert isinstance(prop, ClassGroupProperties)
574            self.prop = prop
575    
576        def IsVisible(self):
577            return self.visible
578    
579        def SetVisible(self, visible):
580            self.visible = visible
581    
582        def __eq__(self, other):
583            return isinstance(other, ClassGroup) \
584                and self.label == other.label \
585                and self.GetProperties() == other.GetProperties()
586    
587        def __ne__(self, other):
588            return not self.__eq__(other)
589    
590        def __repr__(self):
591            return "'" + self.label + "', " + repr(self.GetProperties())
592            
593  class ClassGroupSingleton(ClassGroup):  class ClassGroupSingleton(ClassGroup):
594      """A Group that is associated with a single value."""      """A Group that is associated with a single value."""
595    
596      def __init__(self, value = 0, prop = None, label = ""):      def __init__(self, value = 0, props = None, label = "", group = None):
597          """Constructor.          """Constructor.
598    
599          value -- the associated value.          value -- the associated value.
# Line 563  class ClassGroupSingleton(ClassGroup): Line 603  class ClassGroupSingleton(ClassGroup):
603    
604          label -- a label for this group.          label -- a label for this group.
605          """          """
606          ClassGroup.__init__(self, label)          ClassGroup.__init__(self, label, props, group)
   
         self.prop = None  
         self.value = None  
607    
608          self.SetValue(value)          self.SetValue(value)
         self.SetProperties(prop)  
609    
610      def __copy__(self):      def __copy__(self):
611          return ClassGroupSingleton(self.GetValue(),          return ClassGroupSingleton(self.GetValue(),
# Line 577  class ClassGroupSingleton(ClassGroup): Line 613  class ClassGroupSingleton(ClassGroup):
613                                     self.GetLabel())                                     self.GetLabel())
614    
615      def __deepcopy__(self, memo):      def __deepcopy__(self, memo):
616          return ClassGroupSingleton(copy.copy(self.GetValue()),          return ClassGroupSingleton(self.GetValue(), group = self)
                                    copy.copy(self.GetProperties()),  
                                    copy.copy(self.GetLabel()))  
617    
618      def GetValue(self):      def GetValue(self):
619          """Return the associated value."""          """Return the associated value."""
620          return self.value          return self.__value
621    
622      def SetValue(self, value):      def SetValue(self, value):
623          """Associate this Group with the given value."""          """Associate this Group with the given value."""
624          self.value = value          self.__value = value
625    
626      def Matches(self, value):      def Matches(self, value):
627          """Determine if the given value matches the associated Group value."""          """Determine if the given value matches the associated Group value."""
628    
629          """Returns True if the value matches, False otherwise."""          """Returns True if the value matches, False otherwise."""
630    
631          return self.value == value          return self.__value == value
   
     def GetProperties(self):  
         """Return the Properties associated with this Group."""  
   
         return self.prop  
   
     def SetProperties(self, prop):  
         """Set the properties associated with this Group.  
   
         prop -- a ClassGroupProperties object. if prop is None,  
                 a default set of properties is created.  
         """  
   
         if prop is None: prop = ClassGroupProperties()  
         assert isinstance(prop, ClassGroupProperties)  
         self.prop = prop  
632    
633      def GetDisplayText(self):      def GetDisplayText(self):
634          label = self.GetLabel()          label = self.GetLabel()
# Line 620  class ClassGroupSingleton(ClassGroup): Line 638  class ClassGroupSingleton(ClassGroup):
638          return str(self.GetValue())          return str(self.GetValue())
639    
640      def __eq__(self, other):      def __eq__(self, other):
641          return isinstance(other, ClassGroupSingleton) \          return ClassGroup.__eq__(self, other) \
642              and self.GetProperties() == other.GetProperties() \              and isinstance(other, ClassGroupSingleton) \
643              and self.GetValue() == other.GetValue()              and self.__value == other.__value
644    
645      def __ne__(self, other):      def __repr__(self):
646          return not self.__eq__(other)          return "(" + self.__value + ", " + ClassGroup.__repr__(self) + ")"
647    
648  class ClassGroupDefault(ClassGroup):  class ClassGroupDefault(ClassGroup):
649      """The default Group. When values do not match any other      """The default Group. When values do not match any other
650         Group within a Classification, the properties from this         Group within a Classification, the properties from this
651         class are used."""         class are used."""
652    
653      def __init__(self, prop = None, label = ""):      def __init__(self, props = None, label = "", group = None):
654          """Constructor.          """Constructor.
655    
656          prop -- a ClassGroupProperites object. If prop is None a default          prop -- a ClassGroupProperites object. If prop is None a default
# Line 641  class ClassGroupDefault(ClassGroup): Line 659  class ClassGroupDefault(ClassGroup):
659          label -- a label for this group.          label -- a label for this group.
660          """          """
661    
662          ClassGroup.__init__(self, label)          ClassGroup.__init__(self, label, props, group)
         self.SetProperties(prop)  
663    
664      def __copy__(self):      def __copy__(self):
665          return ClassGroupDefault(self.GetProperties(), self.GetLabel())          return ClassGroupDefault(self.GetProperties(), self.GetLabel())
666    
667      def __deepcopy__(self, memo):      def __deepcopy__(self, memo):
668          return ClassGroupDefault(copy.copy(self.GetProperties()),          return ClassGroupDefault(label = self.GetLabel(), group = self)
                                  copy.copy(self.GetLabel()))  
669    
670      def Matches(self, value):      def Matches(self, value):
671          return True          return True
672    
     def GetProperties(self):  
         """Return the Properties associated with this Group."""  
         return self.prop  
   
     def SetProperties(self, prop):  
         """Set the properties associated with this Group.  
   
         prop -- a ClassGroupProperties object. if prop is None,  
                 a default set of properties is created.  
         """  
   
         if prop is None: prop = ClassGroupProperties()  
         assert isinstance(prop, ClassGroupProperties)  
         self.prop = prop  
   
673      def GetDisplayText(self):      def GetDisplayText(self):
674          label = self.GetLabel()          label = self.GetLabel()
675    
# Line 677  class ClassGroupDefault(ClassGroup): Line 678  class ClassGroupDefault(ClassGroup):
678          return _("DEFAULT")          return _("DEFAULT")
679    
680      def __eq__(self, other):      def __eq__(self, other):
681          return isinstance(other, ClassGroupDefault) \          return ClassGroup.__eq__(self, other) \
682                and isinstance(other, ClassGroupDefault) \
683              and self.GetProperties() == other.GetProperties()              and self.GetProperties() == other.GetProperties()
684    
685      def __ne__(self, other):      def __repr__(self):
686          return not self.__eq__(other)          return "(" + ClassGroup.__repr__(self) + ")"
687    
688  class ClassGroupRange(ClassGroup):  class ClassGroupRange(ClassGroup):
689      """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
690         set of properties."""         set of properties."""
691    
692      def __init__(self, min = 0, max = 1, prop = None, label = ""):      def __init__(self, min = 0, max = 1, props = None, label = "", group=None):
693          """Constructor.          """Constructor.
694    
695          The minumum value must be strictly less than the maximum.          The minumum value must be strictly less than the maximum.
# Line 702  class ClassGroupRange(ClassGroup): Line 704  class ClassGroupRange(ClassGroup):
704          label -- a label for this group.          label -- a label for this group.
705          """          """
706    
707          ClassGroup.__init__(self, label)          ClassGroup.__init__(self, label, props, group)
708    
709          self.min = self.max = 0          self.__min = self.__max = 0
         self.prop = None  
710    
711          self.SetRange(min, max)          self.SetRange(min, max)
         self.SetProperties(prop)  
712    
713      def __copy__(self):      def __copy__(self):
714          return ClassGroupRange(self.GetMin(),          return ClassGroupRange(self.GetMin(),
# Line 719  class ClassGroupRange(ClassGroup): Line 719  class ClassGroupRange(ClassGroup):
719      def __deepcopy__(self, memo):      def __deepcopy__(self, memo):
720          return ClassGroupRange(copy.copy(self.GetMin()),          return ClassGroupRange(copy.copy(self.GetMin()),
721                                 copy.copy(self.GetMax()),                                 copy.copy(self.GetMax()),
722                                 copy.copy(self.GetProperties()),                                 group = self)
                                copy.copy(self.GetLabel()))  
723    
724      def GetMin(self):      def GetMin(self):
725          """Return the range's minimum value."""          """Return the range's minimum value."""
726          return self.min          return self.__min
727    
728      def SetMin(self, min):      def SetMin(self, min):
729          """Set the range's minimum value.          """Set the range's minimum value.
# Line 733  class ClassGroupRange(ClassGroup): Line 732  class ClassGroupRange(ClassGroup):
732                 maximum value. Use SetRange() to change both min and max values.                 maximum value. Use SetRange() to change both min and max values.
733          """          """
734            
735          self.SetRange(min, self.max)          self.SetRange(min, self.__max)
736    
737      def GetMax(self):      def GetMax(self):
738          """Return the range's maximum value."""          """Return the range's maximum value."""
739          return self.max          return self.__max
740    
741      def SetMax(self, max):      def SetMax(self, max):
742          """Set the range's maximum value.          """Set the range's maximum value.
# Line 745  class ClassGroupRange(ClassGroup): Line 744  class ClassGroupRange(ClassGroup):
744          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
745                 minimum value. Use SetRange() to change both min and max values.                 minimum value. Use SetRange() to change both min and max values.
746          """          """
747          self.SetRange(self.min, max)          self.SetRange(self.__min, max)
748    
749      def SetRange(self, min, max):      def SetRange(self, min, max):
750          """Set a new range.          """Set a new range.
# Line 759  class ClassGroupRange(ClassGroup): Line 758  class ClassGroupRange(ClassGroup):
758          if min >= max:          if min >= max:
759              raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") %              raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") %
760                               (min, max))                               (min, max))
761          self.min = min          self.__min = min
762          self.max = max          self.__max = max
763    
764      def GetRange(self):      def GetRange(self):
765          """Return the range as a tuple (min, max)"""          """Return the range as a tuple (min, max)"""
766          return (self.min, self.max)          return (self.__min, self.__max)
767    
768      def Matches(self, value):      def Matches(self, value):
769          """Determine if the given value lies with the current range.          """Determine if the given value lies with the current range.
# Line 772  class ClassGroupRange(ClassGroup): Line 771  class ClassGroupRange(ClassGroup):
771          The following check is used: min <= value < max.          The following check is used: min <= value < max.
772          """          """
773    
774          return self.min <= value < self.max          return self.__min <= value < self.__max
   
     def GetProperties(self):  
         """Return the Properties associated with this Group."""  
         return self.prop  
   
     def SetProperties(self, prop):  
         """Set the properties associated with this Group.  
   
         prop -- a ClassGroupProperties object. if prop is None,  
                 a default set of properties is created.  
         """  
         if prop is None: prop = ClassGroupProperties()  
         assert isinstance(prop, ClassGroupProperties)  
         self.prop = prop  
775    
776      def GetDisplayText(self):      def GetDisplayText(self):
777          label = self.GetLabel()          label = self.GetLabel()
# Line 796  class ClassGroupRange(ClassGroup): Line 781  class ClassGroupRange(ClassGroup):
781          return _("%s - %s") % (self.GetMin(), self.GetMax())          return _("%s - %s") % (self.GetMin(), self.GetMax())
782    
783      def __eq__(self, other):      def __eq__(self, other):
784          return isinstance(other, ClassGroupRange) \          return ClassGroup.__eq__(self, other) \
785              and self.GetProperties() == other.GetProperties() \              and isinstance(other, ClassGroupRange) \
786              and self.GetRange() == other.GetRange()              and self.__min == other.__min \
787                and self.__max == other.__max
788      def __ne__(self, other):  
789          return not self.__eq__(other)      def __repr__(self):
790            return "(" + str(self.__min) + ", " + str(self.__max) + ", " + \
791                   ClassGroup.__repr__(self) + ")"
792    
793  class ClassGroupMap(ClassGroup):  class ClassGroupMap(ClassGroup):
794      """Currently, this class is not used."""      """Currently, this class is not used."""

Legend:
Removed from v.613  
changed lines
  Added in v.681

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26