[Kstars-devel] KDE/kdeedu/kstars/kstars/skycomponents

James Bowlin bowlin at mindspring.com
Sat Aug 18 18:30:51 CEST 2007


SVN commit 701542 by jbowlin:

Renamed StarComponent::setFaintMagnitude() to readData() based on the
principle of least surprise.  Removed the associated SkyMapComposite
proxy function.

Cleaned up SkyMapComposite::draw() just a little.

Put the code that rereads star data and creates the splash screen into
its own independent rereadData() routine which will allow us to try
calling it from other places in an attempt to solve the bug where
qApp->processEvents() causes the skymap to go blank.

Put a similar splash screen into StarComponent::reindexAll() but then
disabled it because the full re-indexing is only taking one second now
probably because I changed the mesh level from 5 to 4.  I had also
streamlined the re-indexing code just a little which may have helped
too.

CCMAIL:kstars-devel at kde.org


 M  +10 -6     skymapcomposite.cpp  
 M  +0 -1      skymapcomposite.h  
 M  +68 -43    starcomponent.cpp  
 M  +12 -2     starcomponent.h  


--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.cpp #701541:701542
@@ -170,7 +170,8 @@
     m_map = ks->map();
 
 	// We delay one draw cycle before re-indexing
-    m_Stars->reindex( &m_reindexNum );
+	// we MUST ensure CLines do not get re-indexed while we use DRAW_BUF
+	// so we do it here.
     m_CLines->reindex( &m_reindexNum );
 	// This queues re-indexing for the next draw cycle
     m_reindexNum = KSNumbers( ks->data()->updateNum()->julianDay() );
@@ -179,25 +180,31 @@
     // cycle so the sky moves as a single sheet.  May not be needed.
     ks->data()->syncUpdateIDs();
 
+	// prepare the aperture
     float radius = m_map->fov();
     if ( radius > 90.0 ) radius = 90.0;
 
-	if (  0 && m_skyMesh->inDraw() ) {
+	if ( m_skyMesh->inDraw() ) {
 		printf("Warning: aborting concurrent SkyMapComposite::draw()\n");
 		return;
 	}
+
 	m_skyMesh->inDraw( true );
     SkyPoint* focus = m_map->focus();
     m_skyMesh->aperture( focus, radius + 1.0, DRAW_BUF ); // divide by 2 for testing
 
+	// create the no-precess aperture only if needed
     if ( Options::showGrid() || Options::showCBounds() || 
 			Options::showEquator() && ! m_skyMesh->isZoomedIn() ) {
 
         m_skyMesh->index( focus, radius + 1.0, NO_PRECESS_BUF );
     }
 
+	// clear marks from old labels and prep fonts
     m_skyLabeler->reset( m_map, psky, scale ); 
 	m_skyLabeler->useStdFont( psky );
+
+	// info boxes have highest label priority
 	ks->infoBoxes()->reserveBoxes( psky );
 
 	//TIMING
@@ -274,6 +281,7 @@
 	m_Horizon->draw( ks, psky, scale );
 //	kDebug() << QString("Horizon     : %1 ms").arg( t.elapsed() );
 
+	// use zoomed-in font if needed and draw all the labels
 	m_skyLabeler->resetFont( psky );
     m_skyLabeler->draw( ks, psky );
 	m_skyLabeler->useStdFont( psky );
@@ -389,10 +397,6 @@
 	}
 }
 
-void SkyMapComposite::setFaintStarMagnitude( float newMag ) {
-	m_Stars->setFaintMagnitude( newMag );
-}
-
 void SkyMapComposite::setStarColorMode( int newMode ) {
 	m_Stars->setStarColorMode( newMode );
 }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.h #701541:701542
@@ -156,7 +156,6 @@
 
 		//Accessors for StarComponent
 		SkyObject* findStarByGenetiveName( const QString name );
-		void setFaintStarMagnitude( float newMag );
 		float faintStarMagnitude() const;
 		void setStarColorMode( int newMode );
 		int starColorMode() const;
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #701541:701542
@@ -51,7 +51,7 @@
 
     lastFilePos = 0;
 	m_zoomMagLimit = 0.0;
-	m_splash = 0;
+	m_reloadSplash = m_reindexSplash = 0;
 }
 
 StarComponent::~StarComponent()
@@ -62,6 +62,16 @@
     return Options::showStars();
 }
 
+void StarComponent::init(KStarsData *data)
+{
+	emitProgressText( i18n("Loading stars" ) );
+	m_ColorMode = data->colorScheme()->starColorMode(); 
+	m_ColorIntensity = data->colorScheme()->starColorIntensity();
+	m_Data = data;
+
+	readData( Options::magLimitDrawStar() );
+}
+
 void StarComponent::update( KStarsData *data, KSNumbers *num )
 {}
 
@@ -72,12 +82,14 @@
 {
     if ( ! num ) return;
 
+	// for large time steps we re-index all points
     if ( fabs( num->julianCenturies() - 
          m_reindexNum.julianCenturies() ) > m_reindexInterval ) {
         reindexAll( num );
         return;
     }
 
+	// otherwise we just re-index fast movers as needed
     for ( int j = 0; j < m_highPMStars.size(); j++ ) {
         m_highPMStars.at( j )->reindex( num, m_starIndex );
     }
@@ -85,48 +97,78 @@
 
 void StarComponent::reindexAll( KSNumbers *num )
 {
+	/***
+	if ( ! m_reindexSplash ) {
+		m_reindexSplash = new KStarsSplash(0, 
+				i18n("Please wait while re-indexing stars ...") );
+		QObject::connect( KStarsData::Instance(), 
+				SIGNAL( progressText( QString ) ),
+				m_reindexSplash, SLOT( setMessage( QString ) ) );
 
-    //printf("Re-indexing Stars to year %4.1f...\n", 2000.0 + num->julianCenturies() * 100.0);
+		m_reindexSplash->show();
+		m_reindexSplash->raise();
+		return;
+	}
+	***/
 
+    printf("Re-indexing Stars to year %4.1f...\n",
+			2000.0 + num->julianCenturies() * 100.0);
+
     m_reindexNum = KSNumbers( *num );
     m_skyMesh->setKSNumbers( num );
 
-    // delete the old index 
+    // clear out the old index 
     for ( int i = 0; i < m_starIndex->size(); i++ ) {
-        delete m_starIndex->at( i );
+        m_starIndex->at( i )->clear();
     }
-    delete m_starIndex;
 
-    // Create a new index
-    m_starIndex = new StarIndex();
-    for (int i = 0; i < m_skyMesh->size(); i++) {
-        m_starIndex->append( new StarList() );
-    }
-
-    // Fill it with stars from old index
-    for ( int i = 0; i < objectList().size(); i++ ) {
+	// re-populate it from the objectList
+	int size = objectList().size();
+    for ( int i = 0; i < size; i++ ) {
         StarObject* star = (StarObject*) objectList()[ i ];
         Trixel trixel = m_skyMesh->indexStar( star );
         m_starIndex->at( trixel )->append( star );
     }
 
-    // Let everyone know we have re-indexed to num
+    // Let everyone else know we have re-indexed to num
     for ( int j = 0; j < m_highPMStars.size(); j++ ) {
         m_highPMStars.at( j )->setIndexTime( num );
     }
 
-    //printf("Done.\n");
+	//delete m_reindexSplash;
+	//m_reindexSplash = 0;
+
+    printf("Done.\n");
 }
 
-
-void StarComponent::init(KStarsData *data)
+void StarComponent::rereadData() 
 {
-	emitProgressText( i18n("Loading stars" ) );
-	m_ColorMode = data->colorScheme()->starColorMode(); 
-	m_ColorIntensity = data->colorScheme()->starColorIntensity();
-	m_Data = data;
+	float magLimit =  Options::magLimitDrawStar();
+	SkyMap* map = SkyMap::Instance();
+	if ( ( map->isSlewing() && Options::hideOnSlew() && Options::hideStars()) ||
+		 m_FaintMagnitude >= magLimit ) 
+		return;
 
-	setFaintMagnitude( Options::magLimitDrawStar() );
+	// First show a splash screen but don't load any data so we can present
+	// a pretty face.  Then load data the next time through and finally erase
+	// the splash screen.
+
+	if ( ! m_reloadSplash ) {
+		m_reloadSplash = new KStarsSplash(0, 
+				i18n("Please wait while loading faint stars ...") );
+		QObject::connect( KStarsData::Instance(), 
+				SIGNAL( progressText( QString ) ),
+				m_reloadSplash, SLOT( setMessage( QString ) ) );
+
+		m_reloadSplash->show();
+		m_reloadSplash->raise();
+		return;
+	}
+	printf("reading data ...\n");
+   	readData( magLimit );
+	printf("Done!\n");
+	delete m_reloadSplash;
+	m_reloadSplash = 0;
 }
 
 void StarComponent::draw(KStars *ks, QPainter& psky, double scale)
@@ -145,27 +187,10 @@
 	bool hideFaintStars( checkSlewing && Options::hideStars() );
 	float maglim = Options::magLimitDrawStar();
 
-	// First show a splash screen but don't load any data so we can present
-	// a pretty face.  Then load data the next time through and finally erase
-	// the splash screen.
-    if ( ! hideFaintStars && ( m_FaintMagnitude < maglim ) ) {
-		if ( ! m_splash ) {
-			m_splash = new KStarsSplash(0, i18n("Please wait while loading faint stars ...") );
-			QObject::connect( KStarsData::Instance(), SIGNAL( progressText(QString) ),
-					m_splash, SLOT( setMessage(QString) ));
+	rereadData();
 
-			m_splash->show();
-			m_splash->raise();
-		}
-		else {
-			printf("reading data ...\n");
-        	setFaintMagnitude( maglim );
-			printf("Done!\n");
-			delete m_splash;
-			m_splash = 0;
-		}
-    }
-
+    reindex( ks->data()->updateNum() );
+	
 	//adjust maglimit for ZoomLevel
 	double lgmin = log10(MINZOOM);
 	double lgmax = log10(MAXZOOM);
@@ -244,7 +269,7 @@
 }
 
  
-void StarComponent::setFaintMagnitude( float newMagnitude ) {
+void StarComponent::readData( float newMagnitude ) {
 	// only load star data if the new magnitude is fainter than we've seen so far
 	if ( newMagnitude <= m_FaintMagnitude ) return;
     m_FaintMagnitude = newMagnitude;  // store new highest magnitude level
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.h #701541:701542
@@ -96,12 +96,21 @@
 
 	    float faintMagnitude() const { return m_FaintMagnitude; }
 
-	    void setFaintMagnitude( float newMagnitude );
+	    void readData( float newMagnitude );
 
         SkyObject* objectNearest(SkyPoint *p, double &maxrad );
 
         SkyObject* findStarByGenetiveName( const QString name );
 
+		/* @short usually does nothing.  If we are drawing faint stars and if
+		 * Options:::magLimitDrawStar() is greater than m_faaintMagnitude then
+		 * the first time we are called we just pop up a splash screen. Then
+		 * the second time we are called we actually re-read the data file and
+		 * finally erase the pop up.
+		 */
+		void rereadData();
+
+
 	private:
         SkyMesh*       m_skyMesh;
         StarIndex*     m_starIndex;
@@ -155,7 +164,8 @@
 		float m_zoomMagLimit;
 		int m_ColorMode, m_ColorIntensity;
 
-		KStarsSplash* m_splash;
+		KStarsSplash* m_reloadSplash;
+		KStarsSplash* m_reindexSplash;
 };
 
 #endif


More information about the Kstars-devel mailing list