Commit 1aa79365 authored by Artem Fedoskin's avatar Artem Fedoskin
Browse files

Optimized the structure of SkyMapLite so that now there is only one node

for clipping and one texture cache.
parent ca0182dc
......@@ -544,6 +544,8 @@ if(BUILD_KSTARS_LITE)
kstarsliteinit.cpp
skymaplite.cpp
skymaplitevents.cpp
#RootNode
kstarslite/skyitems/rootnode.cpp
#SkyItems
kstarslite/skyitems/skyitem.cpp
kstarslite/skyitems/planetsitem.cpp
......@@ -551,9 +553,6 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/cometsitem.cpp
kstarslite/skyitems/horizonitem.cpp
kstarslite/skyitems/linesitem.cpp
#RootNodes
kstarslite/skyitems/skynodes/rootnodes/rootnode.cpp
kstarslite/skyitems/skynodes/rootnodes/linesrootnode.cpp
#SkyNodes
kstarslite/skyitems/skynodes/planetnode.cpp
kstarslite/skyitems/skynodes/skynode.cpp
......@@ -566,7 +565,7 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/skynodes/nodes/polynode.cpp
kstarslite/skyitems/skynodes/nodes/linenode.cpp
#Material
kstarslite/skyitems/skynodes/material/dashedshader.cpp
#kstarslite/skyitems/skynodes/material/dashedshader.cpp
#libtess
libtess/dict.c
libtess/geom.c
......
......@@ -436,11 +436,11 @@ void DetailDialog::createGeneralTab()
//Common to all types:
if ( selectedObject->type() == SkyObject::CONSTELLATION )
Data->ObjectTypeInConstellation->setText(
KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName( selectedObject ) );
KStarsData::Instance()->skyComposite()->constellationBoundary()->constellationName( selectedObject ) );
else
Data->ObjectTypeInConstellation->setText(
i18nc("%1 type of sky object (planet, asteroid etc), %2 name of a constellation", "%1 in %2", objecttyp,
KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName( selectedObject ) ) );
KStarsData::Instance()->skyComposite()->constellationBoundary()->constellationName( selectedObject ) ) );
}
void DetailDialog::createPositionTab( const KStarsDateTime &ut, GeoLocation *geo ) {
......
......@@ -230,7 +230,7 @@ void KSPopupMenu::createSatelliteMenu( Satellite *satellite ) {
addFancyLabel( satellite->name() );
addFancyLabel( satellite->id() );
addFancyLabel( i18n( "satellite" ) );
addFancyLabel( KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName( satellite ) );
addFancyLabel( KStarsData::Instance()->skyComposite()->constellationBoundary()->constellationName( satellite ) );
addSeparator();
......@@ -278,7 +278,7 @@ void KSPopupMenu::initPopupMenu( SkyObject *obj, QString name, QString type, QSt
addFancyLabel( name );
addFancyLabel( type );
addFancyLabel( info );
addFancyLabel( KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName( obj ) );
addFancyLabel( KStarsData::Instance()->skyComposite()->constellationBoundary()->constellationName( obj ) );
//Insert Rise/Set/Transit labels
SkyObject* o = obj->clone();
......
......@@ -459,7 +459,7 @@ QString KStars::getObjectDataXML( const QString &objectName ) {
stream.writeTextElement( "Name", target->name() );
stream.writeTextElement( "Alt_Name", target->name2() );
stream.writeTextElement( "Long_Name", target->longname() );
stream.writeTextElement( "Constellation", KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName( target ) );
stream.writeTextElement( "Constellation", KStarsData::Instance()->skyComposite()->constellationBoundary()->constellationName( target ) );
stream.writeTextElement( "RA_Dec_Epoch_JD", QString::number( target->getLastPrecessJD(), 'f', 3 ) );
stream.writeTextElement( "RA_HMS", target->ra().toHMSString() );
stream.writeTextElement( "Dec_DMS", target->dec().toDMSString() );
......
......@@ -20,68 +20,49 @@
#include "projections/projector.h"
#include "ksasteroid.h"
#include "skynodes/rootnodes/rootnode.h"
#include "skynodes/planetnode.h"
#include "skynodes/pointsourcenode.h"
#include "kstarslite/skyitems/rootnode.h"
AsteroidsItem::AsteroidsItem(QQuickItem* parent)
:SkyItem(parent), m_asteroidsList(0), m_clear(false)
AsteroidsItem::AsteroidsItem(const QList<SkyObject*>& asteroidsList, RootNode *rootNode)
:SkyItem(rootNode), m_asteroidsList(asteroidsList)
{
recreateList();
}
void AsteroidsItem::setAsteroidsList(QList<SkyObject*> *asteroidsList) {
/*void AsteroidsItem::setAsteroidsList(QList<SkyObject*> *asteroidsList) {
m_asteroidsList = asteroidsList;
m_addAsteroids = true;
}
void AsteroidsItem::clear() {
m_clear = true;
}
QSGNode* AsteroidsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) {
Q_UNUSED(updatePaintNodeData);
RootNode *n = static_cast<RootNode*>(oldNode);
QRectF rect = boundingRect();
if (!Options::showAsteroids() || rect.isEmpty()) {
delete n;
return 0;
}
if(m_clear) {
if(n) n->removeAllSkyNodes();
m_clear = false;
}*/
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()));
}
}
}
if(!n) {
if(!m_asteroidsList) return 0;// AsteroidsComponent is not ready
n = new RootNode; // If no RootNode exists create one
void AsteroidsItem::update() {
if (!Options::showAsteroids()) {
removeAllChildNodes();
hide();
return;
} else if (!childCount()) {
recreateList();
}
show();
if(m_addAsteroids) {
int pAstLen = m_asteroidsList->length();
/* If there are some asteroids that have been already displayed once then recreate them
in new instance of RootNode*/
for(int i = 0; i < pAstLen; ++i) {
KSAsteroid *ast = static_cast<KSAsteroid *>(m_asteroidsList->value(i));
if (ast->image().isNull() == false) {
n->appendSkyNode(new PlanetNode(ast, n));
}
else {
n->appendSkyNode(new PointSourceNode(ast,n));
}
}
m_addAsteroids = false;
}
QSGNode *n = firstChild();
while(n != 0) {
SkyNode* pNode = static_cast<SkyNode*>(n);
n = n->nextSibling();
//Update clipping geometry. If m_clipPoly in SkyMapLite wasn't changed, geometry is not updated
n->updateClipPoly();
//Traverse all children nodes of PlanetRootNode
for(int i = 0; i < n->skyNodesCount(); ++i) {
SkyNode* pNode = static_cast<SkyNode*>(n->skyNodeAtIndex(i));
//bool hideLabels = ! Options::showAsteroidNames() ||
//( SkyMapLite::Instance()->isSlewing() && Options::hideLabels() );
......@@ -93,7 +74,7 @@ QSGNode* AsteroidsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *u
if ( labelMagLimit > 10.0 ) labelMagLimit = 10.0;
//printf("labelMagLim = %.1f\n", labelMagLimit );*/
KSAsteroid *ast = static_cast<KSAsteroid *>(pNode->getSkyObject());
KSAsteroid *ast = static_cast<KSAsteroid *>(pNode->skyObject());
if ( ast->mag() > Options::magLimitAsteroid() || std::isnan(ast->mag()) != 0) {
pNode->hide();
......@@ -104,5 +85,4 @@ QSGNode* AsteroidsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *u
//if ( drawn && !( hideLabels || ast->mag() >= labelMagLimit ) )
// SkyLabeler::AddLabel( ast, SkyLabeler::ASTEROID_LABEL );
}
return n;
}
......@@ -20,11 +20,12 @@
class KSAsteroid;
class SkyObject;
class RootNode;
class AsteroidsItem : public SkyItem {
public:
AsteroidsItem(QQuickItem* parent = 0);
AsteroidsItem(const QList<SkyObject*>& asteroidsList, RootNode *rootNode = 0);
/** Adds an object of type KSAsteroid to m_toAdd. In the next call to
* updatePaintNode() the object of type PlanetNode will be created and asteroid
......@@ -33,19 +34,11 @@ public:
*
* @param KSAsteroid that should be displayed on SkyMapLite
*/
void setAsteroidsList(QList<SkyObject*> *asteroidsList);
/**
* Sets m_clear to true. On next call to updatePaintNode all SkyNodes in RootNode and
* all KSAsteroids in m_asteroids and m_toAdd will be deleted.
*/
void clear();
//void setAsteroidsList(QList<SkyObject*> *asteroidsList);
protected:
virtual QSGNode* updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
void recreateList();
virtual void update() override;
private:
bool m_clear;
bool m_addAsteroids;
QList<SkyObject*> *m_asteroidsList;
const QList<SkyObject*>& m_asteroidsList;
};
#endif
......@@ -20,65 +20,24 @@
#include "projections/projector.h"
#include "kscomet.h"
#include "skynodes/rootnodes/rootnode.h"
#include "skynodes/pointsourcenode.h"
CometsItem::CometsItem(QQuickItem* parent)
:SkyItem(parent)
CometsItem::CometsItem(const QList<SkyObject*>& cometsList, RootNode *rootNode)
:SkyItem(rootNode), m_cometsList(cometsList)
{
}
void CometsItem::addComet(KSComet * comet) {
if(!m_comets.contains(comet) && !m_toAdd.contains(comet))
m_toAdd.append(comet);
}
void CometsItem::clear() {
m_clear = true;
m_comets.clear();
m_toAdd.clear();
recreateList();
}
QSGNode* CometsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) {
Q_UNUSED(updatePaintNodeData);
RootNode *n = static_cast<RootNode*>(oldNode);
QRectF rect = boundingRect();
if (!Options::showComets() || Options::zoomFactor() < 10*MINZOOM || rect.isEmpty()) {
delete n;
return 0;
void CometsItem::update() {
if (!Options::showComets() || Options::zoomFactor() < 10*MINZOOM ) {
removeAllChildNodes();
hide();
return;
} else if (!childCount()) {
show();
recreateList();
}
if(!n) {
n = new RootNode; // If no RootNode exists create one
int pComLen = m_comets.length();
if(pComLen > 0) {
/* If there are some asteroids that have been already displayed once then recreate them
in new instance of RootNode*/
for(int i = 0; i < pComLen; ++i) {
n->appendSkyNode(new PointSourceNode(m_comets[i],n));
}
}
}
if(m_clear) {
n->removeAllSkyNodes();
m_clear = false;
}
int addLength = m_toAdd.length();
if(addLength > 0) { // If there are some new comets to add
for(int i = 0; i < addLength; ++i) {
m_comets.append(m_toAdd[i]);
n->appendSkyNode(new PointSourceNode(m_toAdd[i],n));
}
m_toAdd.clear();
}
//Update clipping geometry. If m_clipPoly in SkyMapLite wasn't changed, geometry is not updated
n->updateClipPoly();
show();
/*bool hideLabels = ! Options::showCometNames() ||
(SkyMap::Instance()->isSlewing() &&
......@@ -89,11 +48,14 @@ QSGNode* CometsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upda
skyp->setPen( QPen( QColor( "darkcyan" ) ) );
skyp->setBrush( QBrush( QColor( "darkcyan" ) ) );*/
//Traverse all children nodes of RootNode
for(int i = 0; i < n->skyNodesCount(); ++i) {
SkyNode* skyNode = static_cast<SkyNode*>(n->skyNodeAtIndex(i));
//Traverse all children nodes
QSGNode *n = firstChild();
while( n!= 0) {
SkyNode* skyNode = static_cast<SkyNode*>(n);
n = n->nextSibling();
KSComet *com = static_cast<KSComet *>(skyNode->getSkyObject());
//TODO: Might be better move it to PointSourceNode
KSComet *com = static_cast<KSComet *>(skyNode->skyObject());
double mag = com->mag();
if (std::isnan(mag) == 0)
{
......@@ -105,5 +67,12 @@ QSGNode* CometsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upda
skyNode->hide();
}
}
return n;
}
void CometsItem::recreateList() {
removeAllChildNodes();
foreach(SkyObject *comet, m_cometsList) {
KSComet *com = static_cast<KSComet *>(comet);
appendChildNode(new PointSourceNode(com,rootNode()));
}
}
......@@ -19,10 +19,11 @@
#include "skyitem.h"
class KSComet;
class SkyObject;
class CometsItem : public SkyItem {
public:
CometsItem(QQuickItem* parent = 0);
CometsItem(const QList<SkyObject *>& cometsList, RootNode *rootNode = 0);
/** Adds an object of type KSComet to m_toAdd. In the next call to
* updatePaintNode() the object of type PointSourceNode will be created and comet
* will be moved to m_comets. PointSourceNode represents graphically KSComet on SkyMapLite.
......@@ -31,17 +32,11 @@ public:
*
* @param KSComet that should be displayed on SkyMapLite
*/
void addComet(KSComet * comet);
/**
* @short Sets m_clear to true. On next call to updatePaintNode all child nodes of RootNode will be
* deleted. Clears m_comets
*/
void clear();
protected:
virtual QSGNode* updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
//void addComet(KSComet * comet);
virtual void update() override;
void recreateList();
private:
bool m_clear;
QList<KSComet *> m_comets;
QList<KSComet *> m_toAdd;
const QList<SkyObject *>& m_cometsList;
};
#endif
......@@ -15,48 +15,32 @@
***************************************************************************/
#include "horizonitem.h"
#include "projections/projector.h"
#include "horizoncomponent.h"
#include "skynodes/rootnodes/rootnode.h"
#include "skynodes/horizonnode.h"
#include "Options.h"
HorizonItem::HorizonItem(QQuickItem* parent)
:SkyItem(parent), m_horizonComp(0)
HorizonItem::HorizonItem(HorizonComponent * hComp, RootNode *rootNode)
:SkyItem(rootNode), m_horizonComp(hComp)
{
appendChildNode(new HorizonNode(m_horizonComp->pointList()));
}
QSGNode* HorizonItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) {
RootNode *n = static_cast<RootNode*>(oldNode);
Q_UNUSED(updatePaintNodeData);
QRectF rect = boundingRect();
if (rect.isEmpty()) {
delete n;
return 0;
void HorizonItem::update() {
if(!childCount()) {
appendChildNode(new HorizonNode(m_horizonComp->pointList()));
}
if(!n) {
if(!m_horizonComp) return 0; // HorizonComponent is not ready
n = new RootNode; // If no RootNode exists create one
n->appendSkyNode(new HorizonNode(m_horizonComp->pointList()));
}
//Update clipping geometry. If m_clipPoly in SkyMapLite wasn't changed, geometry is not updated
n->updateClipPoly();
//HorizonNode *hNode = static_cast<HorizonNode *>(n->skyNodeAtIndex(0));
for(int i = 0; i < n->skyNodesCount(); ++i) {
SkyNode *hNode = n->skyNodeAtIndex(i);
QSGNode *n = firstChild();
while(n != 0) {
SkyNode *hNode = static_cast<SkyNode *>(n);
if(m_horizonComp->selected()) {
hNode->update();
} else {
hNode->hide();
}
n = n->nextSibling();
}
return n;
}
......@@ -22,11 +22,10 @@ class HorizonComponent;
class HorizonItem : public SkyItem {
public:
HorizonItem(QQuickItem* parent = 0);
HorizonItem(HorizonComponent * hComp, RootNode *rootNode);
inline void setHorizonComp(HorizonComponent * hComp) { m_horizonComp = hComp; }
protected:
virtual QSGNode* updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
virtual void update();
private:
HorizonComponent *m_horizonComp;
};
......
......@@ -16,14 +16,16 @@
#include "Options.h"
#include "projections/projector.h"
#include <QSGNode>
#include "skynodes/trixelnode.h"
#include "linesitem.h"
#include "linelist.h"
#include "skynodes/rootnodes/linesrootnode.h"
#include "linelistindex.h"
#include "skynodes/nodes/linenode.h"
LinesItem::LinesItem(QQuickItem* parent)
:SkyItem(parent)
LinesItem::LinesItem(RootNode *rootNode)
:SkyItem(rootNode)
{
Options::setHideCBounds(true);
Options::setShowCBounds(true);
......@@ -43,40 +45,59 @@ LinesItem::LinesItem(QQuickItem* parent)
}
void LinesItem::addLinesComponent(LineListIndex *linesComp, QString color, int width, Qt::PenStyle style) {
m_lineIndexes.append(QPair<bool, LineListIndex *>(true,linesComp));
m_colors.append(color);
m_widths.append(width);
m_styles.append(style);
}
QSGNode* LinesItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) {
QSGOpacityNode *node = new QSGOpacityNode;
appendChildNode(node);
Q_UNUSED(updatePaintNodeData);
m_lineIndexes.insert(node, linesComp);
LineListHash *trixels = linesComp->lineIndex();
LinesRootNode *n = static_cast<LinesRootNode *>(oldNode);
QRectF rect = boundingRect();
QHash< Trixel, LineListList *>::const_iterator i = trixels->begin();
while( i != trixels->end()) {
if (rect.isEmpty()) {
delete n;
return 0;
}
if(!n) {
n = new LinesRootNode; // If no RootNode exists create one
TrixelNode *trixel = new TrixelNode(i.key(), i.value());
node->appendChildNode(trixel);
trixel->setStyle(color, width, style);
++i;
}
}
for(int i = 0; i < m_lineIndexes.size(); ++i) {
QPair<bool, LineListIndex *> *p = &m_lineIndexes[i];
if(p->first) {
n->addLinesComponent(p->second,m_colors[i],m_widths[i],m_styles[i]);
p->first = false;
void LinesItem::update() {
QMap< QSGOpacityNode *, LineListIndex *>::const_iterator i = m_lineIndexes.begin();
while( i != m_lineIndexes.end()) {
QVector<Trixel> visTrixels;
SkyMesh * mesh = SkyMesh::Instance();
SkyMapLite *map = SkyMapLite::Instance();
double radius = map->projector()->fov();
if ( radius > 180.0 )
radius = 180.0;
if(mesh) {
//mesh->aperture(map->focus(), radius);
}
}
//Update clipping geometry. If m_clipPoly in SkyMapLite wasn't changed, geometry is not updated
//n->updateClipPoly();
MeshIterator region (mesh,DRAW_BUF);
while ( region.hasNext() ) {
visTrixels.append(region.next());
}
n->update();
return n;
QSGOpacityNode * node = i.key();
if(i.value()->selected()) {
node->setOpacity(1);
//for(int c = 0; c < node->childCount(); ++c) {
QSGNode *n = node->firstChild();
while(n != 0) {
TrixelNode * trixel = static_cast<TrixelNode *>(n);
n = n->nextSibling();
//if(visTrixels.contains(c)) {
trixel->update();
/* } else {
trixel->hide();
}*/
}
} else {
node->setOpacity(0);
}
node->markDirty(QSGNode::DirtyOpacity);
++i;
}
}
......@@ -24,17 +24,13 @@ class LineListIndex;
class LinesItem : public SkyItem {
public:
LinesItem(QQuickItem* parent = 0);
LinesItem(RootNode *rootNode);
void addLinesComponent(LineListIndex *linesComp, QString color, int width, Qt::PenStyle style);
protected:
virtual QSGNode* updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
virtual void update();
private:
QVector<QPair<bool, LineListIndex *>> m_lineIndexes;
QVector<QString> m_colors;
QVector<int> m_widths;
QVector<Qt::PenStyle> m_styles;
QMap<QSGOpacityNode *,LineListIndex *> m_lineIndexes;
};
#endif
......@@ -22,25 +22,22 @@
#include "skynodes/planetmoonsnode.h"
#include "skynodes/planetnode.h"
#include "skynodes/rootnodes/rootnode.h"
#include "Options.h"
PlanetsItem::PlanetsItem(QQuickItem* parent)
:SkyItem(parent)
PlanetsItem::PlanetsItem(QList<SolarSystemSingleComponent *> planets, QList<PlanetMoonsComponent *> moons, RootNode *rootNode)
:SkyItem(rootNode), m_planetComponents(planets), m_moonsComponents(moons)
{
}
void PlanetsItem::addPlanet(SolarSystemSingleComponent* planetComp) {
if(!m_planetComponents.contains(planetComp) && !m_planetsToAdd.contains(planetComp)) {
m_planetsToAdd.append(planetComp);
}
}