/[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

trunk/thuban/Thuban/Model/classification.py revision 2657 by jan, Wed Jul 27 21:49:25 2005 UTC branches/WIP-pyshapelib-bramz/Thuban/Model/classification.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2003, 2005 by Intevation GmbH  # Copyright (c) 2001, 2003, 2005, 2006 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jonathan Coles <[email protected]>  # Jonathan Coles <[email protected]>
4  # Jan-Oliver Wagner <[email protected]> (2005)  # Jan-Oliver Wagner <[email protected]> (2005)
5    # Frank Koormann <[email protected]> (2006)
6  #  #
7  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
8  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 22  on the mapping algorithm. Line 23  on the mapping algorithm.
23  """  """
24        
25  import copy, operator, types  import copy, operator, types
26    import re
27    
28  from Thuban import _  from Thuban import _
29    
# Line 109  class Classification(Publisher): Line 111  class Classification(Publisher):
111    
112              is true.              is true.
113    
114              'pattern'
115                
116                The tuple contains the compiled regular expression object and
117                the original group object.
118    
119          The compiled classification is bound to          The compiled classification is bound to
120          self._compile_classification.          self._compile_classification.
121          """          """
# Line 118  class Classification(Publisher): Line 125  class Classification(Publisher):
125                  if not compiled or compiled[-1][0] != "singletons":                  if not compiled or compiled[-1][0] != "singletons":
126                      compiled.append(("singletons", {}))                      compiled.append(("singletons", {}))
127                  compiled[-1][1].setdefault(group.GetValue(), group)                  compiled[-1][1].setdefault(group.GetValue(), group)
128                elif isinstance(group, ClassGroupPattern):
129                    pattern = re.compile(group.GetPattern())
130                    compiled.append(("pattern", (pattern, group)))
131              elif isinstance(group, ClassGroupRange):              elif isinstance(group, ClassGroupRange):
132                  left, min, max, right = group.GetRangeTuple()                  left, min, max, right = group.GetRangeTuple()
133                  if left == "[":                  if left == "[":
# Line 267  class Classification(Publisher): Line 277  class Classification(Publisher):
277                      lfunc, min, max, rfunc, g = params                      lfunc, min, max, rfunc, g = params
278                      if lfunc(min, value) and rfunc(max, value):                      if lfunc(min, value) and rfunc(max, value):
279                          return g                          return g
280                    elif typ == "pattern":
281                        # TODO: make pattern more robust. The following chrashes
282                        # if accidently be applied on non-string columns.
283                        # Usually the UI prevents this.
284                        p, g = params
285                        if p.match(value):
286                            return g
287    
288          return self.GetDefaultGroup()          return self.GetDefaultGroup()
289    
# Line 747  class ClassGroupRange(ClassGroup): Line 764  class ClassGroupRange(ClassGroup):
764      def __repr__(self):      def __repr__(self):
765          return "(" + str(self.__range) + ClassGroup.__repr__(self) + ")"          return "(" + str(self.__range) + ClassGroup.__repr__(self) + ")"
766    
767    class ClassGroupPattern(ClassGroup):
768        """A Group that is associated with a reg exp pattern."""
769    
770        def __init__(self, pattern = "", props = None, label = "", group = None):
771            """Constructor.
772    
773            pattern -- the associated pattern.
774    
775            props   -- a ClassGroupProperites object. If props is None a default
776                       set of properties is created.
777    
778            label   -- a label for this group.
779            """
780            ClassGroup.__init__(self, label, props, group)
781    
782            self.SetPattern(pattern)
783    
784        def __copy__(self):
785            return ClassGroupPattern(self.GetPattern(),
786                                       self.GetProperties(),
787                                       self.GetLabel())
788    
789        def __deepcopy__(self, memo):
790            return ClassGroupPattern(self.GetPattern(), group = self)
791    
792        def GetPattern(self):
793            """Return the associated pattern."""
794            return self.__pattern
795    
796        def SetPattern(self, pattern):
797            """Associate this Group with the given pattern."""
798            self.__pattern = pattern
799    
800        def Matches(self, pattern):
801            """Check if the given pattern matches the associated Group pattern."""
802    
803            """Returns True if the value matches, False otherwise."""
804    
805            if re.match(self.__pattern, pattern):
806                return True
807            else:
808                return False
809    
810        def GetDisplayText(self):
811            label = self.GetLabel()
812    
813            if label != "": return label
814    
815            return str(self.GetPattern())
816    
817        def __eq__(self, other):
818            return ClassGroup.__eq__(self, other) \
819                and isinstance(other, ClassGroupPattern) \
820                and self.__pattern == other.__pattern
821    
822        def __repr__(self):
823            return "(" + repr(self.__pattern) + ", " + ClassGroup.__repr__(self) + ")"
824    
825  class ClassGroupMap(ClassGroup):  class ClassGroupMap(ClassGroup):
826      """Currently, this class is not used."""      """Currently, this class is not used."""
827    

Legend:
Removed from v.2657  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26