File indexing completed on 2024-04-14 14:11:46

0001 /*
0002     SPDX-FileCopyrightText: 2003 Thomas Kabelmann <tk78@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kstarsdata.h"
0010 #include "kstarsdatetime.h"
0011 #include "ui_wutdialog.h"
0012 #include "catalogobject.h"
0013 #include "catalogsdb.h"
0014 
0015 #include <QFrame>
0016 #include <QDialog>
0017 #include <qevent.h>
0018 
0019 class GeoLocation;
0020 class SkyObject;
0021 
0022 class WUTDialogUI : public QFrame, public Ui::WUTDialog
0023 {
0024     Q_OBJECT
0025 
0026   public:
0027     explicit WUTDialogUI(QWidget *p = nullptr);
0028 };
0029 
0030 /**
0031  * @class WUTDialog
0032  *
0033  * What's up tonight dialog is a window which lists all sky objects
0034  * that will be visible during the next night.
0035  *
0036  * @author Thomas Kabelmann
0037  * @version 1.0
0038  */
0039 class WUTDialog : public QDialog
0040 {
0041     Q_OBJECT
0042 
0043   public:
0044     /** Constructor */
0045     explicit WUTDialog(QWidget *ks, bool session = false,
0046                        GeoLocation *geo  = KStarsData::Instance()->geo(),
0047                        KStarsDateTime lt = KStarsData::Instance()->lt());
0048     virtual ~WUTDialog() override = default;
0049 
0050     /**
0051      * @short Check visibility of object
0052      * @p o the object to check
0053      * @return true if visible
0054      */
0055     bool checkVisibility(const SkyObject *o);
0056 
0057   public slots:
0058     /**
0059      * @short Determine which objects are visible, and store them in
0060      * an array of lists, classified by object type
0061      */
0062     void init();
0063 
0064   private slots:
0065     /**
0066      * @short Load the list of visible objects for selected object type.
0067      * @p category the string describing the type of object
0068      */
0069     void slotLoadList(const QString &category);
0070 
0071     /** Display the rise/transit/set times for selected object */
0072     void slotDisplayObject(const QString &name);
0073 
0074     /**
0075      * @short Apply user's choice of what part of the night should be examined:
0076      * @li 0: Evening only (sunset to midnight)
0077      * @li 1: Morning only (midnight to sunrise)
0078      * @li 2: All night (sunset to sunrise)
0079      */
0080     void slotEveningMorning(int flag);
0081 
0082     /**
0083      * @short Adjust the date for the WUT tool
0084      * @note this does NOT affect the date of the sky map
0085      */
0086     void slotChangeDate();
0087 
0088     /**
0089      * @short Adjust the geographic location for the WUT tool
0090      * @note this does NOT affect the geographic location for the sky map
0091      */
0092     void slotChangeLocation();
0093 
0094     /** Open the detail dialog for the current object */
0095     void slotDetails();
0096 
0097     /** Center the display on the current object */
0098     void slotCenter();
0099 
0100     /** Add the object to the observing list */
0101     void slotObslist();
0102 
0103     /** Filters the objects displayed by Magnitude */
0104     void slotChangeMagnitude();
0105 
0106     void updateMag();
0107 
0108     /**
0109      * Load skyobjects from the DSO database and return an `ObjectLists` like
0110      * vector.
0111      *
0112      * \param category The category for which to load the dsos.
0113      * \param types The types to load.
0114      */
0115     QVector<QPair<QString, const SkyObject *>>
0116     load_dso(const QString &category, const std::vector<SkyObject::TYPE> &types);
0117 
0118   private:
0119     QSet<const SkyObject *> &visibleObjects(const QString &category);
0120     const SkyObject * findVisibleObject(const QString &name);
0121     bool isCategoryInitialized(const QString &category);
0122     /** @short Initialize all SIGNAL/SLOT connections, used in constructor */
0123     void makeConnections();
0124     /** @short Initialize category list, used in constructor */
0125     void initCategories();
0126 
0127     void showEvent(QShowEvent *event) override;
0128 
0129     WUTDialogUI *WUT{ nullptr };
0130     bool session { false };
0131     QTime sunRiseTomorrow, sunSetToday, sunRiseToday, moonRise, moonSet;
0132     KStarsDateTime T0, UT0, Tomorrow, TomorrowUT, Evening, EveningUT;
0133     GeoLocation *geo { nullptr };
0134     int EveningFlag { 0 };
0135     float m_Mag{ 0 };
0136     QTimer *timer{ nullptr };
0137     QStringList m_Categories;
0138     QHash<QString, QSet<const SkyObject *>> m_VisibleList;
0139     QHash<QString, bool> m_CategoryInitialized;
0140     QHash<QString, CatalogsDB::CatalogObjectList> m_CatalogObjects;
0141 };