Stellarium  0.16.1
StelObjectMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2007 Fabien Chereau
4  * Copyright (C) 2016 Marcos Cardinot
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19  */
20 
21 #ifndef _STELOBJECTMGR_HPP_
22 #define _STELOBJECTMGR_HPP_
23 
24 #include "VecMath.hpp"
25 #include "StelModule.hpp"
26 #include "StelObject.hpp"
27 
28 #include <QList>
29 #include <QString>
30 
31 class StelObjectModule;
32 class StelCore;
33 
37 class StelObjectMgr : public StelModule
38 {
39  Q_OBJECT
40 public:
41  StelObjectMgr();
42  virtual ~StelObjectMgr();
43 
45  // Methods defined in the StelModule class
46  virtual void init() {;}
47  virtual void draw(StelCore*) {;}
48  virtual void update(double) {;}
49 
54 
61 
69 
75 
81 
87  QStringList listMatchingObjects(const QString& objPrefix, unsigned int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=true) const;
88 
89  QStringList listAllModuleObjects(const QString& moduleId, bool inEnglish) const;
90  QMap<QString, QString> objectModulesMap() const;
91 
93  bool getWasSelected(void) const {return !lastSelectedObjects.empty();}
94 
96  void unSelect(void);
97 
103 
108  bool setSelectedObject(const QList<StelObjectP>& objs, StelModule::StelModuleSelectAction action=StelModule::ReplaceSelection);
109 
111  const QList<StelObjectP>& getSelectedObject() const {return lastSelectedObjects;}
112 
115  QList<StelObjectP> getSelectedObject(const QString& type);
116 
118  void setFlagSelectedObjectPointer(bool b) {objectPointerVisibility=b;}
120  bool getFlagSelectedObjectPointer(void) {return objectPointerVisibility;}
121 
123  StelObjectP searchByNameI18n(const QString &name) const;
124 
126  StelObjectP searchByName(const QString &name) const;
127 
135  StelObjectP searchByID(const QString& type, const QString& id) const;
136 
138  void setObjectSearchRadius(float radius) {searchRadiusPixel=radius;}
139 
142  void setDistanceWeight(float newDistanceWeight) {distanceWeight=newDistanceWeight;}
143 
147  static QVariantMap getObjectInfo(const StelObjectP obj);
148 
149 signals:
153 
154 private:
155  // The list of StelObjectModule that are referenced in Stellarium
156  QList<StelObjectModule*> objectsModule;
157  QMap<QString, StelObjectModule*> typeToModuleMap;
158  QMap<QString, QString> objModulesMap;
159 
160  // The last selected object in stellarium
161  QList<StelObjectP> lastSelectedObjects;
162  // Should selected object pointer be drawn
163  bool objectPointerVisibility;
164 
166  StelObjectP cleverFind(const StelCore* core, const Vec3d& pos) const;
167 
169  StelObjectP cleverFind(const StelCore* core, int x, int y) const;
170 
171  // Radius in pixel in which objects will be searched when clicking on a point in sky.
172  float searchRadiusPixel;
173 
174  // Weight of the distance factor when choosing the best object to select.
175  float distanceWeight;
176 };
177 
178 #endif // _SELECTIONMGR_HPP_
QStringList listMatchingObjects(const QString &objPrefix, unsigned int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=true) const
Find and return the list of at most maxNbItem objects auto-completing the passed object name...
bool getFlagSelectedObjectPointer(void)
Get whether a pointer is to be drawn over selected object.
StelObjectP searchByNameI18n(const QString &name) const
Find any kind of object by its translated name.
bool getWasSelected(void) const
Return whether an object was selected during last selection related event.
void selectedObjectChanged(StelModule::StelModuleSelectAction)
Indicate that the selected StelObjects has changed.
void setFlagSelectedObjectPointer(bool b)
Set whether a pointer is to be drawn over selected object.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
void registerStelObjectMgr(StelObjectModule *m)
Add a new StelObject manager into the list of supported modules.
void unSelect(void)
Notify that we want to unselect any object.
Specialization of StelModule which manages a collection of StelObject.
virtual void draw(StelCore *)
Execute all the drawing functions for this module.
StelObjectP searchByName(const QString &name) const
Find any kind of object by its standard program name.
bool findAndSelectI18n(const QString &nameI18n, StelModule::StelModuleSelectAction action=StelModule::ReplaceSelection)
Find and select an object from its translated name.
const QList< StelObjectP > & getSelectedObject() const
Get the list of objects which was recently selected by the user.
virtual void update(double)
Update the module with respect to the time.
void setDistanceWeight(float newDistanceWeight)
Set the weight of the distance factor when choosing the best object to select.
StelObjectP searchByID(const QString &type, const QString &id) const
Find an object of the given type and ID.
Manage the selection and queries on one or more StelObjects.
virtual void init()
Initialize itself.
bool setSelectedObject(const StelObjectP obj, StelModule::StelModuleSelectAction action=StelModule::ReplaceSelection)
Notify that we want to select the given object.
bool findAndSelect(const StelCore *core, const Vec3d &pos, StelModule::StelModuleSelectAction action=StelModule::ReplaceSelection)
Find and select an object near given equatorial J2000 position.
StelModuleSelectAction
Enum used when selecting objects to define whether to add to, replace, or remove from the existing se...
Definition: StelModule.hpp:111
Set the StelObject as the new list of selected ones.
Definition: StelModule.hpp:114
void setObjectSearchRadius(float radius)
Set the radius in pixel in which objects will be searched when clicking on a point in sky...
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
static QVariantMap getObjectInfo(const StelObjectP obj)
Return a QMap of data about the object (calls obj->getInfoMap()).