@@ -76,6 +76,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
76
76
mElevationManager( NULL ),
77
77
mObjectPlacer( NULL )
78
78
{
79
+ mIsGlobeRunning = false ;
79
80
}
80
81
81
82
// destructor
@@ -104,12 +105,19 @@ void GlobePlugin::initGui()
104
105
105
106
connect ( mQGisIface ->mapCanvas () , SIGNAL ( extentsChanged () ),
106
107
this , SLOT ( extentsChanged () ) );
107
- // connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ),
108
- // this, SLOT( layersChanged() ) );
108
+ connect ( mQGisIface ->mapCanvas (), SIGNAL ( layersChanged () ),
109
+ this , SLOT ( layersChanged () ) );
110
+ // FIXME: fix sender objact, must be mSettingsDialog
111
+ connect ( mQGisIface ->mapCanvas (), SIGNAL ( elevationDatasourcesChanged () ),
112
+ this , SLOT ( layersChanged () ) );
109
113
connect ( mQGisIface ->mainWindow (), SIGNAL ( projectRead () ), this ,
110
114
SLOT ( projectReady () ) );
111
115
connect ( mQGisIface ->mainWindow (), SIGNAL ( newProjectCreated () ), this ,
112
- SLOT ( blankProject () ) );
116
+ SLOT ( blankProjectReady () ) );
117
+ // FIXME: fix sender objact, must be mSettingsDialog
118
+ connect ( mQGisIface ->mainWindow (), SIGNAL ( globeClosed () ), this ,
119
+ SLOT ( setGlobeNotRunning () ) );
120
+
113
121
}
114
122
115
123
void GlobePlugin::run ()
@@ -158,6 +166,8 @@ void GlobePlugin::run()
158
166
#ifdef GLOBE_OSG_STANDALONE_VIEWER
159
167
viewer.run ();
160
168
#endif
169
+
170
+ mIsGlobeRunning = true ;
161
171
}
162
172
163
173
void GlobePlugin::settings ()
@@ -259,7 +269,7 @@ void GlobePlugin::projectReady()
259
269
mSettingsDialog .readElevationDatasources ();
260
270
}
261
271
262
- void GlobePlugin::blankProject ()
272
+ void GlobePlugin::blankProjectReady ()
263
273
{// TODO
264
274
QMessageBox m;
265
275
m.setText (" new" );
@@ -600,74 +610,80 @@ typedef std::list< osg::ref_ptr<VersionedTile> > TileList;
600
610
void GlobePlugin::layersChanged ()
601
611
{
602
612
QgsDebugMsg ( " layersChanged" );
613
+ if ( mIsGlobeRunning ){
614
+ osg::ref_ptr<Map> map = mMapNode ->getMap ();
603
615
604
- osg::ref_ptr<Map> map = mMapNode ->getMap ();
605
-
606
- if ( map->getImageMapLayers ().size () > 1 || map->getHeightFieldMapLayers ().size () > 1 )
607
- {
608
- viewer.getDatabasePager ()->clear ();
609
- }
610
-
611
- // Remove elevation layers
612
- MapLayerList list = map->getHeightFieldMapLayers ();
613
- for ( MapLayerList::iterator i = list.begin (); i != list.end (); i++ )
614
- {
615
- map->removeMapLayer ( *i );
616
- }
617
-
618
- // Add elevation layers
619
- QSettings settings;
620
- QString cacheDirectory = settings.value ( " cache/directory" , QgsApplication::qgisSettingsDirPath () + " cache" ).toString ();
621
- QTableWidget* table = mSettingsDialog .elevationDatasources ();
622
- for (int i = 0 ; i < table->rowCount (); ++i)
623
- {
624
- QString type = table->item (i, 0 )->text ();
625
- bool cache = table->item (i, 1 )->checkState ();
626
- QString uri = table->item (i, 2 )->text ();
627
- MapLayer* layer = 0 ;
616
+ if ( map->getImageMapLayers ().size () > 1 || map->getHeightFieldMapLayers ().size () > 1 )
617
+ {
618
+ viewer.getDatabasePager ()->clear ();
619
+ }
628
620
629
- if ( " Raster" == type)
621
+ // Remove elevation layers
622
+ MapLayerList list = map->getHeightFieldMapLayers ();
623
+ for ( MapLayerList::iterator i = list.begin (); i != list.end (); i++ )
630
624
{
631
- GDALOptions* options = new GDALOptions ();
632
- options->url () = uri.toStdString ();
633
- layer = new osgEarth::HeightFieldMapLayer ( uri.toStdString (), options );
625
+ map->removeMapLayer ( *i );
634
626
}
635
- else if ( " Worldwind" == type )
627
+
628
+ // Add elevation layers
629
+ QSettings settings;
630
+ QString cacheDirectory = settings.value ( " cache/directory" , QgsApplication::qgisSettingsDirPath () + " cache" ).toString ();
631
+ QTableWidget* table = mSettingsDialog .elevationDatasources ();
632
+ for (int i = 0 ; i < table->rowCount (); ++i)
636
633
{
637
- EarthFile* tmpEarth = new EarthFile (); // Hack for programatic WorldWind layer generation
638
- std::string xml = " <map name=\" Dummy\" type=\" geocentric\" ><heightfield name=\" WorldWind bil\" driver=\" worldwind\" ><worldwind_cache>" + cacheDirectory.toStdString () + " /globe/worldwind_srtm</worldwind_cache></heightfield></map>" ;
639
- std::stringstream strstr (xml);
640
- tmpEarth->readXML ( strstr , " " );
641
- layer = tmpEarth->getMap ()->getHeightFieldMapLayers ().front ();
634
+ QString type = table->item (i, 0 )->text ();
635
+ bool cache = table->item (i, 1 )->checkState ();
636
+ QString uri = table->item (i, 2 )->text ();
637
+ MapLayer* layer = 0 ;
638
+
639
+ if ( " Raster" == type)
640
+ {
641
+ GDALOptions* options = new GDALOptions ();
642
+ options->url () = uri.toStdString ();
643
+ layer = new osgEarth::HeightFieldMapLayer ( uri.toStdString (), options );
644
+ }
645
+ else if ( " Worldwind" == type )
646
+ {
647
+ EarthFile* tmpEarth = new EarthFile (); // Hack for programatic WorldWind layer generation
648
+ std::string xml = " <map name=\" Dummy\" type=\" geocentric\" ><heightfield name=\" WorldWind bil\" driver=\" worldwind\" ><worldwind_cache>" + cacheDirectory.toStdString () + " /globe/worldwind_srtm</worldwind_cache></heightfield></map>" ;
649
+ std::stringstream strstr (xml);
650
+ tmpEarth->readXML ( strstr , " " );
651
+ layer = tmpEarth->getMap ()->getHeightFieldMapLayers ().front ();
652
+ }
653
+ else if ( " TMS" == type )
654
+ {
655
+ TMSOptions* options = new TMSOptions ();
656
+ options->url () = uri.toStdString ();
657
+ layer = new osgEarth::HeightFieldMapLayer ( uri.toStdString (), options );
658
+ // osgEarth 2.0 API:
659
+ // TMSOptions tms( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
660
+ // map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
661
+ }
662
+ map->addMapLayer ( layer );
663
+
664
+ if ( !cache || type == " Worldwind" ) layer->setCache ( 0 ); // no tms cache for worldwind (use worldwind_cache)
642
665
}
643
- else if ( " TMS" == type )
666
+
667
+ // remove QGIS layer
668
+ if ( mQgisMapLayer )
644
669
{
645
- TMSOptions* options = new TMSOptions ();
646
- options->url () = uri.toStdString ();
647
- layer = new osgEarth::HeightFieldMapLayer ( uri.toStdString (), options );
648
- // osgEarth 2.0 API:
649
- // TMSOptions tms( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
650
- // map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
670
+ QgsDebugMsg ( " removeMapLayer" );
671
+ map->removeMapLayer ( mQgisMapLayer );
651
672
}
652
- map->addMapLayer ( layer );
653
673
654
- if ( !cache || type == " Worldwind" ) layer->setCache ( 0 ); // no tms cache for worldwind (use worldwind_cache)
674
+ // add QGIS layer
675
+ QgsDebugMsg ( " addMapLayer" );
676
+ mTileSource = new QgsOsgEarthTileSource ( mQGisIface );
677
+ mTileSource ->initialize ( " " , 0 );
678
+ mQgisMapLayer = new ImageMapLayer ( " QGIS" , mTileSource );
679
+ map->addMapLayer ( mQgisMapLayer );
680
+ mQgisMapLayer ->setCache ( 0 ); // disable caching
655
681
}
656
-
657
- // remove QGIS layer
658
- if ( mQgisMapLayer )
682
+ else
659
683
{
660
- QgsDebugMsg ( " removeMapLayer " );
661
- map-> removeMapLayer ( mQgisMapLayer ) ;
684
+ QgsDebugMsg ( " EXITING layersChanged, globe not running " );
685
+ return ;
662
686
}
663
-
664
- // add QGIS layer
665
- QgsDebugMsg ( " addMapLayer" );
666
- mTileSource = new QgsOsgEarthTileSource ( mQGisIface );
667
- mTileSource ->initialize ( " " , 0 );
668
- mQgisMapLayer = new ImageMapLayer ( " QGIS" , mTileSource );
669
- map->addMapLayer ( mQgisMapLayer );
670
- mQgisMapLayer ->setCache ( 0 ); // disable caching
671
687
}
672
688
673
689
void GlobePlugin::unload ()
@@ -725,6 +741,11 @@ void GlobePlugin::copyFolder( QString sourceFolder, QString destFolder )
725
741
}
726
742
}
727
743
744
+ void GlobePlugin::setGlobeNotRunning ()
745
+ {
746
+ mIsGlobeRunning = false ;
747
+ }
748
+
728
749
bool NavigationControl::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx )
729
750
{
730
751
switch ( ea.getEventType () )
0 commit comments