Stellarium  0.90.0
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  virtual StelObjectP searchByID(const QString &id) const { return searchByName(id); }
97  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
98  // empty as its not celestial objects
99  virtual QStringList listAllObjects(bool) const { return QStringList(); }
100  virtual QString getName() const { return "Telescope Control"; }
101  virtual QString getStelObjectType() const;
102  virtual bool configureGui(bool show = true);
103 
105  // Methods specific to TelescopeControl
110  void telescopeGoto(int telescopeNr, const Vec3d &j2000Pos, StelObjectP selectObject = Q_NULLPTR);
111 
113  void deleteAllTelescopes();
114 
116  const QHash<QString, DeviceModel>& getDeviceModels();
117 
119  void loadConfiguration();
121  void saveConfiguration();
122 
124  void saveTelescopes();
126  void loadTelescopes();
127 
128  //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.
131  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(), QString rts2Url = QString(), QString rts2Username = QString(), QString rts2Password = QString(), int rts2Refresh = -1);
133  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, QString& rts2Url, QString& rts2Username, QString& rts2Password, int& rts2Refresh);
135  bool removeTelescopeAtSlot(int slot);
136 
138  bool startTelescopeAtSlot(int slot);
140  bool stopTelescopeAtSlot(int slot);
142  bool stopAllTelescopes();
143 
145  bool isExistingClientAtSlot(int slot);
147  bool isConnectedClientAtSlot(int slot);
148 
150  QHash<int, QString> getConnectedClientsNames();
151 
152  bool getFlagUseServerExecutables() {return useServerExecutables;}
154  void setFlagUseServerExecutables(bool b);
155  const QString& getServerExecutablesDirectoryPath();
157  bool setServerExecutablesDirectoryPath(const QString& newPath);
158 
159  bool getFlagUseTelescopeServerLogs () {return useTelescopeServerLogs;}
160 
161 public slots:
168  void setFlagTelescopeReticles(bool b) {reticleFader = b;}
175  bool getFlagTelescopeReticles() const {return (bool)reticleFader;}
176 
183  void setFlagTelescopeLabels(bool b) {labelFader = b;}
190  bool getFlagTelescopeLabels() const {return labelFader==true;}
191 
198  void setFlagTelescopeCircles(bool b) {circleFader = b;}
205  bool getFlagTelescopeCircles() const {return circleFader==true;}
206 
212  void setReticleColor(const Vec3f &c) {reticleColor = c;}
219  const Vec3f& getReticleColor() const {return reticleColor;}
220 
227  const Vec3f& getLabelColor() const {return labelColor;}
233  void setLabelColor(const Vec3f &c) {labelColor = c;}
234 
240  void setCircleColor(const Vec3f &c) {circleColor = c;}
247  const Vec3f& getCircleColor() const {return circleColor;}
248 
255  void setFontSize(int fontSize);
256 
264  void slewTelescopeToSelectedObject(const int idx);
265 
274  void slewTelescopeToViewDirection(const int idx);
275 
277  void setFlagUseTelescopeServerLogs (bool b) {useTelescopeServerLogs = b;}
278 
279 signals:
280  void clientConnected(int slot, QString name);
281  void clientDisconnected(int slot);
282 
283 private slots:
285  void translateActionDescriptions();
286 
287 private:
289  void drawPointer(const StelProjectorP& prj, const StelCore* core, StelPainter& sPainter);
290 
292  void communicate(void);
293 
294  LinearFader labelFader;
295  LinearFader reticleFader;
296  LinearFader circleFader;
298  Vec3f reticleColor;
300  Vec3f labelColor;
302  Vec3f circleColor;
303 
305  QFont labelFont;
306 
307  //Toolbar button to toggle the Slew window
308  StelButton* toolbarButton;
309 
311  StelTextureSP reticleTexture;
313  StelTextureSP selectionTexture;
314 
316  QMap<int, TelescopeClientP> telescopeClients;
318  QHash<int, QProcess*> telescopeServerProcess;
319  QStringList telescopeServers;
320  QVariantMap telescopeDescriptions;
321  QHash<QString, DeviceModel> deviceModels;
322 
323  QHash<ConnectionType, QString> connectionTypeNames;
324 
325  bool useTelescopeServerLogs;
326  QHash<int, QFile*> telescopeServerLogFiles;
327  QHash<int, QTextStream*> telescopeServerLogStreams;
328 
329  bool useServerExecutables;
330  QString serverExecutablesDirectoryPath;
331 
332  //GUI
333  TelescopeDialog * telescopeDialog;
334  SlewDialog * slewDialog;
335 
337  bool isValidSlotNumber(int slot);
338  bool isValidPort(uint port);
339  bool isValidDelay(int delay);
340 
345  bool startServerAtSlot(int slot, QString serverName, int tcpPort, QString serialPort);
347  bool stopServerAtSlot(int slot);
348 
350  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(), QString rts2Url = QString(), QString rts2Username = QString(), QString rts2Password = QString(), int rts2Refresh = -1);
351 
353  bool stopClientAtSlot(int slot);
354 
356  void loadTelescopeServerExecutables();
357 
359  void loadDeviceModels();
360 
363  bool restoreDeviceModelsListTo(QString deviceModelsListPath);
364 
365  void addLogAtSlot(int slot);
366  void logAtSlot(int slot);
367  void removeLogAtSlot(int slot);
368 
369  static void translations();
370 
371  QString actionGroupId;
372  QString moveToSelectedActionId;
373  QString moveToCenterActionId;
374 };
375 
376 
377 
378 #include <QObject>
379 #include "StelPluginInterface.hpp"
380 
383 {
384  Q_OBJECT
385  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
386  Q_INTERFACES(StelPluginInterface)
387 public:
388  virtual StelModule* getStelModule() const;
389  virtual StelPluginInfo getPluginInfo() const;
390  virtual QObjectList getExtensionList() const { return QObjectList(); }
391 };
392 
393 #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.
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
virtual StelObjectP searchByID(const QString &id) const
Return the StelObject with the given ID if exists or the empty StelObject if not found.
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.
virtual QString getName() const
Gets a user-displayable name of the object category.