/[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 391 by jonathan, Mon Feb 10 15:26:11 2003 UTC revision 429 by jonathan, Mon Feb 24 18:46:51 2003 UTC
# Line 2  Line 2 
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
5    # Jonathan Coles <[email protected]>
6  #  #
7  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
8  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 19  import Thuban.Lib.fileutil Line 20  import Thuban.Lib.fileutil
20    
21  from Thuban.Model.color import Color  from Thuban.Model.color import Color
22    
23    from Thuban.Model.classification import *
24    
25  #  #
26  # one level of indention  # one level of indention
27  #  #
# Line 93  class Saver: Line 96  class Saver:
96          self.write_header()          self.write_header()
97          self.write_session(self.session)          self.write_session(self.session)
98    
99          if self.indent_level != 0:          assert(self.indent_level == 0)
             raise ValueError("indent_level still positive!")  
100    
101      def write_attribs(self, attrs):      def write_attribs(self, attrs):
102          for name, value in attrs.items():          for name, value in attrs.items():
103              if isinstance(value, Color):              self.file.write(' %s="%s"' % (escape(name), value))
                 value = value.hex()  
             else:  
                 value = str(value)  
             self.file.write(' %s="%s"' % (escape(name), escape(value)))  
104            
105      def open_element(self, element, attrs = {}):      def open_element(self, element, attrs = {}):
106    
# Line 126  class Saver: Line 124  class Saver:
124    
125      def close_element(self, element):      def close_element(self, element):
126          self.indent_level -= 1          self.indent_level -= 1
127          if self.indent_level < 0:          assert(self.indent_level >= 0)
             raise ValueError("close_element called too many times!")  
128    
129          # see open_element() for an explanation          # see open_element() for an explanation
130          if self.element_open == 1:          if self.element_open == 1:
# Line 204  class Saver: Line 201  class Saver:
201          given, should be a mapping from attribute names to attribute          given, should be a mapping from attribute names to attribute
202          values. The values should not be XML-escaped yet.          values. The values should not be XML-escaped yet.
203          """          """
204          lc = layer.classification          lc = layer.GetClassification()
205    
206          if attrs is None:          if attrs is None:
207              attrs = {}              attrs = {}
208          attrs["title"] = layer.title  
209          attrs["filename"] = relative_filename(self.dir, layer.filename)          attrs["title"]        = layer.title
210            attrs["filename"]     = relative_filename(self.dir, layer.filename)
211            attrs["stroke"]       = lc.GetDefaultStroke().hex()
212          attrs["stroke_width"] = str(lc.GetDefaultStrokeWidth())          attrs["stroke_width"] = str(lc.GetDefaultStrokeWidth())
213          fill = lc.GetDefaultFill()          attrs["fill"]         = lc.GetDefaultFill().hex()
         if fill is None:  
             attrs["fill"] = "None"  
         else:  
             attrs["fill"] = fill.hex()  
         stroke = lc.GetDefaultStroke()  
         if stroke is None:  
             attrs["stroke"] = "None"  
         else:  
             attrs["stroke"] = stroke.hex()  
214    
215          self.open_element("layer", attrs)          self.open_element("layer", attrs)
216          self.write_classification(layer)          self.write_classification(layer)
# Line 230  class Saver: Line 220  class Saver:
220          if attrs is None:          if attrs is None:
221              attrs = {}              attrs = {}
222    
223          lc = layer.classification          lc = layer.GetClassification()
224    
225          field = lc.field          field = lc.GetField()
226    
227          #          #
228          # there isn't a classification of anything          # there isn't a classification of anything
# Line 243  class Saver: Line 233  class Saver:
233          attrs["field"] = field          attrs["field"] = field
234          self.open_element("classification", attrs)          self.open_element("classification", attrs)
235    
236    
237    #       self.open_element("clnull")
238    #       write_class_data(lc.GetDefaultData())
239    #       self.close_element("clnull")
240                
241            # just playing now with lambdas and dictionaries
242    
243            types = {ClassData.DEFAULT:
244                         [lambda p: 'clnull',
245                          lambda p: 'clnull'],
246                     ClassData.POINT:
247                         [lambda p: 'clpoint value="%s"' %
248                                     str(p.GetValue()),
249                          lambda p: 'clpoint'],
250                     ClassData.RANGE:
251                         [lambda p: 'clrange min="%s" max="%s"' %
252                                     (str(p.GetMin()),
253                                      (str(p.GetMax()))),
254                          lambda p: 'clrange']}
255    
256          def write_class_data(data):          def write_class_data(data):
257              dict = {'stroke'      : data.GetStroke(),              dict = {'stroke'      : data.GetStroke().hex(),
258                      'stroke_width': data.GetStrokeWidth(),                      'stroke_width': str(data.GetStrokeWidth()),
259                      'fill'        : data.GetFill()}                      'fill'        : data.GetFill().hex()}
260                t = data.GetType()
261                self.open_element(types[t][0](data))
262              self.write_element("cldata", dict)              self.write_element("cldata", dict)
263                self.close_element(types[t][1](data))
264    
265            for i in lc:
266                write_class_data(i)
267    
268          self.open_element("clnull")  #       for i in lc:
269          write_class_data(lc.GetDefaultData())  #           t = i.GetType()
270          self.close_element("clnull")  #           self.open_element(types[t][0](i))
271    #           write_class_data(i)
272    #           self.close_element(types[t][1](i))
273    
274    #       for p in lc:
275    #           type = p.GetType()
276    #           if p == ClassData.DEFAULT:
277    #               lopen = lclose = 'clnull'
278    #           elif p == ClassData.POINTS:
279    #               lopen = 'clpoint value="%s"' % escape(str(p.GetValue()))
280    #               lclose = 'clpoint'
281    #           elif p == ClassData.RANGES:
282    #               lopen = 'clrange min="%s" max="%s"'
283    #                   % (escape(str(p.GetMin())), escape(str(p.GetMax()))))
284    #               lclose = 'clrange'
285    
286    #           self.open_element(lopen)
287    #           write_class_data(p)
288    #           self.close_element(lclose)
289                            
290          if lc.points != {}:  #       if lc.points != {}:
291              for value, data in lc.points.items():  #           for p in lc.points.values():
292                  self.open_element('clpoint value="%s"' % (escape(str(value))))  #               self.open_element('clpoint value="%s"' %
293                  write_class_data(data)  #                   (escape(str(p.GetValue()))))
294                  self.close_element('clpoint')  #               write_class_data(p)
295              #               self.close_element('clpoint')
296          if lc.ranges != []:  #          
297              for p in lc.ranges:  #       if lc.ranges != []:
298                  self.open_element('clrange min="%s" max="%s"'  #           for p in lc.ranges:
299                      % (escape(str(p[0])), escape(str(p[1]))))  #               self.open_element('clrange min="%s" max="%s"'
300                  write_class_data(p[2])  #                   % (escape(str(p.GetMin())), escape(str(p.GetMax()))))
301                  self.close_element('clrange')  #               write_class_data(p)
302    #               self.close_element('clrange')
303    
304          self.close_element("classification")          self.close_element("classification")
305    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26