Stellarium  0.90.0
AstroCalcDialog.hpp
1 /*
2  * Stellarium
3  *
4  * Copyright (C) 2015 Alexander Wolf
5  * Copyright (C) 2016 Nick Fedoseev (visualization of ephemeris)
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19 */
20 
21 #ifndef _ASTROCALCDIALOG_HPP_
22 #define _ASTROCALCDIALOG_HPP_
23 
24 #include <QObject>
25 #include <QTreeWidget>
26 #include <QTreeWidgetItem>
27 #include <QMap>
28 #include <QVector>
29 #include <QTimer>
30 
31 #include "StelDialog.hpp"
32 #include "StelCore.hpp"
33 #include "Planet.hpp"
34 #include "SolarSystem.hpp"
35 #include "Nebula.hpp"
36 #include "NebulaMgr.hpp"
37 #include "StarMgr.hpp"
38 #include "StelUtils.hpp"
39 
40 class Ui_astroCalcDialogForm;
41 class QListWidgetItem;
42 
44 {
45  Q_OBJECT
46 
47 public:
51  CColumnName,
59  };
60 
64  EphemerisDate,
73  };
74 
78  PhenomenaType,
84  };
85 
88  enum GraphsTypes {
89  GraphMagnitudeVsTime = 1,
90  GraphPhaseVsTime = 2,
91  GraphDistanceVsTime = 3,
92  GraphElongationVsTime = 4,
93  GraphAngularSizeVsTime = 5,
94  GraphPhaseAngleVsTime = 6
95  };
96 
97  AstroCalcDialog(QObject* parent);
98  virtual ~AstroCalcDialog();
99 
101  void styleChanged();
102 
103  static QVector<Vec3d> EphemerisListCoords;
104  static QVector<QString> EphemerisListDates;
105  static QVector<float> EphemerisListMagnitudes;
106  static int DisplayedPositionIndex;
107 
108 public slots:
109  void retranslate();
110 
111 protected:
113  virtual void createDialogContent();
114  Ui_astroCalcDialogForm *ui;
115 
116 private slots:
117  void currentCelestialPositions();
118  void populateCelestialCategoryList();
119  void selectCurrentCelestialPosition(const QModelIndex &modelIndex);
120 
121  void saveCelestialPositionsMagnitudeLimit(double mag);
122  void saveCelestialPositionsHorizontalCoordinatesFlag(bool b);
123  void saveCelestialPositionsCategory(int index);
124 
126  void generateEphemeris();
127  void cleanupEphemeris();
128  void selectCurrentEphemeride(const QModelIndex &modelIndex);
129  void saveEphemeris();
130  void onChangedEphemerisPosition(const QModelIndex &modelIndex);
131  void reGenerateEphemeris();
132 
133  void saveEphemerisCelestialBody(int index);
134  void saveEphemerisTimeStep(int index);
135 
137  void calculatePhenomena();
138  void cleanupPhenomena();
139  void selectCurrentPhenomen(const QModelIndex &modelIndex);
140  void savePhenomena();
141  void savePhenomenaAngularSeparation(double v);
142 
143  void savePhenomenaCelestialBody(int index);
144  void savePhenomenaCelestialGroup(int index);
145  void savePhenomenaOppositionFlag(bool b);
146 
148  void drawAltVsTimeDiagram();
150  void drawCurrentTimeDiagram();
152  void drawTransitTimeDiagram();
154  void mouseOverLine(QMouseEvent *event);
155 
156  void saveGraphsCelestialBody(int index);
157  void saveGraphsFirstId(int index);
158  void saveGraphsSecondId(int index);
159  void drawXVsTimeGraphs();
160 
161  // WUT
162  void saveWutMagnitudeLimit(double mag);
163  void saveWutTimeInterval(int index);
164  void calculateWutObjects();
165  void selectWutObject();
166 
167  void updateAstroCalcData();
168 
169  void changePage(QListWidgetItem *current, QListWidgetItem *previous);
170 
171  void updateSolarSystemData();
172 
173 private:
174  class StelCore* core;
175  class SolarSystem* solarSystem;
176  class NebulaMgr* dsoMgr;
177  class StarMgr* starMgr;
178  class StelObjectMgr* objectMgr;
179  class StelLocaleMgr* localeMgr;
180  QSettings* conf;
181  QTimer *currentTimeLine;
182  QHash<QString,QString> wutObjects;
183  QHash<QString,int> wutCategories;
184 
186  void setCelestialPositionsHeaderNames();
188  void setEphemerisHeaderNames();
190  void setPhenomenaHeaderNames();
191 
193  void initListCelestialPositions();
195  void initListEphemeris();
197  void initListPhenomena();
198 
203  void populateCelestialBodyList();
205  void populateEphemerisTimeStepsList();
207  void populateMajorPlanetList();
209  void populateGroupCelestialBodyList();
211  void prepareAxesAndGraph();
212  void prepareXVsTimeAxesAndGraph();
214  void populateTimeIntervalsList();
216  void populateWutGroups();
217 
218  void populateFunctionsList();
219 
224  QMap<double, double> findClosestApproach(PlanetP& object1, PlanetP& object2, double startJD, double stopJD, double maxSeparation, bool opposition);
225  double findDistance(double JD, PlanetP object1, PlanetP object2, bool opposition);
226  bool findPrecise(QPair<double, double>* out, PlanetP object1, PlanetP object2, double JD, double step, int prevSign, bool opposition);
227  void fillPhenomenaTable(const QMap<double, double> list, const PlanetP object1, const PlanetP object2, bool opposition);
228 
229  QMap<double, double> findClosestApproach(PlanetP& object1, NebulaP& object2, double startJD, double stopJD, double maxSeparation);
230  double findDistance(double JD, PlanetP object1, NebulaP object2);
231  bool findPrecise(QPair<double, double>* out, PlanetP object1, NebulaP object2, double JD, double step, int prevSign);
232  void fillPhenomenaTable(const QMap<double, double> list, const PlanetP object1, const NebulaP object2);
233 
234  QMap<double, double> findClosestApproach(PlanetP& object1, StelObjectP& object2, double startJD, double stopJD, double maxSeparation);
235  double findDistance(double JD, PlanetP object1, StelObjectP object2);
236  bool findPrecise(QPair<double, double>* out, PlanetP object1, StelObjectP object2, double JD, double step, int prevSign);
237  void fillPhenomenaTable(const QMap<double, double> list, const PlanetP object1, const StelObjectP object2);
238 
239  QString delimiter, acEndl;
240  QStringList ephemerisHeader, phenomenaHeader, positionsHeader;
241  static float brightLimit;
242  static float minY, maxY, transitX, minY1, maxY1, minY2, maxY2;
243  static QString yAxis1Legend, yAxis2Legend;
244 
247  void updateTabBarListWidgetWidth();
248 };
249 
250 // Reimplements the QTreeWidgetItem class to fix the sorting bug
251 class ACCelPosTreeWidgetItem : public QTreeWidgetItem
252 {
253 public:
254  ACCelPosTreeWidgetItem(QTreeWidget* parent)
255  : QTreeWidgetItem(parent)
256  {
257  }
258 
259 private:
260  bool operator < (const QTreeWidgetItem &other) const
261  {
262  int column = treeWidget()->sortColumn();
263 
264  if (column == AstroCalcDialog::CColumnName)
265  {
266  QRegExp dso("^(\\w+)\\s*(\\d+)\\s*(.*)$");
267  QRegExp mp("^[(](\\d+)[)]\\s(.+)$");
268  int a = 0, b = 0;
269  if (dso.exactMatch(text(column)))
270  a = dso.capturedTexts().at(2).toInt();
271  if (a==0 && mp.exactMatch(text(column)))
272  a = mp.capturedTexts().at(1).toInt();
273  if (dso.exactMatch(other.text(column)))
274  b = dso.capturedTexts().at(2).toInt();
275  if (b==0 && mp.exactMatch(other.text(column)))
276  b = mp.capturedTexts().at(1).toInt();
277  if (a>0 && b>0)
278  return a < b;
279  else
280  return text(column).toLower() < other.text(column).toLower();
281  }
282  else if (column == AstroCalcDialog::CColumnRA || column == AstroCalcDialog::CColumnDec)
283  {
284  return StelUtils::getDecAngle(text(column)) < StelUtils::getDecAngle(other.text(column));
285  }
287  {
288  return text(column).toFloat() < other.text(column).toFloat();
289  }
290  else
291  {
292  return text(column).toLower() < other.text(column).toLower();
293  }
294  }
295 };
296 
297 // Reimplements the QTreeWidgetItem class to fix the sorting bug
298 class ACEphemTreeWidgetItem : public QTreeWidgetItem
299 {
300 public:
301  ACEphemTreeWidgetItem(QTreeWidget* parent)
302  : QTreeWidgetItem(parent)
303  {
304  }
305 
306 private:
307  bool operator < (const QTreeWidgetItem &other) const
308  {
309  int column = treeWidget()->sortColumn();
310 
312  {
313  return StelUtils::getDecAngle(text(column)) < StelUtils::getDecAngle(other.text(column));
314  }
316  {
317  return text(column).toFloat() < other.text(column).toFloat();
318  }
319  else
320  {
321  return text(column).toLower() < other.text(column).toLower();
322  }
323  }
324 };
325 
326 // Reimplements the QTreeWidgetItem class to fix the sorting bug
327 class ACPhenTreeWidgetItem : public QTreeWidgetItem
328 {
329 public:
330  ACPhenTreeWidgetItem(QTreeWidget* parent)
331  : QTreeWidgetItem(parent)
332  {
333  }
334 
335 private:
336  bool operator < (const QTreeWidgetItem &other) const
337  {
338  int column = treeWidget()->sortColumn();
339 
341  {
342  return StelUtils::getDecAngle(text(column)) < StelUtils::getDecAngle(other.text(column));
343  }
344  else
345  {
346  return text(column).toLower() < other.text(column).toLower();
347  }
348  }
349 };
350 
351 #endif // _ASTROCALCDIALOG_HPP_
EphemerisColumns
Defines the number and the order of the columns in the ephemeris table.
date and time of ephemeris
CPositionsColumns
Defines the number and the order of the columns in the table that lists celestial bodies positions...
Manage i18n operations such as message translation and date/time localization.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
Base class for all the GUI windows in Stellarium.
Definition: StelDialog.hpp:72
extra data (surface brightness, separation, period, etc.)
PhenomenaColumns
Defines the number and the order of the columns in the phenomena table.
GraphsTypes
Defines the type of graphs.
This StelObjectModule derivative is used to model SolarSystem bodies.
Definition: SolarSystem.hpp:47
virtual void createDialogContent()
Initialize the dialog widgets and connect the signals/slots.
date and time of ephemeris
Stores the star catalogue data.
Definition: StarMgr.hpp:98
Manage the selection and queries on one or more StelObjects.
double getDecAngle(const QString &str)
Convert a string longitude, latitude, RA or Declination angle to radians.
void styleChanged()
Notify that the application style changed.
Manage a collection of nebulae.
Definition: NebulaMgr.hpp:48