/[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 491 by jonathan, Mon Mar 10 10:44:42 2003 UTC revision 609 by jonathan, Fri Apr 4 13:55:59 2003 UTC
# Line 60  class Classification: Line 60  class Classification:
60          self.fieldType = None          self.fieldType = None
61          self.groups = []          self.groups = []
62    
63            self.__setLayerLock = False
64    
65          self.SetDefaultGroup(ClassGroupDefault())          self.SetDefaultGroup(ClassGroupDefault())
66    
67          self.SetLayer(layer)          self.SetLayer(layer)
# Line 137  class Classification: Line 139  class Classification:
139             field type mismatch the information in the layer's table.             field type mismatch the information in the layer's table.
140          """          """
141    
142            # prevent infinite recursion when calling SetClassification()
143            if self.__setLayerLock: return
144    
145            self.__setLayerLock = True
146    
147          if layer is None:          if layer is None:
148              if self.layer is not None:              if self.layer is not None:
149                  l = self.layer                  l = self.layer
150                  self.layer = None                  self.layer = None
151                  l.SetClassification(None)                  l.SetClassification(None)
152          else:          else:
153              assert(isinstance(layer, Thuban.Model.layer.Layer))              assert isinstance(layer, Thuban.Model.layer.Layer)
154    
             # prevent infinite recursion when calling SetClassification()  
             if layer == self.layer:  
                 return  
               
155              old_layer = self.layer              old_layer = self.layer
156    
157              self.layer = layer              self.layer = layer
# Line 157  class Classification: Line 160  class Classification:
160                  self.SetField(self.GetField()) # this sync's the fieldType                  self.SetField(self.GetField()) # this sync's the fieldType
161              except ValueError:              except ValueError:
162                  self.layer = old_layer                  self.layer = old_layer
163                    self.__setLayerLock = False
164                  raise ValueError                  raise ValueError
165              else:              else:
166                  self.layer.SetClassification(self)                  self.layer.SetClassification(self)
167    
168            self.__setLayerLock = False
169    
170      def GetLayer(self):      def GetLayer(self):
171          """Return the parent layer."""          """Return the parent layer."""
172          return self.layer          return self.layer
# Line 171  class Classification: Line 177  class Classification:
177             group -- group that the value maps to.             group -- group that the value maps to.
178          """          """
179    
180          assert(isinstance(group, ClassGroupDefault))          assert isinstance(group, ClassGroupDefault)
181          self.AddGroup(group)          self.AddGroup(group)
182    
183      def GetDefaultGroup(self):      def GetDefaultGroup(self):
# Line 189  class Classification: Line 195  class Classification:
195    
196          fill -- a Color object.          fill -- a Color object.
197          """          """
198          assert(isinstance(fill, Color))          assert isinstance(fill, Color)
199          self.GetDefaultGroup().GetProperties().SetFill(fill)          self.GetDefaultGroup().GetProperties().SetFill(fill)
200          self.__SendNotification()          self.__SendNotification()
201                    
# Line 202  class Classification: Line 208  class Classification:
208    
209          color -- a Color object.          color -- a Color object.
210          """          """
211          assert(isinstance(color, Color))          assert isinstance(color, Color)
212          self.GetDefaultGroup().GetProperties().SetLineColor(color)          self.GetDefaultGroup().GetProperties().SetLineColor(color)
213          self.__SendNotification()          self.__SendNotification()
214                    
# Line 215  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, IntType)
225          self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)          self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)
226          self.__SendNotification()          self.__SendNotification()
227                    
# Line 229  class Classification: Line 235  class Classification:
235          item -- this must be a valid ClassGroup object          item -- this must be a valid ClassGroup object
236          """          """
237    
238          assert(isinstance(item, ClassGroup))          assert isinstance(item, ClassGroup)
239    
240          if len(self.groups) > 0 and isinstance(item, ClassGroupDefault):          if len(self.groups) > 0 and isinstance(item, ClassGroupDefault):
241              self.groups[0] = item              self.groups[0] = item
# Line 271  class Classification: Line 277  class Classification:
277          items = []          items = []
278    
279          def build_color_item(text, color):          def build_color_item(text, color):
280              if color is Color.None:              if color is Color.Transparent:
281                  return ("%s: %s" % (text, _("None")), None)                  return ("%s: %s" % (text, _("None")), None)
282    
283              return ("%s: (%.3f, %.3f, %.3f)" %              return ("%s: (%.3f, %.3f, %.3f)" %
# Line 367  class ClassGroupProperties: Line 373  class ClassGroupProperties:
373          props -- a ClassGroupProperties object. The class is copied if          props -- a ClassGroupProperties object. The class is copied if
374                   prop is not None. Otherwise, a default set of properties                   prop is not None. Otherwise, a default set of properties
375                   is created such that: line color = Color.Black, line width = 1,                   is created such that: line color = Color.Black, line width = 1,
376                   and fill color = Color.None                   and fill color = Color.Transparent
377          """          """
378    
379          self.stroke = None          self.stroke = None
# Line 379  class ClassGroupProperties: Line 385  class ClassGroupProperties:
385          else:          else:
386              self.SetLineColor(Color.Black)              self.SetLineColor(Color.Black)
387              self.SetLineWidth(1)              self.SetLineWidth(1)
388              self.SetFill(Color.None)              self.SetFill(Color.Transparent)
389    
390      def SetProperties(self, props):      def SetProperties(self, props):
391          """Set this class's properties to those in class props."""          """Set this class's properties to those in class props."""
392    
393          assert(isinstance(props, ClassGroupProperties))          assert isinstance(props, ClassGroupProperties)
394          self.SetLineColor(props.GetLineColor())          self.SetLineColor(props.GetLineColor())
395          self.SetLineWidth(props.GetLineWidth())          self.SetLineWidth(props.GetLineWidth())
396          self.SetFill(props.GetFill())          self.SetFill(props.GetFill())
# Line 399  class ClassGroupProperties: Line 405  class ClassGroupProperties:
405          color -- the color of the line. This must be a Color object.          color -- the color of the line. This must be a Color object.
406          """          """
407    
408          assert(isinstance(color, Color))          assert isinstance(color, Color)
409          self.stroke = color          self.stroke = color
410    
411      def GetLineWidth(self):      def GetLineWidth(self):
# Line 411  class ClassGroupProperties: Line 417  class ClassGroupProperties:
417    
418          lineWidth -- the new line width. This must be > 0.          lineWidth -- the new line width. This must be > 0.
419          """          """
420          assert(isinstance(lineWidth, IntType))          assert isinstance(lineWidth, IntType)
421          if (lineWidth < 1):          if (lineWidth < 1):
422              raise ValueError(_("lineWidth < 1"))              raise ValueError(_("lineWidth < 1"))
423    
# Line 427  class ClassGroupProperties: Line 433  class ClassGroupProperties:
433          fill -- the color of the fill. This must be a Color object.          fill -- the color of the fill. This must be a Color object.
434          """          """
435    
436          assert(isinstance(fill, Color))          assert isinstance(fill, Color)
437          self.fill = fill          self.fill = fill
438    
439      def __eq__(self, other):      def __eq__(self, other):
# Line 444  class ClassGroupProperties: Line 450  class ClassGroupProperties:
450      def __copy__(self):      def __copy__(self):
451          return ClassGroupProperties(self)          return ClassGroupProperties(self)
452    
453        def __deepcopy__(self):
454            return ClassGroupProperties(self)
455    
456  class ClassGroup:  class ClassGroup:
457      """A base class for all Groups within a Classification"""      """A base class for all Groups within a Classification"""
458    
# Line 467  class ClassGroup: Line 476  class ClassGroup:
476          label -- a string representing the Group's label. This must          label -- a string representing the Group's label. This must
477                   not be None.                   not be None.
478          """          """
479          assert(isinstance(label, StringType))          assert isinstance(label, StringType)
480          self.label = label          self.label = label
481    
482        def GetDisplayText(self):
483            assert False, "GetDisplay must be overridden by subclass!"
484            return ""
485    
486      def Matches(self, value):      def Matches(self, value):
487          """Determines if this Group is associated with the given value.          """Determines if this Group is associated with the given value.
488    
489          Returns False. This needs to be overridden by all subclasses.          Returns False. This needs to be overridden by all subclasses.
490          """          """
491            assert False, "GetMatches must be overridden by subclass!"
492          return False          return False
493    
494      def GetProperties(self):      def GetProperties(self):
# Line 482  class ClassGroup: Line 496  class ClassGroup:
496    
497          Returns None. This needs to be overridden by all subclasses.          Returns None. This needs to be overridden by all subclasses.
498          """          """
499            assert False, "GetProperties must be overridden by subclass!"
500          return None          return None
501    
502            
# Line 544  class ClassGroupSingleton(ClassGroup): Line 559  class ClassGroupSingleton(ClassGroup):
559          """          """
560    
561          if prop is None: prop = ClassGroupProperties()          if prop is None: prop = ClassGroupProperties()
562          assert(isinstance(prop, ClassGroupProperties))          assert isinstance(prop, ClassGroupProperties)
563          self.prop = prop          self.prop = prop
564    
565        def GetDisplayText(self):
566            label = self.GetLabel()
567    
568            if label != "": return label
569    
570            return str(self.GetValue())
571    
572      def __eq__(self, other):      def __eq__(self, other):
573          return isinstance(other, ClassGroupSingleton) \          return isinstance(other, ClassGroupSingleton) \
574              and self.GetProperties() == other.GetProperties() \              and self.GetProperties() == other.GetProperties() \
# Line 594  class ClassGroupDefault(ClassGroup): Line 616  class ClassGroupDefault(ClassGroup):
616          """          """
617    
618          if prop is None: prop = ClassGroupProperties()          if prop is None: prop = ClassGroupProperties()
619          assert(isinstance(prop, ClassGroupProperties))          assert isinstance(prop, ClassGroupProperties)
620          self.prop = prop          self.prop = prop
621    
622        def GetDisplayText(self):
623            label = self.GetLabel()
624    
625            if label != "": return label
626    
627            return "DEFAULT"
628    
629      def __eq__(self, other):      def __eq__(self, other):
630          return isinstance(other, ClassGroupDefault) \          return isinstance(other, ClassGroupDefault) \
631              and self.GetProperties() == other.GetProperties()              and self.GetProperties() == other.GetProperties()
# Line 706  class ClassGroupRange(ClassGroup): Line 735  class ClassGroupRange(ClassGroup):
735                  a default set of properties is created.                  a default set of properties is created.
736          """          """
737          if prop is None: prop = ClassGroupProperties()          if prop is None: prop = ClassGroupProperties()
738          assert(isinstance(prop, ClassGroupProperties))          assert isinstance(prop, ClassGroupProperties)
739          self.prop = prop          self.prop = prop
740    
741        def GetDisplayText(self):
742            label = self.GetLabel()
743    
744            if label != "": return label
745    
746            return _("%s - %s") % (self.GetMin(), self.GetMax())
747    
748      def __eq__(self, other):      def __eq__(self, other):
749          return isinstance(other, ClassGroupRange) \          return isinstance(other, ClassGroupRange) \
750              and self.GetProperties() == other.GetProperties() \              and self.GetProperties() == other.GetProperties() \
# Line 740  class ClassGroupMap(ClassGroup): Line 776  class ClassGroupMap(ClassGroup):
776      def GetPropertiesFromValue(self, value):      def GetPropertiesFromValue(self, value):
777          pass          pass
778    
779        def GetDisplayText(self):
780            return "Map: " + self.map_type
781    
782      #      #
783      # built-in mappings      # built-in mappings
784      #      #

Legend:
Removed from v.491  
changed lines
  Added in v.609

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26