Kstars

labelsitem.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "Options.h"
7#include <QSGNode>
8#include "labelsitem.h"
9#include "skylabeler.h"
10#include "skynodes/labelnode.h"
11#include "skynodes/guidelabelnode.h"
12
13#include "cometsitem.h"
14#include "staritem.h"
15#include "rootnode.h"
16#include "skymesh.h"
17#include "skynodes/trixelnode.h"
18
19LabelsItem::LabelsItem() : m_rootNode(0)
20{
21 LabelTypeNode *stars = new LabelTypeNode;
22 appendChildNode(stars);
23
24 //Add trixels to hold star labels
25 int trixelNum = SkyMesh::Instance()->size();
26
27 for (int i = 0; i < trixelNum; ++i)
28 {
29 TrixelNode *trixel = new TrixelNode(i);
30 stars->appendChildNode(trixel);
31 }
32
33 m_labelsLists.insert(label_t::STAR_LABEL, stars);
34
35 LabelTypeNode *catalog_stars = new LabelTypeNode;
36 appendChildNode(catalog_stars);
37 m_labelsLists.insert(label_t::CATALOG_STAR_LABEL, catalog_stars);
38
39 LabelTypeNode *asteroids = new LabelTypeNode;
40 appendChildNode(asteroids);
41 m_labelsLists.insert(label_t::ASTEROID_LABEL, asteroids);
42
43 LabelTypeNode *comets = new LabelTypeNode;
44 appendChildNode(comets);
45 m_labelsLists.insert(label_t::COMET_LABEL, comets);
46
47 LabelTypeNode *planets = new LabelTypeNode;
48 appendChildNode(planets);
49 m_labelsLists.insert(label_t::PLANET_LABEL, planets);
50
51 LabelTypeNode *jupiter_moons = new LabelTypeNode;
52 appendChildNode(jupiter_moons);
53 m_labelsLists.insert(label_t::JUPITER_MOON_LABEL, jupiter_moons);
54
55 LabelTypeNode *saturn_moons = new LabelTypeNode;
56 appendChildNode(saturn_moons);
57 m_labelsLists.insert(label_t::SATURN_MOON_LABEL, saturn_moons);
58
59 LabelTypeNode *deep_sky = new LabelTypeNode;
60 appendChildNode(deep_sky);
61 m_labelsLists.insert(label_t::DEEP_SKY_LABEL, deep_sky);
62
63 LabelTypeNode *dso_messier = new LabelTypeNode;
64 deep_sky->appendChildNode(dso_messier);
65 m_labelsLists.insert(label_t::DSO_MESSIER_LABEL, dso_messier);
66
67 LabelTypeNode *dso_other = new LabelTypeNode;
68 deep_sky->appendChildNode(dso_other);
69 m_labelsLists.insert(label_t::DSO_OTHER_LABEL, dso_other);
70
71 LabelTypeNode *catalog_dso = new LabelTypeNode;
72 appendChildNode(catalog_dso);
73 m_labelsLists.insert(label_t::CATALOG_DSO_LABEL, catalog_dso);
74
75 LabelTypeNode *constellation = new LabelTypeNode;
76 appendChildNode(constellation);
77 m_labelsLists.insert(label_t::CONSTEL_NAME_LABEL, constellation);
78
79 LabelTypeNode *satellite = new LabelTypeNode;
80 appendChildNode(satellite);
81 m_labelsLists.insert(label_t::SATELLITE_LABEL, satellite);
82
83 LabelTypeNode *rude = new LabelTypeNode;
84 appendChildNode(rude);
85 m_labelsLists.insert(label_t::RUDE_LABEL, rude);
86
87 LabelTypeNode *num_label = new LabelTypeNode;
88 appendChildNode(num_label);
89 m_labelsLists.insert(label_t::NUM_LABEL_TYPES, num_label);
90
91 LabelTypeNode *horizon_label = new LabelTypeNode;
92 appendChildNode(horizon_label);
93 m_labelsLists.insert(label_t::HORIZON_LABEL, horizon_label);
94
95 LabelTypeNode *equator = new LabelTypeNode;
96 appendChildNode(equator);
97 m_labelsLists.insert(label_t::EQUATOR_LABEL, equator);
98
99 LabelTypeNode *ecliptic = new LabelTypeNode;
100 appendChildNode(ecliptic);
101 m_labelsLists.insert(label_t::ECLIPTIC_LABEL, ecliptic);
102
103 LabelTypeNode *telescopeSymbol = new LabelTypeNode;
104 appendChildNode(telescopeSymbol);
105 m_labelsLists.insert(label_t::TELESCOPE_SYMBOL, telescopeSymbol);
106
107 skyLabeler = SkyLabeler::Instance();
108 skyLabeler->reset();
109}
110
112{
113 LabelNode *label = new LabelNode(skyObject, labelType);
114 m_labelsLists.value(labelType)->appendChildNode(label);
115 return label;
116}
117
118LabelNode *LabelsItem::addLabel(SkyObject *skyObject, label_t labelType, Trixel trixel)
119{
120 Q_ASSERT(labelType == STAR_LABEL || labelType == DSO_MESSIER_LABEL || labelType == DSO_NGC_LABEL ||
121 labelType == DSO_IC_LABEL || labelType == DSO_OTHER_LABEL);
122 TrixelNode *triNode = static_cast<TrixelNode *>(m_labelsLists.value(labelType)->firstChild());
123 LabelNode *label = 0;
124
125 while (triNode != 0)
126 {
127 if (triNode->trixelID() == trixel)
128 {
129 label = new LabelNode(skyObject, labelType);
130 triNode->appendChildNode(label);
131 break;
132 }
133 triNode = static_cast<TrixelNode *>(triNode->nextSibling());
134 }
135 return label;
136}
137
139{
140 LabelNode *label = new LabelNode(name, labelType);
141 m_labelsLists.value(labelType)->appendChildNode(label);
142 return label;
143}
144
146{
147 GuideLabelNode *label = new GuideLabelNode(name, labelType);
148 m_labelsLists.value(labelType)->appendChildNode(label);
149 return label;
150}
151
152TrixelNode *LabelsItem::addTrixel(label_t labelType, Trixel trixel)
153{
154 TrixelNode *triNode = new TrixelNode(trixel);
155 getLabelNode(labelType)->appendChildNode(triNode);
156 return triNode;
157}
158
160{
161 SkyLabeler *skyLabeler = SkyLabeler::Instance();
162 skyLabeler->reset();
163
164 updateChildLabels(label_t::TELESCOPE_SYMBOL);
165
166 updateChildLabels(label_t::HORIZON_LABEL);
167
168 updateChildLabels(label_t::EQUATOR_LABEL);
169 updateChildLabels(label_t::ECLIPTIC_LABEL);
170
171 updateChildLabels(label_t::PLANET_LABEL);
172
173 updateChildLabels(label_t::JUPITER_MOON_LABEL);
174
175 updateChildLabels(label_t::SATURN_MOON_LABEL);
176 updateChildLabels(label_t::ASTEROID_LABEL);
177
178 updateChildLabels(label_t::COMET_LABEL);
179
180 updateChildLabels(label_t::CONSTEL_NAME_LABEL);
181
182 updateChildLabels(label_t::DSO_MESSIER_LABEL);
183 updateChildLabels(label_t::DSO_OTHER_LABEL);
184 updateChildLabels(label_t::CATALOG_DSO_LABEL);
185
186 updateChildLabels(label_t::STAR_LABEL);
187 updateChildLabels(label_t::CATALOG_STAR_LABEL);
188}
189
191{
192 if (labelType != NO_LABEL)
193 m_labelsLists[labelType]->hide();
194}
195
197{
198 if (labelType != NO_LABEL)
199 m_labelsLists[labelType]->show();
200}
201
203{
204 //Remove from previous parent if had any
205 if (m_rootNode && parent() == m_rootNode)
206 m_rootNode->removeChildNode(this);
207
208 //Append to new parent if haven't already
209 m_rootNode = rootNode;
210 if (parent() != m_rootNode)
211 m_rootNode->appendChildNode(this);
212}
213
215{
216 if (labelType == STAR_LABEL)
217 {
218 LabelTypeNode *node = m_labelsLists[labelType];
219 QSGNode *trixel = node->firstChild();
220 while (trixel != 0)
221 {
222 while (QSGNode *label = trixel->firstChild())
223 {
224 trixel->removeChildNode(label);
225 delete label;
226 }
227 trixel = trixel->nextSibling();
228 }
229 }
230 else if (labelType != NO_LABEL)
231 {
232 LabelTypeNode *node = m_labelsLists[labelType];
233 while (QSGNode *n = node->firstChild())
234 {
235 node->removeChildNode(n);
236 delete n;
237 }
238 }
239}
240
242{
243 if (label)
244 {
245 label_t type = label->labelType();
246 LabelTypeNode *node = m_labelsLists[type];
247
248 if (type == STAR_LABEL || type == DSO_IC_LABEL || type == DSO_NGC_LABEL || type == DSO_MESSIER_LABEL ||
249 type == DSO_OTHER_LABEL)
250 {
251 QSGNode *trixel = node->firstChild();
252 bool found = false;
253
254 while (trixel != 0 && !found)
255 {
256 QSGNode *l = trixel->firstChild();
257 while (l != 0)
258 {
259 if (l == label)
260 {
261 trixel->removeChildNode(label);
262 delete label;
263
264 found = true;
265 break;
266 }
267 l = l->nextSibling();
268 }
269 trixel = trixel->nextSibling();
270 }
271 }
272 else
273 {
274 QSGNode *n = node->firstChild();
275 while (n != 0)
276 {
277 if (n == label)
278 {
279 node->removeChildNode(label);
280 delete label;
281 break;
282 }
283 n = n->nextSibling();
284 }
285 }
286 }
287}
288
290{
291 LabelTypeNode *node = m_labelsLists[labelType];
292 if (node->visible())
293 {
294 QSGNode *n = node->firstChild();
295 while (n != 0)
296 {
297 if (labelType == STAR_LABEL || labelType == DSO_OTHER_LABEL)
298 {
299 TrixelNode *trixel = static_cast<TrixelNode *>(n);
300 if (trixel->visible())
301 {
302 QSGNode *l = trixel->firstChild();
303 while (l != 0)
304 {
305 LabelNode *label = static_cast<LabelNode *>(l);
306 l = l->nextSibling();
307
308 if (skyLabeler->markText(label->labelPos, label->name()))
309 {
310 label->update();
311 }
312 else
313 {
314 label->hide();
315 }
316 }
317 }
318 }
319 else
320 {
321 LabelNode *label = static_cast<LabelNode *>(n);
322
323 if (label->visible())
324 {
325 if (label->zoomFont())
326 skyLabeler->resetFont();
327 if (skyLabeler->markText(label->labelPos, label->name()))
328 {
329 label->update();
330 }
331 else
332 {
333 label->hide();
334 }
335 skyLabeler->useStdFont();
336 }
337 }
338 n = n->nextSibling();
339 }
340 }
341}
Currently this class is not used anywhere.
int size() const
returns the total number of trixels in the HTM.
Definition HTMesh.h:118
A SkyNode derived class used for displaying labels.
Definition labelnode.h:27
void update()
The order of labels update can be changed here.
LabelNode * addLabel(SkyObject *skyObject, label_t labelType)
Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds to type.
label_t
The label_t enum.
Definition labelsitem.h:62
@ NUM_LABEL_TYPES
Rude labels block other labels FIXME: find a better solution.
Definition labelsitem.h:75
void deleteLabels(label_t labelType)
deletes all labels of type labelType
void hideLabels(label_t labelType)
hides all labels of type labelType
void showLabels(label_t labelType)
shows all labels of type labelType
LabelTypeNode * getLabelNode(label_t labelType)
Definition labelsitem.h:126
LabelsItem()
Constructor.
TrixelNode * addTrixel(label_t labelType, Trixel trixel)
adds trixel to the node corresponding to labelType
void updateChildLabels(label_t labelType)
updates child labels of LabelTypeNode that corresponds to type in m_labelsLists Labels for stars and ...
RootNode * rootNode()
Definition labelsitem.h:153
void deleteLabel(LabelNode *label)
deletes particular label
GuideLabelNode * addGuideLabel(QString name, label_t labelType)
does the same as above but instead creates GuideLabelNode
void setRootNode(RootNode *rootNode)
sets m_rootNode and appends to it this node
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
The purpose of this class is to prevent labels from overlapping.
Definition skylabeler.h:99
bool markText(const QPointF &p, const QString &text, qreal padding_factor=1)
tells the labeler the location and text of a label you want to draw.
void resetFont()
sets the font in SkyLabeler and in psky back to the zoom dependent value that was set in reset().
void reset(SkyMap *skyMap)
clears the virtual screen (if needed) and resizes the virtual screen (if needed) to match skyMap.
void useStdFont()
sets the font in SkyLabeler and in psky to the font psky had originally when reset() was called.
static SkyMesh * Instance()
returns the default instance of SkyMesh or null if it has not yet been created.
Definition skymesh.cpp:39
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
A wrapper for QSGOpacityNode that provides hide() and show() functions.
Convenience class that represents trixel in SkyMapLite.
Definition trixelnode.h:21
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
QSGNode * nextSibling() const const
QSGNode * parent() const const
void removeChildNode(QSGNode *node)
NodeType type() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.