Kstars

rootnode.cpp
1#include <QSGTexture>
2#include <QQuickWindow>
3
4#include "rootnode.h"
5#include "skymaplite.h"
6#include "projections/projector.h"
7#include "skymapcomposite.h"
8#include "solarsystemcomposite.h"
9#include "Options.h"
10
11#include "constellationboundarylines.h"
12#include "constellationlines.h"
13#include "starcomponent.h"
14
15#include "horizontalcoordinategrid.h"
16#include "equatorialcoordinategrid.h"
17
18#include "ecliptic.h"
19#include "equator.h"
20
21//SkyItems
22#include "kstarslite/skyitems/staritem.h"
23#include "kstarslite/skyitems/deepskyitem.h"
24#include "kstarslite/skyitems/planetsitem.h"
25#include "kstarslite/skyitems/asteroidsitem.h"
26#include "kstarslite/skyitems/cometsitem.h"
27#include "kstarslite/skyitems/horizonitem.h"
28#include "kstarslite/skyitems/lines/linesitem.h"
29#include "kstarslite/skyitems/labelsitem.h"
30#include "kstarslite/skyitems/constellationnamesitem.h"
31#include "kstarslite/skyitems/constellationartitem.h"
32#include "kstarslite/skyitems/satellitesitem.h"
33#include "kstarslite/skyitems/supernovaeitem.h"
34
35//Lines
36#include "kstarslite/skyitems/lines/equatoritem.h"
37#include "kstarslite/skyitems/lines/eclipticitem.h"
38#include "kstarslite/skyitems/lines/milkywayitem.h"
39
40//Symbols
41#include "kstarslite/skyitems/telescopesymbolsitem.h"
42
43#include "kstarslite/skyitems/fovitem.h"
44
45#include <QSGFlatColorMaterial>
46
47RootNode::RootNode() : m_skyMapLite(SkyMapLite::Instance())
48 {
49 SkyMapLite::setRootNode(this);
50 genCachedTextures();
51
52 m_skyComposite = KStarsData::Instance()->skyComposite();
53
54 // LabelsItem needs to be created first so that other items could insert their labels in labelsList
55 m_labelsItem = new LabelsItem();
56
57 m_MWItem = new MilkyWayItem(m_skyComposite->milkyWay(), this);
58
59 m_linesItem = new LinesItem(this);
60
61 m_linesItem->addLinesComponent(m_skyComposite->equatorialCoordGrid(), "EquatorialGridColor", 1, Qt::DotLine);
62 m_linesItem->addLinesComponent(m_skyComposite->horizontalCoordGrid(), "HorizontalGridColor", 2, Qt::DotLine);
63
64 if (m_skyComposite->currentCulture() == "Western")
65 {
66 m_linesItem->addLinesComponent(m_skyComposite->constellationBoundary(), "CBoundColor", 1, Qt::SolidLine);
67 }
68
69 m_artItem = new ConstellationArtItem(m_skyComposite->constellationArt(), this);
70
71 m_linesItem->addLinesComponent(m_skyComposite->constellationLines(), "CLineColor", 1, Qt::SolidLine);
72
73 m_equator = new EquatorItem(m_skyComposite->equator(), this);
74 m_ecliptic = new EclipticItem(m_skyComposite->ecliptic(), this);
75
76 m_dsoItem = new DeepSkyItem(m_skyComposite->deepSkyComponent(), this);
77 m_starItem = new StarItem(StarComponent::Instance(), this);
78
79 m_solarSystem = m_skyComposite->solarSystemComposite();
80
81 m_planetsItem = new PlanetsItem(m_solarSystem->planets(), /* m_solarSystem->planetMoonsComponent(),*/ this);
82 m_asteroidsItem = new AsteroidsItem(m_solarSystem->asteroids(), this);
83 m_cometsItem = new CometsItem(m_solarSystem->comets(), this);
84
85 m_constelNamesItem = new ConstellationNamesItem(m_skyComposite->constellationNamesComponent(), this);
86
87 m_satItem = new SatellitesItem(m_skyComposite->satellites(), this);
88 m_snovaItem = new SupernovaeItem(m_skyComposite->supernovaeComponent(), this);
89
90 m_horizonItem = new HorizonItem(m_skyComposite->horizon(), this);
91
92 m_FOVItem = new FOVItem(this);
93
94 m_telescopeSymbols = new TelescopeSymbolsItem(this);
95
96 setIsRectangular(false);
97 updateClipPoly();
98
99 m_labelsItem->setRootNode(this);
100}
101
102void RootNode::testLeakAdd()
103{
104 /* m_linesItem = new LinesItem(this);
105
106 m_linesItem->addLinesComponent( m_skyComposite->equatorialCoordGrid(), "EquatorialGridColor", 1, Qt::DotLine );
107 m_linesItem->addLinesComponent( m_skyComposite->horizontalCoordGrid(), "HorizontalGridColor", 2, Qt::DotLine );
108
109 m_linesItem->addLinesComponent( m_skyComposite->constellationBoundary(), "CBoundColor", 1, Qt::SolidLine );
110 m_linesItem->addLinesComponent( m_skyComposite->constellationLines(), "CLineColor", 1, Qt::SolidLine );
111
112 m_starItem = new StarItem(m_skyComposite->starComponent(), this);
113
114 m_solarSystem = m_skyComposite->solarSystemComposite();
115
116 m_equator = new EquatorItem(m_skyComposite->equator(),this);
117 m_ecliptic = new EclipticItem(m_skyComposite->ecliptic(),this);
118
119 m_planetsItem = new PlanetsItem(m_solarSystem->planets(), m_solarSystem->planetMoonsComponent(), this);
120 m_asteroidsItem = new AsteroidsItem(m_solarSystem->asteroids(), this);
121 m_cometsItem = new CometsItem(m_solarSystem->comets(), this);
122
123 m_constelNamesItem = new ConstellationNamesItem(m_skyComposite->constellationNamesComponent(), this);
124 m_horizonItem = new HorizonItem(m_skyComposite->horizon(), this);*/
125}
126
128{
129 /*removeChildNode(m_linesItem);
130 delete m_linesItem;
131
132 removeChildNode(m_starItem);
133 delete m_starItem;
134
135 removeChildNode(m_equator);
136 delete m_equator;
137 removeChildNode(m_ecliptic);
138 delete m_ecliptic;
139
140 removeChildNode(m_planetsItem);
141 delete m_planetsItem;
142 removeChildNode(m_asteroidsItem);
143 delete m_asteroidsItem;
144 removeChildNode(m_cometsItem);
145 delete m_cometsItem;
146
147 removeChildNode(m_constelNamesItem);
148 delete m_constelNamesItem;
149
150 removeChildNode(m_horizonItem);
151 delete m_horizonItem;*/
152}
153
154RootNode::~RootNode()
155{
156 for (int i = 0; i < m_textureCache.length(); ++i)
157 {
158 for (int c = 0; c < m_textureCache[i].size(); ++c)
159 {
160 delete m_textureCache[i][c];
161 }
162 }
163}
164
166{
167 QVector<QVector<QPixmap *>> images = m_skyMapLite->getImageCache();
168
169 QQuickWindow *win = m_skyMapLite->window();
170
171 m_textureCache = QVector<QVector<QSGTexture *>>(images.length());
172
173 for (int i = 0; i < m_textureCache.length(); ++i)
174 {
175 int length = images[i].length();
176 m_textureCache[i] = QVector<QSGTexture *>(length);
177 for (int c = 1; c < length; ++c)
178 {
179 m_textureCache[i][c] =
180 win->createTextureFromImage(images[i][c]->toImage(), QQuickWindow::TextureCanUseAtlas);
181 }
182 }
183}
184
186{
187 return m_textureCache[SkyMapLite::Instance()->harvardToIndex(spType)][size];
188}
189
191{
192 QPolygonF newClip = m_skyMapLite->projector()->clipPoly();
193 m_clipPoly = newClip;
194
195 const int size = m_clipPoly.size();
196 if (!m_clipGeometry)
197 {
198 m_clipGeometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), size);
199 m_clipGeometry->setDrawingMode(GL_TRIANGLE_FAN);
200 setGeometry(m_clipGeometry);
202 }
203 m_clipGeometry->allocate(size);
204
206 for (int i = 0; i < size; i++)
207 {
208 vertex[i].x = m_clipPoly[i].x();
209 vertex[i].y = m_clipPoly[i].y();
210 }
211 m_clipGeometry->markIndexDataDirty();
212 m_clipGeometry->markVertexDataDirty();
214}
215
216void RootNode::update(bool clearTextures)
217{
219 if (clearTextures)
220 {
221 //First we need to create new textures and only after all PointNodes changed their textures we
222 //can delete old textures
224 }
225
226 m_MWItem->update();
227
228 m_artItem->update();
229
230 m_linesItem->update();
231
232 m_equator->update();
233 m_ecliptic->update();
234
235 m_dsoItem->update();
236 m_starItem->update();
237
238 //TODO: Move this check somewhere else (create a separate function)
239 if (Options::showSolarSystem())
240 {
241 m_planetsItem->update();
242 if (!Options::showAsteroids())
243 {
244 if (m_asteroidsItem)
245 delete m_asteroidsItem;
246 }
247 else
248 {
249 if (!m_asteroidsItem)
250 m_asteroidsItem = new AsteroidsItem(m_solarSystem->asteroids(), this);
251 m_asteroidsItem->update();
252 }
253
254 if (!Options::showComets())
255 {
256 if (m_cometsItem)
257 delete m_cometsItem;
258 }
259 else
260 {
261 if (!m_cometsItem)
262 m_cometsItem = new CometsItem(m_solarSystem->comets(), this);
263 m_cometsItem->update();
264 }
265 }
266 else
267 {
268 m_planetsItem->hide();
269 if (m_asteroidsItem)
270 {
271 delete m_asteroidsItem;
272 m_asteroidsItem = 0;
273 }
274 if (m_cometsItem)
275 {
276 delete m_cometsItem;
277 m_cometsItem = 0;
278 }
279 }
280
281 m_constelNamesItem->update();
282
283 m_satItem->update();
284 m_snovaItem->update();
285 m_horizonItem->update();
286
287 m_telescopeSymbols->update();
288 m_labelsItem->update();
289
290 m_FOVItem->update();
291
292 if (clearTextures)
293 {
294 //Delete old textures
295 if (m_oldTextureCache.length())
296 {
297 foreach (QVector<QSGTexture *> textures, m_oldTextureCache)
298 {
299 qDeleteAll(textures.begin(), textures.end());
300 }
301 }
302 }
303}
This class handles asteroids in SkyMapLite.
virtual void update() override
Determines the visibility of the object and its label and hides/updates them accordingly.
This class handles comets in SkyMapLite.
Definition cometsitem.h:20
virtual void update() override
Determines the visibility of the object and its label and hides/updates them accordingly.
This class handles constellation art in SkyMapLite.
void update() override
calls update() of all child ConstellationArtNodes if constellation art is on.
This class represents ConstellationNamesComponent in SkyMapLite.
virtual void update()
Update positions ConstellationName labels based on user settings and labels visibility.
Class that handles representation of Deep Sky Objects.
Definition deepskyitem.h:66
virtual void update()
Call update on all DSOIndexNodes (catalogs)
Represents Ecliptic in SkyMapLite.
virtual void update() override
updates positions of lines and compass labels
Represents Equator in SkyMapLite.
Definition equatoritem.h:23
virtual void update()
updates positions of lines and compass labels
This class handles representation of FOV symbols in SkyMapLite.
Definition fovitem.h:18
virtual void update() override
Update FOVSymbol if user switched it on.
Definition fovitem.cpp:27
Handles representation of HorizonComponent in SkyMapLite (lines, filled polygon and compass labels).
Definition horizonitem.h:23
virtual void update()
Call update() of HorizonNode and update/hide compass labels based on their visibility.
This class is in charge of labels in SkyMapLite.
Definition labelsitem.h:53
void update()
The order of labels update can be changed here.
Class that handles lines (Constellation lines and boundaries and both coordinate grids) in SkyMapLite...
Definition linesitem.h:38
virtual void update()
updates all trixels that are associated with LineListIndex or hide them if selected() of this LineLis...
Definition linesitem.cpp:72
This class handles planets and their moons in SkyMapLite.
Definition planetsitem.h:22
void update() override
calls update() of all child PlanetMoonsNodes
virtual void hide() override
hides this item and labels for all moons (currently only Jupiter moons.
void update(bool clearTextures=false)
update positions of all child SkyItems
Definition rootnode.cpp:216
void genCachedTextures()
initializes textureCache with cached images of stars from SkyMapLite
Definition rootnode.cpp:165
void updateClipPoly()
triangulates and sets new clipping polygon provided by Projection system
Definition rootnode.cpp:190
QSGTexture * getCachedTexture(int size, char spType)
returns cached texture from textureCache
Definition rootnode.cpp:185
void testLeakDelete()
Debug functions.
Definition rootnode.cpp:127
This class handles representation of satellites in SkyMapLite.
virtual void update() override
Update positions and visibility of satellites.
This is the main item that displays all SkyItems.
Definition skymaplite.h:59
const Projector * projector() const
Get the current projector.
Definition skymaplite.h:323
QVector< QVector< QPixmap * > > getImageCache()
returns cache of star images
static StarComponent * Instance()
Class that handles Stars.
Definition staritem.h:23
virtual void update()
Update positions of nodes that represent stars In this function we perform almost the same thing as i...
Definition staritem.cpp:68
This class handles supernovae in SkyMapLite.
virtual void update() override
Update positions and visibility of supernovae.
This class handles representation of telescope symbols in SkyMapLite.
virtual void update() override
Updates position and visibility of CrosshairNodes that represent telescope symbols If client is no mo...
qsizetype size() const const
QQuickWindow * window() const const
QSGTexture * createTextureFromImage(const QImage &image) const const
void setGeometry(QSGGeometry *geometry)
void allocate(int vertexCount, int indexCount)
const AttributeSet & defaultAttributes_Point2D()
void markIndexDataDirty()
void markVertexDataDirty()
void setDrawingMode(unsigned int mode)
Point2D * vertexDataAsPoint2D()
void markDirty(DirtyState bits)
void setFlag(Flag f, bool enabled)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.