/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/map.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/map.py

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

revision 245 by bh, Mon Jul 29 13:37:55 2002 UTC revision 374 by jan, Mon Jan 27 14:20:02 2003 UTC
# Line 11  from messages import LAYERS_CHANGED, MAP Line 11  from messages import LAYERS_CHANGED, MAP
11       CHANGED, LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \       CHANGED, LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \
12       LAYER_VISIBILITY_CHANGED       LAYER_VISIBILITY_CHANGED
13    
14    from Thuban import _
15    
16  from base import TitledObject, Modifiable  from base import TitledObject, Modifiable
17    
18  from label import LabelLayer  from label import LabelLayer
# Line 32  class Map(TitledObject, Modifiable): Line 34  class Map(TitledObject, Modifiable):
34                          Parameter: the map                          Parameter: the map
35      """      """
36    
37      forwarded_channels = (LAYER_PROJECTION_CHANGED,      forwarded_channels = (CHANGED,
38                              LAYER_PROJECTION_CHANGED,
39                            LAYER_LEGEND_CHANGED,                            LAYER_LEGEND_CHANGED,
40                            LAYER_VISIBILITY_CHANGED)                            LAYER_VISIBILITY_CHANGED)
41    
42      def __init__(self, title, projection = None):      def __init__(self, title, projection = None):
43          """Initialize the map."""          """Initialize the map."""
44          TitledObject.__init__(self, title)          TitledObject.__init__(self, title)
45            Modifiable.__init__(self)
46          self.layers = []          self.layers = []
47          self.label_layer = LabelLayer("Labels")          self.label_layer = LabelLayer(_("Labels"))
48          self.label_layer.Subscribe(CHANGED, self.forward, LAYERS_CHANGED)          self.label_layer.Subscribe(CHANGED, self.forward, LAYERS_CHANGED)
49          self.projection = projection          self.projection = projection
50    
51      def Destroy(self):      def Destroy(self):
52          for layer in self.layers:          # call Modifiable.Destroy first since it will call
53              self.unsubscribe_layer_channels(layer)          # Publisher.Destroy which removes all subscriptions. Otherwise
54              layer.Destroy()          # clearing the layers results in messages to be sent which can
55          self.label_layer.Unsubscribe(CHANGED, self.forward, LAYERS_CHANGED)          # cause problems.
56          Modifiable.Destroy(self)          Modifiable.Destroy(self)
57            self.ClearLayers()
58            self.label_layer.Unsubscribe(CHANGED, self.forward, LAYERS_CHANGED)
59            self.label_layer.Destroy()
60    
61      def AddLayer(self, layer):      def AddLayer(self, layer):
62            """Append layer to the map on top opf all."""
63          self.layers.append(layer)          self.layers.append(layer)
64          self.subscribe_layer_channels(layer)          self.subscribe_layer_channels(layer)
65          self.changed(LAYERS_CHANGED, self)          self.changed(LAYERS_CHANGED, self)
66    
67      def RemoveLayer(self, layer):      def RemoveLayer(self, layer):
68            """Remove layer from the map."""
69          self.unsubscribe_layer_channels(layer)          self.unsubscribe_layer_channels(layer)
70          self.layers.remove(layer)          self.layers.remove(layer)
71          self.changed(LAYERS_CHANGED, self)          self.changed(LAYERS_CHANGED, self)
72          layer.Destroy()          layer.Destroy()
73    
74        def CanRemoveLayer(self, layer):
75            """Return true if the layer can be deleted.
76    
77            The default implementation always returns 1. Derived classes
78            should override this method if they have e.g. special layers
79            that the user should not be able to remove.
80            """
81            return 1
82    
83        def ClearLayers(self):
84            """Delete all layers."""
85            for layer in self.layers:
86                self.unsubscribe_layer_channels(layer)
87                layer.Destroy()
88            del self.layers[:]
89            self.label_layer.ClearLabels()
90            self.changed(LAYERS_CHANGED, self)
91    
92      def subscribe_layer_channels(self, layer):      def subscribe_layer_channels(self, layer):
93          """Subscribe to some of layer's channels."""          """Subscribe to some of layer's channels."""
94          for channel in self.forwarded_channels:          for channel in self.forwarded_channels:
# Line 77  class Map(TitledObject, Modifiable): Line 104  class Map(TitledObject, Modifiable):
104          return self.label_layer          return self.label_layer
105    
106      def Layers(self):      def Layers(self):
107            """Return the list of layers contained in the map.
108    
109            The list does not include the label layer"""
110          return self.layers          return self.layers
111    
112      def HasLayers(self):      def HasLayers(self):
113            """Return true if the map has at least one shape layer"""
114          return len(self.layers) > 0          return len(self.layers) > 0
115    
116      def RaiseLayer(self, layer):      def RaiseLayer(self, layer):
117            """Swap the layer with the one above it.
118    
119            If the layer is already at the top do nothing. If the stacking
120            order has been changed, issue a LAYERS_CHANGED message.
121            """
122          index = self.layers.index(layer)          index = self.layers.index(layer)
123          if index < len(self.layers) - 1:          if index < len(self.layers) - 1:
124              del self.layers[index]              del self.layers[index]
125              self.layers.insert(index + 1, layer)              self.layers.insert(index + 1, layer)
126          self.changed(LAYERS_CHANGED, self)              self.changed(LAYERS_CHANGED, self)
127    
128      def LowerLayer(self, layer):      def LowerLayer(self, layer):
129            """Swap the layer with the one below it.
130    
131            If the layer is already at the bottom do nothing. If the
132            stacking order has been changed, issue a LAYERS_CHANGED message.
133            """
134          index = self.layers.index(layer)          index = self.layers.index(layer)
135          if index > 0:          if index > 0:
136              del self.layers[index]              del self.layers[index]
137              self.layers.insert(index - 1, layer)              self.layers.insert(index - 1, layer)
138          self.changed(LAYERS_CHANGED, self)              self.changed(LAYERS_CHANGED, self)
139    
140      def BoundingBox(self):      def BoundingBox(self):
141          """Return the bounding box of the map in projected coordinates.          """Return the bounding box of the map in Lat/Lon coordinates.
142    
143          Return None if there are no layers or no layer contains any shapes.          Return None if there are no layers or no layer contains any shapes.
144          """          """
# Line 126  class Map(TitledObject, Modifiable): Line 167  class Map(TitledObject, Modifiable):
167              return None              return None
168    
169      def ProjectedBoundingBox(self):      def ProjectedBoundingBox(self):
170            """Return the bounding box of the map in projected coordinates.
171    
172            Return None if there are no layers or no layer contains any shapes.
173            """
174          # This simply returns the rectangle given by the projected          # This simply returns the rectangle given by the projected
175          # corners of the non-projected bbox.          # corners of the non-projected bbox.
176          bbox = self.BoundingBox()          bbox = self.BoundingBox()
# Line 134  class Map(TitledObject, Modifiable): Line 179  class Map(TitledObject, Modifiable):
179          return bbox          return bbox
180    
181      def SetProjection(self, projection):      def SetProjection(self, projection):
182            """Set the projection of the map.
183    
184            Issue a MAP_PROJECTION_CHANGED message."""
185          self.projection = projection          self.projection = projection
186          self.changed(MAP_PROJECTION_CHANGED, self)          self.changed(MAP_PROJECTION_CHANGED, self)
187    
# Line 163  class Map(TitledObject, Modifiable): Line 211  class Map(TitledObject, Modifiable):
211      def TreeInfo(self):      def TreeInfo(self):
212          items = []          items = []
213          if self.BoundingBox() != None:          if self.BoundingBox() != None:
214              items.append("Extent (lat-lon): (%g, %g, %g, %g)"              items.append(_("Extent (lat-lon): (%g, %g, %g, %g)")
215                           % self.BoundingBox())                           % self.BoundingBox())
216              if self.projection and len(self.projection.params) > 0:              if self.projection and len(self.projection.params) > 0:
217                  items.append("Extent (projected): (%g, %g, %g, %g)"                  items.append(_("Extent (projected): (%g, %g, %g, %g)")
218                               % self.ProjectedBoundingBox())                               % self.ProjectedBoundingBox())
219                  items.append(("Projection",                  items.append((_("Projection"),
220                                [str(param)                                [str(param)
221                                 for param in self.projection.params]))                                 for param in self.projection.params]))
222    
# Line 176  class Map(TitledObject, Modifiable): Line 224  class Map(TitledObject, Modifiable):
224          layers.reverse()          layers.reverse()
225          items.extend(layers)          items.extend(layers)
226    
227          return ("Map: %s" % self.title, items)          return (_("Map: %s") % self.title, items)
228    

Legend:
Removed from v.245  
changed lines
  Added in v.374

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26