/[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 428 by jonathan, Mon Feb 24 18:46:35 2003 UTC revision 479 by jonathan, Thu Mar 6 16:46:07 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001 by Intevation GmbH  # Copyright (c) 2001, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jonathan Coles <[email protected]>  # Jonathan Coles <[email protected]>
4  #  #
# Line 16  an input value falls with a range that d Line 16  an input value falls with a range that d
16  If no mapping can be found then default data will  If no mapping can be found then default data will
17  be returned. Input values must be hashable objects  be returned. Input values must be hashable objects
18    
19  See the description of GetClassData() for more information  See the description of GetGroup() for more information
20  on the mapping algorithm.  on the mapping algorithm.
21  """  """
22        
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    from types import *
27    
28  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \
29       LAYER_VISIBILITY_CHANGED       LAYER_VISIBILITY_CHANGED
30    
31  from Thuban import _  from Thuban import _
32  from Thuban.Model.color import Color  from Thuban.Model.color import Color
33    
34  from wxPython.wx import *  import Thuban.Model.layer
35    
36  # constants  # constants
37  RANGE_MIN  = 0  RANGE_MIN  = 0
# Line 37  RANGE_MAX  = 1 Line 39  RANGE_MAX  = 1
39  RANGE_DATA = 2  RANGE_DATA = 2
40    
41  class Classification:  class Classification:
42        """Encapsulates the classification of layer. The Classification
43        divides some kind of data into Groups which are associated with
44        properties. Later the properties can be retrieved by matching
45        data values to the appropriate group."""
46    
47      def __init__(self, layer = None, field = None):      def __init__(self, layer = None, field = None):
48          """Initialize a classification.          """Initialize a classification.
49    
50             layer -- the layer object who owns this classification             layer -- the Layer object who owns this classification
51    
52             field -- the name of the data table field that             field -- the name of the data table field that
53                      is to be used to classify layer properties                      is to be used to classify layer properties
54          """          """
55    
56          self.layer = layer          self.layer = None
57          self.points = {}          self.field = None
58          self.ranges = []          self.fieldType = None
59          self.maps   = []          self.groups = []
60          self.DefaultData = ClassDataDefault()          self.__sendMessages = False
61          self.field = field  
62          #self.SetField(field)          self.__ToggleMessages(False)
63            self.SetDefaultGroup(ClassGroupDefault())
64            self.SetLayer(layer)
65            self.SetField(field)
66    
67            self.__ToggleMessages(True)
68    
69      def __iter__(self):      def __iter__(self):
70          return ClassIterator(self.DefaultData,          return ClassIterator(self.groups)
71                               self.points.values(),  
72                               self.ranges,      def __ToggleMessages(self, on):
73                               self.maps)          self.__sendMessages = on
74    
75      def __SendMessage(self, message):      def __SendMessage(self, message):
76          if self.layer is not None:          """Send the message 'message' to the parent layer."""
77            if self.__sendMessages and self.layer is not None:
78              self.layer.changed(message, self.layer)              self.layer.changed(message, self.layer)
79            
80      def SetField(self, field):      def SetField(self, field = None):
81          """Set the name of the data table field to use.          """Set the name of the data table field to use.
82                    
83               If there is no layer then the field type is set to None,
84               otherwise the layer is queried to find the type of the
85               field data
86    
87             field -- if None then all values map to the default data             field -- if None then all values map to the default data
88          """          """
89    
90            if field == "":
91                field = None
92    
93          self.field = field          self.field = field
94    
95            if self.layer is not None:
96                fieldType = self.layer.GetFieldType(field)
97            else:
98                fieldType = None
99    
100            self.SetFieldType(fieldType)
101    
102            # XXX: if fieldType comes back None then field isn't in the table!
103    
104          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendMessage(LAYER_LEGEND_CHANGED)
105    
106      def GetField(self):      def GetField(self):
107            """Return the name of the field."""
108          return self.field          return self.field
109    
110        def GetFieldType(self):
111            """Return the field type."""
112            return self.fieldType
113    
114        def SetFieldType(self, type):
115            self.fieldType = type
116    
117      def SetLayer(self, layer):      def SetLayer(self, layer):
118            """Set the owning Layer of this classification."""
119    
120            if __debug__:
121                if layer is not None:
122                    assert(isinstance(layer, Thuban.Model.layer.Layer))
123    
124            # prevent infinite recursion when calling SetClassification()
125            if self.layer is not None and layer == self.layer:
126                return
127    
128          self.layer = layer          self.layer = layer
129          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.SetField(self.GetField()) # XXX: this sync's the fieldType
130    
131            if self.layer is not None:
132                self.layer.SetClassification(self)
133    
134            #self.__SendMessage(LAYER_LEGEND_CHANGED)
135    
136      def GetLayer(self):      def GetLayer(self):
137          return layer.self          """Return the parent layer."""
138            return self.layer
139    
140      def SetDefaultData(self, data):      def SetDefaultGroup(self, group):
141          """Set the data to be used when a value can't be classified.          """Set the group to be used when a value can't be classified.
142    
143             data -- data that the value maps to. See class description.             group -- group that the value maps to.
144          """          """
145    
146          assert(data.GetType() == ClassData.DEFAULT)          assert(isinstance(group, ClassGroupDefault))
147          self.DefaultData = data          self.AddGroup(group)
148    
149      def GetDefaultData(self):      def GetDefaultGroup(self):
150          return self.DefaultData          """Return the default group."""
151            return self.groups[0]
152    
153      #      #
154      # these SetDefault* methods are really only provided for      # these SetDefault* methods are really only provided for
# Line 103  class Classification: Line 157  class Classification:
157      #      #
158    
159      def SetDefaultFill(self, fill):      def SetDefaultFill(self, fill):
160          self.DefaultData.SetFill(fill)          """Set the default fill color.
161    
162            fill -- a Color object.
163            """
164            assert(isinstance(fill, Color))
165            self.GetDefaultGroup().GetProperties().SetFill(fill)
166          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendMessage(LAYER_LEGEND_CHANGED)
167                    
168      def GetDefaultFill(self):      def GetDefaultFill(self):
169          return self.DefaultData.GetFill()          """Return the default fill color."""
170            return self.GetDefaultGroup().GetProperties().GetFill()
171                    
172      def SetDefaultStroke(self, stroke):      def SetDefaultLineColor(self, color):
173          self.DefaultData.SetStroke(stroke)          """Set the default line color.
174    
175            color -- a Color object.
176            """
177            assert(isinstance(color, Color))
178            self.GetDefaultGroup().GetProperties().SetLineColor(color)
179          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendMessage(LAYER_LEGEND_CHANGED)
180                    
181      def GetDefaultStroke(self):      def GetDefaultLineColor(self):
182          return self.DefaultData.GetStroke()          """Return the default line color."""
183            return self.GetDefaultGroup().GetProperties().GetLineColor()
184                    
185      def SetDefaultStrokeWidth(self, strokeWidth):      def SetDefaultLineWidth(self, lineWidth):
186          self.DefaultData.SetStrokeWidth(strokeWidth)          """Set the default line width.
187    
188            lineWidth -- an integer > 0.
189            """
190            assert(isinstance(lineWidth, IntType))
191            self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)
192          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendMessage(LAYER_LEGEND_CHANGED)
193                    
194      def GetDefaultStrokeWidth(self):      def GetDefaultLineWidth(self):
195          return self.DefaultData.GetStrokeWidth()          """Return the default line width."""
196            return self.GetDefaultGroup().GetProperties().GetLineWidth()
197                    
198      def AddClassData(self, item):      def AddGroup(self, item):
199          type = item.GetType()          """Add a new ClassGroup item to the classification.
200    
201            item -- this must be a valid ClassGroup object
202            """
203    
204          if type == ClassData.POINT:          assert(isinstance(item, ClassGroup))
205              self.points[item.GetValue()] = item  
206          elif type == ClassData.RANGE:          if len(self.groups) > 0 and isinstance(item, ClassGroupDefault):
207              self.ranges.append(item)              self.groups[0] = item
208          elif type == ClassData.MAP:              #self.SetDefaultGroup(item)
             self.maps.append(item)  
         elif type == ClassData.DEFAULT:  
             self.DefaultData = item  
209          else:          else:
210              raise ValueError(_("Unrecognized ClassData type %s") % type)              self.groups.append(item)
211    
212          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendMessage(LAYER_LEGEND_CHANGED)
213    
214      def GetClassData(self, value):      def GetGroup(self, value):
215          """Return the associated data, or the default data.          """Return the associated group, or the default group.
216    
217             The following search technique is used:             Groups are checked in the order the were added to the
218                 (1) if the field is None, return the default data             Classification.
                (2) check if the value exists as a single value  
                (3) check if the value falls within a range. Ranges  
                    are checked in the order they were added to  
                    the classification.  
219    
220             value -- the value to classify. If there is no mapping,             value -- the value to classify. If there is no mapping,
221                      or value is None, return the default properties                      the field is None or value is None,
222                        return the default properties
223          """          """
224    
225          if self.field is not None and value is not None:          if self.GetField() is not None and value is not None:
226              #  
227              # check the discrete values              for i in range(1, len(self.groups)):
228              #                  group = self.groups[i]
229              if self.points.has_key(value):                  if group.Matches(value):
230                  return self.points[value]                      return group
231    
232              #          return self.GetDefaultGroup()
233              # check the ranges  
234              #      def GetProperties(self, value):
235              for p in self.ranges:          """Return the properties associated with the given value."""
                 if p.InRange(value):  
                     return p  
   
             #  
             # check the maps  
             #  
             for p in self.maps:  
                 try:  
                     return p.Map(value)  
                 except: pass  
236    
237          return self.DefaultData          group = self.GetGroup(value)
238            if isinstance(group, ClassGroupMap):
239                return group.GetPropertiesFromValue(value)
240            else:
241                return group.GetProperties()
242    
243      def TreeInfo(self):      def TreeInfo(self):
244          items = []          items = []
# Line 188  class Classification: Line 251  class Classification:
251                      (text, color.red, color.green, color.blue),                      (text, color.red, color.green, color.blue),
252                      color)                      color)
253    
254          def build_item(data, string):          def build_item(group, string):
255              label = data.GetLabel()              label = group.GetLabel()
256              if label == "":              if label == "":
257                  label = string                  label = string
258              else:              else:
259                  label += " (%s)" % string                  label += " (%s)" % string
260    
261                props = group.GetProperties()
262              i = []              i = []
263              v = data.GetStroke()              v = props.GetLineColor()
264              i.append(build_color_item(_("Stroke"), v))              i.append(build_color_item(_("Line Color"), v))
265              v = data.GetStrokeWidth()              v = props.GetLineWidth()
266              i.append(_("Stroke Width: %s") % v)              i.append(_("Line Width: %s") % v)
267              v = data.GetFill()              v = props.GetFill()
268              i.append(build_color_item(_("Fill"), v))              i.append(build_color_item(_("Fill"), v))
269              return (label, i)              return (label, i)
270    
271          for p in self:          for p in self:
272              type = p.GetType()              if isinstance(p, ClassGroupDefault):
273              if type == ClassData.DEFAULT:                  items.append(build_item(self.GetDefaultGroup(), _("'DEFAULT'")))
274                  items.append(build_item(self.DefaultData, _("'DEFAULT'")))              elif isinstance(p, ClassGroupSingleton):
             elif type == ClassData.POINT:  
275                  items.append(build_item(p, str(p.GetValue())))                  items.append(build_item(p, str(p.GetValue())))
276              elif type == ClassData.RANGE:              elif isinstance(p, ClassGroupRange):
277                  items.append(build_item(p, "%s - %s" %                  items.append(build_item(p, "%s - %s" %
278                                             (p.GetMin(), p.GetMax())))                                             (p.GetMin(), p.GetMax())))
279    
280  #       for p in self.points.values():          return (_("Classification"), items)
281  #           items.append(build_item(p, str(p.GetValue())))  
282    class ClassIterator:
283        """Allows the Groups in a Classifcation to be interated over.
284    
285  #       for p in self.ranges:      The items are returned in the following order:
286  #           items.append(build_item(p, "%s - %s" % (p.GetMin(), p.GetMax())))          default data, singletons, ranges, maps
287        """
288    
289          return (_("Classifications"), items)      def __init__(self, data): #default, points, ranges, maps):
290            """Constructor.
291    
292            default -- the default group
293    
294  class ClassIterator:          points -- a list of singleton groups
295    
296      def __init__(self, default, points, ranges, maps):          ranges -- a list of range groups
297          self.data = [default, points, ranges, maps]  
298          self.data_iter = iter(self.data)          maps -- a list of map groups
299          self.iter = None          """
300    
301            self.data = data #[default, points, ranges, maps]
302            self.data_index = 0
303            #self.data_iter = iter(self.data)
304            #self.iter = None
305    
306      def __iter__(self):      def __iter__(self):
307          return self          return self
308    
309      def next(self):      def next(self):
310          if self.iter is None:          """Return the next item."""
311              try:  
312                  self.data_item = self.data_iter.next()          if self.data_index >= len(self.data):
313                  self.iter = iter(self.data_item)              raise StopIteration
314              except TypeError:          else:
315                  return self.data_item              d = self.data[self.data_index]
316                self.data_index += 1
317          try:              return d
318              return self.iter.next()          
319          except StopIteration:  #       if self.iter is None:
320              self.iter = None  #           try:
321              return self.next()  #               self.data_item = self.data_iter.next()
322    #               self.iter = iter(self.data_item)
323    #           except TypeError:
324    #               return self.data_item
325    
326    #       try:
327    #           return self.iter.next()
328    #       except StopIteration:
329    #           self.iter = None
330    #           return self.next()
331                
332  class ClassData:  class ClassGroupProperties:
333        """Represents the properties of a single Classification Group.
334      
335        These are used when rendering a layer."""
336    
337      INVALID = -1      def __init__(self, props = None):
338      DEFAULT = 0          """Constructor.
339      POINT = 1  
340      RANGE = 2          props -- a ClassGroupProperties object. The class is copied if
341      MAP   = 3                   prop is not None. Otherwise, a default set of properties
342                     is created such that: line color = Color.Black, line width = 1,
343      def __init__(self, classData = None, type = INVALID):                   and fill color = Color.None
344            """
345          if classData is not None:  
346              self.SetStroke(classData.GetStroke())          self.stroke = None
347              self.SetStrokeWidth(classData.GetStrokeWidth())          self.strokeWidth = 0
348              self.SetFill(classData.GetFill())          self.fill = None
349    
350            if props is not None:
351                self.SetProperties(props)
352          else:          else:
353              self.SetStroke(Color.None)              self.SetLineColor(Color.None)
354              self.SetStrokeWidth(1)              self.SetLineWidth(1)
355              self.SetFill(Color.None)              self.SetFill(Color.None)
356    
357          self.type = type      def SetProperties(self, props):
358          self.label = ""          """Set this class's properties to those in class props."""
       
     def GetType(self):  
         return self.type  
359    
360      def GetStroke(self):          assert(isinstance(props, ClassGroupProperties))
361            self.SetLineColor(props.GetLineColor())
362            self.SetLineWidth(props.GetLineWidth())
363            self.SetFill(props.GetFill())
364            
365        def GetLineColor(self):
366            """Return the line color as a Color object."""
367          return self.stroke          return self.stroke
368    
369      def SetStroke(self, stroke):      def SetLineColor(self, color):
370          assert(isinstance(stroke, Color))          """Set the line color.
         self.stroke = stroke  
   
     def GetStrokeWidth(self):  
         return self.stroke_width  
   
     def SetStrokeWidth(self, stroke_width):  
         if (stroke_width < 1):  
             raise ValueError(_("stroke_width < 1"))  
371    
372          self.stroke_width = stroke_width          color -- the color of the line. This must be a Color object.
373            """
374    
375            assert(isinstance(color, Color))
376            self.stroke = color
377    
378        def GetLineWidth(self):
379            """Return the line width."""
380            return self.strokeWidth
381    
382        def SetLineWidth(self, lineWidth):
383            """Set the line width.
384    
385            lineWidth -- the new line width. This must be > 0.
386            """
387            assert(isinstance(lineWidth, IntType))
388            if (lineWidth < 1):
389                raise ValueError(_("lineWidth < 1"))
390    
391            self.strokeWidth = lineWidth
392    
393      def GetFill(self):      def GetFill(self):
394            """Return the fill color as a Color object."""
395          return self.fill          return self.fill
396    
397      def SetFill(self, fill):      def SetFill(self, fill):
398            """Set the fill color.
399    
400            fill -- the color of the fill. This must be a Color object.
401            """
402    
403          assert(isinstance(fill, Color))          assert(isinstance(fill, Color))
404          self.fill = fill          self.fill = fill
405    
406        def __eq__(self, other):
407            """Return true if 'props' has the same attributes as this class"""
408    
409            return isinstance(other, ClassGroupProperties)   \
410                and self.stroke      == other.GetLineColor() \
411                and self.strokeWidth == other.GetLineWidth() \
412                and self.fill        == other.GetFill()
413    
414        def __ne__(self, other):
415            return not self.__eq__(other)
416    
417    class ClassGroup:
418        """A base class for all Groups within a Classification"""
419    
420        def __init__(self, label = ""):
421            """Constructor.
422    
423            label -- A string representing the Group's label
424            """
425    
426            self.label = None
427    
428            self.SetLabel(label)
429    
430      def GetLabel(self):      def GetLabel(self):
431            """Return the Group's label."""
432          return self.label          return self.label
433    
434      def SetLabel(self, label):      def SetLabel(self, label):
435            """Set the Group's label.
436    
437            label -- a string representing the Group's label. This must
438                     not be None.
439            """
440            assert(isinstance(label, StringType))
441          self.label = label          self.label = label
442    
443  class ClassDataDefault(ClassData):      def Matches(self, value):
444      def __init__(self, classData = None):          """Determines if this Group is associated with the given value.
445          ClassData.__init__(self, classData, ClassData.DEFAULT)  
446            Returns False. This needs to be overridden by all subclasses.
447            """
448            return False
449    
450        def GetProperties(self):
451            """Return the properties associated with the given value.
452    
453            Returns None. This needs to be overridden by all subclasses.
454            """
455            return None
456    
457            
458  class ClassDataPoint(ClassData):  class ClassGroupSingleton(ClassGroup):
459        """A Group that is associated with a single value."""
460    
461      def __init__(self, value = 0, classData = None):      def __init__(self, value = 0, prop = None, label = ""):
462          ClassData.__init__(self, classData, ClassData.POINT)          """Constructor.
463    
464          self.value = value          value -- the associated value.
465    
466            prop -- a ClassGroupProperites object. If prop is None a default
467                     set of properties is created.
468    
469            label -- a label for this group.
470            """
471            ClassGroup.__init__(self, label)
472    
473            self.prop = None
474            self.value = None
475    
476            self.SetValue(value)
477            self.SetProperties(prop)
478    
479        def __copy__(self):
480            return ClassGroupSingleton(self.GetValue(),
481                                       self.GetProperties(),
482                                       self.GetLabel())
483    
484      def GetValue(self):      def GetValue(self):
485            """Return the associated value."""
486          return self.value          return self.value
487    
488      def SetValue(self, value):      def SetValue(self, value):
489            """Associate this Group with the given value."""
490          self.value = value          self.value = value
491    
492  class ClassDataRange(ClassData):      def Matches(self, value):
493            """Determine if the given value matches the associated Group value."""
494    
495      def __init__(self, min = 0, max = 1, classData = None):          """Returns True if the value matches, False otherwise."""
         ClassData.__init__(self, classData, ClassData.RANGE)  
496    
497          if min >= max:          return self.value == value
498              raise ValueError(_("ClassDataRange: %i(min) >= %i(max)!") %  
499                               (min, max))      def GetProperties(self):
500            """Return the Properties associated with this Group."""
501    
502            return self.prop
503    
504        def SetProperties(self, prop):
505            """Set the properties associated with this Group.
506    
507            prop -- a ClassGroupProperties object. if prop is None,
508                    a default set of properties is created.
509            """
510    
511            if prop is None: prop = ClassGroupProperties()
512            assert(isinstance(prop, ClassGroupProperties))
513            self.prop = prop
514    
515        def __eq__(self, other):
516            return isinstance(other, ClassGroupSingleton) \
517                and self.GetProperties() == other.GetProperties() \
518                and self.GetValue() == other.GetValue()
519    
520        def __ne__(self, other):
521            return not self.__eq__(other)
522    
523    class ClassGroupDefault(ClassGroup):
524        """The default Group. When values do not match any other
525           Group within a Classification, the properties from this
526           class are used."""
527    
528        def __init__(self, prop = None, label = ""):
529            """Constructor.
530    
531            prop -- a ClassGroupProperites object. If prop is None a default
532                     set of properties is created.
533    
534            label -- a label for this group.
535            """
536    
537            ClassGroup.__init__(self, label)
538            self.SetProperties(prop)
539    
540        def __copy__(self):
541            return ClassGroupDefault(self.GetProperties(), self.GetLabel())
542    
543        def Matches(self, value):
544            return True
545    
546        def GetProperties(self):
547            """Return the Properties associated with this Group."""
548            return self.prop
549    
550        def SetProperties(self, prop):
551            """Set the properties associated with this Group.
552    
553            prop -- a ClassGroupProperties object. if prop is None,
554                    a default set of properties is created.
555            """
556    
557            if prop is None: prop = ClassGroupProperties()
558            assert(isinstance(prop, ClassGroupProperties))
559            self.prop = prop
560    
561        def __eq__(self, other):
562            return isinstance(other, ClassGroupDefault) \
563                and self.GetProperties() == other.GetProperties()
564    
565        def __ne__(self, other):
566            return not self.__eq__(other)
567    
568    class ClassGroupRange(ClassGroup):
569        """A Group that represents a range of values that map to the same
570           set of properties."""
571    
572        def __init__(self, min = 0, max = 1, prop = None, label = ""):
573            """Constructor.
574    
575            The minumum value must be strictly less than the maximum.
576    
577            min -- the minimum range value
578    
579            max -- the maximum range value
580    
581            prop -- a ClassGroupProperites object. If prop is None a default
582                     set of properties is created.
583    
584            label -- a label for this group.
585            """
586    
587            ClassGroup.__init__(self, label)
588    
589            self.min = self.max = 0
590            self.prop = None
591    
592          self.SetRange(min, max)          self.SetRange(min, max)
593            self.SetProperties(prop)
594    
595        def __copy__(self):
596            return ClassGroupRange(self.GetMin(),
597                                   self.GetMax(),
598                                   self.GetProperties(),
599                                   self.GetLabel())
600    
601      def GetMin(self):      def GetMin(self):
602            """Return the range's minimum value."""
603          return self.min          return self.min
604    
605      def SetMin(self, min):      def SetMin(self, min):
606            """Set the range's minimum value.
607        
608            min -- the new minimum. Note that this must be less than the current
609                   maximum value. Use SetRange() to change both min and max values.
610            """
611        
612          self.SetRange(min, self.max)          self.SetRange(min, self.max)
613    
614      def GetMax(self):      def GetMax(self):
615            """Return the range's maximum value."""
616          return self.max          return self.max
617    
618      def SetMax(self, max):      def SetMax(self, max):
619            """Set the range's maximum value.
620        
621            max -- the new maximum. Note that this must be greater than the current
622                   minimum value. Use SetRange() to change both min and max values.
623            """
624          self.SetRange(self.min, max)          self.SetRange(self.min, max)
625    
626      def SetRange(self, min, max):      def SetRange(self, min, max):
627          self.min = min          """Set a new range.
628          self.max = max  
629            Note that min must be strictly less than max.
630    
631            min -- the new minimum value
632            min -- the new maximum value
633            """
634    
635          if min >= max:          if min >= max:
636              raise ValueError(_("ClassDataRange: %i(min) >= %i(max)!") %              raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") %
637                               (min, max))                               (min, max))
638            self.min = min
639            self.max = max
640    
641      def GetRange(self):      def GetRange(self):
642            """Return the range as a tuple (min, max)"""
643          return (self.min, self.max)          return (self.min, self.max)
644    
645      def InRange(self, value):      def Matches(self, value):
646            """Determine if the given value lies with the current range.
647    
648            The following check is used: min <= value < max.
649            """
650    
651          return self.min <= value < self.max          return self.min <= value < self.max
652    
653  class ClassDataMap(ClassData):      def GetProperties(self):
654            """Return the Properties associated with this Group."""
655            return self.prop
656    
657        def SetProperties(self, prop):
658            """Set the properties associated with this Group.
659    
660            prop -- a ClassGroupProperties object. if prop is None,
661                    a default set of properties is created.
662            """
663            if prop is None: prop = ClassGroupProperties()
664            assert(isinstance(prop, ClassGroupProperties))
665            self.prop = prop
666    
667        def __eq__(self, other):
668            return isinstance(other, ClassGroupRange) \
669                and self.GetProperties() == other.GetProperties() \
670                and self.GetRange() == other.GetRange()
671    
672        def __ne__(self, other):
673            return not self.__eq__(other)
674    
675    class ClassGroupMap(ClassGroup):
676        """Currently, this class is not used."""
677    
678      FUNC_ID = "id"      FUNC_ID = "id"
679    
680      def __init__(self, map_type = FUNC_ID, func = None, classData = None):      def __init__(self, map_type = FUNC_ID, func = None, prop = None, label=""):
681          ClassData.__init__(self, classData, ClassData.MAP)          ClassGroup.__init__(self, label)
682    
683          self.map_type = map_type          self.map_type = map_type
684          self.func = func          self.func = func
# Line 369  class ClassDataMap(ClassData): Line 689  class ClassDataMap(ClassData):
689      def Map(self, value):      def Map(self, value):
690          return self.func(value)          return self.func(value)
691    
692        def GetProperties(self):
693            return None
694    
695        def GetPropertiesFromValue(self, value):
696            pass
697    
698      #      #
699      # built-in mappings      # built-in mappings
700      #      #

Legend:
Removed from v.428  
changed lines
  Added in v.479

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26