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 
47 RootNode::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 
102 void 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 
154 RootNode::~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 
185 QSGTexture *RootNode::getCachedTexture(int size, char spType)
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);
201  setFlag(QSGNode::OwnsGeometry);
202  }
203  m_clipGeometry->allocate(size);
204 
205  QSGGeometry::Point2D *vertex = m_clipGeometry->vertexDataAsPoint2D();
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();
213  markDirty(QSGNode::DirtyGeometry);
214 }
215 
216 void RootNode::update(bool clearTextures)
217 {
218  updateClipPoly();
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
223  genCachedTextures();
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 }
QSGTexture * getCachedTexture(int size, char spType)
returns cached texture from textureCache
Definition: rootnode.cpp:185
void updateClipPoly()
triangulates and sets new clipping polygon provided by Projection system
Definition: rootnode.cpp:190
void genCachedTextures()
initializes textureCache with cached images of stars from SkyMapLite
Definition: rootnode.cpp:165
QVector::iterator begin()
static StarComponent * Instance()
Definition: starcomponent.h:64
int harvardToIndex(char c)
Returns index for a Harvard spectral classification.
Definition: skymaplite.cpp:809
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
QSGTexture * createTextureFromImage(const QImage &image) const const
const QSGGeometry::AttributeSet & defaultAttributes_Point2D()
Represents Equator in SkyMapLite.
Definition: equatoritem.h:22
Class that handles Stars.
Definition: staritem.h:22
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:165
Class that handles representation of Deep Sky Objects.
Definition: deepskyitem.h:65
QVector::iterator end()
Item for displaying sky objects; also handles user interaction events.
Definition: skymaplite.h:58
void testLeakDelete()
Debug functions.
Definition: rootnode.cpp:127
int length() const const
Represents Ecliptic in SkyMapLite.
Definition: eclipticitem.h:19
Class that handles most of the lines in SkyMapLite.
Definition: linesitem.h:37
int size() const const
void update(bool clearTextures=false)
update positions of all child SkyItems
Definition: rootnode.cpp:216
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:00:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.