Skip to content

Commit 573fea7

Browse files
author
rblazek
committedSep 22, 2006
freeze/thaw output vector map on Windows
git-svn-id: http://svn.osgeo.org/qgis/trunk@5861 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent cc4d3b9 commit 573fea7

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed
 

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,154 @@ QStringList QgsGrassModuleStandardOptions::checkOutput()
594594
return list;
595595
}
596596

597+
void QgsGrassModuleStandardOptions::freezeOutput()
598+
{
599+
#ifdef QGISDEBUG
600+
std::cerr << "QgsGrassModuleStandardOptions::freezeOutput()" << std::endl;
601+
#endif
602+
603+
#ifdef WIN32
604+
for ( int i = 0; i < mItems.size(); i++ )
605+
{
606+
if ( typeid(*(mItems[i])) != typeid (QgsGrassModuleOption) ) {
607+
continue;
608+
}
609+
QgsGrassModuleOption *opt =
610+
dynamic_cast<QgsGrassModuleOption *> ( mItems[i] );
611+
612+
std::cerr << "opt->key() = " << opt->key().ascii() << std::endl;
613+
614+
if ( opt->isOutput()
615+
&& opt->outputType() == QgsGrassModuleOption::Vector )
616+
{
617+
std::cerr << "freeze vector layers" << std::endl;
618+
619+
QChar sep = '/';
620+
621+
int nlayers = mCanvas->layerCount();
622+
for ( int i = 0; i < nlayers; i++ )
623+
{
624+
QgsMapLayer *layer = mCanvas->getZpos(i);
625+
626+
if ( layer->type() != QgsMapLayer::VECTOR ) continue;
627+
628+
QgsVectorLayer *vector = (QgsVectorLayer*)layer;
629+
if ( vector->providerType() != "grass" ) continue;
630+
631+
//TODO dynamic_cast ?
632+
QgsGrassProvider *provider = (QgsGrassProvider *) vector->getDataProvider();
633+
634+
// TODO add map() mapset() location() gisbase() to grass provider
635+
QString source = QDir::cleanPath ( provider->getDataSourceUri() );
636+
#ifdef QGISDEBUG
637+
std::cerr << "source = " << source.ascii() << std::endl;
638+
#endif
639+
640+
// Check GISBASE and LOCATION
641+
QStringList split = QStringList::split ( sep, source );
642+
643+
if ( split.size() < 4 ) continue;
644+
split.pop_back(); // layer
645+
646+
QString map = split.last();
647+
split.pop_back(); // map
648+
649+
QString mapset = split.last();
650+
split.pop_back(); // mapset
651+
652+
QString loc = source.remove ( QRegExp("/[^/]+/[^/]+/[^/]+$") );
653+
loc = QDir(loc).canonicalPath();
654+
655+
QDir curlocDir ( QgsGrass::getDefaultGisdbase() + sep + QgsGrass::getDefaultLocation() );
656+
QString curloc = curlocDir.canonicalPath();
657+
658+
if ( loc != curloc ) continue;
659+
660+
if ( mapset != QgsGrass::getDefaultMapset() ) continue;
661+
662+
if ( provider->isFrozen() ) continue;
663+
664+
provider->freeze();
665+
}
666+
}
667+
}
668+
#endif
669+
}
670+
671+
void QgsGrassModuleStandardOptions::thawOutput()
672+
{
673+
#ifdef QGISDEBUG
674+
std::cerr << "QgsGrassModuleStandardOptions::thawOutput()" << std::endl;
675+
#endif
676+
677+
#ifdef WIN32
678+
for ( int i = 0; i < mItems.size(); i++ )
679+
{
680+
if ( typeid(*(mItems[i])) != typeid (QgsGrassModuleOption) ) {
681+
continue;
682+
}
683+
QgsGrassModuleOption *opt =
684+
dynamic_cast<QgsGrassModuleOption *> ( mItems[i] );
685+
686+
std::cerr << "opt->key() = " << opt->key().ascii() << std::endl;
687+
688+
if ( opt->isOutput()
689+
&& opt->outputType() == QgsGrassModuleOption::Vector )
690+
{
691+
std::cerr << "thaw vector layers" << std::endl;
692+
693+
QChar sep = '/';
694+
695+
int nlayers = mCanvas->layerCount();
696+
for ( int i = 0; i < nlayers; i++ )
697+
{
698+
QgsMapLayer *layer = mCanvas->getZpos(i);
699+
700+
if ( layer->type() != QgsMapLayer::VECTOR ) continue;
701+
702+
QgsVectorLayer *vector = (QgsVectorLayer*)layer;
703+
if ( vector->providerType() != "grass" ) continue;
704+
705+
//TODO dynamic_cast ?
706+
QgsGrassProvider *provider = (QgsGrassProvider *) vector->getDataProvider();
707+
708+
// TODO add map() mapset() location() gisbase() to grass provider
709+
QString source = QDir::cleanPath ( provider->getDataSourceUri() );
710+
#ifdef QGISDEBUG
711+
std::cerr << "source = " << source.ascii() << std::endl;
712+
#endif
713+
714+
// Check GISBASE and LOCATION
715+
QStringList split = QStringList::split ( sep, source );
716+
717+
if ( split.size() < 4 ) continue;
718+
split.pop_back(); // layer
719+
720+
QString map = split.last();
721+
split.pop_back(); // map
722+
723+
QString mapset = split.last();
724+
split.pop_back(); // mapset
725+
726+
QString loc = source.remove ( QRegExp("/[^/]+/[^/]+/[^/]+$") );
727+
loc = QDir(loc).canonicalPath();
728+
729+
QDir curlocDir ( QgsGrass::getDefaultGisdbase() + sep + QgsGrass::getDefaultLocation() );
730+
QString curloc = curlocDir.canonicalPath();
731+
732+
if ( loc != curloc ) continue;
733+
734+
if ( mapset != QgsGrass::getDefaultMapset() ) continue;
735+
736+
if ( !provider->isFrozen() ) continue;
737+
738+
provider->thaw();
739+
}
740+
}
741+
}
742+
#endif
743+
}
744+
597745
QStringList QgsGrassModuleStandardOptions::output(int type )
598746
{
599747
#ifdef QGISDEBUG
@@ -1227,6 +1375,9 @@ void QgsGrassModule::run()
12271375
QString cmd = execArguments.takeFirst();
12281376
execArguments += arguments;
12291377

1378+
// Freeze output vector on Windows
1379+
mOptions->freezeOutput();
1380+
12301381
mProcess.setEnvironment ( environment );
12311382
mProcess.start( cmd, execArguments );
12321383

@@ -1256,6 +1407,7 @@ void QgsGrassModule::finished(int exitCode, QProcess::ExitStatus exitStatus )
12561407
mProgressBar->setProgress ( 100, 100 );
12571408
mSuccess = true;
12581409
mViewButton->setEnabled(true);
1410+
mOptions->thawOutput();
12591411
} else {
12601412
mOutputTextBrowser->append( "<B>Finished with error</B>" );
12611413
}

‎src/plugins/grass/qgsgrassmodule.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ class QgsGrassModuleOptions
196196
// return list of existing output maps
197197
virtual QStringList checkOutput() { return QStringList() ; }
198198

199+
//! Freeze output vector maps used in QGIS on Windows
200+
virtual void freezeOutput() { return; }
201+
202+
//! Thaw output vector maps used in QGIS on Windows
203+
virtual void thawOutput() { return; }
204+
199205
//! Check if otpion is ready
200206
// Returns empty string or error message
201207
virtual QStringList ready() { return QStringList() ; }
@@ -270,6 +276,8 @@ class QgsGrassModuleStandardOptions: public QgsGrassModuleOptions, QWidget
270276

271277
// Reimplemented methods from QgsGrassModuleOptions
272278
QStringList checkOutput();
279+
void freezeOutput();
280+
void thawOutput();
273281
QStringList ready() ;
274282
QStringList output(int type);
275283
QStringList checkRegion();

0 commit comments

Comments
 (0)
Please sign in to comment.