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

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

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

revision 429 by jonathan, Mon Feb 24 18:46:51 2003 UTC revision 466 by jonathan, Wed Mar 5 18:18:20 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 13  Functions to save a session to a file Line 13  Functions to save a session to a file
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    
16    # fix for people using python2.1
17    from __future__ import nested_scopes
18    
19  import os  import os
20  import string  import string
21    
# Line 54  class Saver: Line 57  class Saver:
57      """Class to serialize a session into an XML file.      """Class to serialize a session into an XML file.
58    
59      Applications built on top of Thuban may derive from this class and      Applications built on top of Thuban may derive from this class and
60      override or extend the methods to save additinal information. This      override or extend the methods to save additional information. This
61      additional information should take the form of additional attributes      additional information should take the form of additional attributes
62      or elements whose names are prefixed with a namespace. To define a      or elements whose names are prefixed with a namespace. To define a
63      namespace derived classes should extend the write_session method to      namespace derived classes should extend the write_session method to
# Line 100  class Saver: Line 103  class Saver:
103    
104      def write_attribs(self, attrs):      def write_attribs(self, attrs):
105          for name, value in attrs.items():          for name, value in attrs.items():
106              self.file.write(' %s="%s"' % (escape(name), value))              self.file.write(' %s="%s"' % (escape(name), escape(value)))
107            
108      def open_element(self, element, attrs = {}):      def open_element(self, element, attrs = {}):
109    
# Line 177  class Saver: Line 180  class Saver:
180          element, call write_layer for each layer contained in the map          element, call write_layer for each layer contained in the map
181          and finally call write_label_layer to write the label layer.          and finally call write_label_layer to write the label layer.
182          """          """
183          write = self.file.write          #write = self.file.write
184          self.open_element('map title="%s"' % escape(map.title))          self.open_element('map title="%s"' % escape(map.title))
185          self.write_projection(map.projection)          self.write_projection(map.projection)
186          for layer in map.Layers():          for layer in map.Layers():
# Line 208  class Saver: Line 211  class Saver:
211    
212          attrs["title"]        = layer.title          attrs["title"]        = layer.title
213          attrs["filename"]     = relative_filename(self.dir, layer.filename)          attrs["filename"]     = relative_filename(self.dir, layer.filename)
214          attrs["stroke"]       = lc.GetDefaultStroke().hex()          attrs["stroke"]       = lc.GetDefaultLineColor().hex()
215          attrs["stroke_width"] = str(lc.GetDefaultStrokeWidth())          attrs["stroke_width"] = str(lc.GetDefaultLineWidth())
216          attrs["fill"]         = lc.GetDefaultFill().hex()          attrs["fill"]         = lc.GetDefaultFill().hex()
217    
218          self.open_element("layer", attrs)          self.open_element("layer", attrs)
# Line 231  class Saver: Line 234  class Saver:
234          if field is None: return          if field is None: return
235    
236          attrs["field"] = field          attrs["field"] = field
237            attrs["field_type"] = str(lc.GetFieldType())
238          self.open_element("classification", attrs)          self.open_element("classification", attrs)
239    
240    
# Line 240  class Saver: Line 244  class Saver:
244                            
245          # just playing now with lambdas and dictionaries          # just playing now with lambdas and dictionaries
246    
247          types = {ClassData.DEFAULT:          types = [[lambda p: 'clnull',
248                       [lambda p: 'clnull',                    lambda p: 'clnull'],
249                        lambda p: 'clnull'],                   [lambda p: 'clpoint value="%s"' %
250                   ClassData.POINT:                               str(p.GetValue()),
251                       [lambda p: 'clpoint value="%s"' %                    lambda p: 'clpoint'],
252                                   str(p.GetValue()),                   [lambda p: 'clrange min="%s" max="%s"' %
253                        lambda p: 'clpoint'],                               (str(p.GetMin()),
254                   ClassData.RANGE:                                (str(p.GetMax()))),
255                       [lambda p: 'clrange min="%s" max="%s"' %                    lambda p: 'clrange']]
256                                   (str(p.GetMin()),  
257                                    (str(p.GetMax()))),          def write_class_group(group):
258                        lambda p: 'clrange']}              type = -1
259                if isinstance(group, ClassGroupDefault): type = 0
260          def write_class_data(data):              elif isinstance(group, ClassGroupSingleton): type = 1
261              dict = {'stroke'      : data.GetStroke().hex(),              elif isinstance(group, ClassGroupRange): type = 2
262                      'stroke_width': str(data.GetStrokeWidth()),              elif isinstance(group, ClassGroupMap):   type = 3
263                      'fill'        : data.GetFill().hex()}              assert(type >= 0)
264              t = data.GetType()  
265              self.open_element(types[t][0](data))              if type <= 2:
266              self.write_element("cldata", dict)                  data = group.GetProperties()
267              self.close_element(types[t][1](data))                  dict = {'stroke'      : data.GetLineColor().hex(),
268                            'stroke_width': str(data.GetLineWidth()),
269                            'fill'        : data.GetFill().hex()}
270    
271                    self.open_element(types[type][0](group))
272                    self.write_element("cldata", dict)
273                    self.close_element(types[type][1](group))
274                else: pass # XXX: we need to handle maps
275    
276          for i in lc:          for i in lc:
277              write_class_data(i)              write_class_group(i)
278    
279  #       for i in lc:  #       for i in lc:
280  #           t = i.GetType()  #           t = i.GetType()

Legend:
Removed from v.429  
changed lines
  Added in v.466

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26