Kstars

observatorymodel.cpp
1 /* Ekos Observatory Module
2  SPDX-FileCopyrightText: Wolfgang Reissenberger <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "observatorymodel.h"
8 #include "Options.h"
9 
10 namespace Ekos
11 {
12 
13 ObservatoryModel::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 
24 void ObservatoryModel::setDomeModel(ObservatoryDomeModel *model) {
25  mDomeModel = model;
26  if (model != nullptr)
27  {
28  connect(mDomeModel, &ObservatoryDomeModel::newStatus, [this](ISD::Dome::Status s) { Q_UNUSED(s); updateStatus(); });
29  connect(mDomeModel, &ObservatoryDomeModel::newParkStatus, [this](ISD::ParkStatus s) { Q_UNUSED(s); updateStatus(); });
30  connect(mDomeModel, &ObservatoryDomeModel::newShutterStatus, [this](ISD::Dome::ShutterStatus s) { Q_UNUSED(s); updateStatus(); });
31  if (mWeatherModel != nullptr)
32  connect(mWeatherModel, &ObservatoryWeatherModel::execute, mDomeModel, &ObservatoryDomeModel::execute);
33  }
34  else
35  {
36  if (mWeatherModel != nullptr)
37  disconnect(mWeatherModel, &ObservatoryWeatherModel::execute, mDomeModel, &ObservatoryDomeModel::execute);
38  }
39 
40  updateStatus();
41 }
42 
43 void ObservatoryModel::setWeatherModel(ObservatoryWeatherModel *model) {
44  mWeatherModel = model;
45  if (model != nullptr)
46  {
47  connect(mWeatherModel, &ObservatoryWeatherModel::newStatus, [this](ISD::Weather::Status s) { Q_UNUSED(s); updateStatus(); });
48  if (mDomeModel != nullptr)
49  {
50  connect(mWeatherModel, &ObservatoryWeatherModel::execute, mDomeModel, &ObservatoryDomeModel::execute);
51  }
52  }
53  else
54  {
55  if (mDomeModel != nullptr)
56  disconnect(mWeatherModel, &ObservatoryWeatherModel::execute, mDomeModel, &ObservatoryDomeModel::execute);
57  }
58  updateStatus();
59 }
60 
61 
62 void ObservatoryModel::setStatusControl(ObservatoryStatusControl control)
63 {
64  mStatusControl = control;
65  Options::setObservatoryStatusUseDome(control.useDome);
66  Options::setObservatoryStatusUseShutter(control.useShutter);
67  Options::setObservatoryStatusUseWeather(control.useWeather);
68  updateStatus();
69 }
70 
71 bool ObservatoryModel::isReady()
72 {
73  // dome relevant for the status and dome is ready
74  if (mStatusControl.useDome && (getDomeModel() == nullptr || getDomeModel()->parkStatus() != ISD::PARK_UNPARKED))
75  return false;
76 
77  // shutter relevant for the status and shutter open
78  if (mStatusControl.useShutter && (getDomeModel() == nullptr ||
79  (getDomeModel()->hasShutter() && getDomeModel()->shutterStatus() != ISD::Dome::SHUTTER_OPEN)))
80  return false;
81 
82  // weather relevant for the status and weather is OK
83  if (mStatusControl.useWeather && (getWeatherModel() == nullptr || getWeatherModel()->status() != ISD::Weather::WEATHER_OK))
84  return false;
85 
86  return true;
87 }
88 
89 void ObservatoryModel::updateStatus()
90 {
91  emit newStatus(isReady());
92 }
93 
94 void ObservatoryModel::makeReady()
95 {
96  // dome relevant for the status and dome is ready
97  if (mStatusControl.useDome && (getDomeModel() == nullptr || getDomeModel()->status() != ISD::Dome::DOME_IDLE))
98  getDomeModel()->unpark();
99 
100  // shutter relevant for the status and shutter open
101  if (mStatusControl.useShutter && (getDomeModel() == nullptr ||
102  (getDomeModel()->hasShutter() && getDomeModel()->shutterStatus() != ISD::Dome::SHUTTER_OPEN)))
103  getDomeModel()->openShutter();
104 
105  // weather relevant for the status and weather is OK
106  // Haha, weather we can't change
107 }
108 
109 }
Ekos is an advanced Astrophotography tool for Linux. It is based on a modular extensible framework to...
Definition: align.cpp:70
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:00:02 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.