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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 6 18:26:57 EDT 2008


Author: martinl
Date: 2008-07-06 18:26:57 -0400 (Sun, 06 Jul 2008)
New Revision: 32036

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/nviz.py
   grass/trunk/gui/wxpython/nviz/draw.cpp
   grass/trunk/gui/wxpython/nviz/nviz.h
   grass/trunk/gui/wxpython/nviz/vector.cpp
Log:
nviz2/wxGUI: set vector height
buttons (apply, save, cancel) from tool window removed, various fixes towards workspace integration


Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-07-06 20:51:09 UTC (rev 32035)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-07-06 22:26:57 UTC (rev 32036)
@@ -179,6 +179,9 @@
         try:
             if nviz:
                 layer = self.tree.GetPyData(item)[0]['nviz']
+                if layer is None: # initialize data
+                    self.tree.GetPyData(item)[0]['nviz'] = {}
+                    layer = self.tree.GetPyData(item)[0]['nviz']
             else:
                 layer = self.tree.GetPyData(item)[0]['maplayer']
         except:
@@ -2606,14 +2609,19 @@
             # check for GLCanvas and OpenGL
             msg = None
             if not nviz.haveGLCanvas:
-                msg = _("Unable to start Nviz. The GLCanvas class has not been included with this build "
-                        "of wxPython! Switching back to 2D display mode.")
+                msg = _("Unable to start Nviz. The GLCanvas class has not been "
+                        "included with this build "
+                        "of wxPython! Switching back to "
+                        "2D display mode.\n\nDetails: %s" % nviz.errorMsg)
             if not nviz.haveOpenGL:
-                msg = _("Unable to start Nviz. The OpenGL package was not found. You can get it "
-                        "at http://PyOpenGL.sourceforge.net. Switching back to 2D display mode.")
+                msg = _("Unable to start Nviz. The OpenGL package "
+                        "was not found. You can get it "
+                        "at http://PyOpenGL.sourceforge.net. "
+                        "Switching back to 2D display mode.\n\nDetails: %s" % nviz.errorMsg)
             if not nviz.haveNviz:
-                msg = _("Unable to start Nviz. Python extension for Nviz was not found. "
-                        "Switching back to 2D display mode.")
+                msg = _("Unable to start Nviz. Python extension "
+                        "for Nviz was not found. "
+                        "Switching back to 2D display mode.\n\nDetails: %s" % nviz.errorMsg)
 
             if msg:
                 wx.MessageBox(parent=self,
@@ -2626,7 +2634,9 @@
             #
             self.toolbars['nviz'] = toolbars.NvizToolbar(self, self.Map)
             self.toolbars['map'].Enable2D(False)
-            self.toggleStatus.Enable(False)
+            
+            # erase map window
+            self.MapWindow.EraseMap()
 
             busy = wx.BusyInfo(message=_("Please wait, loading data..."),
                                parent=self)
@@ -2641,7 +2651,12 @@
                 self.nvizToolWin = nviz.NvizToolWindow(self, id=wx.ID_ANY,
                                                        mapWindow=self.MapWindow3D)
             
-
+            #
+            # update status bar
+            #
+            self.toggleStatus.Enable(False)
+            self.SetStatusText("")
+            
             busy.Destroy()
 
             self.nvizToolWin.Show()

Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-06 20:51:09 UTC (rev 32035)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-06 22:26:57 UTC (rev 32036)
@@ -26,18 +26,20 @@
 import wx
 import wx.lib.colourselect as csel
 import wx.lib.scrolledpanel as scrolled
+errorMsg = ''
 try:
     from wx import glcanvas
     haveGLCanvas = True
-except ImportError:
+except ImportError, e:
     haveGLCanvas = False
-
+    errorMsg = e
 try:
     from OpenGL.GL import *
     from OpenGL.GLUT import *
     haveOpenGL = True
-except ImportError:
+except ImportError, e:
     haveOpenGL = False
+    errorMsg = e
 
 import globalvar
 import gcmd
@@ -50,8 +52,9 @@
     sys.path.append(nvizPath)
     import grass7_wxnviz as wxnviz
     haveNviz = True
-except ImportError:
+except ImportError, e:
     haveNviz = False
+    errorMsg = e
 
 class GLWindow(MapWindow, glcanvas.GLCanvas):
     """OpenGL canvas for Map Display Window"""
@@ -222,11 +225,10 @@
         #glRotatef((self.y - self.lastY) * yScale, 1.0, 0.0, 0.0);
         #glRotatef((self.x - self.lastX) * xScale, 0.0, 1.0, 0.0);
 
-        self.parent.onRenderGauge.Show()
-        if self.parent.onRenderGauge.GetRange() > 0:
-            self.parent.onRenderGauge.SetValue(1)
-            self.parent.onRenderTimer.Start(100)
-        self.parent.onRenderCounter = 0
+        if self.render:
+            self.parent.onRenderGauge.Show()
+            self.parent.onRenderGauge.SetRange(2)
+            self.parent.onRenderGauge.SetValue(0)
 
         if 'view' in self.update.keys():
             self.nvizClass.SetView(self.view['pos']['x'], self.view['pos']['y'],
@@ -240,6 +242,8 @@
             del self.update['z-exag']
 
         if self.render is True:
+            self.parent.onRenderGauge.SetValue(1)
+            wx.Yield()
             self.nvizClass.Draw(False)
         else:
             self.nvizClass.Draw(True) # quick
@@ -248,17 +252,14 @@
 
         stop = time.clock()
 
-        #
-        # hide process bar
-        #
-        if self.parent.onRenderGauge.GetRange() > 0:
-            self.parent.onRenderTimer.Stop()
-        self.parent.onRenderGauge.Hide()
+        if self.render:
+            self.parent.onRenderGauge.SetValue(2)
+            # hide process bar
+            self.parent.onRenderGauge.Hide()
 
         #
         # update statusbar
         #
-        ### self.Map.SetRegion()
         # self.parent.StatusbarUpdate()
 
         Debug.msg(3, "GLWindow.UpdateMap(): render=%s, -> time=%g" % \
@@ -299,6 +300,7 @@
                                subkey=['draw', 'res-fine'])
         wire = UserSettings.Get(group='nviz', key='surface',
                                 subkey=['draw', 'res-coarse'])
+
         self.nvizClass.SetSurfaceRes(id, res, wire)
         self.object[self.Map.GetLayerIndex(layer)] = id ### FIXME layer index is not fixed id!
 
@@ -445,6 +447,7 @@
         # settings page
         self.__createSettingsPage()
         self.page['settings'] = 3
+        self.pageUpdated = True
         self.UpdatePage('surface')
         self.UpdatePage('vector')
         self.UpdatePage('settings')
@@ -453,29 +456,15 @@
                       flag=wx.EXPAND | wx.ALL, border=5)
 
         #
-        # button (see menuform)
+        # update dialog (selected layer)
         #
-        btnCancel = wx.Button(self, wx.ID_CANCEL)
-        btnApply = wx.Button(self, wx.ID_APPLY)
-        btnSave = wx.Button(self, wx.ID_SAVE)
-        btnSave.SetDefault()
-        # bindings
-        btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
-        btnApply.SetToolTipString(_("Apply changes and update display"))
-        btnApply.SetDefault()
-        btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
-        btnSave.SetToolTipString(_("Apply changes, update display and save changes to layer settings"))
-        btnCancel.Bind(wx.EVT_BUTTON, self.OnClose)
-        btnCancel.SetToolTipString(_("Hide dialog and ignore changes"))
-        # sizer
-        btnSizer = wx.StdDialogButtonSizer()
-        btnSizer.AddButton(btnApply)
-        btnSizer.AddButton(btnCancel)
-        btnSizer.AddButton(btnSave)
-        btnSizer.Realize()
-        
-        mainSizer.Add(item=btnSizer, proportion=0, flag=wx.ALIGN_CENTER | wx.ALL,
-                      border=5)
+        mapLayer = self.mapWindow.GetSelectedLayer()
+        if mapLayer:
+            type = mapLayer.type
+            if type == 'raster':
+                self.UpdatePage('surface')
+            elif type == 'vector':
+                self.UpdatePage('vector')
 
         #
         # bindings
@@ -1224,24 +1213,21 @@
             
         self.mapWindow.SetLayerSettings(data)
 
-    def OnApply(self, event):
-        """Apply button pressed
-        
-        Apply changes, update map
-        """
-        layer = self.mapWindow.GetSelectedLayer()
-        id = self.mapWindow.GetMapObjId(layer)
+    def UpdateLayerProperties(self):
+        """Update data layer properties"""
+        mapLayer = self.mapWindow.GetSelectedLayer()
+        data = self.mapWindow.GetSelectedLayer(nviz=True)
+        print '#1', data
+        id = self.mapWindow.GetMapObjId(mapLayer)
 
-        if layer.type == 'raster':
-            self.ApplySurface(id)
-        elif layer.type == 'vector':
-            self.ApplyVector(id)
+        if mapLayer.type == 'raster':
+            self.UpdateRasterProperties(id, data)
+        elif mapLayer.type == 'vector':
+            self.UpdateVectorProperies(id, data)
 
-        self.ApplySettings()
+        print '#2', self.mapWindow.GetSelectedLayer(nviz=True)
 
-        self.mapWindow.Refresh(False)
-
-    def ApplySurface(self, id):
+    def UpdateRasterProperties(self, id, data):
         """Apply changes for surfaces"""
         # surface attributes
         for attrb in ('topo', 'color', 'mask',
@@ -1276,6 +1262,8 @@
                     elif attrb == 'emit':
                         self.mapWindow.nvizClass.SetSurfaceEmit(id, map, str(value)) 
 
+                # update properties
+                data[attrb] = self.mapWindow.update[attrb]
                 del self.mapWindow.update[attrb]
 
         # draw res
@@ -1286,6 +1274,9 @@
             else:
                 self.mapWindow.nvizClass.SetSurfaceRes(id, fine, coarse)
 
+            # update properties
+            data['draw-res'] = self.mapWindow.update['draw-res']
+
         # draw style
         if self.mapWindow.update.has_key('draw-style'):
             style, all = self.mapWindow.update['draw-style']
@@ -1293,6 +1284,10 @@
                 self.mapWindow.nvizClass.SetSurfaceStyle(-1, style)
             else:
                 self.mapWindow.nvizClass.SetSurfaceStyle(id, style)
+
+            # update properties
+            data['draw-style'] = self.mapWindow.update['draw-style']
+
         # wire color
         if self.mapWindow.update.has_key('draw-color'):
             color, all = self.mapWindow.update['draw-color']
@@ -1301,20 +1296,19 @@
             else:
                 self.mapWindow.nvizClass.SetWireColor(-1, str(color))
 
-    def ApplyVector(self, id):
+            # update properties
+            data['draw-color'] = self.mapWindow.update['draw-color']
+
+    def UpdateVectorProperties(self, id, data):
         """Apply changes for vector"""
-        width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
-
-        color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
-        color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
-
-        if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
-            flat = False
-        else:
-            flat = True
-
-        self.mapWindow.nvizClass.SetVectorLineMode(id, str(color), width, flat)
-
+        if self.mapWindow.update.has_key('vector-lines'):
+            width, color, flat = self.mapWindow.update['vector-lines']
+            self.mapWindow.nvizClass.SetVectorLineMode(id, color, width, flat)
+            
+        if self.mapWindow.update.has_key('vector-height'):
+            height = self.mapWindow.update['vector-height']
+            self.mapWindow.nvizClass.SetVectorHeight(id, height)
+            
     def ApplySettings(self):
         """Apply changes in settings"""
         # bgcolor
@@ -1360,8 +1354,10 @@
         self.SetSurfaceUseMap(attrb, useMap)
         
         self.mapWindow.update[attrb] = (useMap, str(value))
+        self.UpdateLayerProperties()
+
         if self.parent.autoRender.IsChecked():
-            self.OnApply(None)
+            self.mapWindow.Refresh(False)
 
     def SetSurfaceUseMap(self, attrb, map=None):
         if attrb in ('topo', 'color', 'shine'):
@@ -1413,26 +1409,29 @@
                 value = self.FindWindowById(self.win['surface'][attrb]['const']).GetValue()
             map = False
 
-        self.mapWindow.update[attrb] = (map, str(value))
+        if self.pageUpdated: # do not update when selection is changed
+            self.mapWindow.update[attrb] = (map, str(value))
+            self.UpdateLayerProperties()
 
-        if self.parent.autoRender.IsChecked():
-            self.OnApply(None)
+            if self.parent.autoRender.IsChecked():
+                self.mapWindow.Refresh(False)
 
     def OnSurfaceResolution(self, event):
         """Draw resolution changed"""
         self.SetSurfaceResolution()
 
-    def SetSurfaceResolution(self, all=False, apply=True):
+        if apply and self.parent.autoRender.IsChecked():
+            self.mapWindow.Refresh(False)
+
+    def SetSurfaceResolution(self, all=False):
         """Set draw resolution"""
         coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
         fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
             
         self.mapWindow.update['draw-res'] = (coarse, fine, all) 
+        self.UpdateLayerProperties()
 
-        if apply and self.parent.autoRender.IsChecked():
-            self.OnApply(None)
-
-    def SetSurfaceMode(self, apply=True, all=False):
+    def SetSurfaceMode(self, all=False):
         """Set draw mode
 
         @param apply allow auto-rendering
@@ -1465,35 +1464,42 @@
         else: # surface
             value |= wxnviz.DM_GOURAUD
 
-        self.mapWindow.update['draw-style'] = (value, all)
+        if self.pageUpdated:
+            self.mapWindow.update['draw-style'] = (value, all)
+            self.UpdateLayerProperties()
 
-        if apply and self.parent.autoRender.IsChecked():
-            self.OnApply(None)
-
     def OnSurfaceMode(self, event):
         """Set draw mode"""
         self.SetSurfaceMode()
 
+        if apply and self.parent.autoRender.IsChecked():
+            self.mapWindow.Refresh(False)
+
     def OnSurfaceModeAll(self, event):
         """Set draw mode (including wire color) for all loaded surfaces"""
-        self.SetSurfaceMode(apply=False, all=True)
-        self.SetSurfaceResolution(apply=False, all=True)
+        self.SetSurfaceMode(all=True)
+        self.SetSurfaceResolution(all=True)
         color = self.FindWindowById(self.win['surface']['draw']['color']).GetColour()
         self.SetSurfaceWireColor(color, all=True)
 
-    def SetSurfaceWireColor(self, color, all=False):
+        if apply and self.parent.autoRender.IsChecked():
+            self.mapWindow.Refresh(False)
+
+    def SetSurfaceWireColor(self, color, all=False, apply=True):
         """Set wire color"""
         value = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
 
-        self.mapWindow.update['draw-color'] = (value, all)
+        if self.pageUpdated:
+            self.mapWindow.update['draw-color'] = (value, all)
+            self.UpdateLayerProperties()
 
-        if self.parent.autoRender.IsChecked():
-            self.OnApply(None)
-
     def OnSurfaceWireColor(self, event):
         """Set wire color"""
         self.SetSurfaceWireColor(event.GetValue())
 
+        if self.parent.autoRender.IsChecked():
+            self.mapWindow.Refresh(False)
+
     def OnVectorDisplay(self, event):
         """Display vector lines on surface/flat"""
         if event.GetSelection() == 0: # surface
@@ -1509,8 +1515,21 @@
 
     def OnVectorLines(self, event):
         """Set vector lines mode, apply changes if auto-rendering is enabled"""
+        width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
+
+        color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
+        color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
+
+        if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
+            flat = False
+        else:
+            flat = True
+
+        self.mapWindow.update['vector-lines'] = (width, color, flat)
+        self.UpdateLayerProperties()
+                
         if self.parent.autoRender.IsChecked():
-            self.OnApply(None)
+            self.mapWindow.Refresh(False)
         
     def OnVectorHeight(self, event):
         value = event.GetInt()
@@ -1521,18 +1540,22 @@
             # spin
             win = self.FindWindowById(self.win['vector']['lines']['height']['slider'])
         win.SetValue(value)
+
+        self.mapWindow.update['vector-height'] = value
+        self.UpdateLayerProperties()
+
+        if self.parent.autoRender.IsChecked():
+            self.mapWindow.Refresh(False)
     
-    def OnVectorHeightSpin(self, event):
-        print event
-    
     def OnSettings(self, event):
         """Update settings, apply changes if auto-rendering is enabled""" 
         
         if self.parent.autoRender.IsChecked():
-            self.OnApply(None)
+            self.mapWindow.Refresh(False)
             
     def UpdatePage(self, pageId):
         """Update dialog (selected page)"""
+        self.pageUpdated = False
         layer = self.mapWindow.GetSelectedLayer()
         data = self.mapWindow.GetSelectedLayer(nviz=True)
 
@@ -1542,24 +1565,24 @@
                 self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(0,
                                                                                   max)
         elif pageId == 'surface':
-            # disable vector and enable current
+            # disable vector and enable surface page
             self.notebook.GetPage(self.page['surface']).Enable(True)
             self.notebook.GetPage(self.page['vector']).Enable(False)
 
-            if data is None: # use default values
-                #
+            # use default values
+            if data == {}:
                 # attributes
-                #
-                for attr in ('topo', 'color'):
-                    self.SetSurfaceUseMap(attr, True) # -> map
+                for attr in ('topo', 'color'): # required
                     if layer and layer.type == 'raster':
                         self.FindWindowById(self.win['surface'][attr]['map']).SetValue(layer.name)
                     else:
                         self.FindWindowById(self.win['surface'][attr]['map']).SetValue('')
+                    self.SetSurfaceUseMap(attr, True) # -> map
                 if UserSettings.Get(group='nviz', key='surface', subkey=['shine', 'map']) is False:
                     self.SetSurfaceUseMap('shine', False)
                     value = UserSettings.Get(group='nviz', key='surface', subkey=['shine', 'value'])
                     self.FindWindowById(self.win['surface']['shine']['const']).SetValue(value)
+
                 #
                 # draw
                 #
@@ -1613,6 +1636,8 @@
                     win = self.FindWindowById(self.win['vector']['lines']['height'][type])
                     win.SetValue(value)
 
+        self.pageUpdated = True
+
     def SetPage(self, name):
         """Get named page"""
         self.notebook.SetSelection(self.page[name])

Modified: grass/trunk/gui/wxpython/nviz/draw.cpp
===================================================================
--- grass/trunk/gui/wxpython/nviz/draw.cpp	2008-07-06 20:51:09 UTC (rev 32035)
+++ grass/trunk/gui/wxpython/nviz/draw.cpp	2008-07-06 22:26:57 UTC (rev 32036)
@@ -26,14 +26,13 @@
 */
 void Nviz::Draw(bool quick)
 {
-
     Nviz_draw_cplane(data, -1, -1); // ?
 
     if (quick) {
-	Nviz_draw_quick(data, 1); // clear screen
+	Nviz_draw_quick(data); 
     }
     else {
-      Nviz_draw_all (data, 1); // clear screen
+      Nviz_draw_all (data); 
     }
 
     G_debug(1, "Nviz::Draw(): quick=%d",

Modified: grass/trunk/gui/wxpython/nviz/nviz.h
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.h	2008-07-06 20:51:09 UTC (rev 32035)
+++ grass/trunk/gui/wxpython/nviz/nviz.h	2008-07-06 22:26:57 UTC (rev 32036)
@@ -88,6 +88,7 @@
 
     /* vector */
     int SetVectorLineMode(int, const char *, int, int);
+    int SetVectorHeight(int, float);
 };
 
 #endif /* WXNVIZ_H */

Modified: grass/trunk/gui/wxpython/nviz/vector.cpp
===================================================================
--- grass/trunk/gui/wxpython/nviz/vector.cpp	2008-07-06 20:51:09 UTC (rev 32035)
+++ grass/trunk/gui/wxpython/nviz/vector.cpp	2008-07-06 22:26:57 UTC (rev 32036)
@@ -42,3 +42,22 @@
     
     return 1;
 }
+
+/**
+  \brief Set vector height above surface
+
+  \param id vector set id
+  \param height
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetVectorHeight(int id, float height)
+{
+    if(!GV_vect_exists(id))
+	return 0;
+    
+    GV_set_trans(id, 0.0, 0.0, height);
+
+    return 1;
+}



More information about the grass-commit mailing list