Stellarium  0.16.1
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 saveCelestialPositions();
120  void selectCurrentCelestialPosition(const QModelIndex &modelIndex);
121 
122  void saveCelestialPositionsMagnitudeLimit(double mag);
123  void saveCelestialPositionsHorizontalCoordinatesFlag(bool b);
124  void saveCelestialPositionsCategory(int index);
125 
127  void generateEphemeris();
128  void cleanupEphemeris();
129  void selectCurrentEphemeride(const QModelIndex &modelIndex);
130  void saveEphemeris();
131  void onChangedEphemerisPosition(const QModelIndex &modelIndex);
132  void reGenerateEphemeris();
133 
134  void saveEphemerisCelestialBody(int index);
135  void saveEphemerisTimeStep(int index);
136 
138  void calculatePhenomena();
139  void cleanupPhenomena();
140  void selectCurrentPhenomen(const QModelIndex &modelIndex);
141  void savePhenomena();
142  void savePhenomenaAngularSeparation(double v);
143 
144  void savePhenomenaCelestialBody(int index);
145  void savePhenomenaCelestialGroup(int index);
146  void savePhenomenaOppositionFlag(bool b);
147 
149  void drawAltVsTimeDiagram();
151  void drawCurrentTimeDiagram();
153  void drawTransitTimeDiagram();
155  void mouseOverLine(QMouseEvent *event);
156 
157  void saveGraphsCelestialBody(int index);
158  void saveGraphsFirstId(int index);
159  void saveGraphsSecondId(int index);
160  void drawXVsTimeGraphs();
161 
162  // WUT
163  void saveWutMagnitudeLimit(double mag);
164  void saveWutTimeInterval(int index);
165  void calculateWutObjects();
166  void selectWutObject();
167  void saveWutObjects();
168 
169  void updateAstroCalcData();
170 
171  void changePage(QListWidgetItem *current, QListWidgetItem *previous);
172 
173  void updateSolarSystemData();
174 
175 private:
176  class StelCore* core;
177  class SolarSystem* solarSystem;
178  class NebulaMgr* dsoMgr;
179  class StarMgr* starMgr;
180  class StelObjectMgr* objectMgr;
181  class StelLocaleMgr* localeMgr;
182  QSettings* conf;
183  QTimer *currentTimeLine;
184  QHash<QString,QString> wutObjects;
185  QHash<QString,int> wutCategories;
186 
188  void setCelestialPositionsHeaderNames();
190  void setEphemerisHeaderNames();
192  void setPhenomenaHeaderNames();
193 
195  void initListCelestialPositions();
197  void initListEphemeris();
199  void initListPhenomena();
200 
205  void populateCelestialBodyList();
207  void populateEphemerisTimeStepsList();
209  void populateMajorPlanetList();
211  void populateGroupCelestialBodyList();
213  void prepareAxesAndGraph();
214  void prepareXVsTimeAxesAndGraph();
216  void populateTimeIntervalsList();
218  void populateWutGroups();
219 
220  void populateFunctionsList();
221 
226  QMap<double, double> findClosestApproach(PlanetP& object1, PlanetP& object2, double startJD, double stopJD, double maxSeparation, bool opposition);
227  double findDistance(double JD, PlanetP object1, PlanetP object2, bool opposition);
228  bool findPrecise(QPair<double, double>* out, PlanetP object1, PlanetP object2, double JD, double step, int prevSign, bool opposition);
229  void fillPhenomenaTable(const QMap<double, double> list, const PlanetP object1, const PlanetP object2, bool opposition);
230 
231  QMap<double, double> findClosestApproach(PlanetP& object1, NebulaP& object2, double startJD, double stopJD, double maxSeparation);
232  double findDistance(double JD, PlanetP object1, NebulaP object2);
233  bool findPrecise(QPair<double, double>* out, PlanetP object1, NebulaP object2, double JD, double step, int prevSign);
234  void fillPhenomenaTable(const QMap<double, double> list, const PlanetP object1, const NebulaP object2);
235 
236  QMap<double, double> findClosestApproach(PlanetP& object1, StelObjectP& object2, double startJD, double stopJD, double maxSeparation);
237  double findDistance(double JD, PlanetP object1, StelObjectP object2);
238  bool findPrecise(QPair<double, double>* out, PlanetP object1, StelObjectP object2, double JD, double step, int prevSign);
239  void fillPhenomenaTable(const QMap<double, double> list, const PlanetP object1, const StelObjectP object2);
240 
241  QString delimiter, acEndl;
242  QStringList ephemerisHeader, phenomenaHeader, positionsHeader;
243  static float brightLimit;
244  static float minY, maxY, transitX, minY1, maxY1, minY2, maxY2;
245  static QString yAxis1Legend, yAxis2Legend;
246 
249  void updateTabBarListWidgetWidth();
250 };
251 
252 // Reimplements the QTreeWidgetItem class to fix the sorting bug
253 class ACCelPosTreeWidgetItem : public QTreeWidgetItem
254 {
255 public:
256  ACCelPosTreeWidgetItem(QTreeWidget* parent)
257  : QTreeWidgetItem(parent)
258  {
259  }
260 
261 private:
262  bool operator < (const QTreeWidgetItem &other) const
263  {
264  int column = treeWidget()->sortColumn();
265 
266  if (column == AstroCalcDialog::CColumnName)
267  {
268  QRegExp dso("^(\\w+)\\s*(\\d+)\\s*(.*)$");
269  QRegExp mp("^[(](\\d+)[)]\\s(.+)$");
270  int a = 0, b = 0;
271  if (dso.exactMatch(text(column)))
272  a = dso.capturedTexts().at(2).toInt();
273  if (a==0 && mp.exactMatch(text(column)))
274  a = mp.capturedTexts().at(1).toInt();
275  if (dso.exactMatch(other.text(column)))
276  b = dso.capturedTexts().at(2).toInt();
277  if (b==0 && mp.exactMatch(other.text(column)))
278  b = mp.capturedTexts().at(1).toInt();
279  if (a>0 && b>0)
280  return a < b;
281  else
282  return text(column).toLower() < other.text(column).toLower();
283  }
284  else if (column == AstroCalcDialog::CColumnRA || column == AstroCalcDialog::CColumnDec)
285  {
286  return StelUtils::getDecAngle(text(column)) < StelUtils::getDecAngle(other.text(column));
287  }
289  {
290  return text(column).toFloat() < other.text(column).toFloat();
291  }
292  else
293  {
294  return text(column).toLower() < other.text(column).toLower();
295  }
296  }
297 };
298 
299 // Reimplements the QTreeWidgetItem class to fix the sorting bug
300 class ACEphemTreeWidgetItem : public QTreeWidgetItem
301 {
302 public:
303  ACEphemTreeWidgetItem(QTreeWidget* parent)
304  : QTreeWidgetItem(parent)
305  {
306  }
307 
308 private:
309  bool operator < (const QTreeWidgetItem &other) const
310  {
311  int column = treeWidget()->sortColumn();
312 
314  {
315  return StelUtils::getDecAngle(text(column)) < StelUtils::getDecAngle(other.text(column));
316  }
318  {
319  return text(column).toFloat() < other.text(column).toFloat();
320  }
321  else
322  {
323  return text(column).toLower() < other.text(column).toLower();
324  }
325  }
326 };
327 
328 // Reimplements the QTreeWidgetItem class to fix the sorting bug
329 class ACPhenTreeWidgetItem : public QTreeWidgetItem
330 {
331 public:
332  ACPhenTreeWidgetItem(QTreeWidget* parent)
333  : QTreeWidgetItem(parent)
334  {
335  }
336 
337 private:
338  bool operator < (const QTreeWidgetItem &other) const
339  {
340  int column = treeWidget()->sortColumn();
341 
343  {
344  return StelUtils::getDecAngle(text(column)) < StelUtils::getDecAngle(other.text(column));
345  }
346  else
347  {
348  return text(column).toLower() < other.text(column).toLower();
349  }
350  }
351 };
352 
353 #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