Skip to content

Commit

Permalink
freeze/thaw output vector map on Windows
Browse files Browse the repository at this point in the history
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 94c2db1
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
152 changes: 152 additions & 0 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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>" );
}
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/grass/qgsgrassmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() ; }
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 94c2db1

Please sign in to comment.