[GRASS-SVN] r58543 - in grass/trunk/gui/wxpython: animation core lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Dec 28 20:35:32 PST 2013


Author: annakrat
Date: 2013-12-28 20:35:32 -0800 (Sat, 28 Dec 2013)
New Revision: 58543

Modified:
   grass/trunk/gui/wxpython/animation/controller.py
   grass/trunk/gui/wxpython/animation/data.py
   grass/trunk/gui/wxpython/animation/dialogs.py
   grass/trunk/gui/wxpython/animation/nviztask.py
   grass/trunk/gui/wxpython/animation/provider.py
   grass/trunk/gui/wxpython/core/layerlist.py
   grass/trunk/gui/wxpython/core/workspace.py
   grass/trunk/gui/wxpython/lmgr/frame.py
Log:
wxGUI/animation: enable volume animation; volumes now saved also in workspace file

Modified: grass/trunk/gui/wxpython/animation/controller.py
===================================================================
--- grass/trunk/gui/wxpython/animation/controller.py	2013-12-28 16:33:57 UTC (rev 58542)
+++ grass/trunk/gui/wxpython/animation/controller.py	2013-12-29 04:35:32 UTC (rev 58543)
@@ -397,7 +397,7 @@
         for anim in animationData:
             for layer in anim.layerList:
                 if layer.active and hasattr(layer, 'maps'):
-                    if layer.mapType in ('strds', 'stvds'):
+                    if layer.mapType in ('strds', 'stvds', 'str3ds'):
                         stds += 1
                     else:
                         maps += 1

Modified: grass/trunk/gui/wxpython/animation/data.py
===================================================================
--- grass/trunk/gui/wxpython/animation/data.py	2013-12-28 16:33:57 UTC (rev 58542)
+++ grass/trunk/gui/wxpython/animation/data.py	2013-12-29 04:35:32 UTC (rev 58543)
@@ -76,7 +76,7 @@
         timeseriesList = []
         for layer in layerList:
             if layer.active and hasattr(layer, 'maps'):
-                if layer.mapType in ('strds', 'stvds'):
+                if layer.mapType in ('strds', 'stvds', 'str3ds'):
                     timeseriesList.append((layer.name, layer.mapType))
                     self._firstStdsNameType = layer.name, layer.mapType
                 else:
@@ -189,7 +189,7 @@
     or series of maps."""
     def __init__(self):
         Layer.__init__(self)
-        self._mapTypes.extend(['strds', 'stvds'])
+        self._mapTypes.extend(['strds', 'stvds', 'str3ds'])
         self._maps = []
         tgis.init()
 
@@ -197,14 +197,14 @@
         if not self.hidden:
             if self._mapType is None:
                 raise ValueError("To set layer name, the type of layer must be specified.")
-            if self._mapType in ('strds', 'stvds'):
+            if self._mapType in ('strds', 'stvds', 'str3ds'):
                 try:
                     name = validateTimeseriesName(name, self._mapType)
                     self._maps = getRegisteredMaps(name, self._mapType)
                 except (GException, gcore.ScriptError), e:
                     raise ValueError(str(e))
             else:
-                self._maps = validateMapNames(name.split(','), self._internalTypes[self._mapType])
+                self._maps = validateMapNames(name.split(','), self._mapType)
         self._name = name
         self.label = name
 

Modified: grass/trunk/gui/wxpython/animation/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/animation/dialogs.py	2013-12-28 16:33:57 UTC (rev 58542)
+++ grass/trunk/gui/wxpython/animation/dialogs.py	2013-12-29 04:35:32 UTC (rev 58543)
@@ -434,10 +434,6 @@
         else:
             cmd = ['d.legend', 'at=5,50,2,5']
 
-            mapName = self._getLegendMapHint()
-            if mapName:
-                cmd.append("map=%s" % mapName)
-
         GUI(parent=self, modal=True).ParseCommand(cmd=cmd,
                                                   completed=(self.GetOptData, '', ''))
 
@@ -1102,6 +1098,7 @@
                  SIMPLE_LMGR_TB_TOP | SIMPLE_LMGR_STDS,
                  toolbarCls=AnimSimpleLmgrToolbar, modal=True):
         SimpleLayerManager.__init__(self, parent, layerList, lmgrStyle, toolbarCls, modal)
+        self._3dActivated = False
 
     def OnAddStds(self, event):
         """!Opens dialog for specifying temporal dataset.
@@ -1113,7 +1110,7 @@
         event.Skip()
 
     def SetStdsProperties(self, layer):
-        dlg = AddTemporalLayerDialog(parent=self, layer=layer)
+        dlg = AddTemporalLayerDialog(parent=self, layer=layer, volume=self._3dActivated)
         # first get hidden property, it's altered afterwards
         hidden = layer.hidden
         dlg.CenterOnParent()
@@ -1144,11 +1141,13 @@
         """!Activates/deactivates certain tool depending on 2D/3D view."""
         self._toolbar.EnableTools(['addRaster', 'addVector',
                                    'opacity', 'up', 'down'], not activate)
+        self._3dActivated = activate
 
 
 class AddTemporalLayerDialog(wx.Dialog):
     """!Dialog for adding space-time dataset/ map series."""
-    def __init__(self, parent, layer, title=_("Add space-time dataset layer")):
+    def __init__(self, parent, layer, volume=False,
+                 title=_("Add space-time dataset layer")):
         wx.Dialog.__init__(self, parent=parent, title=title)
 
         self.layer = layer
@@ -1168,8 +1167,13 @@
 
         types = [('rast', _("Multiple raster maps")),
                  ('vect', _("Multiple vector maps")),
+                 ('rast3d', _("Multiple 3D raster maps")),
                  ('strds', _("Space time raster dataset")),
-                 ('stvds', _("Space time vector dataset"))]
+                 ('stvds', _("Space time vector dataset")),
+                 ('str3ds', _("Space time 3D raster dataset"))]
+        if not volume:
+            del types[5]
+            del types[2]
         self._types = dict(types)
 
         self.tchoice = wx.Choice(parent=self)
@@ -1237,7 +1241,7 @@
         if typeName:
             self.tchoice.SetStringSelection(self._types[typeName])
             self.tselect.SetType(typeName)
-            if typeName in ('strds', 'stvds'):
+            if typeName in ('strds', 'stvds', 'str3ds'):
                 self.tselect.SetType(typeName, multiple=False)
                 self.addManyMapsButton.Disable()
             else:
@@ -1247,7 +1251,7 @@
             self.tselect.SetValue('')
         else:
             typeName = self.tchoice.GetClientData(self.tchoice.GetSelection())
-            if typeName in ('strds', 'stvds'):
+            if typeName in ('strds', 'stvds', 'str3ds'):
                 self.tselect.SetType(typeName, multiple=False)
                 self.addManyMapsButton.Disable()
             else:
@@ -1264,8 +1268,10 @@
             cmd.append('d.rast')
         elif self._mapType in ('vect', 'stvds'):
             cmd.append('d.vect')
+        elif self._mapType in ('rast3d', 'str3ds'):
+            cmd.append('d.rast3d')
         if self._name:
-            if self._mapType in ('rast', 'vect'):
+            if self._mapType in ('rast', 'vect', 'rast3d'):
                 cmd.append('map={}'.format(self._name.split(',')[0]))
             else:
                 try:
@@ -1281,7 +1287,13 @@
         dlg = MapLayersDialog(self, title=_("Select raster/vector maps."))
         dlg.applyAddingMapLayers.connect(lambda mapLayers:
                                          self.tselect.SetValue(','.join(mapLayers)))
-        index = 0 if self._mapType == 'rast' else 1
+        if self._mapType == 'rast':
+            index = 0
+        elif self._mapType == 'vect':
+            index = 2
+        else:  # rast3d
+            index = 1
+
         dlg.layerType.SetSelection(index)
         dlg.LoadMapLayers(dlg.GetLayerType(cmd=True),
                           dlg.mapset.GetStringSelection())

Modified: grass/trunk/gui/wxpython/animation/nviztask.py
===================================================================
--- grass/trunk/gui/wxpython/animation/nviztask.py	2013-12-28 16:33:57 UTC (rev 58542)
+++ grass/trunk/gui/wxpython/animation/nviztask.py	2013-12-29 04:35:32 UTC (rev 58543)
@@ -61,7 +61,9 @@
         for display in root.displays:
             if display['viewMode'] == '3d':
                 self.region['w'], self.region['s'],\
-                self.region['e'], self.region['n'] = display['extent']
+                self.region['e'], self.region['n'],\
+                self.region['b'], self.region['t'] = display['extent']
+                self.region['tbres'] = display['tbres']
 
     def _processLayers(self, layers):
         for layer in layers:
@@ -77,6 +79,8 @@
 
             if 'surface' in layer['nviz']:
                 self._processSurface(layer['nviz']['surface'], mapName=layerName)
+            if 'volume' in layer['nviz']:
+                self._processVolume(layer['nviz']['volume'], mapName=layerName)
 
     def _processSurface(self, surface, mapName):
         self._setMultiTaskParam('elevation_map', mapName)
@@ -124,6 +128,68 @@
         value = ','.join(pos)
         self._setMultiTaskParam('surface_position', value)
 
+    def _processVolume(self, volume, mapName):
+        self._setMultiTaskParam('volume', mapName)
+
+        if volume['draw']['box']['enabled']:
+            self.task.set_flag('b', True)
+
+        # isosurfaces
+        isosurfaces = volume['isosurface']
+        if isosurfaces:
+            res_value = volume['draw']['resolution']['isosurface']['value']
+            self._setMultiTaskParam('volume_resolution', res_value)
+            for isosurface in isosurfaces:
+                attributes = ('topo', 'color', 'shine', 'transp')
+                parameters = ((None, 'isosurf_level'),
+                              ('isosurf_color_map', 'isosurf_color_value'),
+                              ('isosurf_shininess_map', 'isosurf_shininess_value'),
+                              ('isosurf_transparency_map', 'isosurf_transparency_value'))
+                for attr, params in zip(attributes, parameters):
+                    mapname = None
+                    const = None
+                    if attr in isosurface:
+                        if isosurface[attr]['map']:
+                            mapname = isosurface[attr]['value']
+                        else:
+                            const = float(isosurface[attr]['value'])
+                    else:
+                        if attr == 'transp':
+                            const = 0
+                        elif attr == 'color':
+                            mapname = mapName
+
+                    if mapname:
+                        self._setMultiTaskParam(params[0], mapname)
+                    else:
+                        if attr == 'topo':
+                            # TODO: we just assume it's the first volume, what to do else?
+                            self._setMultiTaskParam(params[1], '1:' + str(const))
+                        else:
+                            self._setMultiTaskParam(params[1], const)
+                if isosurface['inout']['value']:
+                    self.task.set_flag('n', True)
+        # slices
+        slices = volume['slice']
+        if slices:
+            res_value = volume['draw']['resolution']['slice']['value']
+            self._setMultiTaskParam('volume_resolution', res_value)
+            for slice_ in slices:
+                self._setMultiTaskParam('slice_transparency', slice_['transp']['value'])
+                axis = slice_['position']['axis']
+                self._setMultiTaskParam('slice', '1:' + 'xyz'[axis])
+                pos = slice_['position']
+                coords = pos['x1'], pos['x2'], pos['y1'], pos['y2'], pos['z1'], pos['z2']
+                self._setMultiTaskParam('slice_position', ','.join([str(c) for c in coords]))
+
+        # position
+        pos = []
+        for coor in ('x', 'y', 'z'):
+            pos.append(str(volume['position'][coor]))
+            value = ','.join(pos)
+
+        self._setMultiTaskParam('volume_position', value)
+
     def _processState(self, state):
         color = state['view']['background']['color']
         self.task.set_param('bgcolor', self._join(color, delim=':'))
@@ -163,7 +229,7 @@
         # params = self.task.get_list_params()
         # parameter with 'map' name
         # params = filter(lambda x: 'map' in x, params)
-        return ('elevation_map', 'color_map', 'vline', 'vpoint')
+        return ('elevation_map', 'color_map', 'vline', 'vpoint', 'volume')
 
     def GetCommandSeries(self, layerList, paramName):
         commands = []

Modified: grass/trunk/gui/wxpython/animation/provider.py
===================================================================
--- grass/trunk/gui/wxpython/animation/provider.py	2013-12-28 16:33:57 UTC (rev 58542)
+++ grass/trunk/gui/wxpython/animation/provider.py	2013-12-29 04:35:32 UTC (rev 58543)
@@ -202,7 +202,7 @@
             self.compositionFinished.emit()
         if self._cmds3D:
             for cmd in self._cmds3D:
-                self._bitmapPool[HashCmd(cmd)] = \
+                self._bitmapPool[HashCmds([cmd])] = \
                     wx.Bitmap(GetFileFromCmd(self._tempDir, cmd))
 
         self.mapsLoaded.emit()
@@ -311,7 +311,9 @@
             q = Queue()
             # The separate render process
             if cmd[0] == 'm.nviz.image':
-                p = Process(target=self.RenderProcess3D, args=(cmd, regionFor3D, bgcolor, q))
+                p = Process(target=RenderProcess3D,
+                            args=(self.imageWidth, self.imageHeight, self._tempDir,
+                                  cmd, regionFor3D, bgcolor, q))
             else:
                 p = Process(target=RenderProcess2D,
                             args=(self.imageWidth, self.imageHeight, self._tempDir, cmd, bgcolor, q))
@@ -489,9 +491,9 @@
     """
 
     filename = GetFileFromCmd(tempDir, cmd)
-    os.environ['GRASS_REGION'] = gcore.region_env(**region)
+    os.environ['GRASS_REGION'] = gcore.region_env(region3d=True, **region)
+    Debug.msg(1, "Render image to file " + str(filename))
 
-    Debug.msg(1, "Render image to file " + str(filename))
     cmdTuple = CmdToTuple(cmd)
     cmdTuple[1]['output'] = os.path.splitext(filename)[0]
     # set size

Modified: grass/trunk/gui/wxpython/core/layerlist.py
===================================================================
--- grass/trunk/gui/wxpython/core/layerlist.py	2013-12-28 16:33:57 UTC (rev 58542)
+++ grass/trunk/gui/wxpython/core/layerlist.py	2013-12-29 04:35:32 UTC (rev 58543)
@@ -191,7 +191,7 @@
 
         self._mapTypes = ['rast', 'vect', 'rast3d']
         self._internalTypes = {'rast': 'cell',
-                               'vect': 'vect',
+                               'vect': 'vector',
                                'rast3d': 'grid3'}
 
     def GetName(self):

Modified: grass/trunk/gui/wxpython/core/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/core/workspace.py	2013-12-28 16:33:57 UTC (rev 58542)
+++ grass/trunk/gui/wxpython/core/workspace.py	2013-12-29 04:35:32 UTC (rev 58543)
@@ -25,6 +25,9 @@
 from core.gcmd      import EncodeString, GetDefaultEncoding
 from nviz.main      import NvizSettings
 
+from grass.script import core as gcore
+
+
 class ProcessWorkspaceFile:
     def __init__(self, tree):
         """!A ElementTree handler for the GXW XML file, as defined in
@@ -149,6 +152,7 @@
                     "pos"            : pos,
                     "size"           : size,
                     "extent"         : extent,
+                    "tbres"          : display.get('tbres', '0'),
                     "alignExtent"    : bool(int(display.get('alignExtent', "0"))),
                     "constrainRes"   : bool(int(display.get('constrainRes', "0"))),
                     "projection"     : projection,
@@ -275,175 +279,295 @@
         """
         # init nviz layer properties
         nviz = {}
-        if node_nviz.find('surface') is not None: # -> raster
+        if node_nviz.find('surface') is not None:  # -> raster
             nviz['surface'] = {}
             for sec in ('attribute', 'draw', 'position'):
                 nviz['surface'][sec] = {}
+            self.__processLayerNvizSurface(nviz, node_nviz.find('surface'))
+        elif node_nviz.find('volume') is not None:  # -> raster
+            nviz['volume'] = {}
+            for sec in ('attribute', 'draw', 'position'):
+                nviz['volume'][sec] = {}
+            self.__processLayerNvizVolume(nviz, node_nviz.find('volume'))
         elif node_nviz.find('vlines') is not None or \
-                node_nviz.find('vpoints') is not None: # -> vector
+                node_nviz.find('vpoints') is not None:  # -> vector
             nviz['vector'] = {}
             for sec in ('lines', 'points'):
                 nviz['vector'][sec] = {}
-        
-        if 'surface' in nviz:
-            node_surface = node_nviz.find('surface')
-            # attributes
-            for attrb in node_surface.findall('attribute'):
-                tagName = str(attrb.tag)
-                attrbName = attrb.get('name', '')
-                dc = nviz['surface'][tagName][attrbName] = {}
-                if attrb.get('map', '0') == '0':
-                    dc['map'] = False
-                else:
-                    dc['map'] = True
-                value = self.__getNodeText(attrb, 'value')
+            if node_nviz.find('vlines'):
+                self.__processLayerNvizVectorLines(nviz, node_nviz.find('vlines'))
+            if node_nviz.find('vpoints'):
+                self.__processLayerNvizVectorPoints(nviz, node_nviz.find('vpoints'))
+
+        return nviz
+
+    def __processLayerNvizSurface(self, nvizData, nodeSurface):
+        """!Process 3D layer settings - surface
+
+        @param nodeData nviz data dict
+        @param nodeSurface nviz surface node
+        """
+        # attributes
+        for attrb in nodeSurface.findall('attribute'):
+            tagName = str(attrb.tag)
+            attrbName = attrb.get('name', '')
+            dc = nvizData['surface'][tagName][attrbName] = {}
+            if attrb.get('map', '0') == '0':
+                dc['map'] = False
+            else:
+                dc['map'] = True
+            value = self.__getNodeText(attrb, 'value')
+            try:
+                dc['value'] = int(value)
+            except ValueError:
                 try:
-                    dc['value'] = int(value)
+                    dc['value'] = float(value)
                 except ValueError:
-                    try:
-                        dc['value'] = float(value)
-                    except ValueError:
-                        dc['value'] = str(value)
+                    dc['value'] = str(value)
+
+        # draw
+        node_draw = nodeSurface.find('draw')
+        if node_draw is not None:
+            tagName = str(node_draw.tag)
+            nvizData['surface'][tagName]['all'] = False
+            nvizData['surface'][tagName]['mode'] = {}
+            nvizData['surface'][tagName]['mode']['value'] = -1  # to be calculated
+            nvizData['surface'][tagName]['mode']['desc'] = {}
+            nvizData['surface'][tagName]['mode']['desc']['shading'] = \
+                str(node_draw.get('shading', ''))
+            nvizData['surface'][tagName]['mode']['desc']['style'] = \
+                str(node_draw.get('style', ''))
+            nvizData['surface'][tagName]['mode']['desc']['mode'] = \
+                str(node_draw.get('mode', ''))
+
+            # resolution
+            for node_res in node_draw.findall('resolution'):
+                resType = str(node_res.get('type', ''))
+                if 'resolution' not in nvizData['surface']['draw']:
+                    nvizData['surface']['draw']['resolution'] = {}
+                value = int(self.__getNodeText(node_res, 'value'))
+                nvizData['surface']['draw']['resolution'][resType] = value
+
+            # wire-color
+            node_wire_color = node_draw.find('wire_color')
+            if node_wire_color is not None:
+                nvizData['surface']['draw']['wire-color'] = {}
+                value = str(self.__getNodeText(node_wire_color, 'value'))
+                nvizData['surface']['draw']['wire-color']['value'] = value
+        # position
+        node_pos = nodeSurface.find('position')
+        if node_pos is not None:
+            dc = nvizData['surface']['position']
+            for coor in ['x', 'y', 'z']:
+                node = node_pos.find(coor)
+                if node is None:
+                    continue
+                value = int(self.__getNodeText(node_pos, coor))
+                dc[coor] = value
+
+    def __processLayerNvizVolume(self, nvizData, nodeVolume):
+        """!Process 3D layer settings - volume
+
+        @param nodeData nviz data dict
+        @param nodeVolume nviz volume node
+        """
+        # attributes
+        for attrb in nodeVolume.findall('attribute'):
+            tagName = str(attrb.tag)
+            attrbName = attrb.get('name', '')
+            dc = nvizData['volume'][tagName][attrbName] = {}
+            if attrb.get('map') == '0':
+                dc['map'] = False
+            elif attrb.get('map') == '1':
+                dc['map'] = True
+            else:
+                dc['map'] = None
+            value = self.__getNodeText(attrb, 'value')
+            try:
+                dc['value'] = int(value)
+            except ValueError:
+                try:
+                    dc['value'] = float(value)
+                except ValueError:
+                    dc['value'] = str(value)
+
+        # draw
+        node_draw = nodeVolume.find('draw')
+        if node_draw is not None:
+            node_box = node_draw.find('box')
+            if node_box is not None:
+                nvizData['volume']['draw']['box'] = {}
+                enabled = bool(int(self.__getNodeText(node_box, 'enabled')))
+                nvizData['volume']['draw']['box']['enabled'] = enabled
+            node_mode = node_draw.find('mode')
+            if node_mode is not None:
+                nvizData['volume']['draw']['mode'] = {}
+                desc = self.__getNodeText(node_mode, 'desc')
+                value = int(self.__getNodeText(node_mode, 'value'))
+                nvizData['volume']['draw']['mode']['desc'] = desc
+                nvizData['volume']['draw']['mode']['value'] = value
+            node_res = node_draw.find('resolution')
+            if node_res is not None:
+                nvizData['volume']['draw']['resolution'] = {}
+                for vol_type in ('isosurface', 'slice'):
+                    nd = node_res.find(vol_type)
+                    value = int(self.__getNodeText(nd, 'value'))
+                    nvizData['volume']['draw']['resolution'][vol_type] = {'value': value}
+            node_shading = node_draw.find('shading')
+            if node_shading is not None:
+                nvizData['volume']['draw']['shading'] = {}
+                for vol_type in ('isosurface', 'slice'):
+                    nd = node_shading.find(vol_type)
+                    value = int(self.__getNodeText(nd, 'value'))
+                    desc = self.__getNodeText(nd, 'desc')
+                    nvizData['volume']['draw']['shading'][vol_type] = {'value': value, 'desc': desc}
+
+        nvizData['volume']['isosurface'] = []
+        for isosurfaceNode in nodeVolume.findall('isosurface'):
+            isoDict = {}
+            for att in ('topo', 'transp', 'shine', 'color'):
+                attNode = isosurfaceNode.find(att)
+                if attNode is not None:
+                    isMap = attNode.find('map').text
+                    value = attNode.find('value').text
+                    if not isMap:
+                        isoDict[att] = {'map': None}
+                        isoDict[att]['value'] = float(value)
+                    elif isMap == '1':
+                        isoDict[att] = {'map': True}
+                        isoDict[att]['value'] = value
+                    else:
+                        isoDict[att] = {'map': False}
+                        isoDict[att]['value'] = float(value)
+            inout = isosurfaceNode.find('inout')
+            if inout is not None:
+                isoDict['inout'] = {'value': int(float(inout.find('value').text))}
+            nvizData['volume']['isosurface'].append(isoDict)
             
-            # draw
-            node_draw = node_surface.find('draw')
-            if node_draw is not None:
-                tagName = str(node_draw.tag)
-                nviz['surface'][tagName]['all'] = False
-                nviz['surface'][tagName]['mode'] = {}
-                nviz['surface'][tagName]['mode']['value'] = -1 # to be calculated
-                nviz['surface'][tagName]['mode']['desc'] = {}
-                nviz['surface'][tagName]['mode']['desc']['shading'] = \
-                    str(node_draw.get('shading', ''))
-                nviz['surface'][tagName]['mode']['desc']['style'] = \
-                    str(node_draw.get('style', ''))
-                nviz['surface'][tagName]['mode']['desc']['mode'] = \
-                    str(node_draw.get('mode', ''))
-                
-                # resolution
-                for node_res in node_draw.findall('resolution'):
-                    resType = str(node_res.get('type', ''))
-                    if 'resolution' not in nviz['surface']['draw']:
-                        nviz['surface']['draw']['resolution'] = {}
-                    value = int(self.__getNodeText(node_res, 'value'))
-                    nviz['surface']['draw']['resolution'][resType] = value
-                
-                # wire-color
-                node_wire_color = node_draw.find('wire_color')
-                if node_wire_color is not None:
-                    nviz['surface']['draw']['wire-color'] = {}
-                    value = str(self.__getNodeText(node_wire_color, 'value'))
-                    nviz['surface']['draw']['wire-color']['value'] = value
-                
-            # position
-            node_pos = node_surface.find('position')
-            if node_pos is not None:
-                dc = nviz['surface']['position'] = {}
-                for coor in ['x', 'y', 'z']:
-                    node = node_pos.find(coor)
-                    if node is None:
-                        continue
-                    value = int(self.__getNodeText(node_pos, coor))
-                    dc[coor] = value
-            
-        elif 'vector' in nviz:
-            # vpoints
-            node_vpoints = node_nviz.find('vpoints')
-            if node_vpoints is not None:
-                marker = str(node_vpoints.get('marker', ''))
-                markerId = list(UserSettings.Get(group='nviz', key='vector',
-                                                 subkey=['points', 'marker'], internal=True)).index(marker)
-                nviz['vector']['points']['marker'] = { 'value' : markerId }
-                
-                node_mode = node_vpoints.find('mode')
-                if node_mode is not None:
-                    nviz['vector']['points']['mode'] = {}
-                    nviz['vector']['points']['mode']['type'] = str(node_mode.get('type', 'surface'))
-                    nviz['vector']['points']['mode']['surface'] = {}
-                    nviz['vector']['points']['mode']['surface']['value'] = []
-                    nviz['vector']['points']['mode']['surface']['show'] = []
-                    
-                    # map
-                    for node_map in node_mode.findall('map'):
-                        nviz['vector']['points']['mode']['surface']['value'].append(
-                            self.__processLayerNvizNode(node_map, 'name', str))
-                        nviz['vector']['points']['mode']['surface']['show'].append(bool(
-                            self.__processLayerNvizNode(node_map, 'checked', int)))
-                
-                # color
-                self.__processLayerNvizNode(node_vpoints, 'color', str,
-                                            nviz['vector']['points'])
-                
-                # width
-                self.__processLayerNvizNode(node_vpoints, 'width', int,
-                                            nviz['vector']['points'])
-                
-                # height
-                self.__processLayerNvizNode(node_vpoints, 'height', float,
-                                            nviz['vector']['points'])
-                
-                # height
-                self.__processLayerNvizNode(node_vpoints, 'size', float,
-                                            nviz['vector']['points'])
-                
-                # thematic
-                node_thematic = node_vpoints.find('thematic')
-                thematic = nviz['vector']['points']['thematic'] = {}
-                thematic['rgbcolumn'] = self.__processLayerNvizNode(node_thematic, 'rgbcolumn', str)
-                thematic['sizecolumn'] = self.__processLayerNvizNode(node_thematic, 'sizecolumn', str)
-                for col in ('rgbcolumn', 'sizecolumn'):
-                    if thematic[col] == 'None':
-                        thematic[col] = None
-                thematic['layer'] = self.__processLayerNvizNode(node_thematic, 'layer', int)
-                for use in ('usecolor', 'usesize', 'usewidth'):
-                    if node_thematic.get(use, ''):
-                        thematic[use] = int(node_thematic.get(use, '0'))
-                
-            # vlines
-            node_vlines = node_nviz.find('vlines')
-            if node_vlines is not None:
-                node_mode = node_vlines.find('mode')
-                if node_mode is not None:
-                    nviz['vector']['lines']['mode'] = {}
-                    nviz['vector']['lines']['mode']['type'] = str(node_mode.get('type', ''))
-                    nviz['vector']['lines']['mode']['surface'] = {}
-                    nviz['vector']['lines']['mode']['surface']['value'] = []
-                    nviz['vector']['lines']['mode']['surface']['show'] = []
-                    
-                    # map
-                    for node_map in node_mode.findall('map'):
-                        nviz['vector']['lines']['mode']['surface']['value'].append(
-                            self.__processLayerNvizNode(node_map, 'name', str))
-                        nviz['vector']['lines']['mode']['surface']['show'].append(bool(
-                            self.__processLayerNvizNode(node_map, 'checked', int)))
-                
-                # color
-                self.__processLayerNvizNode(node_vlines, 'color', str,
-                                            nviz['vector']['lines'])
-                
-                # width
-                self.__processLayerNvizNode(node_vlines, 'width', int,
-                                            nviz['vector']['lines'])
-                
-                # height
-                self.__processLayerNvizNode(node_vlines, 'height', int,
-                                            nviz['vector']['lines'])
-                
-                # thematic
-                node_thematic = node_vlines.find('thematic')
-                thematic = nviz['vector']['lines']['thematic'] = {}
-                thematic['rgbcolumn'] = self.__processLayerNvizNode(node_thematic, 'rgbcolumn', str)
-                thematic['sizecolumn'] = self.__processLayerNvizNode(node_thematic, 'sizecolumn', str)
-                for col in ('rgbcolumn', 'sizecolumn'):
-                    if thematic[col] == 'None':
-                        thematic[col] = None
-                thematic['layer'] = self.__processLayerNvizNode(node_thematic, 'layer', int)
-                for use in ('usecolor', 'usesize', 'usewidth'):
-                    if node_thematic.get(use, ''):
-                        thematic[use] = int(node_thematic.get(use, '0'))
-            
-        return nviz
-    
+        nvizData['volume']['slice'] = []
+        for sliceNode in nodeVolume.findall('slice'):
+            sliceDict = {}
+            sliceDict['transp'] = {'value': int(sliceNode.find('transp').find('value').text)}
+            sliceDict['position'] = {}
+            for child in sliceNode.find('position'):
+                if child.tag == 'axis':
+                    sliceDict['position'][child.tag] = int(child.text)
+                else:
+                    sliceDict['position'][child.tag] = float(child.text)
+            nvizData['volume']['slice'].append(sliceDict)
+  
+        # position
+        node_pos = nodeVolume.find('position')
+        if node_pos is not None:
+            dc = nvizData['volume']['position']
+            for coor in ['x', 'y', 'z']:
+                node = node_pos.find(coor)
+                if node is None:
+                    continue
+                value = int(self.__getNodeText(node_pos, coor))
+                dc[coor] = value
+
+    def __processLayerNvizVectorPoints(self, nvizData, nodePoints):
+        """!Process 3D layer settings - vector points
+
+        @param nodeData nviz data dict
+        @param nodeVector nviz vector points node
+        """
+        marker = str(nodePoints.get('marker', ''))
+        markerId = list(UserSettings.Get(group='nviz', key='vector',
+                                         subkey=['points', 'marker'], internal=True)).index(marker)
+        nvizData['vector']['points']['marker'] = {'value': markerId}
+
+        node_mode = nodePoints.find('mode')
+        if node_mode is not None:
+            nvizData['vector']['points']['mode'] = {}
+            nvizData['vector']['points']['mode']['type'] = str(node_mode.get('type', 'surface'))
+            nvizData['vector']['points']['mode']['surface'] = {}
+            nvizData['vector']['points']['mode']['surface']['value'] = []
+            nvizData['vector']['points']['mode']['surface']['show'] = []
+
+            # map
+            for node_map in node_mode.findall('map'):
+                nvizData['vector']['points']['mode']['surface']['value'].append(
+                    self.__processLayerNvizNode(node_map, 'name', str))
+                nvizData['vector']['points']['mode']['surface']['show'].append(bool(
+                    self.__processLayerNvizNode(node_map, 'checked', int)))
+
+        # color
+        self.__processLayerNvizNode(nodePoints, 'color', str,
+                                    nvizData['vector']['points'])
+
+        # width
+        self.__processLayerNvizNode(nodePoints, 'width', int,
+                                    nvizData['vector']['points'])
+
+        # height
+        self.__processLayerNvizNode(nodePoints, 'height', float,
+                                    nvizData['vector']['points'])
+
+        # height
+        self.__processLayerNvizNode(nodePoints, 'size', float,
+                                    nvizData['vector']['points'])
+
+        # thematic
+        node_thematic = nodePoints.find('thematic')
+        thematic = nvizData['vector']['points']['thematic'] = {}
+        thematic['rgbcolumn'] = self.__processLayerNvizNode(node_thematic, 'rgbcolumn', str)
+        thematic['sizecolumn'] = self.__processLayerNvizNode(node_thematic, 'sizecolumn', str)
+        for col in ('rgbcolumn', 'sizecolumn'):
+            if thematic[col] == 'None':
+                thematic[col] = None
+        thematic['layer'] = self.__processLayerNvizNode(node_thematic, 'layer', int)
+        for use in ('usecolor', 'usesize', 'usewidth'):
+            if node_thematic.get(use, ''):
+                thematic[use] = int(node_thematic.get(use, '0'))
+
+    def __processLayerNvizVectorLines(self, nvizData, nodeLines):
+        """!Process 3D layer settings - vector lines
+
+        @param nodeData nviz data dict
+        @param nodeVector nviz vector lines node
+        """
+        node_mode = nodeLines.find('mode')
+        if node_mode is not None:
+            nvizData['vector']['lines']['mode'] = {}
+            nvizData['vector']['lines']['mode']['type'] = str(node_mode.get('type', ''))
+            nvizData['vector']['lines']['mode']['surface'] = {}
+            nvizData['vector']['lines']['mode']['surface']['value'] = []
+            nvizData['vector']['lines']['mode']['surface']['show'] = []
+
+            # map
+            for node_map in node_mode.findall('map'):
+                nvizData['vector']['lines']['mode']['surface']['value'].append(
+                    self.__processLayerNvizNode(node_map, 'name', str))
+                nvizData['vector']['lines']['mode']['surface']['show'].append(bool(
+                    self.__processLayerNvizNode(node_map, 'checked', int)))
+
+        # color
+        self.__processLayerNvizNode(nodeLines, 'color', str,
+                                    nvizData['vector']['lines'])
+
+        # width
+        self.__processLayerNvizNode(nodeLines, 'width', int,
+                                    nvizData['vector']['lines'])
+
+        # height
+        self.__processLayerNvizNode(nodeLines, 'height', int,
+                                    nvizData['vector']['lines'])
+
+        # thematic
+        node_thematic = nodeLines.find('thematic')
+        thematic = nvizData['vector']['lines']['thematic'] = {}
+        thematic['rgbcolumn'] = self.__processLayerNvizNode(node_thematic, 'rgbcolumn', str)
+        thematic['sizecolumn'] = self.__processLayerNvizNode(node_thematic, 'sizecolumn', str)
+        for col in ('rgbcolumn', 'sizecolumn'):
+            if thematic[col] == 'None':
+                thematic[col] = None
+        thematic['layer'] = self.__processLayerNvizNode(node_thematic, 'layer', int)
+        for use in ('usecolor', 'usesize', 'usewidth'):
+            if node_thematic.get(use, ''):
+                thematic[use] = int(node_thematic.get(use, '0'))
+
     def __processLayerNvizNode(self, node, tag, cast, dc = None):
         """!Process given tag nviz/vector"""
         node_tag = node.find(tag)
@@ -598,6 +722,7 @@
             dispName = self.lmgr.GetLayerNotebook().GetPageText(page)
             mapTree = self.lmgr.GetLayerNotebook().GetPage(page).maptree
             region = mapTree.GetMap().GetCurrentRegion()
+            compRegion = gcore.region(region3d=True)
             mapdisp = mapTree.GetMapDisplay()
             
             displayPos = mapdisp.GetPosition()
@@ -613,7 +738,8 @@
                        'alignExtent="%d" '
                        'constrainRes="%d" '
                        'dim="%d,%d,%d,%d" '
-                       'extent="%f,%f,%f,%f" '
+                       'extent="%f,%f,%f,%f,%f,%f" '
+                       'tbres="%f" '  # needed only for animation tool
                        'viewMode="%s" >\n' % (' ' * self.indent,
                                               dispName.encode('utf8'),
                                               int(mapdisp.mapWindowProperties.autoRender),
@@ -629,6 +755,9 @@
                                               region['s'],
                                               region['e'],
                                               region['n'],
+                                              compRegion['b'],
+                                              compRegion['t'],
+                                              compRegion['tbres'],
                                               viewmode
                                               ))
             # projection statusbar info
@@ -749,6 +878,8 @@
                     self.file.write('%s<nviz>\n' % (' ' * self.indent))
                     if maplayer.type == 'raster':
                         self.__writeNvizSurface(nviz['surface'])
+                    if maplayer.type == '3d-raster':
+                        self.__writeNvizVolume(nviz['volume'])
                     elif maplayer.type == 'vector':
                         self.__writeNvizVector(nviz['vector'])
                     self.file.write('%s</nviz>\n' % (' ' * self.indent))
@@ -830,6 +961,134 @@
         self.file.write('%s</surface>\n' % (' ' * self.indent))
         self.indent -= 4
 
+    def __writeNvizVolume(self, data):
+        """!Save Nviz volume layer properties to workspace
+
+        @param data Nviz layer properties
+        """
+        if 'object' not in data:  # skip disabled
+            return
+        self.indent += 4
+        self.file.write('%s<volume>\n' % (' ' * self.indent))
+        self.indent += 4
+        for attrb in data.iterkeys():
+            if len(data[attrb]) < 1:  # skip empty attributes
+                continue
+            if attrb == 'object':
+                continue
+
+            if attrb == 'attribute':
+                for name in data[attrb].iterkeys():
+                    # surface attribute
+                    if data[attrb][name]['map'] is None:
+                        continue
+                    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
+                    # end tag
+                    self.file.write('%s</%s>\n' % (' ' * self.indent, attrb))
+
+            # draw mode
+            if attrb == 'draw':
+                self.file.write('%s<%s>\n' % (' ' * self.indent, attrb))
+
+                self.indent += 4
+                for att in ('resolution', 'shading'):
+                    if att in data[attrb]:
+                        self.file.write('%s<%s>\n' % (' ' * self.indent, att))
+                        for type in ('isosurface', 'slice'):
+                            self.indent += 4
+                            self.file.write('%s<%s>\n' % (' ' * self.indent, type))
+                            self.indent += 4
+                            self.file.write('%s<value>%d</value>\n' % (' ' * self.indent,
+                                                                       data[attrb][att][type]['value']))
+                            if att == 'shading':
+                                self.file.write('%s<desc>%s</desc>\n' % (' ' * self.indent,
+                                                                         data[attrb][att][type]['desc']))
+                            self.indent -= 4
+                            self.file.write('%s</%s>\n' % (' ' * self.indent, type))
+                            self.indent -= 4
+                        self.file.write('%s</%s>\n' % (' ' * self.indent, att))
+
+                if 'box' in data[attrb]:
+                    self.file.write('%s<box>\n' % (' ' * self.indent))
+                    self.indent += 4
+                    self.file.write('%s<enabled>%d</enabled>\n' % (' ' * self.indent, data[attrb]['box']['enabled']))
+                    self.indent -= 4
+                    self.file.write('%s</box>\n' % (' ' * self.indent))
+
+                if 'mode' in data[attrb]:
+                    self.file.write('%s<mode>\n' % (' ' * self.indent))
+                    self.indent += 4
+                    self.file.write('%s<desc>%s</desc>\n' % (' ' * self.indent, data[attrb]['mode']['desc']))
+                    self.file.write('%s<value>%d</value>\n' % (' ' * self.indent, data[attrb]['mode']['value']))
+                    self.indent -= 4
+                    self.file.write('%s</mode>\n' % (' ' * self.indent))
+                self.indent -= 4
+
+            # position
+            elif attrb == 'position':
+                self.file.write('%s<%s>\n' % (' ' * self.indent, attrb))
+                for tag in ('x', 'y', 'z'):
+                    self.indent += 4
+                    self.file.write('%s<%s>%d</%s>\n' % (' ' * self.indent, tag,
+                                                         data[attrb].get(tag, 0), tag))
+                    self.indent -= 4
+            if attrb == 'isosurface':
+                for isosurface in data[attrb]:
+                    self.file.write('%s<%s>\n' % (' ' * self.indent, attrb))
+                    for name in isosurface.iterkeys():
+                        self.indent += 4
+                        self.file.write('%s<%s>\n' % (' ' * self.indent, name))
+                        for att in isosurface[name].iterkeys():
+                            if isosurface[name][att] is True:
+                                val = '1'
+                            elif isosurface[name][att] is False:
+                                val = '0'
+                            else:
+                                try:
+                                    val = '%f' % float(isosurface[name][att])
+                                except ValueError:
+                                    val = '%s' % isosurface[name][att]
+                                except TypeError:  # None
+                                    val = ''
+                            self.indent += 4
+                            self.file.write(('%s<%s>' % (' ' * self.indent, att)) + val)
+                            self.file.write('</%s>\n' % att)
+                            self.indent -= 4
+                        # end tag
+                        self.file.write('%s</%s>\n' % (' ' * self.indent, name))
+                        self.indent -= 4
+                    self.file.write('%s</%s>\n' % (' ' * self.indent, attrb))
+
+            if attrb == 'slice':
+                for slice_ in data[attrb]:
+                    self.file.write('%s<%s>\n' % (' ' * self.indent, attrb))
+                    for name in slice_.iterkeys():
+                        self.indent += 4
+                        self.file.write('%s<%s>\n' % (' ' * self.indent, name))
+                        for att in slice_[name].iterkeys():
+                            if att in ('map', 'update'):
+                                continue
+                            val = slice_[name][att]
+                            self.indent += 4
+                            self.file.write(('%s<%s>' % (' ' * self.indent, att)) + str(val))
+                            self.file.write('</%s>\n' % att)
+                            self.indent -= 4
+                        # end tag
+                        self.file.write('%s</%s>\n' % (' ' * self.indent, name))
+                        self.indent -= 4
+                    self.file.write('%s</%s>\n' % (' ' * self.indent, attrb))
+            if attrb not in ('attribute', 'isosurface', 'slice'):
+                # end tag
+                self.file.write('%s</%s>\n' % (' ' * self.indent, attrb))
+
+        self.indent -= 4
+        self.file.write('%s</volume>\n' % (' ' * self.indent))
+        self.indent -= 4
+
     def __writeNvizVector(self, data):
         """!Save Nviz vector layer properties (lines/points) to workspace
 

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2013-12-28 16:33:57 UTC (rev 58542)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2013-12-29 04:35:32 UTC (rev 58543)
@@ -1158,7 +1158,7 @@
                     
             # set extent if defined
             if display['extent']:
-                w, s, e, n = display['extent']
+                w, s, e, n, b, t = display['extent']
                 region = maptree.Map.region = maptree.Map.GetRegion(w = w, s = s, e = e, n = n)
                 mapdisp.GetWindow().ResetZoomHistory()
                 mapdisp.GetWindow().ZoomHistory(region['n'],



More information about the grass-commit mailing list