@@ -512,6 +512,139 @@ QStringList QgsGrassMapcalc::checkOutput()
512
512
return QStringList ();
513
513
}
514
514
515
+ QStringList QgsGrassMapcalc::checkRegion ()
516
+ {
517
+ #ifdef QGISDEBUG
518
+ std::cerr << " QgsGrassMapcalc::checkRegion()" << std::endl;
519
+ #endif
520
+ QStringList list;
521
+
522
+ Q3CanvasItemList l = mCanvas ->allItems ();
523
+
524
+ struct Cell_head currentWindow;
525
+ if ( !QgsGrass::region ( QgsGrass::getDefaultGisdbase (),
526
+ QgsGrass::getDefaultLocation (),
527
+ QgsGrass::getDefaultMapset (), ¤tWindow ) )
528
+ {
529
+ QMessageBox::warning ( 0 , " Warning" , " Cannot get current region" );
530
+ return list;
531
+ }
532
+
533
+ for ( Q3CanvasItemList::Iterator it=l.fromLast (); it!=l.end (); --it)
534
+ {
535
+ if (! (*it)->isActive () ) continue ;
536
+
537
+ if ( typeid (**it) != typeid (QgsGrassMapcalcObject) ) continue ;
538
+
539
+ QgsGrassMapcalcObject *obj =
540
+ dynamic_cast <QgsGrassMapcalcObject *> (*it);
541
+
542
+ if ( obj->type () != QgsGrassMapcalcObject::Map ) continue ;
543
+
544
+ struct Cell_head window;
545
+
546
+ QStringList mm = obj->value ().split (" @" );
547
+ if ( mm.size () < 1 ) continue ;
548
+
549
+ QString map = mm.at (0 );
550
+ QString mapset = QgsGrass::getDefaultMapset ();
551
+ if ( mm.size () > 1 ) mapset = mm.at (1 );
552
+
553
+ if ( !QgsGrass::mapRegion ( QgsGrass::Raster,
554
+ QgsGrass::getDefaultGisdbase (),
555
+ QgsGrass::getDefaultLocation (), mapset, map,
556
+ &window ) )
557
+ {
558
+ QMessageBox::warning ( 0 , " Warning" , " Cannot check region "
559
+ " of map " + obj->value () );
560
+ continue ;
561
+ }
562
+
563
+ if ( G_window_overlap ( ¤tWindow ,
564
+ window.north , window.south , window.east , window.west ) == 0 )
565
+ {
566
+ list.append ( obj->value () );
567
+ }
568
+ }
569
+ return list;
570
+ }
571
+
572
+ bool QgsGrassMapcalc::inputRegion ( struct Cell_head *window, bool all )
573
+ {
574
+ #ifdef QGISDEBUG
575
+ std::cerr << " gsGrassMapcalc::inputRegion" << std::endl;
576
+ #endif
577
+
578
+ if ( !QgsGrass::region ( QgsGrass::getDefaultGisdbase (),
579
+ QgsGrass::getDefaultLocation (),
580
+ QgsGrass::getDefaultMapset (), window ) )
581
+ {
582
+ QMessageBox::warning ( 0 , " Warning" , " Cannot get current region" );
583
+ return false ;
584
+ }
585
+
586
+ Q3CanvasItemList l = mCanvas ->allItems ();
587
+
588
+ int count = 0 ;
589
+ for ( Q3CanvasItemList::Iterator it=l.fromLast (); it!=l.end (); --it)
590
+ {
591
+ if (! (*it)->isActive () ) continue ;
592
+
593
+ if ( typeid (**it) != typeid (QgsGrassMapcalcObject) ) continue ;
594
+
595
+ QgsGrassMapcalcObject *obj =
596
+ dynamic_cast <QgsGrassMapcalcObject *> (*it);
597
+
598
+ if ( obj->type () != QgsGrassMapcalcObject::Map ) continue ;
599
+
600
+ struct Cell_head mapWindow;
601
+
602
+ QStringList mm = obj->value ().split (" @" );
603
+ if ( mm.size () < 1 ) continue ;
604
+
605
+ QString map = mm.at (0 );
606
+ QString mapset = QgsGrass::getDefaultMapset ();
607
+ if ( mm.size () > 1 ) mapset = mm.at (1 );
608
+
609
+ if ( !QgsGrass::mapRegion ( QgsGrass::Raster,
610
+ QgsGrass::getDefaultGisdbase (),
611
+ QgsGrass::getDefaultLocation (), mapset, map,
612
+ &mapWindow ) )
613
+ {
614
+ QMessageBox::warning ( 0 , " Warning" , " Cannot get region "
615
+ " of map " + obj->value () );
616
+ return false ;
617
+ }
618
+
619
+ // TODO: best way to set resolution ?
620
+ if ( count == 0 )
621
+ {
622
+ QgsGrass::copyRegionExtent ( &mapWindow, window );
623
+ QgsGrass::copyRegionResolution ( &mapWindow, window );
624
+ }
625
+ else
626
+ {
627
+ QgsGrass::extendRegion ( &mapWindow, window );
628
+ }
629
+ count++;
630
+ }
631
+
632
+ return true ;
633
+ }
634
+
635
+ QStringList QgsGrassMapcalc::output ( int type )
636
+ {
637
+ #ifdef QGISDEBUG
638
+ std::cerr << " gsGrassMapcalc::output" << std::endl;
639
+ #endif
640
+ QStringList list;
641
+ if ( type == QgsGrassModuleOption::Raster )
642
+ {
643
+ list.append ( mOutputLineEdit ->text () );
644
+ }
645
+ return list;
646
+ }
647
+
515
648
QgsGrassMapcalc::~QgsGrassMapcalc ()
516
649
{
517
650
}
0 commit comments