Skip to content
Permalink
Browse files
freeze/thaw output vector map on Windows
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5861 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Sep 22, 2006
1 parent cc2762b commit 94c2db18d3d41d3626f390fcee88dc0e2219b89a
Showing with 160 additions and 0 deletions.
  1. +152 −0 src/plugins/grass/qgsgrassmodule.cpp
  2. +8 −0 src/plugins/grass/qgsgrassmodule.h
@@ -594,6 +594,154 @@ QStringList QgsGrassModuleStandardOptions::checkOutput()
return list;
}

void QgsGrassModuleStandardOptions::freezeOutput()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleStandardOptions::freezeOutput()" << std::endl;
#endif

#ifdef WIN32
for ( int i = 0; i < mItems.size(); i++ )
{
if ( typeid(*(mItems[i])) != typeid (QgsGrassModuleOption) ) {
continue;
}
QgsGrassModuleOption *opt =
dynamic_cast<QgsGrassModuleOption *> ( mItems[i] );

std::cerr << "opt->key() = " << opt->key().ascii() << std::endl;

if ( opt->isOutput()
&& opt->outputType() == QgsGrassModuleOption::Vector )
{
std::cerr << "freeze vector layers" << std::endl;

QChar sep = '/';

int nlayers = mCanvas->layerCount();
for ( int i = 0; i < nlayers; i++ )
{
QgsMapLayer *layer = mCanvas->getZpos(i);

if ( layer->type() != QgsMapLayer::VECTOR ) continue;

QgsVectorLayer *vector = (QgsVectorLayer*)layer;
if ( vector->providerType() != "grass" ) continue;

//TODO dynamic_cast ?
QgsGrassProvider *provider = (QgsGrassProvider *) vector->getDataProvider();

// TODO add map() mapset() location() gisbase() to grass provider
QString source = QDir::cleanPath ( provider->getDataSourceUri() );
#ifdef QGISDEBUG
std::cerr << "source = " << source.ascii() << std::endl;
#endif

// Check GISBASE and LOCATION
QStringList split = QStringList::split ( sep, source );

if ( split.size() < 4 ) continue;
split.pop_back(); // layer

QString map = split.last();
split.pop_back(); // map

QString mapset = split.last();
split.pop_back(); // mapset

QString loc = source.remove ( QRegExp("/[^/]+/[^/]+/[^/]+$") );
loc = QDir(loc).canonicalPath();

QDir curlocDir ( QgsGrass::getDefaultGisdbase() + sep + QgsGrass::getDefaultLocation() );
QString curloc = curlocDir.canonicalPath();

if ( loc != curloc ) continue;

if ( mapset != QgsGrass::getDefaultMapset() ) continue;

if ( provider->isFrozen() ) continue;

provider->freeze();
}
}
}
#endif
}

void QgsGrassModuleStandardOptions::thawOutput()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleStandardOptions::thawOutput()" << std::endl;
#endif

#ifdef WIN32
for ( int i = 0; i < mItems.size(); i++ )
{
if ( typeid(*(mItems[i])) != typeid (QgsGrassModuleOption) ) {
continue;
}
QgsGrassModuleOption *opt =
dynamic_cast<QgsGrassModuleOption *> ( mItems[i] );

std::cerr << "opt->key() = " << opt->key().ascii() << std::endl;

if ( opt->isOutput()
&& opt->outputType() == QgsGrassModuleOption::Vector )
{
std::cerr << "thaw vector layers" << std::endl;

QChar sep = '/';

int nlayers = mCanvas->layerCount();
for ( int i = 0; i < nlayers; i++ )
{
QgsMapLayer *layer = mCanvas->getZpos(i);

if ( layer->type() != QgsMapLayer::VECTOR ) continue;

QgsVectorLayer *vector = (QgsVectorLayer*)layer;
if ( vector->providerType() != "grass" ) continue;

//TODO dynamic_cast ?
QgsGrassProvider *provider = (QgsGrassProvider *) vector->getDataProvider();

// TODO add map() mapset() location() gisbase() to grass provider
QString source = QDir::cleanPath ( provider->getDataSourceUri() );
#ifdef QGISDEBUG
std::cerr << "source = " << source.ascii() << std::endl;
#endif

// Check GISBASE and LOCATION
QStringList split = QStringList::split ( sep, source );

if ( split.size() < 4 ) continue;
split.pop_back(); // layer

QString map = split.last();
split.pop_back(); // map

QString mapset = split.last();
split.pop_back(); // mapset

QString loc = source.remove ( QRegExp("/[^/]+/[^/]+/[^/]+$") );
loc = QDir(loc).canonicalPath();

QDir curlocDir ( QgsGrass::getDefaultGisdbase() + sep + QgsGrass::getDefaultLocation() );
QString curloc = curlocDir.canonicalPath();

if ( loc != curloc ) continue;

if ( mapset != QgsGrass::getDefaultMapset() ) continue;

if ( !provider->isFrozen() ) continue;

provider->thaw();
}
}
}
#endif
}

QStringList QgsGrassModuleStandardOptions::output(int type )
{
#ifdef QGISDEBUG
@@ -1227,6 +1375,9 @@ void QgsGrassModule::run()
QString cmd = execArguments.takeFirst();
execArguments += arguments;

// Freeze output vector on Windows
mOptions->freezeOutput();

mProcess.setEnvironment ( environment );
mProcess.start( cmd, execArguments );

@@ -1256,6 +1407,7 @@ void QgsGrassModule::finished(int exitCode, QProcess::ExitStatus exitStatus )
mProgressBar->setProgress ( 100, 100 );
mSuccess = true;
mViewButton->setEnabled(true);
mOptions->thawOutput();
} else {
mOutputTextBrowser->append( "<B>Finished with error</B>" );
}
@@ -196,6 +196,12 @@ class QgsGrassModuleOptions
// return list of existing output maps
virtual QStringList checkOutput() { return QStringList() ; }

//! Freeze output vector maps used in QGIS on Windows
virtual void freezeOutput() { return; }

//! Thaw output vector maps used in QGIS on Windows
virtual void thawOutput() { return; }

//! Check if otpion is ready
// Returns empty string or error message
virtual QStringList ready() { return QStringList() ; }
@@ -270,6 +276,8 @@ class QgsGrassModuleStandardOptions: public QgsGrassModuleOptions, QWidget

// Reimplemented methods from QgsGrassModuleOptions
QStringList checkOutput();
void freezeOutput();
void thawOutput();
QStringList ready() ;
QStringList output(int type);
QStringList checkRegion();

0 comments on commit 94c2db1

Please sign in to comment.