Skip to content

Commit

Permalink
Revert patch uncorrectly applied
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@11434 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
pcav committed Aug 19, 2009
1 parent 666c2a8 commit 9f47660
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 141 deletions.
9 changes: 5 additions & 4 deletions src/plugins/grass/qgsgrassmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class QgsGrassModelItem
{
public:
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name,
QString path, int type );
QString path, int type );
QgsGrassModelItem();
~QgsGrassModelItem();

Expand Down Expand Up @@ -81,7 +81,7 @@ QgsGrassModelItem::QgsGrassModelItem()

QgsGrassModelItem::~QgsGrassModelItem()
{
for ( int i = 0; i < mChildren.size(); i++ )
for ( int i = 0; i < mChildren.size();i++ )
{
delete mChildren[i];
}
Expand Down Expand Up @@ -606,13 +606,13 @@ void QgsGrassModel::addItems( QgsGrassModelItem *item, QStringList list, int typ

// 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 )
{
Expand Down Expand Up @@ -897,6 +897,7 @@ QVariant QgsGrassModel::data( const QModelIndex &index, int role ) const
default:
return mIconDirectory;
}
return mIconDirectory;
}
return item->data( role );
}
Expand Down
13 changes: 5 additions & 8 deletions src/plugins/grass/qgsgrassnewmapset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,20 +1268,17 @@ void QgsGrassNewMapset::createMapset()

int ret = 0;

try
QgsGrass::resetError();
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
{
ret = G_make_location( location.toAscii().data(), &mCellHead, mProjInfo, mProjUnits, stdout );
}
catch ( QgsGrass::Exception &e )
{
ret = -1;
Q_UNUSED( e );
}
QgsGrass::clearErrorEnv();

if ( ret != 0 )
if ( QgsGrass::getError() == QgsGrass::FATAL || ret != 0 )
{
QMessageBox::warning( this, tr( "Create location" ),
tr( "Cannot create new location: %1" ).arg( QgsGrass::errorMessage() ) );
tr( "Cannot create new location: %1" ).arg( QgsGrass::getErrorMessage() ) );
return;
}

Expand Down
46 changes: 22 additions & 24 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,14 @@ void QgsGrassPlugin::addVector()
QgsGrass::setLocation( sel->gisdbase, sel->location );

/* Open vector */
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() );
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() );

if ( QgsGrass::getError() != QgsGrass::FATAL )
{
if ( level >= 2 )
{
// Count layers
Expand Down Expand Up @@ -335,9 +336,9 @@ void QgsGrassPlugin::addVector()

Vect_close( &map );
}
catch ( QgsGrass::Exception &e )
else
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( e.what() ) );
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QgsGrass::getErrorMessage() ) );
}

qGisInterface->addVectorLayer( uri, name, "grass" );
Expand Down Expand Up @@ -485,28 +486,25 @@ void QgsGrassPlugin::newVector()
QgsGrass::getDefaultLocation(),
QgsGrass::getDefaultMapset() );

try
{
struct Map_info Map;
Vect_open_new( &Map, name.toAscii().data(), 0 );
QgsGrass::resetError();
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 );
#else
Vect_build( &Map, stderr );
#endif
Vect_set_release_support( &Map );
Vect_close( &Map );
}
catch ( QgsGrass::Exception &e )
if ( QgsGrass::getError() == QgsGrass::FATAL )
{
QMessageBox::warning( 0, tr( "Warning" ),
tr( "Cannot create new vector: %1" ).arg( e.what() ) );
tr( "Cannot create new vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
return;
}


#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
Vect_build( &Map );
#else
Vect_build( &Map, stderr );
#endif
Vect_set_release_support( &Map );
Vect_close( &Map );

// Open in GRASS vector provider

Expand Down
9 changes: 5 additions & 4 deletions src/plugins/grass/qgsgrassselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,15 @@ QStringList QgsGrassSelect::vectorLayers( QString gisdbase,
// 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...

try
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
{
level = Vect_open_old_head( &map, ( char * ) mapName.toAscii().data(), ( char * ) mapset.toAscii().data() );
}
catch ( QgsGrass::Exception &e )
QgsGrass::clearErrorEnv();

if ( QgsGrass::getError() == QgsGrass::FATAL )
{
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
return list;
}

Expand Down
42 changes: 33 additions & 9 deletions src/providers/grass/qgsgrass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ void GRASS_EXPORT QgsGrass::init( void )
// Set error function
G_set_error_routine( &error_routine );

if ( initialized )
return;
if ( initialized ) return;

QSettings settings;

Expand Down Expand Up @@ -356,7 +355,7 @@ int QgsGrass::initialized = 0;

bool QgsGrass::active = 0;

QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;
QgsGrass::GERROR QgsGrass::error = QgsGrass::OK;

QString QgsGrass::error_message;

Expand All @@ -368,6 +367,9 @@ QString QgsGrass::mMapsetLock;
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 );
Expand All @@ -381,30 +383,52 @@ int QgsGrass::error_routine( const char *msg, int fatal )

if ( fatal )
{
error = FATAL;
// we have to do a long jump here, otherwise GRASS >= 6.3 will kill our process
throw QgsGrass::Exception( msg );
if ( mFatalErrorEnvActive )
longjmp( mFatalErrorEnv, 1 );
else
{
QMessageBox::warning( 0, QObject::tr( "Uncatched fatal GRASS error" ), msg );
abort();
}
}
else
lastError = WARNING;
error = WARNING;

return 1;
}

void GRASS_EXPORT QgsGrass::resetError( void )
{
lastError = OK;
error = OK;
}

int GRASS_EXPORT QgsGrass::error( void )
int GRASS_EXPORT QgsGrass::getError( void )
{
return lastError;
return error;
}

QString GRASS_EXPORT QgsGrass::errorMessage( void )
QString GRASS_EXPORT QgsGrass::getErrorMessage( 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() ) );
Expand Down
29 changes: 16 additions & 13 deletions src/providers/grass/qgsgrass.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,15 @@ extern "C"
}

#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; }
};

public:
//! 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,
Expand Down Expand Up @@ -70,9 +64,10 @@ class QgsGrass
*/
static GRASS_EXPORT void setMapset( QString gisdbase, QString location, QString mapset );

//! Error codes returned by error()
//! Error codes returned by GetError()
enum GERROR { OK, /*!< OK. No error. */
WARNING /*!< Warning, non fatal error. Should be printed by application. */
WARNING, /*!< Warning, non fatal error. Should be printed by application. */
FATAL /*!< Fatal error. Function faild. */
};

//! Map type
Expand All @@ -82,10 +77,10 @@ class QgsGrass
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 error( void );
static GRASS_EXPORT int getError( void );

//! Get last error message
static GRASS_EXPORT QString errorMessage( void );
static GRASS_EXPORT QString getErrorMessage( void );

/** \brief Open existing GRASS mapset
* \return NULL string or error message
Expand Down Expand Up @@ -165,6 +160,10 @@ class QgsGrass
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
Expand All @@ -173,7 +172,7 @@ class QgsGrass
static QString defaultMapset;

/* last error in GRASS libraries */
static GERROR lastError; // static, because used in constructor
static GERROR error; // static, because used in constructor
static QString error_message;

// G_set_error_routine has two versions of the function's first argument it expects:
Expand All @@ -189,6 +188,10 @@ class QgsGrass
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
Loading

0 comments on commit 9f47660

Please sign in to comment.