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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 23 17:06:28 EDT 2008


Author: martinl
Date: 2008-07-23 17:06:28 -0400 (Wed, 23 Jul 2008)
New Revision: 32231

Modified:
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/gui/wxpython/gui_modules/nviz.py
   grass/trunk/gui/wxpython/gui_modules/workspace.py
   grass/trunk/gui/wxpython/nviz/init.cpp
   grass/trunk/gui/wxpython/nviz/nviz.h
   grass/trunk/gui/wxpython/nviz/nviz.i
Log:
nviz/wxGUI: redirect error message from nviz module

Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2008-07-23 15:31:27 UTC (rev 32230)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2008-07-23 21:06:28 UTC (rev 32231)
@@ -105,7 +105,7 @@
         """
         if Debug.get_level() == 0:
             # don't redirect when debugging is enabled
-            # sys.stderr = self.cmd_stderr
+            sys.stderr = self.cmd_stderr
             
             return True
 

Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-23 15:31:27 UTC (rev 32230)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-23 21:06:28 UTC (rev 32231)
@@ -142,6 +142,7 @@
 
         dc = wx.PaintDC(self)
         self.SetCurrent()
+        
         if not self.init:
             self.nvizClass.InitView()
 
@@ -343,13 +344,21 @@
         while(len(listOfItems) > 0):
             item = listOfItems.pop()
             type = self.tree.GetPyData(item)[0]['type']
+            
+            try:
+                if type == 'raster':
+                    self.LoadRaster(item)
+            except gcmd.NvizError, e:
+                print >> sys.stderr, "Nviz: %s" % (self.nvizClass.GetErrorMsg())
+                print >> sys.stderr, "Nviz: " + e.message
 
-            if type == 'raster':
-                self.LoadRaster(item)
+            try:
+                if type == 'vector':
+                    self.LoadVector(item)
+            except gcmd.NvizError, e:
+                print >> sys.stderr, "Nviz: %s" % (self.nvizClass.GetErrorMsg())
+                print >> sys.stderr, "Nviz: " + e.message
 
-            elif type == 'vector':
-                self.LoadVector(item)
-                
         stop = time.time()
         
         Debug.msg(3, "GLWindow.LoadDataLayers(): time=%f" % (stop-start))
@@ -402,7 +411,7 @@
         id = self.nvizClass.LoadSurface(str(layer.name), None, None)
         if id < 0:
             raise gcmd.NvizError(parent=self.parent,
-                                 message=_("Unable to load raster map <%s>" % layer.name))
+                                 message=_("Raster map <%s> not loaded" % layer.name))
         
         self.layers['raster']['name'].append(layer.name)
         self.layers['raster']['id'].append(id)
@@ -587,7 +596,8 @@
 
             if id < 0:
                 raise gcmd.NvizError(parent=self.parent,
-                                     message=_("Unable to load vector map <%s>" % layer.name))
+                                     message=_("Vector map <%s> (%s) not loaded" % \
+                                                   (layer.name, type)))
 
             self.layers['v' + type]['name'].append(layer.name)
             self.layers['v'  + type]['id'].append(id)

Modified: grass/trunk/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/workspace.py	2008-07-23 15:31:27 UTC (rev 32230)
+++ grass/trunk/gui/wxpython/gui_modules/workspace.py	2008-07-23 21:06:28 UTC (rev 32231)
@@ -426,6 +426,9 @@
         for attrb in data.iterkeys():
             if len(data[attrb]) < 1: # skip empty attributes
                 continue
+            if attrb == 'object':
+                continue
+            
             for name in data[attrb].iterkeys():
                 # surface attribute
                 if attrb == 'attribute':

Modified: grass/trunk/gui/wxpython/nviz/init.cpp
===================================================================
--- grass/trunk/gui/wxpython/nviz/init.cpp	2008-07-23 15:31:27 UTC (rev 32230)
+++ grass/trunk/gui/wxpython/nviz/init.cpp	2008-07-23 21:06:28 UTC (rev 32231)
@@ -19,6 +19,8 @@
 #include "nviz.h"
 
 static void swap_gl();
+static int print_error(const char *, const int);
+static std::string *error;
 
 /*!
   \brief Initialize Nviz class instance
@@ -27,6 +29,9 @@
 {
     G_gisinit(""); /* GRASS functions */
 
+    error = new std::string();
+
+    G_set_error_routine(&print_error);
     G_set_verbose(0); // TODO: read progress info
 
     GS_libinit();
@@ -51,6 +56,8 @@
 
     data = NULL;
     glCanvas = NULL;
+
+    delete error;
 }
 
 /*!
@@ -127,3 +134,24 @@
 
     return;
 }
+
+std::string Nviz::GetErrorMsg()
+{
+    if (error) {
+	std::string retStr(*error);
+	error->clear();
+	return retStr;
+    }
+
+    return std::string();
+}
+
+int print_error(const char *msg, const int type)
+{
+    if (error) {
+	error->append(msg);
+	error->append("\n");
+    }
+
+    return 0;
+}

Modified: grass/trunk/gui/wxpython/nviz/nviz.h
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.h	2008-07-23 15:31:27 UTC (rev 32230)
+++ grass/trunk/gui/wxpython/nviz/nviz.h	2008-07-23 21:06:28 UTC (rev 32231)
@@ -1,6 +1,7 @@
 #ifndef WXNVIZ_H
 #define WXNVIZ_H
 
+#include <string>
 #include <vector>
 
 extern "C" {
@@ -41,6 +42,8 @@
     /* destructor */
     ~Nviz();
 
+    std::string GetErrorMsg();
+
     /* change_view.cpp */
     int ResizeWindow(int, int);
     std::vector<double> SetViewDefault();

Modified: grass/trunk/gui/wxpython/nviz/nviz.i
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.i	2008-07-23 15:31:27 UTC (rev 32230)
+++ grass/trunk/gui/wxpython/nviz/nviz.i	2008-07-23 21:06:28 UTC (rev 32231)
@@ -16,4 +16,7 @@
 namespace std { 
    %template(IntVecIntMap) map<int, vector<int> >;
 }
+
+%include "std_string.i"
+
 %include "nviz.h"



More information about the grass-commit mailing list