8#include "opsmiscsettings.h"
9#include "opsdslrsettings.h"
10#include <KConfigDialog>
12#include "cameraprocess.h"
13#include "camerastate.h"
14#include "capturedeviceadaptor.h"
15#include "captureadaptor.h"
16#include "refocusstate.h"
18#include "kstarsdata.h"
20#include "sequencejob.h"
21#include "placeholderpath.h"
22#include "ekos/manager.h"
23#include "ekos/auxiliary/darklibrary.h"
24#include "ekos/auxiliary/opticaltrainmanager.h"
25#include "ekos/auxiliary/profilesettings.h"
26#include "auxiliary/ksmessagebox.h"
28#include "scriptsmanager.h"
29#include "fitsviewer/fitsdata.h"
30#include "indi/driverinfo.h"
31#include "indi/indifilterwheel.h"
32#include "indi/indicamera.h"
33#include "indi/indirotator.h"
34#include "ekos/guide/guide.h"
35#include <basedevice.h>
37#include <ekos_capture_debug.h>
40#define MF_TIMER_TIMEOUT 90000
41#define MF_RA_DIFF_LIMIT 4
46#define KEY_FILTERS "filtersList"
47#define TAB_BUTTON_SIZE 20
57 qRegisterMetaType<CaptureState>(
"CaptureState");
58 qDBusRegisterMetaType<CaptureState>();
59 new CaptureAdaptor(
this);
61 m_moduleState.
reset(
new CaptureModuleState());
67 addButton->
setFixedSize(TAB_BUTTON_SIZE, TAB_BUTTON_SIZE);
68 addButton->
setToolTip(
i18n(
"<p>Add additional camera</p><p><b>WARNING</b>: This feature is experimental!</p>"));
71 cameraTabs->addTab(newTab,
"");
89 DarkLibrary::Instance()->setCaptureModule(
this);
92 connect(m_moduleState.
get(), &CaptureModuleState::dither,
this, &Capture::dither);
93 connect(m_moduleState.
get(), &CaptureModuleState::newLog,
this, &Capture::appendLogText);
105 m_OpsMiscSettings =
new OpsMiscSettings();
109 m_OpsDslrSettings =
new OpsDslrSettings();
110 page = dialog->
addPage(m_OpsDslrSettings,
i18n(
"DSLR"),
nullptr,
i18n(
"Capture DSLR"),
false);
118 newCamera.
reset(
new Camera(cameras().count(),
false,
nullptr));
121 const int tabIndex = cameraTabs->insertTab(std::max(0, cameraTabs->count() - 1), newCamera.
get(),
"new Camera");
122 cameraTabs->setCurrentIndex(tabIndex);
128 connect(newCamera.
get(), &Camera::newLog,
this, &Capture::appendLogText);
130 connect(newCamera.
get(), &Camera::sequenceChanged,
this, &Capture::sequenceChanged);
131 connect(newCamera.
get(), &Camera::newLocalPreview,
this, &Capture::newLocalPreview);
132 connect(newCamera.
get(), &Camera::dslrInfoRequested,
this, &Capture::dslrInfoRequested);
133 connect(newCamera.
get(), &Camera::trainChanged,
this, &Capture::trainChanged);
134 connect(newCamera.
get(), &Camera::settingsUpdated,
this, &Capture::settingsUpdated);
135 connect(newCamera.
get(), &Camera::filterManagerUpdated,
this, &Capture::filterManagerUpdated);
136 connect(newCamera.
get(), &Camera::newFilterStatus,
this, &Capture::newFilterStatus);
137 connect(newCamera.
get(), &Camera::ready,
this, &Capture::ready);
138 connect(newCamera.
get(), &Camera::newExposureProgress,
this, &Capture::newExposureProgress);
139 connect(newCamera.
get(), &Camera::captureComplete,
this, &Capture::captureComplete);
140 connect(newCamera.
get(), &Camera::captureStarting,
this, &Capture::captureStarting);
141 connect(newCamera.
get(), &Camera::captureAborted,
this, &Capture::captureAborted);
142 connect(newCamera.
get(), &Camera::checkFocus,
this, &Capture::checkFocus);
143 connect(newCamera.
get(), &Camera::newImage,
this, &Capture::newImage);
144 connect(newCamera.
get(), &Camera::runAutoFocus,
this, &Capture::runAutoFocus);
145 connect(newCamera.
get(), &Camera::resetFocusFrame,
this, &Capture::resetFocusFrame);
146 connect(newCamera.
get(), &Camera::abortFocus,
this, &Capture::abortFocus);
147 connect(newCamera.
get(), &Camera::adaptiveFocus,
this, &Capture::adaptiveFocus);
148 connect(newCamera.
get(), &Camera::meridianFlipStarted,
this, &Capture::meridianFlipStarted);
149 connect(newCamera.
get(), &Camera::captureTarget,
this, &Capture::captureTarget);
150 connect(newCamera.
get(), &Camera::guideAfterMeridianFlip,
this, &Capture::guideAfterMeridianFlip);
151 connect(newCamera.
get(), &Camera::newStatus,
this, &Capture::newStatus);
152 connect(newCamera.
get(), &Camera::suspendGuiding,
this, &Capture::suspendGuiding);
153 connect(newCamera.
get(), &Camera::resumeGuiding,
this, &Capture::resumeGuiding);
154 connect(newCamera.
get(), &Camera::resetNonGuidedDither,
this, &Capture::resetNonGuidedDither);
155 connect(newCamera.
get(), &Camera::driverTimedout,
this, &Capture::driverTimedout);
157 const QString train = findUnusedOpticalTrain();
160 newCamera->opticalTrainCombo->setCurrentText(train);
161 moduleState()->addCamera(newCamera);
168const QString Capture::findUnusedOpticalTrain()
170 QList<QString> names = OpticalTrainManager::Instance()->getTrainNames();
171 foreach(
auto cam, cameras())
177 return names.
first();
184 if (tabID < cameraTabs->count() && tabID < cameras().count())
186 auto cam = moduleState()->mutableCameras()[tabID];
188 if (cam->activeCamera() !=
nullptr)
190 auto name = cam->activeCamera()->getDeviceName();
191 cameraTabs->setTabText(tabID, name);
195 cam->state()->getRefocusState()->setForceInSeqAF(moduleState()->forceInSeqAF(cam->opticalTrain()));
198 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Unknown camera ID:" << tabID;
201 cameraTabs->setTabText(cameraTabs->currentIndex(),
"no camera");
207 return process()->setDome(device);
212 if (mainCamera()->m_standAlone)
214 if (name ==
"Mount" && mountInterface ==
nullptr)
216 qCDebug(KSTARS_EKOS_CAPTURE) <<
"Registering new Module (" << name <<
")";
217 mountInterface =
new QDBusInterface(
"org.kde.kstars",
"/KStars/Ekos/Mount",
224 if (mainCameraDevices()->getActiveCamera())
225 return mainCameraDevices()->getActiveCamera()->getDeviceName();
237 if (!mainCameraDevices()->getActiveCamera())
240 mainCameraState()->setSuspendGuidingOnDownload((mainCameraDevices()->getActiveCamera()->getChip(
241 ISD::CameraChip::GUIDE_CCD) == guideChip) ||
242 (guideChip->getCCD() == mainCameraDevices()->getActiveCamera() &&
243 mainCameraDevices()->getActiveCamera()->getDriverInfo()->getAuxInfo().value(
"mdpd",
false).toBool()));
249 for (
auto &cam : cameras())
250 if (trainname ==
"" || cam->opticalTrain() == trainname)
251 cam->setFocusStatus(newstate);
257 for (
auto &cam : cameras())
258 if (trainname ==
"" || cam->opticalTrain() == trainname)
259 cam->focusAdaptiveComplete(success);
264 if (mainCameraDevices()->filterWheel())
265 return mainCameraDevices()->filterWheel()->getDeviceName();
272 if (mainCameraDevices()->filterWheel())
274 mainCamera()->FilterPosCombo->setCurrentText(filter);
283 return mainCamera()->FilterPosCombo->currentText();
294 if (mainCamera()->opticalTrain() != train)
295 mainCamera()->selectOpticalTrain(train);
309 return cam->loadSequenceQueue(fileURL, targetName);
313void Capture::appendLogText(
const QString &text)
315 m_LogText.
insert(0,
i18nc(
"log entry; %1 is the date, %2 is the text",
"%1 %2",
316 KStarsData::Instance()->lt().toString(
"yyyy-MM-ddThh:mm:ss"), text));
318 qCInfo(KSTARS_EKOS_CAPTURE) << text;
323void Capture::clearLog()
331 Q_UNUSED(absTemperture);
333 for (
auto &cam : cameras())
334 if (trainname ==
"" || cam->opticalTrain() == trainname)
335 cam->state()->getRefocusState()->setFocusTemperatureDelta(focusTemperatureDelta);
341 moduleState()->setGuideDeviation(delta_ra, delta_dec);
348 mainCameraState()->setIgnoreJobProgress(
true);
361 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Cannot set the captured frames map for train" << train;
366 cam->state()->setCapturedFramesCount(signature, count);
369void Capture::setAlignStatus(
AlignState newstate)
372 mainCameraState()->setAlignState(newstate);
375void Capture::setGuideStatus(GuideState newstate)
378 moduleState()->setGuideStatus(newstate);
383 if (mainCameraDevices()->getActiveCamera() ==
nullptr)
386 return mainCameraDevices()->getActiveCamera()->setStreamLimits(maxBufferSize, maxPreviewFPS);
400 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Cannot start capturing for train" << train;
409 return cam->opticalTrain();
416 for (
auto cam : cameras())
423 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Cannot abort capturing for train" << train;
436 if (i < cameras().count())
437 return moduleState()->mutableCameras()[i];
440 qCWarning(KSTARS_EKOS_CAPTURE) <<
"Unknown camera ID:" << i;
441 return moduleState()->mutableCameras()[0];
445void Ekos::Capture::closeCameraTab(
int tabIndex)
447 cameraTabs->removeTab(tabIndex);
448 moduleState()->removeCamera(tabIndex);
450 cameraTabs->setCurrentIndex(std::max(0, tabIndex - 1));
453void Capture::checkCloseCameraTab(
int tabIndex)
456 if (tabIndex == cameraTabs->count() - 1)
459 if (moduleState()->mutableCameras()[tabIndex]->state()->isBusy())
465 moduleState()->mutableCameras()[tabIndex]->abort();
466 closeCameraTab(tabIndex);
474 KSMessageBox::Instance()->warningContinueCancel(
i18n(
"Camera %1 is busy. Abort to close?",
475 moduleState()->mutableCameras()[tabIndex]->activeCamera()->getDeviceName()),
i18n(
"Stop capturing"), 30,
false,
480 closeCameraTab(tabIndex);
486 if (cameras().
size() > 0)
487 return moduleState()->cameras()[0];
491 cms.
reset(
new CaptureModuleState());
500 for (
auto &cam : cameras())
502 if (cam->opticalTrain() == train)
503 return cam->m_cameraId;
510 cam->selectOpticalTrain(train);
511 return cam->m_cameraId;
517void Capture::setMountStatus(ISD::Mount::Status newState)
521 case ISD::Mount::MOUNT_PARKING:
522 case ISD::Mount::MOUNT_SLEWING:
523 case ISD::Mount::MOUNT_MOVING:
524 mainCamera()->previewB->setEnabled(
false);
525 mainCamera()->liveVideoB->setEnabled(
false);
529 if (mainCameraState()->isBusy() ==
false)
530 mainCamera()->startB->setEnabled(
false);
534 if (mainCameraState()->isBusy() ==
false)
536 mainCamera()->previewB->setEnabled(
true);
537 if (mainCameraDevices()->getActiveCamera())
538 mainCamera()->liveVideoB->setEnabled(mainCameraDevices()->getActiveCamera()->hasVideoStream());
539 mainCamera()->startB->setEnabled(
true);
546void Capture::setAlignResults(
double solverPA,
double ra,
double de,
double pixscale)
551 if (mainCameraDevices()->rotator() && mainCamera()->m_RotatorControlPanel)
552 mainCamera()->m_RotatorControlPanel->refresh(solverPA);
557 mainCameraState()->setMeridianFlipState(newstate);
558 connect(mainCameraState()->getMeridianFlipState().
get(), &MeridianFlipState::newLog,
this, &Capture::appendLogText);
559 connect(mainCameraState()->getMeridianFlipState().
get(), &MeridianFlipState::newMountMFStatus, moduleState().
get(),
560 &CaptureModuleState::updateMFMountState);
566 for (
auto &cam : cameras())
567 if (cam->process()->hasCoolerControl())
568 result |= cam->process()->hasCoolerControl();
575 for (
auto &cam : cameras())
576 if (cam->process()->hasCoolerControl())
577 result &= cam->process()->setCoolerControl(enable);
584 process()->removeDevice(device);
587QString Capture::getTargetName()
590 return activeJob()->getCoreProperty(SequenceJob::SJ_TargetName).
toString();
598 for (
auto &cam : cameras())
599 if (trainname ==
"" || cam->opticalTrain() == trainname)
600 cam->state()->getRefocusState()->setFocusHFR(newHFR, inAutofocus);
606 for (
auto &cam : cameras())
607 if (trainname ==
"" || cam->opticalTrain() == trainname)
609 cam->state()->getRefocusState()->setForceInSeqAF(requested);
611 moduleState()->setForceInSeqAF(requested, trainname);
void setHFR(double newHFR, int position, bool inAutofocus, const QString &trainname)
setHFR Receive the measured HFR value of the latest frame
bool setVideoLimits(uint16_t maxBufferSize, uint16_t maxPreviewFPS)
setVideoLimits sets the buffer size and max preview fps for live preview
bool setDome(ISD::Dome *device)
setDome Set dome device
void updateCamera(int tabID, bool isValid)
Update the camera.
void inSequenceAFRequested(bool requested, const QString &trainname)
inSequenceAFRequested Focuser informs that the user wishes an AF run as soon as possible.
QSharedPointer< CameraProcess > process() const
process shortcut for the process engine
void setFocusStatus(FocusState newstate, const QString &trainname)
setFocusStatus Forward the new focus state to the capture module state machine
void setFocusTemperatureDelta(double focusTemperatureDelta, double absTemperature, const QString &trainname)
setFocusTemperatureDelta update the focuser's temperature delta
void setGuideDeviation(double delta_ra, double delta_dec)
setGuideDeviation Set the guiding deviation as measured by the guiding module.
void registerNewModule(const QString &name)
registerNewModule Register an Ekos module as it arrives via DBus and create the appropriate DBus inte...
void focusAdaptiveComplete(bool success, const QString &trainname)
focusAdaptiveComplete Forward the new focus state to the capture module state machine
int findCamera(QString train, bool addIfNecessary)
find the camera using the given train
void removeDevice(const QSharedPointer< ISD::GenericDevice > &device)
Generic method for removing any connected device.
CameraChip class controls a particular chip in camera.
Class handles control of INDI dome devices.
KPageWidgetItem * addPage(QWidget *page, const QString &itemName, const QString &pixmapName=QString(), const QString &header=QString(), bool manage=true)
void setIcon(const QIcon &icon)
Q_SCRIPTABLE bool hasCoolerControl()
DBUS interface function.
void prepareGUI()
prepareGUI Perform once only GUI prep processing
Q_SCRIPTABLE Q_NOREPLY void abort(QString train="")
DBUS interface function.
Q_SCRIPTABLE Q_NOREPLY void ignoreSequenceHistory()
DBUS interface function.
Q_SCRIPTABLE QString start(QString train="")
DBUS interface function.
Q_SCRIPTABLE bool loadSequenceQueue(const QString &fileURL, QString train="", bool isLead=true, QString targetName="")
DBUS interface function.
Q_SCRIPTABLE bool setCoolerControl(bool enable)
DBUS interface function.
Q_SCRIPTABLE bool setFilter(const QString &filter)
DBUS interface function.
Q_SCRIPTABLE Q_NOREPLY void setCapturedFramesMap(const QString &signature, int count, QString train="")
DBUS interface function.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
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)
QString toString() const const