Commit 8b4072a6 authored by Jasem Mutlaq's avatar Jasem Mutlaq

Add support to telescope center locking in the INDI tool bar

parent b44d8b45
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="KStars" version="3">
<kpartgui name="KStars" version="4">
<MenuBar noMerge="1">
<Menu name="file" noMerge="1"><text>&amp;File</text>
<Action name="new_window" />
......@@ -182,6 +182,7 @@
<Action name="show_ekos" />
<Action name="show_control_panel" />
<Action name="show_fits_viewer" />
<Action name="lock_telescope" />
</ToolBar>
</kpartgui>
......@@ -110,10 +110,12 @@ void GUIManager::closeEvent(QCloseEvent * /*event*/)
if (ks)
{
QAction *a = KStars::Instance()->actionCollection()->action( "show_control_panel" );
a->setChecked(false);
}
QAction *showINDIPanel = KStars::Instance()->actionCollection()->action( "show_control_panel" );
showINDIPanel->setChecked(false);
QAction *centerTelescope = KStars::Instance()->actionCollection()->action( "lock_telescope" );
centerTelescope->setChecked(false);
}
}
void GUIManager::hideEvent(QHideEvent * /*event*/)
......@@ -132,6 +134,9 @@ void GUIManager::showEvent(QShowEvent * /*event*/)
QAction *a = KStars::Instance()->actionCollection()->action( "show_control_panel" );
a->setEnabled(true);
a->setChecked(true);
a = KStars::Instance()->actionCollection()->action( "lock_telescope" );
a->setEnabled(true);
}
/*********************************************************************
......@@ -140,23 +145,26 @@ void GUIManager::showEvent(QShowEvent * /*event*/)
*********************************************************************/
void GUIManager::updateStatus()
{
QAction *a = KStars::Instance()->actionCollection()->action( "show_control_panel" );
QAction *showINDIPanel = KStars::Instance()->actionCollection()->action( "show_control_panel" );
//if (clients.size() == 0)
if (guidevices.count() == 0)
{
KMessageBox::error(0, i18n("No INDI devices currently running. To run devices, please select devices from the Device Manager in the devices menu."));
a->setChecked(false);
showINDIPanel->setChecked(false);
showINDIPanel->setEnabled(false);
QAction *centerTelescope = KStars::Instance()->actionCollection()->action( "lock_telescope" );
centerTelescope->setChecked(false);
centerTelescope->setEnabled(false);
return;
}
a->setChecked(true);
showINDIPanel->setChecked(true);
raise();
activateWindow();
showNormal();
}
INDI_D * GUIManager::findGUIDevice(const QString &deviceName)
......@@ -254,10 +262,13 @@ void GUIManager::removeDevice(DeviceInfo *di)
if (guidevices.isEmpty())
{
QAction *a = KStars::Instance()->actionCollection()->action( "show_control_panel" );
a->setEnabled(false);
}
QAction *showINDIPanel = KStars::Instance()->actionCollection()->action( "show_control_panel" );
showINDIPanel->setEnabled(false);
QAction *centerTelescope = KStars::Instance()->actionCollection()->action( "lock_telescope" );
centerTelescope->setChecked(false);
centerTelescope->setEnabled(false);
}
}
void GUIManager::buildDevice(DeviceInfo *di)
......
......@@ -145,7 +145,7 @@ typedef enum { FRAME_LIGHT,FRAME_BIAS, FRAME_DARK,FRAME_FLAT} CCDFrameType;
typedef enum { SINGLE_BIN, DOUBLE_BIN, TRIPLE_BIN,QUADRAPLE_BIN} CCDBinType;
typedef enum { INDI_SEND_COORDS, INDI_ENGAGE_TRACKING, INDI_SET_PORT, INDI_CONNECT, INDI_DISCONNECT, INDI_SET_FILTER} DeviceCommand;
typedef enum { INDI_SEND_COORDS, INDI_ENGAGE_TRACKING, INDI_CENTER_LOCK, INDI_CENTER_UNLOCK, INDI_SET_PORT, INDI_CONNECT, INDI_DISCONNECT, INDI_SET_FILTER} DeviceCommand;
typedef enum { SOURCE_MANUAL, SOURCE_FLATCAP, SOURCE_WALL, SOURCE_DAWN_DUSK, SOURCE_DARKCAP } FlatFieldSource;
......
......@@ -28,7 +28,13 @@ Telescope::Telescope(GDInterface *iPtr) : DeviceDecorator(iPtr)
dType = KSTARS_TELESCOPE;
minAlt=-1;
maxAlt=-1;
EqCoordPreviousState=IPS_IDLE;
EqCoordPreviousState=IPS_IDLE;
centerLockTimer = new QTimer(this);
// Set it for 5 seconds for now as not to spam the display update
centerLockTimer->setInterval(5000);
centerLockTimer->setSingleShot(true);
connect(centerLockTimer, &QTimer::timeout, this, [this]() { runCommand(INDI_CENTER_LOCK); });
}
Telescope::~Telescope()
......@@ -113,6 +119,10 @@ void Telescope::processNumber(INumberVectorProperty *nvp)
if (RA == NULL || DEC == NULL)
return;
currentCoord.setRA(RA->value);
currentCoord.setDec(DEC->value);
currentCoord.EquatorialToHorizontal(KStars::Instance()->data()->lst(), KStars::Instance()->data()->geo()->lat());
if (nvp->s == IPS_BUSY && EqCoordPreviousState != IPS_BUSY)
{
if (getStatus() != MOUNT_PARKING)
......@@ -121,14 +131,15 @@ void Telescope::processNumber(INumberVectorProperty *nvp)
else if (EqCoordPreviousState == IPS_BUSY && nvp->s == IPS_OK)
{
KNotification::event( QLatin1String( "SlewCompleted" ) , i18n("Mount arrived at target location"));
double maxrad = 1000.0/Options::zoomFactor();
currentObject = KStarsData::Instance()->skyComposite()->objectNearest(&currentCoord, maxrad );
if (currentObject != NULL)
emit newTarget(currentObject->name());
}
EqCoordPreviousState = nvp->s;
currentCoord.setRA(RA->value);
currentCoord.setDec(DEC->value);
currentCoord.EquatorialToHorizontal(KStars::Instance()->data()->lst(), KStars::Instance()->data()->geo()->lat());
KStars::Instance()->map()->update();
}
else if (!strcmp(nvp->name, "HORIZONTAL_COORD"))
......@@ -171,6 +182,7 @@ void Telescope::processSwitch(ISwitchVectorProperty *svp)
{
parkStatus = PARK_PARKING;
KNotification::event( QLatin1String( "MountParking" ) , i18n("Mount parking is in progress"));
currentObject = NULL;
}
else if (svp->s == IPS_BUSY && sp->s == ISS_OFF && parkStatus != PARK_UNPARKING)
{
......@@ -181,11 +193,13 @@ void Telescope::processSwitch(ISwitchVectorProperty *svp)
{
parkStatus = PARK_PARKED;
KNotification::event( QLatin1String( "MountParked" ) , i18n("Mount parked"));
currentObject = NULL;
}
else if (svp->s == IPS_OK && sp->s == ISS_OFF && parkStatus != PARK_UNPARKED)
{
parkStatus = PARK_UNPARKED;
KNotification::event( QLatin1String( "MountUnparked" ) , i18n("Mount unparked"));
currentObject = NULL;
}
}
}
......@@ -368,6 +382,31 @@ bool Telescope::runCommand(int command, void *ptr)
}
break;
case INDI_CENTER_LOCK:
{
//if (currentObject == NULL || KStars::Instance()->map()->focusObject() != currentObject)
if (Options::isTracking() == false || currentCoord.angularDistanceTo(KStars::Instance()->map()->focus()).Degrees() > 0.5)
{
SkyPoint J2000Coord(currentCoord.ra(), currentCoord.dec());
J2000Coord.apparentCoord(KStars::Instance()->data()->ut().djd(), (long double) J2000);
currentCoord.setRA0(J2000Coord.ra());
currentCoord.setDec0(J2000Coord.dec());
//KStars::Instance()->map()->setClickedPoint(&currentCoord);
//KStars::Instance()->map()->slotCenter();
KStars::Instance()->map()->setDestination(currentCoord);
KStars::Instance()->map()->setFocusPoint(&currentCoord);
KStars::Instance()->map()->setFocusObject(currentObject);
Options::setIsTracking( true );
}
centerLockTimer->start();
}
break;
case INDI_CENTER_UNLOCK:
KStars::Instance()->map()->stopTracking();
centerLockTimer->stop();
break;
default:
return DeviceDecorator::runCommand(command, ptr);
break;
......@@ -493,9 +532,9 @@ bool Telescope::sendCoords(SkyPoint *ScopeTarget)
}
double maxrad = 1000.0/Options::zoomFactor();
SkyObject *so = KStarsData::Instance()->skyComposite()->objectNearest(ScopeTarget, maxrad );
if (so)
emit newTarget(so->name());
currentObject = KStarsData::Instance()->skyComposite()->objectNearest(ScopeTarget, maxrad );
if (currentObject)
emit newTarget(currentObject->name());
return true;
......
......@@ -12,6 +12,8 @@
#include "indistd.h"
class SkyObject;
namespace ISD
{
......@@ -100,6 +102,8 @@ private:
double minAlt,maxAlt;
ParkStatus parkStatus = PARK_UNKNOWN;
IPState EqCoordPreviousState;
QTimer *centerLockTimer=NULL;
SkyObject *currentObject=NULL;
};
......
......@@ -104,10 +104,12 @@
#include <KSharedConfig>
#ifdef HAVE_INDI
#include <basedevice.h>
#include "indi/telescopewizardprocess.h"
#include "indi/opsindi.h"
#include "indi/drivermanager.h"
#include "indi/guimanager.h"
#include "indi/indilistener.h"
#endif
#ifdef HAVE_NOTIFYCONFIG
......@@ -265,6 +267,48 @@ void KStars::slotINDIToolBar()
else
ekosManager()->hide();
}
else if ( a == actionCollection()->action( "lock_telescope" ) )
{
if (INDIListener::Instance()->size() == 0)
{
KMessageBox::sorry(0, i18n("KStars did not find any active telescopes."));
return;
}
ISD::GDInterface *oneScope=NULL;
foreach(ISD::GDInterface *gd, INDIListener::Instance()->getDevices())
{
INDI::BaseDevice *bd = gd->getBaseDevice();
if (gd->getType() != KSTARS_TELESCOPE)
continue;
if (bd == NULL)
continue;
if (bd->isConnected() == false)
{
KMessageBox::error(0, i18n("Telescope %1 is offline. Please connect and retry again.", gd->getDeviceName()));
return;
}
oneScope = gd;
break;
}
if (oneScope == NULL)
{
KMessageBox::sorry(0, i18n("KStars did not find any active telescopes."));
return;
}
if (a->isChecked())
oneScope->runCommand(INDI_CENTER_LOCK);
else
oneScope->runCommand(INDI_CENTER_UNLOCK);
}
else if ( a == actionCollection()->action( "show_fits_viewer" ) )
{
if (m_FITSViewers.isEmpty())
......
......@@ -585,10 +585,13 @@ void KStars::initActions() {
<< QIcon::fromTheme("kstars_fitsviewer" , QIcon(":/icons/breeze/default/kstars_fitsviewer.svg") )
<< ToolTip( i18n("Toggle FITS Viewer") );
ka->setEnabled(false);
ka = actionCollection()->add<KToggleAction>("lock_telescope", this, SLOT( slotINDIToolBar() ) )
<< i18nc("Toggle the telescope center lock in display", "Center Telescope" )
<< QIcon::fromTheme("center_telescope" , QIcon(":/icons/center_telescope.svg") )
<< ToolTip( i18n("Toggle Lock Telescope Center") );
ka->setEnabled(false);
#endif
if (Options::fitsDir().isEmpty())
Options::setFitsDir(QDir:: homePath());
}
void KStars::repopulateFOV() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment