TelescopeControl.cpp   TelescopeControl.cpp 
skipping to change at line 45 skipping to change at line 45
#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 "StelMovementMgr.hpp"
#include "StelObject.hpp" #include "StelObject.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelPainter.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelShortcutMgr.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelTextureMgr.hpp" #include "renderer/StelGeometryBuilder.hpp"
#include "renderer/StelRenderer.hpp"
#include "renderer/StelTextureNew.hpp"
#include <QAction> #include <QAction>
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QMapIterator> #include <QMapIterator>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
skipping to change at line 87 skipping to change at line 89
info.contact = "http://stellarium.org"; info.contact = "http://stellarium.org";
info.description = N_("This plug-in allows Stellarium to send \"slew \" commands to a telescope on a computerized mount (a \"GoTo telescope\")." ); info.description = N_("This plug-in allows Stellarium to send \"slew \" commands to a telescope on a computerized mount (a \"GoTo telescope\")." );
return info; return info;
} }
Q_EXPORT_PLUGIN2(TelescopeControl, TelescopeControlStelPluginInterface) Q_EXPORT_PLUGIN2(TelescopeControl, TelescopeControlStelPluginInterface)
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Constructor and destructor // Constructor and destructor
TelescopeControl::TelescopeControl() TelescopeControl::TelescopeControl()
: pixmapHover(NULL)
, pixmapOnIcon(NULL)
, pixmapOffIcon(NULL)
, reticleTexture(NULL)
, selectionTexture(NULL)
, telescopeDialog(NULL)
, slewDialog(NULL)
, actionGroupId("PluginTelescopeControl")
, moveToSelectedActionId("actionMove_Telescope_To_Selection_%1")
, moveToCenterActionId("actionSlew_Telescope_To_Direction_%1")
{ {
setObjectName("TelescopeControl"); setObjectName("TelescopeControl");
connectionTypeNames.insert(ConnectionVirtual, "virtual"); connectionTypeNames.insert(ConnectionVirtual, "virtual");
connectionTypeNames.insert(ConnectionInternal, "internal"); connectionTypeNames.insert(ConnectionInternal, "internal");
connectionTypeNames.insert(ConnectionLocal, "local"); connectionTypeNames.insert(ConnectionLocal, "local");
connectionTypeNames.insert(ConnectionRemote, "remote"); connectionTypeNames.insert(ConnectionRemote, "remote");
} }
TelescopeControl::~TelescopeControl() TelescopeControl::~TelescopeControl()
skipping to change at line 130 skipping to change at line 142
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
//(not necessary since revision 6308; remains as an example) //(not necessary since revision 6308; remains as an example)
//StelApp::getInstance().getModuleMgr().unloadModule("Telesc opeMgr", false); //StelApp::getInstance().getModuleMgr().unloadModule("Telesc opeMgr", false);
/*If the alsoDelete parameter is set to true, Stellarium cra shes with a /*If the alsoDelete parameter is set to true, Stellarium cra shes with a
segmentation fault when an object is selected. TODO: Find segmentation fault when an object is selected. TODO:
out why. Find out why.
unloadModule() didn't work prior to revision 5058: the mod unloadModule() didn't work prior to revision 5058: t
ule unloaded he module unloaded
normally, but Stellarium crashed later with a segmentation normally, but Stellarium crashed later with a segmen
fault, tation fault,
because LandscapeMgr::getCallOrder() depended on the modul because LandscapeMgr::getCallOrder() depended on the
e's module's
existence to return a value.*/ existence to return a value.*/
//Load and start all telescope clients //Load and start all telescope clients
loadTelescopes(); loadTelescopes();
//Load OpenGL textures
reticleTexture = StelApp::getInstance().getTextureManager().
createTexture(":/telescopeControl/telescope_reticle.png");
selectionTexture = StelApp::getInstance().getTextureManager(
).createTexture("textures/pointeur2.png");
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui()); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui());
StelShortcutMgr* shMgr = StelApp::getInstance().getStelShort cutManager();
//Create telescope key bindings //Create telescope key bindings
/* QAction-s with these key bindings existed in Stellarium prior to /* QAction-s with these key bindings existed in Stellarium p rior to
revision 6311. Any future backports should account f or that. */ revision 6311. Any future backports should account f or that. */
QString group = N_("Telescope Control");
for (int i = MIN_SLOT_NUMBER; i <= MAX_SLOT_NUMBER; i++) for (int i = MIN_SLOT_NUMBER; i <= MAX_SLOT_NUMBER; i++)
{ {
// "Slew to object" commands // "Slew to object" commands
QString name = QString("actionMove_Telescope_To_Sele QString name = moveToSelectedActionId.arg(i);
ction_%1").arg(i);
QString description = q_("Move telescope #%1 to sele
cted object").arg(i);
QString shortcut = QString("Ctrl+%1").arg(i); QString shortcut = QString("Ctrl+%1").arg(i);
gui->addGuiActions(name, description, shortcut, grou QAction* action = shMgr->addGuiAction(name, true, ""
p, false, false); ,
connect(gui->getGuiActions(name), SIGNAL(triggered() shortcut, "",
), this, SLOT(slewTelescopeToSelectedObject())); actionGroupId,
false);
connect(action, SIGNAL(triggered()),
this, SLOT(slewTelescopeToSelectedObject()))
;
// "Slew to the center of the screen" commands // "Slew to the center of the screen" commands
name = QString("actionSlew_Telescope_To_Direction_%1 name = moveToCenterActionId.arg(i);
").arg(i);
description = q_("Move telescope #%1 to the point cu
rrently in the center of the screen").arg(i);
shortcut = QString("Alt+%1").arg(i); shortcut = QString("Alt+%1").arg(i);
gui->addGuiActions(name, description, shortcut, grou action = shMgr->addGuiAction(name, true, "",
p, false, false); shortcut, "", actionGro
connect(gui->getGuiActions(name), SIGNAL(triggered() upId,
), this, SLOT(slewTelescopeToViewDirection())); false, false);
} connect(action, SIGNAL(triggered()), this,
SLOT(slewTelescopeToViewDirection()));
}
// Also updates descriptions if the actions have been loaded
from file
translateActionDescriptions();
connect(&StelApp::getInstance(), SIGNAL(languageChanged()),
this, SLOT(translateActionDescriptions()));
//Create and initialize dialog windows //Create and initialize dialog windows
telescopeDialog = new TelescopeDialog(); telescopeDialog = new TelescopeDialog();
slewDialog = new SlewDialog(); slewDialog = new SlewDialog();
//TODO: Think of a better keyboard shortcut connect(shMgr->getGuiAction("actionShow_Slew_Window"), SIGNA
gui->addGuiActions("actionShow_Slew_Window", N_("Move a tele L(toggled(bool)), slewDialog, SLOT(setVisible(bool)));
scope to a given set of coordinates"), "Ctrl+0", group, true, false); connect(slewDialog, SIGNAL(visibleChanged(bool)), shMgr->get
connect(gui->getGuiActions("actionShow_Slew_Window"), SIGNAL GuiAction("actionShow_Slew_Window"), SLOT(setChecked(bool)));
(toggled(bool)), slewDialog, SLOT(setVisible(bool)));
connect(slewDialog, SIGNAL(visibleChanged(bool)), gui->getGu
iActions("actionShow_Slew_Window"), SLOT(setChecked(bool)));
//Create toolbar button //Create toolbar button
pixmapHover = new QPixmap(":/graphicGui/glow32x32.png"); pixmapHover = new QPixmap(":/graphicGui/glow32x32.png");
pixmapOnIcon = new QPixmap(":/telescopeControl/button_Slew_ pixmapOnIcon = new QPixmap(":/telescopeControl/button_Slew_
Dialog_on.png"); Dialog_on.png");
pixmapOffIcon = new QPixmap(":/telescopeControl/button_Slew_ pixmapOffIcon = new QPixmap(":/telescopeControl/button_Slew_
Dialog_off.png"); Dialog_off.png");
toolbarButton = new StelButton(NULL, *pixmapOnIcon, *pixmapO toolbarButton = new StelButton(NULL, *pixmapOnIcon, *pixmapOffIcon,
ffIcon, *pixmapHover, gui->getGuiActions("actionShow_Slew_Window")); *pixmapHover, gui->getGuiAction("actionShow_Slew_Window"));
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr oup"); gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr oup");
} }
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);
skipping to change at line 205 skipping to change at line 219
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 Q_OS_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;
} }
if(NULL != reticleTexture) {delete reticleTexture;}
if(NULL != selectionTexture) {delete selectionTexture;}
if(NULL != telescopeDialog) {delete telescopeDialog;}
if(NULL != slewDialog) {delete slewDialog;}
if(NULL != pixmapHover) {delete pixmapHover;}
if(NULL != pixmapOnIcon) {delete pixmapOnIcon;}
if(NULL != pixmapOffIcon) {delete pixmapOffIcon;}
reticleTexture = selectionTexture = NULL;
telescopeDialog = NULL;
slewDialog = NULL;
pixmapHover = pixmapOnIcon = pixmapOffIcon;
//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)); 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, StelRenderer* renderer)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
StelPainter sPainter(prj); renderer->setFont(labelFont);
sPainter.setFont(labelFont); if(NULL == reticleTexture)
glEnable(GL_TEXTURE_2D); {
glEnable(GL_BLEND); Q_ASSERT_X(NULL == selectionTexture, Q_FUNC_INFO, "Textures
reticleTexture->bind(); should be created simultaneously");
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transpa reticleTexture = renderer->createTexture(":/telescopeContr
rency mode ol/telescope_reticle.png");
selectionTexture = renderer->createTexture("textures/pointeu
r2.png");
}
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(core), XY)) if (prj->projectCheck(telescope->getJ2000EquatorialP os(core), XY))
{ {
//Telescope circles appear synchronously wit h markers //Telescope circles appear synchronously wit h markers
if (circleFader.getInterstate() >= 0) if (circleFader.getInterstate() >= 0)
{ {
glColor4f(circleColor[0], circleColo renderer->setGlobalColor(circleColor
r[1], circleColor[2], circleFader.getInterstate()); [0], circleColor[1], circleColor[2],
glDisable(GL_TEXTURE_2D); circleFader
.getInterstate());
renderer->setBlendMode(BlendMode_Non
e);
StelVertexBuffer<VertexP2>* circleBu
ffer =
renderer->createVertexBuffer
<VertexP2>(PrimitiveType_LineStrip);
foreach (double circle, telescope->g etOculars()) foreach (double circle, telescope->g etOculars())
{ {
sPainter.drawCircle(XY[0], X StelGeometryBuilder()
Y[1], 0.5 * prj->getPixelPerRadAtCenter() * (M_PI/180) * (circle)); .buildCircle(circleB
uffer, XY[0], XY[1],
0.5f *
prj->getPixelPerRadAtCenter() * (M_PI / 180.0f) * circle);
renderer->drawVertexBuffer(c
ircleBuffer);
circleBuffer->unlock();
circleBuffer->clear();
} }
glEnable(GL_TEXTURE_2D); delete circleBuffer;
} }
if (reticleFader.getInterstate() >= 0) if (reticleFader.getInterstate() >= 0)
{ {
glColor4f(reticleColor[0], reticleCo renderer->setBlendMode(BlendMode_Alp
lor[1], reticleColor[2], reticleFader.getInterstate()); ha);
sPainter.drawSprite2dMode(XY[0],XY[1 reticleTexture->bind();
],15.f); renderer->setGlobalColor(reticleColo
r[0], reticleColor[1], reticleColor[2],
reticleFade
r.getInterstate());
renderer->drawTexturedRect(XY[0] - 1
5.0f, XY[1] - 15.0f, 30.0f, 30.0f);
} }
if (labelFader.getInterstate() >= 0) if (labelFader.getInterstate() >= 0)
{ {
glColor4f(labelColor[0], labelColor[ renderer->setGlobalColor(labelColor[
1], labelColor[2], labelFader.getInterstate()); 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 renderer->drawText(TextParams(XY[0],
scope->getNameI18n(), 0, 6 + 10, -4, false); XY[1], telescope->getNameI18n())
.shift(6 + 10, -
4).useGravity());
//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();
} }
} }
} }
} }
if(GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if(GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
drawPointer(prj, core, sPainter); {
drawPointer(prj, core, renderer);
}
} }
void TelescopeControl::setStelStyle(const QString& section) void TelescopeControl::setStelStyle(const QString& section)
{ {
if (section == "night_color") if (section == "night_color")
{ {
setLabelColor(labelNightColor); setLabelColor(labelNightColor);
setReticleColor(reticleNightColor); setReticleColor(reticleNightColor);
setCircleColor(circleNightColor); setCircleColor(circleNightColor);
} }
skipping to change at line 343 skipping to change at line 386
return qSharedPointerCast<StelObject>(telescope); return qSharedPointerCast<StelObject>(telescope);
} }
return 0; return 0;
} }
StelObjectP TelescopeControl::searchByName(const QString &name) const StelObjectP TelescopeControl::searchByName(const QString &name) const
{ {
foreach (const TelescopeClientP& telescope, telescopeClients) foreach (const TelescopeClientP& telescope, telescopeClients)
{ {
if (telescope->getEnglishName() == name) if (telescope->getEnglishName() == name)
return qSharedPointerCast<StelObject>(telescope); return qSharedPointerCast<StelObject>(telescope);
} }
return 0; return 0;
} }
QStringList TelescopeControl::listMatchingObjectsI18n(const QString& objPre fix, int maxNbItem) const QStringList TelescopeControl::listMatchingObjectsI18n(const QString& objPre fix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0) return result;
QString objw = objPrefix.toUpper(); QString objw = objPrefix.toUpper();
skipping to change at line 384 skipping to change at line 427
telescopeDialog->setVisible(true); telescopeDialog->setVisible(true);
} }
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::slewTelescopeToSelectedObject() void TelescopeControl::slewTelescopeToSelectedObject()
{ {
// Find out for which telescope is the command // Find out for which telescope is the command
if (sender() == NULL) if (sender() == NULL)
return; return;
int slotNumber = sender()->objectName().right(1).toInt(); int slotNumber = sender()->objectName().right(1).toInt();
// Find out the coordinates of the target // Find out the coordinates of the target
skipping to change at line 421 skipping to change at line 464
if (sender() == NULL) if (sender() == NULL)
return; return;
int slotNumber = sender()->objectName().right(1).toInt(); int slotNumber = sender()->objectName().right(1).toInt();
// Find out the coordinates of the target // Find out the coordinates of the target
Vec3d centerPosition = GETSTELMODULE(StelMovementMgr)->getViewDirect ionJ2000(); Vec3d centerPosition = GETSTELMODULE(StelMovementMgr)->getViewDirect ionJ2000();
telescopeGoto(slotNumber, centerPosition); telescopeGoto(slotNumber, centerPosition);
} }
void TelescopeControl::drawPointer(const StelProjectorP& prj, const StelCor e* core, StelPainter& sPainter) void TelescopeControl::drawPointer(const StelProjectorP& prj, const StelCor e* core, StelRenderer* renderer)
{ {
#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(core); Vec3d pos = obj->getJ2000EquatorialPos(core);
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 Vec3f& c(obj->getInfoColor()); const Vec3f& c(obj->getInfoColor());
sPainter.setColor(c[0], c[1], c[2]); renderer->setGlobalColor(c[0], c[1], c[2]);
selectionTexture->bind(); selectionTexture->bind();
glEnable(GL_TEXTURE_2D); renderer->setBlendMode(BlendMode_Alpha);
glEnable(GL_BLEND); renderer->drawTexturedRect(screenpos[0] - 25.0f, screenpos[1
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal ] - 25.0f, 50.0f, 50.0f,
transparency mode StelApp::getInstance().getTotalRu
sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 25., S nTime() * 40.0f);
telApp::getInstance().getTotalRunTime() * 40.);
} }
#endif //COMPATIBILITY_001002 #endif //COMPATIBILITY_001002
} }
void TelescopeControl::telescopeGoto(int slotNumber, const Vec3d &j2000Pos) void TelescopeControl::telescopeGoto(int slotNumber, const Vec3d &j2000Pos)
{ {
//TODO: See the original code. I think that something is wrong here. .. //TODO: See the original code. I think that something is wrong here. ..
if(telescopeClients.contains(slotNumber)) if(telescopeClients.contains(slotNumber))
telescopeClients.value(slotNumber)->telescopeGoto(j2000Pos); telescopeClients.value(slotNumber)->telescopeGoto(j2000Pos);
} }
void TelescopeControl::communicate(void) void TelescopeControl::communicate(void)
skipping to change at line 525 skipping to change at line 567
} }
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
{ {
qWarning() << "TelescopeControl: No telescope server executa bles found in" qWarning() << "TelescopeControl: No telescope server executa bles found in"
<< serverExecutablesDirectoryPath; << serverExecutable sDirectoryPath;
} }
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// 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
setFlagTelescopeReticles(settings->value("flag_telescope_reticles", true).toBool()); setFlagTelescopeReticles(settings->value("flag_telescope_reticles", true).toBool());
setFlagTelescopeLabels(settings->value("flag_telescope_labels", true ).toBool()); setFlagTelescopeLabels(settings->value("flag_telescope_labels", true ).toBool());
setFlagTelescopeCircles(settings->value("flag_telescope_circles", tr ue).toBool()); setFlagTelescopeCircles(settings->value("flag_telescope_circles", tr ue).toBool());
//Load font size //Load font size
#ifdef Q_OS_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
reticleNormalColor = StelUtils::strToVec3f(settings->value("color_te lescope_reticles", "0.6,0.4,0").toString()); reticleNormalColor = StelUtils::strToVec3f(settings->value("color_te lescope_reticles", "0.6,0.4,0").toString());
reticleNightColor = StelUtils::strToVec3f(settings->value("night_col or_telescope_reticles", "0.5,0,0").toString()); reticleNightColor = StelUtils::strToVec3f(settings->value("night_col 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()); 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()); 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
skipping to change at line 1179 skipping to change at line 1221
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 Q_OS_WIN32 #ifdef Q_OS_WIN32
QString serialPortName; QString serialPortName;
if(portSerial.right(portSerial.size() - SERIAL_PORT_PREFIX.s ize()).toInt() > 9) if(portSerial.right(portSerial.size() - SERIAL_PORT_PREFIX.s ize()).toInt() > 9)
serialPortName = "\\\\.\\" + portSerial;//"\\.\COMxx ", not sure if it will work serialPortName = "\\\\.\\" + portSerial;//"\\.\COMxx ", not sure if it will work
else else
serialPortName = portSerial; serialPortName = portSerial;
#else #else
QString serialPortName = portSerial; QString serialPortName = portSerial;
#endif //Q_OS_WIN32 #endif //Q_OS_WIN32
QStringList serverArguments; QStringList serverArguments;
serverArguments << QString::number(portTCP) << 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
skipping to change at line 1217 skipping to change at line 1259
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 Q_OS_WIN32 #ifdef Q_OS_WIN32
telescopeServerProcess[slotNumber]->close(); telescopeServerProcess[slotNumber]->close();
#else #else
telescopeServerProcess[slotNumber]->terminate(); telescopeServerProcess[slotNumber]->terminate();
#endif //Q_OS_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, ConnectionType con nectionType, QString name, QString equinox, QString host, int portTCP, int delay, QList<double> circles, QString deviceModelName, QString portSerial) bool TelescopeControl::startClientAtSlot(int slotNumber, ConnectionType con nectionType, QString name, QString equinox, QString host, int portTCP, int delay, QList<double> circles, QString deviceModelName, QString portSerial)
{ {
skipping to change at line 1247 skipping to change at line 1289
//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;
switch (connectionType) switch (connectionType)
{ {
case ConnectionVirtual: case ConnectionVirtual:
initString = QString("%1:%2:%3").arg(name, "TelescopeServerD initString = QString("%1:%2:%3").arg(name, "Telescop
ummy", "J2000"); eServerDummy", "J2000");
break; break;
case ConnectionInternal: case ConnectionInternal:
if(!deviceModelName.isEmpty() && !portSerial.isEmpty()) if(!deviceModelName.isEmpty() && !portSerial.isEmpty
initString = QString("%1:%2:%3:%4:%5").arg(name, dev ())
iceModels[deviceModelName].server, equinox, portSerial, QString::number(del initString = QString("%1:%2:%3:%4:%5").arg(n
ay)); ame, deviceModels[deviceModelName].server, equinox, portSerial, QString::nu
break; mber(delay));
break;
case ConnectionLocal:
if (isValidPort(portTCP)) case ConnectionLocal:
initString = QString("%1:TCP:%2:%3:%4:%5").arg(name, if (isValidPort(portTCP))
equinox, "localhost", QString::number(portTCP), QString::number(delay)); initString = QString("%1:TCP:%2:%3:%4:%5").a
break; rg(name, equinox, "localhost", QString::number(portTCP), QString::number(de
lay));
case ConnectionRemote: break;
default:
if (isValidPort(portTCP) && !host.isEmpty()) case ConnectionRemote:
initString = QString("%1:TCP:%2:%3:%4:%5").arg(name, default:
equinox, host, QString::number(portTCP), QString::number(delay)); if (isValidPort(portTCP) && !host.isEmpty())
initString = QString("%1:TCP:%2:%3:%4:%5").a
rg(name, equinox, host, QString::number(portTCP), QString::number(delay));
} }
//qDebug() << "initString:" << initString; //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)
skipping to change at line 1517 skipping to change at line 1559
QDir newServerDirectory(newPath); QDir newServerDirectory(newPath);
if(!newServerDirectory.exists()) if(!newServerDirectory.exists())
{ {
qWarning() << "TelescopeControl: Can't find such a directory :" << newPath; qWarning() << "TelescopeControl: Can't find such a directory :" << newPath;
return false; return false;
} }
QList<QFileInfo> telescopeServerExecutables = newServerDirectory.ent ryInfoList(QStringList("TelescopeServer*"), (QDir::Files|QDir::Executable|Q Dir::CaseSensitive), QDir::Name); QList<QFileInfo> telescopeServerExecutables = newServerDirectory.ent ryInfoList(QStringList("TelescopeServer*"), (QDir::Files|QDir::Executable|Q Dir::CaseSensitive), QDir::Name);
if(telescopeServerExecutables.isEmpty()) if(telescopeServerExecutables.isEmpty())
{ {
qWarning() << "TelescopeControl: No telescope server executa bles found in" qWarning() << "TelescopeControl: No telescope server executa bles found in"
<< serverExecutablesDirectoryPath; << serverExecutable sDirectoryPath;
return false; return false;
} }
//If everything is fine... //If everything is fine...
serverExecutablesDirectoryPath = newPath; serverExecutablesDirectoryPath = newPath;
stopAllTelescopes(); stopAllTelescopes();
loadDeviceModels(); loadDeviceModels();
return true; return true;
} }
skipping to change at line 1557 skipping to change at line 1599
telescopeServerLogFiles.insert(slot, new QFile()); telescopeServerLogFiles.insert(slot, new QFile());
telescopeServerLogStreams.insert(slot, new QTextStre am(telescopeServerLogFiles.value(slot))); telescopeServerLogStreams.insert(slot, new QTextStre am(telescopeServerLogFiles.value(slot)));
return; return;
} }
QString filePath = StelFileMgr::getUserDir() + "/log_Telesco peServer" + QString::number(slot) + ".txt"; QString filePath = StelFileMgr::getUserDir() + "/log_Telesco peServer" + QString::number(slot) + ".txt";
QFile* logFile = new QFile(filePath); QFile* logFile = new QFile(filePath);
if (!logFile->open(QFile::WriteOnly|QFile::Text|QFile::Trunc ate|QFile::Unbuffered)) if (!logFile->open(QFile::WriteOnly|QFile::Text|QFile::Trunc ate|QFile::Unbuffered))
{ {
qWarning() << "TelescopeControl: Unable to create a log file for slot" qWarning() << "TelescopeControl: Unable to create a log file for slot"
<< slot << ":" << filePath; << slot << ":" << filePath;
telescopeServerLogFiles.insert(slot, logFile); telescopeServerLogFiles.insert(slot, logFile);
telescopeServerLogStreams.insert(slot, new QTextStre am(new QFile())); telescopeServerLogStreams.insert(slot, new QTextStre am(new QFile()));
} }
telescopeServerLogFiles.insert(slot, logFile); telescopeServerLogFiles.insert(slot, logFile);
QTextStream * logStream = new QTextStream(logFile); QTextStream * logStream = new QTextStream(logFile);
telescopeServerLogStreams.insert(slot, logStream); telescopeServerLogStreams.insert(slot, logStream);
} }
} }
skipping to change at line 1583 skipping to change at line 1625
telescopeServerLogStreams.remove(slot); telescopeServerLogStreams.remove(slot);
telescopeServerLogFiles.remove(slot); telescopeServerLogFiles.remove(slot);
} }
} }
void TelescopeControl::logAtSlot(int slot) void TelescopeControl::logAtSlot(int slot)
{ {
if(telescopeServerLogStreams.contains(slot)) if(telescopeServerLogStreams.contains(slot))
log_file = telescopeServerLogStreams.value(slot); log_file = telescopeServerLogStreams.value(slot);
} }
void TelescopeControl::translateActionDescriptions()
{
StelShortcutMgr* shMgr = StelApp::getInstance().getStelShortcutManag
er();
if (!shMgr)
return;
for (int i = MIN_SLOT_NUMBER; i <= MAX_SLOT_NUMBER; i++)
{
QString name = moveToSelectedActionId.arg(i);
QString description = q_("Move telescope #%1 to selected obj
ect")
.arg(i);
shMgr->setShortcutText(name, actionGroupId, description);
name = moveToCenterActionId.arg(i);
description = q_("Move telescope #%1 to the point currently
in the center of the screen").arg(i);
shMgr->setShortcutText(name, actionGroupId, description);
}
}
 End of changes. 50 change blocks. 
124 lines changed or deleted 174 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/