File indexing completed on 2024-07-21 06:28:43

0001 /*
0002     SPDX-FileCopyrightText: 2018 Valentin Boettcher <valentin@boettcher.cf (do not hesitate to contact)>
0003     matrix               : @hiro98@tchncs.de
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "earthshadowcomponent.h"
0009 #include "skycomposite.h"
0010 #include "skypainter.h"
0011 #include "kstarsdata.h"
0012 
0013 //TODO: (Valentin) Error Handling
0014 EarthShadowComponent::EarthShadowComponent(SkyComposite *parent, KSEarthShadow *shadow) : SkyComponent(parent)
0015 {
0016     m_shadow = shadow;
0017     m_up_to_date = false;
0018 }
0019 
0020 void EarthShadowComponent::update(KSNumbers *)
0021 {
0022     KStarsData *data = KStarsData::Instance();
0023     m_shadow->EquatorialToHorizontal(data->lst(), data->geo()->lat());
0024 }
0025 
0026 void EarthShadowComponent::updateSolarSystemBodies(KSNumbers *num)
0027 {
0028     // don't bother if the moon is not in position
0029     if(!m_shadow->shouldUpdate()) { // TODO: There must be sth. more efficient
0030         m_up_to_date = false;
0031         return;
0032     }
0033 
0034     KStarsData *data = KStarsData::Instance();
0035     CachingDms *LST = data->lst();
0036     const CachingDms *lat = data->geo()->lat();
0037 
0038     m_shadow->findPosition(num, lat, LST);
0039     m_shadow->EquatorialToHorizontal(LST, lat);
0040     m_up_to_date = true;
0041 }
0042 
0043 void EarthShadowComponent::draw(SkyPainter *skyp)
0044 {
0045     // check if the shadow has been updated
0046     if(m_up_to_date && (m_shadow->isInEclipse()))
0047         skyp->drawEarthShadow(m_shadow);
0048 }