Stellarium  0.16.1
StelMainScriptAPI.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2009 Matthew Gates
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 _STELMAINSCRIPTAPI_HPP_
21 #define _STELMAINSCRIPTAPI_HPP_
22 
23 #include <QObject>
24 #include <QVariant>
25 #include <QStringList>
26 #include "StelObject.hpp"
27 #include "StelCore.hpp"
28 
29 class QScriptEngine;
30 
37 class StelMainScriptAPI : public QObject
38 {
39  Q_OBJECT
40  Q_PROPERTY(double JDay READ getJDay WRITE setJDay)
41  Q_PROPERTY(double timeSpeed READ getTimeRate WRITE setTimeRate)
42 
43 public:
44  StelMainScriptAPI(QObject *parent = Q_NULLPTR);
46 
47 // These functions will be available in scripts
48 public slots:
51  void setJDay(double JD);
54  double getJDay() const;
55 
58  void setMJDay(double MJD);
61  double getMJDay() const;
62 
78  // TODO: This calls for implementing "sol" days (planets's solar days)!
89  // GZ JDfix for 0.14: I estimate 99.7% of users will want to set UT-based dates here. We could use an awkward name like dateIsUTbased=true to keep default value true.
90  //void setDate(const QString& dt, const QString& spec="utc", const bool& enableDeltaT=true);
91  void setDate(const QString& dateStr, const QString& spec="utc", const bool& dateIsDT=false);
92 
98  QString getDate(const QString& spec="utc");
99 
103  QString getDeltaT() const;
104 
107  QString getDeltaTAlgorithm() const;
108 
117  void setDeltaTAlgorithm(QString algorithmName);
118 
124  void setTimeRate(double ts);
127  double getTimeRate() const;
128 
132  bool isRealTime();
133 
135  void setRealTime();
136 
142  void selectObjectByName(const QString& name, bool pointer=false);
143 
149  QVariantMap getObjectPosition(const QString& name);
150 
196  QVariantMap getObjectInfo(const QString& name);
197 
200  QVariantMap getSelectedObjectInfo();
201 
211  void clear(const QString& state="natural");
212 
216  double getViewAltitudeAngle();
217 
221  double getViewAzimuthAngle();
222 
226  double getViewRaAngle();
227 
231  double getViewDecAngle();
232 
235  double getViewRaJ2000Angle();
236 
239  double getViewDecJ2000Angle();
240 
247  void moveToAltAzi(const QString& alt, const QString& azi, float duration=1.);
248 
255  void moveToRaDec(const QString& ra, const QString& dec, float duration=1.);
256 
262  void moveToRaDecJ2000(const QString& ra, const QString& dec, float duration=1.);
263 
281  void setObserverLocation(double longitude, double latitude, double altitude, double duration=1., const QString& name="", const QString& planet="");
282 
288  void setObserverLocation(const QString id, float duration=1.);
289 
291  QString getObserverLocation();
292 
305  QVariantMap getObserverLocationInfo();
306 
313  void screenshot(const QString& prefix, bool invert=false, const QString& dir="", const bool overwrite=false);
314 
318  void setGuiVisible(bool b);
319 
325  void setMinFps(float m);
326 
329  float getMinFps();
330 
333  void setMaxFps(float m);
334 
337  float getMaxFps();
338 
341  QString getMountMode();
342 
345  void setMountMode(const QString& mode);
346 
349  bool getNightMode();
350 
353  void setNightMode(bool b);
354 
358  QString getProjectionMode();
359 
373  void setProjectionMode(const QString& id);
374 
377  bool getDiskViewport();
378 
381  void setDiskViewport(bool b);
382 
385  void setSphericMirror(bool b);
386 
392  void setViewportOffset(const float x, const float y);
393 
398  void setViewportStretch(const float stretch);
399 
402  QStringList getAllSkyCultureIDs();
403 
407  QString getSkyCulture();
408 
411  void setSkyCulture(const QString& id);
412 
415  QString getSkyCultureName();
416 
419  QString getSkyCultureNameI18n();
420 
423  bool getFlagGravityLabels();
424 
427  void setFlagGravityLabels(bool b);
428 
453  void loadSkyImage(const QString& id, const QString& filename,
454  double lon0, double lat0,
455  double lon1, double lat1,
456  double lon2, double lat2,
457  double lon3, double lat3,
458  double minRes=2.5, double maxBright=14, bool visible=true, const QString &frame="EqJ2000");
459 
460 
463  void loadSkyImage(const QString& id, const QString& filename,
464  const QString& lon0, const QString& lat0,
465  const QString& lon1, const QString& lat1,
466  const QString& lon2, const QString& lat2,
467  const QString& lon3, const QString& lat3,
468  double minRes=2.5, double maxBright=14, bool visible=true, const QString& frame="EqJ2000");
469 
487  void loadSkyImage(const QString& id, const QString& filename,
488  double lon, double lat, double angSize, double rotation,
489  double minRes=2.5, double maxBright=14, bool visible=true, const QString& frame="EqJ2000");
490 
495  void loadSkyImage(const QString& id, const QString& filename,
496  const QString& lon, const QString& lat, double angSize, double rotation,
497  double minRes=2.5, double maxBright=14, bool visible=true, const QString& frame="EqJ2000");
498 
518  void loadSkyImageAltAz(const QString& id, const QString& filename,
519  double azi0, double alt0,
520  double azi1, double alt1,
521  double azi2, double alt2,
522  double azi3, double alt3,
523  double minRes=2.5, double maxBright=14, bool visible=true);
524 
540  void loadSkyImageAltAz(const QString& id, const QString& filename,
541  double alt, double azi, double angSize, double rotation,
542  double minRes=2.5, double maxBright=14, bool visible=true);
543 
546  void removeSkyImage(const QString& id);
547 
555  QVariantMap getScreenXYFromAltAzi(const QString& alt, const QString& azi);
556 
561  void loadSound(const QString& filename, const QString& id);
562 
565  void playSound(const QString& id);
566 
570  void pauseSound(const QString& id);
571 
576  void stopSound(const QString& id);
577 
581  void dropSound(const QString& id);
582 
586  qint64 getSoundPosition(const QString& id);
587 
591  qint64 getSoundDuration(const QString& id);
592 
593 
606  void loadVideo(const QString& filename, const QString& id, float x, float y, bool show=true, float alpha=1.0f);
607 
610  void playVideo(const QString& id, bool keepVisibleAtEnd=false);
611 
625  void playVideoPopout(const QString& id, float fromX, float fromY, float atCenterX, float atCenterY, float finalSizeX, float finalSizeY, float popupDuration, bool frozenInTransition);
626 
630  void pauseVideo(const QString& id);
631 
636  void stopVideo(const QString& id);
637 
641  void dropVideo(const QString& id);
642 
647  void seekVideo(const QString& id, qint64 ms, bool pause=false);
648 
654  void setVideoXY(const QString& id, float x, float y, bool relative=false);
655 
660  void setVideoAlpha(const QString& id, float alpha);
661 
666  void resizeVideo(const QString& id, float w, float h);
667 
672  void showVideo(const QString& id, bool show=true);
673 
676  qint64 getVideoDuration(const QString& id);
677 
680  qint64 getVideoPosition(const QString& id);
681 
684  int getScreenWidth();
687  int getScreenHeight();
688 
691  double getScriptRate();
696  void setScriptRate(double r);
697 
700  void pauseScript();
701 
704  void setSelectedObjectInfo(const QString& level);
705 
707  void exit();
708 
710  void quitStellarium();
711 
713  QStringList getPropertyList() const;
714 
717  static void debug(const QString& s);
718 
721  void output(const QString& s) const;
722 
727  QString mapToString(const QVariantMap &map) const;
728 
730  void resetOutput(void) const;
731 
734  void saveOutputAs(const QString &filename);
735 
738  QString getAppLanguage() const;
739 
742  void setAppLanguage(QString langCode);
743 
746  QString getSkyLanguage() const;
747 
750  void setSkyLanguage(QString langCode);
751 
753  void goHome();
754 
757  void setMilkyWayVisible(bool b);
758 
761  void setMilkyWayIntensity(double i);
762 
765  double getMilkyWayIntensity() const;
766 
769  void setZodiacalLightVisible(bool b);
770 
773  void setZodiacalLightIntensity(double i);
774 
777  double getZodiacalLightIntensity() const;
778 
783  int getBortleScaleIndex() const;
784 
790  void setBortleScaleIndex(int index);
791 
794  void setDSSMode(bool b);
797  bool isDSSModeEnabled() const;
798 
802  double jdFromDateString(const QString& dt, const QString& spec);
803 
804  // Methods wait() and waitFor() were added for documentation.
805  // Details: https://bugs.launchpad.net/stellarium/+bug/1402200
806  // re-implemented for 0.15.1 to avoid a busy-loop.
809  void wait(double t);
810 
819  void waitFor(const QString& dt, const QString& spec="utc");
820 
821 
822 signals:
823 
824  void requestLoadSkyImage(const QString& id, const QString& filename,
825  double c1, double c2,
826  double c3, double c4,
827  double c5, double c6,
828  double c7, double c8,
829  double minRes, double maxBright, bool visible, const StelCore::FrameType frameType);
832  void requestLoadSkyImageAltAz(const QString& id, const QString& filename,
833  double c1, double c2,
834  double c3, double c4,
835  double c5, double c6,
836  double c7, double c8,
837  double minRes, double maxBright, bool visible);
838 
839  void requestRemoveSkyImage(const QString& id);
840 
841  void requestLoadSound(const QString& filename, const QString& id);
842  void requestPlaySound(const QString& id);
843  void requestPauseSound(const QString& id);
844  void requestStopSound(const QString& id);
845  void requestDropSound(const QString& id);
846  void requestLoadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha);
847  void requestPlayVideo(const QString& id, const bool keepVisibleAtEnd);
848  void requestPlayVideoPopout(const QString& id, float fromX, float fromY, float atCenterX, float atCenterY, float finalSizeX, float finalSizeY, float popupDuration, bool frozenInTransition);
849  void requestPauseVideo(const QString& id);
850  void requestStopVideo(const QString& id);
851  void requestDropVideo(const QString& id);
852  void requestSeekVideo(const QString& id, qint64 ms, bool pause=false);
853  void requestSetVideoXY(const QString& id, float x, float y, bool relative=false);
854  void requestSetVideoAlpha(const QString& id, float alpha);
855  void requestResizeVideo(const QString& id, float w, float h);
856  void requestShowVideo(const QString& id, bool show);
857 
858  void requestSetNightMode(bool b);
859  void requestSetProjectionMode(QString id);
860  void requestSetSkyCulture(QString id);
861  void requestSetDiskViewport(bool b);
862  void requestExit();
863  void requestSetHomePosition();
864 };
865 
866 #endif // _STELMAINSCRIPTAPI_HPP_
867 
void setBortleScaleIndex(int index)
Changes the Bortle scale index, which is used to simulate light pollution.
void setMinFps(float m)
Set the minimum frames per second.
double getViewDecAngle()
Get the current viewing direction Declination angle at center of view.
void setDSSMode(bool b)
Show or hide the DSS (photorealistic sky).
double getMJDay() const
Get the current date as Modified Julian Day.
bool getNightMode()
Get the current status of Night Mode.
QVariantMap getObjectInfo(const QString &name)
Fetch a map with data about an object&#39;s position, magnitude and so on.
void selectObjectByName(const QString &name, bool pointer=false)
Select an object by name.
void clear(const QString &state="natural")
Clear the display options, setting a "standard" view.
double jdFromDateString(const QString &dt, const QString &spec)
For use in setDate and waitFor For parameter descriptions see setDate().
void saveOutputAs(const QString &filename)
Save output file to new file (in same directory as output.txt).
void pauseVideo(const QString &id)
Pause a video which is playing.
void moveToAltAzi(const QString &alt, const QString &azi, float duration=1.)
move the current viewing direction to some specified altitude and azimuth.
int getScreenHeight()
Get the screen height (actually, height of Stellarium main view) in pixels.
void setProjectionMode(const QString &id)
Set the current projection mode.
void setDiskViewport(bool b)
Set the disk viewport.
void resetOutput(void) const
Reset (clear) output file.
bool isRealTime()
Get the simulation time and rate state - is it "real time".
void playSound(const QString &id)
Play a sound which has previously been loaded with loadSound.
QString getAppLanguage() const
Get the current application language.
void moveToRaDec(const QString &ra, const QString &dec, float duration=1.)
move the current viewing direction to some specified right ascension and declination.
void playVideo(const QString &id, bool keepVisibleAtEnd=false)
Play a video which has previously been loaded with loadVideo.
void requestLoadSkyImageAltAz(const QString &id, const QString &filename, double c1, double c2, double c3, double c4, double c5, double c6, double c7, double c8, double minRes, double maxBright, bool visible)
QString getDeltaTAlgorithm() const
get the DeltaT equation name for the simulation date and time as a string
double getTimeRate() const
Get simulation time rate.
double getViewDecJ2000Angle()
Get the current viewing direction Declination angle in J2000 frame at center of view.
double getViewRaJ2000Angle()
Get the current viewing direction Right Ascension in J2000 frame at center of view.
QString getProjectionMode()
Get the current projection mode ID string.
void setRealTime()
Set the simulation time to the current system time, and the time rate to 1.
void exit()
Stop the script.
QVariantMap getObserverLocationInfo()
Get the info of the current observer location.
double getMilkyWayIntensity() const
Get Milky Way intensity.
void wait(double t)
Pauses the script for t seconds.
int getScreenWidth()
Get the screen width in pixels.
void setMilkyWayVisible(bool b)
Show or hide the Milky Way.
void resizeVideo(const QString &id, float w, float h)
Resize the video widget to the specified width, height.
void setVideoAlpha(const QString &id, float alpha)
Set the alpha value of a video when visible.
void playVideoPopout(const QString &id, float fromX, float fromY, float atCenterX, float atCenterY, float finalSizeX, float finalSizeY, float popupDuration, bool frozenInTransition)
Play a video which has previously been loaded with loadVideo with a complex effect.
QString getSkyLanguage() const
Get the current sky language.
void setNightMode(bool b)
Set the status of Night Mode.
void setViewportStretch(const float stretch)
Set a lateral width distortion.
void setSphericMirror(bool b)
Set the viewport distortion effect.
void setSelectedObjectInfo(const QString &level)
Set the amount of selected object information to display.
QString getSkyCultureName()
Find out the current sky culture and get it English name.
bool isDSSModeEnabled() const
Get the current status of DSS mode.
QString getSkyCultureNameI18n()
Find out the current sky culture and get it localized name.
void dropSound(const QString &id)
Drop a sound from memory.
void removeSkyImage(const QString &id)
Remove a SkyImage.
void setFlagGravityLabels(bool b)
Turn on/off gravity labels.
int getBortleScaleIndex() const
Returns the currently set Bortle scale index, which is used to simulate light pollution.
void setZodiacalLightVisible(bool b)
Show or hide the Zodiacal Light.
void setMountMode(const QString &mode)
Set the mount mode.
qint64 getSoundPosition(const QString &id)
Get position in a playing sound.
double getViewAltitudeAngle()
Get the current viewing direction altitude angle at center of view.
QString getDate(const QString &spec="utc")
get the simulation date and time as a string in ISO format, e.g.
Provide script API for Stellarium global functions.
QVariantMap getSelectedObjectInfo()
Fetch a map with data about the latest selected object&#39;s position, magnitude and so on...
void setJDay(double JD)
Set the current date as Julian Day number.
void loadSkyImageAltAz(const QString &id, const QString &filename, double azi0, double alt0, double azi1, double alt1, double azi2, double alt2, double azi3, double alt3, double minRes=2.5, double maxBright=14, bool visible=true)
Load an image which will have a sky location given in alt-azimuthal coordinates.
FrameType
Supported reference frame types.
Definition: StelCore.hpp:69
float getMinFps()
Get the current minimum frames per second.
QVariantMap getScreenXYFromAltAzi(const QString &alt, const QString &azi)
Get screen coordinates from some specified altitude and azimuth angles may be specified in a format r...
void setViewportOffset(const float x, const float y)
Set viewport offset This can be used e.g.
void setScriptRate(double r)
Set the script execution rate as a multiple of normal execution speed.
void moveToRaDecJ2000(const QString &ra, const QString &dec, float duration=1.)
move the current viewing direction to some specified right ascension and declination in the J2000 fra...
void setMaxFps(float m)
Set the maximum frames per second.
QString mapToString(const QVariantMap &map) const
print contents of a QVariantMap as []-delimited list of [ "key" = ] lists.
QStringList getAllSkyCultureIDs()
Get a list of Sky Culture IDs.
void setSkyLanguage(QString langCode)
Set the current sky language.
void loadVideo(const QString &filename, const QString &id, float x, float y, bool show=true, float alpha=1.0f)
Load a video from a file.
void goHome()
Go to defaults position and direction of view.
void waitFor(const QString &dt, const QString &spec="utc")
Waits until a specified simulation date/time.
void loadSound(const QString &filename, const QString &id)
Load a sound from a file.
void setDate(const QString &dateStr, const QString &spec="utc", const bool &dateIsDT=false)
set the date in ISO format, e.g.
void setAppLanguage(QString langCode)
Set the current application language.
qint64 getVideoDuration(const QString &id)
Get the duration of a loaded video, or -1.
QString getMountMode()
Get the mount mode as a string.
void output(const QString &s) const
print an output message from script
void setGuiVisible(bool b)
Show or hide the GUI (toolbars).
void pauseScript()
Pause the currently running script.
bool getDiskViewport()
Get the status of the disk viewport.
void dropVideo(const QString &id)
Drop a video from memory.
QString getDeltaT() const
get the DeltaT for the simulation date and time as a string in HMS format, e.g.
void showVideo(const QString &id, bool show=true)
Set the visibility state of a video.
double getViewAzimuthAngle()
Get the current viewing direction azimuth angle at center of view.
void seekVideo(const QString &id, qint64 ms, bool pause=false)
Seeks a video to the requested time and either start playing or freeze there.
QString getObserverLocation()
Get the ID of the current observer location.
double getZodiacalLightIntensity() const
Get Zodiacal Light intensity.
float getMaxFps()
Get the current maximum frames per second.
void screenshot(const QString &prefix, bool invert=false, const QString &dir="", const bool overwrite=false)
Save a screenshot.
void quitStellarium()
Close Stellarium.
void setDeltaTAlgorithm(QString algorithmName)
set equation of the DeltaT for the simulation date and time
double getScriptRate()
Get the script execution rate as a multiple of normal execution speed.
void setMJDay(double MJD)
Set the current date as Modified Julian Day.
qint64 getSoundDuration(const QString &id)
Get duration of a sound object (if possible).
static void debug(const QString &s)
print a debugging message to the console
void setTimeRate(double ts)
Set time speed in JDay/sec.
void pauseSound(const QString &id)
Pause a sound which is playing.
qint64 getVideoPosition(const QString &id)
Get the current position of a loaded video, or -1.
void setVideoXY(const QString &id, float x, float y, bool relative=false)
Sets the position of the video widget.
void setMilkyWayIntensity(double i)
Set Milky Way intensity.
bool getFlagGravityLabels()
Get the current status of the gravity labels option.
QStringList getPropertyList() const
Return a QStringlist of all available properties. Useful for script development...
void setSkyCulture(const QString &id)
Set the current sky culture.
QString getSkyCulture()
Find out the current sky culture.
double getViewRaAngle()
Get the current viewing direction Right Ascension at center of view.
void setZodiacalLightIntensity(double i)
Set Zodiacal Light intensity.
void stopSound(const QString &id)
Stop a sound from playing.
double getJDay() const
Get the current date as Julian Day number.
QVariantMap getObjectPosition(const QString &name)
Fetch a map with data about an object&#39;s position, magnitude and so on.
void stopVideo(const QString &id)
Stop a video from playing.
void setObserverLocation(double longitude, double latitude, double altitude, double duration=1., const QString &name="", const QString &planet="")
Set the observer location.
void loadSkyImage(const QString &id, const QString &filename, double lon0, double lat0, double lon1, double lat1, double lon2, double lat2, double lon3, double lat3, double minRes=2.5, double maxBright=14, bool visible=true, const QString &frame="EqJ2000")
Load an image into the sky background at the given sky coordinates and be warped with the sky...