Stellarium 0.14.3
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;
96  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
102  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
103  // empty as its not celestial objects
104  virtual QStringList listAllObjects(bool inEnglish) const { Q_UNUSED(inEnglish) return QStringList(); }
105  virtual QStringList listAllObjectsByType(const QString& objType, bool inEnglish) const { Q_UNUSED(objType) Q_UNUSED(inEnglish) return QStringList(); }
106  virtual QString getName() const { return "Telescope Control"; }
107  virtual bool configureGui(bool show = true);
108 
110  // Methods specific to TelescopeControl
114  void telescopeGoto(int telescopeNr, const Vec3d &j2000Pos);
115 
117  void deleteAllTelescopes();
118 
120  const QHash<QString, DeviceModel>& getDeviceModels();
121 
123  void loadConfiguration();
125  void saveConfiguration();
126 
128  void saveTelescopes();
130  void loadTelescopes();
131 
132  //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.
135  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());
137  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);
139  bool removeTelescopeAtSlot(int slot);
140 
142  bool startTelescopeAtSlot(int slot);
144  bool stopTelescopeAtSlot(int slot);
146  bool stopAllTelescopes();
147 
149  bool isExistingClientAtSlot(int slot);
151  bool isConnectedClientAtSlot(int slot);
152 
154  QHash<int, QString> getConnectedClientsNames();
155 
156  bool getFlagUseServerExecutables() {return useServerExecutables;}
158  void setFlagUseServerExecutables(bool b);
159  const QString& getServerExecutablesDirectoryPath();
161  bool setServerExecutablesDirectoryPath(const QString& newPath);
162 
163  bool getFlagUseTelescopeServerLogs () {return useTelescopeServerLogs;}
164 
165 public slots:
167  void setFlagTelescopeReticles(bool b) {reticleFader = b;}
169  bool getFlagTelescopeReticles() const {return (bool)reticleFader;}
170 
172  void setFlagTelescopeLabels(bool b) {labelFader = b;}
174  bool getFlagTelescopeLabels() const {return labelFader==true;}
175 
177  void setFlagTelescopeCircles(bool b) {circleFader = b;}
179  bool getFlagTelescopeCircles() const {return circleFader==true;}
180 
182  void setReticleColor(const Vec3f &c) {reticleColor = c;}
184  const Vec3f& getReticleColor() const {return reticleColor;}
185 
187  const Vec3f& getLabelColor() const {return labelColor;}
189  void setLabelColor(const Vec3f &c) {labelColor = c;}
190 
192  void setCircleColor(const Vec3f &c) {circleColor = c;}
194  const Vec3f& getCircleColor() const {return circleColor;}
195 
197  void setFontSize(int fontSize);
198 
202  void slewTelescopeToSelectedObject();
203 
208  void slewTelescopeToViewDirection();
209 
211  void setFlagUseTelescopeServerLogs (bool b) {useTelescopeServerLogs = b;}
212 
213 signals:
214  void clientConnected(int slot, QString name);
215  void clientDisconnected(int slot);
216 
217 private slots:
218  void setStelStyle(const QString& section);
220  void translateActionDescriptions();
221 
222 private:
224  void drawPointer(const StelProjectorP& prj, const StelCore* core, StelPainter& sPainter);
225 
227  void communicate(void);
228 
229  LinearFader labelFader;
230  LinearFader reticleFader;
231  LinearFader circleFader;
233  Vec3f reticleColor;
235  Vec3f labelColor;
237  Vec3f circleColor;
239  Vec3f reticleNormalColor;
241  Vec3f reticleNightColor;
243  Vec3f labelNormalColor;
245  Vec3f labelNightColor;
247  Vec3f circleNormalColor;
249  Vec3f circleNightColor;
250 
252  QFont labelFont;
253 
254  //Toolbar button to toggle the Slew window
255  StelButton* toolbarButton;
256 
258  StelTextureSP reticleTexture;
260  StelTextureSP selectionTexture;
261 
263  QMap<int, TelescopeClientP> telescopeClients;
265  QHash<int, QProcess*> telescopeServerProcess;
266  QStringList telescopeServers;
267  QVariantMap telescopeDescriptions;
268  QHash<QString, DeviceModel> deviceModels;
269 
270  QHash<ConnectionType, QString> connectionTypeNames;
271 
272  bool useTelescopeServerLogs;
273  QHash<int, QFile*> telescopeServerLogFiles;
274  QHash<int, QTextStream*> telescopeServerLogStreams;
275 
276  bool useServerExecutables;
277  QString serverExecutablesDirectoryPath;
278 
279  //GUI
280  TelescopeDialog * telescopeDialog;
281  SlewDialog * slewDialog;
282 
284  bool isValidSlotNumber(int slot);
285  bool isValidPort(uint port);
286  bool isValidDelay(int delay);
287 
292  bool startServerAtSlot(int slot, QString serverName, int tcpPort, QString serialPort);
294  bool stopServerAtSlot(int slot);
295 
297  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());
298 
300  bool stopClientAtSlot(int slot);
301 
303  void loadTelescopeServerExecutables();
304 
306  void loadDeviceModels();
307 
310  bool restoreDeviceModelsListTo(QString deviceModelsListPath);
311 
312  void addLogAtSlot(int slot);
313  void logAtSlot(int slot);
314  void removeLogAtSlot(int slot);
315 
316  QString actionGroupId;
317  QString moveToSelectedActionId;
318  QString moveToCenterActionId;
319 };
320 
321 
322 
323 #include <QObject>
324 #include "StelPluginInterface.hpp"
325 
328 {
329  Q_OBJECT
330  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
331  Q_INTERFACES(StelPluginInterface)
332 public:
333  virtual StelModule* getStelModule() const;
334  virtual StelPluginInfo getPluginInfo() const;
335 };
336 
337 #endif /*_TELESCOPE_CONTROL_HPP_*/
const Vec3f & getLabelColor() const
Get the telescope labels color.
void setLabelColor(const Vec3f &c)
Set the telescope labels color.
void setFlagTelescopeReticles(bool b)
Set display flag for telescope reticles.
void setFlagTelescopeCircles(bool b)
Set display flag for telescope field of view circles.
bool getFlagTelescopeCircles() const
Get display flag for telescope field of view circles.
An abstract base class that should never be used directly, only inherited.
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.
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
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.
void setFlagUseTelescopeServerLogs(bool b)
Used in the GUI.
void setReticleColor(const Vec3f &c)
Set the telescope reticle color.
QSharedPointer< StelTexture > StelTextureSP
const Vec3f & getCircleColor() const
Get the field of view circles color.