Skip to content
Permalink
Browse files

GRASS version support

  • Loading branch information
blazek committed Nov 7, 2011
1 parent 7ea5ee6 commit 4b12e5cf6269752526527cf7f0a8580eaaefb5bc
@@ -1,18 +1,4 @@
IF (GRASS_NUM_VERSION LESS 60300)
SET (GRASS_MODULES_DIR "modules-6.3")
ELSE (GRASS_NUM_VERSION LESS 60300)
SET (GRASS_MODULES_DIR "modules-${GRASS_MAJOR_VERSION}.${GRASS_MINOR_VERSION}")
ENDIF (GRASS_NUM_VERSION LESS 60300)

IF (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR}")
MESSAGE (SEND_ERROR "Your GRASS version is not supported (${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR} is not found).")
ENDIF (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR}")
IF (NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR}")
MESSAGE (SEND_ERROR "Your GRASS version is not supported (${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR} is not a Directory).")
ENDIF (NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR}")

ADD_SUBDIRECTORY(modules-common)
ADD_SUBDIRECTORY(${GRASS_MODULES_DIR})
ADD_SUBDIRECTORY(modules)
ADD_SUBDIRECTORY(scripts)

ADD_DEFINITIONS(-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\")
@@ -2,3 +2,7 @@
FILE (GLOB MODULE_FILES *.qgm *.svg *.png)
INSTALL (FILES ${MODULE_FILES}
DESTINATION ${QGIS_DATA_DIR}/grass/modules)

FILE (GLOB CONFIG *.qgc)
INSTALL (FILES ${CONFIG}
DESTINATION ${QGIS_DATA_DIR}/grass/config)
@@ -29,7 +29,7 @@
<grass name="r.in.gdal.qgis"/>
<grass name="r.in.gdal.qgis.loc"/>
</section>
<section label="Register external data sources in GRASS">
<section label="Register external data sources in GRASS" version_min="6.4">
<grass name="r.external"/>
<grass name="r.external.qgis"/>
<grass name="r.external.all"/>
@@ -63,7 +63,7 @@
<grass name="v.in.db"/>
<grass name="v.in.garmin"/>
<grass name="v.in.gpsbabel"/>
<grass name="v.in.geonames"/>
<grass name="v.in.geonames" version_min="6.4"/>
<grass name="v.in.gns"/>
</section>
<section label="Import from database into GRASS">
@@ -101,7 +101,7 @@
<grass name="v.out.vtk"/>
</section>
<section label="Export vector table from GRASS to database format">
<grass name="db.out.ogr"/>
<grass name="db.out.ogr" version_min="6.4"/>
</section>
</section>
<section label="Map type conversion">
@@ -169,7 +169,7 @@
<grass name="r.colors.table"/>
<grass name="r.colors.rules"/>
<grass name="r.colors.rast"/>
<grass name="r.colors.stddev"/>
<grass name="r.colors.stddev" version_min="6.4"/>
<grass name="r.blend"/>
<grass name="r.composite"/>
<grass name="r.his"/>
@@ -211,7 +211,7 @@
<grass name="r.texture"/>
<grass name="r.texture.bis"/>
<grass name="r.los"/>
<grass name="r.grow.distance"/>
<grass name="r.grow.distance" version_min="6.4"/>
<grass name="r.walk.coord"/>
<grass name="r.walk.vect"/>
</section>
@@ -263,7 +263,7 @@
<grass name="v.surf.bspline"/>
<grass name="v.surf.idw"/>
<grass name="v.surf.rst"/>
<grass name="r.bilinear"/>
<grass name="r.bilinear" version_min="6.4"/>
<grass name="r.surf.idw"/>
<grass name="r.surf.idw2"/>
<grass name="r.fillnulls"/>
@@ -457,7 +457,7 @@
<section label="Database management">
<grass name="db.connect"/>
<grass name="db.connect.schema"/>
<grass name="db.connect-login.pg"/>
<grass name="db.connect-login.pg" version_min="6.4"/>
<grass name="v.db.reconnect.all"/>
<grass name="db.login"/>
</section>
@@ -472,7 +472,7 @@
<grass name="v.db.update_query"/>
<grass name="v.db.update_op"/>
<grass name="v.db.update_op_query"/>
<grass name="v.db.dropcol"/>
<grass name="v.db.dropcol" version_min="6.4"/>
<grass name="v.db.renamecol"/>
<grass name="db.execute"/>
<grass name="db.select"/>
@@ -2,7 +2,10 @@
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">

<qgisgrassmodule label="Create fractal surface of given fractal dimension" module="r.surf.fractal">
<option key="dimension" />
<option key="number" />
<option key="output" />
<option key="d" version_max="6.3" />
<option key="dimension" version_min="6.4" />
<option key="n" version_max="6.3" />
<option key="number" version_min="6.4" />
<option key="out" version_max="6.3" />
<option key="output" version_min="6.4" />
</qgisgrassmodule>
@@ -3,6 +3,7 @@

<qgisgrassmodule label="Vector buffer" module="v.buffer">
<option key="input" typeoption="type" layeroption="layer" />
<option key="distance"/>
<option key="buffer" version_max="6.3"/>
<option key="distance" version_min="6.4"/>
<option key="output" />
</qgisgrassmodule>
@@ -3,6 +3,7 @@

<qgisgrassmodule label="Display vector attributes" module="v.db.select">
<option key="map" layeroption="layer" />
<field key="columns" layer="map" type="integer,double,varchar"/>
<field key="column" layer="map" type="integer,double,varchar" version_max="6.3"/>
<field key="columns" layer="map" type="integer,double,varchar" version_min="6.4"/>
<option key="fs" answer="|" hidden="yes" />
</qgisgrassmodule>
@@ -3,7 +3,8 @@

<qgisgrassmodule label="Display vector map attributes with SQL" module="v.db.select">
<option key="map" layeroption="layer" />
<field key="columns" layer="map" type="integer,double,varchar"/>
<field key="column" layer="map" type="integer,double,varchar" version_max="6.3"/>
<field key="columns" layer="map" type="integer,double,varchar" version_min="6.4"/>
<option key="where" />
<option key="fs" answer="|" hidden="yes" />
</qgisgrassmodule>
@@ -5,5 +5,6 @@
<option key="map" layeroption="layer"/>
<option key="option"/>
<option key="units"/>
<field key="columns" layer="map" type="integer,double" label="Attribute field" />
<field key="column" layer="map" type="integer,double" label="Attribute field" version_max="6.3" />
<field key="columns" layer="map" type="integer,double" label="Attribute field" version_min="6.4" />
</qgisgrassmodule>
@@ -410,6 +410,16 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions(
QDomElement e = n.toElement();
if ( !e.isNull() )
{
// Check GRASS version
QString version_min = e.attribute( "version_min" );
QString version_max = e.attribute( "version_max" );

if ( !QgsGrassModuleOption::checkVersion( e.attribute( "version_min" ), e.attribute( "version_max" ) ) )
{
n = n.nextSibling();
continue;
}

QString optionType = e.tagName();
QgsDebugMsg( "optionType = " + optionType );

@@ -2082,6 +2092,51 @@ QString QgsGrassModuleOption::value()
return value;
}

bool QgsGrassModuleOption::checkVersion( QString version_min, QString version_max )
{
QgsDebugMsg( "version_min = " + version_min );
QgsDebugMsg( "version_max = " + version_max );

QRegExp rxVersion( "(\\d+)\\.(\\d+)" );
if ( !version_min.isEmpty() )
{
if ( !rxVersion.exactMatch( version_min ) )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot parse version_min %1" ).arg( version_min ) );
return false;
}
else
{
int versionMajor = rxVersion.cap( 1 ).toInt();
int versionMinor = rxVersion.cap( 2 ).toInt();
if ( QgsGrass::versionMajor() < versionMajor || ( QgsGrass::versionMajor() == versionMajor && QgsGrass::versionMinor() < versionMinor ) )
{
return false;
}
}
}

if ( !version_max.isEmpty() )
{
if ( !rxVersion.exactMatch( version_max ) )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot parse version_max %1" ).arg( version_max ) );
return false;
}
else
{
int versionMajor = rxVersion.cap( 1 ).toInt();
int versionMinor = rxVersion.cap( 2 ).toInt();
if ( QgsGrass::versionMajor() > versionMajor || ( QgsGrass::versionMajor() == versionMajor && QgsGrass::versionMinor() > versionMinor ) )
{
return false;
}
}
}

return true;
}

QStringList QgsGrassModuleOption::options()
{
QStringList list;
@@ -491,6 +491,9 @@ class QgsGrassModuleOption: public QgsGrassModuleGroupBoxItem
// Use of region can be forced by 'region' attribute in qgm
bool usesRegion() { return mUsesRegion; }

//! Check min/max version
static bool checkVersion( QString version_min, QString version_max );

public slots:
// Add new line edit for multiple options
void addLineEdit();
@@ -267,12 +267,22 @@ void QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element )
{
// QgsDebugMsg(QString("tag = %1").arg(e.tagName()));

if ( e.tagName() == "section" && e.tagName() == "grass" )
if ( e.tagName() != "section" && e.tagName() != "grass" )
{
QgsDebugMsg( QString( "Unknown tag: %1" ).arg( e.tagName() ) );
continue;
}

// Check GRASS version
QString version_min = e.attribute( "version_min" );
QString version_max = e.attribute( "version_max" );

if ( !QgsGrassModuleOption::checkVersion( e.attribute( "version_min" ), e.attribute( "version_max" ) ) )
{
n = n.nextSibling();
continue;
}

if ( parent )
{
item = new QTreeWidgetItem( parent, lastItem );

0 comments on commit 4b12e5c

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