Stellarium 0.15.2
TelescopeControl.hpp
1 /*
2  * Stellarium Telescope Control Plug-in
3  *
4  * Copyright (C) 2006 Johannes Gajdosik
5  * Copyright (C) 2009-2010 Bogdan Marinov
6  *
7  * This module was originally written by Johannes Gajdosik in 2006
8  * as a core module of Stellarium. In 2009 it was significantly extended with
9  * GUI features and later split as an external plug-in module by Bogdan Marinov.
10  *
11  * This class used to be called TelescopeMgr before the split.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
26  */
27 
28 #ifndef _TELESCOPE_CONTROL_HPP_
29 #define _TELESCOPE_CONTROL_HPP_
30 
31 #include "StelFader.hpp"
32 #include "StelGui.hpp"
33 #include "StelJsonParser.hpp"
34 #include "StelObjectModule.hpp"
35 #include "StelProjectorType.hpp"
36 #include "StelTextureTypes.hpp"
37 #include "TelescopeControlGlobals.hpp"
38 #include "VecMath.hpp"
39 
40 #include <QFile>
41 #include <QFont>
42 #include <QHash>
43 #include <QMap>
44 #include <QProcess>
45 #include <QSettings>
46 #include <QString>
47 #include <QStringList>
48 #include <QTextStream>
49 #include <QVariant>
50 
51 class StelObject;
52 class StelPainter;
53 class StelProjector;
54 class TelescopeClient;
55 class TelescopeDialog;
56 class SlewDialog;
57 
58 
59 using namespace TelescopeControlGlobals;
60 
61 typedef QSharedPointer<TelescopeClient> TelescopeClientP;
62 
71 {
72  Q_OBJECT
73 
74 public:
76  virtual ~TelescopeControl();
77 
79  // Methods defined in the StelModule class
80  virtual void init();
81  virtual void deinit();
82  virtual void update(double deltaTime);
83  virtual void draw(StelCore * core);
84  virtual double getCallOrder(StelModuleActionName actionName) const;
85 
87  // Methods defined in the StelObjectModule class
88  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
89  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
90  virtual StelObjectP searchByName(const QString& name) const;
91  // empty as its not celestial objects
92  virtual QStringList listAllObjects(bool) const { return QStringList(); }
93  virtual QString getName() const { return "Telescope Control"; }
94  virtual bool configureGui(bool show = true);
95 
97  // Methods specific to TelescopeControl
101  void telescopeGoto(int telescopeNr, const Vec3d &j2000Pos);
102 
104  void deleteAllTelescopes();
105 
107  const QHash<QString, DeviceModel>& getDeviceModels();
108 
110  void loadConfiguration();
112  void saveConfiguration();
113 
115  void saveTelescopes();
117  void loadTelescopes();
118 
119  //These are public, but not slots, because they don't use sufficient validation. Scripts shouldn't be able to add/remove telescopes, only to point them.
122  bool addTelescopeAtSlot(int slot, ConnectionType connectionType, QString name, QString equinox, QString host = QString("localhost"), int portTCP = DEFAULT_TCP_PORT, int delay = DEFAULT_DELAY, bool connectAtStartup = false, QList<double> circles = QList<double>(), QString serverName = QString(), QString portSerial = QString());
124  bool getTelescopeAtSlot(int slot, ConnectionType& connectionType, QString& name, QString& equinox, QString& host, int& portTCP, int& delay, bool& connectAtStartup, QList<double>& circles, QString& serverName, QString& portSerial);
126  bool removeTelescopeAtSlot(int slot);
127 
129  bool startTelescopeAtSlot(int slot);
131  bool stopTelescopeAtSlot(int slot);
133  bool stopAllTelescopes();
134 
136  bool isExistingClientAtSlot(int slot);
138  bool isConnectedClientAtSlot(int slot);
139 
141  QHash<int, QString> getConnectedClientsNames();
142 
143  bool getFlagUseServerExecutables() {return useServerExecutables;}
145  void setFlagUseServerExecutables(bool b);
146  const QString& getServerExecutablesDirectoryPath();
148  bool setServerExecutablesDirectoryPath(const QString& newPath);
149 
150  bool getFlagUseTelescopeServerLogs () {return useTelescopeServerLogs;}
151 
152 public slots:
159  void setFlagTelescopeReticles(bool b) {reticleFader = b;}
166  bool getFlagTelescopeReticles() const {return (bool)reticleFader;}
167 
174  void setFlagTelescopeLabels(bool b) {labelFader = b;}
181  bool getFlagTelescopeLabels() const {return labelFader==true;}
182 
189  void setFlagTelescopeCircles(bool b) {circleFader = b;}
196  bool getFlagTelescopeCircles() const {return circleFader==true;}
197 
203  void setReticleColor(const Vec3f &c) {reticleColor = c;}
210  const Vec3f& getReticleColor() const {return reticleColor;}
211 
218  const Vec3f& getLabelColor() const {return labelColor;}
224  void setLabelColor(const Vec3f &c) {labelColor = c;}
225 
231  void setCircleColor(const Vec3f &c) {circleColor = c;}
238  const Vec3f& getCircleColor() const {return circleColor;}
239 
246  void setFontSize(int fontSize);
247 
255  void slewTelescopeToSelectedObject(const int idx);
256 
265  void slewTelescopeToViewDirection(const int idx);
266 
268  void setFlagUseTelescopeServerLogs (bool b) {useTelescopeServerLogs = b;}
269 
270 signals:
271  void clientConnected(int slot, QString name);
272  void clientDisconnected(int slot);
273 
274 private slots:
276  void translateActionDescriptions();
277 
278 private:
280  void drawPointer(const StelProjectorP& prj, const StelCore* core, StelPainter& sPainter);
281 
283  void communicate(void);
284 
285  LinearFader labelFader;
286  LinearFader reticleFader;
287  LinearFader circleFader;
289  Vec3f reticleColor;
291  Vec3f labelColor;
293  Vec3f circleColor;
294 
296  QFont labelFont;
297 
298  //Toolbar button to toggle the Slew window
299  StelButton* toolbarButton;
300 
302  StelTextureSP reticleTexture;
304  StelTextureSP selectionTexture;
305 
307  QMap<int, TelescopeClientP> telescopeClients;
309  QHash<int, QProcess*> telescopeServerProcess;
310  QStringList telescopeServers;
311  QVariantMap telescopeDescriptions;
312  QHash<QString, DeviceModel> deviceModels;
313 
314  QHash<ConnectionType, QString> connectionTypeNames;
315 
316  bool useTelescopeServerLogs;
317  QHash<int, QFile*> telescopeServerLogFiles;
318  QHash<int, QTextStream*> telescopeServerLogStreams;
319 
320  bool useServerExecutables;
321  QString serverExecutablesDirectoryPath;
322 
323  //GUI
324  TelescopeDialog * telescopeDialog;
325  SlewDialog * slewDialog;
326 
328  bool isValidSlotNumber(int slot);
329  bool isValidPort(uint port);
330  bool isValidDelay(int delay);
331 
336  bool startServerAtSlot(int slot, QString serverName, int tcpPort, QString serialPort);
338  bool stopServerAtSlot(int slot);
339 
341  bool startClientAtSlot(int slot, ConnectionType connectionType, QString name, QString equinox, QString host, int portTCP, int delay, QList<double> circles, QString serverName = QString(), QString portSerial = QString());
342 
344  bool stopClientAtSlot(int slot);
345 
347  void loadTelescopeServerExecutables();
348 
350  void loadDeviceModels();
351 
354  bool restoreDeviceModelsListTo(QString deviceModelsListPath);
355 
356  void addLogAtSlot(int slot);
357  void logAtSlot(int slot);
358  void removeLogAtSlot(int slot);
359 
360  QString actionGroupId;
361  QString moveToSelectedActionId;
362  QString moveToCenterActionId;
363 };
364 
365 
366 
367 #include <QObject>
368 #include "StelPluginInterface.hpp"
369 
372 {
373  Q_OBJECT
374  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
375  Q_INTERFACES(StelPluginInterface)
376 public:
377  virtual StelModule* getStelModule() const;
378  virtual StelPluginInfo getPluginInfo() const;
379 };
380 
381 #endif /*_TELESCOPE_CONTROL_HPP_*/
const Vec3f & getLabelColor() const
Get the telescope labels color.
virtual QStringList listAllObjects(bool) const
List all StelObjects.
void setLabelColor(const Vec3f &c)
Set the telescope labels color.
Define the interface to implement when creating a plugin.
Implementation of StelFader which implements a linear transition.
Definition: StelFader.hpp:77
The base abstract class for sky objects used in Stellarium like Stars, Planets, Constellations etc...
Definition: StelObject.hpp:36
void setFlagTelescopeReticles(bool b)
Set display flag for telescope reticles.
void setFlagTelescopeCircles(bool b)
Set display flag for telescope field of view circles.
Define the StelTextureSP type.
bool getFlagTelescopeCircles() const
Get display flag for telescope field of view circles.
An abstract base class that should never be used directly, only inherited.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
This class manages the controlling of one or more telescopes by one instance of the stellarium progra...
bool getFlagTelescopeReticles() const
Get display flag for telescope reticles.
Specialization of StelModule which manages a collection of StelObject.
This class is used by Qt to manage a plug-in interface.
void setCircleColor(const Vec3f &c)
Set the field of view circles color.
QSharedPointer< StelProjector > StelProjectorP
Shared pointer on a StelProjector instance (implement reference counting)
bool getFlagTelescopeLabels() const
Get display flag for telescope name labels.
void setFlagTelescopeLabels(bool b)
Set display flag for telescope name labels.
const Vec3f & getReticleColor() const
Get the telescope reticle color.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
Provide the main interface to all operations of projecting coordinates from sky to screen...
A Button Graphicsitem for use in Stellarium&#39;s graphic widgets.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
void setFlagUseTelescopeServerLogs(bool b)
Used in the GUI.
void setReticleColor(const Vec3f &c)
Set the telescope reticle color.
Define the StelProjectorP type.
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
const Vec3f & getCircleColor() const
Get the field of view circles color.
Contains information about a Stellarium plugin.