File indexing completed on 2024-04-28 15:10:48
0001 #include <QSGSimpleTextureNode> 0002 0003 #include "planetnode.h" 0004 #include "pointsourcenode.h" 0005 #include "planetmoonsnode.h" 0006 #include "planetmoons.h" 0007 #include "ksplanetbase.h" 0008 #include "skylabeler.h" 0009 0010 #include "../rootnode.h" 0011 #include "../labelsitem.h" 0012 0013 #include "Options.h" 0014 0015 PlanetMoonsNode::PlanetMoonsNode(KSPlanetBase *planet, RootNode *parentNode) 0016 : SkyNode(planet), m_rootNode(parentNode), pmoons(0), m_planetNode(new PlanetNode(planet, parentNode)), 0017 m_labelType(LabelsItem::label_t::NO_LABEL) 0018 //For now we consider labels only in case of Jupiter 0019 { 0020 appendChildNode(m_planetNode); 0021 } 0022 0023 PlanetMoonsNode::~PlanetMoonsNode() 0024 { 0025 if (m_labelType != LabelsItem::label_t::NO_LABEL) 0026 { 0027 m_rootNode->labelsItem()->deleteLabels(m_labelType); 0028 } 0029 } 0030 0031 void PlanetMoonsNode::update() 0032 { 0033 updateMoons(); 0034 m_planetNode->update(); 0035 } 0036 0037 void PlanetMoonsNode::hide() 0038 { 0039 m_planetNode->hide(); 0040 0041 foreach (PointSourceNode *moon, m_moonNodes) 0042 { 0043 moon->hide(); 0044 } 0045 } 0046 0047 //TODO updateMoons and destructor 0048 void PlanetMoonsNode::updateMoons() 0049 { 0050 //In order to get the z-order right for the moons and the planet, 0051 //we need to first append the planet (both m_point and m_planetPic) then append all nodes for moons 0052 //that are nearer than the planet and then prepend nodes for moons that are further than the planet 0053 if (pmoons) 0054 { 0055 int nmoons = pmoons->nMoons(); 0056 if (m_labelType == LabelsItem::label_t::NO_LABEL) 0057 { 0058 m_labelType = LabelsItem::label_t::JUPITER_MOON_LABEL; 0059 } 0060 0061 if (!m_moonNodes.length()) //Initialize PointSourceNodes used for drawing moons 0062 { 0063 for (int i = 0; i < nmoons; ++i) 0064 { 0065 m_moonNodes.append(new PointSourceNode(pmoons->moon(i), m_rootNode, m_labelType)); 0066 } 0067 } 0068 0069 removeAllChildNodes(); // Clear all child nodes so that we can render moons according to z-order 0070 0071 // We need to reappend node that draws the planet 0072 appendChildNode(m_planetNode); 0073 0074 bool drawLabel = true; 0075 0076 if (!(Options::showPlanetNames() && Options::zoomFactor() > 50. * MINZOOM)) 0077 { 0078 drawLabel = false; 0079 } 0080 0081 for (int i = 0; i < nmoons; ++i) 0082 { 0083 if (pmoons->z(i) < 0.0) //Moon is nearer than the planet 0084 { 0085 appendChildNode(m_moonNodes[i]); 0086 m_moonNodes[i]->SkyNode::update(drawLabel); 0087 } 0088 else 0089 { 0090 //Draw Moons that are further than the planet 0091 //skyp->drawPointSource( pmoons->moon(i), pmoons->moon(i)->mag() ); 0092 prependChildNode(m_moonNodes[i]); 0093 m_moonNodes[i]->SkyNode::update(drawLabel); 0094 } 0095 } 0096 0097 /* //Draw Moon name labels if at high zoom 0098 return; 0099 for ( int i=0; i<nmoons; ++i ) { 0100 0101 if (planet ==KSPlanetBase::SATURN) 0102 SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::SATURN_MOON_LABEL ); 0103 else 0104 0105 SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::JUPITER_MOON_LABEL ); 0106 }*/ 0107 } 0108 }