TelescopeControl.cpp   TelescopeControl.cpp 
/* /*
* Stellarium Telescope Control Plug-in * Stellarium Telescope Control Plug-in
* *
* Copyright (C) 2006 Johannes Gajdosik * Copyright (C) 2006 Johannes Gajdosik
* Copyright (C) 2009 Bogdan Marinov * Copyright (C) 2009-2010 Bogdan Marinov
* *
* This module was originally written by Johannes Gajdosik in 2006 * This module was originally written by Johannes Gajdosik in 2006
* as a core module of Stellarium. In 2009 it was significantly extended wi th * as a core module of Stellarium. In 2009 it was significantly extended wi th
* GUI features and later split as an external plug-in module by Bogdan Mar inov. * GUI features and later split as an external plug-in module by Bogdan Mar inov.
* *
* This class used to be called TelescopeMgr before the split. * This class used to be called TelescopeMgr before the split.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
skipping to change at line 30 skipping to change at line 30
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "TelescopeControl.hpp" #include "TelescopeControl.hpp"
#include "TelescopeClient.hpp" #include "TelescopeClient.hpp"
#include "TelescopeDialog.hpp"
#include "SlewDialog.hpp"
#include "LogFile.hpp" #include "LogFile.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelMovementMgr.hpp"
#include "StelObject.hpp" #include "StelObject.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include <QAction> #include <QAction>
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
skipping to change at line 86 skipping to change at line 89
return info; return info;
} }
Q_EXPORT_PLUGIN2(TelescopeControl, TelescopeControlStelPluginInterface) Q_EXPORT_PLUGIN2(TelescopeControl, TelescopeControlStelPluginInterface)
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Constructor and destructor // Constructor and destructor
TelescopeControl::TelescopeControl() TelescopeControl::TelescopeControl()
{ {
setObjectName("TelescopeControl"); setObjectName("TelescopeControl");
connectionTypeNames.insert(ConnectionVirtual, "virtual");
connectionTypeNames.insert(ConnectionInternal, "internal");
connectionTypeNames.insert(ConnectionLocal, "local");
connectionTypeNames.insert(ConnectionRemote, "remote");
} }
TelescopeControl::~TelescopeControl() TelescopeControl::~TelescopeControl()
{ {
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Methods inherited from the StelModule class // Methods inherited from the StelModule class
// init(), update(), draw(), setStelStyle(), getCallOrder() // init(), update(), draw(), setStelStyle(), getCallOrder()
skipping to change at line 119 skipping to change at line 127
StelFileMgr::mkDir(moduleDirectoryPath); StelFileMgr::mkDir(moduleDirectoryPath);
//Load the device models //Load the device models
loadDeviceModels(); loadDeviceModels();
if(deviceModels.isEmpty()) if(deviceModels.isEmpty())
{ {
qWarning() << "TelescopeControl: No device model des criptions have been loaded. Stellarium will not be able to control a telesc ope on its own, but it is still possible to do it through an external appli cation or to connect to a remote host."; qWarning() << "TelescopeControl: No device model des criptions have been loaded. Stellarium will not be able to control a telesc ope on its own, but it is still possible to do it through an external appli cation or to connect to a remote host.";
} }
//Unload Stellarium's internal telescope control module //Unload Stellarium's internal telescope control module
StelApp::getInstance().getModuleMgr().unloadModule("Telescop //(not necessary since revision 6308; remains as an example)
eMgr", false);//If the alsoDelete parameter is set to true, Stellarium cras //StelApp::getInstance().getModuleMgr().unloadModule("Telesc
hes with a segmentation fault when an object is selected. TODO: Find out wh opeMgr", false);
y. /*If the alsoDelete parameter is set to true, Stellarium cra
//unloadModule() didn't work prior to revision 5058: the mod shes with a
ule unloaded OK, but Stellarium crashed later with a segmentation fault, segmentation fault when an object is selected. TODO: Find
//because LandscapeMgr::getCallOrder() depended on the modul out why.
e's existence to return a value. unloadModule() didn't work prior to revision 5058: the mod
ule unloaded
normally, but Stellarium crashed later with a segmentation
fault,
because LandscapeMgr::getCallOrder() depended on the modul
e's
existence to return a value.*/
//Load and start all telescope clients //Load and start all telescope clients
loadTelescopes(); loadTelescopes();
//Load OpenGL textures //Load OpenGL textures
reticleTexture = StelApp::getInstance().getTextureManager(). createTexture(":/telescopeControl/telescope_reticle.png"); reticleTexture = StelApp::getInstance().getTextureManager(). createTexture(":/telescopeControl/telescope_reticle.png");
selectionTexture = StelApp::getInstance().getTextureManager( ).createTexture("pointeur2.png"); selectionTexture = StelApp::getInstance().getTextureManager( ).createTexture("textures/pointeur2.png");
//Load the module's custom style sheets //Load the module's custom style sheets
QFile styleSheetFile; QFile styleSheetFile;
styleSheetFile.setFileName(":/telescopeControl/normalStyle.c ss"); styleSheetFile.setFileName(":/telescopeControl/normalStyle.c ss");
if(styleSheetFile.open(QFile::ReadOnly|QFile::Text)) if(styleSheetFile.open(QFile::ReadOnly|QFile::Text))
{ {
moduleStyleSheet.insert("color", QString(styleSheetF ile.readAll())); normalStyleSheet = new QByteArray(styleSheetFile.rea dAll());
} }
styleSheetFile.close(); styleSheetFile.close();
styleSheetFile.setFileName(":/telescopeControl/nightStyle.cs s"); styleSheetFile.setFileName(":/telescopeControl/nightStyle.cs s");
if(styleSheetFile.open(QFile::ReadOnly|QFile::Text)) if(styleSheetFile.open(QFile::ReadOnly|QFile::Text))
{ {
moduleStyleSheet.insert("night_color", QString(style SheetFile.readAll())); nightStyleSheet = new QByteArray(styleSheetFile.read All());
} }
styleSheetFile.close(); styleSheetFile.close();
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui()); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui());
//Create telescope key bindings //Create telescope key bindings
/* QAction-s with these key bindings existed in Stellarium
prior to
revision 6311. Any future backports should account f
or that. */
QString group = N_("Telescope Control"); QString group = N_("Telescope Control");
#ifdef COMPATIBILITY_001003
//QAction-s with these key bindings already exist in Stellar // "Slew to object" commands
ium
gui->getGuiActions("actionMove_Telescope_To_Selection_0")->s
etVisible(false);
#else
//gui->addGuiActions("actionMove_Telescope_To_Selection_0",
N_("Move telescope #0 to selected object"), "Ctrl+0", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_1", N_ ("Move telescope #1 to selected object"), "Ctrl+1", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_1", N_ ("Move telescope #1 to selected object"), "Ctrl+1", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_2", N_ ("Move telescope #2 to selected object"), "Ctrl+2", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_2", N_ ("Move telescope #2 to selected object"), "Ctrl+2", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_3", N_ ("Move telescope #3 to selected object"), "Ctrl+3", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_3", N_ ("Move telescope #3 to selected object"), "Ctrl+3", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_4", N_ ("Move telescope #4 to selected object"), "Ctrl+4", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_4", N_ ("Move telescope #4 to selected object"), "Ctrl+4", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_5", N_ ("Move telescope #5 to selected object"), "Ctrl+5", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_5", N_ ("Move telescope #5 to selected object"), "Ctrl+5", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_6", N_ ("Move telescope #6 to selected object"), "Ctrl+6", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_6", N_ ("Move telescope #6 to selected object"), "Ctrl+6", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_7", N_ ("Move telescope #7 to selected object"), "Ctrl+7", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_7", N_ ("Move telescope #7 to selected object"), "Ctrl+7", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_8", N_ ("Move telescope #8 to selected object"), "Ctrl+8", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_8", N_ ("Move telescope #8 to selected object"), "Ctrl+8", group, false, false);
gui->addGuiActions("actionMove_Telescope_To_Selection_9", N_ ("Move telescope #9 to selected object"), "Ctrl+9", group, false, false); gui->addGuiActions("actionMove_Telescope_To_Selection_9", N_ ("Move telescope #9 to selected object"), "Ctrl+9", group, false, false);
#endif //COMPATIBILITY_001003
//connect(gui->getGuiActions("actionMove_Telescope_To_Select // "Slew to the center of the screen" commands
ion_0"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); gui->addGuiActions("actionSlew_Telescope_To_Direction_1", N_
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio ("Move telescope #1 to the point currently in the center of the screen"), "
n_1"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); Alt+1", group, false, false);
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio gui->addGuiActions("actionSlew_Telescope_To_Direction_2", N_
n_2"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); ("Move telescope #2 to the point currently in the center of the screen"), "
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio Alt+2", group, false, false);
n_3"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); gui->addGuiActions("actionSlew_Telescope_To_Direction_3", N_
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio ("Move telescope #3 to the point currently in the center of the screen"), "
n_4"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); Alt+3", group, false, false);
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio gui->addGuiActions("actionSlew_Telescope_To_Direction_4", N_
n_5"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); ("Move telescope #4 to the point currently in the center of the screen"), "
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio Alt+4", group, false, false);
n_6"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); gui->addGuiActions("actionSlew_Telescope_To_Direction_5", N_
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio ("Move telescope #5 to the point currently in the center of the screen"), "
n_7"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); Alt+5", group, false, false);
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio gui->addGuiActions("actionSlew_Telescope_To_Direction_6", N_
n_8"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); ("Move telescope #6 to the point currently in the center of the screen"), "
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio Alt+6", group, false, false);
n_9"), SIGNAL(triggered()), this, SLOT(moveTelescopeToSelected())); gui->addGuiActions("actionSlew_Telescope_To_Direction_7", N_
("Move telescope #7 to the point currently in the center of the screen"), "
Alt+7", group, false, false);
gui->addGuiActions("actionSlew_Telescope_To_Direction_8", N_
("Move telescope #8 to the point currently in the center of the screen"), "
Alt+8", group, false, false);
gui->addGuiActions("actionSlew_Telescope_To_Direction_9", N_
("Move telescope #9 to the point currently in the center of the screen"), "
Alt+9", group, false, false);
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_1"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_2"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_3"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_4"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_5"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_6"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_7"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_8"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionMove_Telescope_To_Selectio
n_9"), SIGNAL(triggered()), this, SLOT(slewTelescopeToSelectedObject()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_1"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_2"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_3"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_4"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_5"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_6"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_7"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_8"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
connect(gui->getGuiActions("actionSlew_Telescope_To_Directio
n_9"), SIGNAL(triggered()), this, SLOT(slewTelescopeToViewDirection()));
//Create and initialize the telescope management window //Create and initialize dialog windows
telescopeDialog = new TelescopeDialog(); telescopeDialog = new TelescopeDialog();
slewDialog = new SlewDialog();
#ifdef USE_TOGGLEABLE_TELESCOPE_WINDOW
//TODO: Think of a better keyboard shortcut //TODO: Think of a better keyboard shortcut
#ifdef COMPATIBILITY_001003 gui->addGuiActions("actionShow_Slew_Window", N_("Move a tele
gui->addGuiActions("actionShow_Telescopes_Window", N_("Teles scope to a given set of coordinates"), "Ctrl+0", group, true, false);
copes window"), "Alt+0", group, true, false); connect(gui->getGuiActions("actionShow_Slew_Window"), SIGNAL
#else (toggled(bool)), slewDialog, SLOT(setVisible(bool)));
gui->addGuiActions("actionShow_Telescopes_Window", N_("Teles connect(slewDialog, SIGNAL(visibleChanged(bool)), gui->getGu
copes window"), "Ctrl+0", group, true, false); iActions("actionShow_Slew_Window"), SLOT(setChecked(bool)));
#endif //COMPATIBILITY_001003
connect(gui->getGuiActions("actionShow_Telescopes_Window"),
SIGNAL(toggled(bool)), telescopeDialog, SLOT(setVisible(bool)));
connect(telescopeDialog, SIGNAL(visibleChanged(bool)), gui->
getGuiActions("actionShow_Telescopes_Window"), SLOT(setChecked(bool)));
#ifdef USE_TOOLBAR_BUTTON
//Create toolbar button //Create toolbar button
pixmapHover = new QPixmap(":/graphicGui/gui/glow32x32.png"); pixmapHover = new QPixmap(":/graphicGui/glow32x32.png");
pixmapOnIcon = new QPixmap(":/telescopeControl/bt_TelescopeC pixmapOnIcon = new QPixmap(":/telescopeControl/button_Slew_
ontrol_on.png"); Dialog_on.png");
pixmapOffIcon = new QPixmap(":/telescopeControl/bt_Telescope pixmapOffIcon = new QPixmap(":/telescopeControl/button_Slew_
Control_off.png"); Dialog_off.png");
toolbarButton = new StelButton(NULL, *pixmapOnIcon, *pixmapO toolbarButton = new StelButton(NULL, *pixmapOnIcon, *pixmapO
ffIcon, *pixmapHover, gui->getGuiActions("actionShow_Telescopes_Window")); ffIcon, *pixmapHover, gui->getGuiActions("actionShow_Slew_Window"));
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr oup"); gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr oup");
#endif //USE_TOOLBAR_BUTTON
#endif //USE_TOGGLEABLE_TELESCOPE_WINDOW
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "TelescopeControl::init() error: " << e.what() ; qWarning() << "TelescopeControl::init() error: " << e.what() ;
return; return;
} }
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
//Initialize style, as it is not called at startup: //Initialize style, as it is not called at startup:
setStelStyle(*StelApp::getInstance().getCurrentStelStyle()); //(necessary to initialize the reticle/label/circle colors)
setStelStyle(StelApp::getInstance().getCurrentStelStyle());
} }
void TelescopeControl::deinit() void TelescopeControl::deinit()
{ {
//Destroy all clients first in order to avoid displaying a TCP error //Destroy all clients first in order to avoid displaying a TCP error
deleteAllTelescopes(); deleteAllTelescopes();
QHash<int, QProcess*>::const_iterator iterator = telescopeServerProc ess.constBegin(); QHash<int, QProcess*>::const_iterator iterator = telescopeServerProc ess.constBegin();
while(iterator != telescopeServerProcess.constEnd()) while(iterator != telescopeServerProcess.constEnd())
{ {
int slotNumber = iterator.key(); int slotNumber = iterator.key();
#ifdef WIN32 #ifdef Q_OS_WIN32
telescopeServerProcess[slotNumber]->close(); telescopeServerProcess[slotNumber]->close();
#else #else
telescopeServerProcess[slotNumber]->terminate(); telescopeServerProcess[slotNumber]->terminate();
#endif #endif
telescopeServerProcess[slotNumber]->waitForFinished(); telescopeServerProcess[slotNumber]->waitForFinished();
delete telescopeServerProcess[slotNumber]; delete telescopeServerProcess[slotNumber];
qDebug() << "TelescopeControl::deinit(): Server process at s lot" << slotNumber << "terminated successfully."; qDebug() << "TelescopeControl::deinit(): Server process at s lot" << slotNumber << "terminated successfully.";
++iterator; ++iterator;
} }
//TODO: Decide if it should be saved on change //TODO: Decide if it should be saved on change
//Save the configuration on exit //Save the configuration on exit
saveConfiguration(); saveConfiguration();
} }
void TelescopeControl::update(double deltaTime) void TelescopeControl::update(double deltaTime)
{ {
labelFader.update((int)(deltaTime*1000)); labelFader.update((int)(deltaTime*1000));
reticleFader.update((int)(deltaTime*1000)); reticleFader.update((int)(deltaTime*1000));
circleFader.update((int)(deltaTime*1000));
// communicate with the telescopes: // communicate with the telescopes:
communicate(); communicate();
} }
void TelescopeControl::draw(StelCore* core) void TelescopeControl::draw(StelCore* core)
{ {
StelNavigator* nav = core->getNavigator(); StelNavigator* nav = core->getNavigator();
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
StelPainter sPainter(prj); StelPainter sPainter(prj);
sPainter.setFont(labelFont); sPainter.setFont(labelFont);
skipping to change at line 264 skipping to change at line 289
reticleTexture->bind(); reticleTexture->bind();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa rency mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa rency mode
foreach (const TelescopeClientP& telescope, telescopeClients) foreach (const TelescopeClientP& telescope, telescopeClients)
{ {
if (telescope->isConnected() && telescope->hasKnownPosition( )) if (telescope->isConnected() && telescope->hasKnownPosition( ))
{ {
Vec3d XY; Vec3d XY;
if (prj->projectCheck(telescope->getJ2000EquatorialP os(nav), XY)) if (prj->projectCheck(telescope->getJ2000EquatorialP os(nav), XY))
{ {
//Telescope circles appear synchronously wit h markers //Telescope circles appear synchronously wit h markers
if (reticleFader.getInterstate() >= 0) if (circleFader.getInterstate() >= 0)
{ {
glColor4f(circleColor[0], circleColo r[1], circleColor[2], reticleFader.getInterstate()); glColor4f(circleColor[0], circleColo r[1], circleColor[2], circleFader.getInterstate());
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
foreach (double circle, telescope->g etOculars()) foreach (double circle, telescope->g etOculars())
{ {
sPainter.drawCircle(XY[0], X Y[1], 0.5 * prj->getPixelPerRadAtCenter() * (M_PI/180) * (circle)); sPainter.drawCircle(XY[0], X Y[1], 0.5 * prj->getPixelPerRadAtCenter() * (M_PI/180) * (circle));
} }
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
}
if (reticleFader.getInterstate() >= 0)
{
glColor4f(reticleColor[0], reticleCo
lor[1], reticleColor[2], reticleFader.getInterstate());
sPainter.drawSprite2dMode(XY[0],XY[1 ],15.f); sPainter.drawSprite2dMode(XY[0],XY[1 ],15.f);
} }
if (labelFader.getInterstate() >= 0) if (labelFader.getInterstate() >= 0)
{ {
glColor4f(labelColor[0], labelColor[ 1], labelColor[2], labelFader.getInterstate()); glColor4f(labelColor[0], labelColor[ 1], labelColor[2], labelFader.getInterstate());
//TODO: Different position of the la bel if circles are shown? //TODO: Different position of the la bel if circles are shown?
//TODO: Remove magic number (text sp acing) //TODO: Remove magic number (text sp acing)
sPainter.drawText(XY[0], XY[1], tele scope->getNameI18n(), 0, 6 + 10, -4, false); sPainter.drawText(XY[0], XY[1], tele scope->getNameI18n(), 0, 6 + 10, -4, false);
//Same position as the other objects : doesn't work, telescope label overlaps object label //Same position as the other objects : doesn't work, telescope label overlaps object label
//sPainter.drawText(XY[0], XY[1], sc ope->getNameI18n(), 0, 10, 10, false); //sPainter.drawText(XY[0], XY[1], sc ope->getNameI18n(), 0, 10, 10, false);
reticleTexture->bind(); reticleTexture->bind();
} }
} }
} }
} }
if(GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if(GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
drawPointer(prj, nav, sPainter); drawPointer(prj, nav, sPainter);
} }
void TelescopeControl::setStelStyle(const StelStyle& style) void TelescopeControl::setStelStyle(const QString& section)
{ {
if(style.confSectionName == "night_color") if (section == "night_color")
{ {
setLabelColor(labelNightColor); setLabelColor(labelNightColor);
setReticleColor(reticleNightColor);
setCircleColor(circleNightColor); setCircleColor(circleNightColor);
} }
else else
{ {
setLabelColor(labelNormalColor); setLabelColor(labelNormalColor);
setReticleColor(reticleNormalColor);
setCircleColor(circleNormalColor); setCircleColor(circleNormalColor);
} }
telescopeDialog->setStelStyle(style); telescopeDialog->updateStyle();
slewDialog->updateStyle();
} }
double TelescopeControl::getCallOrder(StelModuleActionName actionName) cons t double TelescopeControl::getCallOrder(StelModuleActionName actionName) cons t
{ {
//TODO: Remove magic number (call order offset) //TODO: Remove magic number (call order offset)
if (actionName == StelModule::ActionDraw) if (actionName == StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Mete orMgr")->getCallOrder(actionName) + 2.; return StelApp::getInstance().getModuleMgr().getModule("Mete orMgr")->getCallOrder(actionName) + 2.;
return 0.; return 0.;
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Methods inherited from the StelObjectModule class // Methods inherited from the StelObjectModule class
// //
QList<StelObjectP> TelescopeControl::searchAround(const Vec3d& vv, double l imitFov, const StelCore* core) const QList<StelObjectP> TelescopeControl::searchAround(const Vec3d& vv, double l imitFov, const StelCore* core) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
if (!getFlagTelescopes()) if (!getFlagTelescopeReticles())
return result; return result;
Vec3d v(vv); Vec3d v(vv);
v.normalize(); v.normalize();
double cosLimFov = cos(limitFov * M_PI/180.); double cosLimFov = cos(limitFov * M_PI/180.);
foreach (const TelescopeClientP& telescope, telescopeClients) foreach (const TelescopeClientP& telescope, telescopeClients)
{ {
if (telescope->getJ2000EquatorialPos(core->getNavigator()).d ot(v) >= cosLimFov) if (telescope->getJ2000EquatorialPos(core->getNavigator()).d ot(v) >= cosLimFov)
{ {
result.append(qSharedPointerCast<StelObject>(telesco pe)); result.append(qSharedPointerCast<StelObject>(telesco pe));
} }
skipping to change at line 384 skipping to change at line 416
{ {
result.erase(result.begin() + maxNbItem, result.end()); result.erase(result.begin() + maxNbItem, result.end());
} }
return result; return result;
} }
bool TelescopeControl::configureGui(bool show) bool TelescopeControl::configureGui(bool show)
{ {
if(show) if(show)
{ {
#ifdef USE_TOGGLEABLE_TELESCOPE_WINDOW
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance()
.getGui());
gui->getGuiActions("actionShow_Telescopes_Window")->setCheck
ed(true);
#else
telescopeDialog->setVisible(true); telescopeDialog->setVisible(true);
#endif //USE_TOGGLEABLE_TELESCOPE_WINDOW
} }
return true; return true;
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Misc methods (from TelescopeMgr; TODO: Better categorization) // Misc methods (from TelescopeMgr; TODO: Better categorization)
void TelescopeControl::setFontSize(int fontSize) void TelescopeControl::setFontSize(int fontSize)
{ {
labelFont.setPixelSize(fontSize); labelFont.setPixelSize(fontSize);
} }
void TelescopeControl::moveTelescopeToSelected(void) void TelescopeControl::slewTelescopeToSelectedObject()
{ {
StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr); // Find out for which telescope is the command
if (omgr->getSelectedObject().isEmpty()) if (sender() == NULL)
return; return;
int slotNumber = sender()->objectName().right(1).toInt();
if (sender() == NULL) // Find out the coordinates of the target
StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
if (omgr->getSelectedObject().isEmpty())
return; return;
StelObjectP selectObject = omgr->getSelectedObject().at(0); StelObjectP selectObject = omgr->getSelectedObject().at(0);
if (!selectObject) // should never happen if (!selectObject) // should never happen
return; return;
Vec3d objectPos = selectObject->getJ2000EquatorialPos(StelApp::getIn Vec3d objectPosition = selectObject->getJ2000EquatorialPos(StelApp::
stance().getCore()->getNavigator()); getInstance().getCore()->getNavigator());
int telNum = sender()->objectName().right(1).toInt();
telescopeGoto(telNum, objectPos); telescopeGoto(slotNumber, objectPosition);
}
void TelescopeControl::slewTelescopeToViewDirection()
{
// Find out for which telescope is the command
if (sender() == NULL)
return;
int slotNumber = sender()->objectName().right(1).toInt();
// Find out the coordinates of the target
Vec3d centerPosition = GETSTELMODULE(StelMovementMgr)->getViewDirect
ionJ2000();
telescopeGoto(slotNumber, centerPosition);
} }
void TelescopeControl::drawPointer(const StelProjectorP& prj, const StelNav igator * nav, StelPainter& sPainter) void TelescopeControl::drawPointer(const StelProjectorP& prj, const StelNav igator * nav, StelPainter& sPainter)
{ {
#ifndef COMPATIBILITY_001002 #ifndef COMPATIBILITY_001002
//Leaves this whole routine empty if this is the backport version. //Leaves this whole routine empty if this is the backport version.
//Otherwise, there will be two concentric selection markers drawn ar ound the telescope pointer. //Otherwise, there will be two concentric selection markers drawn ar ound the telescope pointer.
//In 0.10.3, the plug-in unloads the module that draws the surplus m arker. //In 0.10.3, the plug-in unloads the module that draws the surplus m arker.
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Telescope"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Telescope");
if (!newSelected.empty()) if (!newSelected.empty())
{ {
const StelObjectP obj = newSelected[0]; const StelObjectP obj = newSelected[0];
Vec3d pos = obj->getJ2000EquatorialPos(nav); Vec3d pos = obj->getJ2000EquatorialPos(nav);
Vec3d screenpos; Vec3d screenpos;
// Compute 2D pos and return if outside screen // Compute 2D pos and return if outside screen
if (!prj->project(pos, screenpos)) if (!prj->project(pos, screenpos))
return; return;
const Vec3d& c(obj->getInfoColor()); const Vec3f& c(obj->getInfoColor());
sPainter.setColor(c[0], c[1], c[2]); sPainter.setColor(c[0], c[1], c[2]);
selectionTexture->bind(); selectionTexture->bind();
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 25., S telApp::getInstance().getTotalRunTime() * 40.); sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 25., S telApp::getInstance().getTotalRunTime() * 40.);
} }
#endif //COMPATIBILITY_001002 #endif //COMPATIBILITY_001002
} }
skipping to change at line 512 skipping to change at line 555
//TODO: I don't like how this turned out //TODO: I don't like how this turned out
if(serverExecutablesDirectoryPath.isEmpty()) if(serverExecutablesDirectoryPath.isEmpty())
return; return;
//As StelFileMgr is quite limited, use Qt's handy methods (I love Qt !) //As StelFileMgr is quite limited, use Qt's handy methods (I love Qt !)
//Get all executable files with names beginning with "TelescopeServe r" in this directory //Get all executable files with names beginning with "TelescopeServe r" in this directory
QDir serverDirectory(serverExecutablesDirectoryPath); QDir serverDirectory(serverExecutablesDirectoryPath);
if(!serverDirectory.exists()) if(!serverDirectory.exists())
{ {
qWarning() << "TelescopeControl: Can't load telescope server executables: Can't find telescope server directory."; qWarning() << "TelescopeControl: No telescope server directo ry has been found.";
return; return;
} }
QList<QFileInfo> telescopeServerExecutables = serverDirectory.entryI nfoList(QStringList("TelescopeServer*"), (QDir::Files|QDir::Executable|QDir ::CaseSensitive), QDir::Name); QList<QFileInfo> telescopeServerExecutables = serverDirectory.entryI nfoList(QStringList("TelescopeServer*"), (QDir::Files|QDir::Executable|QDir ::CaseSensitive), QDir::Name);
if(!telescopeServerExecutables.isEmpty()) if(!telescopeServerExecutables.isEmpty())
{ {
foreach(QFileInfo telescopeServerExecutable, telescopeServer Executables) foreach(QFileInfo telescopeServerExecutable, telescopeServer Executables)
telescopeServers.append(telescopeServerExecutable.ba seName());//This strips the ".exe" suffix on Windows telescopeServers.append(telescopeServerExecutable.ba seName());//This strips the ".exe" suffix on Windows
} }
else else
{ {
skipping to change at line 539 skipping to change at line 582
// Methods for reading from and writing to the configuration file // Methods for reading from and writing to the configuration file
void TelescopeControl::loadConfiguration() void TelescopeControl::loadConfiguration()
{ {
QSettings* settings = StelApp::getInstance().getSettings(); QSettings* settings = StelApp::getInstance().getSettings();
Q_ASSERT(settings); Q_ASSERT(settings);
settings->beginGroup("TelescopeControl"); settings->beginGroup("TelescopeControl");
//Load display flags //Load display flags
setFlagTelescopes(settings->value("flag_telescope_circles", true).to setFlagTelescopeReticles(settings->value("flag_telescope_reticles",
Bool()); true).toBool());
setFlagTelescopeName(settings->value("flag_telescope_labels", true). setFlagTelescopeLabels(settings->value("flag_telescope_labels", true
toBool()); ).toBool());
setFlagTelescopeCircles(settings->value("flag_telescope_circles", tr
ue).toBool());
//Load font size //Load font size
#ifdef WIN32 #ifdef Q_OS_WIN32
setFontSize(settings->value("telescope_labels_font_size", 13).toInt( )); //Windows Qt bug workaround setFontSize(settings->value("telescope_labels_font_size", 13).toInt( )); //Windows Qt bug workaround
#else #else
setFontSize(settings->value("telescope_labels_font_size", 12).toInt( )); setFontSize(settings->value("telescope_labels_font_size", 12).toInt( ));
#endif #endif
//Load colours //Load colours
circleNormalColor = StelUtils::strToVec3f(settings->value("color_tel reticleNormalColor = StelUtils::strToVec3f(settings->value("color_te
escope_circles", "0.6,0.4,0").toString()); lescope_reticles", "0.6,0.4,0").toString());
circleNightColor = StelUtils::strToVec3f(settings->value("night_colo reticleNightColor = StelUtils::strToVec3f(settings->value("night_col
r_telescope_circles", "0.5,0,0").toString());; or_telescope_reticles", "0.5,0,0").toString());
labelNormalColor = StelUtils::strToVec3f(settings->value("color_tele scope_labels", "0.6,0.4,0").toString()); labelNormalColor = StelUtils::strToVec3f(settings->value("color_tele scope_labels", "0.6,0.4,0").toString());
labelNightColor = StelUtils::strToVec3f(settings->value("night_color _telescope_labels", "0.5,0,0").toString()); labelNightColor = StelUtils::strToVec3f(settings->value("night_color _telescope_labels", "0.5,0,0").toString());
circleNormalColor = StelUtils::strToVec3f(settings->value("color_tel
escope_circles", "0.6,0.4,0").toString());
circleNightColor = StelUtils::strToVec3f(settings->value("night_colo
r_telescope_circles", "0.5,0,0").toString());
//Load server executables flag and directory //Load server executables flag and directory
useServerExecutables = settings->value("flag_use_server_executables" , false).toBool(); useServerExecutables = settings->value("flag_use_server_executables" , false).toBool();
serverExecutablesDirectoryPath = settings->value("server_executables _path").toString(); serverExecutablesDirectoryPath = settings->value("server_executables _path").toString();
//If no directory is specified in the configuration file, try to fin d the default one //If no directory is specified in the configuration file, try to fin d the default one
if(serverExecutablesDirectoryPath.isEmpty() || !QDir(serverExecutabl esDirectoryPath).exists()) if(serverExecutablesDirectoryPath.isEmpty() || !QDir(serverExecutabl esDirectoryPath).exists())
{ {
//Find out if the default server directory exists //Find out if the default server directory exists
QString serverDirectoryPath; QString serverDirectoryPath;
try try
{ {
serverDirectoryPath = StelFileMgr::findFile("servers ", StelFileMgr::Directory); serverDirectoryPath = StelFileMgr::findFile("servers ", StelFileMgr::Directory);
} }
catch(std::runtime_error &e) catch(std::runtime_error &e)
{ {
qDebug() << "TelescopeControl: No telescope servers directory detected."; //qDebug() << "TelescopeControl: No telescope server s directory detected.";
useServerExecutables = false; useServerExecutables = false;
serverDirectoryPath = StelFileMgr::getUserDir() + "/ servers"; serverDirectoryPath = StelFileMgr::getUserDir() + "/ servers";
} }
if(!serverDirectoryPath.isEmpty()) if(!serverDirectoryPath.isEmpty())
{ {
serverExecutablesDirectoryPath = serverDirectoryPath ; serverExecutablesDirectoryPath = serverDirectoryPath ;
} }
} }
//Load logging flag //Load logging flag
skipping to change at line 594 skipping to change at line 640
} }
void TelescopeControl::saveConfiguration() void TelescopeControl::saveConfiguration()
{ {
QSettings* settings = StelApp::getInstance().getSettings(); QSettings* settings = StelApp::getInstance().getSettings();
Q_ASSERT(settings); Q_ASSERT(settings);
settings->beginGroup("TelescopeControl"); settings->beginGroup("TelescopeControl");
//Save display flags //Save display flags
settings->setValue("flag_telescope_circles", getFlagTelescopes()); settings->setValue("flag_telescope_reticles", getFlagTelescopeReticl
settings->setValue("flag_telescope_labels", getFlagTelescopeName()); es());
settings->setValue("flag_telescope_labels", getFlagTelescopeLabels()
);
settings->setValue("flag_telescope_circles", getFlagTelescopeCircles
());
//Save colours //Save colours
settings->setValue("color_telescope_circles", QString("%1,%2,%3").ar settings->setValue("color_telescope_reticles", QString("%1,%2,%3").a
g(circleNormalColor[0], 0, 'f', 2).arg(circleNormalColor[1], 0, 'f', 2).arg rg(reticleNormalColor[0], 0, 'f', 2).arg(reticleNormalColor[1], 0, 'f', 2).
(circleNormalColor[2], 0, 'f', 2)); arg(reticleNormalColor[2], 0, 'f', 2));
settings->setValue("night_color_telescope_circles", QString("%1,%2,% settings->setValue("night_color_telescope_reticles", QString("%1,%2,
3").arg(circleNightColor[0], 0, 'f', 2).arg(circleNightColor[1], 0, 'f', 2) %3").arg(reticleNightColor[0], 0, 'f', 2).arg(reticleNightColor[1], 0, 'f',
.arg(circleNightColor[2], 0, 'f', 2)); 2).arg(reticleNightColor[2], 0, 'f', 2));
settings->setValue("color_telescope_labels", QString("%1,%2,%3").arg (labelNormalColor[0], 0, 'f', 2).arg(labelNormalColor[1], 0, 'f', 2).arg(la belNormalColor[2], 0, 'f', 2)); settings->setValue("color_telescope_labels", QString("%1,%2,%3").arg (labelNormalColor[0], 0, 'f', 2).arg(labelNormalColor[1], 0, 'f', 2).arg(la belNormalColor[2], 0, 'f', 2));
settings->setValue("night_color_telescope_labels", QString("%1,%2,%3 ").arg(labelNightColor[0], 0, 'f', 2).arg(labelNightColor[1], 0, 'f', 2).ar g(labelNightColor[2], 0, 'f', 2)); settings->setValue("night_color_telescope_labels", QString("%1,%2,%3 ").arg(labelNightColor[0], 0, 'f', 2).arg(labelNightColor[1], 0, 'f', 2).ar g(labelNightColor[2], 0, 'f', 2));
settings->setValue("color_telescope_circles", QString("%1,%2,%3").ar
g(circleNormalColor[0], 0, 'f', 2).arg(circleNormalColor[1], 0, 'f', 2).arg
(circleNormalColor[2], 0, 'f', 2));
settings->setValue("night_color_telescope_circles", QString("%1,%2,%
3").arg(circleNightColor[0], 0, 'f', 2).arg(circleNightColor[1], 0, 'f', 2)
.arg(circleNightColor[2], 0, 'f', 2));
//Save telescope server executables flag and directory //Save telescope server executables flag and directory
settings->setValue("flag_use_server_executables", useServerExecutabl es); settings->setValue("flag_use_server_executables", useServerExecutabl es);
if(useServerExecutables) if(useServerExecutables)
{ {
settings->setValue("server_executables_path", serverExecutab lesDirectoryPath); settings->setValue("server_executables_path", serverExecutab lesDirectoryPath);
} }
else else
{ {
settings->remove("server_executables_path"); settings->remove("server_executables_path");
skipping to change at line 633 skipping to change at line 682
{ {
//Open/create the JSON file //Open/create the JSON file
QString telescopesJsonPath = StelFileMgr::findFile("modules/ TelescopeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr: :Writable)) + "/telescopes.json"; QString telescopesJsonPath = StelFileMgr::findFile("modules/ TelescopeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr: :Writable)) + "/telescopes.json";
QFile telescopesJsonFile(telescopesJsonPath); QFile telescopesJsonFile(telescopesJsonPath);
if(!telescopesJsonFile.open(QFile::WriteOnly|QFile::Text)) if(!telescopesJsonFile.open(QFile::WriteOnly|QFile::Text))
{ {
qWarning() << "TelescopeControl: Telescopes can not be saved. A file can not be open for writing:" << telescopesJsonPath; qWarning() << "TelescopeControl: Telescopes can not be saved. A file can not be open for writing:" << telescopesJsonPath;
return; return;
} }
//Add the version:
telescopeDescriptions.insert("version", QString(PLUGIN_VERSI
ON));
//Convert the tree to JSON //Convert the tree to JSON
StelJsonParser::write(telescopeDescriptions, &telescopesJson File); StelJsonParser::write(telescopeDescriptions, &telescopesJson File);
telescopesJsonFile.flush();//Is this necessary? telescopesJsonFile.flush();//Is this necessary?
telescopesJsonFile.close(); telescopesJsonFile.close();
} }
catch(std::runtime_error &e) catch(std::runtime_error &e)
{ {
qWarning() << "TelescopeControl: Error saving telescopes: " << e.what(); qWarning() << "TelescopeControl: Error saving telescopes: " << e.what();
return; return;
} }
skipping to change at line 682 skipping to change at line 734
telescopesJsonFile.close(); telescopesJsonFile.close();
} }
//File contains any telescopes? //File contains any telescopes?
if(map.isEmpty()) if(map.isEmpty())
{ {
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
QString version = map.value("version", "0.0.0").toString();
if(version < QString(PLUGIN_VERSION))
{
QString newName = telescopesJsonPath + ".backup." +
QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
if(telescopesJsonFile.rename(newName))
{
qWarning() << "TelescopeControl: The existin
g version of telescopes.json is obsolete. Backing it up as" << newName;
qWarning() << "TelescopeControl: A blank tel
escopes.json file will have to be created.";
telescopeDescriptions = result;
return;
}
else
{
qWarning() << "TelescopeControl: The existin
g version of telescopes.json is obsolete. Unable to rename.";
telescopeDescriptions = result;
return;
}
}
map.remove("version");//Otherwise it will try to read it as
a telescope
//Make sure that there are no telescope clients yet //Make sure that there are no telescope clients yet
deleteAllTelescopes(); deleteAllTelescopes();
//Read telescopes, if any //Read telescopes, if any
int telescopesCount = 0; int telescopesCount = 0;
QMapIterator<QString, QVariant> node(map); QMapIterator<QString, QVariant> node(map);
bool ok; bool ok;
while(node.hasNext()) while(node.hasNext())
{ {
node.next(); node.next();
QString key = node.key(); QString key = node.key();
//If this is not a valid slot number, remove the nod e //If this is not a valid slot number, remove the nod e
int slot = key.toInt(&ok); int slot = key.toInt(&ok);
if(!ok || slot < MIN_SLOT_NUMBER || slot > MAX_SLOT_ NUMBER) if(!ok || !isValidSlotNumber(slot))
{ {
qDebug() << "TelescopeControl::loadTelescope s(): Deleted node unrecogised as slot:" << key; qDebug() << "TelescopeControl::loadTelescope s(): Deleted node unrecogised as slot:" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
QVariantMap telescope = node.value().toMap(); QVariantMap telescope = node.value().toMap();
//If some of the essential parameters is missing, re //Essential parameters: Name and connection type
move the node
//TODO: More validation?
//Validation: Name //Validation: Name
QString name = telescope.value("name").toString(); QString name = telescope.value("name").toString();
if(name.isEmpty()) if(name.isEmpty())
{ {
qDebug() << "TelescopeControl: Unable to loa d telescope: No name specified at slot" << key; qDebug() << "TelescopeControl: Unable to loa d telescope: No name specified at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
//Validation: Protocol
//QString protocol = telescope.value("protocol").toS
tring(); //Returns an empty string if this key doesn't exist
//if(protocol.isEmpty())
//{
// qDebug() << "TelescopeControl: No protocol s
pecified at slot" << key;
// map.remove(key);
// continue;
//}
//Validation: Connection //Validation: Connection
QString connection = telescope.value("connection").t oString(); QString connection = telescope.value("connection").t oString();
if(connection.isEmpty() || (connection != "internal" && connection != "local" && connection != "remote")) if(connection.isEmpty() || !connectionTypeNames.valu es().contains(connection))
{ {
qDebug() << "TelescopeControl: Unable to loa d telescope: No valid connection type at slot" << key; qDebug() << "TelescopeControl: Unable to loa d telescope: No valid connection type at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
ConnectionType connectionType = connectionTypeNames. key(connection);
//Validation: Host name QString hostName("localhost");
QString hostName = telescope.value("host_name").toSt int portTCP = 0;
ring(); int delay = 0;
if(hostName.isEmpty()) QString deviceModelName;
{ QString portSerial;
qDebug() << "TelescopeControl::loadTelescope
s(): No host name at slot" << key;
map.remove(key);
continue;
}
//Validation: TCP port if (connectionType == ConnectionInternal)
int portTCP = telescope.value("tcp_port").toInt();
if(!telescope.contains("tcp_port") || portTCP < 0 ||
portTCP > 65535) //TODO: remove magic number
{ {
qDebug() << "TelescopeControl: Unable to loa //Serial port and device model
d telescope: No valid TCP port at slot" << key; deviceModelName = telescope.value("device_mo
map.remove(key); del").toString();
continue; portSerial = telescope.value("serial_port").
} toString();
//Validation: Delay
int delay = telescope.value("delay", 0).toInt();
if(delay <= 0 || delay > 10000000)
{
qDebug() << "TelescopeControl: Unable to loa
d telescope: No valid delay at slot" << key;
map.remove(key);
continue;
}
//Validation: Connect at startup
bool connectAtStartup = telescope.value("connect_at_
startup", false).toBool();
//Validation: Parameters needed only for telescopes
launched by Stellarium
QString deviceModelName = telescope.value("device_mo
del").toString();
QString portSerial = telescope.value("serial_port").
toString();
if(connection == "internal")
{
//Validation: Telescope server
if(deviceModelName.isEmpty()) if(deviceModelName.isEmpty())
{ {
qDebug() << "TelescopeControl: Unabl e to load telescope: No device model specified at slot" << key; qDebug() << "TelescopeControl: Unabl e to load telescope: No device model specified at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
//Do we have this server? //Do we have this server?
if(!deviceModels.contains(deviceModelName)) if(!deviceModels.contains(deviceModelName))
{ {
qWarning() << "TelescopeControl: Una ble to load telescope at slot" << slot << "because the specified device mod el is missing:" << deviceModelName; qWarning() << "TelescopeControl: Una ble to load telescope at slot" << slot << "because the specified device mod el is missing:" << deviceModelName;
map.remove(key); map.remove(key);
continue; continue;
} }
//Validation: Serial port if(portSerial.isEmpty() || !portSerial.start
//int portNumber; sWith(SERIAL_PORT_PREFIX))
//bool isNumber = false;
if(portSerial.isEmpty()
|| !portSerial.startsWith(SERIAL_PORT_PRE
FIX)
//TODO: Validation for Windows!
// || (portNumber = portSerial.right(portS
erial.length() - SERIAL_PORT_PREFIX.length()).toInt(&isNumber)) < MIN_SERIA
L_PORT_NUMBER
// || !isNumber
// || portNumber > MAX_SERIAL_PORT_NUMBER
//TODO: More validation?
)
{ {
qDebug() << "TelescopeControl: Unabl e to load telescope: No valid serial port specified at slot" << key; qDebug() << "TelescopeControl: Unabl e to load telescope: No valid serial port specified at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
} }
if (connectionType == ConnectionRemote)
{
//Validation: Host name
hostName = telescope.value("host_name").toSt
ring();
if(hostName.isEmpty())
{
qDebug() << "TelescopeControl::loadT
elescopes(): No host name at slot" << key;
map.remove(key);
continue;
}
}
if (connectionType != ConnectionVirtual)
{
//Validation: TCP port
portTCP = telescope.value("tcp_port").toInt(
);
if(!telescope.contains("tcp_port") || !isVal
idPort(portTCP))
{
qDebug() << "TelescopeControl: Unabl
e to load telescope: No valid TCP port at slot" << key;
map.remove(key);
continue;
}
//Validation: Delay
delay = telescope.value("delay", 0).toInt();
if(!isValidDelay(delay))
{
qDebug() << "TelescopeControl: Unabl
e to load telescope: No valid delay at slot" << key;
map.remove(key);
continue;
}
}
//Connect at startup
bool connectAtStartup = telescope.value("connect_at_
startup", false).toBool();
//Validation: FOV circles //Validation: FOV circles
QVariantList parsedJsonCircles = telescope.value("ci rcles").toList(); QVariantList parsedJsonCircles = telescope.value("ci rcles").toList();
QList<double> internalCircles; QList<double> internalCircles;
for(int i = 0; i< parsedJsonCircles.size(); i++) for(int i = 0; i< parsedJsonCircles.size(); i++)
{ {
if(i >= MAX_CIRCLE_COUNT) if(i >= MAX_CIRCLE_COUNT)
break; break;
internalCircles.append(parsedJsonCircles.val ue(i, -1.0).toDouble()); internalCircles.append(parsedJsonCircles.val ue(i, -1.0).toDouble());
} }
if(internalCircles.isEmpty()) if(internalCircles.isEmpty())
skipping to change at line 833 skipping to change at line 897
for(int i = 0; i < internalCircles.size(); i ++) for(int i = 0; i < internalCircles.size(); i ++)
newJsonCircles.append(internalCircle s.at(i)); newJsonCircles.append(internalCircle s.at(i));
telescope.insert("circles", newJsonCircles); telescope.insert("circles", newJsonCircles);
map.insert(key, telescope); map.insert(key, telescope);
} }
//Initialize a telescope client for this slot //Initialize a telescope client for this slot
//TODO: Improve the flow of control //TODO: Improve the flow of control
if(connectAtStartup) if(connectAtStartup)
{ {
//Use a sever if necessary if (connectionType == ConnectionInternal)
if(connection == "internal")
{ {
//Use a sever if necessary
if(deviceModels[deviceModelName].use Executable) if(deviceModels[deviceModelName].use Executable)
{ {
if(startClientAtSlot(slot, n ame, hostName, portTCP, delay, internalCircles)) if(startClientAtSlot(slot, c onnectionType, name, hostName, portTCP, delay, internalCircles))
{ {
if(!startServerAtSlo t(slot, deviceModelName, portTCP, portSerial)) if(!startServerAtSlo t(slot, deviceModelName, portTCP, portSerial))
{ {
stopClientAt Slot(slot); stopClientAt Slot(slot);
qDebug() << "TelescopeControl: Unable to launch a telescope server at slot" << slot; qDebug() << "TelescopeControl: Unable to launch a telescope server at slot" << slot;
} }
} }
else else
{ {
qDebug() << "Telesco peControl: Unable to create a telescope client at slot" << slot; qDebug() << "Telesco peControl: Unable to create a telescope client at slot" << slot;
continue; continue;
} }
} }
else else
{ {
addLogAtSlot(slot); addLogAtSlot(slot);
logAtSlot(slot); logAtSlot(slot);
if(!startClientAtSlot(slot, name, QString(), 0, delay, internalCircles, deviceModelName, portSerial)) if(!startClientAtSlot(slot, connectionType, name, QString(), 0, delay, internalCircles, deviceModelName , portSerial))
{ {
qDebug() << "Telesco peControl: Unable to create a telescope client at slot" << slot; qDebug() << "Telesco peControl: Unable to create a telescope client at slot" << slot;
continue; continue;
} }
} }
} }
else else
{ {
if(!startClientAtSlot(slot, name, ho stName, portTCP, delay, internalCircles)) if(!startClientAtSlot(slot, connecti onType, name, hostName, portTCP, delay, internalCircles))
{ {
qDebug() << "TelescopeContro l: Unable to create a telescope client at slot" << slot; qDebug() << "TelescopeContro l: Unable to create a telescope client at slot" << slot;
continue; continue;
} }
} }
} }
//If this line is reached, the telescope at this slo t has been loaded successfully //If this line is reached, the telescope at this slo t has been loaded successfully
telescopesCount++; telescopesCount++;
} }
skipping to change at line 892 skipping to change at line 956
} }
} }
catch(std::runtime_error &e) catch(std::runtime_error &e)
{ {
qWarning() << "TelescopeControl: Error loading telescopes: " << e.what(); qWarning() << "TelescopeControl: Error loading telescopes: " << e.what();
} }
telescopeDescriptions = result; telescopeDescriptions = result;
} }
bool TelescopeControl::addTelescopeAtSlot(int slot, QString name, QString h ost, int portTCP, int delay, bool connectAtStartup, QList<double> circles, QString deviceModelName, QString portSerial) bool TelescopeControl::addTelescopeAtSlot(int slot, ConnectionType connecti onType, QString name, QString host, int portTCP, int delay, bool connectAtS tartup, QList<double> circles, QString deviceModelName, QString portSerial)
{ {
//Validation //Validation
if(!isValidSlotNumber(slot)) if(!isValidSlotNumber(slot) || name.isEmpty() || connectionType <= C onnectionNA || connectionType >= ConnectionCount)
return false; return false;
//Create a new map node and fill it with parameters //Create a new map node and fill it with parameters
QVariantMap telescope; QVariantMap telescope;
telescope.insert("name", name); telescope.insert("name", name);
if(!deviceModelName.isEmpty()) telescope.insert("connection", connectionTypeNames.value(connectionT
ype));
if (connectionType == ConnectionRemote)
{ {
telescope.insert("connection", "internal"); //TODO: Add more validation!
if (host.isEmpty())
return false;
telescope.insert("host_name", host);
} }
else if(host != "localhost")
if(connectionType == ConnectionInternal)
{ {
telescope.insert("connection", "remote"); if (!deviceModels.contains(deviceModelName))
return false;
telescope.insert("device_model", deviceModelName);
if (portSerial.isEmpty())
return false;
telescope.insert("serial_port", portSerial);
} }
else
if (connectionType != ConnectionVirtual)
{ {
telescope.insert("connection", "local"); if (!isValidPort(portTCP))
return false;
telescope.insert("tcp_port", portTCP);
if (!isValidDelay(delay))
return false;
telescope.insert("delay", delay);
} }
telescope.insert("host_name", host);
telescope.insert("tcp_port", portTCP);
telescope.insert("delay", delay);
telescope.insert("connect_at_startup", connectAtStartup); telescope.insert("connect_at_startup", connectAtStartup);
if(!circles.isEmpty()) if(!circles.isEmpty())
{ {
QVariantList circleList; QVariantList circleList;
for(int i = 0; i < circles.size(); i++) for(int i = 0; i < circles.size(); i++)
circleList.append(circles[i]); circleList.append(circles[i]);
telescope.insert("circles", circleList); telescope.insert("circles", circleList);
} }
if(!deviceModelName.isEmpty())
{
telescope.insert("device_model", deviceModelName);
telescope.insert("serial_port", portSerial);
}
telescopeDescriptions.insert(QString::number(slot), telescope); telescopeDescriptions.insert(QString::number(slot), telescope);
return true; return true;
} }
bool TelescopeControl::getTelescopeAtSlot(int slot, QString& name, QString& host, int& portTCP, int& delay, bool& connectAtStartup, QList<double>& cir cles, QString& deviceModelName, QString& portSerial) bool TelescopeControl::getTelescopeAtSlot(int slot, ConnectionType& connect ionType, QString& name, QString& host, int& portTCP, int& delay, bool& conn ectAtStartup, QList<double>& circles, QString& deviceModelName, QString& po rtSerial)
{ {
//Validation //Validation
if(!isValidSlotNumber(slot)) if(!isValidSlotNumber(slot))
return false; return false;
//Read the node at that slot //Read the node at that slot
QVariantMap telescope = telescopeDescriptions.value(QString::number( slot)).toMap(); QVariantMap telescope = telescopeDescriptions.value(QString::number( slot)).toMap();
if(telescope.isEmpty()) if(telescope.isEmpty())
{ {
telescopeDescriptions.remove(QString::number(slot)); telescopeDescriptions.remove(QString::number(slot));
skipping to change at line 966 skipping to change at line 1041
connectAtStartup = telescope.value("connect_at_startup", false).toBo ol(); connectAtStartup = telescope.value("connect_at_startup", false).toBo ol();
QVariantList circleList = telescope.value("circles").toList(); QVariantList circleList = telescope.value("circles").toList();
if(!circleList.isEmpty() && circleList.size() <= MAX_CIRCLE_COUNT) if(!circleList.isEmpty() && circleList.size() <= MAX_CIRCLE_COUNT)
{ {
for(int i = 0; i < circleList.size(); i++) for(int i = 0; i < circleList.size(); i++)
circles.append(circleList.value(i, -1.0).toDouble()) ; circles.append(circleList.value(i, -1.0).toDouble()) ;
} }
QString connection = telescope.value("connection").toString(); QString connection = telescope.value("connection").toString();
if(connection == "internal") connectionType = connectionTypeNames.key(connection, ConnectionVirtu
al);
if(connectionType == ConnectionInternal)
{ {
deviceModelName = telescope.value("device_model").toString() ; deviceModelName = telescope.value("device_model").toString() ;
portSerial = telescope.value("serial_port").toString(); portSerial = telescope.value("serial_port").toString();
} }
return true; return true;
} }
bool TelescopeControl::removeTelescopeAtSlot(int slot) bool TelescopeControl::removeTelescopeAtSlot(int slot)
{ {
skipping to change at line 993 skipping to change at line 1069
bool TelescopeControl::startTelescopeAtSlot(int slot) bool TelescopeControl::startTelescopeAtSlot(int slot)
{ {
//Validation //Validation
if(!isValidSlotNumber(slot)) if(!isValidSlotNumber(slot))
return false; return false;
//Read the telescope properties //Read the telescope properties
QString name; QString name;
QString host; QString host;
ConnectionType connectionType;
int portTCP; int portTCP;
int delay; int delay;
bool connectAtStartup; bool connectAtStartup;
QList<double> circles; QList<double> circles;
QString deviceModelName; QString deviceModelName;
QString portSerial; QString portSerial;
if(!getTelescopeAtSlot(slot, name, host, portTCP, delay, connectAtSt artup, circles, deviceModelName, portSerial)) if(!getTelescopeAtSlot(slot, connectionType, name, host, portTCP, de lay, connectAtStartup, circles, deviceModelName, portSerial))
{ {
//TODO: Add debug //TODO: Add debug
return false; return false;
} }
if(!deviceModelName.isEmpty()) if(connectionType == ConnectionInternal && !deviceModelName.isEmpty( ))
{ {
if(deviceModels[deviceModelName].useExecutable) if(deviceModels[deviceModelName].useExecutable)
{ {
if (startClientAtSlot(slot, name, host, portTCP, del ay, circles)) if (startClientAtSlot(slot, connectionType, name, ho st, portTCP, delay, circles))
{ {
if(!startServerAtSlot(slot, deviceModelName, portTCP, portSerial)) if(!startServerAtSlot(slot, deviceModelName, portTCP, portSerial))
{ {
//If a server can't be started, remo ve the client too //If a server can't be started, remo ve the client too
stopClientAtSlot(slot); stopClientAtSlot(slot);
return false; return false;
} }
emit clientConnected(slot, name);
return true; return true;
} }
} }
else else
{ {
addLogAtSlot(slot); addLogAtSlot(slot);
logAtSlot(slot); logAtSlot(slot);
if (startClientAtSlot(slot, name, QString(), 0, dela y, circles, deviceModelName, portSerial)) if (startClientAtSlot(slot, connectionType, name, QS tring(), 0, delay, circles, deviceModelName, portSerial))
{ {
emit clientConnected(slot, name);
return true; return true;
} }
} }
} }
else else
{ {
if (startClientAtSlot(slot, name, host, portTCP, delay, circ les)) if (startClientAtSlot(slot, connectionType, name, host, port TCP, delay, circles))
{ {
emit clientConnected(slot, name);
return true; return true;
} }
} }
return false; return false;
} }
bool TelescopeControl::stopTelescopeAtSlot(int slot) bool TelescopeControl::stopTelescopeAtSlot(int slot)
{ {
//Validation //Validation
skipping to change at line 1083 skipping to change at line 1163
} }
return allStoppedSuccessfully; return allStoppedSuccessfully;
} }
bool TelescopeControl::isValidSlotNumber(int slot) bool TelescopeControl::isValidSlotNumber(int slot)
{ {
return ((slot < MIN_SLOT_NUMBER || slot > MAX_SLOT_NUMBER) ? false : true); return ((slot < MIN_SLOT_NUMBER || slot > MAX_SLOT_NUMBER) ? false : true);
} }
bool TelescopeControl::startServerAtSlot(int slotNumber, QString deviceMode bool TelescopeControl::isValidPort(uint port)
lName, int tcpPort, QString serialPort) {
//Check if the port number is in IANA's allowed range
return (port > 1023 && port <= 65535);
}
bool TelescopeControl::isValidDelay(int delay)
{
return (delay > 0 && delay <= MICROSECONDS_FROM_SECONDS(10));
}
bool TelescopeControl::startServerAtSlot(int slotNumber, QString deviceMode
lName, int portTCP, QString portSerial)
{ {
//Validate //Validate
if(!isValidSlotNumber(slotNumber) || tcpPort < 0 || tcpPort > 65535) //TODO: remove magic number if(!isValidSlotNumber(slotNumber) || !isValidPort(portTCP))
return false; return false;
//TODO: Validate the serial port? (Is this method going to be public ?) //TODO: Validate the serial port? (Is this method going to be public ?)
if(!deviceModels.contains(deviceModelName)) if(!deviceModels.contains(deviceModelName))
{ {
//TODO: Add debug //TODO: Add debug
return false; return false;
} }
QString slotName = QString::number(slotNumber); QString slotName = QString::number(slotNumber);
skipping to change at line 1113 skipping to change at line 1204
try try
{ {
serverExecutablePath = StelFileMgr::findFile(serverE xecutablesDirectoryPath + TELESCOPE_SERVER_PATH.arg(serverName), StelFileMg r::File); serverExecutablePath = StelFileMgr::findFile(serverE xecutablesDirectoryPath + TELESCOPE_SERVER_PATH.arg(serverName), StelFileMg r::File);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "TelescopeControl: Error starting telesc ope server: Can't find executable:" << serverExecutablePath; qDebug() << "TelescopeControl: Error starting telesc ope server: Can't find executable:" << serverExecutablePath;
return false; return false;
} }
#ifdef WIN32 #ifdef Q_OS_WIN32
QString serialPortName; QString serialPortName;
if(serialPort.right(serialPort.size() - SERIAL_PORT_PREFIX.s if(portSerial.right(portSerial.size() - SERIAL_PORT_PREFIX.s
ize()).toInt() > 9) ize()).toInt() > 9)
serialPortName = "\\\\.\\" + serialPort + ":";//"\\. serialPortName = "\\\\.\\" + portSerial + ":";//"\\.
\COMxx", not sure if it will work \COMxx", not sure if it will work
else else
serialPortName = serialPort + ":"; serialPortName = portSerial + ":";
#else #else
QString serialPortName = serialPort; QString serialPortName = portSerial;
#endif //WIN32 #endif //Q_OS_WIN32
QStringList serverArguments; QStringList serverArguments;
serverArguments << QString::number(tcpPort) << serialPortNam e; serverArguments << QString::number(portTCP) << serialPortNam e;
if(useTelescopeServerLogs) if(useTelescopeServerLogs)
serverArguments << QString(StelFileMgr::getUserDir() + "/log_TelescopeServer" + slotName + ".txt"); serverArguments << QString(StelFileMgr::getUserDir() + "/log_TelescopeServer" + slotName + ".txt");
qDebug() << "TelescopeControl: Starting tellescope server at slot" << slotName << "with path" << serverExecutablePath << "and arguments " << serverArguments.join(" "); qDebug() << "TelescopeControl: Starting tellescope server at slot" << slotName << "with path" << serverExecutablePath << "and arguments " << serverArguments.join(" ");
//Starting the new process //Starting the new process
telescopeServerProcess.insert(slotNumber, new QProcess()); telescopeServerProcess.insert(slotNumber, new QProcess());
//telescopeServerProcess[slotNumber]->setStandardOutputFile( StelFileMgr::getUserDir() + "/log_TelescopeServer" + slotName + ".txt");//I n case the server does not accept logfiles //telescopeServerProcess[slotNumber]->setStandardOutputFile( StelFileMgr::getUserDir() + "/log_TelescopeServer" + slotName + ".txt");//I n case the server does not accept logfiles
telescopeServerProcess[slotNumber]->start(serverExecutablePa th, serverArguments); telescopeServerProcess[slotNumber]->start(serverExecutablePa th, serverArguments);
//return telescopeServerProcess[slotNumber]->waitForStarted( ); //return telescopeServerProcess[slotNumber]->waitForStarted( );
skipping to change at line 1151 skipping to change at line 1242
return false; return false;
} }
bool TelescopeControl::stopServerAtSlot(int slotNumber) bool TelescopeControl::stopServerAtSlot(int slotNumber)
{ {
//Validate //Validate
if(!isValidSlotNumber(slotNumber) || !telescopeServerProcess.contain s(slotNumber)) if(!isValidSlotNumber(slotNumber) || !telescopeServerProcess.contain s(slotNumber))
return false; return false;
//Stop/close the process //Stop/close the process
#ifdef WIN32 #ifdef Q_OS_WIN32
telescopeServerProcess[slotNumber]->close(); telescopeServerProcess[slotNumber]->close();
#else #else
telescopeServerProcess[slotNumber]->terminate(); telescopeServerProcess[slotNumber]->terminate();
#endif //WIN32 #endif //Q_OS_WIN32
telescopeServerProcess[slotNumber]->waitForFinished(); telescopeServerProcess[slotNumber]->waitForFinished();
delete telescopeServerProcess[slotNumber]; delete telescopeServerProcess[slotNumber];
telescopeServerProcess.remove(slotNumber); telescopeServerProcess.remove(slotNumber);
return true; return true;
} }
bool TelescopeControl::startClientAtSlot(int slotNumber, QString name, QStr ing host, int portTCP, int delay, QList<double> circles, QString deviceMode lName, QString portSerial) bool TelescopeControl::startClientAtSlot(int slotNumber, ConnectionType con nectionType, QString name, QString host, int portTCP, int delay, QList<doub le> circles, QString deviceModelName, QString portSerial)
{ {
//Validation //Validation
if(!isValidSlotNumber(slotNumber)) if(!isValidSlotNumber(slotNumber))
return false; return false;
//Check if it's not already running //Check if it's not already running
//Should it return, or should it remove the old one and proceed? //Should it return, or should it remove the old one and proceed?
if(telescopeClients.contains(slotNumber)) if(telescopeClients.contains(slotNumber))
{ {
//TODO: Add debug. Update logic? //TODO: Add debug. Update logic?
return false; return false;
} }
QString initString; QString initString;
if(!deviceModelName.isEmpty() && !portSerial.isEmpty()) switch (connectionType)
{ {
initString = QString("%1:%2:%3:%4").arg(name, deviceModels[d case ConnectionVirtual:
eviceModelName].server, portSerial, QString::number(delay)); initString = QString("%1:%2").arg(name, "TelescopeServerDumm
} y");
else break;
{
initString = QString("%1:TCP:%2:%3:%4").arg(name, host, QStr case ConnectionInternal:
ing::number(portTCP), QString::number(delay)); if(!deviceModelName.isEmpty() && !portSerial.isEmpty())
initString = QString("%1:%2:%3:%4").arg(name, device
Models[deviceModelName].server, portSerial, QString::number(delay));
break;
case ConnectionLocal:
if (isValidPort(portTCP))
initString = QString("%1:TCP:%2:%3:%4").arg(name, "l
ocalhost", QString::number(portTCP), QString::number(delay));
break;
case ConnectionRemote:
default:
if (isValidPort(portTCP) && !host.isEmpty())
initString = QString("%1:TCP:%2:%3:%4").arg(name, ho
st, QString::number(portTCP), QString::number(delay));
} }
qDebug() << "initString:" << initString;
TelescopeClient* newTelescope = TelescopeClient::create(initString); TelescopeClient* newTelescope = TelescopeClient::create(initString);
if (newTelescope) if (newTelescope)
{ {
//Add FOV circles to the client if there are any specified //Add FOV circles to the client if there are any specified
if(!circles.isEmpty() && circles.size() <= MAX_CIRCLE_COUNT) if(!circles.isEmpty() && circles.size() <= MAX_CIRCLE_COUNT)
for (int i = 0; i < circles.size(); ++i) for (int i = 0; i < circles.size(); ++i)
newTelescope->addOcular(circles[i]); newTelescope->addOcular(circles[i]);
telescopeClients.insert(slotNumber, TelescopeClientP(newTele scope)); telescopeClients.insert(slotNumber, TelescopeClientP(newTele scope));
return true; return true;
skipping to change at line 1226 skipping to change at line 1332
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Telescope"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Telescope");
if(!newSelected.isEmpty()) if(!newSelected.isEmpty())
{ {
GETSTELMODULE(StelObjectMgr)->unSelect(); GETSTELMODULE(StelObjectMgr)->unSelect();
} }
telescopeClients.remove(slotNumber); telescopeClients.remove(slotNumber);
//This is not needed by every client //This is not needed by every client
removeLogAtSlot(slotNumber); removeLogAtSlot(slotNumber);
emit clientDisconnected(slotNumber);
return true; return true;
} }
void TelescopeControl::loadDeviceModels() void TelescopeControl::loadDeviceModels()
{ {
qDebug() << "TelescopeControl: Loading device model descriptions..." ; //qDebug() << "TelescopeControl: Loading device model descriptions.. .";
//Make sure that the device models file exists //Make sure that the device models file exists
bool useDefaultList = false; bool useDefaultList = false;
QString deviceModelsJsonPath = StelFileMgr::findFile("modules/Telesc opeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writa ble)) + "/device_models.json"; QString deviceModelsJsonPath = StelFileMgr::findFile("modules/Telesc opeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writa ble)) + "/device_models.json";
if(!QFileInfo(deviceModelsJsonPath).exists()) if(!QFileInfo(deviceModelsJsonPath).exists())
{ {
if(!restoreDeviceModelsListTo(deviceModelsJsonPath)) if(!restoreDeviceModelsListTo(deviceModelsJsonPath))
{ {
qWarning() << "TelescopeControl: Unable to find" << deviceModelsJsonPath; qWarning() << "TelescopeControl: Unable to find" << deviceModelsJsonPath;
useDefaultList = true; useDefaultList = true;
skipping to change at line 1306 skipping to change at line 1413
{ {
return; return;
} }
//Compile a list of the available telescope server executables //Compile a list of the available telescope server executables
loadTelescopeServerExecutables(); loadTelescopeServerExecutables();
if(telescopeServers.isEmpty()) if(telescopeServers.isEmpty())
{ {
//deviceModels = QHash<QString, DeviceModel>(); //deviceModels = QHash<QString, DeviceModel>();
//return; //return;
qWarning() << "TelescopeControl: No external telescope serve rs found, trying to use embedded servers..."; qWarning() << "TelescopeControl: Only embedded telescope ser vers are available.";
} }
//Clear the list of device models - it may not be empty. //Clear the list of device models - it may not be empty.
deviceModels.clear(); deviceModels.clear();
//Cicle the list of telescope deifinitions //Cicle the list of telescope deifinitions
for(int i = 0; i < deviceModelsList.size(); i++) for(int i = 0; i < deviceModelsList.size(); i++)
{ {
QVariantMap model = deviceModelsList.at(i).toMap(); QVariantMap model = deviceModelsList.at(i).toMap();
if(model.isEmpty()) if(model.isEmpty())
skipping to change at line 1335 skipping to change at line 1442
} }
if(deviceModels.contains(name)) if(deviceModels.contains(name))
{ {
qWarning() << "TelescopeControl: Skipping device mod el: Duplicate name:" << name; qWarning() << "TelescopeControl: Skipping device mod el: Duplicate name:" << name;
continue; continue;
} }
//Telescope server //Telescope server
QString server = model.value("server").toString(); QString server = model.value("server").toString();
bool useExecutable = true; //The default behaviour is to use embedded servers:
bool useExecutable = false;
if(server.isEmpty()) if(server.isEmpty())
{ {
//TODO: Add warning qWarning() << "TelescopeControl: Skipping device mod el: No server specified for" << name;
continue; continue;
} }
if(!telescopeServers.contains(server) || !useServerExecutabl es) if(useServerExecutables)
{ {
if(EMBEDDED_TELESCOPE_SERVERS.contains(server)) if(telescopeServers.contains(server))
{ {
qDebug() << "TelescopeControl: Using embedde qDebug() << "TelescopeControl: Using telesco
d telescope server for" << name; pe server executable for" << name;
useExecutable = true;
}
else if(EMBEDDED_TELESCOPE_SERVERS.contains(server))
{
qWarning() << "TelescopeControl: No external
telescope server executable found for" << name;
qWarning() << "TelescopeControl: Using embed
ded telescope server" << server << "for" << name;
useExecutable = false; useExecutable = false;
} }
else else
{ {
qWarning() << "TelescopeControl: Skipping de vice model: No server found:" << server; qWarning() << "TelescopeControl: Skipping de vice model: No server" << server << "found for" << name;
continue; continue;
} }
} }
else
{
if(!EMBEDDED_TELESCOPE_SERVERS.contains(server))
{
qWarning() << "TelescopeControl: Skipping de
vice model: No server" << server << "found for" << name;
continue;
}
//else: everything is OK, using embedded server
}
//Description and default connection delay //Description and default connection delay
QString description = model.value("description", "No descrip tion is available.").toString(); QString description = model.value("description", "No descrip tion is available.").toString();
int delay = model.value("default_delay", DEFAULT_DELAY).toIn t(); int delay = model.value("default_delay", DEFAULT_DELAY).toIn t();
//Add this to the main list //Add this to the main list
DeviceModel newDeviceModel = {name, description, server, del ay, useExecutable}; DeviceModel newDeviceModel = {name, description, server, del ay, useExecutable};
deviceModels.insert(name, newDeviceModel); deviceModels.insert(name, newDeviceModel);
qDebug() << "TelescopeControl: Adding device model:" << name << description << server << delay; //qDebug() << "TelescopeControl: Adding device model:" << na me << description << server << delay;
} }
} }
const QHash<QString, DeviceModel>& TelescopeControl::getDeviceModels() const QHash<QString, DeviceModel>& TelescopeControl::getDeviceModels()
{ {
return deviceModels; return deviceModels;
} }
QHash<int, QString> TelescopeControl::getConnectedClientsNames()
{
QHash<int, QString> connectedClientsNames;
if (telescopeClients.isEmpty())
return connectedClientsNames;
foreach (const int slotNumber, telescopeClients.keys())
{
if (telescopeClients.value(slotNumber)->isConnected())
connectedClientsNames.insert(slotNumber, telescopeCl
ients.value(slotNumber)->getNameI18n());
}
return connectedClientsNames;
}
bool TelescopeControl::restoreDeviceModelsListTo(QString deviceModelsListPa th) bool TelescopeControl::restoreDeviceModelsListTo(QString deviceModelsListPa th)
{ {
QFile defaultFile(":/telescopeControl/device_models.json"); QFile defaultFile(":/telescopeControl/device_models.json");
if (!defaultFile.copy(deviceModelsListPath)) if (!defaultFile.copy(deviceModelsListPath))
{ {
qWarning() << "TelescopeControl: Unable to copy the default device models list to" << deviceModelsListPath; qWarning() << "TelescopeControl: Unable to copy the default device models list to" << deviceModelsListPath;
return false; return false;
} }
QFile newCopy(deviceModelsListPath); QFile newCopy(deviceModelsListPath);
newCopy.setPermissions(newCopy.permissions() | QFile::WriteOwner); newCopy.setPermissions(newCopy.permissions() | QFile::WriteOwner);
qDebug() << "TelescopeControl: The default device models list has be en copied to" << deviceModelsListPath; qDebug() << "TelescopeControl: The default device models list has be en copied to" << deviceModelsListPath;
return true; return true;
} }
const QString& TelescopeControl::getModuleStyleSheet(const QString& styleMo deName) const StelStyle TelescopeControl::getModuleStyleSheet(const StelStyle& styl e)
{ {
return moduleStyleSheet[styleModeName]; StelStyle pluginStyle(style);
if (style.confSectionName == "color")
{
pluginStyle.qtStyleSheet.append(*normalStyleSheet);
}
else
{
pluginStyle.qtStyleSheet.append(*nightStyleSheet);
}
return pluginStyle;
} }
const QString& TelescopeControl::getServerExecutablesDirectoryPath() const QString& TelescopeControl::getServerExecutablesDirectoryPath()
{ {
return serverExecutablesDirectoryPath; return serverExecutablesDirectoryPath;
} }
bool TelescopeControl::setServerExecutablesDirectoryPath(const QString& new Path) bool TelescopeControl::setServerExecutablesDirectoryPath(const QString& new Path)
{ {
//TODO: Reuse code. //TODO: Reuse code.
 End of changes. 114 change blocks. 
245 lines changed or deleted 436 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/