1 /* 2 * Stellarium Remote Control plugin 3 * Copyright (C) 2015 Florian Schaukowitsch 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 */ 19 20 #ifndef MAINSERVICE_HPP 21 #define MAINSERVICE_HPP 22 23 #include "AbstractAPIService.hpp" 24 25 #include "StelObjectType.hpp" 26 #include "VecMath.hpp" 27 28 #include <QContiguousCache> 29 #include <QJsonObject> 30 #include <QMutex> 31 32 class StelCore; 33 class StelActionMgr; 34 class LandscapeMgr; 35 class StelLocaleMgr; 36 class StelMovementMgr; 37 class StelObjectMgr; 38 class StelPropertyMgr; 39 class StelProperty; 40 class StelScriptMgr; 41 class StelSkyCultureMgr; 42 43 //! @ingroup remoteControl 44 //! Implements the main API services, including the \c status operation which can be repeatedly polled to find the current state of the main program, 45 //! including time, view, location, StelAction and StelProperty state changes, movement, script status ... 46 //! 47 //! @see @ref rcMainService 48 class MainService : public AbstractAPIService 49 { 50 Q_OBJECT 51 52 public: 53 enum SelectionMode 54 { 55 Center, 56 Zoom, 57 Mark 58 }; 59 Q_ENUM(SelectionMode) 60 61 MainService(QObject* parent = Q_NULLPTR); 62 63 //! Used to implement move functionality 64 virtual void update(double deltaTime) Q_DECL_OVERRIDE; getPath() const65 virtual QLatin1String getPath() const Q_DECL_OVERRIDE { return QLatin1String("main"); } 66 //! @brief Implements the GET operations 67 //! @see @ref rcMainServiceGET 68 virtual void get(const QByteArray& operation,const APIParameters ¶meters, APIServiceResponse& response) Q_DECL_OVERRIDE; 69 //! @brief Implements the HTTP POST operations 70 //! @see @ref rcMainServicePOST 71 virtual void post(const QByteArray &operation, const APIParameters ¶meters, const QByteArray &data, APIServiceResponse &response) Q_DECL_OVERRIDE; 72 73 private slots: 74 StelObjectP getSelectedObject(); 75 76 //! Returns the info string of the currently selected object 77 QString getInfoString(); 78 79 //! Like StelDialog::gotoObject 80 bool focusObject(const QString& name, SelectionMode mode); 81 void focusPosition(const Vec3d& pos); 82 83 void updateMovement(double x, double y, bool xUpdated, bool yUpdated); 84 // Allow azimut/altitude changes. Values must be in Radians. 85 void updateView(double az, double alt, bool azUpdated, bool altUpdated); 86 void setFov(double fov); 87 88 void actionToggled(const QString& id, bool val); 89 void propertyChanged(StelProperty* prop, const QVariant &val); 90 91 private: 92 StelCore* core; 93 StelActionMgr* actionMgr; 94 LandscapeMgr* lsMgr; 95 StelLocaleMgr* localeMgr; 96 StelMovementMgr* mvmgr; 97 StelObjectMgr* objMgr; 98 StelPropertyMgr* propMgr; 99 #ifdef ENABLE_SCRIPTING 100 StelScriptMgr* scriptMgr; 101 #endif 102 StelSkyCultureMgr* skyCulMgr; 103 104 double moveX,moveY; 105 qint64 lastMoveUpdateTime; 106 107 struct ActionCacheEntry 108 { ActionCacheEntryMainService::ActionCacheEntry109 ActionCacheEntry(const QString& str,bool val) : action(str),val(val) {} 110 QString action; 111 bool val; 112 }; 113 114 //lists the recently toggled actions - this is a pseudo-circular buffer 115 QContiguousCache<ActionCacheEntry> actionCache; 116 QMutex actionMutex; 117 QJsonObject getActionChangesSinceID(int changeId); 118 119 struct PropertyCacheEntry 120 { PropertyCacheEntryMainService::PropertyCacheEntry121 PropertyCacheEntry(const QString& str, const QVariant& val) : id(str),val(val) {} 122 QString id; 123 QVariant val; 124 }; 125 QContiguousCache<PropertyCacheEntry> propCache; 126 QMutex propMutex; 127 QJsonObject getPropertyChangesSinceID(int changeId); 128 }; 129 130 131 132 #endif 133