eclipsefinderdlg.cpp
上传用户:center1979
上传日期:2022-07-26
资源大小:50633k
文件大小:4k
源码类别:

OpenGL

开发平台:

Visual C++

  1. #include <libintl.h>
  2. #include <klocale.h>
  3. #include <qstatusbar.h>
  4. #include <qdatetime.h>
  5. #include <knuminput.h>
  6. #include <kcombobox.h>
  7. #include <qradiobutton.h>
  8. #include <qlistview.h>
  9. #include <kpopupmenu.h>
  10. #include "eclipsefinderdlg.h"
  11. #include "celestiacore.h"
  12. #include "celengine/astro.h"
  13. #include "eclipsefinder.h"
  14. /* 
  15.  *  Constructs a EclipseFinder which is a child of 'parent', with the 
  16.  *  name 'name' and widget flags set to 'f' 
  17.  */
  18. EclipseFinderDlg::EclipseFinderDlg( QWidget* parent, CelestiaCore *appCore)
  19.     : EclipseFinderDlgBase( parent, i18n("Eclipse Finder") ),appCore(appCore)
  20. {  
  21.     astro::Date date(appCore->getSimulation()->getTime());
  22.     fromYSpin->setValue(date.year-1);
  23.     fromMSpin->setValue(date.month);
  24.     fromDSpin->setValue(date.day);    
  25.     toYSpin->setValue(date.year+1);
  26.     toMSpin->setValue(date.month);
  27.     toDSpin->setValue(date.day);    
  28.     
  29.     statusBar()->hide();
  30. }
  31. /*  
  32.  *  Destroys the object and frees any allocated resources
  33.  */
  34. EclipseFinderDlg::~EclipseFinderDlg()
  35. {
  36.     // no need to delete child widgets, Qt does it all for us
  37. }
  38. /*
  39.  * public slot
  40.  */
  41. void EclipseFinderDlg::search()
  42. {
  43.     std::string onBody = "";
  44.        
  45.     switch(comboBody->currentItem()) {
  46.         case 0:
  47.             onBody = "Earth";
  48.             break;    
  49.         case 1:
  50.             onBody = "Jupiter";
  51.             break;    
  52.         case 2:
  53.             onBody = "Saturn";
  54.             break;    
  55.         case 3:
  56.             onBody = "Uranus";
  57.             break;    
  58.         case 4:
  59.             onBody = "Neptune";
  60.             break;    
  61.         case 5:
  62.             onBody = "Pluto";
  63.             break;    
  64.     }
  65.     EclipseFinder ef(appCore, 
  66.                      onBody, 
  67.                      (radioSolar->isChecked()?Eclipse::Solar:Eclipse::Moon), 
  68.                      (double)(astro::Date(fromYSpin->value(), 
  69.                                           fromMSpin->value(), 
  70.                                           fromDSpin->value())),
  71.                      (double)(astro::Date(toYSpin->value(),
  72.                                           toMSpin->value(),
  73.                                           toDSpin->value())) + 1 
  74.                      );
  75.     std::vector<Eclipse> eclipses = ef.getEclipses();
  76.     
  77.     listEclipses->clear();
  78.     for (std::vector<Eclipse>::iterator i = eclipses.begin();
  79.          i != eclipses.end();
  80.          i++) {
  81.          
  82.          if ((*i).planete == "None") {
  83.          new QListViewItem(listEclipses, 
  84.              QString((*i).planete.c_str()));
  85.                  continue;
  86.          }
  87.          
  88.          char d[12], strStart[10], strEnd[10];
  89.          astro::Date start((*i).startTime);
  90.          astro::Date end((*i).endTime);
  91.          
  92.          sprintf(d, "%d-%02d-%02d", (*i).date->year, (*i).date->month, (*i).date->day);
  93.          sprintf(strStart, "%02d:%02d:%02d", start.hour, start.minute, (int)start.seconds);
  94.          sprintf(strEnd, "%02d:%02d:%02d", end.hour, end.minute, (int)end.seconds);
  95.          
  96.          new QListViewItem(listEclipses, 
  97.              QString::fromUtf8(_((*i).planete.c_str())), 
  98.              QString::fromUtf8(_((*i).sattelite.c_str())),
  99.              d,
  100.              strStart,
  101.              strEnd
  102.              );
  103.     }
  104. }
  105. void EclipseFinderDlg::gotoEclipse(QListViewItem* item, const QPoint& p, int col) {
  106.     if (item->text(0) == "None") return;
  107.     
  108.     KPopupMenu menu(this);
  109.     
  110.     menu.insertTitle(item->text(col == 1));
  111.     menu.insertItem(i18n("&Goto"), 1);
  112.     int id=menu.exec(p);
  113.     
  114.     if (id == 1) {
  115.         Selection target = appCore->getSimulation()->findObjectFromPath(std::string(item->text(col == 1).utf8()), true);
  116. Selection ref = target.body()->getSystem()->getStar();
  117. appCore->getSimulation()->setFrame(ObserverFrame::PhaseLock, target, ref);
  118. QString date = item->text(2);
  119.         int yearEnd = date.find('-', 1);
  120.         astro::Date d(date.left(yearEnd).toInt(), 
  121.                       date.mid(yearEnd + 1, 2).toInt(),
  122.                       date.mid(yearEnd + 4, 2).toInt());
  123.         d.hour = item->text(3).left(2).toInt();
  124.         d.minute = item->text(3).mid(3, 2).toInt();
  125.         d.seconds = item->text(3).mid(6, 2).toDouble();
  126.         appCore->getSimulation()->setTime((double)d);
  127.         appCore->getSimulation()->update(0.0);
  128. double distance = astro::kilometersToMicroLightYears(target.radius() * 4.0);
  129.         appCore->getSimulation()->gotoLocation(Point3d(distance, 0, 0), Quatd::yrotation(-PI / 2) * Quatd::xrotation(-PI / 2), 5.0);
  130.     }
  131. }