File indexing completed on 2024-06-16 09:53:45

0001 /*
0002     SkyPainter: class for painting onto the sky for KStars
0003     SPDX-FileCopyrightText: 2010 Henry de Valence <hdevalence@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "skycomponents/typedef.h"
0011 #include "config-kstars.h"
0012 
0013 #include <QList>
0014 #include <QPainter>
0015 
0016 class ConstellationsArt;
0017 class DeepSkyObject;
0018 class KSComet;
0019 class KSAsteroid;
0020 class KSPlanetBase;
0021 class KSEarthShadow;
0022 class LineList;
0023 class LineListLabel;
0024 class Satellite;
0025 class MosaicTiles;
0026 class SkipHashList;
0027 class SkyMap;
0028 class SkyObject;
0029 class SkyPoint;
0030 class Supernova;
0031 class CatalogObject;
0032 class ImageOverlay;
0033 
0034 /**
0035  * @short Draws things on the sky, without regard to backend.
0036  * This class serves as an interface to draw objects onto the sky without
0037  * worrying about whether we are using a QPainter or OpenGL.
0038  */
0039 class SkyPainter
0040 {
0041     public:
0042         SkyPainter();
0043 
0044         virtual ~SkyPainter() = default;
0045 
0046         /** @short Set the pen of the painter **/
0047         virtual void setPen(const QPen &pen) = 0;
0048 
0049         /** @short Set the brush of the painter **/
0050         virtual void setBrush(const QBrush &brush) = 0;
0051 
0052         //FIXME: find a better way to do this.
0053         void setSizeMagLimit(float sizeMagLim);
0054 
0055         /**
0056          * Begin painting.
0057          * @note this function <b>must</b> be called before painting anything.
0058          * @see end()
0059          */
0060         virtual void begin() = 0;
0061 
0062         /**
0063          * End and finalize painting.
0064          * @note this function <b>must</b> be called after painting anything.
0065          * @note it is not guaranteed that anything will actually be drawn until end() is called.
0066          * @see begin();
0067          */
0068         virtual void end() = 0;
0069 
0070         ////////////////////////////////////
0071         //                                //
0072         // SKY DRAWING FUNCTIONS:         //
0073         //                                //
0074         ////////////////////////////////////
0075 
0076         /** @short Draw the sky background */
0077         virtual void drawSkyBackground() = 0;
0078 
0079         /**
0080          * @short Draw a line between points in the sky.
0081          * @param a the first point
0082          * @param b the second point
0083          * @note this function will skip lines not on screen and clip lines
0084          * that are only partially visible.
0085          */
0086         virtual void drawSkyLine(SkyPoint *a, SkyPoint *b) = 0;
0087 
0088         /**
0089          * @short Draw a polyline in the sky.
0090          * @param list a list of points in the sky
0091          * @param skipList a SkipList object used to control skipping line segments
0092          * @param label a pointer to the label for this line
0093          * @note it's more efficient to use this than repeated calls to drawSkyLine(),
0094          * because it avoids an extra points->size() -2 projections.
0095          */
0096         virtual void drawSkyPolyline(LineList *list, SkipHashList *skipList = nullptr,
0097                                      LineListLabel *label = nullptr) = 0;
0098 
0099         /**
0100          * @short Draw a polygon in the sky.
0101          * @param list a list of points in the sky
0102          * @param forceClip If true (default), it enforces clipping of the polygon, otherwise, it draws the
0103          * complete polygen without running any boundary checks.
0104          * @see drawSkyPolyline()
0105          */
0106         virtual void drawSkyPolygon(LineList *list, bool forceClip = true) = 0;
0107 
0108         /**
0109          * @short Draw a comet in the sky.
0110          * @param com comet to draw
0111          * @return true if a comet was drawn
0112          */
0113         virtual bool drawComet(KSComet *com) = 0;
0114 
0115         /**
0116          * @short Draw an asteroid in the sky.
0117          * @param ast asteroid to draw
0118          * @return true if a asteroid was drawn
0119          */
0120         virtual bool drawAsteroid(KSAsteroid *ast) = 0;
0121 
0122         /**
0123          * @short Draw a point source (e.g., a star).
0124          * @param loc the location of the source in the sky
0125          * @param mag the magnitude of the source
0126          * @param sp the spectral class of the source
0127          * @return true if a source was drawn
0128          */
0129         virtual bool drawPointSource(const SkyPoint *loc, float mag, char sp = 'A') = 0;
0130 
0131         /**
0132         * @short Draw a deep sky object (loaded from the new implementation)
0133         * @param obj the object to draw
0134         * @param drawImage if true, try to draw the image of the object
0135         * @return true if it was drawn
0136         */
0137         virtual bool drawCatalogObject(const CatalogObject &obj) = 0;
0138 
0139         /**
0140              * @short Draw a planet
0141              * @param planet the planet to draw
0142              * @return true if it was drawn
0143              */
0144         virtual bool drawPlanet(KSPlanetBase *planet) = 0;
0145 
0146         /**
0147          * @short Draw the earths shadow on the moon (red-ish)
0148          * @param shadow the shadow to draw
0149          * @return true if it was drawn
0150          */
0151         virtual bool drawEarthShadow(KSEarthShadow *shadow) = 0;
0152 
0153         /**
0154          * @short Draw the symbols for the observing list
0155          * @param obs the observing list
0156          */
0157         virtual void drawObservingList(const QList<SkyObject *> &obs) = 0;
0158 
0159         /** @short Draw flags */
0160         virtual void drawFlags() = 0;
0161 
0162         /** @short Draw a satellite */
0163         virtual bool drawSatellite(Satellite *sat) = 0;
0164 
0165         /** @short Draw a Supernova */
0166         virtual bool drawSupernova(Supernova *sup) = 0;
0167 
0168         virtual void drawHorizon(bool filled, SkyPoint *labelPoint = nullptr,
0169                                  bool *drawLabel = nullptr) = 0;
0170 
0171         /** @short Get the width of a star of magnitude mag */
0172         float starWidth(float mag) const;
0173 
0174         /**
0175          * @short Draw a ConstellationsArt object
0176          * @param obj the object to draw
0177          * @return true if it was drawn
0178          */
0179         virtual bool drawConstellationArtImage(ConstellationsArt *obj) = 0;
0180 
0181         /**
0182          * @brief drawMosaicPanel Draws mosaic panel in planning or operation mode.
0183          * @return true if it was drawn
0184          */
0185 #ifdef HAVE_INDI
0186         virtual bool drawMosaicPanel(MosaicTiles *obj) = 0;
0187 #endif
0188         /**
0189          * @brief drawHips Draw HIPS all sky catalog
0190          * @param useCache if True, try to re-use last generated image instead of rendering a new image.
0191          * @return true if it was drawn
0192          */
0193         virtual bool drawHips(bool useCache = false) = 0;
0194 
0195         /**
0196          * @brief drawTerrain Draw the Terrain
0197          * @param useCache if True, try to re-use last generated image instead of rendering a new image.
0198          * @return true if it was drawn
0199          */
0200         virtual bool drawTerrain(bool useCache = false) = 0;
0201 
0202         /**
0203          * @brief drawImageOverlay Draws a user-supplied image onto the skymap
0204          * @param useCache if True, try to re-use last generated image instead of rendering a new image.
0205          * @return true if it was drawn
0206          */
0207         virtual bool drawImageOverlay(const QList<ImageOverlay> *imageOverlays, bool useCache = false) = 0;
0208 
0209     private:
0210         float m_sizeMagLim{ 10.0f };
0211 };