[Kstars-devel] KDE/kdeedu/kstars/kstars/tools
Akarsh Simha
akarshsimha at gmail.com
Sat Jul 12 16:37:02 CEST 2008
SVN commit 831366 by asimha:
The Conjunction Tool can now handle Stars and Deep Sky Objects in
addition to Planets for one of the two Objects. Comets and Asteroids
are still not handled.
CCMAIL: kstars-devel at kde.org
M +56 -6 conjunctions.cpp
M +8 -0 conjunctions.h
M +18 -21 conjunctions.ui
M +29 -5 ksconjunct.cpp
M +5 -4 ksconjunct.h
--- trunk/KDE/kdeedu/kstars/kstars/tools/conjunctions.cpp #831365:831366
@@ -41,9 +41,12 @@
#include "ksmoon.h"
#include "kspluto.h"
#include "widgets/dmsbox.h"
+#include "finddialog.h"
+#include "kscomet.h"
+#include "ksasteroid.h"
ConjunctionsTool::ConjunctionsTool(QWidget *parentSplit)
- : QFrame(parentSplit) {
+ : QFrame(parentSplit), Object1( 0 ), Object2( 0 ) {
setupUi(this);
@@ -66,7 +69,6 @@
geoPlace = kd -> geo();
LocationButton -> setText( geoPlace -> fullName() );
- QHash<int, QString> pNames;
pNames[KSPlanetBase::MERCURY] = i18n("Mercury");
pNames[KSPlanetBase::VENUS] = i18n("Venus");
pNames[KSPlanetBase::MARS] = i18n("Mars");
@@ -79,19 +81,64 @@
pNames[KSPlanetBase::MOON] = i18n("Moon");
for ( int i=0; i<KSPlanetBase::UNKNOWN_PLANET; ++i ) {
- Obj1ComboBox->insertItem( i, pNames[i] );
+ // Obj1ComboBox->insertItem( i, pNames[i] );
Obj2ComboBox->insertItem( i, pNames[i] );
}
// signals and slots connections
connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation()));
+ connect(Obj1FindButton, SIGNAL(clicked()), this, SLOT(slotFindObject()));
connect(ComputeButton, SIGNAL(clicked()), this, SLOT(slotCompute()));
show();
}
ConjunctionsTool::~ConjunctionsTool(){
+ if( Object1 )
+ delete Object1;
+ if( Object2 )
+ delete Object2;
}
+void ConjunctionsTool::slotFindObject() {
+ FindDialog fd( (KStars*) topLevelWidget()->parent() );
+ if ( fd.exec() == QDialog::Accepted ) {
+ if( Object1 )
+ delete Object1;
+ if( !fd.selectedObject() )
+ return;
+ if( !fd.selectedObject()->isSolarSystem() ) {
+ Object1 = new SkyObject( *fd.selectedObject() );
+ }
+ else {
+ switch( fd.selectedObject()->type() ) {
+ case 2: {
+ Object1 = KSPlanetBase::createPlanet( pNames.key( fd.selectedObject()->name() ) ); // TODO: Fix i18n issues.
+ break;
+ }
+ /*
+ case 9: {
+ Object1 = (KSComet *) new KSComet();
+ *Object1 = *fd.selectedObject();
+ break;
+ }
+ case 10: {
+ Object1 = (KSAsteroid *) new KSAsteroid();
+ *Object1 = *fd.selectedObject();
+ break;
+ }
+ */
+ case 9:
+ case 10: {
+ KMessageBox::error( NULL, i18n( "This feature is not yet implemented for Comets and Asteroids" ) );
+ break;
+ }
+ }
+ }
+ if( Object1 )
+ Obj1FindButton->setText( Object1->name() );
+ }
+}
+
void ConjunctionsTool::slotLocation()
{
LocationDialog ld( (KStars*) topLevelWidget()->parent() );
@@ -112,9 +159,12 @@
dms maxSeparation(1.0); // TODO: Make maxSeparation user-specifiable
// TODO: Get geoPlace from user.
// dms LST( geoPlace->GSTtoLST( dt.gst() ) );
- KSPlanetBase *Object1, *Object2;
- Object1 = KSPlanetBase::createPlanet( Obj1ComboBox->currentIndex() );
+ if( !Object1 ) {
+ // TODO: Display some error message
+ KMessageBox::sorry( 0, i18n("Please select an object to check conjunctions with, by clicking on the \'Find Object\' button.") );
+ return;
+ }
Object2 = KSPlanetBase::createPlanet( Obj2ComboBox->currentIndex() );
QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
@@ -126,8 +176,8 @@
ComputeStack->setCurrentIndex( 0 );
QApplication::restoreOverrideCursor();
- delete Object1;
delete Object2;
+ Object2 = NULL;
}
--- trunk/KDE/kdeedu/kstars/kstars/tools/conjunctions.h #831365:831366
@@ -28,6 +28,8 @@
#include <QTextStream>
#include "ui_conjunctions.h"
+#include "skyobject.h"
+#include "ksplanetbase.h"
class GeoLocation;
class KSPlanetBase;
@@ -50,8 +52,14 @@
void slotLocation();
void slotCompute();
void showProgress(int);
+ void slotFindObject();
private:
+ SkyObject *Object1;
+ KSPlanetBase *Object2; // Second object is always a planet.
+
+ QHash<int, QString> pNames; // To store the names of Planets vs. values expected by KSPlanetBase::createPlanet()
+
void showConjunctions(QMap<long double, dms> conjunctionlist);
GeoLocation *geoPlace;
--- trunk/KDE/kdeedu/kstars/kstars/tools/conjunctions.ui #831365:831366
@@ -32,28 +32,12 @@
<item row="2" column="1" >
<widget class="QDateTimeEdit" name="stopDate" />
</item>
- <item row="3" column="0" >
- <widget class="QLabel" name="textLabel1" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text" >
- <string>Between solar system bodies:</string>
- </property>
- </widget>
- </item>
<item row="3" column="1" >
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
- <widget class="QComboBox" name="Obj1ComboBox" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <widget class="QPushButton" name="Obj1FindButton" >
+ <property name="text" >
+ <string>Find Object...</string>
</property>
</widget>
</item>
@@ -93,6 +77,19 @@
</property>
</widget>
</item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="textLabel1" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Between solar system bodies:</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item>
@@ -111,8 +108,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>456</width>
- <height>40</height>
+ <width>446</width>
+ <height>46</height>
</rect>
</property>
<property name="sizePolicy" >
--- trunk/KDE/kdeedu/kstars/kstars/tools/ksconjunct.cpp #831365:831366
@@ -21,6 +21,9 @@
#include "ksnumbers.h"
#include "ksplanetbase.h"
+#include "ksplanet.h"
+#include "ksasteroid.h"
+#include "kscomet.h"
#include "kstarsdata.h"
KSConjunct::KSConjunct() {
@@ -29,7 +32,7 @@
}
-QMap<long double, dms> KSConjunct::findClosestApproach(KSPlanetBase& Object1, KSPlanetBase& Object2, long double startJD, long double stopJD, dms maxSeparation) {
+QMap<long double, dms> KSConjunct::findClosestApproach(SkyObject& Object1, KSPlanetBase& Object2, long double startJD, long double stopJD, dms maxSeparation) {
QMap<long double, dms> Separations;
QPair<long double, dms> extremum;
@@ -112,7 +115,7 @@
}
-dms KSConjunct::findDistance(long double jd, KSPlanetBase *Object1, KSPlanetBase *Object2) {
+dms KSConjunct::findDistance(long double jd, SkyObject *Object1, KSPlanetBase *Object2) {
KStarsDateTime t(jd);
KSNumbers num(jd);
@@ -125,15 +128,36 @@
m_Earth -> findPosition( &num );
dms LST(ksdata->geo()->GSTtoLST(t.gst()));
- Object1 -> findPosition(&num, ksdata->geo()->lat(), &LST, (KSPlanetBase *)m_Earth);
- Object2 -> findPosition(&num, ksdata->geo()->lat(), &LST, (KSPlanetBase *)m_Earth);
+ if( Object1->isSolarSystem() ) {
+ switch( Object1->type() ) {
+ case 2: {
+ KSPlanet *Planet = (KSPlanet *)Object1;
+ Planet->findPosition(&num, ksdata->geo()->lat(), &LST, (KSPlanetBase *)m_Earth);
+ break;
+ }
+ case 9: {
+ KSComet *Comet = (KSComet *)Object1;
+ Comet->findPosition(&num, ksdata->geo()->lat(), &LST, (KSPlanetBase *)m_Earth);
+ break;
+ }
+ case 10: {
+ KSAsteroid *Asteroid = (KSAsteroid *)Object1;
+ Asteroid->findPosition(&num, ksdata->geo()->lat(), &LST, (KSPlanetBase *)m_Earth);
+ break;
+ }
+ }
+ }
+ else
+ Object1->updateCoords( &num );
+ Object2->findPosition(&num, ksdata->geo()->lat(), &LST, (KSPlanetBase *)m_Earth);
+
dist.setRadians(Object1 -> angularDistanceTo(Object2).radians());
return dist;
}
-bool KSConjunct::findPrecise(QPair<long double, dms> *out, KSPlanetBase *Object1, KSPlanetBase *Object2, long double jd, double step, int prevSign) {
+bool KSConjunct::findPrecise(QPair<long double, dms> *out, SkyObject *Object1, KSPlanetBase *Object2, long double jd, double step, int prevSign) {
dms prevDist;
int Sign;
dms Dist;
--- trunk/KDE/kdeedu/kstars/kstars/tools/ksconjunct.h #831365:831366
@@ -23,11 +23,12 @@
#include <QObject>
#include "dms.h"
+#include "skyobject.h"
#include "ksplanet.h"
#include "ksplanetbase.h"
#include "ksnumbers.h"
-
+class SkyObject;
class KSNumbers;
class KSPlanetBase;
class KSPlanet;
@@ -71,7 +72,7 @@
*@return Hash containing julian days of close conjunctions against separation
*/
- QMap<long double, dms> findClosestApproach(KSPlanetBase& Object1, KSPlanetBase& Object2, long double startJD, long double stopJD, dms maxSeparation);
+ QMap<long double, dms> findClosestApproach(SkyObject& Object1, KSPlanetBase& Object2, long double startJD, long double stopJD, dms maxSeparation);
signals:
void madeProgress( int progress );
@@ -89,7 +90,7 @@
*@return The angular distance between the two bodies.
*/
- dms findDistance(long double jd, KSPlanetBase *Object1, KSPlanetBase *Object2);
+ dms findDistance(long double jd, SkyObject *Object1, KSPlanetBase *Object2);
/**
*@short Compute the precise value of the extremum once the extremum has been detected.
@@ -104,7 +105,7 @@
*@return true if the extremum is a minimum
*/
- bool findPrecise(QPair<long double, dms> *out, KSPlanetBase *Object1, KSPlanetBase *Object2, long double jd, double step, int prevSign);
+ bool findPrecise(QPair<long double, dms> *out, SkyObject *Object1, KSPlanetBase *Object2, long double jd, double step, int prevSign);
/**
*@short Return the sign of an angle
More information about the Kstars-devel
mailing list