Commit 762487c3 authored by Artem Fedoskin's avatar Artem Fedoskin
Browse files

Added support of planet moons in SkyMapLite. SkyMapLite now can handle

rotation using two fingers and pinch-to-zoom into specific area.
parent cd3def57
......@@ -557,6 +557,7 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/nodes/pointnode.cpp
kstarslite/skyitems/nodes/skynode.cpp
kstarslite/skyitems/nodes/pointsourcenode.cpp
kstarslite/skyitems/nodes/planetmoonsnode.cpp
)
#Qml files will be probably moved to user's data dir, but for use
#with QtCreator it is more convenient to have them here
......@@ -635,8 +636,11 @@ set(kstars_SRCS ${indi_SRCS} ${fits_SRCS} ${ekos_SRCS} ${onlineparser_SRCS}
${kstars_options_SRCS} ${kstars_skyobjects_SRCS} ${kstars_dialogs_SRCS} ${oal_SRCS}
${printing_SRCS} ${kstarslite_SRCS} ${kstarslite_RESOURCE}
)
kconfig_add_kcfg_files(kstars_SRCS ${kstars_KCFG_SRCS})
if(BUILD_KSTARS_LITE)
kconfig_add_kcfg_files(kstars_SRCS GENERATE_MOC ${kstars_KCFG_SRCS})
else()
kconfig_add_kcfg_files(kstars_SRCS ${kstars_KCFG_SRCS})
endif()
if(NOT BUILD_KSTARS_LITE)
qt5_add_dbus_adaptor(kstars_SRCS org.kde.kstars.xml kstars.h KStars)
......
......@@ -60,19 +60,19 @@
<label>Time InfoBox anchor flag</label>
<whatsthis>Is the Time InfoBox anchored to a window edge? 0 = not anchored; 1 = anchored to right edge; 2 = anchored to bottom edge; 3 = anchored to bottom and right edges.</whatsthis>
<default>0</default>
<min>0</min><max>3</max>
<!--<min>0</min><max>3</max>-->
</entry>
<entry name="StickyFocusBox" type="Int">
<label>Time InfoBox anchor flag</label>
<whatsthis>Is the Focus InfoBox anchored to a window edge? 0 = not anchored; 1 = anchored to right edge; 2 = anchored to bottom edge; 3 = anchored to bottom and right edges.</whatsthis>
<default>1</default>
<min>0</min><max>3</max>
<!--<min>0</min><max>3</max>-->
</entry>
<entry name="StickyGeoBox" type="Int">
<label>Geographic InfoBox anchor flag</label>
<whatsthis>Is the Geographic Location InfoBox anchored to a window edge? 0 = not anchored; 1 = anchored to right edge; 2 = anchored to bottom edge; 3 = anchored to bottom and right edges.</whatsthis>
<default>2</default>
<min>0</min><max>3</max>
<!--<min>0</min><max>3</max>-->
</entry>
<entry name="ShowStatusBar" type="Bool">
<label>Display the statusbar?</label>
......@@ -125,7 +125,7 @@
</entry>
</group>
<group name="indi">
<group name="indi">
<entry name="useGeographicUpdate" type="Bool">
<label>Automatically updates geographic location?</label>
<default>true</default>
......@@ -143,7 +143,7 @@
<label>Display INDI messages in the statusbar?</label>
<whatsthis>Toggle display of INDI messages in the KStars statusbar.</whatsthis>
<default>true</default>
</entry>
</entry>
<entry name="useComputerSource" type="Bool">
<label>Use computer time and location for synchronization?</label>
<default>true</default>
......@@ -644,7 +644,7 @@
<label>Zoom Factor, in pixels per radian</label>
<whatsthis>The zoom level, measured in pixels per radian.</whatsthis>
<default>1000.</default>
<min>200.</min><max>5000000.</max>
<!--<min>200.</min><max>5000000.</max>-->
</entry>
<entry name="MagLimitAsteroid" type="Double">
<label>Faint limit for asteroids</label>
......@@ -762,13 +762,13 @@
<label>Mode for rendering stars</label>
<whatsthis>The method for rendering stars: 0="realistic colors"; 1="solid red"; 2="solid black"; 3="solid white"</whatsthis>
<default>0</default>
<max>3</max>
<!--<max>3</max>-->
</entry>
<entry name="StarColorIntensity" type="UInt">
<label>Saturation level of star colors</label>
<whatsthis>The color saturation level of stars (only applicable when using "realistic colors" mode).</whatsthis>
<default>6</default>
<max>10</max>
<!--<max>10</max>-->
</entry>
<entry name="AngularRulerColor" type="String">
<label>Color of angular distance ruler</label>
......@@ -1538,7 +1538,7 @@
<entry name="PHD2Port" type="UInt">
<label>PHD2 Event Monitoring Port</label>
<default>4400</default>
</entry>
</entry>
<entry name="CalibrationPulseDuration" type="UInt">
<label>Pulse duration in milliseconds used for guiding pulses during calibration stage.</label>
<default>1000</default>
......
......@@ -41,7 +41,6 @@ KStarsLite::KStarsLite( bool doSplash, bool startClock, const QString &startDate
//Make instance of KStarsLite and KStarsData available to QML
m_Engine.rootContext()->setContextProperty("KStarsLite", this);
m_Engine.rootContext()->setContextProperty("KStarsData", m_KStarsData);
m_Engine.rootContext()->setContextProperty("Options", Options::self());
/*Register SkyMapLite for use within QML
......@@ -63,6 +62,8 @@ KStarsLite::KStarsLite( bool doSplash, bool startClock, const QString &startDate
have to add SkyItems to the SkyMapLite*/
m_SkyMapLite = SkyMapLite::createInstance(skyMapLiteWrapper);
m_Engine.rootContext()->setContextProperty("SkyMapLite", m_SkyMapLite);
// Set pinstance to yourself
pinstance = this;
......@@ -118,6 +119,13 @@ KStarsLite *KStarsLite::createInstance( bool doSplash, bool clockrunning, const
return nullptr;
}
void KStarsLite::fullUpdate() {
m_KStarsData->setFullTimeUpdate();
updateTime();
m_SkyMapLite->forceUpdate();
}
void KStarsLite::updateTime( const bool automaticDSTchange ) {
// Due to frequently use of this function save data and map pointers for speedup.
// Save options and geo() to a pointer would not speedup because most of time options
......
......@@ -78,6 +78,9 @@ public:
/** @return pointer to KStarsData object which contains application data. */
inline KStarsData* data() const { return m_KStarsData; }
/** @short used from QML to update positions of sky objects and update SkyMapLite */
Q_INVOKABLE void fullUpdate();
signals:
/** Sent when KStarsData finishes loading data */
void dataLoadFinished();
......
......@@ -168,6 +168,11 @@ ColumnLayout {
}
TopMenuButton {
iconSrc: num.iconpath + "media-playback-start.png"
MouseArea {
onClicked: {
Options.setRunClock(false);
}
}
}
TopMenuButton {
iconSrc: num.iconpath + "media-skip-forward.png"
......
......@@ -86,13 +86,21 @@ ColumnLayout {
}
TopMenuButton {
iconSrc: num.iconpath + "/sc-actions-kstars_deepsky.png"
MouseArea {
anchors.fill: parent
onClicked: {
Options.showJupiter = !Options.showJupiter
KStarsLite.fullUpdate()
}
}
}
TopMenuButton {
iconSrc: num.iconpath + "/sc-actions-kstars_planets.png"
MouseArea {
anchors.fill: parent
onClicked: {
Options.setShowSolarSystem(false);
Options.showSolarSystem = !Options.showSolarSystem
KStarsLite.fullUpdate()
}
}
}
......@@ -109,9 +117,23 @@ ColumnLayout {
iconSrc: num.iconpath + "/sc-actions-kstars_mw.png"
}
TopMenuButton {
MouseArea {
anchors.fill: parent
onClicked: {
SkyMapLite.slotZoomIn()
KStarsLite.fullUpdate()
}
}
iconSrc: num.iconpath + "/sc-actions-kstars_grid.png"
}
TopMenuButton {
MouseArea {
anchors.fill: parent
onClicked: {
SkyMapLite.slotZoomOut()
KStarsLite.fullUpdate()
}
}
iconSrc: num.iconpath + "/sc-actions-kstars_horizon.png"
}
}
......
#include "planetnode.h"
#include "pointsourcenode.h"
#include "planetmoonsnode.h"
#include "planetmoons.h"
#include "ksplanetbase.h"
PlanetMoonsNode::PlanetMoonsNode(KSPlanetBase* planet, RootNode* parentNode)
:SkyNode(planet), m_rootNode(parentNode), pmoons(0),
m_planetNode(new PlanetNode(planet, parentNode))
{
appendChildNode(m_planetNode);
}
void PlanetMoonsNode::update() {
if(pmoons) updateMoons();
m_planetNode->update();
}
void PlanetMoonsNode::hide() {
m_planetNode->hide();
foreach(PointSourceNode *moon, m_moonNodes) {
moon->hide();
}
}
//TODO updateMoons and destructor
void PlanetMoonsNode::updateMoons() {
//In order to get the z-order right for the moons and the planet,
//we need to first append the planet (both m_point and m_planetPic) then append all nodes for moons
//that are nearer than the planet and then prepend nodes for moons that are further than the planet
int nmoons = pmoons->nMoons();
if(!m_moonNodes.length()) { //Initialize PointSourceNodes used for drawing moons
for ( int i=0; i<nmoons; ++i ) {
m_moonNodes.append(new PointSourceNode(pmoons->moon(i), m_rootNode));
}
}
removeAllChildNodes(); // Clear all child nodes so that we can render moons according to z-order
// We need to reappend node that draws the planet
appendChildNode(m_planetNode);
for ( int i=0; i<nmoons; ++i ) {
if ( pmoons->z(i) < 0.0 ) { //Moon is nearer than the planet
appendChildNode(m_moonNodes[i]);
m_moonNodes[i]->update();
} else {
//Draw Moons that are further than the planet
//skyp->drawPointSource( pmoons->moon(i), pmoons->moon(i)->mag() );
prependChildNode(m_moonNodes[i]);
m_moonNodes[i]->update();
}
}
/* //Draw Moon name labels if at high zoom
/*if ( ! (Options::showPlanetNames() && Options::zoomFactor() > 50.*MINZOOM) ) return;
for ( int i=0; i<nmoons; ++i ) {
/*
if (planet ==KSPlanetBase::SATURN)
SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::SATURN_MOON_LABEL );
else
SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::JUPITER_MOON_LABEL );
}*/
}
/** *************************************************************************
planetmoonsnode.h - K Desktop Planetarium
-------------------
begin : 24/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 PLANETMOONSNODE_H_
#define PLANETMOONSNODE_H_
#include "skynode.h"
class PlanetNode;
class PlanetMoons;
class RootNode;
class PointSourceNode;
class KSPlanetBase;
/** @class PlanetMoonsNode
*
* A SkyNode derived class used as a container for displaying a planet with its moons (if any). Unlike
* PlanetMoons in SkyComponents PlanetMoonsNode represents both planet and moons. Thus the planet has to
* be created only using this class that in turn will create an object of type PlanetNode. Although all
* SkyNodes are "movable" objects this class is just a container that provides z-order for moons and
* planets, which changes their positions on their own.
*
*@short A container for planets and moons that provides z-order.
*@author Artem Fedoskin
*@version 1.0
*/
class PlanetMoonsNode : public SkyNode {
public:
PlanetMoonsNode(KSPlanetBase* planet, RootNode* parentNode);
/**
* @short Add object of type PlanetMoons to this node
* @param planetMoons PlanetMoons component
*/
inline void addMoons(PlanetMoons * planetMoons) { pmoons = planetMoons; }
virtual void update() override;
virtual void hide() override;
/**
* @note PlanetMoonsNode is not meant to be moved. PlanetNode and PointSourceNodes handle this on
* their own.
*/
virtual void changePos(QPointF pos) { }
/**
* @short update position of moons if planet has them
*/
void updateMoons();
private:
PlanetNode *m_planetNode;
PlanetMoons *pmoons;
QList<PointSourceNode *> m_moonNodes;
RootNode *m_rootNode;
};
#endif
......@@ -22,7 +22,9 @@
#include "ksplanetbase.h"
#include "Options.h"
#include "projections/projector.h"
#include "planetnode.h"
#include "pointnode.h"
PlanetNode::PlanetNode(KSPlanetBase* pb, RootNode* parentNode)
:SkyNode(pb), m_planetPic(new QSGSimpleTextureNode), m_planetOpacity(new QSGOpacityNode)
......@@ -40,8 +42,8 @@ PlanetNode::PlanetNode(KSPlanetBase* pb, RootNode* parentNode)
m_point = new PointNode(parentNode, spType);
appendChildNode(m_point);
appendChildNode(m_planetOpacity);
//Add planet to opacity node so that we could hide the planet
m_planetOpacity->appendChildNode(m_planetPic);
m_planetPic->setTexture(SkyMapLite::Instance()->window()->createTextureFromImage(
......@@ -49,56 +51,51 @@ PlanetNode::PlanetNode(KSPlanetBase* pb, RootNode* parentNode)
}
void PlanetNode::update() {
if(0) {
//if(!pNode->planet()->select) {
// pNode->hide(); //TODO
} else {
KSPlanetBase * planet = static_cast<KSPlanetBase *>(m_skyObject);
const Projector * proj = projector();
KSPlanetBase * planet = static_cast<KSPlanetBase *>(m_skyObject);
const Projector * proj = projector();
if( !proj->checkVisibility(planet) ) {
hide();
return;
}
if( !proj->checkVisibility(planet) ) {
hide();
return;
}
bool visible = false;
QPointF pos = proj->toScreen(planet,true,&visible);
if( !visible || !proj->onScreen(pos) ) {
hide();
return;
}
float fakeStarSize = ( 10.0 + log10( Options::zoomFactor() ) - log10( MINZOOM ) ) * ( 10 - planet->mag() ) / 10;
if( fakeStarSize > 15.0 )
fakeStarSize = 15.0;
bool visible = false;
QPointF pos = proj->toScreen(planet,true,&visible);
if( !visible || !proj->onScreen(pos) ) {
hide();
return;
}
float fakeStarSize = ( 10.0 + log10( Options::zoomFactor() ) - log10( MINZOOM ) ) * ( 10 - planet->mag() ) / 10;
if( fakeStarSize > 15.0 )
fakeStarSize = 15.0;
float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
if( size < fakeStarSize && planet->name() != "Sun" && planet->name() != "Moon" ) {
setPointSize(fakeStarSize);
changePos(pos);
showPoint();
} else {
float sizemin = 1.0;
if( planet->name() == "Sun" || planet->name() == "Moon" )
sizemin = 8.0;
float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
if( size < fakeStarSize && planet->name() != "Sun" && planet->name() != "Moon" ) {
setPointSize(fakeStarSize);
if( size < sizemin )
size = sizemin;
//Options::showPlanetImages() &&
if( !planet->image().isNull() ) {
//Because Saturn has rings, we inflate its image size by a factor 2.5
if( planet->name() == "Saturn" )
size = int(2.5*size);
// Scale size exponentially so it is visible at large zooms
else if (planet->name() == "Pluto")
size = int(size*exp(1.5*size));
setPlanetPicSize(size);
changePos(pos);
showPoint();
} else {
float sizemin = 1.0;
if( planet->name() == "Sun" || planet->name() == "Moon" )
sizemin = 8.0;
float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
if( size < sizemin )
size = sizemin;
//Options::showPlanetImages() &&
if( !planet->image().isNull() ) {
//Because Saturn has rings, we inflate its image size by a factor 2.5
if( planet->name() == "Saturn" )
size = int(2.5*size);
// Scale size exponentially so it is visible at large zooms
else if (planet->name() == "Pluto")
size = int(size*exp(1.5*size));
setPlanetPicSize(size);
changePos(pos);
showPlanetPic();
} else { //Otherwise, draw a simple circle.
//drawEllipse( pos, size, size );
}
showPlanetPic();
} else { //Otherwise, draw a simple circle. Do we need it?
//drawEllipse( pos, size, size );
}
}
}
......
......@@ -15,15 +15,13 @@
***************************************************************************/
#ifndef PLANETNODE_H_
#define PLANETNODE_H_
#include <QSGNode>
#include "pointnode.h"
#include "skynode.h"
class QSGSimpleTextureNode;
class QImage;
class KSPlanetBase;
class RootNode;
class PointNode;
/** @class PlanetNode
*
......@@ -70,14 +68,15 @@ public:
virtual void changePos(QPointF pos) override;
virtual void update() override;
virtual void hide() override;
private:
PointNode* m_point;
PointNode *m_point;
// This opacity node is used to hide m_planetPic. m_point is subclass of QSGOpacityNode so it needs
// no explicit opacity node here.
QSGOpacityNode* m_planetOpacity;
QSGSimpleTextureNode* m_planetPic;
QSGOpacityNode *m_planetOpacity;
QSGSimpleTextureNode *m_planetPic;
};
......
......@@ -26,7 +26,7 @@
PointSourceNode::PointSourceNode(SkyObject * skyObject, RootNode* p, char sp, float size)
:SkyNode(skyObject), m_point(0), m_sizeMagLim(10.) // has to be changed when stars will be introduced
{
m_point = new PointNode(p,sp,starWidth(size));
m_point = new PointNode(p,starWidth(size),sp);
appendChildNode(m_point);
}
......
......@@ -35,11 +35,21 @@ QSGTexture* RootNode::getCachedTexture(int size, char spType) {
return m_textureCache[SkyMapLite::Instance()->harvardToIndex(spType)][size];
}
void RootNode::appendSkyNode(SkyNode * skyNode) {
void RootNode::appendSkyNode(SkyNode *skyNode) {
m_skyNodes.append(skyNode);
appendChildNode(skyNode);
}
void RootNode::prependSkyNode(SkyNode *skyNode) {
m_skyNodes.append(skyNode);
prependChildNode(skyNode);
}
void RootNode::removeSkyNode(SkyNode *skyNode) {
removeChildNode(skyNode);
m_skyNodes.removeOne(skyNode);
}
void RootNode::removeAllSkyNodes() {
for(int i = 0; i < m_skyNodes.length(); ++i) {
removeChildNode(m_skyNodes[i]);
......
......@@ -57,17 +57,25 @@ public:
inline int skyNodesCount() { return m_skyNodes.length(); }
/**
* @short returns a SkyNode in m_skyNodes with i index
* @short returns a SkyNode in m_skyNodes with index i
* @param i index of SkyNode
* @return desired SkyNode
*/
inline SkyNode * skyNodeAtIndex(int i) { return m_skyNodes[i]; }
inline SkyNode *skyNodeAtIndex(int i) { return m_skyNodes[i]; }
/**
* @brief Adds node to m_skyNodes and node tree
* @param skyNode pointer to skyNode that has to be added
*/
void appendSkyNode(SkyNode * skyNode);
void appendSkyNode(SkyNode *skyNode);
void prependSkyNode(SkyNode *skyNode);
/**
* @short remove given skyNode from m_skyNodes and a node tree
* @param skyNode pointer to skyNode that needs to be deleted
*/
void removeSkyNode(SkyNode *skyNode);
/**
* @short deletes all SkyNodes from m_skyNodes and node tree
......
......@@ -44,6 +44,10 @@ public:
/** @short short function that returns pointer to the current projector
* @return pointer to current projector of SkyMapLite
*/
// All children nodes allocated on heap are deleted automatically
//virtual ~SkyNode() { }
inline const Projector* projector() { return SkyMapLite::Instance()->projector(); }
/** @short short function to access SkyMapLite
......
......@@ -18,7 +18,9 @@
#include "projections/projector.h"
#include "solarsystemsinglecomponent.h"
#include "ksplanet.h"
#include "planetmoonscomponent.h"
#include "nodes/planetmoonsnode.h"
#include "nodes/planetnode.h"
#include "nodes/rootnode.h"
......@@ -31,8 +33,15 @@ PlanetsItem::PlanetsItem(QQuickItem* parent)
}
void PlanetsItem::addPlanet(SolarSystemSingleComponent* planetComp) {
if(!m_planetComponents.contains(planetComp) && !m_toAdd.contains(planetComp))
m_toAdd.append(planetComp);
if(!m_planetComponents.contains(planetComp) && !m_planetsToAdd.contains(planetComp)) {
m_planetsToAdd.append(planetComp);
}
}
void PlanetsItem::addMoons(PlanetMoonsComponent * moonsComponent) {
if(!m_moonsComponents.contains(moonsComponent) && !m_moonsToAdd.contains(moonsComponent)) {
m_moonsToAdd.append(moonsComponent);
}
}
SolarSystemSingleComponent * PlanetsItem::getParentComponent(SkyObject * planet) {
......@@ -57,26 +66,59 @@ QSGNode* PlanetsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upd
int pCompLen = m_planetComponents.length();
if(pCompLen > 0) {
/* If there are some planets that have been already displayed once then recreate them
in new instance of PlanetRootNode*/
for(int i = 0; i < pCompLen; ++i) {
n->appendSkyNode(new PlanetNode(m_planetComponents[i]->planet(), n));
in the new instance of RootNode*/
int mCompLen = m_moonsComponents.length();
foreach(SolarSystemSingleComponent * planetComp, m_planetComponents) {
KSPlanetBase *planet = planetComp->planet();
PlanetMoonsNode *pNode = new PlanetMoonsNode(planet, n);