/[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 364 by jonathan, Mon Jan 27 11:47:12 2003 UTC revision 437 by jonathan, Thu Feb 27 15:53:21 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001, 2002 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4    # Jonathan Coles <[email protected]>
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 10  __version__ = "$Revision$" Line 11  __version__ = "$Revision$"
11  import os  import os
12  from math import log, ceil  from math import log, ceil
13    
14    from Thuban import _
15    
16  import shapelib, shptree  import shapelib, shptree
17    
18  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \  from messages import LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \
19       LAYER_VISIBILITY_CHANGED       LAYER_VISIBILITY_CHANGED
20    
21  from color import Color  from color import Color
 # Some predefined colors for internal use  
 _black = Color(0, 0, 0)  
22    
23  from classification import Classification  import classification
24    
25  from table import Table  from table import Table
26    
# Line 106  class Layer(BaseLayer): Line 107  class Layer(BaseLayer):
107      """      """
108    
109      def __init__(self, title, filename, projection = None,      def __init__(self, title, filename, projection = None,
110                   fill = None, stroke = _black, stroke_width = 1, visible = 1):                   fill = Color.None,
111                     stroke = Color.Black,
112                     stroke_width = 1,
113                     visible = 1):
114          """Initialize the layer.          """Initialize the layer.
115    
116          title -- the title          title -- the title
# Line 129  class Layer(BaseLayer): Line 133  class Layer(BaseLayer):
133          self.filename = os.path.abspath(filename)          self.filename = os.path.abspath(filename)
134    
135          self.projection = projection          self.projection = projection
         self.fill = fill  
         self.stroke = stroke  
         self.stroke_width = stroke_width  
136          self.shapefile = None          self.shapefile = None
137          self.shapetree = None          self.shapetree = None
138          self.open_shapefile()          self.open_shapefile()
# Line 141  class Layer(BaseLayer): Line 142  class Layer(BaseLayer):
142          self.shapetable = Table(filename)          self.shapetable = Table(filename)
143          self.table = self.shapetable          self.table = self.shapetable
144    
145          self.classification = Classification()          self.__classification = classification.Classification(self)
146          self.classification.setNull(          self.__classification.SetDefaultStroke(stroke)
147              {'stroke':stroke, 'stroke_width':stroke_width, 'fill':fill})          self.__classification.SetDefaultStrokeWidth(stroke_width)
148            self.__classification.SetDefaultFill(fill)
149    
150            self.UnsetModified()
151    
152      def open_shapefile(self):      def open_shapefile(self):
153          if self.shapefile is None:          if self.shapefile is None:
# Line 246  class Layer(BaseLayer): Line 250  class Layer(BaseLayer):
250          self.projection = projection          self.projection = projection
251          self.changed(LAYER_PROJECTION_CHANGED, self)          self.changed(LAYER_PROJECTION_CHANGED, self)
252    
253      def SetFill(self, fill):      def GetClassification(self):
254          """Set the layer's fill color. None means the shapes are not filled"""          return self.__classification
         self.fill = fill  
         self.changed(LAYER_LEGEND_CHANGED, self)  
   
     def SetStroke(self, stroke):  
         """Set the layer's stroke color. None means the shapes are not  
         stroked."""  
         self.stroke = stroke  
         self.changed(LAYER_LEGEND_CHANGED, self)  
255    
256      def SetStrokeWidth(self, width):      def SetClassification(self, clazz):
257          """Set the layer's stroke width."""          self.__classification = clazz
         self.stroke_width = width  
258          self.changed(LAYER_LEGEND_CHANGED, self)          self.changed(LAYER_LEGEND_CHANGED, self)
259    
260      def TreeInfo(self):      def TreeInfo(self):
261          items = []          items = []
262    
263          if self.Visible():          if self.Visible():
264              items.append("Shown")              items.append(_("Shown"))
265          else:          else:
266              items.append("Hidden")              items.append(_("Hidden"))
267          items.append("Shapes: %d" % self.NumShapes())          items.append(_("Shapes: %d") % self.NumShapes())
268    
269          bbox = self.LatLongBoundingBox()          bbox = self.LatLongBoundingBox()
270          if bbox is not None:          if bbox is not None:
271              items.append("Extent (lat-lon): (%g, %g, %g, %g)" % bbox)              items.append(_("Extent (lat-lon): (%g, %g, %g, %g)") % bbox)
272          else:          else:
273              items.append("Extent (lat-lon):")              items.append(_("Extent (lat-lon):"))
274          items.append("Shapetype: %s" % shapetype_names[self.ShapeType()])          items.append(_("Shapetype: %s") % shapetype_names[self.ShapeType()])
275    
276            items.append(self.__classification)
277    
278          def color_string(color):          return (_("Layer '%s'") % self.Title(), items)
             if color is None:  
                 return "None"  
             return "(%.3f, %.3f, %.3f)" % (color.red, color.green, color.blue)  
         items.append("Fill: " + color_string(self.fill))  
         items.append("Outline: " + color_string(self.stroke))  
279    
         return ("Layer '%s'" % self.Title(), items)  

Legend:
Removed from v.364  
changed lines
  Added in v.437

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26