Skip to content
Permalink
Browse files

Revert patch uncorrectly applied

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11434 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
pcav
pcav committed Aug 19, 2009
1 parent f05e245 commit 6accda401cbc4dccec2f8d39cba7edbe25467891
@@ -37,7 +37,7 @@ class QgsGrassModelItem
{
public:
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name,
QString path, int type );
QString path, int type );
QgsGrassModelItem();
~QgsGrassModelItem();

@@ -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];
}
@@ -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 )
{
@@ -897,6 +897,7 @@ QVariant QgsGrassModel::data( const QModelIndex &index, int role ) const
default:
return mIconDirectory;
}
return mIconDirectory;
}
return item->data( role );
}
@@ -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;
}

@@ -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
@@ -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" );
@@ -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

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

@@ -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;

@@ -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;

@@ -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 );
@@ -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() ) );
@@ -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,
@@ -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
@@ -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
@@ -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
@@ -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:
@@ -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

0 comments on commit 6accda4

Please sign in to comment.
You can’t perform that action at this time.