Skip to content
Permalink
Browse files

[GRASS] fixed path to modules used in browser

  • Loading branch information
blazek committed Aug 24, 2015
1 parent f82b8c6 commit c078ce55064514ee694f204873ef10c90626402c
@@ -542,7 +542,7 @@ void QgsGrassModuleStandardOptions::freezeOutput()

QgsDebugMsg( "source = " + source );

// Check GISBASE and LOCATION
// Check GISDBASE and LOCATION
QStringList split = source.split( sep );

if ( split.size() < 4 )
@@ -617,7 +617,7 @@ void QgsGrassModuleStandardOptions::thawOutput()

QgsDebugMsg( "source = " + source );

// Check GISBASE and LOCATION
// Check GISDBASE and LOCATION
QStringList split = source.split( sep );

if ( split.size() < 4 )
@@ -1603,7 +1603,7 @@ void QgsGrassModuleInput::updateQgisLayers()

QgsDebugMsg( "source = " + source );

// Check GISBASE and LOCATION
// Check GISDBASE and LOCATION
QStringList split = source.split( sep, QString::SkipEmptyParts );

if ( split.size() < 4 )
@@ -1720,7 +1720,7 @@ void QgsGrassModuleInput::updateQgisLayers()
if ( source.contains( "cellhd" ) == 0 )
continue;

// Most probably GRASS layer, check GISBASE and LOCATION
// Most probably GRASS layer, check GISDBASE and LOCATION
QStringList split = source.split( sep, QString::SkipEmptyParts );

if ( split.size() < 4 )
@@ -328,7 +328,7 @@ void QgsGrass::init( void )
#else
QString gisBase = getenv( "GISBASE" );
#endif
QgsDebugMsg( QString( "GRASS gisBase from GISBASE env var is: %1" ).arg( gisBase ) );
QgsDebugMsg( QString( "GRASS gisBase from GISBASE/WINGISBASE env var is: %1" ).arg( gisBase ) );
if ( !isValidGrassBaseDir( gisBase ) )
{
// Look for gisbase in QSettings
@@ -381,7 +381,7 @@ void QgsGrass::init( void )
break;
}

// XXX Need to subclass this and add explantory message above to left side
// XXX Need to subclass this and add explantory message aboveSencha to left side
userGisbase = true;
// For Mac, GISBASE folder may be inside GRASS bundle. Use Qt file dialog
// since Mac native dialog doesn't allow user to browse inside bundles.
@@ -412,16 +412,18 @@ void QgsGrass::init( void )
}

QgsDebugMsg( QString( "Valid GRASS gisBase is: %1" ).arg( gisBase ) );
// GISBASE environment variable must be set because is required by directly called GRASS functions
putEnv( "GISBASE", gisBase );
mGisbase = gisBase;

// Create list of paths to GRASS modules
// PATH environment variable is not used to search for modules (since 2.12) because it could
// create a lot of confusion especially if both GRASS 6 and 7 are installed and path to one version
// $GISBASE/bin somehow gets to PATH and another version plugin is loaded to QGIS, because if a module
// is missing in one version, it could be found in another $GISBASE/bin and misleadin error could be reported
mGrassModulesPaths.clear();
mGrassModulesPaths << gisBase + "/bin";
mGrassModulesPaths << gisBase + "/scripts";
mGrassModulesPaths << gisbase() + "/bin";
mGrassModulesPaths << gisbase() + "/scripts";
mGrassModulesPaths << QgsApplication::pkgDataPath() + "/grass/scripts";

// On windows the GRASS libraries are in
@@ -450,7 +452,7 @@ void QgsGrass::init( void )

// TODO: move setting of PYTHONPATH to QProcess where necessary
// Set PYTHONPATH
QString pythonpath = gisBase + "/etc/python";
QString pythonpath = gisbase() + "/etc/python";
QString pp = getenv( "PYTHONPATH" );
pythonpath.append( pathSeparator() + pp );
QgsDebugMsg( QString( "set PYTHONPATH: %1" ).arg( pythonpath ) );
@@ -609,6 +611,7 @@ QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;

QString QgsGrass::error_message;

QString QgsGrass::mGisbase;
QStringList QgsGrass::mGrassModulesPaths;
QString QgsGrass::defaultGisdbase;
QString QgsGrass::defaultLocation;
@@ -685,8 +688,7 @@ QString QgsGrass::openMapset( const QString& gisdbase,
QString mapsetPath = gisdbase + "/" + location + "/" + mapset;

// Check if the mapset is in use
QString gisBase = getenv( "GISBASE" );
if ( gisBase.isEmpty() )
if ( !isValidGrassBaseDir( gisbase() ) )
return QObject::tr( "GISBASE is not set." );

QFileInfo fi( mapsetPath + "/WIND" );
@@ -708,7 +710,7 @@ QString QgsGrass::openMapset( const QString& gisdbase,
#ifndef Q_OS_WIN
QFile lockFile( lock );
QProcess process;
QString lockProgram( gisBase + "/etc/lock" );
QString lockProgram( gisbase() + "/etc/lock" );
QStringList lockArguments;
lockArguments << lock << QString::number( pid );
QString lockCommand = lockProgram + " " + lockArguments.join( " " ); // for debug
@@ -2028,7 +2030,7 @@ QMap<QString, QString> QgsGrass::query( QString gisdbase, QString location, QStr
void QgsGrass::renameObject( const QgsGrassObject & object, const QString& newName )
{
QgsDebugMsg( "entered" );
QString cmd = "g.rename";
QString cmd = gisbase() + "/bin/g.rename";
QStringList arguments;

arguments << object.elementShort() + "=" + object.name() + "," + newName;
@@ -2048,7 +2050,7 @@ void QgsGrass::copyObject( const QgsGrassObject & srcObject, const QgsGrassObjec
throw QgsGrass::Exception( QObject::tr( "Attempt to copy from different location." ) );
}

QString cmd = "g.copy";
QString cmd = gisbase() + "/bin/g.copy";
QStringList arguments;

arguments << srcObject.elementShort() + "=" + srcObject.name() + "@" + srcObject.mapset() + "," + destObject.name();
@@ -2074,8 +2076,7 @@ bool QgsGrass::deleteObject( const QgsGrassObject & object )
}
*/

// path to g.remove should be in PATH (added by QgsGrass::init())
QString cmd = "g.remove";
QString cmd = gisbase() + "/bin/g.remove";
QStringList arguments;

#if GRASS_VERSION_MAJOR < 7
@@ -126,7 +126,7 @@ class GRASS_LIB_EXPORT QgsGrassObject
Type mType;
};

/*!
/** QString gisdbase()
Methods for C library initialization and error handling.
*/
class GRASS_LIB_EXPORT QgsGrass : public QObject
@@ -159,6 +159,9 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
/** Get singleton instance of this class. Used as signals proxy between provider and plugin. */
static QgsGrass* instance();

/** Path to where GRASS is installed (GISBASE) */
static QString gisbase() { return mGisbase; }

//! 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,
@@ -530,6 +533,7 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
private:
static int initialized; // Set to 1 after initialization
static bool active; // is active mode
static QString mGisbase;
static QStringList mGrassModulesPaths;
static QString defaultGisdbase;
static QString defaultLocation;
@@ -816,8 +816,7 @@ int QgsGrassProvider::openMap( QString gisdbase, QString location, QString mapse
}
G_CATCH( QgsGrass::Exception &e )
{
Q_UNUSED( e );
QgsDebugMsg( QString( "Cannot open GRASS vector head on level2: %1" ).arg( e.what() ) );
QgsGrass::warning( e );
level = -1;
}

@@ -844,8 +843,7 @@ int QgsGrassProvider::openMap( QString gisdbase, QString location, QString mapse
}
G_CATCH( QgsGrass::Exception &e )
{
Q_UNUSED( e );
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
QgsGrass::warning( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
return -1;
}

@@ -862,8 +860,7 @@ int QgsGrassProvider::openMap( QString gisdbase, QString location, QString mapse
}
G_CATCH( QgsGrass::Exception &e )
{
Q_UNUSED( e );
QgsDebugMsg( QString( "Cannot build topology: %1" ).arg( e.what() ) );
QgsGrass::warning( QString( "Cannot build topology: %1" ).arg( e.what() ) );
return -1;
}
}

0 comments on commit c078ce5

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