[GRASS-SVN] r32849 - in grass/trunk/gui/wxpython: gui_modules nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 17 17:51:16 EDT 2008


Author: martinl
Date: 2008-08-17 17:51:15 -0400 (Sun, 17 Aug 2008)
New Revision: 32849

Modified:
   grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
   grass/trunk/gui/wxpython/nviz/nviz.h
   grass/trunk/gui/wxpython/nviz/volume.cpp
Log:
wxGUI/nviz2: better isosurface draw mode support, added methods to change isosurface attributes
(merge from devbr6, r32848)


Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2008-08-17 21:39:32 UTC (rev 32848)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2008-08-17 21:51:15 UTC (rev 32849)
@@ -400,7 +400,7 @@
             for sec in data.keys():
                 for sec1 in data[sec].keys():
                     for sec2 in data[sec][sec1].keys():
-                        if sec2 not in ('object'):
+                        if sec2 not in ('object', 'all'):
                             data[sec][sec1][sec2]['update'] = None
 
             event = wxUpdateProperties(data=data)
@@ -1059,14 +1059,11 @@
                     if attrb == 'mask':
                         # TODO: invert mask
                         # TODO: broken in NVIZ
-                        # self.nvizClass.UnsetSurfaceMask(id)
-                        pass
+                        self.nvizClass.UnsetIsosurfaceMask(id, isosurfId)
                     elif attrb == 'transp':
-                        # self.nvizClass.UnsetSurfaceTransp(id)
-                        pass
+                        self.nvizClass.UnsetIsosurfaceTransp(id, isosurfId)
                     elif attrb == 'emit':
-                        # self.nvizClass.UnsetSurfaceEmit(id) 
-                        pass
+                        self.nvizClass.UnsetIsosurfaceEmit(id, isosurfId) 
                 else:
                     if type(value) == type('') and \
                             len(value) <= 0: # ignore empty values (TODO: warning)
@@ -1076,17 +1073,13 @@
                     elif attrb == 'mask':
                         # TODO: invert mask
                         # TODO: broken in NVIZ
-                        # self.nvizClass.SetSurfaceMask(id, False, str(value))
-                        pass
+                        self.nvizClass.SetIsosurfaceMask(id, isosurfId, False, str(value))
                     elif attrb == 'transp':
-                        # self.nvizClass.SetSurfaceTransp(id, map, str(value)) 
-                        pass
+                        self.nvizClass.SetIsosurfaceTransp(id, isosurfId, map, str(value)) 
                     elif attrb == 'shine':
-                        # self.nvizClass.SetSurfaceShine(id, map, str(value)) 
-                        pass
+                        self.nvizClass.SetIsosurfaceShine(id, isosurfId, map, str(value)) 
                     elif attrb == 'emit':
-                        # self.nvizClass.SetSurfaceEmit(id, map, str(value)) 
-                        pass
+                        self.nvizClass.SetIsosurfaceEmit(id, isosurfId, map, str(value)) 
                 isosurf[attrb].pop('update')
             isosurfId += 1
         

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2008-08-17 21:39:32 UTC (rev 32848)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2008-08-17 21:51:15 UTC (rev 32849)
@@ -6,7 +6,6 @@
 Classes:
  - NvizToolWindow
  - ViewPositionWindow
- - IsoSurfList
 
 (C) 2008 by the GRASS Development Team
 
@@ -797,8 +796,11 @@
         gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
 
         # list
-        isolevel = IsoSurfList(parent=panel, win=self.win['volume'],
-                               size=(300, 150))
+        isolevel = wx.CheckListBox(parent=panel, id=wx.ID_ANY,
+                                   size=(300, 150))
+        self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeIsosurfCheck, isolevel)
+        self.Bind(wx.EVT_LISTBOX, self.OnVolumeIsosurfSelect, isolevel)
+
         self.win['volume']['isosurfs'] = isolevel.GetId()
         gridSizer.Add(item=isolevel, pos=(0, 0), span=(4, 1))
         
@@ -905,8 +907,8 @@
                     value.SetRange(minVal=0, maxVal=255)
                 else:
                     value.SetRange(minVal=0, maxVal=100)
-                value.Bind(wx.EVT_SPINCTRL, self.OnSurfaceMap)
-                value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
+                value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
+                value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
             
             if value:
                 self.win['volume'][code]['const'] = value.GetId()
@@ -1613,6 +1615,9 @@
         if not attrb:
             return
 
+        if nvizType == 'volume' and attrb == 'topo':
+            return
+        
         selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
         if self.win[nvizType][attrb]['required']:
             selection += 1
@@ -2063,7 +2068,50 @@
     def OnVolumeIsosurfMap(self, event):
         """Set surface attribute"""
         self.SetMapObjAttrb(nvizType='volume', winId=event.GetId())
-                
+
+    def OnVolumeIsosurfCheck(self, event):
+        """Isosurface checked (->load) or unchecked (->unload)"""
+        index = event.GetSelection()
+        list = self.FindWindowById(self.win['volume']['isosurfs'])
+        data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']
+        id = data['object']['id']
+        
+        isosurfId = event.GetSelection()
+        
+        if list.IsChecked(index):
+            self.mapWindow.nvizClass.SetIsosurfaceTransp(id, isosurfId, False, "0")
+        else:
+            # disable -> make transparent
+            self.mapWindow.nvizClass.SetIsosurfaceTransp(id, isosurfId, False, "255")
+        
+        if self.parent.autoRender.IsChecked():
+            self.mapWindow.Refresh(False)
+        
+    def OnVolumeIsosurfSelect(self, event):
+        """Isosurface item selected"""
+        winUp = self.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
+        winDown = self.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
+        selection = event.GetSelection()
+        if selection == 0:
+            winUp.Enable(False)
+            if not winDown.IsEnabled():
+                winDown.Enable()
+        elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
+            winDown.Enable(False)
+            if not winUp.IsEnabled():
+                winUp.Enable()
+        else:
+            if not winDown.IsEnabled():
+                winDown.Enable()
+            if not winUp.IsEnabled():
+                winUp.Enable()
+        
+        # update dialog
+        layer = self.mapWindow.GetSelectedLayer()
+        data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']['isosurface'][selection]
+        
+        self.UpdateVolumeIsosurfPage(layer, data)
+
     def OnVolumeIsosurfAdd(self, event):
         """Add new isosurface to the list"""
         list = self.FindWindowById(self.win['volume']['isosurfs'])
@@ -2499,36 +2547,50 @@
 
         self.SetIsosurfaceMode(data['draw']['shading']['value'])
         self.SetIsosurfaceResolution(data['draw']['resolution']['value'])
-                
+            
+        self.UpdateVolumeIsosurfPage(layer, data['attribute'])
+        
+    def UpdateVolumeIsosurfPage(self, layer, data):
+        """Update dialog -- isosurface attributes"""
         #
         # isosurface attributes
         #
-        for attr in ('color', ): # required
-            if layer and layer.type == '3d-raster':
-                self.FindWindowById(self.win['volume'][attr]['map']).SetValue(layer.name)
+        for attrb in ('topo', 'color', 'mask',
+                     'transp', 'shine', 'emit'):
+            # check required first
+            if attrb == 'topo':
+                self.FindWindowById(self.win['volume'][attrb]['const']).SetValue(0)
+                continue
+            if attrb == 'color':
+                if layer and layer.type == '3d-raster':
+                    self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(layer.name)
+                else:
+                    self.FindWindowById(self.win['volume'][attrb]['map']).SetValue('')
+                self.SetMapObjUseMap(nvizType='volume',
+                                     attrb=attrb, map=True) # -> map
+                continue
+
+            # skip empty attributes
+            if not data.has_key(attrb):
+                continue
+            
+            value = data[attrb]['value']
+            if attrb == 'color':
+                if data[attrb]['map']:
+                    self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
+                else: # constant
+                    color = map(int, value.split(':'))
+                    self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
             else:
-                self.FindWindowById(self.win['volume'][attr]['map']).SetValue('')
+                if data[attrb]['map']:
+                    win = self.FindWindowById(self.win['volume'][attrb]['map'])
+                else:
+                    win = self.FindWindowById(self.win['volume'][attrb]['const'])
+                win.SetValue(value)
+            
             self.SetMapObjUseMap(nvizType='volume',
-                                 attrb=attr, map=True) # -> map
-        
-        if data['attribute'].has_key('color'):
-            value = data['attribute']['color']['value']
-            if data['attribute']['color']['map']:
-                self.FindWindowById(self.win['volume']['color']['map']).SetValue(value)
-            else: # constant
-                color = map(int, value.split(':'))
-                self.FindWindowById(self.win['volume']['color']['const']).SetColour(color)
-            self.SetMapObjUseMap(nvizType='volume',
-                                 attrb=attr, map=data['attribute']['color']['map'])
-
-        self.SetMapObjUseMap(nvizType='volume',
-                             attrb='shine', map=data['attribute']['shine']['map'])
-        value = data['attribute']['shine']['value']
-        if data['attribute']['shine']['map']:
-            self.FindWindowById(self.win['volume']['shine']['map']).SetValue(value)
-        else:
-            self.FindWindowById(self.win['volume']['shine']['const']).SetValue(value)
-        
+                                 attrb=attrb, map=data[attrb]['map'])
+            
     def SetPage(self, name):
         """Get named page"""
         self.notebook.SetSelection(self.page[name]['id'])
@@ -2604,37 +2666,4 @@
             self.mapWindow.Refresh(eraseBackground=False)
         
         event.Skip()
-
-class IsoSurfList(wx.CheckListBox):
-    """List of loaded volume isosurfaces (volume properties page)"""
-    def __init__(self, parent, win, id=wx.ID_ANY, size=wx.DefaultSize):
-        self.parent = parent
-        self.win = win
-        
-        wx.CheckListBox.__init__(self, parent, id, size=size)
-    
-        self.Bind(wx.EVT_CHECKLISTBOX, self.OnCheck)
-        self.Bind(wx.EVT_LISTBOX, self.OnSelect)
-    
-    def OnCheck(self, event):
-        """Item checked/unchecked -> load/delete surface"""
-        # event.IsChecked()
-        
-    def OnSelect(self, event):
-        """Item selected"""
-        winUp = self.parent.FindWindowById(self.win['btnIsosurfMoveUp'])
-        winDown = self.parent.FindWindowById(self.win['btnIsosurfMoveDown'])
-        selection = event.GetSelection()
-        if selection == 0:
-            winUp.Enable(False)
-            if not winDown.IsEnabled():
-                winDown.Enable()
-        elif selection == self.GetCount() - 1:
-            winDown.Enable(False)
-            if not winUp.IsEnabled():
-                winUp.Enable()
-        else:
-            if not winDown.IsEnabled():
-                winDown.Enable()
-            if not winUp.IsEnabled():
-                winUp.Enable()
+  

Modified: grass/trunk/gui/wxpython/nviz/nviz.h
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.h	2008-08-17 21:39:32 UTC (rev 32848)
+++ grass/trunk/gui/wxpython/nviz/nviz.h	2008-08-17 21:51:15 UTC (rev 32849)
@@ -104,6 +104,13 @@
     int DeleteIsosurface(int, int);
     int MoveIsosurface(int, int, bool);
     int SetIsosurfaceColor(int, int, bool, const char *);
+    int SetIsosurfaceMask(int, int, bool, const char *);
+    int SetIsosurfaceTransp(int, int, bool, const char *);
+    int SetIsosurfaceShine(int, int, bool, const char *);
+    int SetIsosurfaceEmit(int, int, bool, const char *);
+    int UnsetIsosurfaceMask(int, int);
+    int UnsetIsosurfaceTransp(int, int);
+    int UnsetIsosurfaceEmit(int, int);
     int SetIsosurfaceMode(int, int);
     int SetIsosurfaceRes(int, int);
 };

Modified: grass/trunk/gui/wxpython/nviz/volume.cpp
===================================================================
--- grass/trunk/gui/wxpython/nviz/volume.cpp	2008-08-17 21:39:32 UTC (rev 32848)
+++ grass/trunk/gui/wxpython/nviz/volume.cpp	2008-08-17 21:51:15 UTC (rev 32849)
@@ -103,9 +103,9 @@
 }
 
 /*!
-  \brief Set surface color
+  \brief Set isosurface color
 
-  \param id surface id
+  \param id volume id
   \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
   \param map if true use map otherwise constant
   \param value map name of value
@@ -113,7 +113,7 @@
   \return 1 on success
   \return -1 volume not found
   \return -2 isosurface not found
-  \return -3 setting attributes failed
+  \return -3 on failure
 */
 int Nviz::SetIsosurfaceColor(int id, int isosurf_id,
 			     bool map, const char *value)
@@ -122,6 +122,84 @@
 }
 
 /*!
+  \brief Set isosurface mask
+
+  @todo invert
+  
+  \param id volume id
+  \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+  \param invert true for invert mask
+  \param value map name to be used for mask
+
+  \return 1 on success
+  \return -1 volume not found
+  \return -2 isosurface not found
+  \return -3 on failure
+*/
+int Nviz::SetIsosurfaceMask(int id, int isosurf_id,
+			    bool invert, const char *value)
+{
+    return SetIsosurfaceAttr(id, isosurf_id, ATT_MASK, true, value);
+}
+
+/*!
+  \brief Set isosurface transparency
+
+  \param id volume id
+  \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return -1 volume not found
+  \return -2 isosurface not found
+  \return -3 on failure
+*/
+int Nviz::SetIsosurfaceTransp(int id, int isosurf_id,
+			      bool map, const char *value)
+{
+    return SetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP, map, value);
+}
+
+/*!
+  \brief Set isosurface shininess
+
+  \param id volume id
+  \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return -1 volume not found
+  \return -2 isosurface not found
+  \return -3 on failure
+*/
+int Nviz::SetIsosurfaceShine(int id, int isosurf_id,
+			     bool map, const char *value)
+{
+    return SetIsosurfaceAttr(id, isosurf_id, ATT_SHINE, map, value);
+}
+
+/*!
+  \brief Set isosurface emission
+
+  \param id volume id
+  \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return -1 volume not found
+  \return -2 isosurface not found
+  \return -3 on failure
+*/
+int Nviz::SetIsosurfaceEmit(int id, int isosurf_id,
+			    bool map, const char *value)
+{
+    return SetIsosurfaceAttr(id, isosurf_id, ATT_EMIT, map, value);
+}
+
+/*!
   \brief Set isosurface attribute
 
   \param id volume id
@@ -171,6 +249,54 @@
 }
 
 /*!
+  \brief Unset isosurface mask
+
+  \param id volume id
+  \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+
+  \return 1 on success
+  \return -1 volume not found
+  \return -2 isosurface not found
+  \return -3 setting attributes failed
+*/
+int Nviz::UnsetIsosurfaceMask(int id, int isosurf_id)
+{
+    return UnsetIsosurfaceAttr(id, isosurf_id, ATT_MASK);
+}
+
+/*!
+  \brief Unset isosurface transparency
+
+  \param id volume id
+  \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+
+  \return 1 on success
+  \return -1 volume not found
+  \return -2 isosurface not found
+  \return -3 setting attributes failed
+*/
+int Nviz::UnsetIsosurfaceTransp(int id, int isosurf_id)
+{
+    return UnsetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP);
+}
+
+/*!
+  \brief Unset isosurface emission
+
+  \param id volume id
+  \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+
+  \return 1 on success
+  \return -1 volume not found
+  \return -2 isosurface not found
+  \return -3 setting attributes failed
+*/
+int Nviz::UnsetIsosurfaceEmit(int id, int isosurf_id)
+{
+    return UnsetIsosurfaceAttr(id, isosurf_id, ATT_EMIT);
+}
+
+/*!
   \brief Unset surface attribute
 
   \param id surface id



More information about the grass-commit mailing list