1878_grassexception.diff
src/plugins/grass/qgsgrassplugin.cpp (working copy) | ||
---|---|---|
301 | 301 |
QgsGrass::setLocation( sel->gisdbase, sel->location ); |
302 | 302 | |
303 | 303 |
/* Open vector */ |
304 |
QgsGrass::resetError(); |
|
305 |
Vect_set_open_level( 2 ); |
|
306 |
struct Map_info map; |
|
307 |
int level = Vect_open_old_head( &map, sel->map.toAscii().data(), |
|
308 |
sel->mapset.toAscii().data() ); |
|
304 |
try |
|
305 |
{ |
|
306 |
Vect_set_open_level( 2 ); |
|
307 |
struct Map_info map; |
|
308 |
int level = Vect_open_old_head( &map, sel->map.toAscii().data(), |
|
309 |
sel->mapset.toAscii().data() ); |
|
309 | 310 | |
310 |
if ( QgsGrass::getError() != QgsGrass::FATAL ) |
|
311 |
{ |
|
312 | 311 |
if ( level >= 2 ) |
313 | 312 |
{ |
314 | 313 |
// Count layers |
... | ... | |
336 | 335 | |
337 | 336 |
Vect_close( &map ); |
338 | 337 |
} |
339 |
else
|
|
338 |
catch ( QgsGrass::Exception &e )
|
|
340 | 339 |
{ |
341 |
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QgsGrass::getErrorMessage() ) );
|
|
340 |
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( e.what() ) );
|
|
342 | 341 |
} |
343 | 342 | |
344 | 343 |
qGisInterface->addVectorLayer( uri, name, "grass" ); |
... | ... | |
486 | 485 |
QgsGrass::getDefaultLocation(), |
487 | 486 |
QgsGrass::getDefaultMapset() ); |
488 | 487 | |
489 |
QgsGrass::resetError(); |
|
490 |
struct Map_info Map; |
|
491 |
Vect_open_new( &Map, name.toAscii().data(), 0 ); |
|
492 | ||
493 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
488 |
try |
|
494 | 489 |
{ |
495 |
QMessageBox::warning( 0, tr( "Warning" ), |
|
496 |
tr( "Cannot create new vector: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
497 |
return; |
|
498 |
} |
|
490 |
struct Map_info Map; |
|
491 |
Vect_open_new( &Map, name.toAscii().data(), 0 ); |
|
499 | 492 | |
500 | 493 |
#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \ |
501 | 494 |
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 ) |
502 |
Vect_build( &Map ); |
|
495 |
Vect_build( &Map );
|
|
503 | 496 |
#else |
504 |
Vect_build( &Map, stderr ); |
|
497 |
Vect_build( &Map, stderr );
|
|
505 | 498 |
#endif |
506 |
Vect_set_release_support( &Map ); |
|
507 |
Vect_close( &Map ); |
|
499 |
Vect_set_release_support( &Map ); |
|
500 |
Vect_close( &Map ); |
|
501 |
} |
|
502 |
catch ( QgsGrass::Exception &e ) |
|
503 |
{ |
|
504 |
QMessageBox::warning( 0, tr( "Warning" ), |
|
505 |
tr( "Cannot create new vector: %1" ).arg( e.what() ) ); |
|
506 |
return; |
|
507 |
} |
|
508 | 508 | |
509 | ||
510 | ||
509 | 511 |
// Open in GRASS vector provider |
510 | 512 | |
511 | 513 |
QString uri = QgsGrass::getDefaultGisdbase() + "/" |
src/plugins/grass/qgsgrassnewmapset.cpp (working copy) | ||
---|---|---|
1268 | 1268 | |
1269 | 1269 |
int ret = 0; |
1270 | 1270 | |
1271 |
QgsGrass::resetError(); |
|
1272 |
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 ) |
|
1271 |
try |
|
1273 | 1272 |
{ |
1274 | 1273 |
ret = G_make_location( location.toAscii().data(), &mCellHead, mProjInfo, mProjUnits, stdout ); |
1275 | 1274 |
} |
1276 |
QgsGrass::clearErrorEnv(); |
|
1275 |
catch ( QgsGrass::Exception &e ) |
|
1276 |
{ |
|
1277 |
ret = -1; |
|
1278 |
Q_UNUSED( e ); |
|
1279 |
} |
|
1277 | 1280 | |
1278 |
if ( QgsGrass::getError() == QgsGrass::FATAL || ret != 0 )
|
|
1281 |
if ( ret != 0 ) |
|
1279 | 1282 |
{ |
1280 | 1283 |
QMessageBox::warning( this, tr( "Create location" ), |
1281 |
tr( "Cannot create new location: %1" ).arg( QgsGrass::getErrorMessage() ) );
|
|
1284 |
tr( "Cannot create new location: %1" ).arg( QgsGrass::errorMessage() ) );
|
|
1282 | 1285 |
return; |
1283 | 1286 |
} |
1284 | 1287 |
src/plugins/grass/qgsgrassmodel.cpp (working copy) | ||
---|---|---|
36 | 36 |
class QgsGrassModelItem |
37 | 37 |
{ |
38 | 38 |
public: |
39 |
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name, |
|
40 |
QString path, int type ); |
|
39 |
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name, QString path, int type ); |
|
41 | 40 |
QgsGrassModelItem(); |
42 | 41 |
~QgsGrassModelItem(); |
43 | 42 | |
... | ... | |
81 | 80 | |
82 | 81 |
QgsGrassModelItem::~QgsGrassModelItem() |
83 | 82 |
{ |
84 |
for ( int i = 0; i < mChildren.size();i++ ) |
|
83 |
for ( int i = 0; i < mChildren.size(); i++ )
|
|
85 | 84 |
{ |
86 | 85 |
delete mChildren[i]; |
87 | 86 |
} |
... | ... | |
606 | 605 | |
607 | 606 |
// Add new items |
608 | 607 | |
609 |
for ( int i = 0; i < list.size();i++ ) |
|
608 |
for ( int i = 0; i < list.size(); i++ )
|
|
610 | 609 |
{ |
611 | 610 |
QString name = list.at( i ); |
612 | 611 |
// QgsDebugMsg(QString("? add %1").arg(name)); |
613 | 612 | |
614 | 613 |
int insertAt = item->mChildren.size(); |
615 |
for ( int i = 0; i < item->mChildren.size();i++ ) |
|
614 |
for ( int i = 0; i < item->mChildren.size(); i++ )
|
|
616 | 615 |
{ |
617 | 616 |
if ( item->mChildren[i]->name() == name ) |
618 | 617 |
{ |
... | ... | |
897 | 896 |
default: |
898 | 897 |
return mIconDirectory; |
899 | 898 |
} |
900 |
return mIconDirectory; |
|
901 | 899 |
} |
902 | 900 |
return item->data( role ); |
903 | 901 |
} |
src/plugins/grass/qgsgrassselect.cpp (working copy) | ||
---|---|---|
410 | 410 |
// Call to setjmp() returns 0 first time. In case of fatal error, |
411 | 411 |
// our error routine uses longjmp() to come back to this context, |
412 | 412 |
// this time setjmp() will return non-zero value and we can continue... |
413 |
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 ) |
|
413 | ||
414 |
try |
|
414 | 415 |
{ |
415 | 416 |
level = Vect_open_old_head( &map, ( char * ) mapName.toAscii().data(), ( char * ) mapset.toAscii().data() ); |
416 | 417 |
} |
417 |
QgsGrass::clearErrorEnv(); |
|
418 | ||
419 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
418 |
catch ( QgsGrass::Exception &e ) |
|
420 | 419 |
{ |
421 |
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
420 |
Q_UNUSED( e ); |
|
421 |
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) ); |
|
422 | 422 |
return list; |
423 | 423 |
} |
424 | 424 |
src/core/qgsmessageoutput.cpp (working copy) | ||
---|---|---|
62 | 62 |
{ |
63 | 63 |
// show title if provided |
64 | 64 |
if ( !mTitle.isNull() ) |
65 |
{ |
|
65 | 66 |
QgsDebugMsg( QString( "%1:" ).arg( mTitle ) ); |
67 |
} |
|
68 | ||
66 | 69 |
// show the message |
67 | 70 |
QgsDebugMsg( mMessage ); |
68 | 71 |
emit destroyed(); |
src/providers/grass/qgsgrass.h (working copy) | ||
---|---|---|
23 | 23 |
#include <grass/form.h> |
24 | 24 |
} |
25 | 25 | |
26 |
#include <stdexcept> |
|
26 | 27 |
#include <QString> |
27 |
#include <setjmp.h> |
|
28 | 28 | |
29 | 29 |
/*! |
30 | 30 |
Methods for C library initialization and error handling. |
31 | 31 |
*/ |
32 | 32 |
class QgsGrass |
33 | 33 |
{ |
34 | ||
35 | 34 |
public: |
35 |
struct Exception : public std::runtime_error |
|
36 |
{ |
|
37 |
Exception( const std::string &msg ) : std::runtime_error( msg ) {} |
|
38 |
}; |
|
39 | ||
36 | 40 |
//! Get info about the mode |
37 | 41 |
/*! QgsGrass may be running in active or passive mode. |
38 | 42 |
* Active mode means that GISRC is set up and GISRC file is available, |
... | ... | |
64 | 68 |
*/ |
65 | 69 |
static GRASS_EXPORT void setMapset( QString gisdbase, QString location, QString mapset ); |
66 | 70 | |
67 |
//! Error codes returned by GetError()
|
|
71 |
//! Error codes returned by error()
|
|
68 | 72 |
enum GERROR { OK, /*!< OK. No error. */ |
69 |
WARNING, /*!< Warning, non fatal error. Should be printed by application. */ |
|
70 |
FATAL /*!< Fatal error. Function faild. */ |
|
73 |
WARNING /*!< Warning, non fatal error. Should be printed by application. */ |
|
71 | 74 |
}; |
72 | 75 | |
73 | 76 |
//! Map type |
... | ... | |
77 | 80 |
static GRASS_EXPORT void resetError( void ); // reset error status |
78 | 81 | |
79 | 82 |
//! Check if any error occured in lately called functions. Returns value from ERROR. |
80 |
static GRASS_EXPORT int getError( void );
|
|
83 |
static GRASS_EXPORT int error( void );
|
|
81 | 84 | |
82 | 85 |
//! Get last error message |
83 |
static GRASS_EXPORT QString getErrorMessage( void );
|
|
86 |
static GRASS_EXPORT QString errorMessage( void );
|
|
84 | 87 | |
85 | 88 |
/** \brief Open existing GRASS mapset |
86 | 89 |
* \return NULL string or error message |
... | ... | |
160 | 163 |
static GRASS_EXPORT int versionRelease(); |
161 | 164 |
static GRASS_EXPORT QString versionString(); |
162 | 165 | |
163 |
static GRASS_EXPORT jmp_buf& fatalErrorEnv(); |
|
164 |
static GRASS_EXPORT void clearErrorEnv(); |
|
165 | ||
166 | ||
167 | 166 |
private: |
168 | 167 |
static int initialized; // Set to 1 after initialization |
169 | 168 |
static bool active; // is active mode |
... | ... | |
172 | 171 |
static QString defaultMapset; |
173 | 172 | |
174 | 173 |
/* last error in GRASS libraries */ |
175 |
static GERROR error; // static, because used in constructor
|
|
174 |
static GERROR lastError; // static, because used in constructor
|
|
176 | 175 |
static QString error_message; |
177 | 176 | |
178 | 177 |
// G_set_error_routine has two versions of the function's first argument it expects: |
... | ... | |
188 | 187 |
static QString mGisrc; |
189 | 188 |
// Temporary directory where GISRC and sockets are stored |
190 | 189 |
static QString mTmp; |
191 | ||
192 |
// Context saved before a call to routine that can produce a fatal error |
|
193 |
static jmp_buf mFatalErrorEnv; |
|
194 |
static bool mFatalErrorEnvActive; |
|
195 | 190 |
}; |
196 | 191 | |
197 | 192 |
#endif // QGSGRASS_H |
src/providers/grass/qgsgrassprovider.cpp (working copy) | ||
---|---|---|
218 | 218 | |
219 | 219 |
mValid = false; |
220 | 220 | |
221 |
if ( ! mMaps[mLayers[mLayerId].mapId].valid ) return; |
|
221 |
if ( !mMaps[mLayers[mLayerId].mapId].valid ) |
|
222 |
return; |
|
222 | 223 | |
223 | 224 |
// Getting the total number of features in the layer |
224 | 225 |
// It may happen that the field disappeares from the map (deleted features, new map without that field) |
... | ... | |
300 | 301 |
if ( isEdited() || isFrozen() || !mValid ) |
301 | 302 |
return false; |
302 | 303 | |
303 |
if ( mCidxFieldIndex < 0 ) return false; // No features, no features in this layer |
|
304 |
if ( mCidxFieldIndex < 0 || mNextCidx >= mCidxFieldNumCats ) |
|
305 |
return false; // No features, no features in this layer |
|
304 | 306 | |
305 | 307 |
// Get next line/area id |
306 | 308 |
int found = 0; |
... | ... | |
309 | 311 |
Vect_cidx_get_cat_by_index( mMap, mCidxFieldIndex, mNextCidx++, &cat, &type, &id ); |
310 | 312 |
// Warning: selection array is only of type line/area of current layer -> check type first |
311 | 313 | |
312 |
if ( !( type & mGrassType ) ) continue; |
|
313 |
if ( !mSelection[id] ) continue; |
|
314 |
if ( !( type & mGrassType ) ) |
|
315 |
continue; |
|
316 | ||
317 |
if ( !mSelection[id] ) |
|
318 |
continue; |
|
319 | ||
314 | 320 |
found = 1; |
315 | 321 |
break; |
316 | 322 |
} |
317 |
if ( !found ) return false; // No more features |
|
323 |
if ( !found ) |
|
324 |
return false; // No more features |
|
318 | 325 |
#if QGISDEBUG > 3 |
319 | 326 |
QgsDebugMsg( QString( "cat = %1 type = %2 id = %3" ).arg( cat ).arg( type ).arg( id ) ); |
320 | 327 |
#endif |
... | ... | |
655 | 662 | |
656 | 663 |
// Open map |
657 | 664 |
QgsGrass::init(); |
658 |
QgsGrass::resetError(); |
|
659 |
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
|
|
665 | ||
666 |
try
|
|
660 | 667 |
{ |
661 | 668 |
layer.mapId = openMap( gisdbase, location, mapset, mapName ); |
662 | 669 |
} |
663 |
QgsGrass::clearErrorEnv(); |
|
664 | ||
665 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
670 |
catch ( QgsGrass::Exception &e ) |
|
666 | 671 |
{ |
667 |
QgsDebugMsg( QString( "Cannot open vector map: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
672 |
Q_UNUSED( e ); |
|
673 |
QgsDebugMsg( QString( "Cannot open vector map: %1" ).arg( e.what() ) ); |
|
668 | 674 |
return -1; |
669 | 675 |
} |
670 | 676 | |
... | ... | |
1020 | 1026 | |
1021 | 1027 |
// Do we have topology and cidx (level2) |
1022 | 1028 |
int level = 2; |
1023 |
QgsGrass::resetError(); |
|
1024 |
Vect_set_open_level( 2 ); |
|
1025 |
Vect_open_old_head( map.map, mapName.toAscii().data(), mapset.toAscii().data() ); |
|
1026 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
1029 |
try |
|
1027 | 1030 |
{ |
1028 |
QgsDebugMsg( QString( "Cannot open GRASS vector head on level2: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
1029 |
level = 1; |
|
1031 |
Vect_set_open_level( 2 ); |
|
1032 |
Vect_open_old_head( map.map, mapName.toAscii().data(), mapset.toAscii().data() ); |
|
1033 |
Vect_close( map.map ); |
|
1030 | 1034 |
} |
1031 |
else
|
|
1035 |
catch ( QgsGrass::Exception &e )
|
|
1032 | 1036 |
{ |
1033 |
Vect_close( map.map ); |
|
1037 |
Q_UNUSED( e ); |
|
1038 |
QgsDebugMsg( QString( "Cannot open GRASS vector head on level2: %1" ).arg( e.what() ) ); |
|
1039 |
level = 1; |
|
1034 | 1040 |
} |
1035 | 1041 | |
1036 | 1042 |
if ( level == 1 ) |
1037 | 1043 |
{ |
1038 | 1044 |
QMessageBox::StandardButton ret = QMessageBox::question( 0, "Warning", |
1039 |
"GRASS vector map " + mapName + |
|
1040 |
+ " does not have topology. Build topology?", |
|
1045 |
tr( "GRASS vector map %1 does not have topology. Build topology?" ).arg( mapName ), |
|
1041 | 1046 |
QMessageBox::Ok | QMessageBox::Cancel ); |
1042 | 1047 | |
1043 | 1048 |
if ( ret == QMessageBox::Cancel ) return -1; |
1044 | 1049 |
} |
1045 | 1050 | |
1046 | 1051 |
// Open vector |
1047 |
QgsGrass::resetError(); // to "catch" error after Vect_open_old() |
|
1048 |
Vect_set_open_level( level ); |
|
1049 |
Vect_open_old( map.map, mapName.toAscii().data(), mapset.toAscii().data() ); |
|
1050 | ||
1051 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
1052 |
try |
|
1052 | 1053 |
{ |
1053 |
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
1054 |
Vect_set_open_level( level ); |
|
1055 |
Vect_open_old( map.map, mapName.toAscii().data(), mapset.toAscii().data() ); |
|
1056 |
} |
|
1057 |
catch ( QgsGrass::Exception &e ) |
|
1058 |
{ |
|
1059 |
Q_UNUSED( e ); |
|
1060 |
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) ); |
|
1054 | 1061 |
return -1; |
1055 | 1062 |
} |
1056 | 1063 | |
1057 | 1064 |
if ( level == 1 ) |
1058 | 1065 |
{ |
1059 |
QgsGrass::resetError(); |
|
1066 |
try |
|
1067 |
{ |
|
1060 | 1068 |
#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \ |
1061 | 1069 |
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 ) |
1062 |
Vect_build( map.map ); |
|
1070 |
Vect_build( map.map );
|
|
1063 | 1071 |
#else |
1064 |
Vect_build( map.map, stderr ); |
|
1072 |
Vect_build( map.map, stderr );
|
|
1065 | 1073 |
#endif |
1066 | ||
1067 |
if ( QgsGrass::getError() == QgsGrass::FATAL )
|
|
1074 |
} |
|
1075 |
catch ( QgsGrass::Exception &e )
|
|
1068 | 1076 |
{ |
1069 |
QgsDebugMsg( QString( "Cannot build topology: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
1077 |
Q_UNUSED( e ); |
|
1078 |
QgsDebugMsg( QString( "Cannot build topology: %1" ).arg( e.what() ) ); |
|
1070 | 1079 |
return -1; |
1071 | 1080 |
} |
1072 | 1081 |
} |
... | ... | |
1098 | 1107 |
// TODO: Is it necessary for close ? |
1099 | 1108 |
G__setenv(( char * )"MAPSET", map->mapset.toAscii().data() ); |
1100 | 1109 | |
1101 |
if ( closeMap ) Vect_close( map->map ); |
|
1110 |
if ( closeMap ) |
|
1111 |
Vect_close( map->map ); |
|
1102 | 1112 | |
1103 | 1113 |
QFileInfo di( map->gisdbase + "/" + map->location + "/" + map->mapset + "/vector/" + map->mapName ); |
1104 | 1114 |
map->lastModified = di.lastModified(); |
... | ... | |
1107 | 1117 |
map->lastAttributesModified = di.lastModified(); |
1108 | 1118 | |
1109 | 1119 |
// Reopen vector |
1110 |
QgsGrass::resetError(); // to "catch" error after Vect_open_old() |
|
1111 |
Vect_set_open_level( 2 ); |
|
1112 |
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 ) |
|
1120 |
try |
|
1113 | 1121 |
{ |
1122 |
Vect_set_open_level( 2 ); |
|
1114 | 1123 |
Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() ); |
1115 | 1124 |
} |
1116 |
QgsGrass::clearErrorEnv(); |
|
1117 | ||
1118 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
1125 |
catch ( QgsGrass::Exception &e ) |
|
1119 | 1126 |
{ |
1120 |
QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
1127 |
Q_UNUSED( e ); |
|
1128 |
QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) ); |
|
1121 | 1129 | |
1122 | 1130 |
// if reopen fails, mLayers should be also updated |
1123 | 1131 |
for ( unsigned int i = 0; i < mLayers.size(); i++ ) |
... | ... | |
1168 | 1176 |
bool mapsetunset = G__getenv( "MAPSET" ) == NULL || *G__getenv( "MAPSET" ) == 0; |
1169 | 1177 |
if ( mapsetunset ) |
1170 | 1178 |
G__setenv(( char * )"MAPSET", mMaps[mapId].mapset.toAscii().data() ); |
1171 |
Vect_close( mMaps[mapId].map ); |
|
1179 |
try |
|
1180 |
{ |
|
1181 |
Vect_close( mMaps[mapId].map ); |
|
1182 |
} |
|
1183 |
catch ( QgsGrass::Exception &e ) |
|
1184 |
{ |
|
1185 |
Q_UNUSED( e ); |
|
1186 |
QgsDebugMsg( QString( "Vect_close failed: %1" ).arg( e.what() ) ); |
|
1187 |
} |
|
1172 | 1188 |
if ( mapsetunset ) |
1173 | 1189 |
G__setenv(( char * )"MAPSET", "" ); |
1174 | 1190 |
} |
... | ... | |
1268 | 1284 |
GATT *att = ( GATT * ) bsearch( &key, mLayers[layerId].attributes, mLayers[layerId].nAttributes, |
1269 | 1285 |
sizeof( GATT ), cmpAtt ); |
1270 | 1286 | |
1271 |
for ( QgsAttributeList::const_iterator iter = attlist.begin(); iter != attlist.end();++iter ) |
|
1287 |
for ( QgsAttributeList::const_iterator iter = attlist.begin(); iter != attlist.end(); ++iter )
|
|
1272 | 1288 |
{ |
1273 | 1289 |
if ( att != NULL ) |
1274 | 1290 |
{ |
... | ... | |
1306 | 1322 |
const char *oldlocale = setlocale( LC_NUMERIC, NULL ); |
1307 | 1323 |
setlocale( LC_NUMERIC, "C" ); |
1308 | 1324 | |
1309 |
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
|
|
1325 |
try
|
|
1310 | 1326 |
{ |
1311 | 1327 |
G_get_default_window( &cellhd ); |
1312 | 1328 |
} |
1313 |
QgsGrass::clearErrorEnv(); |
|
1314 | ||
1315 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
1329 |
catch ( QgsGrass::Exception &e ) |
|
1316 | 1330 |
{ |
1331 |
Q_UNUSED( e ); |
|
1317 | 1332 |
setlocale( LC_NUMERIC, oldlocale ); |
1318 |
QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( QgsGrass::getErrorMessage() ) );
|
|
1333 |
QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( e.what() ) );
|
|
1319 | 1334 |
return QgsCoordinateReferenceSystem(); |
1320 | 1335 |
} |
1321 | 1336 | |
... | ... | |
1473 | 1488 |
Vect_close( map->map ); |
1474 | 1489 | |
1475 | 1490 |
// TODO: Catch error |
1476 | ||
1477 |
QgsGrass::resetError(); |
|
1478 |
int level = Vect_open_update( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() ); |
|
1479 |
if ( level < 2 ) |
|
1491 |
int level = -1; |
|
1492 |
try |
|
1480 | 1493 |
{ |
1481 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
1494 |
level = Vect_open_update( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() ); |
|
1495 |
if ( level < 2 ) |
|
1482 | 1496 |
{ |
1483 |
QgsDebugMsg( QString( "Cannot open GRASS vector for update: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
1484 |
} |
|
1485 |
else |
|
1486 |
{ |
|
1487 | 1497 |
QgsDebugMsg( "Cannot open GRASS vector for update on level 2." ); |
1488 | 1498 |
} |
1499 |
} |
|
1500 |
catch ( QgsGrass::Exception &e ) |
|
1501 |
{ |
|
1502 |
Q_UNUSED( e ); |
|
1503 |
QgsDebugMsg( QString( "Cannot open GRASS vector for update: %1" ).arg( e.what() ) ); |
|
1504 |
} |
|
1489 | 1505 | |
1506 |
if ( level < 2 ) |
|
1507 |
{ |
|
1490 | 1508 |
// reopen vector for reading |
1491 |
QgsGrass::resetError(); |
|
1492 |
Vect_set_open_level( 2 ); |
|
1493 |
level = Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() ); |
|
1494 | ||
1495 |
if ( level < 2 ) |
|
1509 |
try |
|
1496 | 1510 |
{ |
1497 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
1511 |
Vect_set_open_level( 2 ); |
|
1512 |
level = Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() ); |
|
1513 |
if ( level < 2 ) |
|
1498 | 1514 |
{ |
1499 |
QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
|
|
1515 |
QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::errorMessage() ) );
|
|
1500 | 1516 |
} |
1501 |
else |
|
1502 |
{ |
|
1503 |
QgsDebugMsg( "Cannot reopen GRASS vector on level 2." ); |
|
1504 |
} |
|
1505 | 1517 |
} |
1506 |
else
|
|
1518 |
catch ( QgsGrass::Exception &e )
|
|
1507 | 1519 |
{ |
1508 |
map->valid = true; |
|
1520 |
Q_UNUSED( e ); |
|
1521 |
QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) ); |
|
1509 | 1522 |
} |
1510 | 1523 | |
1524 |
if ( level >= 2 ) |
|
1525 |
map->valid = true; |
|
1526 | ||
1511 | 1527 |
return false; |
1512 | 1528 |
} |
1513 | 1529 |
Vect_set_category_index_update( map->map ); |
... | ... | |
1588 | 1604 |
map->lastAttributesModified = di.lastModified(); |
1589 | 1605 | |
1590 | 1606 |
// Reopen vector |
1591 |
QgsGrass::resetError(); // to "catch" error after Vect_open_old() |
|
1592 |
Vect_set_open_level( 2 ); |
|
1593 | ||
1594 |
Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() ); |
|
1595 | ||
1596 |
if ( QgsGrass::getError() == QgsGrass::FATAL ) |
|
1607 |
try |
|
1597 | 1608 |
{ |
1598 |
QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) ); |
|
1609 |
Vect_set_open_level( 2 ); |
|
1610 |
Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() ); |
|
1611 |
} |
|
1612 |
catch ( QgsGrass::Exception &e ) |
|
1613 |
{ |
|
1614 |
Q_UNUSED( e ); |
|
1615 |
QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) ); |
|
1599 | 1616 |
return false; |
1600 | 1617 |
} |
1601 | 1618 |
src/providers/grass/provider.cpp (working copy) | ||
---|---|---|
14 | 14 |
* * |
15 | 15 |
***************************************************************************/ |
16 | 16 |
#include <string.h> |
17 |
#include <iostream> |
|
18 | 17 |
#include <vector> |
19 | 18 |
#include <cfloat> |
20 | 19 |
src/providers/grass/qgsgrass.cpp (working copy) | ||
---|---|---|
54 | 54 |
// Set error function |
55 | 55 |
G_set_error_routine( &error_routine ); |
56 | 56 | |
57 |
if ( initialized ) return; |
|
57 |
if ( initialized ) |
|
58 |
return; |
|
58 | 59 | |
59 | 60 |
QSettings settings; |
60 | 61 | |
... | ... | |
355 | 356 | |
356 | 357 |
bool QgsGrass::active = 0; |
357 | 358 | |
358 |
QgsGrass::GERROR QgsGrass::error = QgsGrass::OK;
|
|
359 |
QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;
|
|
359 | 360 | |
360 | 361 |
QString QgsGrass::error_message; |
361 | 362 | |
... | ... | |
367 | 368 |
QString QgsGrass::mGisrc; |
368 | 369 |
QString QgsGrass::mTmp; |
369 | 370 | |
370 |
jmp_buf QgsGrass::mFatalErrorEnv; |
|
371 |
bool QgsGrass::mFatalErrorEnvActive = false; |
|
372 | ||
373 | 371 |
int QgsGrass::error_routine( char *msg, int fatal ) |
374 | 372 |
{ |
375 | 373 |
return error_routine(( const char* ) msg, fatal ); |
... | ... | |
383 | 381 | |
384 | 382 |
if ( fatal ) |
385 | 383 |
{ |
386 |
error = FATAL; |
|
387 | 384 |
// we have to do a long jump here, otherwise GRASS >= 6.3 will kill our process |
388 |
if ( mFatalErrorEnvActive ) |
|
389 |
longjmp( mFatalErrorEnv, 1 ); |
|
390 |
else |
|
391 |
{ |
|
392 |
QMessageBox::warning( 0, QObject::tr( "Uncatched fatal GRASS error" ), msg ); |
|
393 |
abort(); |
|
394 |
} |
|
385 |
throw QgsGrass::Exception( msg ); |
|
395 | 386 |
} |
396 | 387 |
else |
397 |
error = WARNING;
|
|
388 |
lastError = WARNING;
|
|
398 | 389 | |
399 | 390 |
return 1; |
400 | 391 |
} |
401 | 392 | |
402 | 393 |
void GRASS_EXPORT QgsGrass::resetError( void ) |
403 | 394 |
{ |
404 |
error = OK;
|
|
395 |
lastError = OK;
|
|
405 | 396 |
} |
406 | 397 | |
407 |
int GRASS_EXPORT QgsGrass::getError( void )
|
|
398 |
int GRASS_EXPORT QgsGrass::error( void )
|
|
408 | 399 |
{ |
409 |
return error;
|
|
400 |
return lastError;
|
|
410 | 401 |
} |
411 | 402 | |
412 |
QString GRASS_EXPORT QgsGrass::getErrorMessage( void )
|
|
403 |
QString GRASS_EXPORT QgsGrass::errorMessage( void )
|
|
413 | 404 |
{ |
414 | 405 |
return error_message; |
415 | 406 |
} |
416 | 407 | |
417 |
jmp_buf GRASS_EXPORT &QgsGrass::fatalErrorEnv() |
|
418 |
{ |
|
419 |
if ( mFatalErrorEnvActive ) |
|
420 |
QgsDebugMsg( "fatal error environment already active." ); |
|
421 |
mFatalErrorEnvActive = true; |
|
422 |
return mFatalErrorEnv; |
|
423 |
} |
|
424 | ||
425 |
void GRASS_EXPORT QgsGrass::clearErrorEnv() |
|
426 |
{ |
|
427 |
if ( !mFatalErrorEnvActive ) |
|
428 |
QgsDebugMsg( "fatal error environment already deactive." ); |
|
429 |
mFatalErrorEnvActive = false; |
|
430 |
} |
|
431 | ||
432 | 408 |
QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, QString mapset ) |
433 | 409 |
{ |
434 | 410 |
QgsDebugMsg( QString( "gisdbase = %1" ).arg( gisdbase.toLocal8Bit().constData() ) ); |