@@ -594,6 +594,154 @@ QStringList QgsGrassModuleStandardOptions::checkOutput()
594
594
return list;
595
595
}
596
596
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
+
597
745
QStringList QgsGrassModuleStandardOptions::output (int type )
598
746
{
599
747
#ifdef QGISDEBUG
@@ -1227,6 +1375,9 @@ void QgsGrassModule::run()
1227
1375
QString cmd = execArguments.takeFirst ();
1228
1376
execArguments += arguments;
1229
1377
1378
+ // Freeze output vector on Windows
1379
+ mOptions ->freezeOutput ();
1380
+
1230
1381
mProcess .setEnvironment ( environment );
1231
1382
mProcess .start ( cmd, execArguments );
1232
1383
@@ -1256,6 +1407,7 @@ void QgsGrassModule::finished(int exitCode, QProcess::ExitStatus exitStatus )
1256
1407
mProgressBar ->setProgress ( 100 , 100 );
1257
1408
mSuccess = true ;
1258
1409
mViewButton ->setEnabled (true );
1410
+ mOptions ->thawOutput ();
1259
1411
} else {
1260
1412
mOutputTextBrowser ->append ( " <B>Finished with error</B>" );
1261
1413
}
0 commit comments