Kstars

skycomposite.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Thomas Kabelmann <thomas.kabelmann@gmx.de>
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
15
17{
18 qDeleteAll(components());
19 m_Components.clear();
20}
21
22void 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 {
55 foreach (SkyComponent *component, components())
56 component->draw(skyp);
57 }
58}
59
61{
62 foreach (SkyComponent *component, components())
63 component->update(num);
64}
65
67{
68 for (const auto &oneComponent : components())
69 {
70 auto o = oneComponent->findByName(name, exact);
71 if (o)
72 return o;
73 }
74 return nullptr;
75}
76
78{
79 if (!selected())
80 return nullptr;
81 SkyObject *oBest = nullptr;
82 foreach (SkyComponent *comp, components())
83 {
84 //qDebug() << Q_FUNC_INFO << "Checking " << typeid( *comp ).name() <<" for oBest";
85 SkyObject *oTry = comp->objectNearest(p, maxrad);
86 if (oTry)
87 {
88 oBest = oTry;
89 maxrad =
90 p->angularDistanceTo(oBest).Degrees() *
91 0.95; // Set a new maxrad, smaller than original to give priority to the earlier objects in the list.
92 // qDebug() << Q_FUNC_INFO << "oBest = " << oBest << " of type " << typeid( *oTry ).name() << "; updated maxrad = " << maxrad;
93 }
94 }
95 // qDebug() << Q_FUNC_INFO << "Returning best match: oBest = " << oBest;
96 return oBest; //will be 0 if no object nearer than maxrad was found
97}
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
SkyComponent represents an object on the sky map.
virtual void draw(SkyPainter *skyp)=0
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
virtual SkyObject * objectNearest(SkyPoint *p, double &maxrad)
Find the SkyObject nearest the given SkyPoint.
virtual void update(KSNumbers *)
Update the sky position(s) of this component.
virtual bool selected()
SkyComposite is a kind of container class for SkyComponent objects.
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...
void removeComponent(SkyComponent *const comp)
Remove a sub component from the composite comp Pointer to the SkyComponent to be removed.
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Identify the nearest SkyObject to the given SkyPoint, among the children of this SkyComposite p point...
~SkyComposite() override
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComposite for a SkyObject whose name matches the argument.
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
void update(KSNumbers *num=nullptr) override
Delegate update-position requests to all sub components.
SkyComposite(SkyComposite *parent=nullptr)
Constructor parent pointer to the parent SkyComponent.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
The sky coordinates of a point in the sky.
Definition skypoint.h:45
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=nullptr) const
Computes the angular distance between two SkyObjects.
Definition skypoint.cpp:899
const double & Degrees() const
Definition dms.h:141
iterator begin()
void clear()
iterator end()
iterator erase(const_iterator first, const_iterator last)
iterator insert(const Key &key, const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:59:52 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.