File indexing completed on 2025-02-16 03:32:46
0001 /* 0002 SPDX-FileCopyrightText: 2007 James B. Bowlin <bowlin@mindspring.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "skycomponent.h" 0010 #include "skymesh.h" 0011 0012 #include <QMutex> 0013 0014 #include <memory> 0015 #include <set> 0016 0017 class LineList; 0018 class LineListLabel; 0019 class SkipHashList; 0020 class SkyPainter; 0021 0022 /** 0023 * @class LineListIndex 0024 * Contains almost all the code needed for indexing and drawing and clipping 0025 * lines and polygons. 0026 * 0027 * @author James B. Bowlin @version 0.1 0028 */ 0029 class LineListIndex : public SkyComponent 0030 { 0031 friend class LinesItem; //Needs access to reindexLines 0032 public: 0033 /** 0034 * @short Constructor 0035 * Simply set the internal skyMesh, parent, and name. 0036 * @param parent Pointer to the parent SkyComponent object 0037 * @param name name of the subclass used for debugging 0038 */ 0039 explicit LineListIndex(SkyComposite *parent, const QString &name = ""); 0040 0041 virtual ~LineListIndex() override = default; 0042 0043 /** 0044 * @short The top level draw routine. Draws all the LineLists for any 0045 * subclass in one fell swoop which minimizes some of the loop overhead. 0046 * Overridden by MilkWay so it can decide whether to draw outlines or 0047 * filled. Therefore MilkyWay does not need to override preDraw(). The 0048 * MilkyWay draw() routine calls all of the more specific draw() 0049 * routines below. 0050 */ 0051 void draw(SkyPainter *skyp) override; 0052 0053 #ifdef KSTARS_LITE 0054 /** 0055 * @short KStars Lite needs direct access to m_lineIndex for drawing the lines 0056 */ 0057 inline LineListHash *lineIndex() const { return m_lineIndex.get(); } 0058 inline LineListHash *polyIndex() const { return m_polyIndex.get(); } 0059 0060 /** @short returns MeshIterator for currently visible trixels */ 0061 MeshIterator visibleTrixels(); 0062 0063 #endif 0064 //Moved to public because KStars Lite uses it 0065 /** 0066 * @short this is called from within the draw routines when the updateID 0067 * of the lineList is stale. It is virtual because different subclasses 0068 * have different update routines. NoPrecessIndex doesn't precess in 0069 * the updates and ConstellationLines must update its points as stars, 0070 * not points. that doesn't precess the points. 0071 */ 0072 virtual void JITupdate(LineList *lineList); 0073 0074 protected: 0075 /** 0076 * @short as the name says, recreates the lineIndex using the LineLists 0077 * in the previous index. Since we are indexing everything at J2000 0078 * this is only used by ConstellationLines which needs to reindex 0079 * because of the proper motion of the stars. 0080 */ 0081 void reindexLines(); 0082 0083 /** @short retrieve name of object */ 0084 QString name() const { return m_name; } 0085 0086 /** 0087 * @short displays a message that we are loading m_name. Also prints 0088 * out the message if skyMesh debug is greater than zero. 0089 */ 0090 void intro(); 0091 0092 /** 0093 * @short prints out some summary statistics if the skyMesh debug is 0094 * greater than 1. 0095 */ 0096 void summary(); 0097 0098 /** @short Returns the SkyMesh object. */ 0099 SkyMesh *skyMesh() { return m_skyMesh; } 0100 0101 /** 0102 * @short Typically called from within a subclasses constructors. 0103 * Adds the trixels covering the outline of lineList to the lineIndex. 0104 */ 0105 void appendLine(const std::shared_ptr<LineList> &lineList); 0106 0107 void removeLine(const std::shared_ptr<LineList> &lineList); 0108 0109 /** 0110 * @short Typically called from within a subclasses constructors. 0111 * Adds the trixels covering the full lineList to the polyIndex. 0112 */ 0113 void appendPoly(const std::shared_ptr<LineList> &lineList); 0114 0115 /** 0116 * @short a convenience method that adds a lineList to both the lineIndex and the polyIndex. 0117 */ 0118 void appendBoth(const std::shared_ptr<LineList> &lineList); 0119 0120 /** 0121 * @short Draws all the lines in m_listList as simple lines in float mode. 0122 */ 0123 void drawLines(SkyPainter *skyp); 0124 0125 /** 0126 * @short Draws all the lines in m_listList as filled polygons in float 0127 * mode. 0128 */ 0129 void drawFilled(SkyPainter *skyp); 0130 0131 /** 0132 * @short Gives the subclasses access to the top of the draw() method. 0133 * Typically used for setting the QPen, etc. in the QPainter being 0134 * passed in. Defaults to setting a thin white pen. 0135 */ 0136 virtual void preDraw(SkyPainter *skyp); 0137 0138 /** 0139 * @short a callback overridden by NoPrecessIndex so it can use the 0140 * drawing code with the non-reverse-precessed mesh buffer. 0141 */ 0142 virtual MeshBufNum_t drawBuffer() { return DRAW_BUF; } 0143 0144 /** 0145 * @short Returns an IndexHash from the SkyMesh that contains the set of 0146 * trixels that cover lineList. Overridden by SkipListIndex so it can 0147 * pass SkyMesh an IndexHash indicating which line segments should not 0148 * be indexed @param lineList contains the list of points to be covered. 0149 */ 0150 virtual const IndexHash &getIndexHash(LineList *lineList); 0151 0152 /** 0153 * @short Also overridden by SkipListIndex. 0154 * Controls skipping inside of the draw() routines. The default behavior 0155 * is to simply return a null pointer. 0156 * 0157 * FIXME: I don't think that the SkipListIndex class even exists -- hdevalence 0158 */ 0159 virtual SkipHashList *skipList(LineList *lineList); 0160 0161 virtual LineListLabel *label() { return nullptr; } 0162 0163 inline LineListList listList() const { return m_listList; } 0164 0165 private: 0166 QString m_name; 0167 0168 SkyMesh *m_skyMesh { nullptr }; 0169 std::unique_ptr<LineListHash> m_lineIndex; 0170 std::unique_ptr<LineListHash> m_polyIndex; 0171 0172 LineListList m_listList; 0173 0174 QMutex mutex; 0175 };