[GRASS-SVN] r32072 - in grass/trunk/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 10 13:53:06 EDT 2008


Author: martinl
Date: 2008-07-10 13:53:06 -0400 (Thu, 10 Jul 2008)
New Revision: 32072

Modified:
   grass/trunk/gui/wxpython/gui_modules/nviz.py
   grass/trunk/gui/wxpython/gui_modules/workspace.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
nviz2/wxGUI: workspace file definition (gxw) extended for Nviz properties (in progress)"


Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-10 12:20:08 UTC (rev 32071)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-10 17:53:06 UTC (rev 32072)
@@ -1439,52 +1439,6 @@
             file = UserSettings.SaveToFile(fileSettings)
             self.lmgr.goutput.WriteLog(_('Nviz settings saved to file <%s>.') % file)
 
-#             #
-#             # surface attributes
-#             #
-#             data['attribute'] = {}
-#             for attrb in ('topo', 'color', 'mask',
-#                          'transp', 'shine', 'emit'):
-#                 use = self.FindWindowById(self.win['surface'][attrb]['use']).GetSelection()
-#                 if self.win['surface'][attrb]['required']: # map, constant
-#                     if use == 0: # map
-#                         map = True
-#                     elif use == 1: # constant
-#                         map = False
-#                 else: # unset, map, constant
-#                     if use == 0: # unset
-#                         map = None
-#                     elif use == 1: # map
-#                         map = True
-#                     elif use == 2: # constant
-#                         map = False
-
-#                 if map is None:
-#                     continue
-
-#                 if map:
-#                     value = self.FindWindowById(self.win['surface'][attrb]['map']).GetValue()
-#                 else:
-#                     if attrb == 'color':
-#                         value = self.FindWindowById(self.win['surface'][attrb]['map']).GetColour()
-#                     else:
-#                         value = self.FindWindowById(self.win['surface'][attrb]['const']).GetValue()
-                    
-#                 data['attribute'][attrb] = {}
-#                 data['attribute'][attrb]['map'] = map
-#                 data['attribute'][attrb]['value'] = value
-
-#             #
-#             # draw
-#             #
-#             data['draw'] = {}
-#             for control in ('mode', 'shading', 'style'):
-#                 data['draw'][control] = self.FindWindowById(self.win['surface']['draw'][control]).GetSelection()
-#             for control in ('res-coarse', 'res-fine'):
-#                 data['draw'][control] = self.FindWindowById(self.win['surface']['draw'][control]).GetValue()
-            
-#         self.mapWindow.SetLayerSettings(data)
-
     def UpdateLayerProperties(self):
         """Update data layer properties"""
         mapLayer = self.mapWindow.GetSelectedLayer()
@@ -1510,7 +1464,8 @@
         for attrb in ('topo', 'color', 'mask',
                      'transp', 'shine', 'emit'):
             if self.mapWindow.update['surface']['attribute'].has_key(attrb):
-                map, value = self.mapWindow.update['surface']['attribute'][attrb]
+                map = self.mapWindow.update['surface']['attribute'][attrb]['map']
+                value = self.mapWindow.update['surface']['attribute'][attrb]['value']
                 if map is None: # unset
                     # only optional attributes
                     if attrb == 'mask':
@@ -1586,8 +1541,9 @@
     def UpdateVectorProperties(self, id, data):
         """Apply changes for vector"""
         if self.mapWindow.update['vector']['lines'].has_key('mode'):
-            width, color, flat = self.mapWindow.update['vector']['lines']['mode']
-            self.mapWindow.nvizClass.SetVectorLineMode(id, color, width, flat)
+            attrb = self.mapWindow.update['vector']['lines']['mode']
+            self.mapWindow.nvizClass.SetVectorLineMode(id, attrb['color'],
+                                                       attrb['width'], attrb['flat'][0])
             
         if self.mapWindow.update['vector']['lines'].has_key('height'):
             height = self.mapWindow.update['vector']['lines']['height']
@@ -1649,7 +1605,9 @@
 
         self.SetSurfaceUseMap(attrb, useMap)
         
-        self.mapWindow.update['surface']['attribute'][attrb] = (useMap, str(value))
+        self.mapWindow.update['surface']['attribute'][attrb] = { 'map' : useMap,
+                                                                 'value' : str(value),
+                                                                 }
         self.UpdateLayerProperties()
 
         if self.parent.autoRender.IsChecked():
@@ -1706,7 +1664,9 @@
             map = False
 
         if self.pageUpdated: # do not update when selection is changed
-            self.mapWindow.update['surface']['attribute'][attrb] = (map, str(value))
+            self.mapWindow.update['surface']['attribute'][attrb] = { 'map' : map,
+                                                                     'value' : str(value),
+                                                                     }
             self.UpdateLayerProperties()
 
             if self.parent.autoRender.IsChecked():
@@ -1857,10 +1817,15 @@
 
         if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
             flat = False
+            map = ''
         else:
             flat = True
+            map = ''
 
-        self.mapWindow.update['vector']['lines']['mode'] = (width, color, flat)
+        self.mapWindow.update['vector']['lines']['mode'] = { 'width' : width,
+                                                             'color' : color,
+                                                             'flat' : (flat, map)
+                                                             }
         self.UpdateLayerProperties()
                 
         if self.parent.autoRender.IsChecked():

Modified: grass/trunk/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/workspace.py	2008-07-10 12:20:08 UTC (rev 32071)
+++ grass/trunk/gui/wxpython/gui_modules/workspace.py	2008-07-10 17:53:06 UTC (rev 32072)
@@ -5,6 +5,7 @@
 
 Classes:
  - ProcessWorkspaceFile
+ - WriteWorkspaceFile
  - ProcessGrcFile
 
 (C) 2007-2008 by the GRASS Development Team
@@ -47,10 +48,19 @@
         self.inDisplay   = False
         self.inLayerManager = False
 
+        #
+        # Nviz section
+        #
+        self.inNviz = False
+        self.inAttribute = False
+
+        #
         # layer manager properties
+        #
         self.layerManager = {}
         self.layerManager['pos'] = None # window position
         self.layerManager['size'] = None # window size
+
         # list of mapdisplays
         self.displays = []
         # list of map layers
@@ -153,6 +163,15 @@
             else:
                 pass
 
+        #
+        # Nviz section
+        #
+        elif name == 'nviz':
+            self.inNviz = True
+
+        elif name == 'attribute':
+            self.inAttribute = True
+
     def endElement(self, name):
         if name == 'gxw':
             self.inGxw = False
@@ -201,6 +220,15 @@
         elif name == 'layer_manager':
             self.inLayerManager = False
 
+        #
+        # Nviz section
+        #
+        elif name == 'nviz':
+            self.inNviz = False
+        
+        elif name == 'attribute':
+            self.inAttribute = False
+
     def characters(self, ch):
         self.my_characters(ch)
 
@@ -208,6 +236,217 @@
         if self.inValue:
             self.value += ch
 
+class WriteWorkspaceFile(object):
+    """Generic class for writing workspace file"""
+    def __init__(self, lmgr, file):
+        self.file =  file
+        self.lmgr = lmgr
+        self.indent = 0
+
+        # write header
+        self.file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
+        self.file.write('<!DOCTYPE gxw SYSTEM "grass-gxw.dtd">\n')
+        self.file.write('%s<gxw>\n' % (' ' * self.indent))
+        
+        self.indent =+ 4
+        
+        # layer manager
+        windowPos = self.lmgr.GetPosition()
+        windowSize = self.lmgr.GetSize()
+        file.write('%s<layer_manager dim="%d,%d,%d,%d">\n' % (' ' * self.indent,
+                                                              windowPos[0],
+                                                              windowPos[1],
+                                                              windowSize[0],
+                                                              windowSize[1]
+                                                              ))
+        
+        file.write('%s</layer_manager>\n' % (' ' * self.indent))
+        
+        # list of displays
+        for page in range(0, self.lmgr.gm_cb.GetPageCount()):
+            mapTree = self.lmgr.gm_cb.GetPage(page).maptree
+            region = mapTree.Map.region
+            
+            displayPos = mapTree.mapdisplay.GetPosition()
+            displaySize = mapTree.mapdisplay.GetSize()
+            
+            file.write('%s<display render="%d" '
+                       'mode="%d" showCompExtent="%d" '
+                       'dim="%d,%d,%d,%d" '
+                       'extent="%f,%f,%f,%f">\n' % (' ' * self.indent,
+                                                    int(mapTree.mapdisplay.autoRender.IsChecked()),
+                                                    mapTree.mapdisplay.toggleStatus.GetSelection(),
+                                                    int(mapTree.mapdisplay.showRegion.IsChecked()),
+                                                    displayPos[0],
+                                                    displayPos[1],
+                                                    displaySize[0],
+                                                    displaySize[1],
+                                                    region['w'],
+                                                    region['s'],
+                                                    region['e'],
+                                                    region['n']
+                                                    ))
+            
+            # list of layers
+            item = mapTree.GetFirstChild(mapTree.root)[0]
+            self.__writeLayer(mapTree, item)
+            file.write('%s</display>\n' % (' ' * self.indent))
+
+        self.indent =- 4
+        file.write('%s</gxw>\n' % (' ' * self.indent))
+
+    def __writeLayer(self, mapTree, item):
+        """Write bunch of layers to GRASS Workspace XML file"""
+        self.indent += 4
+        while item and item.IsOk():
+            type = mapTree.GetPyData(item)[0]['type']
+            if type != 'group':
+                maplayer = mapTree.GetPyData(item)[0]['maplayer']
+            else:
+                maplayer = None
+
+            checked = int(item.IsChecked())
+            cmd = mapTree.GetPyData(item)[0]['cmd']
+            if type == 'command':
+                self.file.write('%s<layer type="%s" name="%s" checked="%d">\n' % \
+                               (' ' * self.indent, type, ' '.join(cmd), checked));
+                self.file.write('%s</layer>\n' % (' ' * self.indent));
+            elif type == 'group':
+                name = mapTree.GetItemText(item)
+                self.file.write('%s<group name="%s" checked="%d">\n' % \
+                               (' ' * self.indent, name, checked));
+                self.indent += 4
+                subItem = mapTree.GetFirstChild(item)[0]
+                self.WriteLayer(subItem)
+                self.indent -= 4
+                self.file.write('%s</group>\n' % (' ' * self.indent));
+            else:
+                name = mapTree.GetItemText(item)
+                opacity = maplayer.GetOpacity(float=True)
+                self.file.write('%s<layer type="%s" name="%s" checked="%d" opacity="%f">\n' % \
+                               (' ' * self.indent, type, name, checked, opacity));
+
+                self.indent += 4
+                # selected ?
+                if item == mapTree.layer_selected:
+                    self.file.write('%s<selected />\n' % (' ' * self.indent))
+                # layer properties
+                self.file.write('%s<task name="%s">\n' % (' ' * self.indent, cmd[0]))
+                self.indent += 4
+                for option in cmd[1:]:
+                    if option[0] == '-': # flag
+                        self.file.write('%s<flag name="%s" />\n' %
+                                   (' ' * self.indent, option[1]))
+                    else: # parameter
+                        key, value = option.split('=', 1)
+                        self.file.write('%s<parameter name="%s">\n' %
+                                   (' ' * self.indent, key))
+                        self.indent += 4
+                        self.file.write('%s<value>%s</value>\n' %
+                                   (' ' * self.indent, value))
+                        self.indent -= 4
+                        self.file.write('%s</parameter>\n' % (' ' * self.indent));
+                self.indent -= 4
+                self.file.write('%s</task>\n' % (' ' * self.indent));
+                nviz = mapTree.GetPyData(item)[0]['nviz']
+                if nviz:
+                    self.file.write('%s<nviz>\n' % (' ' * self.indent));
+                    if maplayer.type == 'raster':
+                        self.__writeNvizSurface(nviz)
+                    elif maplayer.type == 'vector':
+                        self.__writeNvizVector(nviz)
+                    self.file.write('%s</nviz>\n' % (' ' * self.indent));
+                self.indent -= 4
+                self.file.write('%s</layer>\n' % (' ' * self.indent));
+            item = mapTree.GetNextSibling(item)
+        self.indent -= 4
+
+    def __writeNvizSurface(self, data):
+        """Save Nviz raster layer properties to workspace
+
+        @param data Nviz layer properties
+        """
+        self.indent += 4
+        for attrb in data.iterkeys():
+            if len(data[attrb]) < 1: # skip empty attributes
+                continue
+            for name in data[attrb].iterkeys():
+                # surface attribute
+                if attrb == 'attribute':
+                    self.file.write('%s<%s name="%s" map="%d">\n' % \
+                                   (' ' * self.indent, attrb, name, data[attrb][name]['map']))
+                    self.indent += 4
+                    self.file.write('%s<value>%s</value>\n' % (' ' * self.indent, data[attrb][name]['value']))
+                    self.indent -= 4
+            # draw mode
+            if attrb == 'draw':
+                self.file.write('%s<%s' %(' ' * self.indent, attrb))
+                resTag = None
+                for name in data[attrb]:
+                    if name == 'resolution':
+                        self.indent += 4
+                        resTag = ''
+                        for type, value in (('coarse', data[attrb][name][0]),
+                                            ('fine', data[attrb][name][1])):
+                            resTag += '%s<resolution type="%s">\n' % (' ' * self.indent, type)
+                            self.indent += 4
+                            resTag += '%s<value>%s</value>\n' % (' ' * self.indent, value)
+                            self.indent -= 4
+                            resTag += '%s</resolution>\n' % (' ' * self.indent)
+                        self.indent -= 4
+                    else:
+                        # note: second argument is 'all' -> skip
+                        self.file.write(' %s="%s"' % (name, data[attrb][name][0]))
+                self.file.write('>\n') # <draw ...>
+                if resTag:
+                    self.file.write(resTag)
+            # position
+            elif attrb == 'position':
+                self.file.write('%s<%s>\n' %(' ' * self.indent, attrb))
+                i = 0
+                for tag in ('x', 'y', 'z'):
+                    self.indent += 4
+                    self.file.write('%s<%s>%s<%s>\n' % (' ' * self.indent, tag,
+                                                   data[attrb][name][i], tag))
+                    i += 1
+                    self.indent -= 4
+            # end tag
+            self.file.write('%s<%s>\n' % (' ' * self.indent, attrb))
+        self.indent -= 4
+
+    def __writeNvizVector(self, data):
+        """Save Nviz vector layer properties to workspace
+
+        @param data Nviz layer properties
+        """
+        self.indent += 4
+        for attrb in data.iterkeys():
+            if len(data[attrb]) < 1: # skip empty attributes
+                continue
+            self.file.write('%s<%s>\n' % (' ' * self.indent, attrb))
+            self.indent += 4
+            for name in data[attrb].iterkeys():
+                self.file.write('%s<%s>' % (' ' * self.indent, name))
+                if type(data[attrb][name]) == type({}):
+                    self.file.write('\n')
+                    self.indent += 4
+                    for subname in data[attrb][name].iterkeys():
+                        if subname == 'flat':
+                            self.file.write('%s<style flat="%d">%s</style>\n' % (' ' * self.indent, 
+                                                                            data[attrb][name][subname][0],
+                                                                            data[attrb][name][subname][1]))
+                        else:
+                            self.file.write('%s<%s>%s</%s>\n' % (' ' * self.indent, subname,
+                                                            data[attrb][name][subname], subname))
+                    self.indent -= 4
+                    self.file.write('%s</%s>\n' % (' ' * self.indent, name))
+                else:
+                    self.file.write('%s</%s>\n' % (data[attrb][name], name))
+            self.indent -= 4
+            self.file.write('%s</%s>\n' % (' ' * self.indent, attrb))
+
+        self.indent -= 4
+
 class ProcessGrcFile(object):
     def __init__(self, filename):
         """Process GRC file"""

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2008-07-10 12:20:08 UTC (rev 32071)
+++ grass/trunk/gui/wxpython/wxgui.py	2008-07-10 17:53:06 UTC (rev 32072)
@@ -813,94 +813,6 @@
         else:
             self.OnWorkspaceSaveAs()
 
-    def WriteLayersToWorkspaceFile(self, file, mapTree, item):
-        """Write bunch of layers to GRASS Workspace XML file"""
-        self.indent += 4
-        while item and item.IsOk():
-            type = mapTree.GetPyData(item)[0]['type']
-            if type != 'group':
-                maplayer = mapTree.GetPyData(item)[0]['maplayer']
-            else:
-                maplayer = None
-
-            checked = int(item.IsChecked())
-            cmd = mapTree.GetPyData(item)[0]['cmd']
-            if type == 'command':
-                file.write('%s<layer type="%s" name="%s" checked="%d">\n' % \
-                               (' ' * self.indent, type, ' '.join(cmd), checked));
-                file.write('%s</layer>\n' % (' ' * self.indent));
-            elif type == 'group':
-                name = mapTree.GetItemText(item)
-                file.write('%s<group name="%s" checked="%d">\n' % \
-                               (' ' * self.indent, name, checked));
-                self.indent += 4
-                subItem = mapTree.GetFirstChild(item)[0]
-                self.WriteLayersToWorkspaceFile(file, mapTree, subItem)
-                self.indent -= 4
-                file.write('%s</group>\n' % (' ' * self.indent));
-            else:
-                name = mapTree.GetItemText(item)
-                opacity = maplayer.GetOpacity(float=True)
-                file.write('%s<layer type="%s" name="%s" checked="%d" opacity="%f">\n' % \
-                               (' ' * self.indent, type, name, checked, opacity));
-
-                self.indent += 4
-                # selected ?
-                if item == mapTree.layer_selected:
-                    file.write('%s<selected />\n' % (' ' * self.indent))
-                # layer properties
-                file.write('%s<task name="%s">\n' % (' ' * self.indent, cmd[0]))
-                self.indent += 4
-                for option in cmd[1:]:
-                    if option[0] == '-': # flag
-                        file.write('%s<flag name="%s" />\n' %
-                                   (' ' * self.indent, option[1]))
-                    else: # parameter
-                        key, value = option.split('=', 1)
-                        file.write('%s<parameter name="%s">\n' %
-                                   (' ' * self.indent, key))
-                        self.indent += 4
-                        file.write('%s<value>%s</value>\n' %
-                                   (' ' * self.indent, value))
-                        self.indent -= 4
-                        file.write('%s</parameter>\n' % (' ' * self.indent));
-                self.indent -= 4
-                file.write('%s</task>\n' % (' ' * self.indent));
-                nviz = mapTree.GetPyData(item)[0]['nviz']
-                if nviz:
-                    file.write('%s<nviz>\n' % (' ' * self.indent));
-                    self.WriteNvizToWorkspace(file, self.indent, nviz, type=maplayer.type)
-                    file.write('%s</nviz>\n' % (' ' * self.indent));
-                self.indent -= 4
-                file.write('%s</layer>\n' % (' ' * self.indent));
-            item = mapTree.GetNextSibling(item)
-        self.indent -= 4
-
-    def WriteNvizToWorkspace(self, file, indent, data, type):
-        """Save Nviz layer properties to workspace
-
-        @param file file stream
-        @param indent indentation value
-        @param data Nviz layer properties
-        @param type map layer type ('raster' or 'vector')
-        """
-        indent += 4
-        if type == 'raster':
-            for attrb in data.iterkeys():
-                if len(data[attrb]) < 1: # skip empty attributes
-                    continue
-                for name in data[attrb].iterkeys():
-                    if attrb == 'attribute': # surface attribute
-                        map, value = data[attrb][name]
-                        print '%s<%s name="%s" map="%d">\n' % \
-                            (' ' * indent, attrb, name, map)
-                    indent += 4
-                    print '%s<value>%s</value>\n' % (' ' * indent, value)
-                    indent -= 4
-                    print '%s<%s>\n' % (' ' * indent, attrb)
-        elif type == 'vector':
-            pass
-
     def SaveToWorkspaceFile(self, filename):
         """Save layer tree layout to workspace file
 
@@ -916,59 +828,7 @@
             return False
 
         try:
-            self.indent = 0 # number of spaces
-            # write header
-            file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
-            file.write('<!DOCTYPE gxw SYSTEM "grass-gxw.dtd">\n')
-            file.write('%s<gxw>\n' % (' ' * self.indent))
-            
-            self.indent =+ 4
-
-            # layer manager
-            windowPos = self.GetPosition()
-            windowSize = self.GetSize()
-            file.write('%s<layer_manager dim="%d,%d,%d,%d">\n' % (' ' * self.indent,
-                                                                  windowPos[0],
-                                                                  windowPos[1],
-                                                                  windowSize[0],
-                                                                  windowSize[1]
-                                                                  ))
-            
-            file.write('%s</layer_manager>\n' % (' ' * self.indent))
-
-            # list of displays
-            for page in range(0, self.gm_cb.GetPageCount()):
-                mapTree = self.gm_cb.GetPage(page).maptree
-                region = mapTree.Map.region
-
-                displayPos = mapTree.mapdisplay.GetPosition()
-                displaySize = mapTree.mapdisplay.GetSize()
-
-                file.write('%s<display render="%d" '
-                           'mode="%d" showCompExtent="%d" '
-                           'dim="%d,%d,%d,%d" '
-                           'extent="%f,%f,%f,%f">\n' % (' ' * self.indent,
-                                                      int(mapTree.mapdisplay.autoRender.IsChecked()),
-                                                      mapTree.mapdisplay.toggleStatus.GetSelection(),
-                                                      int(mapTree.mapdisplay.showRegion.IsChecked()),
-                                                      displayPos[0],
-                                                      displayPos[1],
-                                                      displaySize[0],
-                                                      displaySize[1],
-                                                      region['w'],
-                                                      region['s'],
-                                                      region['e'],
-                                                      region['n']
-                                                      ))
-
-                # list of layers
-                item = mapTree.GetFirstChild(mapTree.root)[0]
-                self.WriteLayersToWorkspaceFile(file, mapTree, item)
-                file.write('%s</display>\n' % (' ' * self.indent))
-
-            self.indent =- 4
-            file.write('%s</gxw>\n' % (' ' * self.indent))
-            del self.indent
+            workspace.WriteWorkspaceFile(lmgr=self, file=file)
         except StandardError, e:
             file.close()
             wx.MessageBox(parent=self,



More information about the grass-commit mailing list