00001 #include <klocale.h>
00002 #include <qstatusbar.h>
00003 #include <qdatetime.h>
00004 #include <knuminput.h>
00005 #include <kcombobox.h>
00006 #include <qradiobutton.h>
00007 #include <qlistview.h>
00008 #include <kpopupmenu.h>
00009
00010 #include "eclipsefinderdlg.h"
00011 #include "celestiacore.h"
00012 #include "celengine/astro.h"
00013 #include "eclipsefinder.h"
00014
00015
00016
00017
00018
00019 EclipseFinderDlg::EclipseFinderDlg( QWidget* parent, CelestiaCore *appCore)
00020 : EclipseFinderDlgBase( parent, i18n("Eclipse Finder") ),appCore(appCore)
00021 {
00022 astro::Date date(appCore->getSimulation()->getTime());
00023 fromYSpin->setValue(date.year);
00024 fromMSpin->setValue(date.month);
00025 fromDSpin->setValue(date.day);
00026 toYSpin->setValue(date.year);
00027 toMSpin->setValue(date.month);
00028 toDSpin->setValue(date.day);
00029
00030
00031 statusBar()->hide();
00032 }
00033
00034
00035
00036
00037 EclipseFinderDlg::~EclipseFinderDlg()
00038 {
00039
00040 }
00041
00042
00043
00044
00045 void EclipseFinderDlg::search()
00046 {
00047 std::string onBody = "";
00048
00049 switch(comboBody->currentItem()) {
00050 case 0:
00051 onBody = "Earth";
00052 break;
00053 case 1:
00054 onBody = "Jupiter";
00055 break;
00056 case 2:
00057 onBody = "Saturn";
00058 break;
00059 case 3:
00060 onBody = "Uranus";
00061 break;
00062 case 4:
00063 onBody = "Neptune";
00064 break;
00065 case 5:
00066 onBody = "Pluto";
00067 break;
00068 }
00069 EclipseFinder ef(appCore,
00070 onBody,
00071 (radioSolar->isChecked()?Eclipse::Solar:Eclipse::Moon),
00072 (double)(astro::Date(fromYSpin->value(),
00073 fromMSpin->value(),
00074 fromDSpin->value())),
00075 (double)(astro::Date(toYSpin->value(),
00076 toMSpin->value(),
00077 toDSpin->value())) + 1
00078 );
00079
00080 std::vector<Eclipse> eclipses = ef.getEclipses();
00081
00082 listEclipses->clear();
00083 for (std::vector<Eclipse>::iterator i = eclipses.begin();
00084 i != eclipses.end();
00085 i++) {
00086
00087 if ((*i).planete == "None") {
00088 new QListViewItem(listEclipses,
00089 QString((*i).planete.c_str()));
00090 continue;
00091 }
00092
00093 char d[12], strStart[10], strEnd[10];
00094 astro::Date start((*i).startTime);
00095 astro::Date end((*i).endTime);
00096
00097 sprintf(d, "%d-%02d-%02d", (*i).date->year, (*i).date->month, (*i).date->day);
00098 sprintf(strStart, "%02d:%02d:%02d", start.hour, start.minute, (int)start.seconds);
00099 sprintf(strEnd, "%02d:%02d:%02d", end.hour, end.minute, (int)end.seconds);
00100
00101 new QListViewItem(listEclipses,
00102 QString(_((*i).planete.c_str())),
00103 QString(_((*i).sattelite.c_str())),
00104 d,
00105 strStart,
00106 strEnd
00107 );
00108 }
00109 }
00110
00111 void EclipseFinderDlg::gotoEclipse(QListViewItem* item, const QPoint& p, int col) {
00112 if (item->text(0) == "None") return;
00113
00114 KPopupMenu menu(this);
00115
00116 menu.insertTitle(item->text(col == 1));
00117 menu.insertItem(i18n("&Goto"), 1);
00118
00119 int id=menu.exec(p);
00120
00121 if (id == 1) {
00122 Selection target = appCore->getSimulation()->findObjectFromPath(std::string(item->text(col == 1).latin1()), true);
00123 Selection ref = target.body()->getSystem()->getStar();
00124 appCore->getSimulation()->setFrame(FrameOfReference(astro::PhaseLock, target, ref));
00125 QString date = item->text(2);
00126 int yearEnd = date.find('-', 1);
00127 astro::Date d(date.left(yearEnd).toInt(),
00128 date.mid(yearEnd + 1, 2).toInt(),
00129 date.mid(yearEnd + 4, 2).toInt());
00130 d.hour = item->text(3).left(2).toInt();
00131 d.minute = item->text(3).mid(3, 2).toInt();
00132 d.seconds = item->text(3).mid(6, 2).toDouble();
00133 appCore->getSimulation()->setTime((double)d);
00134 appCore->getSimulation()->update(0.0);
00135
00136 double distance = astro::kilometersToMicroLightYears(target.radius() * 4.0);
00137 RigidTransform to;
00138 to.rotation = Quatd::yrotation(PI);
00139 to.translation = Point3d(0, 0, -distance);
00140 appCore->getSimulation()->gotoLocation(to, 2.5);
00141 }
00142 }
00143
00144
00145
00146
00147