/[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 484 by jonathan, Fri Mar 7 18:20:10 2003 UTC revision 491 by jonathan, Mon Mar 10 10:44:42 2003 UTC
# Line 59  class Classification: Line 59  class Classification:
59          self.field = None          self.field = None
60          self.fieldType = None          self.fieldType = None
61          self.groups = []          self.groups = []
         self.__sendMessages = False  
62    
         self.__ToggleMessages(False)  
63          self.SetDefaultGroup(ClassGroupDefault())          self.SetDefaultGroup(ClassGroupDefault())
64    
65          self.SetLayer(layer)          self.SetLayer(layer)
66          self.SetField(field)          self.SetField(field)
67    
         self.__ToggleMessages(True)  
   
68      def __iter__(self):      def __iter__(self):
69          return ClassIterator(self.groups)          return ClassIterator(self.groups)
70    
71      def __ToggleMessages(self, on):      def __SendNotification(self):
72          self.__sendMessages = on          """Notify the layer that this class has changed."""
73            if self.layer is not None:
74      def __SendMessage(self, message):              self.layer.ClassChanged()
         """Send the message 'message' to the parent layer."""  
         if self.__sendMessages and self.layer is not None:  
             self.layer.changed(message, self.layer)  
75            
76      def SetField(self, field = None):      def SetField(self, field):
77          """Set the name of the data table field to use.          """Set the name of the data table field to use.
78                    
79             If there is no layer then the field type is set to None,             If there is no layer then the field type is set to None,
# Line 92  class Classification: Line 86  class Classification:
86          if field == "":          if field == "":
87              field = None              field = None
88    
         self.field = field  
89    
90          if self.layer is not None:          if field is None:
91              fieldType = self.layer.GetFieldType(field)              if self.layer is not None:
92                    self.fieldType = None
93          else:          else:
94              fieldType = None              if self.layer is not None:
95                    fieldType = self.layer.GetFieldType(field)
96          self.SetFieldType(fieldType)                  if fieldType is None:
97                        raise ValueError("'%s' was not found in the layer's table."
98                                         % self.field)
99    
100                    #
101                    # unfortunately we cannot call SetFieldType() because it
102                    # requires the layer to be None
103                    #
104                    self.fieldType = fieldType
105                    #self.SetFieldType(fieldType)
106    
107          # XXX: if fieldType comes back None then field isn't in the table!          self.field = field
108    
109          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendNotification()
110    
111      def GetField(self):      def GetField(self):
112          """Return the name of the field."""          """Return the name of the field."""
# Line 114  class Classification: Line 117  class Classification:
117          return self.fieldType          return self.fieldType
118    
119      def SetFieldType(self, type):      def SetFieldType(self, type):
120          self.fieldType = type          """Set the type of the field used by this classification.
121    
122      def SetLayer(self, layer):          A ValueError is raised if the owning layer is not None and
123          """Set the owning Layer of this classification."""          'type' is different from the current field type.
124            """
125    
126          if __debug__:          if type != self.fieldType:
127              if layer is not None:              if self.layer is not None:
128                  assert(isinstance(layer, Thuban.Model.layer.Layer))                  raise ValueError()
129                else:
130          # prevent infinite recursion when calling SetClassification()                  self.fieldType = type
131          if self.layer is not None and layer == self.layer:                  self.__SendNotification()
             return  
132    
133          self.layer = layer      def SetLayer(self, layer):
134          self.SetField(self.GetField()) # XXX: this sync's the fieldType          """Set the owning Layer of this classification.
135    
136               A ValueError exception will be thrown either the field or
137               field type mismatch the information in the layer's table.
138            """
139    
140          if self.layer is not None:          if layer is None:
141              self.layer.SetClassification(self)              if self.layer is not None:
142                    l = self.layer
143                    self.layer = None
144                    l.SetClassification(None)
145            else:
146                assert(isinstance(layer, Thuban.Model.layer.Layer))
147    
148          #self.__SendMessage(LAYER_LEGEND_CHANGED)              # prevent infinite recursion when calling SetClassification()
149                if layer == self.layer:
150                    return
151                
152                old_layer = self.layer
153    
154                self.layer = layer
155    
156                try:
157                    self.SetField(self.GetField()) # this sync's the fieldType
158                except ValueError:
159                    self.layer = old_layer
160                    raise ValueError
161                else:
162                    self.layer.SetClassification(self)
163    
164      def GetLayer(self):      def GetLayer(self):
165          """Return the parent layer."""          """Return the parent layer."""
# Line 165  class Classification: Line 191  class Classification:
191          """          """
192          assert(isinstance(fill, Color))          assert(isinstance(fill, Color))
193          self.GetDefaultGroup().GetProperties().SetFill(fill)          self.GetDefaultGroup().GetProperties().SetFill(fill)
194          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendNotification()
195                    
196      def GetDefaultFill(self):      def GetDefaultFill(self):
197          """Return the default fill color."""          """Return the default fill color."""
# Line 178  class Classification: Line 204  class Classification:
204          """          """
205          assert(isinstance(color, Color))          assert(isinstance(color, Color))
206          self.GetDefaultGroup().GetProperties().SetLineColor(color)          self.GetDefaultGroup().GetProperties().SetLineColor(color)
207          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendNotification()
208                    
209      def GetDefaultLineColor(self):      def GetDefaultLineColor(self):
210          """Return the default line color."""          """Return the default line color."""
# Line 191  class Classification: Line 217  class Classification:
217          """          """
218          assert(isinstance(lineWidth, IntType))          assert(isinstance(lineWidth, IntType))
219          self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)          self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth)
220          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendNotification()
221                    
222      def GetDefaultLineWidth(self):      def GetDefaultLineWidth(self):
223          """Return the default line width."""          """Return the default line width."""
# Line 207  class Classification: Line 233  class Classification:
233    
234          if len(self.groups) > 0 and isinstance(item, ClassGroupDefault):          if len(self.groups) > 0 and isinstance(item, ClassGroupDefault):
235              self.groups[0] = item              self.groups[0] = item
             #self.SetDefaultGroup(item)  
236          else:          else:
237              self.groups.append(item)              self.groups.append(item)
238    
239          self.__SendMessage(LAYER_LEGEND_CHANGED)          self.__SendNotification()
240    
241      def GetGroup(self, value):      def GetGroup(self, value):
242          """Return the associated group, or the default group.          """Return the associated group, or the default group.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26