Kstars

skymapcomposite.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Thomas Kabelmann <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "skymapcomposite.h"
8 
9 #include "artificialhorizoncomponent.h"
10 #include "catalogsdb.h"
11 #include "constellationartcomponent.h"
12 #include "constellationboundarylines.h"
13 #include "constellationlines.h"
14 #include "constellationnamescomponent.h"
15 #include "culturelist.h"
16 #include "deepstarcomponent.h"
17 #include "catalogscomponent.h"
18 #include "ecliptic.h"
19 #include "equator.h"
20 #include "equatorialcoordinategrid.h"
21 #include "horizoncomponent.h"
22 #include "horizontalcoordinategrid.h"
23 #include "localmeridiancomponent.h"
24 #include "ksasteroid.h"
25 #include "kscomet.h"
26 #include <kmessagebox.h>
27 #ifndef KSTARS_LITE
28 #include "kstars.h"
29 #endif
30 #include "kstarsdata.h"
31 #include "milkyway.h"
32 #include "satellitescomponent.h"
33 #include "skylabeler.h"
34 #include "skypainter.h"
35 #include "solarsystemcomposite.h"
36 #include "starcomponent.h"
37 #include "supernovaecomponent.h"
38 #include "targetlistcomponent.h"
39 #include "projections/projector.h"
40 #include "skyobjects/ksplanet.h"
41 #include "skyobjects/constellationsart.h"
42 
43 #ifndef KSTARS_LITE
44 #include "flagcomponent.h"
45 #include "ksutils.h"
46 #include "observinglist.h"
47 #include "skymap.h"
48 #include "hipscomponent.h"
49 #include "terraincomponent.h"
50 #include "imageoverlaycomponent.h"
51 #include "mosaiccomponent.h"
52 #endif
53 
54 #include <QApplication>
55 
56 #include <kstars_debug.h>
57 
59  : SkyComposite(parent), m_reindexNum(J2000)
60 {
61  m_skyLabeler.reset(SkyLabeler::Instance());
62  m_skyMesh = SkyMesh::Create(3); // level 5 mesh = 8192 trixels
63  m_skyMesh->debug(0);
64  // 1 => print "indexing ..."
65  // 2 => prints totals too
66  // 10 => prints detailed lists
67  // You can also set the debug level of individual
68  // appendLine() and appendPoly() calls.
69 
70  //Add all components
71  //Stars must come before constellation lines
72 #ifdef KSTARS_LITE
73  addComponent(m_MilkyWay = new MilkyWay(this), 50);
74  addComponent(m_Stars = StarComponent::Create(this), 10);
75  addComponent(m_EquatorialCoordinateGrid = new EquatorialCoordinateGrid(this));
76  addComponent(m_HorizontalCoordinateGrid = new HorizontalCoordinateGrid(this));
77 
78  // Do add to components.
79  addComponent(m_CBoundLines = new ConstellationBoundaryLines(this), 80);
80  m_Cultures.reset(new CultureList());
81  addComponent(m_CLines = new ConstellationLines(this, m_Cultures.get()), 85);
82  addComponent(m_CNames = new ConstellationNamesComponent(this, m_Cultures.get()), 90);
83  addComponent(m_Equator = new Equator(this), 95);
84  addComponent(m_Ecliptic = new Ecliptic(this), 95);
85  addComponent(m_Horizon = new HorizonComponent(this), 100);
87  m_ConstellationArt = new ConstellationArtComponent(this, m_Cultures.get()), 100);
88 
89  addComponent(m_ArtificialHorizon = new ArtificialHorizonComponent(this), 110);
90 
91  QStringList allcatalogs = Options::showCatalogNames();
92 
93  Options::setShowCatalogNames(allcatalogs);
94 
95  addComponent(m_SolarSystem = new SolarSystemComposite(this), 2);
96 
97  //addComponent( m_ObservingList = new TargetListComponent( this , 0, QPen(),
98  // &Options::obsListSymbol, &Options::obsListText ), 120 );
99  addComponent(m_StarHopRouteList = new TargetListComponent(this, 0, QPen()), 130);
100  addComponent(m_Satellites = new SatellitesComponent(this), 7);
101  addComponent(m_Supernovae = new SupernovaeComponent(this), 7);
102  SkyMapLite::Instance()->loadingFinished();
103 #else
104  addComponent(m_MilkyWay = new MilkyWay(this), 50);
105  addComponent(m_Stars = StarComponent::Create(this), 10);
106  addComponent(m_EquatorialCoordinateGrid = new EquatorialCoordinateGrid(this));
107  addComponent(m_HorizontalCoordinateGrid = new HorizontalCoordinateGrid(this));
108  addComponent(m_LocalMeridianComponent = new LocalMeridianComponent(this));
109 
110  // Do add to components.
111  addComponent(m_CBoundLines = new ConstellationBoundaryLines(this), 80);
112  m_Cultures.reset(new CultureList());
113  addComponent(m_CLines = new ConstellationLines(this, m_Cultures.get()), 85);
114  addComponent(m_CNames = new ConstellationNamesComponent(this, m_Cultures.get()), 90);
115  addComponent(m_Equator = new Equator(this), 95);
116  addComponent(m_Ecliptic = new Ecliptic(this), 95);
117  addComponent(m_Horizon = new HorizonComponent(this), 100);
118 
119  const auto &path = CatalogsDB::dso_db_path();
120  try
121  {
122  addComponent(m_Catalogs = new CatalogsComponent(this, path, !QFile::exists(path)),
123  5);
124  }
125  catch (const CatalogsDB::DatabaseError &e)
126  {
127  KMessageBox::detailedError(nullptr, i18n("Failed to load the DSO database."),
128  e.what());
129 
130  const auto &backup_path =
131  QString("%1.%2").arg(path).arg(QDateTime::currentDateTime().toTime_t());
132 
133  const auto &answer = KMessageBox::questionYesNo(
134  nullptr,
135  i18n("Do you want to start over with an empty database?\n"
136  "This will move the current DSO database \"%1\"\n"
137  "to \"%2\"",
138  path, backup_path),
139  "Start over?");
140 
141  if (answer == KMessageBox::Yes)
142  {
143  QFile::rename(path, backup_path);
144  addComponent(m_Catalogs = new CatalogsComponent(this, path, true), 5);
145  }
146  else
147  {
148  KStars::Instance()->close();
149  }
150  }
151 
152  addComponent(
153  m_ConstellationArt = new ConstellationArtComponent(this, m_Cultures.get()), 100);
154 
155  // Hips
156  addComponent(m_HiPS = new HIPSComponent(this));
157 
158  addComponent(m_Terrain = new TerrainComponent(this));
159 
160  addComponent(m_ImageOverlay = new ImageOverlayComponent(this));
161 
162  // Mosaic Component
163 #ifdef HAVE_INDI
164  addComponent(m_Mosaic = new MosaicComponent(this));
165 #endif
166 
167  addComponent(m_ArtificialHorizon = new ArtificialHorizonComponent(this), 110);
168 
169  addComponent(m_SolarSystem = new SolarSystemComposite(this), 2);
170 
171  addComponent(m_Flags = new FlagComponent(this), 4);
172 
173  addComponent(m_ObservingList = new TargetListComponent(this, nullptr, QPen(),
174  &Options::obsListSymbol,
175  &Options::obsListText),
176  120);
177  addComponent(m_StarHopRouteList = new TargetListComponent(this, nullptr, QPen()),
178  130);
179  addComponent(m_Satellites = new SatellitesComponent(this), 7);
180  addComponent(m_Supernovae = new SupernovaeComponent(this), 7);
181 #endif
182  connect(this, SIGNAL(progressText(QString)), KStarsData::Instance(),
183  SIGNAL(progressText(QString)));
184 }
185 
187 {
188  //printf("updating SkyMapComposite\n");
189  //1. Milky Way
190  //m_MilkyWay->update( data, num );
191  //2. Coordinate grid
192  //m_EquatorialCoordinateGrid->update( num );
193  m_HorizontalCoordinateGrid->update(num);
194 #ifndef KSTARS_LITE
195  m_LocalMeridianComponent->update(num);
196 #endif
197  //3. Constellation boundaries
198  //m_CBounds->update( data, num );
199  //4. Constellation lines
200  //m_CLines->update( data, num );
201  //5. Constellation names
202  if (m_CNames)
203  m_CNames->update(num);
204  //6. Equator
205  //m_Equator->update( data, num );
206  //7. Ecliptic
207  //m_Ecliptic->update( data, num );
208  //8. Deep sky
209  //m_DeepSky->update( data, num );
210  //10. Stars
211  //m_Stars->update( data, num );
212  //m_CLines->update( data, num ); // MUST follow stars.
213 
214  //12. Solar system
215  m_SolarSystem->update(num);
216  //13. Satellites
217  m_Satellites->update(num);
218  //14. Supernovae
219  m_Supernovae->update(num);
220  //15. Horizon
221  m_Horizon->update(num);
222 #ifndef KSTARS_LITE
223  //16. Flags
224  m_Flags->update(num);
225 #endif
226 }
227 
229 {
230  m_SolarSystem->updateSolarSystemBodies(num);
231 }
232 
234 {
235  m_SolarSystem->updateMoons(num);
236 }
237 
238 //Reimplement draw function so that we have control over the order of
239 //elements, and we can add object labels
240 //
241 //The order in which components are drawn naturally determines the
242 //z-ordering (the layering) of the components. Objects which
243 //should appear "behind" others should be drawn first.
245 {
246  Q_UNUSED(skyp)
247 #ifndef KSTARS_LITE
248  SkyMap *map = SkyMap::Instance();
249  KStarsData *data = KStarsData::Instance();
250 
251  // We delay one draw cycle before re-indexing
252  // we MUST ensure CLines do not get re-indexed while we use DRAW_BUF
253  // so we do it here.
254  m_CLines->reindex(&m_reindexNum);
255  // This queues re-indexing for the next draw cycle
256  m_reindexNum = KSNumbers(data->updateNum()->julianDay());
257 
258  // This ensures that the JIT updates are synchronized for the entire draw
259  // cycle so the sky moves as a single sheet. May not be needed.
260  data->syncUpdateIDs();
261 
262  // prepare the aperture
263  // FIXME_FOV: We may want to rejigger this to allow
264  // wide-angle views --hdevalence
265  float radius = map->projector()->fov();
266  if (radius > 180.0)
267  radius = 180.0;
268 
269  if (m_skyMesh->inDraw())
270  {
271  printf("Warning: aborting concurrent SkyMapComposite::draw()\n");
272  return;
273  }
274 
275  m_skyMesh->inDraw(true);
276  SkyPoint *focus = map->focus();
277  m_skyMesh->aperture(focus, radius + 1.0, DRAW_BUF); // divide by 2 for testing
278 
279  // create the no-precess aperture if needed
280  if (Options::showEquatorialGrid() || Options::showHorizontalGrid() ||
281  Options::showCBounds() || Options::showEquator())
282  {
283  m_skyMesh->index(focus, radius + 1.0, NO_PRECESS_BUF);
284  }
285 
286  // clear marks from old labels and prep fonts
287  m_skyLabeler->reset(map);
288  m_skyLabeler->useStdFont();
289 
290  // info boxes have highest label priority
291  // FIXME: REGRESSION. Labeler now know nothing about infoboxes
292  // map->infoBoxes()->reserveBoxes( psky );
293 
294  // JM 2016-12-01: Why is this done this way?!! It's too inefficient
295  if (KStars::Instance())
296  {
297  auto &obsList = KStarsData::Instance()->observingList()->sessionList();
298 
299  if (Options::obsListText())
300  for (auto &obj_clone : obsList)
301  {
302  // Find the "original" obj
303  SkyObject *o = findByName(
304  obj_clone->name()); // FIXME: This is slow.... and can also fail!!!
305  if (!o)
306  continue;
307  SkyLabeler::AddLabel(o, SkyLabeler::RUDE_LABEL);
308  }
309  }
310 
311  m_MilkyWay->draw(skyp);
312 
313  // Draw HIPS after milky way but before everything else
314  m_HiPS->draw(skyp);
315 
316  m_EquatorialCoordinateGrid->draw(skyp);
317  m_HorizontalCoordinateGrid->draw(skyp);
318  m_LocalMeridianComponent->draw(skyp);
319 
320  //Draw constellation boundary lines only if we draw western constellations
321  if (m_Cultures->current() == "Western")
322  {
323  m_CBoundLines->draw(skyp);
324  m_ConstellationArt->draw(skyp);
325  }
326  else if (m_Cultures->current() == "Inuit")
327  {
328  m_ConstellationArt->draw(skyp);
329  }
330 
331  m_CLines->draw(skyp);
332 
333  m_Equator->draw(skyp);
334 
335  m_Ecliptic->draw(skyp);
336 
337  m_Catalogs->draw(skyp);
338 
339  m_Stars->draw(skyp);
340 
341  m_SolarSystem->drawTrails(skyp);
342  m_SolarSystem->draw(skyp);
343 
344  m_Satellites->draw(skyp);
345 
346  m_Supernovae->draw(skyp);
347 
348  map->drawObjectLabels(labelObjects());
349 
350  m_skyLabeler->drawQueuedLabels();
351  m_CNames->draw(skyp);
352  m_Stars->drawLabels();
353 
354  m_ObservingList->pen =
355  QPen(QColor(data->colorScheme()->colorNamed("ObsListColor")), 1.);
356  m_ObservingList->list2 = KStarsData::Instance()->observingList()->sessionList();
357  m_ObservingList->draw(skyp);
358 
359  m_Flags->draw(skyp);
360 
361  m_StarHopRouteList->pen =
362  QPen(QColor(data->colorScheme()->colorNamed("StarHopRouteColor")), 1.);
363  m_StarHopRouteList->draw(skyp);
364 
365  // Draw fits overlay before mosaic and terrain/horizon, but after most things.
366  m_ImageOverlay->draw(skyp);
367 
368 #ifdef HAVE_INDI
369  m_Mosaic->draw(skyp);
370 #endif
371 
372  m_ArtificialHorizon->draw(skyp);
373 
374  m_Horizon->draw(skyp);
375 
376  m_skyMesh->inDraw(false);
377 
378  // Draw terrain at the end.
379  m_Terrain->draw(skyp);
380 
381  // DEBUG Edit. Keywords: Trixel boundaries. Currently works only in QPainter mode
382  // -jbb uncomment these to see trixel outlines:
383  /*
384  QPainter *psky = dynamic_cast< QPainter *>( skyp );
385  if( psky ) {
386  qCDebug(KSTARS) << "Drawing trixel boundaries for debugging.";
387  psky->setPen( QPen( QBrush( QColor( "yellow" ) ), 1, Qt::SolidLine ) );
388  m_skyMesh->draw( *psky, OBJ_NEAREST_BUF );
389  SkyMesh *p;
390  if( p = SkyMesh::Instance( 6 ) ) {
391  qCDebug(KSTARS) << "We have a deep sky mesh to draw";
392  p->draw( *psky, OBJ_NEAREST_BUF );
393  }
394 
395  psky->setPen( QPen( QBrush( QColor( "green" ) ), 1, Qt::SolidLine ) );
396  m_skyMesh->draw( *psky, NO_PRECESS_BUF );
397  if( p )
398  p->draw( *psky, NO_PRECESS_BUF );
399  }
400  */
401 #endif
402 }
403 
404 //Select nearest object to the given skypoint, but give preference
405 //to certain object types.
406 //we multiply each object type's smallest angular distance by the
407 //following factors before selecting the final nearest object:
408 // faint stars > 12th mag = 1.75
409 // stars > 4 and < 12 = 1.5
410 // stars brighter than 4th mag = 0.75
411 // custom object = 0.5
412 // Solar system = 0.25
414 {
415  double rTry = maxrad;
416  double rBest = maxrad;
417  SkyObject *oTry = nullptr;
418  SkyObject *oBest = nullptr;
419 
420  //printf("%.1f %.1f\n", p->ra().Degrees(), p->dec().Degrees() );
421  m_skyMesh->aperture(p, maxrad + 1.0, OBJ_NEAREST_BUF);
422 
423  oBest = m_Stars->objectNearest(p, rBest);
424  //reduce rBest by 0.75 for stars brighter than 4th mag
425  if (oBest && oBest->mag() < 4.0)
426  rBest *= 0.75;
427  // For stars fainter than 12th mag
428  else if (oBest && oBest->mag() > 12.0)
429  rBest *= 2.00;
430  // For stars between 4th and 12th mag
431  else if (oBest)
432  rBest *= 2.5;
433 
434  oTry = m_Satellites->objectNearest(p, rTry);
435  if (rTry < rBest)
436  {
437  rBest = rTry;
438  oBest = oTry;
439  }
440 
441  for (auto &star : m_DeepStars)
442  {
443  rTry = maxrad;
444  oTry = star->objectNearest(p, rTry);
445  if (rTry < rBest)
446  {
447  rBest = rTry;
448  oBest = oTry;
449  }
450  }
451 
452  rTry = maxrad;
453  oTry = m_Catalogs->objectNearest(p, rTry);
454  if (oTry && rTry < rBest)
455  {
456  rBest = rTry;
457  oBest = oTry;
458  }
459 
460  rTry = maxrad;
461  oTry = m_Supernovae->objectNearest(p, rTry);
462  //qCDebug(KSTARS)<<rTry<<rBest<<maxrad;
463  if (rTry < rBest)
464  {
465  rBest = rTry;
466  oBest = oTry;
467  }
468 
469  rTry = maxrad;
470  oTry = m_SolarSystem->objectNearest(p, rTry);
471  if (!dynamic_cast<KSComet *>(oTry) &&
472  !dynamic_cast<KSAsteroid *>(
473  oTry)) // There are gazillions of faint asteroids and comets; we want to prevent them from getting precedence
474  {
475  rTry *=
476  0.25; // this is either sun, moon, or one of the major planets or their moons.
477  }
478  else
479  {
480  if (std::isfinite(oTry->mag()) && oTry->mag() < 12.0)
481  {
482  rTry *= 0.75; // Bright comets / asteroids get some precedence.
483  }
484  }
485  if (rTry < rBest)
486  {
487  rBest = rTry;
488  oBest = oTry;
489  }
490 
491  //if ( oBest && Options::verboseLogging())
492  //qCDebug(KSTARS) << "OBEST=" << oBest->name() << " - " << oBest->name2();
493  maxrad = rBest;
494  return oBest; //will be 0 if no object nearer than maxrad was found
495 }
496 
498 {
499  double rtry = maxrad;
500  SkyObject *star = nullptr;
501 
502  m_skyMesh->aperture(p, maxrad + 1.0, OBJ_NEAREST_BUF);
503 
504  star = m_Stars->objectNearest(p, rtry);
505  //reduce rBest by 0.75 for stars brighter than 4th mag
506  if (star && star->mag() < 4.0)
507  rtry *= 0.75;
508 
509  // TODO: Add Deep Star Catalog support
510 
511  maxrad = rtry;
512  return star;
513 }
514 
515 bool SkyMapComposite::addNameLabel(SkyObject *o)
516 {
517  if (!o)
518  return false;
519  labelObjects().append(o);
520  return true;
521 }
522 
523 bool SkyMapComposite::removeNameLabel(SkyObject *o)
524 {
525  if (!o)
526  return false;
527  int index = labelObjects().indexOf(o);
528  if (index < 0)
529  return false;
530  labelObjects().removeAt(index);
531  return true;
532 }
533 
534 QHash<int, QStringList> &SkyMapComposite::getObjectNames()
535 {
536  return m_ObjectNames;
537 }
538 
539 QHash<int, QVector<QPair<QString, const SkyObject *>>> &SkyMapComposite::getObjectLists()
540 {
541  return m_ObjectLists;
542 }
543 
545  const SkyPoint &p2)
546 {
547  const SkyRegion &region = m_skyMesh->skyRegion(p1, p2);
548  QList<SkyObject *> list;
549  // call objectsInArea( QList<SkyObject*>&, const SkyRegion& ) for each of the
550  // components of the SkyMapComposite
551  if (m_Stars->selected())
552  m_Stars->objectsInArea(list, region);
553  if (m_Catalogs->selected())
554  m_Catalogs->objectsInArea(list, region);
555  return list;
556 }
557 
559 {
560 #ifndef KSTARS_LITE
561  if (KStars::Closing)
562  return nullptr;
563 #endif
564 
565  //We search the children in an "intelligent" order (most-used
566  //object types first), in order to avoid wasting too much time
567  //looking for a match. The most important part of this ordering
568  //is that stars should be last (because the stars list is so long)
569  SkyObject *o = nullptr;
570  o = m_SolarSystem->findByName(name);
571  if (o)
572  return o;
573  o = m_Catalogs->findByName(name, exact);
574  if (o)
575  return o;
576  o = m_CNames->findByName(name);
577  if (o)
578  return o;
579  o = m_Stars->findByName(name);
580  if (o)
581  return o;
582  o = m_Supernovae->findByName(name);
583  if (o)
584  return o;
585  o = m_Satellites->findByName(name);
586  if (o)
587  return o;
588 
589  return nullptr;
590 }
591 
592 SkyObject *SkyMapComposite::findStarByGenetiveName(const QString name)
593 {
594  return m_Stars->findStarByGenetiveName(name);
595 }
596 
597 KSPlanetBase *SkyMapComposite::planet(int n)
598 {
599  if (n == KSPlanetBase::SUN)
600  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Sun"))));
601  if (n == KSPlanetBase::MERCURY)
602  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Mercury"))));
603  if (n == KSPlanetBase::VENUS)
604  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Venus"))));
605  if (n == KSPlanetBase::MOON)
606  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Moon"))));
607  if (n == KSPlanetBase::MARS)
608  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Mars"))));
609  if (n == KSPlanetBase::JUPITER)
610  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Jupiter"))));
611  if (n == KSPlanetBase::SATURN)
612  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Saturn"))));
613  if (n == KSPlanetBase::URANUS)
614  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Uranus"))));
615  if (n == KSPlanetBase::NEPTUNE)
616  return dynamic_cast<KSPlanetBase *>((m_SolarSystem->findByName(i18n("Neptune"))));
617  //if ( n == KSPlanetBase::PLUTO ) return (KSPlanetBase*)(m_SolarSystem->findByName( i18n( "Pluto" ) ) );
618 
619  return nullptr;
620 }
621 
622 void SkyMapComposite::reloadCLines()
623 {
624 #ifndef KSTARS_LITE
625  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
627  true); // This is not (yet) multithreaded, so I think we don't have to worry about overwriting the state of an existing lock --asimha
628  removeComponent(m_CLines);
629  delete m_CLines;
630  addComponent(m_CLines = new ConstellationLines(this, m_Cultures.get()));
632 #endif
633 }
634 
635 void SkyMapComposite::reloadCNames()
636 {
637  // Q_ASSERT( !SkyMapDrawAbstract::drawLock() );
638  // SkyMapDrawAbstract::setDrawLock( true ); // This is not (yet) multithreaded, so I think we don't have to worry about overwriting the state of an existing lock --asimha
639  // objectNames(SkyObject::CONSTELLATION).clear();
640  // delete m_CNames;
641  // m_CNames = 0;
642  // m_CNames = new ConstellationNamesComponent( this, m_Cultures.get() );
643  // SkyMapDrawAbstract::setDrawLock( false );
644  objectNames(SkyObject::CONSTELLATION).clear();
645  objectLists(SkyObject::CONSTELLATION).clear();
646  removeComponent(m_CNames);
647  delete m_CNames;
648  addComponent(m_CNames = new ConstellationNamesComponent(this, m_Cultures.get()));
649 }
650 
651 void SkyMapComposite::reloadConstellationArt()
652 {
653 #ifndef KSTARS_LITE
654  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
656  removeComponent(m_ConstellationArt);
657  delete m_ConstellationArt;
658  addComponent(m_ConstellationArt =
659  new ConstellationArtComponent(this, m_Cultures.get()));
661 #endif
662 }
663 
664 void SkyMapComposite::reloadDeepSky()
665 {
666 #ifndef KSTARS_LITE
667  Q_ASSERT(!SkyMapDrawAbstract::drawLock());
668 
669  // Deselect object if selected! If not deselected then InfoBox tries to
670  // get the name of an object which may not exist (getLongName)
671  // FIXME (spacetime): Is there a better way?
672  // Current Solution: Look for the nearest star in the region and select it.
673 
674  SkyMap *current_map = KStars::Instance()->map();
675  double maxrad = 30.0;
676  SkyPoint center_point = current_map->getCenterPoint();
677 
678  current_map->setClickedObject(
679  KStars::Instance()->data()->skyComposite()->starNearest(&center_point, maxrad));
680  current_map->setClickedPoint(current_map->clickedObject());
681  current_map->slotCenter();
682 
683  // Remove and Regenerate set of catalog objects
684  //
685  // FIXME: Why should we do this? Because it messes up observing
686  // list really bad to delete and regenerate SkyObjects.
688 
689  // FIXME: We should also reload anything that refers to SkyObject
690  // * in memory, because all the old SkyObjects are now gone! This
691  // includes the observing list. Otherwise, expect a bad, bad crash
692  // that is hard to debug! -- AS
693  m_Catalogs->dropCache();
695 #endif
696 }
697 
698 bool SkyMapComposite::isLocalCNames()
699 {
700  return m_CNames->isLocalCNames();
701 }
702 
704 {
705  emit progressText(message);
706 #ifndef Q_OS_ANDROID
707  //Can cause crashes on Android, investigate it
708  qApp->processEvents(); // -jbb: this seemed to make it work.
709 #endif
710  //qCDebug(KSTARS) << QString("PROGRESS TEXT: %1\n").arg( message );
711 }
712 
713 const QList<SkyObject *> &SkyMapComposite::constellationNames() const
714 {
715  return m_CNames->objectList();
716 }
717 
718 // Returns only named stars, and should not be used
719 const QList<SkyObject *> &SkyMapComposite::stars() const
720 {
721  return m_Stars->objectList();
722 }
723 
724 const QList<SkyObject *> &SkyMapComposite::asteroids() const
725 {
726  return m_SolarSystem->asteroids();
727 }
728 
729 const QList<SkyObject *> &SkyMapComposite::comets() const
730 {
731  return m_SolarSystem->comets();
732 }
733 
734 const QList<SkyObject *> &SkyMapComposite::supernovae() const
735 {
736  return m_Supernovae->objectList();
737 }
738 
739 QList<SkyObject *> SkyMapComposite::planets()
740 {
741  return solarSystemComposite()->planetObjects();
742 }
743 
744 //Store it permanently
745 /*
746 QList<SkyObject*> SkyMapComposite::moons()
747 {
748  QList<SkyObject*> skyObjects;
749  foreach(PlanetMoonsComponent *pMoons, m_SolarSystem->planetMoonsComponent()) {
750  PlanetMoons *moons = pMoons->getMoons();
751  for(int i = 0; i < moons->nMoons(); ++i) {
752  skyObjects.append(moons->moon(i));
753  }
754  }
755  return skyObjects;
756 }
757 */
758 
759 const QList<SkyObject *> *SkyMapComposite::getSkyObjectsList(SkyObject::TYPE t)
760 {
761  switch (t)
762  {
763  case SkyObject::STAR:
764  return &m_Stars->objectList();
765  case SkyObject::CATALOG_STAR:
766  return nullptr;
767  case SkyObject::PLANET:
768  return &m_SolarSystem->planetObjects();
769  case SkyObject::COMET:
770  return &comets();
771  case SkyObject::ASTEROID:
772  return &asteroids();
773  case SkyObject::MOON:
774  return &m_SolarSystem->moons();
775  case SkyObject::GALAXY:
776  case SkyObject::PLANETARY_NEBULA:
777  case SkyObject::GASEOUS_NEBULA:
778  case SkyObject::GLOBULAR_CLUSTER:
779  case SkyObject::OPEN_CLUSTER:
780  return nullptr;
781  case SkyObject::CONSTELLATION:
782  return &constellationNames();
783  case SkyObject::SUPERNOVA:
784  return &supernovae();
785  default:
786  return nullptr;
787  }
788  //return nullptr;
789 }
790 
791 KSPlanet *SkyMapComposite::earth()
792 {
793  return m_SolarSystem->earth();
794 }
795 
796 QStringList SkyMapComposite::getCultureNames()
797 {
798  return m_Cultures->getNames();
799 }
800 
801 QString SkyMapComposite::getCultureName(int index)
802 {
803  return m_Cultures->getName(index);
804 }
805 
806 void SkyMapComposite::setCurrentCulture(QString culture)
807 {
808  m_Cultures->setCurrent(culture);
809 }
810 
811 QString SkyMapComposite::currentCulture()
812 {
813  return m_Cultures->current();
814 }
815 #ifndef KSTARS_LITE
816 FlagComponent *SkyMapComposite::flags()
817 {
818  return m_Flags;
819 }
820 #endif
821 
822 SatellitesComponent *SkyMapComposite::satellites()
823 {
824  return m_Satellites;
825 }
826 
827 SupernovaeComponent *SkyMapComposite::supernovaeComponent()
828 {
829  return m_Supernovae;
830 }
831 
832 ArtificialHorizonComponent *SkyMapComposite::artificialHorizon()
833 {
834  return m_ArtificialHorizon;
835 }
836 
837 ImageOverlayComponent *SkyMapComposite::imageOverlay()
838 {
839  return m_ImageOverlay;
840 }
void append(const T &value)
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComposite for a SkyObject whose name matches the argument.
void update(KSNumbers *) override
Update the sky position(s) of this component.
void draw(SkyPainter *skyp) override
Draw this component by iterating over the list.
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
void update(KSNumbers *num=nullptr) override
Update the sky positions of this component.
void update(KSNumbers *num) override
Update satellites position.
static void AddLabel(SkyObject *obj, label_t type)
static version of addLabel() below.
Definition: skylabeler.h:135
QDateTime currentDateTime()
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
bool rename(const QString &newName)
void drawTrails(SkyPainter *skyp) override
Draw trails for objects.
void setClickedPoint(const SkyPoint *f)
Set the ClickedPoint to the skypoint given as an argument.
Definition: skymap.cpp:1011
void update(KSNumbers *) override
Update the sky position(s) of this component.
void aperture(SkyPoint *center, double radius, MeshBufNum_t bufNum=DRAW_BUF)
finds the set of trixels that cover the circular aperture specified after first performing a reverse ...
Definition: skymesh.cpp:56
void clear()
A subclass of KSPlanetBase that implements asteroids.
Definition: ksasteroid.h:41
void update(KSNumbers *num) override
Delegate update-position requests to all sub components.
A subclass of KSPlanetBase that implements comets.
Definition: kscomet.h:43
SkyObject * clickedObject() const
Retrieve the object nearest to a mouse click event.
Definition: skymap.h:244
float mag() const
Definition: skyobject.h:206
SkyMap * map() const
Definition: kstars.h:141
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
void addComponent(SkyComponent *comp, int priority=1024)
Add a new sub component to the composite comp Pointer to the SkyComponent to be added priority A prio...
Class that handles drawing of MilkyWay (both filled and non-filled)
Definition: milkyway.h:24
QList< SkyObject * > findObjectsInArea(const SkyPoint &p1, const SkyPoint &p2)
bool close()
void objectsInArea(QList< SkyObject * > &list, const SkyRegion &region) override
Searches the region(s) and appends the SkyObjects found to the list of sky objects.
static StarComponent * Create(SkyComposite *)
Create an instance of StarComponent.
bool exists() const const
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void draw(SkyPainter *skyp) override
The top level draw routine.
Definition: milkyway.cpp:57
void emitProgressText(const QString &message) override
Emit signal about progress.
void removeAt(int i)
static KStars * Instance()
Definition: kstars.h:123
void updateMoons(KSNumbers *num) override
Delegate moon position updates to the SolarSystemComposite.
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
void update(KSNumbers *) override
Update the sky position(s) of this component.
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument.
bool selected() override
Wether to show the DSOs.
QString i18n(const char *text, const TYPE &arg...)
bool isLocalCNames()
Return true if we are using localized constellation names.
void update(KSNumbers *num=nullptr) override
Update the sky position(s) of this component.
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Definition: equator.cpp:59
void draw(SkyPainter *skyp) override
void loadingFinished()
called when SkyMapComposite finished loading all SkyComponents
Definition: skymaplite.h:301
int indexOf(const T &value, int from) const const
ColorScheme * colorScheme()
Definition: kstarsdata.h:172
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
long double julianDay() const
Definition: ksnumbers.h:91
void update(KSNumbers *num) override
we need a custom routine (for now) so we don't precess the locations of the names.
void setClickedObject(SkyObject *o)
Set the ClickedObject pointer to the argument.
Definition: skymap.cpp:363
void draw(SkyPainter *skyp) override
Draws the objects in the currently visible trixels by dynamically loading them from the database.
void removeComponent(SkyComponent *const comp)
Remove a sub component from the composite comp Pointer to the SkyComponent to be removed.
void updateSolarSystemBodies(KSNumbers *num) override
Delegate planet position updates to the SolarSystemComposite.
void draw(SkyPainter *skyp) override
Draw constellation names on the sky map.
void update(KSNumbers *num=nullptr) override
Delegate update-position requests to all sub components.
Draws things on the sky, without regard to backend.
Definition: skypainter.h:39
void draw(SkyPainter *skyp) override
Draw the Horizon on the Sky map.
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Provides necessary information about objects in the solar system.
Definition: ksplanet.h:32
void draw(SkyPainter *skyp) override
The top level draw routine.
void slotCenter()
Center the display at the point ClickedPoint.
Definition: skymap.cpp:377
void draw(SkyPainter *skyp) override
Draw all satellites.
const SkyRegion & skyRegion(const SkyPoint &p1, const SkyPoint &p2)
returns the sky region needed to cover the rectangle defined by two SkyPoints p1 and p2
Definition: skymesh.cpp:312
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
bool selected() override
static bool Closing
Set to true when the application is being closed.
Definition: kstars.h:841
int debug() const
Returns the debug level.
Definition: skymesh.h:255
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
void detailedError(QWidget *parent, const QString &text, const QString &details, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Highlights objects present in certain lists by drawing "target" symbols around them.
This class encapsulates Supernovae.
Canvas widget for displaying the sky bitmap; also handles user interaction events.
Definition: skymap.h:53
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComponent for a SkyObject whose name matches the argument name the nam...
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Search the nearest satellite from point p.
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Definition: ecliptic.cpp:57
void drawLabels()
draw all the labels in the prioritized LabelLists and then clear the LabelLists.
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Identify the nearest SkyObject to the given SkyPoint, among the children of this SkyComposite p point...
void objectsInArea(QList< SkyObject * > &list, const SkyRegion &region) override
Searches the region(s) and appends the SkyObjects found to the list of sky objects.
SkyMapComposite(SkyComposite *parent=nullptr)
Constructor parent pointer to the parent SkyComponent.
QPen pen
Pen to use to draw.
Represents objects loaded from an sqlite backed, trixel indexed catalog.
Represents a flag on the sky map. Each flag is composed by a SkyPoint where coordinates are stored,...
Definition: flagcomponent.h:33
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
SkyObject * findByName(const QString &name, bool exact=true) override
Search the underlying database for an object with the name.
Trixel index(const SkyPoint *p)
returns the index of the trixel containing p.
Definition: skymesh.cpp:74
ButtonCode questionYesNo(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Notify)
SkyObject * starNearest(SkyPoint *p, double &maxrad)
SkyObject * findByName(const QString &name, bool exact=true) override
Return object given name.
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:87
void dropCache()
Clear the internal cache and effectively reload all objects from the database.
Information about an object in the sky.
Definition: skyobject.h:41
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
static SkyMesh * Create(int level)
creates the single instance of SkyMesh.
Definition: skymesh.cpp:25
QObject * parent() const const
static void setDrawLock(bool state)
Acquire / release a draw lock.
QString message
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Provides necessary information about objects in the solar system.
Definition: ksplanetbase.h:49
QList< QSharedPointer< SkyObject > > list2
Pointer to list of objects to draw.
Database related error, thrown when database access fails or an action does not succeed.
Definition: catalogsdb.h:687
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Dec 5 2023 03:58:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.