[Kstars-devel] [kstars] kstars/tools: Display more realistics twilights in Alt vs time tool.
Jérome SONRIER
jsid at emor3j.fr.eu.org
Tue Apr 26 03:29:17 CEST 2011
Git commit 8bd09a9d1a25baa1c18524423f26d1d1b01f9a2f by Jérome SONRIER.
Committed on 26/04/2011 at 03:27.
Pushed by jsonrier into branch 'master'.
Display more realistics twilights in Alt vs time tool.
This should also fix bug 179389.
CCMAIL: kstars-devel at kde.org
CCBUG: 243364
CCBUG: 179389
M +61 -0 kstars/tools/altvstime.cpp
M +3 -0 kstars/tools/altvstime.h
M +63 -22 kstars/tools/avtplotwidget.cpp
M +5 -1 kstars/tools/avtplotwidget.h
http://commits.kde.org/kstars/8bd09a9d1a25baa1c18524423f26d1d1b01f9a2f
diff --git a/kstars/tools/altvstime.cpp b/kstars/tools/altvstime.cpp
index 570ddcc..6f0d014 100644
--- a/kstars/tools/altvstime.cpp
+++ b/kstars/tools/altvstime.cpp
@@ -32,10 +32,12 @@
#include "kstarsdatetime.h"
#include "ksnumbers.h"
#include "simclock.h"
+#include "kssun.h"
#include "dialogs/finddialog.h"
#include "dialogs/locationdialog.h"
#include "skyobjects/skypoint.h"
#include "skyobjects/skyobject.h"
+#include "skycomponents/skymapcomposite.h"
#include "avtplotwidget.h"
#include "ui_altvstime.h"
@@ -92,6 +94,7 @@ AltVsTime::AltVsTime( QWidget* parent) :
computeSunRiseSetTimes();
setLSTLimits();
+ setDawnDusk();
connect( avtUI->browseButton, SIGNAL( clicked() ), this, SLOT( slotBrowseObject() ) );
connect( avtUI->cityButton, SIGNAL( clicked() ), this, SLOT( slotChooseCity() ) );
@@ -355,6 +358,8 @@ void AltVsTime::slotUpdateDateLoc() {
//First determine time of sunset and sunrise
computeSunRiseSetTimes();
+ // Determine dawn/dusk time and min/max sun elevation
+ setDawnDusk();
for ( int i = 0; i < avtUI->PlotList->count(); ++i ) {
QString oName = avtUI->PlotList->item( i )->text().toLower();
@@ -461,4 +466,60 @@ double AltVsTime::getEpoch(const QString &eName)
return epoch;
}
+void AltVsTime::setDawnDusk()
+{
+ KStarsData* data = KStarsData::Instance();
+ KStarsDateTime today = getDate();
+ KSNumbers *oldNum = new KSNumbers( data->ut().djd() );
+ KSNumbers *num = new KSNumbers( today.djd() );
+ dms LST = geo->GSTtoLST( today.gst() );
+
+ SkyObject* o = KStarsData::Instance()->skyComposite()->findByName( "Sun" );
+ o->updateCoords( num, true, geo->lat(), &LST );
+ double alt, dawn, da, dusk, du, max_alt, min_alt;
+ double last_h = -12.0;
+ double last_alt = findAltitude( o, last_h );
+ dawn = dusk = -13.0;
+ max_alt = -100.0;
+ min_alt = 100.0;
+ bool asc;
+ for ( double h=-11.95; h<=12.0; h+=0.05 ) {
+ alt = findAltitude( o, h );
+
+ if ( alt - last_alt > 0 )
+ asc = true;
+ else
+ asc = false;
+
+ if ( alt > max_alt )
+ max_alt = alt;
+
+ if ( alt < min_alt )
+ min_alt = alt;
+
+ if ( asc && last_alt <= -18.0 && alt >= -18.0 )
+ dawn = h;
+
+ if ( ! asc && last_alt >= -18.0 && alt <= -18.0 )
+ dusk = h;
+
+ last_h = h;
+ last_alt = alt;
+ }
+
+ o->updateCoords( oldNum, true, data->geo()->lat(), data->lst() );
+ delete oldNum;
+
+ if ( dawn < -12.0 || dusk < -12.0 ) {
+ da = -1.0;
+ du = -1.0;
+ } else {
+ da = dawn / 24.0;
+ du = ( dusk + 24.0 ) / 24.0;
+ }
+
+ avtUI->View->setDawnDuskTimes( da, du );
+ avtUI->View->setMinMaxSunAlt( min_alt, max_alt );
+}
+
#include "altvstime.moc"
diff --git a/kstars/tools/altvstime.h b/kstars/tools/altvstime.h
index 067d4f8..c13ebf2 100644
--- a/kstars/tools/altvstime.h
+++ b/kstars/tools/altvstime.h
@@ -139,6 +139,9 @@ public slots:
void slotHighlight(int);
private:
+ /**@short find start of dawn, end of dusk, maximum and minimum elevation of the sun */
+ void setDawnDusk();
+
AltVsTimeUI *avtUI;
GeoLocation *geo;
diff --git a/kstars/tools/avtplotwidget.cpp b/kstars/tools/avtplotwidget.cpp
index eb3cbfc..61b00f7 100644
--- a/kstars/tools/avtplotwidget.cpp
+++ b/kstars/tools/avtplotwidget.cpp
@@ -88,30 +88,58 @@ void AVTPlotWidget::paintEvent( QPaintEvent *e ) {
QColor SkyColor( 0, 100, 200 );
//draw daytime sky if the Sun rises for the current date/location
- //(when Sun does not rise, SunSet = -1.0)
- if ( SunSet != -1.0 ) {
- //If Sun does not set, then just fill the daytime sky color
- if ( SunSet == 1.0 ) {
- p.fillRect( 0, 0, pW, int(0.5*pH), SkyColor );
+ if ( SunMaxAlt > -18.0 ) {
+ //Display centered on midnight, so need to modulate dawn/dusk by 0.5
+ int rise = int( pW * ( 0.5 + SunRise ) );
+ int set = int( pW * ( SunSet - 0.5 ) );
+ int da = int( pW * ( 0.5 + Dawn ) );
+ int du = int( pW * ( Dusk - 0.5 ) );
+
+ if ( SunMinAlt > 0.0 ) {
+ // The sun never set and the sky is always blue
+ p.fillRect( rect(), SkyColor );
+ } else if ( SunMaxAlt < 0.0 && SunMinAlt < -18.0 ) {
+ // The sun never rise but the sky is not completely dark
+ QLinearGradient grad = QLinearGradient( QPointF( 0.0, 0.0 ), QPointF( du, 0.0 ) );
+ grad.setColorAt( 0, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) );
+ grad.setColorAt( 1, Qt::black );
+ p.fillRect( QRectF( 0.0, 0.0, du+20.0, pH ), grad );
+
+ grad.setStart( QPointF( pW, 0.0 ) );
+ grad.setFinalStop( QPointF( da-20.0, 0.0 ) );
+ p.fillRect( QRectF( da-20.0, 0.0, pW, pH ), grad );
+ } else if ( SunMaxAlt < 0.0 && SunMinAlt > -18.0 ) {
+ // The sun never rise but the sky is NEVER completely dark
+ QLinearGradient grad = QLinearGradient( QPointF( 0.0, 0.0 ), QPointF( pW, 0.0 ) );
+ grad.setColorAt( 0, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) );
+ grad.setColorAt( 0.5, SkyColor.darker( SunMinAlt / -18.0 * 1000 ) );
+ grad.setColorAt( 1, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) );
+ p.fillRect( QRectF( 0.0, 0.0, pW, pH ), grad );
+ } else if ( Dawn < 0.0 ) {
+ // The sun sets and rises but the sky is never completely dark
+ p.fillRect( 0, 0, set, int( 0.5 * pH ), SkyColor );
+ p.fillRect( rise, 0, pW, int( 0.5 * pH ), SkyColor );
+
+ QLinearGradient grad = QLinearGradient( QPointF( set-20.0, 0.0 ), QPointF( rise, 0.0 ) );
+ grad.setColorAt( 0, SkyColor );
+ grad.setColorAt( 0.5, SkyColor.darker( SunMinAlt / -18.0 * 1000 ) );
+ grad.setColorAt( 1, SkyColor );
+ p.fillRect( QRectF( set-20.0, 0.0, rise-set+20.0, pH ), grad );
} else {
- //Display centered on midnight, so need to modulate dawn/dusk by 0.5
- int dawn = int(pW*(0.5 + SunRise));
- int dusk = int(pW*(SunSet - 0.5));
- p.fillRect( 0, 0, dusk, int(0.5*pH), SkyColor );
- p.fillRect( dawn, 0, pW - dawn, int(0.5*pH), SkyColor );
-
- //draw twilight gradients
- QLinearGradient grad = QLinearGradient( QPointF(dusk-20.0, 0.0), QPointF(dusk+20.0, 0.0) );
- grad.setColorAt(0, SkyColor );
- grad.setColorAt(1, Qt::black );
- p.fillRect( QRectF( dusk-20.0, 0.0, 40.0, pH ), grad );
-
- grad.setStart( QPointF(dawn+20.0, 0.0) );
- grad.setFinalStop( QPointF(dawn-20.0, 0.0) );
- p.fillRect( QRectF( dawn-20.0, 0.0, 40.0, pH ), grad );
- }
+ p.fillRect( 0, 0, set, pH, SkyColor );
+ p.fillRect( rise, 0, pW, pH, SkyColor );
+
+ QLinearGradient grad = QLinearGradient( QPointF( set-20.0, 0.0 ), QPointF( du, 0.0 ) );
+ grad.setColorAt( 0, SkyColor );
+ grad.setColorAt( 1, Qt::black );
+ p.fillRect( QRectF( set-20.0, 0.0, du-set+20.0, pH ), grad );
+
+ grad.setStart( QPointF( rise+20.0, 0.0 ) );
+ grad.setFinalStop( QPointF( da, 0.0 ) );
+ p.fillRect( QRectF( da, 0.0, rise-da+20.0, pH ), grad );
+ }
}
-
+
//draw ground
p.fillRect( 0, int(0.5*pH), pW, int(0.5*pH), QColor( "#002200" ) );
@@ -163,4 +191,17 @@ void AVTPlotWidget::paintEvent( QPaintEvent *e ) {
p.end();
}
+void AVTPlotWidget::setDawnDuskTimes( double da, double du )
+{
+ Dawn = da;
+ Dusk = du;
+}
+
+void AVTPlotWidget::setMinMaxSunAlt( double min, double max )
+{
+ SunMinAlt = min;
+ SunMaxAlt = max;
+}
+
+
#include "avtplotwidget.moc"
diff --git a/kstars/tools/avtplotwidget.h b/kstars/tools/avtplotwidget.h
index eb1fd94..d728b26 100644
--- a/kstars/tools/avtplotwidget.h
+++ b/kstars/tools/avtplotwidget.h
@@ -54,6 +54,10 @@ public:
*/
void setSunRiseSetTimes( double sr, double ss ) { SunRise = sr; SunSet = ss; update(); }
+ void setDawnDuskTimes( double da, double du );
+
+ void setMinMaxSunAlt( double min, double max );
+
protected:
/**Handle mouse move events. If the mouse button is down,
*draw crosshair lines centered at the cursor position. This
@@ -76,7 +80,7 @@ protected:
void paintEvent( QPaintEvent *e );
private:
- double SunRise, SunSet;
+ double SunRise, SunSet, Dawn, Dusk, SunMinAlt, SunMaxAlt;
QPoint MousePoint;
};
More information about the Kstars-devel
mailing list