Kstars

observatorymodel.cpp
1/* Ekos Observatory Module
2 SPDX-FileCopyrightText: Wolfgang Reissenberger <sterne-jaeger@t-online.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "observatorymodel.h"
8#include "Options.h"
9
10namespace Ekos
11{
12
13ObservatoryModel::ObservatoryModel()
14{
15
16 mStatusControl.useDome = Options::observatoryStatusUseDome();
17 mStatusControl.useShutter = Options::observatoryStatusUseShutter();
18 mStatusControl.useWeather = Options::observatoryStatusUseWeather();
19
20 setDomeModel(new ObservatoryDomeModel());
21 setWeatherModel(new ObservatoryWeatherModel());
22}
23
24void ObservatoryModel::setDomeModel(ObservatoryDomeModel *model)
25{
26 mDomeModel = model;
27 if (model != nullptr)
28 {
29 connect(mDomeModel, &ObservatoryDomeModel::newStatus, [this](ISD::Dome::Status s)
30 {
31 Q_UNUSED(s);
32 updateStatus();
33 });
34 connect(mDomeModel, &ObservatoryDomeModel::newParkStatus, [this](ISD::ParkStatus s)
35 {
36 Q_UNUSED(s);
37 updateStatus();
38 });
39 connect(mDomeModel, &ObservatoryDomeModel::newShutterStatus, [this](ISD::Dome::ShutterStatus s)
40 {
41 Q_UNUSED(s);
42 updateStatus();
43 });
44 if (mWeatherModel != nullptr)
45 connect(mWeatherModel, &ObservatoryWeatherModel::execute, mDomeModel, &ObservatoryDomeModel::execute);
46 }
47 else
48 {
49 if (mWeatherModel != nullptr)
50 disconnect(mWeatherModel, &ObservatoryWeatherModel::execute, mDomeModel, &ObservatoryDomeModel::execute);
51 }
52
53 updateStatus();
54}
55
56void ObservatoryModel::setWeatherModel(ObservatoryWeatherModel *model)
57{
58 mWeatherModel = model;
59 if (model != nullptr)
60 {
61 connect(mWeatherModel, &ObservatoryWeatherModel::newStatus, [this](ISD::Weather::Status s)
62 {
63 Q_UNUSED(s);
64 updateStatus();
65 });
66 if (mDomeModel != nullptr)
67 {
68 connect(mWeatherModel, &ObservatoryWeatherModel::execute, mDomeModel, &ObservatoryDomeModel::execute);
69 }
70 }
71 else
72 {
73 if (mDomeModel != nullptr)
74 disconnect(mWeatherModel, &ObservatoryWeatherModel::execute, mDomeModel, &ObservatoryDomeModel::execute);
75 }
76 updateStatus();
77}
78
79
80void ObservatoryModel::setStatusControl(ObservatoryStatusControl control)
81{
82 mStatusControl = control;
83 Options::setObservatoryStatusUseDome(control.useDome);
84 Options::setObservatoryStatusUseShutter(control.useShutter);
85 Options::setObservatoryStatusUseWeather(control.useWeather);
86 updateStatus();
87}
88
89bool ObservatoryModel::isReady()
90{
91 // dome relevant for the status and dome is ready
92 if (mStatusControl.useDome && (getDomeModel() == nullptr || getDomeModel()->parkStatus() != ISD::PARK_UNPARKED))
93 return false;
94
95 // shutter relevant for the status and shutter open
96 if (mStatusControl.useShutter && (getDomeModel() == nullptr ||
97 (getDomeModel()->hasShutter() && getDomeModel()->shutterStatus() != ISD::Dome::SHUTTER_OPEN)))
98 return false;
99
100 // weather relevant for the status and weather is OK
101 if (mStatusControl.useWeather && (getWeatherModel() == nullptr || getWeatherModel()->status() != ISD::Weather::WEATHER_OK))
102 return false;
103
104 return true;
105}
106
107void ObservatoryModel::updateStatus()
108{
109 emit newStatus(isReady());
110}
111
112void ObservatoryModel::makeReady()
113{
114 // dome relevant for the status and dome is ready
115 if (mStatusControl.useDome && (getDomeModel() == nullptr || getDomeModel()->status() != ISD::Dome::DOME_IDLE))
116 getDomeModel()->unpark();
117
118 // shutter relevant for the status and shutter open
119 if (mStatusControl.useShutter && (getDomeModel() == nullptr ||
120 (getDomeModel()->hasShutter() && getDomeModel()->shutterStatus() != ISD::Dome::SHUTTER_OPEN)))
121 getDomeModel()->openShutter();
122
123 // weather relevant for the status and weather is OK
124 // Haha, weather we can't change
125}
126
127}
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.