Kstars

skycomposite.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Thomas Kabelmann <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "skycomposite.h"
8 
9 #include "skyobjects/skyobject.h"
10 #include <qdebug.h>
11 
13 {
14 }
15 
17 {
18  qDeleteAll(components());
19  m_Components.clear();
20 }
21 
22 void SkyComposite::addComponent(SkyComponent *component, int priority)
23 {
24  //qDebug() << Q_FUNC_INFO << "Adding sky component " << component << " of type " << typeid( *component ).name() << " with priority " << priority;
25  m_Components.insert(priority, component);
26  /*
27  foreach( SkyComponent *p, components() ) {
28  qDebug() << Q_FUNC_INFO << "List now has: " << p << " of type " << typeid( *p ).name();
29  }
30  */
31 }
32 
34 {
35  // qDebug() << Q_FUNC_INFO << "Removing sky component " << component << " of type " << typeid( *component ).name();
37  for (it = m_Components.begin(); it != m_Components.end();)
38  {
39  if (it.value() == component)
40  it = m_Components.erase(it);
41  else
42  ++it;
43  }
44  /*
45  foreach( SkyComponent *p, components() ) {
46  qDebug() << Q_FUNC_INFO << "List now has: " << p << " of type " << typeid( *p ).name();
47  }
48  */
49 }
50 
52 {
53  if (selected())
54  foreach (SkyComponent *component, components())
55  component->draw(skyp);
56 }
57 
59 {
60  foreach (SkyComponent *component, components())
61  component->update(num);
62 }
63 
64 SkyObject *SkyComposite::findByName(const QString &name, bool exact)
65 {
66  for (const auto &oneComponent : components())
67  {
68  SkyObject *o = oneComponent->findByName(name, exact);
69  if (o)
70  return o;
71  }
72  return nullptr;
73 }
74 
76 {
77  if (!selected())
78  return nullptr;
79  SkyObject *oBest = nullptr;
80  foreach (SkyComponent *comp, components())
81  {
82  //qDebug() << Q_FUNC_INFO << "Checking " << typeid( *comp ).name() <<" for oBest";
83  SkyObject *oTry = comp->objectNearest(p, maxrad);
84  if (oTry)
85  {
86  oBest = oTry;
87  maxrad =
88  p->angularDistanceTo(oBest).Degrees() *
89  0.95; // Set a new maxrad, smaller than original to give priority to the earlier objects in the list.
90  // qDebug() << Q_FUNC_INFO << "oBest = " << oBest << " of type " << typeid( *oTry ).name() << "; updated maxrad = " << maxrad;
91  }
92  }
93  // qDebug() << Q_FUNC_INFO << "Returning best match: oBest = " << oBest;
94  return oBest; //will be 0 if no object nearer than maxrad was found
95 }
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComposite for a SkyObject whose name matches the argument.
virtual SkyObject * objectNearest(SkyPoint *p, double &maxrad)
Find the SkyObject nearest the given SkyPoint.
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
virtual void draw(SkyPainter *skyp)=0
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
virtual void update(KSNumbers *)
Update the sky position(s) of this component.
Definition: skycomponent.h:126
~SkyComposite() override
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...
SkyComposite(SkyComposite *parent=nullptr)
Constructor parent pointer to the parent SkyComponent.
virtual bool selected()
Definition: skycomponent.h:131
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
void update(KSNumbers *num=nullptr) override
Delegate update-position requests to all sub components.
void removeComponent(SkyComponent *const comp)
Remove a sub component from the composite comp Pointer to the SkyComponent to be removed.
Draws things on the sky, without regard to backend.
Definition: skypainter.h:37
typename QMap< Key, T >::iterator insert(const Key &key, const T &value)
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=nullptr) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:899
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
const double & Degrees() const
Definition: dms.h:141
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Identify the nearest SkyObject to the given SkyPoint, among the children of this SkyComposite p point...
Information about an object in the sky.
Definition: skyobject.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:04:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.