/[thuban]/trunk/thuban/Thuban/Model/layer.py
ViewVC logotype

Diff of /trunk/thuban/Thuban/Model/layer.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1338 by jonathan, Tue Jul 1 16:10:00 2003 UTC revision 1452 by bh, Fri Jul 18 12:57:59 2003 UTC
# Line 15  from Thuban import _ Line 15  from Thuban import _
15  import shapelib, shptree  import shapelib, shptree
16    
17  from messages import LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \  from messages import LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \
18       LAYER_CHANGED, LAYER_SHAPESTORE_REPLACED       LAYER_CHANGED, LAYER_SHAPESTORE_REPLACED, CLASS_CHANGED
19    
20  import classification  import classification
21    
# Line 152  class Layer(BaseLayer): Line 152  class Layer(BaseLayer):
152                                   visible = visible,                                   visible = visible,
153                                   projection = projection)                                   projection = projection)
154    
         #  
         # this is really important so that when the classification class  
         # tries to set its parent layer the variable will exist  
         #  
155          self.__classification = None          self.__classification = None
156            self.store = None
157    
158          self.SetShapeStore(data)          self.SetShapeStore(data)
159    
160            self.classification_column = None
161            self.SetClassificationColumn(None)
162          self.SetClassification(None)          self.SetClassification(None)
163    
164          self.__classification.SetDefaultLineColor(stroke)          self.__classification.SetDefaultLineColor(stroke)
# Line 190  class Layer(BaseLayer): Line 189  class Layer(BaseLayer):
189          return value          return value
190    
191      def SetShapeStore(self, store):      def SetShapeStore(self, store):
192            # Set the classification to None if there is a classification
193            # and the new shapestore doesn't have a table with a suitable
194            # column, i.e one with the same name and type as before
195            # FIXME: Maybe we should keep it the same if the type is
196            # compatible enough such as FIELDTYPE_DOUBLE and FIELDTYPE_INT
197            if self.__classification is not None:
198                columnname = self.classification_column
199                columntype = self.GetFieldType(columnname)
200                table = store.Table()
201                if (columnname is not None
202                    and (not table.HasColumn(columnname)
203                         or table.Column(columnname).type != columntype)):
204                    self.SetClassification(None)
205    
206          self.store = store          self.store = store
207          shapefile = self.store.Shapefile()          shapefile = self.store.Shapefile()
208    
# Line 215  class Layer(BaseLayer): Line 228  class Layer(BaseLayer):
228    
229          self.shapetree = shptree.SHPTree(shapefile.cobject(), 2,          self.shapetree = shptree.SHPTree(shapefile.cobject(), 2,
230                                           maxdepth)                                           maxdepth)
         # Set the classification to None if there is a classification  
         # and the new shapestore doesn't have a table with a suitable  
         # column, i.e one with the same name and type as before  
         # FIXME: Maybe we should keep it the same if the type is  
         # compatible enough such as FIELDTYPE_DOUBLE and FIELDTYPE_INT  
         if self.__classification is not None:  
             fieldname = self.__classification.GetField()  
             fieldtype = self.__classification.GetFieldType()  
             table = self.store.Table()  
             if (fieldname is not None  
                 and (not table.HasColumn(fieldname)  
                      or table.Column(fieldname).type != fieldtype)):  
                 self.SetClassification(None)  
231          self.changed(LAYER_SHAPESTORE_REPLACED, self)          self.changed(LAYER_SHAPESTORE_REPLACED, self)
232    
233      def ShapeStore(self):      def ShapeStore(self):
# Line 235  class Layer(BaseLayer): Line 235  class Layer(BaseLayer):
235    
236      def Destroy(self):      def Destroy(self):
237          BaseLayer.Destroy(self)          BaseLayer.Destroy(self)
238          self.GetClassification()._set_layer(None)          if self.__classification is not None:
239                self.__classification.Unsubscribe(CLASS_CHANGED,
240                                                  self._classification_changed)
241    
242      def BoundingBox(self):      def BoundingBox(self):
243          """Return the layer's bounding box in the intrinsic coordinate system.          """Return the layer's bounding box in the intrinsic coordinate system.
# Line 292  class Layer(BaseLayer): Line 294  class Layer(BaseLayer):
294          return (min(llx), min(lly), max(urx), max(ury))          return (min(llx), min(lly), max(urx), max(ury))
295    
296      def GetFieldType(self, fieldName):      def GetFieldType(self, fieldName):
297          table = self.store.Table()          if self.store:
298          if table.HasColumn(fieldName):              table = self.store.Table()
299              return table.Column(fieldName).type              if table.HasColumn(fieldName):
300                    return table.Column(fieldName).type
301          return None          return None
302    
303      def HasShapes(self):      def HasShapes(self):
# Line 338  class Layer(BaseLayer): Line 341  class Layer(BaseLayer):
341    
342          return self.shapetree.find_shapes((left, bottom), (right, top))          return self.shapetree.find_shapes((left, bottom), (right, top))
343    
344        def GetClassificationColumn(self):
345            return self.classification_column
346    
347        def SetClassificationColumn(self, column):
348            """Set the column to classifiy on, or None. If column is not None
349            and the column does not exist in the table, raise a ValueError.
350            """
351            if column:
352                columnType = self.GetFieldType(column)
353                if columnType is None:
354                    raise ValueError()
355            changed = self.classification_column != column
356            self.classification_column = column
357            if changed:
358                self.changed(LAYER_CHANGED, self)
359    
360      def HasClassification(self):      def HasClassification(self):
361          return True          return True
362    
# Line 349  class Layer(BaseLayer): Line 368  class Layer(BaseLayer):
368    
369          If 'clazz' is None a default classification is created.          If 'clazz' is None a default classification is created.
370    
371          ValueError is raised if the classification's field name          This issues a LAYER_CHANGED event.
         and type are different (if they aren't None) than what  
         is in the shapestore. The Layer will not be changed in  
         this case.  
372          """          """
373    
374          old_class = self.__classification          if self.__classification is not None:
375                self.__classification.Unsubscribe(CLASS_CHANGED,
376                                                  self._classification_changed)
377    
378          if clazz is None:          if clazz is None:
379              clazz = classification.Classification()              clazz = classification.Classification()
380    
381          try:          self.__classification = clazz
382              clazz._set_layer(self)          self.__classification.Subscribe(CLASS_CHANGED,
383                                            self._classification_changed)
384    
385              # only change things after a successful call          self._classification_changed()
             if old_class is not None:  
                 old_class._set_layer(None)  
             self.__classification = clazz  
         except ValueError:  
             raise ValueError  
   
         # we don't need this since a message will be sent  
         # after calling _set_layer()  
         #self.changed(LAYER_CHANGED, self)  
386    
387      def ClassChanged(self):      def _classification_changed(self):
388          """Called from the classification object when it has changed."""          """Called from the classification object when it has changed."""
389          self.changed(LAYER_CHANGED, self)          self.changed(LAYER_CHANGED, self)
390    

Legend:
Removed from v.1338  
changed lines
  Added in v.1452

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26