[QGIS Commit] r11433 - in trunk/qgis: . src/plugins/grass
src/providers/grass
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Aug 19 08:45:39 EDT 2009
Author: pcav
Date: 2009-08-19 08:45:38 -0400 (Wed, 19 Aug 2009)
New Revision: 11433
Modified:
trunk/qgis/DONORS
trunk/qgis/src/plugins/grass/qgsgrassmodel.cpp
trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp
trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp
trunk/qgis/src/plugins/grass/qgsgrassselect.cpp
trunk/qgis/src/providers/grass/qgsgrass.cpp
trunk/qgis/src/providers/grass/qgsgrass.h
trunk/qgis/src/providers/grass/qgsgrassprovider.cpp
Log:
Added donor detail
Modified: trunk/qgis/DONORS
===================================================================
--- trunk/qgis/DONORS 2009-08-19 06:27:09 UTC (rev 11432)
+++ trunk/qgis/DONORS 2009-08-19 12:45:38 UTC (rev 11433)
@@ -32,7 +32,7 @@
James Crone
Jaroslaw Kowalczyk
Jason Jorgenson
-John C. Tull
+John C. Tull|http://www.wildnevada.org
John Dean
Kanton Solothurn SOGIS
Kevin Shook
Modified: trunk/qgis/src/plugins/grass/qgsgrassmodel.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassmodel.cpp 2009-08-19 06:27:09 UTC (rev 11432)
+++ trunk/qgis/src/plugins/grass/qgsgrassmodel.cpp 2009-08-19 12:45:38 UTC (rev 11433)
@@ -37,7 +37,7 @@
{
public:
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name,
- QString path, int type );
+ QString path, int type );
QgsGrassModelItem();
~QgsGrassModelItem();
@@ -81,7 +81,7 @@
QgsGrassModelItem::~QgsGrassModelItem()
{
- for ( int i = 0; i < mChildren.size();i++ )
+ for ( int i = 0; i < mChildren.size(); i++ )
{
delete mChildren[i];
}
@@ -606,13 +606,13 @@
// Add new items
- for ( int i = 0; i < list.size();i++ )
+ for ( int i = 0; i < list.size(); i++ )
{
QString name = list.at( i );
// QgsDebugMsg(QString("? add %1").arg(name));
int insertAt = item->mChildren.size();
- for ( int i = 0; i < item->mChildren.size();i++ )
+ for ( int i = 0; i < item->mChildren.size(); i++ )
{
if ( item->mChildren[i]->name() == name )
{
@@ -897,7 +897,6 @@
default:
return mIconDirectory;
}
- return mIconDirectory;
}
return item->data( role );
}
Modified: trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp 2009-08-19 06:27:09 UTC (rev 11432)
+++ trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp 2009-08-19 12:45:38 UTC (rev 11433)
@@ -1268,17 +1268,20 @@
int ret = 0;
- QgsGrass::resetError();
- if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+ try
{
ret = G_make_location( location.toAscii().data(), &mCellHead, mProjInfo, mProjUnits, stdout );
}
- QgsGrass::clearErrorEnv();
+ catch ( QgsGrass::Exception &e )
+ {
+ ret = -1;
+ Q_UNUSED( e );
+ }
- if ( QgsGrass::getError() == QgsGrass::FATAL || ret != 0 )
+ if ( ret != 0 )
{
QMessageBox::warning( this, tr( "Create location" ),
- tr( "Cannot create new location: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ tr( "Cannot create new location: %1" ).arg( QgsGrass::errorMessage() ) );
return;
}
Modified: trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp 2009-08-19 06:27:09 UTC (rev 11432)
+++ trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp 2009-08-19 12:45:38 UTC (rev 11433)
@@ -301,14 +301,13 @@
QgsGrass::setLocation( sel->gisdbase, sel->location );
/* Open vector */
- QgsGrass::resetError();
- Vect_set_open_level( 2 );
- struct Map_info map;
- int level = Vect_open_old_head( &map, sel->map.toAscii().data(),
- sel->mapset.toAscii().data() );
+ try
+ {
+ Vect_set_open_level( 2 );
+ struct Map_info map;
+ int level = Vect_open_old_head( &map, sel->map.toAscii().data(),
+ sel->mapset.toAscii().data() );
- if ( QgsGrass::getError() != QgsGrass::FATAL )
- {
if ( level >= 2 )
{
// Count layers
@@ -336,9 +335,9 @@
Vect_close( &map );
}
- else
+ catch ( QgsGrass::Exception &e )
{
- QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QgsGrass::getErrorMessage() ) );
+ QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( e.what() ) );
}
qGisInterface->addVectorLayer( uri, name, "grass" );
@@ -486,26 +485,29 @@
QgsGrass::getDefaultLocation(),
QgsGrass::getDefaultMapset() );
- QgsGrass::resetError();
- struct Map_info Map;
- Vect_open_new( &Map, name.toAscii().data(), 0 );
-
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ try
{
- QMessageBox::warning( 0, tr( "Warning" ),
- tr( "Cannot create new vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
- return;
- }
+ struct Map_info Map;
+ Vect_open_new( &Map, name.toAscii().data(), 0 );
#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
- Vect_build( &Map );
+ Vect_build( &Map );
#else
- Vect_build( &Map, stderr );
+ Vect_build( &Map, stderr );
#endif
- Vect_set_release_support( &Map );
- Vect_close( &Map );
+ Vect_set_release_support( &Map );
+ Vect_close( &Map );
+ }
+ catch ( QgsGrass::Exception &e )
+ {
+ QMessageBox::warning( 0, tr( "Warning" ),
+ tr( "Cannot create new vector: %1" ).arg( e.what() ) );
+ return;
+ }
+
+
// Open in GRASS vector provider
QString uri = QgsGrass::getDefaultGisdbase() + "/"
Modified: trunk/qgis/src/plugins/grass/qgsgrassselect.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassselect.cpp 2009-08-19 06:27:09 UTC (rev 11432)
+++ trunk/qgis/src/plugins/grass/qgsgrassselect.cpp 2009-08-19 12:45:38 UTC (rev 11433)
@@ -410,15 +410,14 @@
// Call to setjmp() returns 0 first time. In case of fatal error,
// our error routine uses longjmp() to come back to this context,
// this time setjmp() will return non-zero value and we can continue...
- if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+
+ try
{
level = Vect_open_old_head( &map, ( char * ) mapName.toAscii().data(), ( char * ) mapset.toAscii().data() );
}
- QgsGrass::clearErrorEnv();
-
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ catch ( QgsGrass::Exception &e )
{
- QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
return list;
}
Modified: trunk/qgis/src/providers/grass/qgsgrass.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.cpp 2009-08-19 06:27:09 UTC (rev 11432)
+++ trunk/qgis/src/providers/grass/qgsgrass.cpp 2009-08-19 12:45:38 UTC (rev 11433)
@@ -54,7 +54,8 @@
// Set error function
G_set_error_routine( &error_routine );
- if ( initialized ) return;
+ if ( initialized )
+ return;
QSettings settings;
@@ -355,7 +356,7 @@
bool QgsGrass::active = 0;
-QgsGrass::GERROR QgsGrass::error = QgsGrass::OK;
+QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;
QString QgsGrass::error_message;
@@ -367,9 +368,6 @@
QString QgsGrass::mGisrc;
QString QgsGrass::mTmp;
-jmp_buf QgsGrass::mFatalErrorEnv;
-bool QgsGrass::mFatalErrorEnvActive = false;
-
int QgsGrass::error_routine( char *msg, int fatal )
{
return error_routine(( const char* ) msg, fatal );
@@ -383,52 +381,30 @@
if ( fatal )
{
- error = FATAL;
// we have to do a long jump here, otherwise GRASS >= 6.3 will kill our process
- if ( mFatalErrorEnvActive )
- longjmp( mFatalErrorEnv, 1 );
- else
- {
- QMessageBox::warning( 0, QObject::tr( "Uncatched fatal GRASS error" ), msg );
- abort();
- }
+ throw QgsGrass::Exception( msg );
}
else
- error = WARNING;
+ lastError = WARNING;
return 1;
}
void GRASS_EXPORT QgsGrass::resetError( void )
{
- error = OK;
+ lastError = OK;
}
-int GRASS_EXPORT QgsGrass::getError( void )
+int GRASS_EXPORT QgsGrass::error( void )
{
- return error;
+ return lastError;
}
-QString GRASS_EXPORT QgsGrass::getErrorMessage( void )
+QString GRASS_EXPORT QgsGrass::errorMessage( void )
{
return error_message;
}
-jmp_buf GRASS_EXPORT &QgsGrass::fatalErrorEnv()
-{
- if ( mFatalErrorEnvActive )
- QgsDebugMsg( "fatal error environment already active." );
- mFatalErrorEnvActive = true;
- return mFatalErrorEnv;
-}
-
-void GRASS_EXPORT QgsGrass::clearErrorEnv()
-{
- if ( !mFatalErrorEnvActive )
- QgsDebugMsg( "fatal error environment already deactive." );
- mFatalErrorEnvActive = false;
-}
-
QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, QString mapset )
{
QgsDebugMsg( QString( "gisdbase = %1" ).arg( gisdbase.toLocal8Bit().constData() ) );
Modified: trunk/qgis/src/providers/grass/qgsgrass.h
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.h 2009-08-19 06:27:09 UTC (rev 11432)
+++ trunk/qgis/src/providers/grass/qgsgrass.h 2009-08-19 12:45:38 UTC (rev 11433)
@@ -24,15 +24,21 @@
}
#include <QString>
-#include <setjmp.h>
/*!
Methods for C library initialization and error handling.
*/
class QgsGrass
{
-
public:
+ class Exception
+ {
+ QString mMsg;
+ public:
+ Exception( const char *msg ) : mMsg( msg ) {}
+ QString what() const { return mMsg; }
+ };
+
//! Get info about the mode
/*! QgsGrass may be running in active or passive mode.
* Active mode means that GISRC is set up and GISRC file is available,
@@ -64,10 +70,9 @@
*/
static GRASS_EXPORT void setMapset( QString gisdbase, QString location, QString mapset );
- //! Error codes returned by GetError()
+ //! Error codes returned by error()
enum GERROR { OK, /*!< OK. No error. */
- WARNING, /*!< Warning, non fatal error. Should be printed by application. */
- FATAL /*!< Fatal error. Function faild. */
+ WARNING /*!< Warning, non fatal error. Should be printed by application. */
};
//! Map type
@@ -77,10 +82,10 @@
static GRASS_EXPORT void resetError( void ); // reset error status
//! Check if any error occured in lately called functions. Returns value from ERROR.
- static GRASS_EXPORT int getError( void );
+ static GRASS_EXPORT int error( void );
//! Get last error message
- static GRASS_EXPORT QString getErrorMessage( void );
+ static GRASS_EXPORT QString errorMessage( void );
/** \brief Open existing GRASS mapset
* \return NULL string or error message
@@ -160,10 +165,6 @@
static GRASS_EXPORT int versionRelease();
static GRASS_EXPORT QString versionString();
- static GRASS_EXPORT jmp_buf& fatalErrorEnv();
- static GRASS_EXPORT void clearErrorEnv();
-
-
private:
static int initialized; // Set to 1 after initialization
static bool active; // is active mode
@@ -172,7 +173,7 @@
static QString defaultMapset;
/* last error in GRASS libraries */
- static GERROR error; // static, because used in constructor
+ static GERROR lastError; // static, because used in constructor
static QString error_message;
// G_set_error_routine has two versions of the function's first argument it expects:
@@ -188,10 +189,6 @@
static QString mGisrc;
// Temporary directory where GISRC and sockets are stored
static QString mTmp;
-
- // Context saved before a call to routine that can produce a fatal error
- static jmp_buf mFatalErrorEnv;
- static bool mFatalErrorEnvActive;
};
#endif // QGSGRASS_H
Modified: trunk/qgis/src/providers/grass/qgsgrassprovider.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrassprovider.cpp 2009-08-19 06:27:09 UTC (rev 11432)
+++ trunk/qgis/src/providers/grass/qgsgrassprovider.cpp 2009-08-19 12:45:38 UTC (rev 11433)
@@ -300,7 +300,8 @@
if ( isEdited() || isFrozen() || !mValid )
return false;
- if ( mCidxFieldIndex < 0 ) return false; // No features, no features in this layer
+ if ( mCidxFieldIndex < 0 || mNextCidx < mCidxFieldNumCats )
+ return false; // No features, no features in this layer
// Get next line/area id
int found = 0;
@@ -309,12 +310,17 @@
Vect_cidx_get_cat_by_index( mMap, mCidxFieldIndex, mNextCidx++, &cat, &type, &id );
// Warning: selection array is only of type line/area of current layer -> check type first
- if ( !( type & mGrassType ) ) continue;
- if ( !mSelection[id] ) continue;
+ if ( !( type & mGrassType ) )
+ continue;
+
+ if ( !mSelection[id] )
+ continue;
+
found = 1;
break;
}
- if ( !found ) return false; // No more features
+ if ( !found )
+ return false; // No more features
#if QGISDEBUG > 3
QgsDebugMsg( QString( "cat = %1 type = %2 id = %3" ).arg( cat ).arg( type ).arg( id ) );
#endif
@@ -655,16 +661,15 @@
// Open map
QgsGrass::init();
- QgsGrass::resetError();
- if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+
+ try
{
layer.mapId = openMap( gisdbase, location, mapset, mapName );
}
- QgsGrass::clearErrorEnv();
-
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ catch ( QgsGrass::Exception &e )
{
- QgsDebugMsg( QString( "Cannot open vector map: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ Q_UNUSED( e );
+ QgsDebugMsg( QString( "Cannot open vector map: %1" ).arg( e.what() ) );
return -1;
}
@@ -1020,53 +1025,55 @@
// Do we have topology and cidx (level2)
int level = 2;
- QgsGrass::resetError();
- Vect_set_open_level( 2 );
- Vect_open_old_head( map.map, mapName.toAscii().data(), mapset.toAscii().data() );
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ try
{
- QgsDebugMsg( QString( "Cannot open GRASS vector head on level2: %1" ).arg( QgsGrass::getErrorMessage() ) );
- level = 1;
+ Vect_set_open_level( 2 );
+ Vect_open_old_head( map.map, mapName.toAscii().data(), mapset.toAscii().data() );
+ Vect_close( map.map );
}
- else
+ catch ( QgsGrass::Exception &e )
{
- Vect_close( map.map );
+ QgsDebugMsg( QString( "Cannot open GRASS vector head on level2: %1" ).arg( e.what() ) );
+ level = 1;
}
if ( level == 1 )
{
QMessageBox::StandardButton ret = QMessageBox::question( 0, "Warning",
- "GRASS vector map " + mapName +
- + " does not have topology. Build topology?",
+ tr( "GRASS vector map %1 does not have topology. Build topology?" ).arg( mapName ),
QMessageBox::Ok | QMessageBox::Cancel );
if ( ret == QMessageBox::Cancel ) return -1;
}
// Open vector
- QgsGrass::resetError(); // to "catch" error after Vect_open_old()
- Vect_set_open_level( level );
- Vect_open_old( map.map, mapName.toAscii().data(), mapset.toAscii().data() );
-
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ try
{
- QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ Vect_set_open_level( level );
+ Vect_open_old( map.map, mapName.toAscii().data(), mapset.toAscii().data() );
+ }
+ catch ( QgsGrass::Exception &e )
+ {
+ Q_UNUSED( e );
+ QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
return -1;
}
if ( level == 1 )
{
- QgsGrass::resetError();
+ try
+ {
#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
- Vect_build( map.map );
+ Vect_build( map.map );
#else
- Vect_build( map.map, stderr );
+ Vect_build( map.map, stderr );
#endif
-
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ }
+ catch ( QgsGrass::Exception &e )
{
- QgsDebugMsg( QString( "Cannot build topology: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ Q_UNUSED( e );
+ QgsDebugMsg( QString( "Cannot build topology: %1" ).arg( e.what() ) );
return -1;
}
}
@@ -1107,17 +1114,15 @@
map->lastAttributesModified = di.lastModified();
// Reopen vector
- QgsGrass::resetError(); // to "catch" error after Vect_open_old()
- Vect_set_open_level( 2 );
- if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+ try
{
+ Vect_set_open_level( 2 );
Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
}
- QgsGrass::clearErrorEnv();
-
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ catch ( QgsGrass::Exception &e )
{
- QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ Q_UNUSED( e );
+ QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) );
// if reopen fails, mLayers should be also updated
for ( unsigned int i = 0; i < mLayers.size(); i++ )
@@ -1268,7 +1273,7 @@
GATT *att = ( GATT * ) bsearch( &key, mLayers[layerId].attributes, mLayers[layerId].nAttributes,
sizeof( GATT ), cmpAtt );
- for ( QgsAttributeList::const_iterator iter = attlist.begin(); iter != attlist.end();++iter )
+ for ( QgsAttributeList::const_iterator iter = attlist.begin(); iter != attlist.end(); ++iter )
{
if ( att != NULL )
{
@@ -1306,16 +1311,15 @@
const char *oldlocale = setlocale( LC_NUMERIC, NULL );
setlocale( LC_NUMERIC, "C" );
- if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+ try
{
G_get_default_window( &cellhd );
}
- QgsGrass::clearErrorEnv();
-
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ catch ( QgsGrass::Exception &e )
{
+ Q_UNUSED( e );
setlocale( LC_NUMERIC, oldlocale );
- QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( e.what() ) );
return QgsCoordinateReferenceSystem();
}
@@ -1473,40 +1477,37 @@
Vect_close( map->map );
// TODO: Catch error
+ int level = -1;
+ try
+ {
+ level = Vect_open_update( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
+ if ( level < 2 )
+ QgsDebugMsg( "Cannot open GRASS vector for update on level 2." );
+ }
+ catch ( QgsGrass::Exception &e )
+ {
+ Q_UNUSED( e );
+ QgsDebugMsg( QString( "Cannot open GRASS vector for update: %1" ).arg( e.what() ) );
+ }
- QgsGrass::resetError();
- int level = Vect_open_update( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
if ( level < 2 )
{
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ // reopen vector for reading
+ try
{
- QgsDebugMsg( QString( "Cannot open GRASS vector for update: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ Vect_set_open_level( 2 );
+ level = Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
+ if ( level < 2 )
+ QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::errorMessage() ) );
}
- else
+ catch ( QgsGrass::Exception &e )
{
- QgsDebugMsg( "Cannot open GRASS vector for update on level 2." );
+ Q_UNUSED( e );
+ QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) );
}
- // reopen vector for reading
- QgsGrass::resetError();
- Vect_set_open_level( 2 );
- level = Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
-
- if ( level < 2 )
- {
- if ( QgsGrass::getError() == QgsGrass::FATAL )
- {
- QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
- }
- else
- {
- QgsDebugMsg( "Cannot reopen GRASS vector on level 2." );
- }
- }
- else
- {
+ if ( level >= 2 )
map->valid = true;
- }
return false;
}
@@ -1588,14 +1589,15 @@
map->lastAttributesModified = di.lastModified();
// Reopen vector
- QgsGrass::resetError(); // to "catch" error after Vect_open_old()
- Vect_set_open_level( 2 );
-
- Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
-
- if ( QgsGrass::getError() == QgsGrass::FATAL )
+ try
{
- QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+ Vect_set_open_level( 2 );
+ Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
+ }
+ catch ( QgsGrass::Exception &e )
+ {
+ Q_UNUSED( e );
+ QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) );
return false;
}
More information about the QGIS-commit
mailing list