Commit 4c02dbca authored by Artem Fedoskin's avatar Artem Fedoskin
Browse files

Added labels for planets, asteroids, comets and stars

parent 1aa79365
......@@ -553,6 +553,8 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/cometsitem.cpp
kstarslite/skyitems/horizonitem.cpp
kstarslite/skyitems/linesitem.cpp
kstarslite/skyitems/labelsitem.cpp
kstarslite/skyitems/constellationnamesitem.cpp
#SkyNodes
kstarslite/skyitems/skynodes/planetnode.cpp
kstarslite/skyitems/skynodes/skynode.cpp
......@@ -560,6 +562,8 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/skynodes/planetmoonsnode.cpp
kstarslite/skyitems/skynodes/horizonnode.cpp
kstarslite/skyitems/skynodes/trixelnode.cpp
kstarslite/skyitems/skynodes/labelnode.cpp
kstarslite/skyitems/skynodes/guidelabelnode.cpp
#Nodes
kstarslite/skyitems/skynodes/nodes/pointnode.cpp
kstarslite/skyitems/skynodes/nodes/polynode.cpp
......
......@@ -24,65 +24,54 @@
#include "skynodes/pointsourcenode.h"
#include "kstarslite/skyitems/rootnode.h"
#include "labelsitem.h"
AsteroidsItem::AsteroidsItem(const QList<SkyObject*>& asteroidsList, RootNode *rootNode)
:SkyItem(rootNode), m_asteroidsList(asteroidsList)
:SkyItem(LabelsItem::label_t::ASTEROID_LABEL, rootNode), m_asteroidsList(asteroidsList)
{
recreateList();
}
/*void AsteroidsItem::setAsteroidsList(QList<SkyObject*> *asteroidsList) {
m_asteroidsList = asteroidsList;
m_addAsteroids = true;
}*/
void AsteroidsItem::recreateList() {
removeAllChildNodes();
foreach(SkyObject *asteroid, m_asteroidsList) {
KSAsteroid *ast = static_cast<KSAsteroid *>(asteroid);
if (ast->image().isNull() == false) {
appendChildNode(new PlanetNode(ast, rootNode()));
}
else {
appendChildNode(new PointSourceNode(ast, rootNode()));
} else {
appendChildNode(new PointSourceNode(ast, rootNode(),labelType()));
}
}
}
void AsteroidsItem::update() {
if (!Options::showAsteroids()) {
removeAllChildNodes();
hide();
return;
} else if (!childCount()) {
recreateList();
}
show();
QSGNode *n = firstChild();
while(n != 0) {
SkyNode* pNode = static_cast<SkyNode*>(n);
n = n->nextSibling();
//bool hideLabels = ! Options::showAsteroidNames() ||
//( SkyMapLite::Instance()->isSlewing() && Options::hideLabels() );
bool hideLabels = ! Options::showAsteroidNames() ||
( SkyMapLite::Instance()->isSlewing() && Options::hideLabels() );
/*double lgmin = log10(MINZOOM);
double lgmin = log10(MINZOOM);
double lgmax = log10(MAXZOOM);
double lgz = log10(Options::zoomFactor());
double labelMagLimit = 2.5 + Options::asteroidLabelDensity() / 5.0;
labelMagLimit += ( 15.0 - labelMagLimit ) * ( lgz - lgmin) / (lgmax - lgmin );
if ( labelMagLimit > 10.0 ) labelMagLimit = 10.0;
//printf("labelMagLim = %.1f\n", labelMagLimit );*/
//printf("labelMagLim = %.1f\n", labelMagLimit );
KSAsteroid *ast = static_cast<KSAsteroid *>(pNode->skyObject());
bool drawLabel = false;
if ( ast->mag() > Options::magLimitAsteroid() || std::isnan(ast->mag()) != 0) {
pNode->hide();
continue;
}
//bool drawn = false;
pNode->update();
//if ( drawn && !( hideLabels || ast->mag() >= labelMagLimit ) )
// SkyLabeler::AddLabel( ast, SkyLabeler::ASTEROID_LABEL );
if (!( hideLabels || ast->mag() >= labelMagLimit ) ) {
drawLabel = true;
}
pNode->update(drawLabel);
}
}
......@@ -20,37 +20,38 @@
#include "projections/projector.h"
#include "kscomet.h"
#include "rootnode.h"
#include "labelsitem.h"
#include "skylabeler.h"
#include "skynodes/pointsourcenode.h"
CometsItem::CometsItem(const QList<SkyObject*>& cometsList, RootNode *rootNode)
:SkyItem(rootNode), m_cometsList(cometsList)
:SkyItem(LabelsItem::label_t::COMET_LABEL, rootNode), m_cometsList(cometsList)
{
recreateList();
}
void CometsItem::update() {
if (!Options::showComets() || Options::zoomFactor() < 10*MINZOOM ) {
removeAllChildNodes();
if(Options::zoomFactor() < 10*MINZOOM) {
hide();
return;
} else if (!childCount()) {
show();
recreateList();
}
show();
/*bool hideLabels = ! Options::showCometNames() ||
(SkyMap::Instance()->isSlewing() &&
bool hideLabels = ! Options::showCometNames() ||
(SkyMapLite::Instance()->isSlewing() &&
Options::hideLabels() );
double rsunLabelLimit = Options::maxRadCometName();
//FIXME: Should these be config'able?
/*//FIXME: Should these be config'able?
skyp->setPen( QPen( QColor( "darkcyan" ) ) );
skyp->setBrush( QBrush( QColor( "darkcyan" ) ) );*/
//Traverse all children nodes
QSGNode *n = firstChild();
while( n!= 0) {
while( n != 0) {
SkyNode* skyNode = static_cast<SkyNode*>(n);
n = n->nextSibling();
......@@ -59,10 +60,11 @@ void CometsItem::update() {
double mag = com->mag();
if (std::isnan(mag) == 0)
{
skyNode->update();
//bool drawn = skyp->drawPointSource(com,mag);
//if ( drawn && !(hideLabels || com->rsun() >= rsunLabelLimit) )
// SkyLabeler::AddLabel( com, SkyLabeler::COMET_LABEL );
bool drawLabel = false;
if ( !(hideLabels || com->rsun() >= rsunLabelLimit) ) {
drawLabel = true;
}
skyNode->update(drawLabel);
} else {
skyNode->hide();
}
......@@ -73,6 +75,6 @@ void CometsItem::recreateList() {
removeAllChildNodes();
foreach(SkyObject *comet, m_cometsList) {
KSComet *com = static_cast<KSComet *>(comet);
appendChildNode(new PointSourceNode(com,rootNode()));
appendChildNode(new PointSourceNode(com, rootNode(),labelType()));
}
}
/** *************************************************************************
constellationnamesitem.cpp - K Desktop Planetarium
-------------------
begin : 10/06/2016
copyright : (C) 2016 by Artem Fedoskin
email : afedoskin3@gmail.com
***************************************************************************/
/** *************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "constellationnamesitem.h"
#include "constellationnamescomponent.h"
ConstellationNamesItem::ConstellationNamesItem(const QList<SkyObject*>& namesList, RootNode* parent)
:SkyItem(LabelsItem::label_t::CONSTEL_NAME_LABEL, parent), m_namesList(namesList)
{
}
void ConstellationNamesItem::update() {
/*if ( ! selected() )
return;
const Projector *proj = SkyMap::Instance()->projector();
SkyLabeler* skyLabeler = SkyLabeler::Instance();
skyLabeler->useStdFont();
skyLabeler->setPen( QColor( KStarsData::Instance()->colorScheme()->colorNamed( "CNameColor" ) ) );
QString name;
foreach(SkyObject *p, m_ObjectList) {
if( ! proj->checkVisibility( p ) )
continue;
bool visible = false;
QPointF o = proj->toScreen( p, false, &visible );
if( !visible || !proj->onScreen( o ) )
continue;
if( Options::useLatinConstellNames() || Options::useLocalConstellNames() )
name = p->name();
else
name = p->name2();
o.setX( o.x() - 5.0 * name.length() );
skyLabeler->drawGuideLabel( o, name, 0.0 );
}
skyLabeler->resetFont();*/
}
void ConstellationNamesItem::recreateList() {
removeAllChildNodes();
/*foreach(SkyObject *comet, m_namesList) {
appendChildNode(new PointSourceNode(com, rootNode(),labelType()));
}*/
}
/** *************************************************************************
constellationnamesitem.h - K Desktop Planetarium
-------------------
begin : 10/06/2016
copyright : (C) 2016 by Artem Fedoskin
email : afedoskin3@gmail.com
***************************************************************************/
/** *************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef CONSTELLATIONNAMESITEM_H_
#define CONSTELLATIONNAMESITEM_H_
#include <QSGOpacityNode>
#include "skyitem.h"
class ConstellationNamesComponent;
/** @class SkyItem
*
*This is an interface for implementing SkyItems that are used to display SkyComponent
*derived objects on the SkyMapLite.
*
*@short A base class that is used for displaying SkyComponents on SkyMapLite.
*@author Artem Fedoskin
*@version 1.0
*/
class ConstellationNamesItem : public SkyItem {
public:
/**
*Constructor, add SkyItem to parent in a node tree
*
* @param parent a pointer to SkyItem's parent node
*/
explicit ConstellationNamesItem(const QList<SkyObject*>& namesList, RootNode *rootNode = 0);
virtual void update();
void hide();
void show();
void recreateList();
private:
const QList<SkyObject*>& m_namesList;
};
#endif
......@@ -18,9 +18,10 @@
#include "horizoncomponent.h"
#include "skynodes/horizonnode.h"
#include "labelsitem.h"
HorizonItem::HorizonItem(HorizonComponent * hComp, RootNode *rootNode)
:SkyItem(rootNode), m_horizonComp(hComp)
:SkyItem(LabelsItem::label_t::RUDE_LABEL, rootNode), m_horizonComp(hComp)
{
appendChildNode(new HorizonNode(m_horizonComp->pointList()));
}
......
/** *************************************************************************
labelsitem.cpp - K Desktop Planetarium
-------------------
begin : 09/06/2016
copyright : (C) 2016 by Artem Fedoskin
email : afedoskin3@gmail.com
***************************************************************************/
/** *************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "Options.h"
#include <QSGNode>
#include "labelsitem.h"
#include "skylabeler.h"
#include "skynodes/labelnode.h"
#include "cometsitem.h"
#include "rootnode.h"
LabelsItem::LabelsItem(RootNode *rootNode)
:m_rootNode(rootNode)
{
LabelTypeNode *stars = new LabelTypeNode;
appendChildNode(stars);
labelsLists.insert(label_t::STAR_LABEL, stars);
LabelTypeNode *asteroids = new LabelTypeNode;
appendChildNode(asteroids);
labelsLists.insert(label_t::ASTEROID_LABEL, asteroids);
LabelTypeNode *comets = new LabelTypeNode;
appendChildNode(comets);
labelsLists.insert(label_t::COMET_LABEL, comets);
LabelTypeNode *planets = new LabelTypeNode;
appendChildNode(planets);
labelsLists.insert(label_t::PLANET_LABEL, planets);
LabelTypeNode *jupiter_moons = new LabelTypeNode;
appendChildNode(jupiter_moons);
labelsLists.insert(label_t::JUPITER_MOON_LABEL, jupiter_moons);
LabelTypeNode *saturn_moons = new LabelTypeNode;
appendChildNode(saturn_moons);
labelsLists.insert(label_t::SATURN_MOON_LABEL, saturn_moons);
LabelTypeNode *deep_sky = new LabelTypeNode;
appendChildNode(deep_sky);
labelsLists.insert(label_t::DEEP_SKY_LABEL, deep_sky);
LabelTypeNode *constellation = new LabelTypeNode;
appendChildNode(constellation);
labelsLists.insert(label_t::CONSTEL_NAME_LABEL, constellation);
LabelTypeNode *satellite = new LabelTypeNode;
appendChildNode(satellite);
labelsLists.insert(label_t::SATELLITE_LABEL, satellite);
LabelTypeNode *rude = new LabelTypeNode;
appendChildNode(rude);
labelsLists.insert(label_t::RUDE_LABEL, rude);
LabelTypeNode *num_label = new LabelTypeNode;
appendChildNode(num_label);
labelsLists.insert(label_t::NUM_LABEL_TYPES, num_label);
}
LabelNode *LabelsItem::addLabel(SkyObject *skyObject, label_t type) {
LabelNode *label = new LabelNode(skyObject, type);
labelsLists.value(type)->appendChildNode(label);
return label;
}
void LabelsItem::update() {
SkyLabeler * skyLabeler = SkyLabeler::Instance();
skyLabeler->reset();
updateChildLabels(label_t::PLANET_LABEL);
updateChildLabels(label_t::SATURN_MOON_LABEL);
updateChildLabels(label_t::JUPITER_MOON_LABEL);
updateChildLabels(label_t::ASTEROID_LABEL);
if(rootNode()->cometsItem()->visible()) {
updateChildLabels(label_t::COMET_LABEL);
} else {
hideLabels(label_t::COMET_LABEL);
}
}
void LabelsItem::hideLabels(label_t type) {
QSGOpacityNode *node = labelsLists[type];
node->setOpacity(0);
node->markDirty(QSGNode::DirtyOpacity);
}
void LabelsItem::deleteLabels(label_t type) {
QSGOpacityNode *node = labelsLists[type];
QSGNode *n = node->firstChild();
while( n != 0) {
delete n;
n = n->nextSibling();
}
node->removeAllChildNodes();
}
void LabelsItem::updateChildLabels(label_t type) {
QSGOpacityNode *node = labelsLists[type];
node->setOpacity(1);
node->markDirty(QSGNode::DirtyOpacity);
QSGNode *n = node->firstChild();
while( n != 0) {
LabelNode *label = static_cast<LabelNode *>(n);
if(label->visible()) {
if(SkyLabeler::Instance()->markText(label->labelPos, label->skyObject()->name())) {
label->update();
} else {
label->hide();
}
}
n = n->nextSibling();
}
}
/** *************************************************************************
asteroidsitem.h - K Desktop Planetarium
-------------------
begin : 16/05/2016
copyright : (C) 2016 by Artem Fedoskin
email : afedoskin3@gmail.com
***************************************************************************/
/** *************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef LABELSITEM_H_
#define LABELSITEM_H_
#include "skylabeler.h"
#include <QSGOpacityNode>
typedef QSGOpacityNode LabelTypeNode;
class KSAsteroid;
class LineListIndex;
class LabelNode;
class SkyObject;
class RootNode;
class LabelsItem : public QSGOpacityNode {
public:
LabelsItem(RootNode *rootNode);
enum label_t {
STAR_LABEL,
ASTEROID_LABEL,
COMET_LABEL,
PLANET_LABEL,
JUPITER_MOON_LABEL,
SATURN_MOON_LABEL,
DEEP_SKY_LABEL,
CONSTEL_NAME_LABEL,
SATELLITE_LABEL,
RUDE_LABEL, ///Rude labels block other labels FIXME: find a better solution
NUM_LABEL_TYPES,
};
LabelNode *addLabel(SkyObject *skyObject, label_t);
void update();
void updateChildLabels(label_t type);
QSGOpacityNode *getLabelNode(label_t type) { return labelsLists.value(type); }
void deleteLabels(label_t type);
void hideLabels(label_t type);
RootNode *rootNode() { return m_rootNode; }
private:
QMap<label_t, LabelTypeNode *> labelsLists;
RootNode *m_rootNode;
};
#endif
......@@ -25,23 +25,32 @@
#include "skynodes/nodes/linenode.h"
LinesItem::LinesItem(RootNode *rootNode)
:SkyItem(rootNode)
:SkyItem(LabelsItem::label_t::RUDE_LABEL, rootNode)
{
Options::setHideCBounds(true);
//Under construction
Options::setShowCBounds(true);
Options::setShowCLines(true);
Options::setHideOnSlew(true);
Options::setHideCLines(false);
Options::setShowSolarSystem(true);
Options::setShowEcliptic(true);
Options::setShowEquator(true);
Options::setShowEquatorialGrid(true);
Options::setShowHorizontalGrid(true);
Options::setShowGround(true);
//Labels
Options::setShowCometNames(true);
Options::setShowAsteroidNames(true);
Options::setShowAsteroids(true);
Options::setAsteroidLabelDensity(10000);
Options::setMagLimitAsteroid(-10);
Options::setHideCBounds(true);
Options::setHideCLines(false);
Options::setHideOnSlew(true);
Options::setHideGrids(false);
Options::setRunClock(false);
Options::setShowGround(true);
}
void LinesItem::addLinesComponent(LineListIndex *linesComp, QString color, int width, Qt::PenStyle style) {
......
......@@ -25,7 +25,7 @@
#include "Options.h"
PlanetsItem::PlanetsItem(QList<SolarSystemSingleComponent *> planets, QList<PlanetMoonsComponent *> moons, RootNode *rootNode)
:SkyItem(rootNode), m_planetComponents(planets), m_moonsComponents(moons)
:SkyItem(LabelsItem::label_t::PLANET_LABEL, rootNode), m_planetComponents(planets), m_moonsComponents(moons)
{
foreach(SolarSystemSingleComponent * planetComp, m_planetComponents) {
KSPlanetBase *planet = planetComp->planet();
......
......@@ -23,6 +23,7 @@
#include "kstarslite/skyitems/cometsitem.h"
#include "kstarslite/skyitems/horizonitem.h"
#include "kstarslite/skyitems/linesitem.h"
#include "kstarslite/skyitems/labelsitem.h"
RootNode::RootNode()
:m_skyMapLite(SkyMapLite::Instance()),
......@@ -31,31 +32,33 @@ RootNode::RootNode()
genCachedTextures();
Options::setProjection(Projector::Lambert);
SkyMapComposite *skyComposite = KStarsData::Instance()->skyComposite();
SolarSystemComposite *solarSystem = skyComposite->solarSystemComposite();
m_planetsItem = new PlanetsItem(solarSystem->planets(), solarSystem->planetMoonsComponent(), this);
m_asteroidsItem = new AsteroidsItem(solarSystem->asteroids(), this);
m_cometsItem = new CometsItem(solarSystem->comets(), this);
m_skyComposite = KStarsData::Instance()->skyComposite();
m_solarSystem = m_skyComposite->solarSystemComposite();
// LabelsItem needs to be created first so that other items could insert their labels in labelsList
m_labelsItem = new LabelsItem(this);
m_linesItem = new LinesItem(this);
m_linesItem->addLinesComponent( skyComposite->constellationBoundary(), "CBoundColor", 1, Qt::SolidLine );
m_linesItem->addLinesComponent( skyComposite->constellationLines(), "СLineColor", 1, Qt::SolidLine );
m_linesItem->addLinesComponent( m_skyComposite->equatorialCoordGrid(), "EquatorialGridColor", 1, Qt::DotLine );
m_linesItem->addLinesComponent( m_skyComposite->horizontalCoordGrid(), "HorizontalGridColor", 1, Qt::DotLine );
m_linesItem->addLinesComponent( m_skyComposite->equator(), "EqColor", 1, Qt::SolidLine );
m_linesItem->addLinesComponent( m_skyComposite->ecliptic(), "EclColor", 1, Qt::SolidLine );
m_linesItem->addLinesComponent( skyComposite->equator(), "EqColor", 1, Qt::SolidLine );
m_linesItem->addLinesComponent( skyComposite->ecliptic(), "EclColor", 1, Qt::SolidLine );
m_linesItem->addLinesComponent( m_skyComposite->constellationBoundary(), "CBoundColor", 1, Qt::SolidLine );
m_linesItem->addLinesComponent( m_skyComposite->constellationLines(), "CLineColor", 1, Qt::SolidLine );
m_linesItem->addLinesComponent( skyComposite->equatorialCoordGrid(), "EquatorialGridColor", 1, Qt::DotLine );
m_linesItem->addLinesComponent( skyComposite->horizontalCoordGrid(), "HorizontalGridColor", 1, Qt::DotLine );
m_planetsItem = new PlanetsItem(m_solarSystem->planets(), m_solarSystem->planetMoonsComponent(), this);
m_asteroidsItem = new AsteroidsItem(m_solarSystem->asteroids(), this);
m_cometsItem = new CometsItem(m_solarSystem->comets(), this);
m_horizonItem = new HorizonItem(skyComposite->horizon(), this);
m_horizonItem = new HorizonItem(m_skyComposite->horizon(), this);
setIsRectangular(false);