7#include "focusmodule.h"
11#include "auxiliary/ksmessagebox.h"
12#include "ekos/auxiliary/opticaltrainmanager.h"
13#include "kstarsdata.h"
16#include "ekos_focus_debug.h"
18#define TAB_BUTTON_SIZE 20
23FocusModule::FocusModule()
28 focusTabs->setTabsClosable(
false);
35 addButton->
setFixedSize(TAB_BUTTON_SIZE, TAB_BUTTON_SIZE);
36 addButton->
setToolTip(
i18n(
"<p>Add additional focuser</p><p><b>WARNING</b>: This feature is experimental!</p>"));
39 FocusModule::addFocuser();
42 focusTabs->addTab(newTab,
"");
54FocusModule::~FocusModule()
56 m_FocusLogFile.
close();
61 if (i < m_Focusers.count())
65 qCWarning(KSTARS_EKOS_FOCUS) <<
"Unknown focuser ID:" << i;
73 if (m_Focusers.size() <= 0)
76 newFocuser.
reset(
new Focus(0));
77 m_Focusers.append(newFocuser);
82void FocusModule::checkFocus(
double requiredHFR,
const QString &trainname)
86 for (
auto focuser : m_Focusers)
87 if (trainname ==
"" || focuser->opticalTrain() == trainname)
89 focuser->checkFocus(requiredHFR);
96 newFocuser->checkFocus(requiredHFR);
100void FocusModule::runAutoFocus(
const AutofocusReason autofocusReason,
const QString &reasonInfo,
const QString &trainname)
104 for (
auto focuser : m_Focusers)
105 if (trainname ==
"" || focuser->opticalTrain() == trainname)
107 focuser->runAutoFocus(autofocusReason, reasonInfo);
114 newFocuser->runAutoFocus(autofocusReason, reasonInfo);
118void FocusModule::resetFrame(
const QString &trainname)
122 for (
auto focuser : m_Focusers)
123 if (trainname ==
"" || focuser->opticalTrain() == trainname)
125 focuser->resetFrame();
132 newFocuser->resetFrame();
136void FocusModule::abort(
const QString &trainname)
140 for (
auto focuser : m_Focusers)
141 if (trainname ==
"" || focuser->opticalTrain() == trainname)
154void FocusModule::adaptiveFocus(
const QString &trainname)
158 for (
auto focuser : m_Focusers)
159 if (trainname ==
"" || focuser->opticalTrain() == trainname)
161 focuser->adaptiveFocus();
168 newFocuser->adaptiveFocus();
172void FocusModule::meridianFlipStarted(
const QString &trainname)
176 for (
auto focuser : m_Focusers)
177 if (trainname ==
"" || focuser->opticalTrain() == trainname)
179 focuser->meridianFlipStarted();
186 newFocuser->meridianFlipStarted();
190void FocusModule::setMountStatus(ISD::Mount::Status newState)
193 for (
auto focuser : m_Focusers)
194 focuser->setMountStatus(newState);
197void FocusModule::setMountCoords(
const SkyPoint &position, ISD::Mount::PierSide pierSide,
const dms &ha)
200 for (
auto focuser : m_Focusers)
201 focuser->setMountCoords(position, pierSide, ha);
209 for (
auto &oneSource : m_TemperatureSources)
211 if (oneSource->getDeviceName() == device->getDeviceName())
215 m_TemperatureSources.append(device);
218 for (
auto focuser : m_Focusers)
219 focuser->updateTemperatureSources(m_TemperatureSources);
224void FocusModule::syncCameraInfo(
const char* devicename)
227 for (
auto focuser : m_Focusers)
228 if (focuser->camera() == devicename)
229 focuser->syncCameraInfo();
232void FocusModule::clearLog()
238void FocusModule::appendLogText(
const QString &logtext)
240 m_LogText.
insert(0,
i18nc(
"log entry; %1 is the date, %2 is the text",
"%1 %2",
241 KStarsData::Instance()->lt().
toString(
"yyyy-MM-ddThh:mm:ss"), logtext));
243 qCInfo(KSTARS_EKOS_FOCUS) << logtext;
245 emit newLog(logtext);
248void FocusModule::appendFocusLogText(
const QString &lines)
250 if (Options::focusLogging())
253 if (!m_FocusLogFile.
exists())
257 dir.mkpath(
"focuslogs");
259 if (m_FocusLogEnabled)
262 header <<
"date, time, position, temperature, filter, HFR, altitude\n";
266 qCWarning(KSTARS_EKOS_FOCUS) <<
"Failed to open focus log file: " << m_FocusLogFileName;
269 if (m_FocusLogEnabled)
282 for (
auto &oneSource : m_TemperatureSources)
283 if (oneSource->getDeviceName() == deviceRemoved->getDeviceName())
284 m_TemperatureSources.removeAll(oneSource);
287 for (
auto focuser : m_Focusers)
288 focuser->removeDevice(deviceRemoved);
294 connect(newFocuser.
get(), &Focus::focuserChanged,
this, &FocusModule::updateFocuser);
295 connect(newFocuser.
get(), &Focus::suspendGuiding,
this, &FocusModule::suspendGuiding);
296 connect(newFocuser.
get(), &Focus::resumeGuiding,
this, &FocusModule::resumeGuiding);
297 connect(newFocuser.
get(), &Focus::resumeGuiding,
this, &FocusModule::resumeGuiding);
298 connect(newFocuser.
get(), &Focus::newStatus,
this, &FocusModule::newStatus);
299 connect(newFocuser.
get(), &Focus::focusAdaptiveComplete,
this, &FocusModule::focusAdaptiveComplete);
300 connect(newFocuser.
get(), &Focus::newHFR,
this, &FocusModule::newHFR);
301 connect(newFocuser.
get(), &Focus::newFocusTemperatureDelta,
this, &FocusModule::newFocusTemperatureDelta);
302 connect(newFocuser.
get(), &Focus::inSequenceAF,
this, &FocusModule::inSequenceAF);
303 connect(newFocuser.
get(), &Focus::newLog,
this, &FocusModule::appendLogText);
304 connect(newFocuser.
get(), &Focus::newFocusLog,
this, &FocusModule::appendFocusLogText);
310 newFocuser.
reset(
new Focus(m_Focusers.count()));
313 const int tabIndex = focusTabs->insertTab(std::max(0, focusTabs->count() - 1), newFocuser.
get(),
"new Focuser");
314 focusTabs->setCurrentIndex(tabIndex);
319 const QString train = findUnusedOpticalTrain();
321 m_Focusers.append(newFocuser);
324 newFocuser->opticalTrainCombo->setCurrentText(train);
327 newFocuser->updateTemperatureSources(m_TemperatureSources);
329 if (trainname !=
"" && newFocuser->opticalTrainCombo->findText(trainname))
330 newFocuser->opticalTrainCombo->setCurrentText(trainname);
333 updateFocuser(tabIndex,
true);
334 initFocuser(newFocuser);
339void FocusModule::updateFocuser(
int tabID,
bool isValid)
343 if (tabID < focusTabs->count() && tabID < m_Focusers.count() && !m_Focusers[tabID].isNull())
345 const QString name = m_Focusers[tabID]->m_Focuser !=
nullptr ?
346 m_Focusers[tabID]->m_Focuser->getDeviceName() :
348 focusTabs->setTabText(tabID, name);
351 qCWarning(KSTARS_EKOS_FOCUS) <<
"Unknown focuser ID:" << tabID;
354 focusTabs->setTabText(focusTabs->currentIndex(),
"no focuser");
357void FocusModule::closeFocuserTab(
int tabIndex)
360 if (tabIndex == focusTabs->count() - 1)
363 focusTabs->removeTab(tabIndex);
365 focusTabs->setCurrentIndex(std::max(0, tabIndex - 1));
367 auto focuser = m_Focusers.at(tabIndex);
368 focuser->disconnect(
this);
369 focuser->disconnectSyncSettings();
370 m_Focusers.removeAt(tabIndex);
373void FocusModule::checkCloseFocuserTab(
int tabIndex)
375 if (m_Focusers[tabIndex]->isBusy())
381 m_Focusers[tabIndex]->abort();
382 closeFocuserTab(tabIndex);
390 KSMessageBox::Instance()->warningContinueCancel(
i18n(
"Camera %1 is busy. Abort to close?",
391 m_Focusers[tabIndex]->m_Focuser->getDeviceName()),
i18n(
"Stop capturing"), 30,
false,
i18n(
"Abort"));
395 closeFocuserTab(tabIndex);
400const QString FocusModule::findUnusedOpticalTrain()
402 QList<QString> names = OpticalTrainManager::Instance()->getTrainNames();
403 foreach(
auto focuser, m_Focusers)
404 names.
removeAll(focuser->opticalTrain());
409 return names.
first();
The sky coordinates of a point in the sky.
An angle, stored as degrees, but expressible in many ways.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
Ekos is an advanced Astrophotography tool for Linux.
QString name(GameStandardAction id)
KIOCORE_EXPORT QString dir(const QString &fileClass)
QDateTime currentDateTime()
QString toString(QStringView format, QCalendar cal) const const
QString filePath(const QString &fileName) const const
bool exists(const QString &fileName)
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
void setFileName(const QString &name)
virtual void close() override
QIcon fromTheme(const QString &name)
iterator insert(const_iterator before, parameter_type value)
bool isEmpty() const const
qsizetype removeAll(const AT &t)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
bool isNull() const const