• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 17068063291

19 Aug 2025 11:22AM UTC coverage: 11.766%. Remained the same
17068063291

push

github

alex-w
Reformatting

14706 of 124990 relevant lines covered (11.77%)

18303.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/scripting/StelMainScriptAPI.cpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2009 Matthew Gates
4
 * Copyright (C) 2007 Fabien Chereau
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
#include "StelMainScriptAPI.hpp"
22
#include "StelMainScriptAPIProxy.hpp"
23
#include "StelScriptMgr.hpp"
24
#include "StelLocaleMgr.hpp"
25

26
#include "ConstellationMgr.hpp"
27
#include "AsterismMgr.hpp"
28
#include "GridLinesMgr.hpp"
29
#include "SpecialMarkersMgr.hpp"
30
#include "LandscapeMgr.hpp"
31
#include "SporadicMeteorMgr.hpp"
32
#include "NebulaMgr.hpp"
33
#include "Planet.hpp"
34
#include "SolarSystem.hpp"
35
#include "StarMgr.hpp"
36
#include "StelApp.hpp"
37
#include "StelAudioMgr.hpp"
38
#include "StelVideoMgr.hpp"
39
#include "StelCore.hpp"
40
#include "StelFileMgr.hpp"
41
#include "StelLocation.hpp"
42
#include "StelLocationMgr.hpp"
43
#include "StelMainView.hpp"
44
#include "StelModuleMgr.hpp"
45
#include "StelMovementMgr.hpp"
46
#include "StelPropertyMgr.hpp"
47
#include "StelScriptMgr.hpp"
48

49
#include "StelObject.hpp"
50
#include "StelObjectMgr.hpp"
51
#include "StelProjector.hpp"
52
#include "StelSkyCultureMgr.hpp"
53
#include "StelSkyDrawer.hpp"
54
#include "StelSkyLayerMgr.hpp"
55
#include "StelUtils.hpp"
56
#include "StelGuiBase.hpp"
57
#include "ZodiacalLight.hpp"
58
//#include "ToastMgr.hpp"
59
#include "StelToneReproducer.hpp"
60

61
#include <QDateTime>
62
#include <QDebug>
63
#include <QDir>
64
#include <QFile>
65
#include <QFileInfo>
66
#include <QRegularExpression>
67
#include <QSet>
68
#include <QStringList>
69
#include <QTemporaryFile>
70
#include <QTimer>
71
#include <QEventLoop>
72

73
#include <cmath>
74

75
StelMainScriptAPI::StelMainScriptAPI(QObject *parent) : QObject(parent)
×
76
{
77
        if(StelSkyLayerMgr* smgr = GETSTELMODULE(StelSkyLayerMgr))
×
78
        {
79
                connect(this, SIGNAL(requestLoadSkyImage(const QString&, const QString&, double, double, double, double, double, double, double, double, double, double, bool, StelCore::FrameType, bool)),
×
80
                        smgr, SLOT(         loadSkyImage(const QString&, const QString&, double, double, double, double, double, double, double, double, double, double, bool, StelCore::FrameType, bool)));
81
                connect(this, SIGNAL(requestRemoveSkyImage(const QString&)), smgr, SLOT(removeSkyLayer(const QString&)));
×
82
        }
83

84
        connect(this, SIGNAL(requestLoadSound(const QString&, const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(loadSound(const QString&, const QString&)));
×
85
        connect(this, SIGNAL(requestPlaySound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(playSound(const QString&)));
×
86
        connect(this, SIGNAL(requestPauseSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(pauseSound(const QString&)));
×
87
        connect(this, SIGNAL(requestStopSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(stopSound(const QString&)));
×
88
        connect(this, SIGNAL(requestDropSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(dropSound(const QString&)));
×
89

90
        connect(this, SIGNAL(requestLoadVideo(const QString&, const QString&, float, float, bool, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(loadVideo(const QString&, const QString&, float, float, bool, float)));
×
91
        connect(this, SIGNAL(requestPlayVideo(const QString&, const bool)), StelApp::getInstance().getStelVideoMgr(), SLOT(playVideo(const QString&, const bool)));
×
92
        connect(this, SIGNAL(requestPlayVideoPopout(QString,float,float,float,float,float,float,float,bool)), StelApp::getInstance().getStelVideoMgr(), SLOT(playVideoPopout(QString,float,float,float,float,float,float,float,bool)));
×
93
        connect(this, SIGNAL(requestPauseVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(pauseVideo(const QString&)));
×
94
        connect(this, SIGNAL(requestStopVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(stopVideo(const QString&)));
×
95
        connect(this, SIGNAL(requestDropVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(dropVideo(const QString&)));
×
96
        connect(this, SIGNAL(requestSeekVideo(const QString&, qint64, bool)), StelApp::getInstance().getStelVideoMgr(), SLOT(seekVideo(const QString&, qint64, bool)));
×
97
        connect(this, SIGNAL(requestSetVideoXY(const QString&, float, float, bool)), StelApp::getInstance().getStelVideoMgr(), SLOT(setVideoXY(const QString&, float, float, bool)));
×
98
        connect(this, SIGNAL(requestSetVideoAlpha(const QString&, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(setVideoAlpha(const QString&, float)));
×
99
        connect(this, SIGNAL(requestResizeVideo(const QString&, float, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(resizeVideo(const QString&, float, float)));
×
100
        connect(this, SIGNAL(requestShowVideo(const QString&, bool)), StelApp::getInstance().getStelVideoMgr(), SLOT(showVideo(const QString&, bool)));
×
101

102
        connect(this, SIGNAL(requestExit()), this->parent(), SLOT(stopScript()));
×
103
        connect(this, SIGNAL(requestSetProjectionMode(QString)), StelApp::getInstance().getCore(), SLOT(setCurrentProjectionTypeKey(QString)));
×
104
        connect(this, SIGNAL(requestSetSkyCulture(QString)), &StelApp::getInstance().getSkyCultureMgr(), SLOT(setCurrentSkyCultureID(QString)));
×
105
        connect(this, SIGNAL(requestSetDiskViewport(bool)), StelApp::getInstance().getMainScriptAPIProxy(), SLOT(setDiskViewport(bool)));        
×
106
        connect(this, SIGNAL(requestSetHomePosition()), StelApp::getInstance().getCore(), SLOT(returnToHome()));
×
107

108
        //QMetaType::registerConverter<V3d,QString>(&V3d::toString);
109
        //QMetaType::registerConverter<V3f,QString>(&V3f::toString);
110
        //QMetaType::registerConverter<Color,QString>(&Color::toString);
111
}
×
112

113
StelMainScriptAPI::~StelMainScriptAPI()
×
114
{
115
}
×
116

117
Vec3d StelMainScriptAPI::vec3d(const double x, const double y, const double z)
×
118
{
119
        return Vec3d(x, y, z);
×
120
}
121

122
Vec3f StelMainScriptAPI::vec3f(const float x, const float y, const float z)
×
123
{
124
        return Vec3f(x, y, z);
×
125
}
126

127
//Col StelMainScriptAPI::vec3f(const QString &cstr){return color(cstr);}
128
#ifdef ENABLE_SCRIPT_QML
129
Color StelMainScriptAPI::color(const QString &cstr)
×
130
{
131
        Color res(0,0,0);
×
132

133
        QColor qcol = QColor(cstr);
×
134
        if(qcol.isValid())
×
135
                res.set( static_cast<float>(qcol.redF()), static_cast<float>(qcol.greenF()), static_cast<float>(qcol.blueF()) );
×
136
        else
137
                qWarning() << "Color: invalid color name: " << cstr;
×
138
        return res;
×
139
}
×
140
#endif
141
//V3d StelMainScriptAPI::toV3d(const Vec3d &vec)
142
//{
143
//        return V3d(vec);
144
//}
145

146
bool StelMainScriptAPI::useQtScript()
×
147
{
148
#ifdef ENABLE_SCRIPT_QML
149
        return false;
×
150
#else
151
        return true;
152
#endif
153
}
154

155
//! Set the current date in Julian Day
156
//! @param JD the Julian Date (UT)
157
void StelMainScriptAPI::setJDay(double JD)
×
158
{
159
        StelApp::getInstance().getCore()->setJD(JD);
×
160
}
×
161

162
//! Get the current date in Julian Day
163
//! @return the Julian Date (UT)
164
double StelMainScriptAPI::getJDay()
×
165
{
166
        return StelApp::getInstance().getCore()->getJD();
×
167
}
168

169
//! Set the current date in Modified Julian Day
170
//! @param MJD the Modified Julian Date
171
void StelMainScriptAPI::setMJDay(double MJD)
×
172
{
173
        StelApp::getInstance().getCore()->setMJDay(MJD);
×
174
}
×
175

176
//! Get the current date in Modified Julian Day
177
//! @return the Modified Julian Date
178
double StelMainScriptAPI::getMJDay()
×
179
{
180
        return StelApp::getInstance().getCore()->getMJDay();
×
181
}
182

183
void StelMainScriptAPI::setDate(const QString& dateStr, const QString& spec, const bool &dateIsDT)
×
184
{
185
        StelCore* core = StelApp::getInstance().getCore();
×
186
        double JD = jdFromDateString(dateStr, spec);
×
187
        if (dateIsDT)
×
188
                core->setJDE(JD);
×
189
        else
190
                core->setJD(JD);
×
191
}
×
192

193
QString StelMainScriptAPI::getDate(const QString& spec)
×
194
{
195
        if (spec=="utc")
×
196
                return StelUtils::julianDayToISO8601String(getJDay());
×
197
        else
198
                return StelUtils::julianDayToISO8601String(getJDay()+static_cast<double>(StelApp::getInstance().getCore()->getUTCOffset(getJDay()))/24);
×
199
}
200

201
QString StelMainScriptAPI::getDeltaT()
×
202
{
203
        return StelUtils::hoursToHmsStr(StelApp::getInstance().getCore()->getDeltaT()/3600.);
×
204
}
205

206
double StelMainScriptAPI::getDeltaTsec()
×
207
{
208
        return StelApp::getInstance().getCore()->getDeltaT();
×
209
}
210

211
QString StelMainScriptAPI::getDeltaTAlgorithm()
×
212
{
213
        return StelApp::getInstance().getCore()->getCurrentDeltaTAlgorithmKey();
×
214
}
215

216
void StelMainScriptAPI::setDeltaTAlgorithm(QString algorithmName)
×
217
{
218
        StelApp::getInstance().getCore()->setCurrentDeltaTAlgorithmKey(algorithmName);
×
219
}
×
220

221
//! Set time speed in JDay/sec
222
//! @param ts time speed in JDay/sec
223
void StelMainScriptAPI::setTimeRate(double ts)
×
224
{
225
        // 1 second = .00001157407407407407 JDay
226
        StelApp::getInstance().getCore()->setTimeRate(ts * 0.00001157407407407407 * StelApp::getInstance().getScriptMgr().getScriptRate());
×
227
}
×
228

229
//! Get time speed in JDay/sec
230
//! @return time speed in JDay/sec
231
double StelMainScriptAPI::getTimeRate()
×
232
{
233
        return StelApp::getInstance().getCore()->getTimeRate() / (0.00001157407407407407 * StelApp::getInstance().getScriptMgr().getScriptRate());
×
234
}
235

236
bool StelMainScriptAPI::isRealTime()
×
237
{
238
        return StelApp::getInstance().getCore()->getIsTimeNow();
×
239
}
240

241
void StelMainScriptAPI::setRealTime()
×
242
{
243
        setTimeRate(1.0);
×
244
        StelApp::getInstance().getCore()->setTimeNow();
×
245
}
×
246

247
bool StelMainScriptAPI::isPlanetocentricCalculations()
×
248
{
249
        return !(StelApp::getInstance().getCore()->getUseTopocentricCoordinates());
×
250
}
251

252
void StelMainScriptAPI::setPlanetocentricCalculations(bool f)
×
253
{
254
        StelApp::getInstance().getCore()->setUseTopocentricCoordinates(!f);
×
255
}
×
256

257
void StelMainScriptAPI::setObserverLocation(double longitude, double latitude, double altitude, double duration, const QString& name, const QString& planet)
×
258
{
259
        StelCore* core = StelApp::getInstance().getCore();
×
260
        StelLocation loc = core->getCurrentLocation();
×
261
        loc.setLongitude(static_cast<float>(longitude));
×
262
        loc.setLatitude(static_cast<float>(latitude));
×
263
        if (altitude > -1000)
×
264
                loc.altitude = qRound(altitude);
×
265
        if (!planet.isEmpty())
×
266
        {
267
                // backward compatible layer: probably we have Solar system body...
268
                PlanetP ssObj = GETSTELMODULE(SolarSystem)->searchByEnglishName(planet);
×
269
                if (!ssObj.isNull())
×
270
                        loc.planetName = ssObj->getEnglishName();
×
271
        }
×
272

273
        static const QRegularExpression cico( "^\\s*([^,]+),\\s*(\\S.*)$" );
×
274
        QRegularExpressionMatch match=cico.match(name);
×
275
        if( match.hasMatch() )
×
276
        {
277
                loc.name = match.captured(1);
×
278
                loc.region = match.captured(2);
×
279
        }
280
        else
281
                loc.name = name;
×
282

283
        core->moveObserverTo(loc, duration, duration);
×
284
}
×
285

286
void StelMainScriptAPI::setObserverLocation(const QString &id, double duration)
×
287
{
288
        StelCore* core = StelApp::getInstance().getCore();
×
289
        StelLocation loc = StelApp::getInstance().getLocationMgr().locationForString(id);
×
290
        if (loc.isValid())
×
291
                core->moveObserverTo(loc, duration);
×
292
        else
293
                qWarning() << "core.setObserverLocation: location" << id << "invalid, not changing location:" << loc.serializeToLine();
×
294
}
×
295

296
QString StelMainScriptAPI::getObserverLocation()
×
297
{
298
        return StelApp::getInstance().getCore()->getCurrentLocation().getID();
×
299
}
300

301
QVariantMap StelMainScriptAPI::getObserverLocationInfo()
×
302
{
303
        StelCore* core = StelApp::getInstance().getCore();
×
304
        const PlanetP& planet = core->getCurrentPlanet();
×
305
        QString planetName = core->getCurrentLocation().planetName;
×
306
        QVariantMap map;
×
307
        map.insert("longitude", core->getCurrentLocation().getLongitude());
×
308
        map.insert("latitude", core->getCurrentLocation().getLatitude());
×
309
        map.insert("planet", planetName);
×
310
        map.insert("altitude", core->getCurrentLocation().altitude);
×
311
        map.insert("location", core->getCurrentLocation().getID());
×
312
        // extra data
313
        map.insert("sidereal-year", planet->getSiderealPeriod());
×
314
        map.insert("sidereal-day", planet->getSiderealDay()*24.);
×
315
        map.insert("solar-day", planet->getMeanSolarDay()*24.);
×
316
        unsigned int h, m;
317
        double s;
318
        StelUtils::radToHms(core->getLocalSiderealTime(), h, m, s);
×
319
        map.insert("local-sidereal-time", static_cast<double>(h) + static_cast<double>(m)/60. + s/3600);
×
320
        map.insert("local-sidereal-time-hms", StelUtils::radToHmsStr(core->getLocalSiderealTime()));
×
321
        map.insert("location-timezone", core->getCurrentLocation().ianaTimeZone);
×
322
        map.insert("timezone", core->getCurrentTimeZone());
×
323

324
        return map;
×
325
}
×
326

327
void StelMainScriptAPI::setTimezone(QString tz, int markAsCustom)
×
328
{
329
        StelCore* core = StelApp::getInstance().getCore();
×
330
        core->setCurrentTimeZone(tz);
×
331
        switch (markAsCustom){
×
332
                case 0: // and
×
333
                case 1:        core->setUseCustomTimeZone(static_cast<bool>(markAsCustom));
×
334
                        break;
×
335
                default: break;
×
336
        }
337
}
×
338

339
QStringList StelMainScriptAPI::getAllTimezoneNames()
×
340
{
341
        return StelApp::getInstance().getLocationMgr().getAllTimezoneNames();
×
342
}
343

344
// Coordinate conversion: geographic (WGS84)-->UTM
345
QList<double> StelMainScriptAPI::geo2utm(const double longitude, const double latitude, const int zone)
×
346
{
347
        QPair<Vec3d, Vec2d> utm=StelLocationMgr::geo2utm(longitude, latitude, zone);
×
348
        Vec3d pos=utm.first;
×
349
        Vec2d ang=utm.second;
×
350
        return QList<double>({pos[0], pos[1], pos[2], ang[0]*M_180_PI, ang[1]});
×
351
}
352
// Coordinate conversion: UTM->geographic (WGS84)
353
QList<double> StelMainScriptAPI::utm2geo(const double easting, const double northing, const int zone, const bool north)
×
354
{
355
        QPair<Vec3d, Vec2d> geo=StelLocationMgr::utm2geo(easting, northing, zone, north);
×
356
        Vec3d pos=geo.first;
×
357
        Vec2d ang=geo.second;
×
358
        return QList<double>({pos[0], pos[1], pos[2], ang[0]*M_180_PI, ang[1]});
×
359
}
360

361
void StelMainScriptAPI::screenshot(const QString& prefix, bool invert, const QString& dir, const bool overwrite, const QString &format)
×
362
{
363
        QString realDir("");
×
364
        if ((!dir.isEmpty()) && (!StelApp::getInstance().getScriptMgr().getFlagAllowExternalScreenshotDir()))
×
365
        {
366
                qWarning() << "SCRIPT CONFIGURATION ISSUE: the script wants to store a screenshot" << prefix << "." << format << "to an external directory " << dir;
×
367
                qWarning() << "  To enable this, check the settings in the script console";
×
368
                qWarning() << "  or set entry scripts/flag_allow_screenshots_dir=true in config.ini.";
×
369
        }
370
        else
371
                realDir=dir;
×
372

373

374
        const bool oldInvertSetting = StelMainView::getInstance().getFlagInvertScreenShotColors();
×
375
        const QString oldFormat=StelMainView::getInstance().getScreenshotFormat();
×
376
        if ((!format.isEmpty()) && (format.length()<=4))
×
377
                StelMainView::getInstance().setScreenshotFormat(format);
×
378
        // Check requested against set image format.
379
        if ((!format.isEmpty()) && (StelMainView::getInstance().getScreenshotFormat() != format))
×
380
        {
381
                qWarning() << "Screenshot format" << format << "not supported. Not saving screenshot.";
×
382
                return;
×
383
        }
384

385
        StelMainView::getInstance().setFlagInvertScreenShotColors(invert);
×
386
        StelMainView::getInstance().setFlagOverwriteScreenShots(overwrite);
×
387
        StelMainView::getInstance().saveScreenShot(prefix, realDir, overwrite);
×
388
        StelMainView::getInstance().setFlagInvertScreenShotColors(oldInvertSetting);
×
389
        StelMainView::getInstance().setScreenshotFormat(oldFormat);
×
390
}
×
391

392
void StelMainScriptAPI::setGuiVisible(bool b)
×
393
{
394
        StelApp::getInstance().getGui()->setVisible(b);
×
395
}
×
396

397
void StelMainScriptAPI::setSelectedObjectMarkerVisible(bool b)
×
398
{
399
        GETSTELMODULE(StelObjectMgr)->setFlagSelectedObjectPointer(b);
×
400
}
×
401

402
void StelMainScriptAPI::setGuiStyle(const QString& cssStyle)
×
403
{
404
        emit StelApp::getInstance().colorSchemeChanged(cssStyle);
×
405
}
×
406

407
void StelMainScriptAPI::setMinFps(float m)
×
408
{
409
        StelMainView::getInstance().setMinFps(m);
×
410
}
×
411

412
float StelMainScriptAPI::getMinFps()
×
413
{
414
        return StelMainView::getInstance().getMinFps();
×
415
}
416

417
void StelMainScriptAPI::setMaxFps(float m)
×
418
{
419
        StelMainView::getInstance().setMaxFps(m);
×
420
}
×
421

422
float StelMainScriptAPI::getMaxFps()
×
423
{
424
        return StelMainView::getInstance().getMaxFps();
×
425
}
426

427
QString StelMainScriptAPI::getMountMode()
×
428
{
429
        if (GETSTELMODULE(StelMovementMgr)->getMountMode() == StelMovementMgr::MountEquinoxEquatorial)
×
430
                return "equatorial";
×
431
        else
432
                return "azimuthal";
×
433
}
434

435
void StelMainScriptAPI::setMountMode(const QString& mode)
×
436
{
437
        if (mode=="equatorial")
×
438
                GETSTELMODULE(StelMovementMgr)->setMountMode(StelMovementMgr::MountEquinoxEquatorial);
×
439
        else if (mode=="azimuthal")
×
440
                GETSTELMODULE(StelMovementMgr)->setMountMode(StelMovementMgr::MountAltAzimuthal);
×
441
}
×
442

443
bool StelMainScriptAPI::getNightMode()
×
444
{
445
        return StelApp::getInstance().getVisionModeNight();
×
446
}
447

448
void StelMainScriptAPI::setNightMode(bool b)
×
449
{
450
        StelApp::getInstance().setVisionModeNight(b);
×
451
}
×
452

453
QString StelMainScriptAPI::getProjectionMode()
×
454
{
455
        return StelApp::getInstance().getCore()->getCurrentProjectionTypeKey();
×
456
}
457

458
void StelMainScriptAPI::setProjectionMode(const QString& id)
×
459
{
460
        emit requestSetProjectionMode(id);
×
461
}
×
462

463
QStringList StelMainScriptAPI::getAllSkyCultureIDs()
×
464
{
465
        return StelApp::getInstance().getSkyCultureMgr().getSkyCultureListIDs();
×
466
}
467

468
QString StelMainScriptAPI::getSkyCulture()
×
469
{
470
        return StelApp::getInstance().getSkyCultureMgr().getCurrentSkyCultureID();
×
471
}
472

473
void StelMainScriptAPI::setSkyCulture(const QString& id)
×
474
{
475
        GETSTELMODULE(StelObjectMgr)->unSelect(); // mistake-proofing!
×
476
        if (!StelApp::getInstance().getSkyCultureMgr().getSkyCultureListIDs().contains(id))
×
477
        {
478
                qDebug().noquote() << "Could not find skyculture" << id << ". Please check your script.";
×
479
                if (id.startsWith("western", Qt::CaseInsensitive))
×
480
                        qDebug() << "Western skycultures have been renamed to modern_*. Please update your scripts.";
×
481
        }
482
        else
483
                emit requestSetSkyCulture(id);
×
484
}
×
485

486
QString StelMainScriptAPI::getSkyCultureName()
×
487
{
488
        return StelApp::getInstance().getSkyCultureMgr().getCurrentSkyCultureEnglishName();
×
489
}
490

491
QString StelMainScriptAPI::getSkyCultureNameI18n()
×
492
{
493
        return StelApp::getInstance().getSkyCultureMgr().getCurrentSkyCultureNameI18();
×
494
}
495

496
bool StelMainScriptAPI::getFlagGravityLabels()
×
497
{
498
        return StelApp::getInstance().getCore()->getProjection(StelCore::FrameJ2000)->getFlagGravityLabels();
×
499
}
500

501
void StelMainScriptAPI::setFlagGravityLabels(bool b)
×
502
{
503
        StelApp::getInstance().getCore()->setFlagGravityLabels(b);
×
504
}
×
505

506
bool StelMainScriptAPI::getFlipHorz()
×
507
{
508
        return StelApp::getInstance().getCore()->getFlipHorz();
×
509
}
510

511
void StelMainScriptAPI::setFlipHorz(bool b)
×
512
{
513
        StelApp::getInstance().getCore()->setFlipHorz(b);
×
514
}
×
515

516
bool StelMainScriptAPI::getFlipVert()
×
517
{
518
        return StelApp::getInstance().getCore()->getFlipVert();
×
519
}
520

521
void StelMainScriptAPI::setFlipVert(bool b)
×
522
{
523
        StelApp::getInstance().getCore()->setFlipVert(b);
×
524
}
×
525

526
bool StelMainScriptAPI::getDiskViewport()
×
527
{
528
        return StelApp::getInstance().getCore()->getProjection(StelCore::FrameJ2000)->getMaskType() == StelProjector::MaskDisk;
×
529
}
530

531
void StelMainScriptAPI::setSphericMirror(bool b)
×
532
{
533
        StelCore* core = StelApp::getInstance().getCore();
×
534
        if (b)
×
535
        {
536
                core->setCurrentProjectionType(StelCore::ProjectionFisheye);
×
537
                StelApp::getInstance().setViewportEffect("sphericMirrorDistorter");
×
538
        }
539
        else
540
        {
541
                core->setCurrentProjectionTypeKey(core->getDefaultProjectionTypeKey());
×
542
                StelApp::getInstance().setViewportEffect("none");
×
543
        }
544
}
×
545

546
void StelMainScriptAPI::setDiskViewport(bool b)
×
547
{
548
        emit requestSetDiskViewport(b);
×
549
}
×
550

551
void StelMainScriptAPI::setViewportStretch(const float stretch)
×
552
{
553
        StelApp::getInstance().getCore()->setViewportStretch(stretch);
×
554
}
×
555

556
void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,
×
557
                                     double lon0, double lat0,
558
                                     double lon1, double lat1,
559
                                     double lon2, double lat2,
560
                                     double lon3, double lat3,
561
                                     double minRes, double maxBright, bool visible, const QString &frame, bool withAberration)
562
{
563
        QString path = "scripts/" + filename;
×
564
        StelCore::FrameType frameType=StelCore::FrameJ2000;
×
565
        if (frame=="EqDate")
×
566
                frameType=StelCore::FrameEquinoxEqu;
×
567
        else if (frame=="EclJ2000")
×
568
                frameType=StelCore::FrameObservercentricEclipticJ2000;
×
569
        else if (frame=="EclDate")
×
570
                frameType=StelCore::FrameObservercentricEclipticOfDate;
×
571
        else if (frame.startsWith("Gal"))
×
572
                frameType=StelCore::FrameGalactic;
×
573
        else if (frame.startsWith("SuperG"))
×
574
                frameType=StelCore::FrameSupergalactic;
×
575
        else if (frame=="AzAlt")
×
576
                frameType=StelCore::FrameAltAz;
×
577
        else if (frame!="EqJ2000")
×
578
        {
579
                qDebug() << "StelMainScriptAPI::loadSkyImage(): unknown frame type " << frame << " requested -- Using Equatorial J2000";
×
580
        }
581

582
        emit requestLoadSkyImage(id, path, lon0, lat0, lon1, lat1, lon2, lat2, lon3, lat3, minRes, maxBright, visible, frameType, withAberration);
×
583
}
×
584

585
// Convenience method:
586
void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,
×
587
                                     const QString& lon0, const QString& lat0,
588
                                     const QString& lon1, const QString& lat1,
589
                                     const QString& lon2, const QString& lat2,
590
                                     const QString& lon3, const QString& lat3,
591
                                     double minRes, double maxBright, bool visible, const QString& frame, bool withAberration)
592
{
593
        loadSkyImage(id, filename,
×
594
                     StelUtils::getDecAngle(lon0) *M_180_PI, StelUtils::getDecAngle(lat0)*M_180_PI,
×
595
                     StelUtils::getDecAngle(lon1) *M_180_PI, StelUtils::getDecAngle(lat1)*M_180_PI,
×
596
                     StelUtils::getDecAngle(lon2) *M_180_PI, StelUtils::getDecAngle(lat2)*M_180_PI,
×
597
                     StelUtils::getDecAngle(lon3) *M_180_PI, StelUtils::getDecAngle(lat3)*M_180_PI,
×
598
                     minRes, maxBright, visible, frame, withAberration);
599
}
×
600

601
// Convenience method: (Fixed 2017-03: rotation increased by 90deg, makes upright images now!)
602
void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,
×
603
                                     double lon, double lat, double angSize, double rotation,
604
                                     double minRes, double maxBright, bool visible, const QString &frame, bool withAberration)
605
{
606
        Vec3f XYZ;
×
607
        static const float RADIUS_NEB = 1.f;
608
        StelUtils::spheToRect(static_cast<float>(lon*M_PI_180), static_cast<float>(lat*M_PI_180), XYZ);
×
609
        XYZ*=RADIUS_NEB;
×
610
        float texSize = RADIUS_NEB * static_cast<float>(sin(angSize/2./60.*M_PI_180));
×
611
        Mat4f matPrecomp = Mat4f::translation(XYZ) *
×
612
                           Mat4f::zrotation(static_cast<float>(lon*M_PI_180)) *
×
613
                           Mat4f::yrotation(static_cast<float>(-lat*M_PI_180)) *
×
614
                           Mat4f::xrotation(static_cast<float>((rotation+90.0)*M_PI_180));
×
615

616
        Vec3f corners[4];
×
617
        corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize);
×
618
        corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize);
×
619
        corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize);
×
620
        corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize);
×
621

622
        // convert back to ra/dec (radians)
623
        Vec3f cornersRaDec[4];
×
624
        for(int i=0; i<4; i++)
×
625
                StelUtils::rectToSphe(&cornersRaDec[i][0], &cornersRaDec[i][1], corners[i]);
×
626

627
        loadSkyImage(id, filename,
×
628
                     static_cast<double>(cornersRaDec[0][0])*(M_180_PI), static_cast<double>(cornersRaDec[0][1])*(M_180_PI),
×
629
                     static_cast<double>(cornersRaDec[1][0])*(M_180_PI), static_cast<double>(cornersRaDec[1][1])*(M_180_PI),
×
630
                     static_cast<double>(cornersRaDec[3][0])*(M_180_PI), static_cast<double>(cornersRaDec[3][1])*(M_180_PI),
×
631
                     static_cast<double>(cornersRaDec[2][0])*(M_180_PI), static_cast<double>(cornersRaDec[2][1])*(M_180_PI),
×
632
                     minRes, maxBright, visible, frame, withAberration);
633
}
×
634

635
// Convenience method:
636
void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,
×
637
                                     const QString& lon, const QString& lat,
638
                                     double angSize, double rotation,
639
                                     double minRes, double maxBright, bool visible, const QString &frame, bool withAberration)
640
{
641
        loadSkyImage(id, filename, StelUtils::getDecAngle(lon)*M_180_PI,
×
642
                     StelUtils::getDecAngle(lat)*M_180_PI, angSize,
×
643
                     rotation, minRes, maxBright, visible, frame, withAberration);
644
}
×
645

646
void StelMainScriptAPI::removeSkyImage(const QString& id)
×
647
{
648
        emit requestRemoveSkyImage(id);
×
649
}
×
650

651
void StelMainScriptAPI::loadSound(const QString& filename, const QString& id)
×
652
{
653
        QString path = StelFileMgr::findFile("scripts/" + filename);
×
654
        if (path.isEmpty())
×
655
        {
656
                qWarning() << "cannot play sound" << QDir::toNativeSeparators(filename);
×
657
                return;
×
658
        }
659

660
        emit requestLoadSound(path, id);
×
661
}
×
662

663
void StelMainScriptAPI::playSound(const QString& id)
×
664
{
665
        emit requestPlaySound(id);
×
666
}
×
667

668
void StelMainScriptAPI::pauseSound(const QString& id)
×
669
{
670
        emit requestPauseSound(id);
×
671
}
×
672

673
void StelMainScriptAPI::stopSound(const QString& id)
×
674
{
675
        emit requestStopSound(id);
×
676
}
×
677

678
void StelMainScriptAPI::dropSound(const QString& id)
×
679
{
680
        emit requestDropSound(id);
×
681
}
×
682

683
qint64 StelMainScriptAPI::getSoundPosition(const QString& id)
×
684
{
685
        return StelApp::getInstance().getStelAudioMgr()->position(id);
×
686
}
687

688
qint64 StelMainScriptAPI::getSoundDuration(const QString& id)
×
689
{
690
        return StelApp::getInstance().getStelAudioMgr()->duration(id);
×
691
}
692

693
void StelMainScriptAPI::loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha)
×
694
{
695
        QString path = StelFileMgr::findFile("scripts/" + filename);
×
696
        if (path.isEmpty())
×
697
        {
698
                qWarning() << "cannot play video" << QDir::toNativeSeparators(filename);
×
699
                return;
×
700
        }
701

702
        emit requestLoadVideo(path, id, x, y, show, alpha);
×
703
}
×
704

705
void StelMainScriptAPI::playVideo(const QString& id, bool keepVisibleAtEnd)
×
706
{
707
        emit requestPlayVideo(id, keepVisibleAtEnd);
×
708
}
×
709

710
void StelMainScriptAPI::playVideoPopout(const QString& id, float fromX, float fromY, float atCenterX, float atCenterY, float finalSizeX, float finalSizeY, float popupDuration, bool frozenInTransition)
×
711
{
712
        emit requestPlayVideoPopout(id, fromX, fromY, atCenterX, atCenterY, finalSizeX, finalSizeY, popupDuration, frozenInTransition);
×
713
}
×
714

715
void StelMainScriptAPI::pauseVideo(const QString& id)
×
716
{
717
        emit requestPauseVideo(id);
×
718
}
×
719

720
void StelMainScriptAPI::stopVideo(const QString& id)
×
721
{
722
        emit requestStopVideo(id);
×
723
}
×
724

725
void StelMainScriptAPI::dropVideo(const QString& id)
×
726
{
727
        emit requestDropVideo(id);
×
728
}
×
729

730
void StelMainScriptAPI::seekVideo(const QString& id, qint64 ms, bool pause)
×
731
{
732
        emit requestSeekVideo(id, ms, pause);
×
733
}
×
734

735
void StelMainScriptAPI::setVideoXY(const QString& id, float x, float y, bool relative)
×
736
{
737
        emit requestSetVideoXY(id, x, y, relative);
×
738
}
×
739

740
void StelMainScriptAPI::setVideoAlpha(const QString& id, float alpha)
×
741
{
742
        emit requestSetVideoAlpha(id, alpha);
×
743
}
×
744

745
void StelMainScriptAPI::resizeVideo(const QString& id, float w, float h)
×
746
{
747
        emit requestResizeVideo(id, w, h);
×
748
}
×
749

750
void StelMainScriptAPI::showVideo(const QString& id, bool show)
×
751
{
752
        emit requestShowVideo(id, show);
×
753
}
×
754

755
qint64 StelMainScriptAPI::getVideoDuration(const QString& id)
×
756
{
757
        return StelApp::getInstance().getStelVideoMgr()->getVideoDuration(id);
×
758
}
759

760
qint64 StelMainScriptAPI::getVideoPosition(const QString& id)
×
761
{
762
        return StelApp::getInstance().getStelVideoMgr()->getVideoPosition(id);
×
763
}
764

765
int StelMainScriptAPI::getScreenWidth()
×
766
{
767
        return StelMainView::getInstance().size().width();
×
768
}
769

770
int StelMainScriptAPI::getScreenHeight()
×
771
{
772
        return StelMainView::getInstance().size().height();
×
773
}
774

775
double StelMainScriptAPI::getScriptRate()
×
776
{
777
        return StelApp::getInstance().getScriptMgr().getScriptRate();
×
778
}
779

780
void StelMainScriptAPI::setScriptRate(double r)
×
781
{
782
        return StelApp::getInstance().getScriptMgr().setScriptRate(r);
×
783
}
784

785
void StelMainScriptAPI::pauseScript()
×
786
{
787
#ifdef ENABLE_SCRIPT_QML
788
        qDebug() << "NOTE: pauseScript() is no longer supported. Ignoring.";
×
789
#else
790
        return StelApp::getInstance().getScriptMgr().pauseScript();
791
#endif
792
}
×
793

794
void StelMainScriptAPI::setSelectedObjectInfo(const QString& level)
×
795
{
796
        if (level == "AllInfo")
×
797
                StelApp::getInstance().getGui()->setInfoTextFilters(StelObject::InfoStringGroup(StelObject::AllInfo));
×
798
        else if (level == "DefaultInfo")
×
799
                StelApp::getInstance().getGui()->setInfoTextFilters(StelObject::InfoStringGroup(StelObject::DefaultInfo));
×
800
        else if (level == "ShortInfo")
×
801
                StelApp::getInstance().getGui()->setInfoTextFilters(StelObject::InfoStringGroup(StelObject::ShortInfo));
×
802
        else if (level == "None")
×
803
                StelApp::getInstance().getGui()->setInfoTextFilters(StelObject::InfoStringGroup(StelObject::None));
×
804
        else if (level == "Custom")
×
805
                StelApp::getInstance().getGui()->setInfoTextFilters(GETSTELMODULE(StelObjectMgr)->getCustomInfoStrings());
×
806
        else
807
                qWarning() << "setSelectedObjectInfo unknown level string \"" << level << "\"";
×
808
}
×
809

810
void StelMainScriptAPI::exit()
×
811
{
812
        emit requestExit();
×
813
}
×
814

815
void StelMainScriptAPI::quitStellarium()
×
816
{
817
        StelApp::getInstance().quit(); // quit from planetarium
×
818
}
×
819

820
QStringList StelMainScriptAPI::getPropertyList()
×
821
{
822
        return StelApp::getInstance().getStelPropertyManager()->getPropertyList();
×
823
}
824

825
void StelMainScriptAPI::debug(const QString& s)
×
826
{
827
        qDebug() << "script: " << s;
×
828
        StelApp::getInstance().getScriptMgr().debug(s);
×
829
}
×
830

831
void StelMainScriptAPI::output(const QString &s)
×
832
{
833
        StelApp::getInstance().getScriptMgr().output(s);
×
834
}
×
835

836
//! print contents of a QVariantMap
837
//! @param map QVariantMap e.g. from getObjectInfo() or getLocationInfo()
838
QString StelMainScriptAPI::mapToString(const QVariantMap& map)
×
839
{
840
        QString res = QString("[\n");
×
841
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
842
        QList<QMetaType::Type> simpleTypeList;
×
843
        simpleTypeList.push_back(QMetaType::Bool);
×
844
        simpleTypeList.push_back(QMetaType::Int);
×
845
        simpleTypeList.push_back(QMetaType::UInt);
×
846
        simpleTypeList.push_back(QMetaType::Double);
×
847

848
        for (auto i = map.constBegin(); i != map.constEnd(); ++i)
×
849
        {
850
                if (i.value().typeId()==QMetaType::QString)
×
851
                {
852
                        res.append(QString("[ \"%1\" = \"%2\" ]\n").arg(i.key(), i.value().toString()));
×
853
                }
854
                else if (simpleTypeList.contains(i.value().typeId()))
×
855
                {
856
                        res.append(QString("[ \"%1\" = %2 ]\n").arg(i.key(), i.value().toString()));
×
857
                }
858
                else
859
                {
860
                        res.append(QString("[ \"%1\" = \"<%2>:%3\" ]\n").arg(i.key(), i.value().typeName(), i.value().toString()));
×
861
                }
862
        }
863
#else
864
        QList<QVariant::Type> simpleTypeList;
865
        simpleTypeList.push_back(QVariant::Bool);
866
        simpleTypeList.push_back(QVariant::Int);
867
        simpleTypeList.push_back(QVariant::UInt);
868
        simpleTypeList.push_back(QVariant::Double);
869

870
        for (auto i = map.constBegin(); i != map.constEnd(); ++i)
871
        {
872
                if (i.value().type()==QVariant::String)
873
                {
874
                        res.append(QString("[ \"%1\" = \"%2\" ]\n").arg(i.key(), i.value().toString()));
875
                }
876
                else if (simpleTypeList.contains(i.value().type()))
877
                {
878
                        res.append(QString("[ \"%1\" = %2 ]\n").arg(i.key(), i.value().toString()));
879
                }
880
                else
881
                {
882
                        res.append(QString("[ \"%1\" = \"<%2>:%3\" ]\n").arg(i.key(), i.value().typeName(), i.value().toString()));
883
                }
884
        }
885
#endif
886
        res.append( QString("]\n"));
×
887
        return res;
×
888
}
×
889

890
void StelMainScriptAPI::resetOutput(void)
×
891
{
892
        StelApp::getInstance().getScriptMgr().resetOutput();
×
893
}
×
894

895
void StelMainScriptAPI::saveOutputAs(const QString &filename)
×
896
{
897
        StelApp::getInstance().getScriptMgr().saveOutputAs(filename);
×
898
}
×
899

900
double StelMainScriptAPI::jdFromDateString(const QString& dt, const QString& spec)
×
901
{
902
        QString tdt = dt.trimmed();
×
903
        StelCore *core = StelApp::getInstance().getCore();
×
904
        if (tdt == "now")
×
905
                return StelUtils::getJDFromSystem();
×
906
        
907
        bool ok;
908
        double jd;
909
        if (spec=="local")
×
910
                jd = StelApp::getInstance().getLocaleMgr().getJdFromISO8601TimeLocal(tdt, &ok);
×
911
        else
912
                jd = StelUtils::getJulianDayFromISO8601String(tdt, &ok);
×
913

914
        if (ok)
×
915
                return jd;
×
916

917
        static const QRegularExpression nowRe("(now)?"
918
                      "\\s*([-+])"
919
                      "\\s*(\\d+(?:\\.\\d+)?(?:[eE][-+]?\\d+)?)"
920
                      "\\s*(second|minute|hour|day|sol|week|month|year)s?"
921
                      "(?:\\s+(sidereal))?");
×
922
        QRegularExpressionMatch nowMatch=nowRe.match(tdt);
×
923
        if (nowMatch.hasMatch())
×
924
        {
925
                double delta;
926
                double unit;
927
                double dayLength = 1.0;
×
928
                double yearLength = 365.242190419; // duration of Earth's mean tropical year
×
929
                double monthLength = 27.321582241; // duration of Earth's mean tropical month
×
930

931
                if (nowMatch.captured(1)=="now")
×
932
                        jd = StelUtils::getJDFromSystem();
×
933
                else
934
                        jd = core->getJD();
×
935

936
                if (nowMatch.captured(5) == "sidereal")
×
937
                {
938
                        dayLength = core->getLocalSiderealDayLength();
×
939
                        yearLength = core->getLocalSiderealYearLength();
×
940
                        monthLength = 27.321661; // duration of Earth's sidereal month
×
941
                }
942

943
                QString unitString = nowMatch.captured(4);
×
944
                if ( unitString == "second")
×
945
                        unit = dayLength / (24*3600.);
×
946
                else if (unitString == "minute")
×
947
                        unit = dayLength / (24*60.);
×
948
                else if (unitString == "hour")
×
949
                        unit = dayLength / (24.);
×
950
                else if (unitString == "day")
×
951
                        unit = dayLength;
×
952
                else if (unitString == "sol")
×
953
                        unit = core->getCurrentPlanet()->getMeanSolarDay();
×
954
                else if (unitString == "week")
×
955
                        unit = dayLength * 7.;
×
956
                else if (unitString == "month")
×
957
                        unit = monthLength;
×
958
                else if (unitString == "year")
×
959
                        unit = yearLength;
×
960
                else
961
                {
962
                        qWarning() << "StelMainScriptAPI::setDate - unknown time unit:" << unitString;
×
963
                        unit = 0;
×
964
                }
965

966
                delta = nowMatch.captured(3).toDouble();
×
967

968
                if (nowMatch.captured(2) == "+")
×
969
                        jd += (unit * delta);
×
970
                else if (nowMatch.captured(2) == "-")
×
971
                        jd -= (unit * delta);
×
972
                return jd;
×
973
        }
×
974
        
975
        qWarning() << "StelMainScriptAPI::jdFromDateString error: date string" << dt << "not recognised, returning \"now\"";
×
976
        return StelUtils::getJDFromSystem();
×
977
}
×
978

979
void StelMainScriptAPI::wait(double t)
×
980
{
981
        StelScriptMgr* scriptMgr = &StelApp::getInstance().getScriptMgr();
×
982
        QCoreApplication::processEvents();
×
983
        QEventLoop* loop = scriptMgr->getWaitEventLoop();
×
984
        QTimer::singleShot(qRound(1000*t), loop, SLOT(quit()));
×
985
        if( loop->exec() != 0 )
×
986
        {
987
                emit requestExit(); // causes a call of stopScript
×
988
        }
989
}
×
990

991
void StelMainScriptAPI::waitFor(const QString& dt, const QString& spec)
×
992
{
993
        double deltaJD = jdFromDateString(dt, spec) - getJDay();
×
994
        double timeRate = getTimeRate();
×
995
        if (timeRate == 0.)
×
996
        {
997
                qDebug() << "waitFor() called with no time passing - would be infinite. Not waiting!";
×
998
                return;
×
999
        }
1000
        int interval=qRound(1000*deltaJD*86400/timeRate);
×
1001
        if (interval<=0)
×
1002
        {
1003
                qDebug() << "waitFor() called, but negative interval (time exceeded before starting timer). Not waiting!";
×
1004
                return;
×
1005
        }
1006
        StelScriptMgr* scriptMgr = &StelApp::getInstance().getScriptMgr();
×
1007
        QEventLoop* loop = scriptMgr->getWaitEventLoop();
×
1008
        QTimer::singleShot(interval, loop, SLOT(quit()));
×
1009
        if( loop->exec() != 0 )
×
1010
        {
1011
                emit requestExit(); // causes a call of stopScript
×
1012
        }
1013
}
1014

1015

1016
void StelMainScriptAPI::selectObjectByName(const QString& name, bool pointer)
×
1017
{
1018
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
×
1019
        omgr->setFlagSelectedObjectPointer(pointer);
×
1020
        bool state = omgr->findAndSelect(name);
×
1021
        // backward compatible layer: probably we have Solar system body...
1022
        if (!state)
×
1023
        {
1024
                StelObjectP obj = qSharedPointerCast<StelObject>(GETSTELMODULE(SolarSystem)->searchByEnglishName(name));
×
1025
                if (!obj.isNull())
×
1026
                        state = omgr->setSelectedObject(obj, StelModule::ReplaceSelection);
×
1027
                else
1028
                        state = false;
×
1029
        }
×
1030

1031
        if (name.isEmpty() || !state)
×
1032
                omgr->unSelect();
×
1033
}
×
1034

1035
void StelMainScriptAPI::selectConstellationByName(const QString& name)
×
1036
{
1037
        StelObjectP constellation = Q_NULLPTR;
×
1038
        if (!name.isEmpty())
×
1039
                constellation = GETSTELMODULE(ConstellationMgr)->searchByName(name);
×
1040

1041
        if (!constellation.isNull())
×
1042
                GETSTELMODULE(StelObjectMgr)->setSelectedObject(constellation);
×
1043
}
×
1044

1045
QVariantMap StelMainScriptAPI::getObjectInfo(const QString& name)
×
1046
{
1047
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
×
1048
        StelObjectP obj = omgr->searchByName(name);
×
1049
        // backward compatible layer: probably we have Solar system body...
1050
        if (obj.isNull())
×
1051
                obj = qSharedPointerCast<StelObject>(GETSTELMODULE(SolarSystem)->searchByEnglishName(name));
×
1052

1053
        return StelObjectMgr::getObjectInfo(obj);
×
1054
}
×
1055

1056
QVariantMap StelMainScriptAPI::getSelectedObjectInfo()
×
1057
{
1058
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
×
1059
        QVariantMap map;
×
1060
        if (omgr->getSelectedObject().isEmpty())
×
1061
        {
1062
                debug("getObjectData WARNING - object not selected");
×
1063
                map.insert("found", false);
×
1064
                return map;
×
1065
        }
1066

1067
        StelObjectP obj = omgr->getSelectedObject()[0];
×
1068

1069
        return StelObjectMgr::getObjectInfo(obj);
×
1070
}
×
1071

1072
void StelMainScriptAPI::addToSelectedObjectInfoString(const QString &str, bool replace)
×
1073
{
1074
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
×
1075
        if (omgr->getSelectedObject().isEmpty())
×
1076
        {
1077
                debug("addToSelectedObjectInfoString WARNING - no object selected");
×
1078
                return;
×
1079
        }
1080

1081
        StelObjectP obj = omgr->getSelectedObject()[0];
×
1082
        if (obj)
×
1083
        {
1084
                if (replace)
×
1085
                        obj->setExtraInfoString(StelObject::Script, str);
×
1086
                else
1087
                        obj->addToExtraInfoString(StelObject::Script, str);
×
1088
        }
1089
}
×
1090

1091
QVariantMap StelMainScriptAPI::getRTS(const QString &objectName, const double altitude)
×
1092
{
1093
        static const QMap<double, QString> statusCodeMap={
1094
                {0, "OK"},
×
1095
                {100., "circumpolar"},
×
1096
                {-100., "never rises"},
×
1097
                {20., "no transit this day"},
×
1098
                {30., "no rise this day"},
×
1099
                {40., "no set this day"},
×
1100
                {-1000., "invalid result"}
×
1101
        };
×
1102
        StelCore* core = StelApp::getInstance().getCore();
×
1103

1104
        QVariantMap map = {{"name"       ,  objectName},
1105
                           {"status-code",  -1001.},
×
1106
                           {"status"     ,  "no object"}};
×
1107

1108
        StelObjectP obj = GETSTELMODULE(StelObjectMgr)->searchByName(objectName);
×
1109
        // backward compatible layer: probably we have Solar system body...
1110
        if (obj.isNull())
×
1111
                obj = qSharedPointerCast<StelObject>(GETSTELMODULE(SolarSystem)->searchByEnglishName(objectName));
×
1112

1113
        if (obj.isNull())
×
1114
                return map;
×
1115

1116
        const Vec4d rts=obj->getRTSTime(core, altitude);
×
1117
        map.insert("status-code", rts[3]);
×
1118
        map.insert("status", statusCodeMap.value(rts[3], "unknown status"));
×
1119

1120
        // following StelObject::getInfoMap(const StelCore *core) const
1121
        if (rts[3]>-1000.)
×
1122
        {
1123
                const double utcShift = core->getUTCOffset(core->getJD()) / 24.; // Fix DST shift...
×
1124
                int hr, min, sec;
1125
                StelUtils::getTimeFromJulianDay(rts[1]+utcShift, &hr, &min, &sec);
×
1126
                double hours=hr+static_cast<double>(min)/60. + static_cast<double>(sec)/3600.;
×
1127

1128
                int year, month, day, currentDay;
1129
                StelUtils::getDateFromJulianDay(core->getJD()+utcShift, &year, &month, &currentDay);
×
1130
                StelUtils::getDateFromJulianDay(rts[1]+utcShift, &year, &month, &day);
×
1131
                if (rts[3]==20 || day != currentDay) // no transit
×
1132
                {
1133
                        map.insert("transit", "---");
×
1134
                }
1135
                else {
1136
                        map.insert("transit", StelUtils::hoursToHmsStr(hours, true));
×
1137
                        map.insert("transit-dhr", hours);
×
1138
                }
1139

1140
                StelUtils::getDateFromJulianDay(rts[0]+utcShift, &year, &month, &day);
×
1141
                if (rts[3]==30 || rts[3]<0 || rts[3]>50 || day != currentDay) // no rise
×
1142
                {
1143
                        map.insert("rise", "---");
×
1144
                }
1145
                else {
1146
                        StelUtils::getTimeFromJulianDay(rts[0]+utcShift, &hr, &min, &sec);
×
1147
                        hours=hr+static_cast<double>(min)/60. + static_cast<double>(sec)/3600.;
×
1148
                        map.insert("rise", StelUtils::hoursToHmsStr(hours, true));
×
1149
                        map.insert("rise-dhr", hours);
×
1150
                }
1151

1152
                StelUtils::getDateFromJulianDay(rts[2]+utcShift, &year, &month, &day);
×
1153
                if (rts[3]==40 || rts[3]<0 || rts[3]>50 || day != currentDay) // no set
×
1154
                {
1155
                        map.insert("set", "---");
×
1156
                }
1157
                else {
1158
                        StelUtils::getTimeFromJulianDay(rts[2]+utcShift, &hr, &min, &sec);
×
1159
                        hours=hr+static_cast<double>(min)/60. + static_cast<double>(sec)/3600.;
×
1160
                        map.insert("set", StelUtils::hoursToHmsStr(hours, true));
×
1161
                        map.insert("set-dhr", hours);
×
1162
                }
1163
        }
1164
        return map;
×
1165
}
×
1166

1167
void StelMainScriptAPI::setStelProperty(const QString& propertyName, QVariant propertyValue)
×
1168
{
1169
        StelApp::getInstance().getStelPropertyManager()->setStelPropertyValue(propertyName, propertyValue);
×
1170
}
×
1171

1172
QVariant StelMainScriptAPI::getStelProperty(const QString& propertyName)
×
1173
{
1174
        return StelApp::getInstance().getStelPropertyManager()->getStelPropertyValue(propertyName, true);
×
1175
}
1176

1177

1178
void StelMainScriptAPI::clear(const QString& state)
×
1179
{
1180
        static const QMap<QString, int>stateMap={
1181
                { "natural",   1},
×
1182
                { "starchart", 2},
×
1183
                { "deepspace", 3},
×
1184
                { "galactic",  4},
×
1185
                { "supergalactic", 5 }};
×
1186
        const int stateInt = stateMap.value(state.toLower(), 0);
×
1187
        if (stateInt == 0)
×
1188
        {
1189
                qWarning() << "State for command clear(" << state << ") not known";
×
1190
        }
1191
        else
1192
        {
1193
                LandscapeMgr* lmgr = GETSTELMODULE(LandscapeMgr);
×
1194
                SolarSystem* ssmgr = GETSTELMODULE(SolarSystem);
×
1195
                SporadicMeteorMgr* mmgr = GETSTELMODULE(SporadicMeteorMgr);
×
1196
                StelSkyDrawer* skyd = StelApp::getInstance().getCore()->getSkyDrawer();
×
1197
                ConstellationMgr* cmgr = GETSTELMODULE(ConstellationMgr);
×
1198
                AsterismMgr* amgr = GETSTELMODULE(AsterismMgr);
×
1199
                StarMgr* smgr = GETSTELMODULE(StarMgr);
×
1200
                NebulaMgr* nmgr = GETSTELMODULE(NebulaMgr);
×
1201
                GridLinesMgr* glmgr = GETSTELMODULE(GridLinesMgr);
×
1202
                SpecialMarkersMgr* spmgr = GETSTELMODULE(SpecialMarkersMgr);
×
1203
                StelMovementMgr* movmgr = GETSTELMODULE(StelMovementMgr);
×
1204
                ZodiacalLight* zl = GETSTELMODULE(ZodiacalLight);
×
1205
                StelPropertyMgr* propMgr = StelApp::getInstance().getStelPropertyManager();
×
1206

1207
                // Hide artificial satellites through StelProperties to avoid crash if plugin was not loaded
1208
                propMgr->setStelPropertyValue("Satellites.flagHintsVisible",   false, true);
×
1209
                propMgr->setStelPropertyValue("Satellites.flagLabelsVisible",  false, true);
×
1210
                propMgr->setStelPropertyValue("Satellites.flagOrbitLines", false, true);
×
1211

1212
                // identical for all states
1213
                glmgr->setFlagAllGrids(false);
×
1214
                glmgr->setFlagAllLines(false);
×
1215
                glmgr->setFlagAllPoints(false);
×
1216
                ssmgr->setFlagHints(false);
×
1217
                ssmgr->setFlagOrbits(false);
×
1218
                ssmgr->setFlagMoonScale(false);
×
1219
                ssmgr->setFlagMinorBodyScale(false);
×
1220
                ssmgr->setFlagTrails(false);
×
1221
                lmgr->setFlagCardinalPoints(false);
×
1222
                spmgr->setFlagCompassMarks(false);
×
1223
                spmgr->setFlagFOVCenterMarker(false);
×
1224
                spmgr->setFlagFOVCircularMarker(false);
×
1225
                spmgr->setFlagFOVRectangularMarker(false);
×
1226
                amgr->setFlagLines(false);
×
1227
                amgr->setFlagLabels(false);
×
1228
                amgr->setFlagRayHelpers(false);
×
1229

1230
                // applicable for most states
1231
                skyd->setFlagTwinkle(false);
×
1232
                skyd->setFlagLuminanceAdaptation(false);
×
1233
                ssmgr->setFlagPlanets(false);
×
1234
                mmgr->setZHR(0);
×
1235
                cmgr->setFlagLines(false);
×
1236
                cmgr->setFlagLabels(false);
×
1237
                cmgr->setFlagBoundaries(false);
×
1238
                cmgr->setFlagArt(false);
×
1239
                smgr->setFlagLabels(false);
×
1240
                ssmgr->setFlagLabels(false);
×
1241
                lmgr->setFlagLandscape(false);
×
1242
                lmgr->setFlagAtmosphere(false);
×
1243
                lmgr->setFlagFog(false);
×
1244
                nmgr->setFlagHints(false);
×
1245
                zl->setFlagShow(false);
×
1246

1247
                switch (stateInt)
×
1248
                {
1249
                        case 1: // natural
×
1250
                        {
1251
                                movmgr->setMountMode(StelMovementMgr::MountAltAzimuthal);
×
1252
                                skyd->setFlagTwinkle(true);
×
1253
                                skyd->setFlagLuminanceAdaptation(true);
×
1254
                                ssmgr->setFlagPlanets(true);
×
1255
                                mmgr->setZHR(10);
×
1256
                                lmgr->setFlagLandscape(true);
×
1257
                                lmgr->setFlagAtmosphere(true);
×
1258
                                lmgr->setFlagFog(true);
×
1259
                                zl->setFlagShow(true);
×
1260
                                break;
×
1261
                        }
1262
                        case 2: // starchart
×
1263
                        {
1264
                                movmgr->setMountMode(StelMovementMgr::MountEquinoxEquatorial);
×
1265
                                ssmgr->setFlagPlanets(true);
×
1266
                                cmgr->setFlagLines(true);
×
1267
                                cmgr->setFlagLabels(true);
×
1268
                                cmgr->setFlagBoundaries(true);
×
1269
                                smgr->setFlagLabels(true);
×
1270
                                ssmgr->setFlagLabels(true);
×
1271
                                nmgr->setFlagHints(true);
×
1272
                                glmgr->setFlagEquatorGrid(true);
×
1273
                                break;
×
1274
                        }
1275
                        case 3: // deepspace
×
1276
                                movmgr->setMountMode(StelMovementMgr::MountEquinoxEquatorial);
×
1277
                                break;
×
1278
                        case 4: // galactic
×
1279
                        {
1280
                                movmgr->setMountMode(StelMovementMgr::MountGalactic);
×
1281
                                glmgr->setFlagGalacticGrid(true);
×
1282
                                break;
×
1283
                        }
1284
                        case 5: // supergalactic
×
1285
                        {
1286
                                movmgr->setMountMode(StelMovementMgr::MountSupergalactic);
×
1287
                                glmgr->setFlagSupergalacticGrid(true);
×
1288
                                break;
×
1289
                        }
1290
                }
1291
        }
1292
}
×
1293

1294
double StelMainScriptAPI::getViewAltitudeAngle()
×
1295
{
1296
        const Vec3d& current = StelApp::getInstance().getCore()->j2000ToAltAz(GETSTELMODULE(StelMovementMgr)->getViewDirectionJ2000(), StelCore::RefractionOff);
×
1297
        double alt, azi;
1298
        StelUtils::rectToSphe(&azi, &alt, current);
×
1299
        return alt*180/M_PI; // convert to degrees from radians
×
1300
}
1301

1302
double StelMainScriptAPI::getViewAzimuthAngle()
×
1303
{
1304
        const Vec3d& current = StelApp::getInstance().getCore()->j2000ToAltAz(GETSTELMODULE(StelMovementMgr)->getViewDirectionJ2000(), StelCore::RefractionOff);
×
1305
        double alt, azi;
1306
        StelUtils::rectToSphe(&azi, &alt, current);
×
1307
        // The returned azimuth angle is in radians and set up such that:
1308
        // N=+/-PI; E=PI/2; S=0; W=-PI/2;
1309
        // But we want compass bearings, i.e. N=0, E=90, S=180, W=270
1310
        return std::fmod(((azi*180/M_PI)*-1)+180., 360.);
×
1311
}
1312

1313
double StelMainScriptAPI::getViewRaAngle()
×
1314
{
1315
        const Vec3d& current = StelApp::getInstance().getCore()->j2000ToEquinoxEqu(GETSTELMODULE(StelMovementMgr)->getViewDirectionJ2000(), StelCore::RefractionOff);
×
1316
        double ra, dec;
1317
        StelUtils::rectToSphe(&ra, &dec, current);
×
1318
        // returned RA angle is in range -PI .. PI, but we want 0 .. 360
1319
        return std::fmod((ra*180/M_PI)+360., 360.); // convert to degrees from radians
×
1320
}
1321

1322
double StelMainScriptAPI::getViewDecAngle()
×
1323
{
1324
        const Vec3d& current = StelApp::getInstance().getCore()->j2000ToEquinoxEqu(GETSTELMODULE(StelMovementMgr)->getViewDirectionJ2000(), StelCore::RefractionOff);
×
1325
        double ra, dec;
1326
        StelUtils::rectToSphe(&ra, &dec, current);
×
1327
        return dec*180/M_PI; // convert to degrees from radians
×
1328
}
1329

1330
double StelMainScriptAPI::getViewRaJ2000Angle()
×
1331
{
1332
        Vec3d current = GETSTELMODULE(StelMovementMgr)->getViewDirectionJ2000();
×
1333
        double ra, dec;
1334
        StelUtils::rectToSphe(&ra, &dec, current);
×
1335
        // returned RA angle is in range -PI .. PI, but we want 0 .. 360
1336
        return std::fmod((ra*180/M_PI)+360., 360.); // convert to degrees from radians
×
1337
}
1338

1339
double StelMainScriptAPI::getViewDecJ2000Angle()
×
1340
{
1341
        Vec3d current = GETSTELMODULE(StelMovementMgr)->getViewDirectionJ2000();
×
1342
        double ra, dec;
1343
        StelUtils::rectToSphe(&ra, &dec, current);
×
1344
        return dec*180/M_PI; // convert to degrees from radians
×
1345
}
1346

1347
void StelMainScriptAPI::moveToObject(const QString& name, float duration)
×
1348
{
1349
        if (name.isEmpty())
×
1350
                return;
×
1351

1352
        StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementMgr);
×
1353
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
×
1354
        StelObjectP obj = omgr->searchByName(name);
×
1355

1356
        if (!obj.isNull())
×
1357
                mvmgr->moveToObject(obj, duration);
×
1358
}
×
1359

1360
void StelMainScriptAPI::moveToSelectedObject(float duration)
×
1361
{
1362
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
×
1363
        if (omgr->getSelectedObject().isEmpty())
×
1364
                return;
×
1365

1366
        StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementMgr);
×
1367
        mvmgr->moveToObject(omgr->getSelectedObject()[0], duration); // Object may be without English name
×
1368
}
1369

1370
void StelMainScriptAPI::moveToAltAzi(const QString& alt, const QString& azi, float duration)
×
1371
{
1372
        StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementMgr);
×
1373
        Q_ASSERT(mvmgr);
×
1374
        GETSTELMODULE(StelObjectMgr)->unSelect();
×
1375

1376
        Vec3d aim;
×
1377
        double dAlt = StelUtils::getDecAngle(alt);        
×
1378
        double dAzi = M_PI - StelUtils::getDecAngle(azi);
×
1379

1380
        if (StelApp::getInstance().getFlagSouthAzimuthUsage())
×
1381
                dAzi -= M_PI;
×
1382

1383
        StelUtils::spheToRect(dAzi,dAlt,aim);
×
1384

1385
        // make up vector more stable:
1386
        StelMovementMgr::MountMode mountMode=mvmgr->getMountMode();
×
1387
        Vec3d aimUp;
×
1388
        if ( (mountMode==StelMovementMgr::MountAltAzimuthal) && (fabs(dAlt)> (0.9*M_PI/2.0)) )
×
1389
                aimUp=Vec3d(-cos(dAzi), -sin(dAzi), 0.) * (dAlt>0. ? 1. : -1.);
×
1390
        else
1391
                aimUp=Vec3d(0., 0., 1.);
×
1392

1393
        mvmgr->moveToAltAzi(aim, aimUp, duration);
×
1394
}
×
1395

1396
void StelMainScriptAPI::moveToRaDec(const QString& ra, const QString& dec, float duration)
×
1397
{
1398
        StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementMgr);
×
1399
        Q_ASSERT(mvmgr);
×
1400
        StelCore* core = StelApp::getInstance().getCore();
×
1401

1402
        GETSTELMODULE(StelObjectMgr)->unSelect();
×
1403

1404
        Vec3d aim;
×
1405
        double dRa = StelUtils::getDecAngle(ra);
×
1406
        double dDec = StelUtils::getDecAngle(dec);
×
1407

1408
        StelUtils::spheToRect(dRa,dDec,aim);
×
1409
        // make up vector more stable:
1410
        StelMovementMgr::MountMode mountMode=mvmgr->getMountMode();
×
1411
        Vec3d aimUp;
×
1412
        if ( (mountMode==StelMovementMgr::MountEquinoxEquatorial) && (fabs(dDec)> (0.9*M_PI/2.0)) )
×
1413
        {
1414
                //qDebug() << "ATTENTION: Aiming into pole!";
1415
                //qDebug() << "\tdRa=" << dRa << "dDec=" << dDec;
1416
                aimUp=//core->equinoxEquToJ2000(
×
1417
                                        Vec3d(-cos(dRa), -sin(dRa), 0.) * (dDec>0. ? 1. : -1. ); //, StelCore::RefractionOff);
×
1418
                //qDebug() << "\taimUp=" << aimUp;
1419
        }
1420
        else
1421
                aimUp=core->equinoxEquToJ2000(Vec3d(0., 0., 1.), StelCore::RefractionOff);
×
1422

1423
        mvmgr->moveToJ2000(StelApp::getInstance().getCore()->equinoxEquToJ2000(aim, StelCore::RefractionOff), aimUp, duration);
×
1424
}
×
1425

1426
void StelMainScriptAPI::moveToRaDecJ2000(const QString& ra, const QString& dec, float duration)
×
1427
{
1428
        StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementMgr);
×
1429
        Q_ASSERT(mvmgr);
×
1430
        GETSTELMODULE(StelObjectMgr)->unSelect();
×
1431

1432
        Vec3d aimJ2000;
×
1433
        double dRa = StelUtils::getDecAngle(ra);
×
1434
        double dDec = StelUtils::getDecAngle(dec);
×
1435

1436
        StelUtils::spheToRect(dRa,dDec,aimJ2000);        
×
1437
        // make up vector more stable. Not sure if we have to set the up vector in this case though.
1438
        StelMovementMgr::MountMode mountMode=mvmgr->getMountMode();
×
1439
        Vec3d aimUp;
×
1440
        if ( (mountMode==StelMovementMgr::MountEquinoxEquatorial) && (fabs(dDec)> (0.9*M_PI/2.0)) )
×
1441
                aimUp=Vec3d(-cos(dRa), -sin(dRa), 0.) * (dDec>0. ? 1. : -1. );
×
1442
        else
1443
                aimUp=Vec3d(0., 0., 1.);
×
1444

1445
        mvmgr->moveToJ2000(aimJ2000, aimUp, duration);
×
1446
}
×
1447

1448
void StelMainScriptAPI::moveToGalLongLat(const QString& lon, const QString& lat, float duration)
×
1449
{
1450
        StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementMgr);
×
1451
        Q_ASSERT(mvmgr);
×
1452
        GETSTELMODULE(StelObjectMgr)->unSelect();
×
1453

1454
        Vec3d aimJ2000;
×
1455
        double dRa = StelUtils::getDecAngle(lon);
×
1456
        double dDec = StelUtils::getDecAngle(lat);
×
1457

1458
        StelUtils::spheToRect(dRa,dDec,aimJ2000);
×
1459
        aimJ2000=StelApp::getInstance().getCore()->galacticToJ2000(aimJ2000);
×
1460
        // make up vector more stable. Not sure if we have to set the up vector in this case though.
1461
        StelMovementMgr::MountMode mountMode=mvmgr->getMountMode();
×
1462
        Vec3d aimUp;
×
1463
        if ( (mountMode==StelMovementMgr::MountEquinoxEquatorial) && (fabs(dDec)> (0.9*M_PI/2.0)) )
×
1464
                aimUp=Vec3d(-cos(dRa), -sin(dRa), 0.) * (dDec>0. ? 1. : -1. );
×
1465
        else
1466
                aimUp=Vec3d(0., 0., 1.);
×
1467

1468
        mvmgr->moveToJ2000(aimJ2000, aimUp, duration);
×
1469
}
×
1470

1471
QString StelMainScriptAPI::getAppLanguage()
×
1472
{
1473
        return StelApp::getInstance().getLocaleMgr().getAppLanguage();
×
1474
}
1475

1476
void StelMainScriptAPI::setAppLanguage(QString langCode)
×
1477
{
1478
        StelApp::getInstance().getLocaleMgr().setAppLanguage(langCode);
×
1479
}
×
1480

1481
QString StelMainScriptAPI::translate(QString englishText)
×
1482
{
1483
        return StelApp::getInstance().getLocaleMgr().getScriptsTranslator().qtranslate(englishText);
×
1484
}
1485

1486
void StelMainScriptAPI::goHome()
×
1487
{
1488
        emit requestSetHomePosition();
×
1489
}
×
1490

1491
int StelMainScriptAPI::getBortleScaleIndex()
×
1492
{
1493
        return StelApp::getInstance().getCore()->getSkyDrawer()->getBortleScaleIndex();
×
1494
}
1495

1496
void StelMainScriptAPI::setBortleScaleIndex(int index)
×
1497
{
1498
        const auto lum = StelCore::bortleScaleIndexToLuminance(index);
×
1499
        StelApp::getInstance().getCore()->getSkyDrawer()->setLightPollutionLuminance(lum);
×
1500
}
×
1501

1502
double StelMainScriptAPI::refraction(double altitude, bool apparent)
×
1503
{
1504
        Vec3d pos(1., 0., 0.);
×
1505
        // rotate to set altitude.
1506
        pos=Mat4d::yrotation(-altitude*M_PI_180)*pos;
×
1507

1508
        const Refraction refraction=StelApp::getInstance().getCore()->getSkyDrawer()->getRefraction();
×
1509
        if (apparent)
×
1510
        {
1511
                refraction.backward(pos);
×
1512
        }
1513
        else
1514
        {
1515
                refraction.forward(pos);
×
1516
        }
1517
        return asin(pos[2])*M_180_PI;
×
1518
}
×
1519

1520
QVariantMap StelMainScriptAPI::getScreenXYFromAltAzi(const QString &alt, const QString &azi)
×
1521
{
1522
        Vec3d aim, v;
×
1523
        double dAlt = StelUtils::getDecAngle(alt);
×
1524
        double dAzi = M_PI - StelUtils::getDecAngle(azi);
×
1525

1526
        if (StelApp::getInstance().getFlagSouthAzimuthUsage())
×
1527
                dAzi -= M_PI;
×
1528

1529
        StelUtils::spheToRect(dAzi,dAlt,aim);
×
1530

1531
        const StelProjectorP prj = StelApp::getInstance().getCore()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
×
1532

1533
        prj->project(aim, v);
×
1534

1535
        QVariantMap map;
×
1536
        map.insert("x", qRound(v[0]));
×
1537
        map.insert("y", prj->getViewportHeight()-qRound(v[1]));
×
1538

1539
        return map;
×
1540
}
×
1541

1542
QString StelMainScriptAPI::getEnv(const QString &var)
×
1543
{
1544
        return qEnvironmentVariable(var.toLocal8Bit().constData());
×
1545
}
1546

1547
// return whether a particular module has been loaded. Mostly useful to check whether a module available as plugin is active.
1548
bool StelMainScriptAPI::isModuleLoaded(const QString &moduleID)
×
1549
{
1550
        StelModule *module= StelApp::getInstance().getModuleMgr().getModule (moduleID, true);
×
1551
        return module != Q_NULLPTR;
×
1552
}
1553

1554
// return the name of platform where running Stellarium
1555
QString StelMainScriptAPI::getPlatformName(void)
×
1556
{
1557
        // Get info about operating system
1558
        QString os = StelUtils::getOperatingSystemInfo();
×
1559
        if (os.contains("FreeBSD", Qt::CaseInsensitive))
×
1560
                os = "FreeBSD";
×
1561
        else if (os.contains("NetBSD", Qt::CaseInsensitive))
×
1562
                os = "NetBSD";
×
1563
        else if (os.contains("OpenBSD", Qt::CaseInsensitive))
×
1564
                os = "OpenBSD";
×
1565
        else if (os.contains("Haiku", Qt::CaseInsensitive))
×
1566
                os = "Haiku";
×
1567
        else if (os.contains("SunOS", Qt::CaseInsensitive))
×
1568
                os = "Solaris";
×
1569
        else if (os.contains("linux", Qt::CaseInsensitive) || QSysInfo::kernelType().contains("linux", Qt::CaseInsensitive))
×
1570
                os = "Linux";
×
1571
        else if (os.contains("windows", Qt::CaseInsensitive) || os.contains("winrt", Qt::CaseInsensitive))
×
1572
                os = "Windows";
×
1573
        else if (os.contains("osx", Qt::CaseInsensitive) || os.contains("macos", Qt::CaseInsensitive))
×
1574
                os = "macOS";
×
1575
        else
1576
                os = "Unknown";
×
1577

1578
        return os;
×
1579
}
×
1580

1581
// Get the current status of media playback support
1582
bool StelMainScriptAPI::isMediaPlaybackSupported(void)
×
1583
{
1584
        #ifdef ENABLE_MEDIA
1585
        return true;
×
1586
        #else
1587
        return false;
1588
        #endif
1589
}
1590

1591
// Experimental. Try to play with physical display properties for tonemapping.
1592
void StelMainScriptAPI::setDisplayMaxLuminance(double cdPerSqM)
×
1593
{
1594
    StelApp::getInstance().getCore()->getToneReproducer()->setMaxDisplayLuminance(static_cast<float>(cdPerSqM));
×
1595
}
×
1596
double StelMainScriptAPI::getDisplayMaxLuminance()
×
1597
{
1598
    return static_cast<double>(StelApp::getInstance().getCore()->getToneReproducer()->getMaxDisplayLuminance());
×
1599
}
1600
void StelMainScriptAPI::setDisplayAdaptationLuminance(double cdPerSqM)
×
1601
{
1602
    StelApp::getInstance().getCore()->getToneReproducer()->setDisplayAdaptationLuminance(static_cast<float>(cdPerSqM));
×
1603
}
×
1604
double StelMainScriptAPI::getDisplayAdaptationLuminance()
×
1605
{
1606
    return static_cast<double>(StelApp::getInstance().getCore()->getToneReproducer()->getDisplayAdaptationLuminance());
×
1607
}
1608
void StelMainScriptAPI::setDisplayGamma(double gamma)
×
1609
{
1610
    StelApp::getInstance().getCore()->getToneReproducer()->setDisplayGamma(static_cast<float>(gamma));
×
1611
}
×
1612
double StelMainScriptAPI::getDisplayGamma()
×
1613
{
1614
    return static_cast<double>(StelApp::getInstance().getCore()->getToneReproducer()->getDisplayGamma());
×
1615
}
1616

1617
Vec2d StelMainScriptAPI::setWindowSize(int width, int height)
×
1618
{
1619
        StelMainView &mainView=StelMainView::getInstance();
×
1620
        QRectF rect=mainView.setWindowSize(width, height);
×
1621
        return Vec2d(rect.width(), rect.height());
×
1622
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc