Commit 13562153 authored by Artem Fedoskin's avatar Artem Fedoskin

Added constellation names (ConstellationNamesItem) to SkyMapLite.

HorizonItem, EquatorItem and EclipticItem now have compass labels.
parent 3d9a01bb
......@@ -552,9 +552,12 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/asteroidsitem.cpp
kstarslite/skyitems/cometsitem.cpp
kstarslite/skyitems/horizonitem.cpp
kstarslite/skyitems/linesitem.cpp
kstarslite/skyitems/labelsitem.cpp
kstarslite/skyitems/constellationnamesitem.cpp
#Lines
kstarslite/skyitems/lines/linesitem.cpp
kstarslite/skyitems/lines/equatoritem.cpp
kstarslite/skyitems/lines/eclipticitem.cpp
#SkyNodes
kstarslite/skyitems/skynodes/planetnode.cpp
kstarslite/skyitems/skynodes/skynode.cpp
......
......@@ -15,47 +15,93 @@
***************************************************************************/
#include "constellationnamesitem.h"
#include "constellationnamescomponent.h"
#include "skymaplite.h"
#include "projections/projector.h"
ConstellationNamesItem::ConstellationNamesItem(const QList<SkyObject*>& namesList, RootNode* parent)
:SkyItem(LabelsItem::label_t::CONSTEL_NAME_LABEL, parent), m_namesList(namesList)
#include "rootnode.h"
#include "labelsitem.h"
#include "skynodes/labelnode.h"
#include "Options.h"
ConstellationName::ConstellationName(SkyObject *skyObj)
:obj(skyObj), latin(0), secondary(0)
{
}
void ConstellationName::hide() {
if(latin) latin->hide();
if(secondary) secondary->hide();
}
ConstellationNamesItem::ConstellationNamesItem(ConstellationNamesComponent *constComp, RootNode* parent)
:SkyItem(LabelsItem::label_t::CONSTEL_NAME_LABEL, parent), m_constelNamesComp(constComp)
{
recreateList();
}
void ConstellationNamesItem::update() {
/*if ( ! selected() )
if ( ! m_constelNamesComp->selected() )
return;
if( !m_constelNamesComp->selected() ) {
hide();
rootNode()->labelsItem()->hideLabels(labelType());
return;
}
show();
const Projector *proj = SkyMap::Instance()->projector();
SkyLabeler* skyLabeler = SkyLabeler::Instance();
skyLabeler->useStdFont();
skyLabeler->setPen( QColor( KStarsData::Instance()->colorScheme()->colorNamed( "CNameColor" ) ) );
const Projector *proj = SkyMapLite::Instance()->projector();
QString name;
foreach(SkyObject *p, m_ObjectList) {
if( ! proj->checkVisibility( p ) )
foreach(ConstellationName *constName, m_names) {
SkyObject *p = constName->obj;
if( ! proj->checkVisibility( p ) ) {
constName->hide();
continue;
}
bool visible = false;
QPointF o = proj->toScreen( p, false, &visible );
if( !visible || !proj->onScreen( o ) )
if( !visible || !proj->onScreen( o ) ) {
constName->hide();
continue;
}
QString name;
if( Options::useLatinConstellNames() || Options::useLocalConstellNames() )
if( Options::useLatinConstellNames() || Options::useLocalConstellNames() ) {
name = p->name();
else
if(!constName->latin) {
constName->latin = rootNode()->labelsItem()->addLabel(name,labelType());
}
o.setX( o.x() - 5.0 * name.length() );
constName->latin->setLabelPos(o);
if(constName->secondary) constName->secondary->hide();
} else {
name = p->name2();
o.setX( o.x() - 5.0 * name.length() );
skyLabeler->drawGuideLabel( o, name, 0.0 );
if(!constName->secondary) {
constName->secondary = rootNode()->labelsItem()->addLabel(name,labelType());
}
o.setX( o.x() - 5.0 * name.length() );
constName->secondary->setLabelPos(o);
if(constName->latin) constName->latin->hide();
}
}
skyLabeler->resetFont();*/
//skyLabeler->resetFont();
}
void ConstellationNamesItem::recreateList() {
removeAllChildNodes();
/*foreach(SkyObject *comet, m_namesList) {
appendChildNode(new PointSourceNode(com, rootNode(),labelType()));
}*/
foreach(SkyObject *skyObj, m_constelNamesComp->objectList()) {
m_names.append(new ConstellationName(skyObj));
}
}
......@@ -32,6 +32,16 @@ class ConstellationNamesComponent;
*@version 1.0
*/
struct ConstellationName {
ConstellationName(SkyObject *skyObj);
SkyObject *obj;
LabelNode *latin;
LabelNode *secondary;
void hide();
};
class ConstellationNamesItem : public SkyItem {
public:
......@@ -41,15 +51,14 @@ public:
* @param parent a pointer to SkyItem's parent node
*/
explicit ConstellationNamesItem(const QList<SkyObject*>& namesList, RootNode *rootNode = 0);
explicit ConstellationNamesItem(ConstellationNamesComponent *constComp, RootNode *rootNode = 0);
virtual void update();
void hide();
void show();
void recreateList();
private:
const QList<SkyObject*>& m_namesList;
ConstellationNamesComponent *m_constelNamesComp;
QVector<ConstellationName *> m_names;
};
#endif
......@@ -19,13 +19,50 @@
#include "horizoncomponent.h"
#include "skynodes/horizonnode.h"
#include "labelsitem.h"
#include "skynodes/labelnode.h"
#include "rootnode.h"
#include "labelsitem.h"
#include "Options.h"
HorizonItem::HorizonItem(HorizonComponent * hComp, RootNode *rootNode)
:SkyItem(LabelsItem::label_t::RUDE_LABEL, rootNode), m_horizonComp(hComp)
:SkyItem(LabelsItem::label_t::HORIZON_LABEL, rootNode), m_horizonComp(hComp)
{
appendChildNode(new HorizonNode(m_horizonComp->pointList()));
double az = -0.01;
static QString name[8];
name[0] = i18nc( "Northeast", "NE" );
name[1] = i18nc( "East", "E" );
name[2] = i18nc( "Southeast", "SE" );
name[3] = i18nc( "South", "S" );
name[4] = i18nc( "Southwest", "SW" );
name[5] = i18nc( "West", "W" );
name[6] = i18nc( "Northwest", "NW" );
name[7] = i18nc( "North", "N" );
for ( int i = 0; i < 8; i++ ) {
SkyPoint *c = new SkyPoint;
az += 45.0;
c->setAz( az );
c->setAlt( 0.0 );
LabelNode *compass = rootNode->labelsItem()->addLabel(name[i],labelType());
m_compassLabels.insert(c,compass);
}
}
void HorizonItem::hideLabels() {
QMap<SkyPoint *,LabelNode *>::iterator i = m_compassLabels.begin();
while ( i != m_compassLabels.end() ) {
LabelNode * compass = (*i);
compass->hide();
i++;
}
}
void HorizonItem::update() {
if(!childCount()) {
......@@ -37,9 +74,35 @@ void HorizonItem::update() {
while(n != 0) {
SkyNode *hNode = static_cast<SkyNode *>(n);
if(m_horizonComp->selected()) {
QPointF cpoint;
bool visible;
const Projector *proj = SkyMapLite::Instance()->projector();
KStarsData *data = KStarsData::Instance();
QMap<SkyPoint *,LabelNode *>::iterator i = m_compassLabels.begin();
while ( i != m_compassLabels.end() ) {
SkyPoint *c = i.key();
if ( !Options::useAltAz() ) {
c->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
}
LabelNode * compass = (*i);
cpoint = proj->toScreen( c, false, &visible );
if ( visible && proj->onScreen(cpoint) ) {
compass->setLabelPos(cpoint);
} else {
compass->hide();
}
i++;
}
hNode->update();
} else {
hNode->hide();
hideLabels();
}
n = n->nextSibling();
}
......
......@@ -19,15 +19,19 @@
#include "skyitem.h"
class HorizonComponent;
class GuideLabelNode;
class HorizonItem : public SkyItem {
public:
HorizonItem(HorizonComponent * hComp, RootNode *rootNode);
inline void setHorizonComp(HorizonComponent * hComp) { m_horizonComp = hComp; }
void hideLabels();
virtual void update();
private:
HorizonComponent *m_horizonComp;
QMap<SkyPoint *, LabelNode *> m_compassLabels;
};
#endif
......@@ -19,6 +19,7 @@
#include "labelsitem.h"
#include "skylabeler.h"
#include "skynodes/labelnode.h"
#include "skynodes/guidelabelnode.h"
#include "cometsitem.h"
#include "rootnode.h"
......@@ -69,6 +70,18 @@ LabelsItem::LabelsItem(RootNode *rootNode)
LabelTypeNode *num_label = new LabelTypeNode;
appendChildNode(num_label);
labelsLists.insert(label_t::NUM_LABEL_TYPES, num_label);
LabelTypeNode *horizon_label = new LabelTypeNode;
appendChildNode(horizon_label);
labelsLists.insert(label_t::HORIZON_LABEL, horizon_label);
LabelTypeNode *equator = new LabelTypeNode;
appendChildNode(equator);
labelsLists.insert(label_t::EQUATOR_LABEL, equator);
LabelTypeNode *ecliptic = new LabelTypeNode;
appendChildNode(ecliptic);
labelsLists.insert(label_t::ECLIPTIC_LABEL, ecliptic);
}
LabelNode *LabelsItem::addLabel(SkyObject *skyObject, label_t type) {
......@@ -77,13 +90,31 @@ LabelNode *LabelsItem::addLabel(SkyObject *skyObject, label_t type) {
return label;
}
LabelNode *LabelsItem::addLabel(QString name, label_t type) {
LabelNode *label = new LabelNode(name, type);
labelsLists.value(type)->appendChildNode(label);
return label;
}
GuideLabelNode *LabelsItem::addGuideLabel(QString name, label_t type) {
GuideLabelNode *label = new GuideLabelNode(name, 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::HORIZON_LABEL);
updateChildLabels(label_t::EQUATOR_LABEL);
updateChildLabels(label_t::ECLIPTIC_LABEL);
updateChildLabels(label_t::SATURN_MOON_LABEL);
updateChildLabels(label_t::ASTEROID_LABEL);
if(rootNode()->cometsItem()->visible()) {
......@@ -91,6 +122,8 @@ void LabelsItem::update() {
} else {
hideLabels(label_t::COMET_LABEL);
}
updateChildLabels(label_t::CONSTEL_NAME_LABEL);
}
void LabelsItem::hideLabels(label_t type) {
......@@ -115,10 +148,26 @@ void LabelsItem::updateChildLabels(label_t type) {
node->markDirty(QSGNode::DirtyOpacity);
QSGNode *n = node->firstChild();
/*if( type == label_t::HORIZON_LABEL
|| type == label_t::ECLIPTIC_LABEL || type == label_t::EQUATOR_LABEL) {
while( n != 0) {
GuideLabelNode *label = static_cast<GuideLabelNode *>(n);
if(label->visible()) {
//if(SkyLabeler::Instance()->markRegion(label->left,label->right,label->top,label->bot)) {
QString name = label->name();
if(SkyLabeler::Instance()->markText(label->labelPos, name)) {
label->update();
} else {
label->hide();
}
}
n = n->nextSibling();
}
} else {*/
while( n != 0) {
LabelNode *label = static_cast<LabelNode *>(n);
if(label->visible()) {
if(SkyLabeler::Instance()->markText(label->labelPos, label->skyObject()->name())) {
if(SkyLabeler::Instance()->markText(label->labelPos, label->name())) {
label->update();
} else {
label->hide();
......@@ -126,4 +175,5 @@ void LabelsItem::updateChildLabels(label_t type) {
}
n = n->nextSibling();
}
}
......@@ -25,6 +25,7 @@ typedef QSGOpacityNode LabelTypeNode;
class KSAsteroid;
class LineListIndex;
class LabelNode;
class GuideLabelNode;
class SkyObject;
class RootNode;
......@@ -45,9 +46,15 @@ public:
SATELLITE_LABEL,
RUDE_LABEL, ///Rude labels block other labels FIXME: find a better solution
NUM_LABEL_TYPES,
HORIZON_LABEL,
EQUATOR_LABEL,
ECLIPTIC_LABEL
};
LabelNode *addLabel(SkyObject *skyObject, label_t);
LabelNode *addLabel(SkyObject *skyObject, label_t type);
LabelNode *addLabel(QString name, label_t type);
GuideLabelNode *addGuideLabel(QString name, label_t type);
void update();
void updateChildLabels(label_t type);
QSGOpacityNode *getLabelNode(label_t type) { return labelsLists.value(type); }
......
/** *************************************************************************
EclipticItem.cpp - 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. *
* *
***************************************************************************/
#include "eclipticitem.h"
#include "../rootnode.h"
#include "../labelsitem.h"
#include "ecliptic.h"
#include "../skynodes/labelnode.h"
#include "../skynodes/trixelnode.h"
EclipticItem::EclipticItem(Ecliptic *eclipticComp, RootNode *rootNode)
:SkyItem(LabelsItem::label_t::ECLIPTIC_LABEL, rootNode), m_eclipticComp(eclipticComp)
{
LineListHash *trixels = eclipticComp->lineIndex();
QHash< Trixel, LineListList *>::const_iterator i = trixels->begin();
while( i != trixels->end()) {
TrixelNode *trixel = new TrixelNode(i.key(), i.value(), "EclColor", 1, Qt::SolidLine );
appendChildNode(trixel);
++i;
}
KStarsData *data = KStarsData::Instance();
KSNumbers num( data->ut().djd() );
dms elat(0.0), elng(0.0);
QString label;
for( int ra = 0; ra < 23; ra += 6 ) {
elng.setH( ra );
SkyPoint *o = new SkyPoint;
o->setFromEcliptic( num.obliquity(), elng, elat );
o->setRA0( o->ra() );
o->setDec0( o->dec() );
o->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
label.setNum( o->ra().reduce().Degrees() );
LabelNode *compass = rootNode->labelsItem()->addLabel(label, labelType());
m_compassLabels.insert(o, compass);
}
}
void EclipticItem::update() {
if(m_eclipticComp->selected()) {
show();
QSGNode *n = firstChild();
while(n != 0) {
TrixelNode * trixel = static_cast<TrixelNode *>(n);
n = n->nextSibling();
trixel->update();
}
const Projector *proj = SkyMapLite::Instance()->projector();
KStarsData *data = KStarsData::Instance();
//SkyLabeler* skyLabeler = SkyLabeler::Instance();
QMap<SkyPoint *,LabelNode *>::iterator i = m_compassLabels.begin();
while ( i != m_compassLabels.end() ) {
SkyPoint *c = i.key();
c->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
LabelNode * compass = (*i);
bool visible;
QPointF cpoint = proj->toScreen( c, false, &visible );
if ( visible && proj->checkVisibility( c ) ) {
compass->setLabelPos(cpoint);
} else {
compass->hide();
}
i++;
}
} else {
hide();
rootNode()->labelsItem()->hideLabels(labelType());
}
}
/** *************************************************************************
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 ECLIPTICITEM_H_
#define ECLIPTICITEM_H_
#include "../skyitem.h"
class Ecliptic;
class EclipticItem : public SkyItem {
public:
EclipticItem(Ecliptic *eclipticComp, RootNode *rootNode);
virtual void update();
private:
Ecliptic *m_eclipticComp;
QMap<SkyPoint *, LabelNode *> m_compassLabels;
};
#endif
/** *************************************************************************
EquatorItem.cpp - 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. *
* *
***************************************************************************/
#include "Options.h"
#include "projections/projector.h"
#include <QSGNode>
#include "equatoritem.h"
#include "../skynodes/trixelnode.h"
#include "../rootnode.h"
#include "../labelsitem.h"
#include "../skynodes/labelnode.h"
EquatorItem::EquatorItem(Equator *equatorComp, RootNode *rootNode)
:SkyItem(LabelsItem::label_t::EQUATOR_LABEL, rootNode), m_equatorComp(equatorComp)
{
LineListHash *trixels = equatorComp->lineIndex();
QHash< Trixel, LineListList *>::const_iterator i = trixels->begin();
while( i != trixels->end()) {
TrixelNode *trixel = new TrixelNode(i.key(), i.value(), "EqColor", 1, Qt::SolidLine );
appendChildNode(trixel);
++i;
}
for( int ra = 0; ra < 23; ra += 2 ) {
SkyPoint *o = new SkyPoint( ra, 0.0 );
QString label;
label.setNum( o->ra().hour() );
LabelNode *compass = rootNode->labelsItem()->addLabel(label, labelType());
m_compassLabels.insert(o, compass);
}
}
void EquatorItem::update() {
if(m_equatorComp->selected()) {
show();
QSGNode *n = firstChild();
while(n != 0) {
TrixelNode * trixel = static_cast<TrixelNode *>(n);
n = n->nextSibling();
trixel->update();
}
const Projector *proj = SkyMapLite::Instance()->projector();
KStarsData *data = KStarsData::Instance();
//SkyLabeler* skyLabeler = SkyLabeler::Instance();
QMap<SkyPoint *,LabelNode *>::iterator i = m_compassLabels.begin();
KSNumbers num( data->ut().djd() );
while ( i != m_compassLabels.end() ) {
SkyPoint *c = i.key();
c->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
LabelNode * compass = (*i);
bool visible;
QPointF cpoint = proj->toScreen( c, false, &visible );
if ( visible && proj->checkVisibility( c ) ) {
compass->setLabelPos(cpoint);
} else {
compass->hide();
}
i++;
}
} else {
hide();
rootNode()->labelsItem()->hideLabels(labelType());
}
}
/**/
/** *************************************************************************
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 EQUATORITEM_H_
#define EQUATORITEM_H_
#include "../skyitem.h"
#include "equator.h"
class KSAsteroid;
class LineListIndex;
class EquatorItem : public SkyItem {
public:
EquatorItem(Equator *equatorComp, RootNode *rootNode);
virtual void update();
private:
Equator *m_equatorComp;
QMap<SkyPoint *, LabelNode *> m_compassLabels;
};
#endif