File indexing completed on 2024-07-14 07:17:21

0001 /*
0002     SPDX-FileCopyrightText: 2009 Jerome SONRIER <jsid@emor3j.fr.eu.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "pointlistcomponent.h"
0010 
0011 #include <QColor>
0012 #include <QImage>
0013 #include <QObject>
0014 #include <QStringList>
0015 
0016 class SkyPainter;
0017 
0018 /**
0019  * @class FlagComponent
0020  * @short Represents a flag on the sky map.
0021  * Each flag is composed by a SkyPoint where coordinates are stored, an
0022  * epoch and a label. This class also stores flag images and associates
0023  * each flag with an image.
0024  * When FlagComponent is created, it seeks all file names beginning with
0025  * "_flag" in the user directory and *consider* them as flag images.
0026  *
0027  * The file flags.dat stores coordinates, epoch, image name and label of each
0028  * flags and is read to init FlagComponent
0029  *
0030  * @author Jerome SONRIER
0031  * @version 1.1
0032  */
0033 class FlagComponent : public QObject, public PointListComponent
0034 {
0035     Q_OBJECT
0036 
0037   public:
0038     /** @short Constructor. */
0039     explicit FlagComponent(SkyComposite *);
0040 
0041     virtual ~FlagComponent() override = default;
0042 
0043     void draw(SkyPainter *skyp) override;
0044 
0045     bool selected() override;
0046 
0047     void update(KSNumbers *num = nullptr) override;
0048 
0049     /**
0050      * @short Add a flag.
0051      * @param flagPoint Sky point in epoch coordinates
0052      * @param epoch Moment for which celestial coordinates are specified
0053      * @param image Image name
0054      * @param label Label of the flag
0055      * @param labelColor Color of the label
0056      */
0057     void add(const SkyPoint &flagPoint, QString epoch, QString image, QString label, QColor labelColor);
0058 
0059     /**
0060      * @short Remove a flag.
0061      * @param index Index of the flag to be remove.
0062      */
0063     void remove(int index);
0064 
0065     /**
0066      * @short Update a flag.
0067      * @param index index of the flag to be updated.
0068      * @param flagPoint point of the flag.
0069      * @param epoch new flag epoch.
0070      * @param image new flag image.
0071      * @param label new flag label.
0072      * @param labelColor new flag label color.
0073      */
0074     void updateFlag(int index, const SkyPoint &flagPoint, QString epoch, QString image, QString label,
0075                     QColor labelColor);
0076 
0077     /**
0078      * @short Return image names.
0079      * @return the list of all image names
0080      */
0081     QStringList getNames();
0082 
0083     /**
0084      * @short Return the numbers of flags.
0085      * @return the size of m_PointList
0086      */
0087     int size();
0088 
0089     /**
0090      * @short Get epoch.
0091      * @return the epoch as a string
0092      * @param index Index of the flag
0093      */
0094     QString epoch(int index);
0095 
0096     /**
0097      * @short Get label.
0098      * @return the label as a string
0099      * @param index Index of the flag
0100      */
0101     QString label(int index);
0102 
0103     /**
0104      * @short Get label color.
0105      * @return the label color
0106      * @param index Index of the flag
0107      */
0108     QColor labelColor(int index);
0109 
0110     /**
0111      * @short Get image.
0112      * @return the image associated with the flag
0113      * @param index Index of the flag
0114      */
0115     QImage image(int index);
0116 
0117     /**
0118      * @short Get image name.
0119      * @return the name of the image associated with the flag
0120      * @param index Index of the flag
0121      */
0122     QString imageName(int index);
0123 
0124     /**
0125      * @short Get images.
0126      * @return all images that can be use
0127      */
0128     QList<QImage> imageList();
0129 
0130     /**
0131      * @short Get image.
0132      * @param index Index of the image in m_Images
0133      * @return an image from m_Images
0134      */
0135     QImage imageList(int index);
0136 
0137     /**
0138      * @brief epochCoords return coordinates recorded in original epoch
0139      * @param index index of the flag
0140      * @return pair of RA/DEC in original epoch
0141      */
0142     QPair<double, double> epochCoords(int index);
0143 
0144     /**
0145      * @short Get list of flag indexes near specified SkyPoint with radius specified in pixels.
0146      * @param point central SkyPoint.
0147      * @param pixelRadius radius in pixels.
0148      */
0149     QList<int> getFlagsNearPix(SkyPoint *point, int pixelRadius);
0150 
0151     /** @short Load flags from flags.dat file. */
0152     void loadFromFile();
0153 
0154     /** @short Save flags to flags.dat file. */
0155     void saveToFile();
0156 
0157   private:
0158     // Convert from given epoch to J2000. If epoch is already J2000, do nothing
0159     void toJ2000(SkyPoint *p, QString epoch);
0160 
0161     /// List of epochs
0162     QStringList m_Epoch;
0163     /// RA/DEC stored in original epoch
0164     QList<QPair<double, double>> m_EpochCoords;
0165     /// List of image index
0166     QList<int> m_FlagImages;
0167     /// List of label
0168     QStringList m_Labels;
0169     /// List of label colors
0170     QList<QColor> m_LabelColors;
0171     /// List of image names
0172     QStringList m_Names;
0173     /// List of flag images
0174     QList<QImage> m_Images;
0175 };