[GRASS-SVN] r32655 - in grass/trunk/gui/wxpython: . gui_modules nviz scripts

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 9 09:21:36 EDT 2008


Author: martinl
Date: 2008-08-09 09:21:36 -0400 (Sat, 09 Aug 2008)
New Revision: 32655

Modified:
   grass/trunk/gui/wxpython/Makefile
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/nviz.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/render.py
   grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
   grass/trunk/gui/wxpython/nviz/load.cpp
   grass/trunk/gui/wxpython/nviz/nviz.h
   grass/trunk/gui/wxpython/scripts/d.rast3d
Log:
wxGUI/nviz: volume support in progress, cosmetics in preferences dialog
fix preferences - OnDefault
(merge from devbr6, r32653 and r32654)


Modified: grass/trunk/gui/wxpython/Makefile
===================================================================
--- grass/trunk/gui/wxpython/Makefile	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/Makefile	2008-08-09 13:21:36 UTC (rev 32655)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-SUBDIRS = docs
+SUBDIRS = docs scripts
 
 include $(MODULE_TOPDIR)/include/Make/Platform.make
 

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-08-09 13:21:36 UTC (rev 32655)
@@ -2643,6 +2643,11 @@
             self.toolbars['map'].Enable2D(False)
 
             #
+            # update layer tree (-> enable 3d-rasters)
+            #
+            self.tree.EnableItemType(type='3d-raster', enable=True)
+            
+            #
             # update status bar
             #
             self.toggleStatus.Enable(False)
@@ -2727,7 +2732,12 @@
                               CloseButton(False).DestroyOnClose(True).
                               Layer(0))
             self.MapWindow = self.MapWindow2D
-        
+  
+            #
+            # update layer tree (-> disable 3d-rasters)
+            #
+            self.tree.EnableItemType(type='3d-raster', enable=False)
+            
         self.toolbars['map'].combo.SetValue ("Tools")
         self.toolbars['map'].Enable2D(True)
         self.toggleStatus.Enable(True)

Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-08-09 13:21:36 UTC (rev 32655)
@@ -86,7 +86,7 @@
 
         # list of loaded map layers
         self.layers = {}
-        for type in ('raster', 'vlines', 'vpoints'):
+        for type in ('raster', 'vlines', 'vpoints', '3d-raster'):
             self.layers[type] = {}
             self.layers[type]['name'] = []
             self.layers[type]['id'] = []
@@ -122,7 +122,7 @@
         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
         self.Bind(wx.EVT_MOTION, self.OnMouseAction)
         self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseAction)
-
+        
     def OnEraseBackground(self, event):
         pass # do nothing, to avoid flashing on MSW
 
@@ -331,7 +331,7 @@
         while item and item.IsOk():
             type = self.tree.GetPyData(item)[0]['type']
             if not item.IsChecked() or \
-                    type not in ('raster', 'vector'):
+                    type not in ('raster', 'vector', '3d-raster'):
                 item = self.tree.GetNextSibling(item)
                 continue
 
@@ -348,6 +348,8 @@
             try:
                 if type == 'raster':
                     self.LoadRaster(item)
+                elif type == '3d-raster':
+                    self.LoadRaster3d(item)
             except gcmd.NvizError, e:
                 print >> sys.stderr, "Nviz:" + e.message
 
@@ -400,6 +402,12 @@
 
                 # reset to default properties (lines/points)
                 self.SetVectorDefaultProp(data['vector'])
+
+            elif type == '3d-raster':
+                data[nvizType] = {}
+
+                # reset to default properties 
+                self.SetVolumeDefaultProp(data[nvizType])
         
         else:
             # check data
@@ -428,73 +436,131 @@
         return data
 
     def LoadRaster(self, item):
-        """Load raster map and set surface attributes
+        """Load 2d raster map and set surface attributes
 
         @param layer item
         """
+        return self._loadRaster(item)
+
+    def LoadRaster3d(self, item):
+        """Load 3d raster map and set surface attributes
+
+        @param layer item
+        """
+        return self._loadRaster(item)
+
+    def _loadRaster(self, item):
+        """Load 2d/3d raster map and set its attributes
+
+        @param layer item
+        """
         layer = self.tree.GetPyData(item)[0]['maplayer']
 
-        if layer.type != 'raster':
+        if layer.type not in ('raster', '3d-raster'):
             return
 
-        id = self.nvizClass.LoadSurface(str(layer.name), None, None)
+        if layer.type == 'raster':
+            id = self.nvizClass.LoadSurface(str(layer.name), None, None)
+            nvizType = 'surface'
+            errorMsg = _("Loading raster map")
+        elif layer.type == '3d-raster':
+            id = self.nvizClass.LoadVolume(str(layer.name), None, None)
+            nvizType = 'volume'
+            errorMsg = _("Loading 3d raster map")
+        else:
+            id = -1
+        
         if id < 0:
-            print >> sys.stderr, "Nviz:" + _("Loading raster map <%s> failed") % layer.name
+            if layer.type in ('raster', '3d-raster'):
+                print >> sys.stderr, "Nviz:" + "%s <%s> %s" % (errorMsg, layer.name, _("failed"))
+            else:
+                print >> sys.stderr, "Nviz:" + _("Unsupported layer type '%s'") % layer.type
         
-        self.layers['raster']['name'].append(layer.name)
-        self.layers['raster']['id'].append(id)
+        self.layers[layer.type]['name'].append(layer.name)
+        self.layers[layer.type]['id'].append(id)
 
         # set default/workspace layer properties
-        data = self.SetLayerData(item, id, 'surface')
-
+        data = self.SetLayerData(item, id, nvizType)
+        
         # update properties
         self.UpdateLayerProperties(item)
-
+        
         # update tools window
         if hasattr(self.parent, "nvizToolWin") and \
-                item == self.GetSelectedLayer(type='item'):
+                item == self.GetSelectedLayer(type='item') and \
+                layer.type == 'raster':
             toolWin = self.parent.nvizToolWin
             win = toolWin.FindWindowById( \
                 toolWin.win['vector']['lines']['surface'])
-            win.SetItems(self.layers['raster']['name'])
+            win.SetItems(self.layers[layer.type]['name'])
 
-            toolWin.UpdatePage('surface')
-            toolWin.SetPage('surface')
+            toolWin.UpdatePage(nvizType)
+            toolWin.SetPage(nvizType)
             
         return id
 
     def UnloadRaster(self, item):
-        """Unload raster map
+        """Unload 2d raster map
 
+        @param layer item
+        """
+        return self._unloadRaster(item)
+
+    def UnloadRaster3d(self, item):
+        """Unload 3d raster map
+
+        @param layer item
+        """
+        return self._unloadRaster(item)
+
+    def _unloadRaster(self, item):
+        """Unload 2d/3d raster map
+
         @param item layer item
         """
         layer = self.tree.GetPyData(item)[0]['maplayer']
+
+        if layer.type not in ('raster', '3d-raster'):
+            return
+
         data = self.tree.GetPyData(item)[0]['nviz']
 
-        id = data['surface']['object']['id']
+        if layer.type == 'raster':
+            nvizType = 'surface'
+            unloadFn = self.nvizClass.UnloadSurface
+            errorMsg = _("Unable to unload raster map")
+            successMsg = _("Raster map")
+        else:
+            nvizType = 'volume'
+            unloadFn = self.nvizClass.UnloadVolume
+            errorMsg = _("Unable to unload 3d raster map")
+            successMsg = _("3d raster map")
 
-        if self.nvizClass.UnloadSurface(id) == 0:
-            print >> sys.stderr, "Nviz:" + _("Unable to unload raster map <%s>") % layer.name
+        id = data[nvizType]['object']['id']
+
+        if unloadFn(id) == 0:
+            print >> sys.stderr, "Nviz:" + "%s <%s>" % (errorMsg, layer.name)
         else:
-            print "Nviz:" + _("Raster map <%s> unloaded successfully") % layer.name
+            print "Nviz:" + "%s <%s> %s" % (successMsg, layer.name, _("unloaded successfully"))
 
-        data['surface'].pop('object')
+        data[nvizType].pop('object')
 
-        idx = self.layers['raster']['id'].index(id)
-        del self.layers['raster']['name'][idx]
-        del self.layers['raster']['id'][idx]
+        idx = self.layers[layer.type]['id'].index(id)
+        del self.layers[layer.type]['name'][idx]
+        del self.layers[layer.type]['id'][idx]
 
         # update tools window
-        if hasattr(self.parent, "nvizToolWin"):
+        if hasattr(self.parent, "nvizToolWin") and \
+                layer.type == 'raster':
             toolWin = self.parent.nvizToolWin
             win = toolWin.FindWindowById( \
                 toolWin.win['vector']['lines']['surface'])
-            win.SetItems(self.layers['raster']['name'])
+            win.SetItems(self.layers[layer.type]['name'])
 
             # remove surface page
-            if toolWin.notebook.GetSelection() == toolWin.page['surface']['id']:
-                toolWin.notebook.RemovePage(toolWin.page['surface']['id'])
-                toolWin.page['surface']['id'] = -1
+            if toolWin.notebook.GetSelection() == toolWin.page[nvizType]['id']:
+                toolWin.notebook.RemovePage(toolWin.page[nvizType]['id'])
+                toolWin.page[nvizType]['id'] = -1
                 toolWin.page['settings']['id'] = 1
         
     def GetSurfaceMode(self, mode, style, shade, string=False):
@@ -785,6 +851,10 @@
             self.update.append('vector:points:color')
             self.update.append('vector:points:surface')
             self.update.append('vector:points:height')
+
+    def SetVolumeDefaultProp(self, data):
+        """Set default volume properties"""
+        pass
         
     def Reset(self):
         """Reset (unload data)"""
@@ -1066,6 +1136,8 @@
         size = (size[0] + 25, size[0] + 20)
         # vector page
         self.__createVectorPage()
+        # volume page
+        self.__createVolumePage()
         # settings page
         self.__createSettingsPage()
         self.page['settings'] = { 'id' : 1 }
@@ -1713,6 +1785,103 @@
 
         return panel.GetBestSize()
 
+    def __createVolumePage(self):
+        """Create view settings page"""
+        panel = wx.Panel(parent=self.notebook, id=wx.ID_ANY)
+        self.page['volume'] = {}
+        self.page['volume']['id'] = -1
+        self.page['volume']['panel'] = panel.GetId()
+        
+        pageSizer = wx.BoxSizer(wx.VERTICAL)
+        
+        self.win['volume'] = {}
+        
+        #
+        # volume attributes
+        #
+        box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
+                            label=" %s " % (_("Volume attributes")))
+        boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+        gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
+
+        self.win['volume']['attr'] = {}
+        row = 0
+        for code, attrb in (('topo', _("Topography level")),
+                            ('color', _("Color")),
+                            ('mask', _("Mask")),
+                            ('transp', _("Transparency")),
+                            ('shine', _("Shininess")),
+                            ('emit', _("Emission"))):
+            self.win['volume'][code] = {} 
+            gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
+                                             label=attrb + ':'),
+                          pos=(row, 0), flag=wx.ALIGN_CENTER_VERTICAL)
+            use = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
+                             choices = [_("map")])
+            if code not in ('topo', 'color', 'shine'):
+                use.Insert(item=_("unset"), pos=0)
+                self.win['volume'][code]['required'] = False
+            else:
+                self.win['surface'][code]['required'] = True
+            if code != 'mask':
+                use.Append(item=_('constant'))
+            self.win['surface'][code]['use'] = use.GetId()
+            use.Bind(wx.EVT_CHOICE, self.OnSurfaceUse)
+            gridSizer.Add(item=use, flag=wx.ALIGN_CENTER_VERTICAL,
+                          pos=(row, 1))
+            
+            map = gselect.Select(parent=panel, id=wx.ID_ANY,
+                                 # size=globalvar.DIALOG_GSELECT_SIZE,
+                                 size=(200, -1),
+                                 type="raster")
+            self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
+            map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
+            # changing map topography not allowed
+            if code == 'topo':
+                map.Enable(False)
+            gridSizer.Add(item=map, flag=wx.ALIGN_CENTER_VERTICAL,
+                          pos=(row, 2))
+            
+            if code == 'color':
+                value = csel.ColourSelect(panel, id=wx.ID_ANY,
+                                          colour=UserSettings.Get(group='nviz', key='volume',
+                                                                  subkey=['color', 'value']))
+                value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
+            elif code == 'mask':
+                value = None
+            else:
+                value = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
+                                    initial=0)
+                if code == 'topo':
+                    value.SetRange(minVal=-1e9, maxVal=1e9)
+                elif code in ('shine', 'transp', 'emit'):
+                    value.SetRange(minVal=0, maxVal=255)
+                else:
+                    value.SetRange(minVal=0, maxVal=100)
+                value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
+            
+            if value:
+                self.win['volume'][code]['const'] = value.GetId()
+                value.Enable(False)
+                gridSizer.Add(item=value, flag=wx.ALIGN_CENTER_VERTICAL,
+                              pos=(row, 3))
+            else:
+                self.win['volume'][code]['const'] = None
+            
+            ### self.SetSurfaceUseMap(code) # -> enable map / disable constant
+                
+            row += 1
+        
+        boxSizer.Add(item=gridSizer, proportion=1,
+                     flag=wx.ALL | wx.EXPAND, border=3)
+        pageSizer.Add(item=boxSizer, proportion=0,
+                      flag=wx.EXPAND | wx.ALL,
+                      border=5)
+        
+        panel.SetSizer(pageSizer)
+        
+        return panel.GetBestSize()
+    
     def __createSettingsPage(self):
         """Create settings page"""
         panel = wx.Panel(parent=self.notebook, id=wx.ID_ANY)
@@ -1835,7 +2004,7 @@
         hstep = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
                            initial=hvals['step'],
                            min=1,
-                           max=hvals['max']-1)
+                           max=1e6)
         self.win['settings']['view']['height']['step'] = hstep.GetId()
         gridSizer.Add(item=hstep, pos=(2, 2),
                       flag=wx.ALIGN_CENTER_VERTICAL)
@@ -2761,26 +2930,43 @@
                                          page=panel,
                                          text=" %s " % _("Layer properties"),
                                          select=True)
-
+            
             self.UpdateSurfacePage(layer, data['surface'])
-
+        
         elif pageId == 'vector':
             if self.notebook.GetSelection() != self.page['vector']['id']:
                 if self.page['surface']['id'] > -1:
                     self.notebook.RemovePage(self.page['surface']['id'])
                     self.page['surface']['id'] = -1
-
+                    
                 self.page['vector']['id'] = 1
                 self.page['settings']['id'] = 2
-
+                
                 panel = wx.FindWindowById(self.page['vector']['panel'])
                 self.notebook.InsertPage(n=self.page['vector']['id'],
                                          page=panel,
                                          text=" %s " % _("Layer properties"),
                                          select=True)
+                
+            self.UpdateVectorPage(layer, data['vector'])
+            
+        elif pageId == 'volume':
+            if self.notebook.GetSelection() != self.page['volume']['id']:
+                if self.page['volume']['id'] > -1:
+                    self.notebook.RemovePage(self.page['volume']['id'])
+                    self.page['volume']['id'] = -1
+                    
+                self.page['volume']['id'] = 1
+                self.page['settings']['id'] = 2
 
-            self.UpdateVectorPage(layer, data['vector'])
-        
+                panel = wx.FindWindowById(self.page['volume']['panel'])
+                self.notebook.InsertPage(n=self.page['volume']['id'],
+                                         page=panel,
+                                         text=" %s " % _("Layer properties"),
+                                         select=True)
+                
+            self.UpdateVolumePage(layer, data['volume'])
+            
         self.pageChanging = False
         
     def UpdateSurfacePage(self, layer, data):
@@ -2962,6 +3148,10 @@
             win = self.FindWindowById(self.win['vector']['points']['height'][type])
             win.SetValue(data['points']['height'])
 
+    def UpdateVolumePage(self, layer, data):
+        """Update volume layer properties page"""
+        pass
+    
     def SetPage(self, name):
         """Get named page"""
         self.notebook.SetSelection(self.page[name]['id'])

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-08-09 13:21:36 UTC (rev 32655)
@@ -445,6 +445,12 @@
                         'height' : 0,
                         }
                     },
+                'volume' : {
+                    'color' : {
+                        'map' : True,
+                        'value' : (0, 0, 0, 255), # constant: black
+                        },
+                    },
                 'settings': {
                     'general' : {
                         'bgcolor' : (255, 255, 255, 255), # white
@@ -1132,10 +1138,14 @@
         box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Vector settings"))
         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
         
-        gridSizer = wx.FlexGridSizer (cols=6, hgap=3, vgap=3)
+        gridSizer = wx.FlexGridSizer (cols=7, hgap=3, vgap=3)
         
+        gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
+                                         label=_("Display:")),
+                      flag=wx.ALIGN_CENTER_VERTICAL)
+        
         for type in ('point', 'line', 'centroid', 'boundary',
-                        'area', 'face'):
+                     'area', 'face'):
             chkbox = wx.CheckBox(parent=panel, label=type)
             checked = self.settings.Get(group='cmd', key='showType',
                                         subkey=[type, 'enabled'])
@@ -1439,8 +1449,12 @@
         
         # update widgets
         for gks in self.winId.keys():
-            group, key, subkey = gks.split(':')
-            value = self.settings.Get(group, key, subkey)
+            try:
+                group, key, subkey = gks.split(':')
+                value = self.settings.Get(group, key, subkey)
+            except ValueError:
+                group, key, subkey, subkey1 = gks.split(':')
+                value = self.settings.Get(group, key, [subkey, subkey1])
             win = self.FindWindowById(self.winId[gks])
             if win.GetName() in ('GetValue', 'IsChecked'):
                 value = win.SetValue(value)

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2008-08-09 13:21:36 UTC (rev 32655)
@@ -95,6 +95,10 @@
         """
         if len(self.cmdlist) == 0:
             return None
+        
+        # ignore in 2D
+        if self.type == '3d-raster':
+            return None
 
         Debug.msg (3, "Layer.Render(): type=%s, name=%s" % \
                        (self.type, self.name))

Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-08-09 13:21:36 UTC (rev 32655)
@@ -1,23 +1,23 @@
 """
-MODULE:     wxgui_utils.py
+ at package wxgui_utils.py
 
-CLASSES:
-    * AbstractLayer
-    * Layer
-    * LayerTree
+ at brief Utility classes for GRASS wxPython GUI. Main functions include
+tree control for GIS map layer management, command console, and
+command parsing.
 
-PURPOSE:    Utility classes for GRASS wxPython GUI. Main functions include tree control
-            for GIS map layer management, command console, and command parsing.
+Classes:
+ - AbstractLayer
+ - Layer
+ - LayerTree
 
-AUTHORS:    The GRASS Development Team
-            Michael Barton (Arizona State University)
-            Jachym Cepicky (Mendel University of Agriculture)
-            Martin Landa <landa.martin gmail.com>
-
-COPYRIGHT:  (C) 2007-2008 by the GRASS Development Team
-            This program is free software under the GNU General Public
-            License (>=v2). Read the file COPYING that comes with GRASS
-            for details.
+(C) 2007-2008 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+ 
+ at author Michael Barton (Arizona State University)
+ at author Jachym Cepicky (Mendel University of Agriculture)
+ at author Martin Landa <landa.martin gmail.com>
 """
 
 import os
@@ -663,7 +663,11 @@
             # run properties dialog if no properties given
             if len(cmd) == 0:
                 self.PropertiesDialog(layer, show=True)
-
+                
+            if ltype == '3d-raster' and \
+                    not self.mapdisplay.toolbars['nviz']:
+                self.EnableItem(layer, False)
+            
         else: # group
             self.SetPyData(layer, ({'cmd': None,
                                     'type' : ltype,
@@ -682,7 +686,7 @@
                 self.SetItemText(layer, name)
             else:
                 ctrl.SetValue(lname)
-
+            
         # updated progress bar range (mapwindow statusbar)
         if checked is True:
             self.mapdisplay.onRenderGauge.SetRange(len(self.Map.GetListOfLayers(l_active=True)))
@@ -869,6 +873,8 @@
             if checked: # enable
                 if mapLayer.type == 'raster':
                     self.mapdisplay.MapWindow.LoadRaster(item)
+                elif mapLayer.type == '3d-raster':
+                    self.mapdisplay.MapWindow.LoadRaster3d(item)
                 elif mapLayer.type == 'vector':
                     self.mapdisplay.MapWindow.LoadVector(item)
 
@@ -877,6 +883,8 @@
 
                 if mapLayer.type == 'raster':
                     self.mapdisplay.MapWindow.UnloadRaster(item)
+                elif mapLayer.type == '3d-raster':
+                    self.mapdisplay.MapWindow.UnloadRaster3d(item)
                 elif mapLayer.type == 'vector':
                     self.mapdisplay.MapWindow.UnloadVector(item)
                     
@@ -952,8 +960,11 @@
                 elif type == 'vector':
                     self.mapdisplay.nvizToolWin.UpdatePage('vector')
                     self.mapdisplay.nvizToolWin.SetPage('vector')
+                elif type == '3d-raster':
+                    self.mapdisplay.nvizToolWin.UpdatePage('volume')
+                    self.mapdisplay.nvizToolWin.SetPage('volume')
             else:
-                for page in ('surface', 'vector'):
+                for page in ('surface', 'vector', 'volume'):
                     pageId = self.mapdisplay.nvizToolWin.page[page]['id']
                     if pageId > -1:
                         self.mapdisplay.nvizToolWin.notebook.RemovePage(pageId)
@@ -1148,6 +1159,13 @@
                         mapWin.UnloadRaster(layer)
                     
                     mapWin.LoadRaster(layer)
+                    
+                elif mapLayer.type == '3d-raster':
+                    if mapWin.IsLoaded(layer):
+                        mapWin.UnloadRaster3d(layer)
+                    
+                    mapWin.LoadRaster3d(layer)
+                    
                 elif mapLayer.type == 'vector':
                     if mapWin.IsLoaded(layer):
                         mapWin.UnloadVector(layer)
@@ -1239,6 +1257,15 @@
         item = self.GetFirstChild(self.root)[0]
         return self.__FindSubItemByData(item, key, value)
 
+    def EnableItemType(self, type, enable=True):
+        """Enable/disable items in layer tree"""
+        item = self.GetFirstChild(self.root)[0]
+        while item and item.IsOk():
+            ltype = self.GetPyData(item)[0]['maplayer'].type
+            if type == ltype:
+                self.EnableItem(item, enable)
+            item = self.GetNextSibling(item)
+        
     def __FindSubItemByData(self, item, key, value):
         """Support method for FindItemByValue"""
         while item and item.IsOk():

Modified: grass/trunk/gui/wxpython/nviz/load.cpp
===================================================================
--- grass/trunk/gui/wxpython/nviz/load.cpp	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/nviz/load.cpp	2008-08-09 13:21:36 UTC (rev 32655)
@@ -19,6 +19,7 @@
 #include "nviz.h"
 
 extern "C" {
+#include <grass/G3d.h>
 #include <grass/glocale.h>
 }
 
@@ -185,3 +186,85 @@
 
     return 1;
 }
+
+/*!
+  \brief Load 3d raster map (volume)
+
+  \param name 3d raster map name
+  \param color_name 3d raster map for color (NULL for color_value)
+  \param color_value color string (named color or RGB triptet)
+
+  \return object id
+  \return -1 on failure
+*/
+int Nviz::LoadVolume(const char* name, const char *color_name, const char *color_value)
+{
+    char *mapset;
+    int id;
+
+    mapset = G_find_grid3(name, "");
+    if (mapset == NULL) {
+	G_warning(_("3d raster map <%s> not found"),
+		  name);
+	return -1;
+    }
+	    
+    /* topography */
+    id = Nviz_new_map_obj(MAP_OBJ_VOL,
+			  G_fully_qualified_name(name, mapset), 0.0,
+			  data);
+
+    if (color_name) { /* check for color map */
+	mapset = G_find_grid3(color_name, "");
+	if (mapset == NULL) {
+	    G_warning(_("3d raster map <%s> not found"),
+		      color_name);
+	    GVL_delete_vol(id);
+	    return -1;
+	}
+
+	Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
+		      G_fully_qualified_name(color_name, mapset), -1.0,
+		      data);
+    }
+    else if (color_value) { /* check for color value */
+	Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, CONST_ATT,
+		      NULL, Nviz_color_from_str(color_value),
+		      data);
+    }
+    else { /* use by default elevation map for coloring */
+	Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
+		      G_fully_qualified_name(name, mapset), -1.0,
+		      data);
+    }
+	    
+    /* focus on loaded data */
+    Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
+
+    G_debug(1, "Nviz::LoadVolume(): name=%s -> id=%d", name, id);
+
+    return id;
+}
+
+/*!
+  \brief Unload volume
+
+  \param id volume id
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::UnloadVolume(int id)
+{
+    if (!GVL_vol_exists(id)) {
+	return 0;
+    }
+
+    G_debug(1, "Nviz::UnloadVolume(): id=%d", id);
+
+    if (GVL_delete_vol(id) < 0)
+      return 0;
+
+    return 1;
+}
+

Modified: grass/trunk/gui/wxpython/nviz/nviz.h
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.h	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/nviz/nviz.h	2008-08-09 13:21:36 UTC (rev 32655)
@@ -64,6 +64,8 @@
     int UnloadSurface(int);
     int LoadVector(const char *, bool);
     int UnloadVector(int, bool);
+    int LoadVolume(const char*, const char *, const char *);
+    int UnloadVolume(int);
 
     /* draw.cpp */
     void Draw(bool, bool, bool);

Modified: grass/trunk/gui/wxpython/scripts/d.rast3d
===================================================================
--- grass/trunk/gui/wxpython/scripts/d.rast3d	2008-08-09 13:19:20 UTC (rev 32654)
+++ grass/trunk/gui/wxpython/scripts/d.rast3d	2008-08-09 13:21:36 UTC (rev 32655)
@@ -18,10 +18,10 @@
 
 #%Module
 #%  description: Displays 3d raster data in the active frame on the graphics monitor.
-#%  keywords: display, raster3d, voxel
+#%  keywords: display, raster3d
 #%End
 #%option
-#% key: input
+#% key: map
 #% type: string
 #% gisprompt: old,grid3,3d-raster
 #% description: 3D raster map to be displayed



More information about the grass-commit mailing list