~ubuntu-branches/debian/sid/stellarium/sid

« back to all changes in this revision

Viewing changes to src/scripting/StelMainScriptAPI.cpp

  • Committer: Package Import Robot
  • Author(s): Tomasz Buchert
  • Date: 2013-08-04 15:06:55 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130804150655-iji0vb5navh3lk13
Tags: 0.12.2-1
* Imported Upstream version 0.12.2
* Added dependency to phonon (to enable video/sound)
* Fixed VCS links
* Removed unused lintian tag (embedded-library glee)
* Dropped obsolete patch
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
        return StelUtils::hoursToHmsStr(StelApp::getInstance().getCore()->getDeltaT(getJDay())/3600.);
162
162
}
163
163
 
 
164
QString StelMainScriptAPI::getDeltaTAlgorithm() const
 
165
{
 
166
        return StelApp::getInstance().getCore()->getCurrentDeltaTAlgorithmKey();
 
167
}
 
168
 
 
169
void StelMainScriptAPI::setDeltaTAlgorithm(QString algorithmName)
 
170
{
 
171
        StelApp::getInstance().getCore()->setCurrentDeltaTAlgorithmKey(algorithmName);
 
172
}
 
173
 
164
174
//! Set time speed in JDay/sec
165
175
//! @param ts time speed in JDay/sec
166
176
void StelMainScriptAPI::setTimeRate(double ts)
481
491
        }
482
492
        catch(std::runtime_error& e)
483
493
        {
484
 
                qWarning() << "cannot play sound" << filename << ":" << e.what();
 
494
                qWarning() << "cannot play sound" << QDir::toNativeSeparators(filename) << ":" << e.what();
485
495
                return;
486
496
        }
487
497
 
517
527
        }
518
528
        catch(std::runtime_error& e)
519
529
        {
520
 
                qWarning() << "cannot play video" << filename << ":" << e.what();
 
530
                qWarning() << "cannot play video" << QDir::toNativeSeparators(filename) << ":" << e.what();
521
531
                return;
522
532
        }
523
533
 
624
634
 
625
635
double StelMainScriptAPI::jdFromDateString(const QString& dt, const QString& spec)
626
636
{
 
637
        StelCore *core = StelApp::getInstance().getCore();
627
638
        if (dt == "now")
628
639
                return StelUtils::getJDFromSystem();
629
640
        
640
651
        if (ok)
641
652
                return jd;
642
653
        
643
 
        QRegExp nowRe("^(now)?(\\s*([+\\-])\\s*(\\d+(\\.\\d+)?)\\s*(second|seconds|minute|minutes|hour|hours|day|days|week|weeks))(\\s+(sidereal)?)?");
 
654
        QRegExp nowRe("^(now)?(\\s*([+\\-])\\s*(\\d+(\\.\\d+)?)\\s*(second|seconds|minute|minutes|hour|hours|day|days|week|weeks|month|months|year|years))(\\s+(sidereal)?)?");
644
655
        if (nowRe.exactMatch(dt))
645
656
        {
646
657
                double delta;
647
658
                double unit;
648
659
                double dayLength = 1.0;
 
660
                double yearLength = 365.242190419; // duration of Earth's mean tropical year
 
661
                double monthLength = 27.321582241; // duration of Earth's mean tropical month
649
662
 
650
663
                if (nowRe.capturedTexts().at(1)=="now")
651
664
                        jd = StelUtils::getJDFromSystem();
652
665
                else
653
 
                        jd = StelApp::getInstance().getCore()->getJDay();
 
666
                        jd = core->getJDay();
654
667
 
655
668
                if (nowRe.capturedTexts().at(8) == "sidereal")
656
 
                        dayLength = StelApp::getInstance().getCore()->getLocalSideralDayLength();
 
669
                {
 
670
                        dayLength = core->getLocalSideralDayLength();
 
671
                        yearLength = core->getLocalSideralYearLength();
 
672
                        monthLength = 27.321661; // duration of Earth's sidereal month
 
673
                }
657
674
 
658
675
                QString unitString = nowRe.capturedTexts().at(6);
659
676
                if (unitString == "seconds" || unitString == "second")
666
683
                        unit = dayLength;
667
684
                else if (unitString == "weeks" || unitString == "week")
668
685
                        unit = dayLength * 7.;
 
686
                else if (unitString == "months" || unitString == "month")
 
687
                        unit = monthLength;
 
688
                else if (unitString == "years" || unitString == "year")
 
689
                        unit = yearLength;
669
690
                else
670
691
                {
671
692
                        qWarning() << "StelMainScriptAPI::setDate - unknown time unit:" << nowRe.capturedTexts().at(4);
766
787
        return map;
767
788
}
768
789
 
 
790
QVariantMap StelMainScriptAPI::getSelectedObjectInfo()
 
791
{
 
792
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
 
793
        QVariantMap map;
 
794
        if (omgr->getSelectedObject().isEmpty())
 
795
        {
 
796
                debug("getObjectData WARNING - object not selected");
 
797
                map.insert("found", false);
 
798
                return map;
 
799
        }
 
800
 
 
801
        StelObjectP obj = omgr->getSelectedObject()[0];
 
802
 
 
803
        if (!obj)
 
804
        {
 
805
                debug("getObjectData WARNING - object not found");
 
806
                map.insert("found", false);
 
807
                return map;
 
808
        }
 
809
        else
 
810
        {
 
811
                map.insert("found", true);
 
812
        }
 
813
 
 
814
        // OK, object found. Let's go.
 
815
        Vec3d pos;
 
816
        double ra, dec, alt, azi, glong, glat;
 
817
        StelCore* core = StelApp::getInstance().getCore();
 
818
 
 
819
        // ra/dec
 
820
        pos = obj->getEquinoxEquatorialPos(core);
 
821
        StelUtils::rectToSphe(&ra, &dec, pos);
 
822
        map.insert("ra", ra*180./M_PI);
 
823
        map.insert("dec", dec*180./M_PI);
 
824
 
 
825
        // ra/dec in J2000
 
826
        pos = obj->getJ2000EquatorialPos(core);
 
827
        StelUtils::rectToSphe(&ra, &dec, pos);
 
828
        map.insert("raJ2000", ra*180./M_PI);
 
829
        map.insert("decJ2000", dec*180./M_PI);
 
830
 
 
831
        // apparent altitude/azimuth
 
832
        pos = obj->getAltAzPosApparent(core);
 
833
        StelUtils::rectToSphe(&azi, &alt, pos);
 
834
        map.insert("altitude", alt*180./M_PI);
 
835
        map.insert("azimuth", azi*180./M_PI);
 
836
 
 
837
        // geometric altitude/azimuth
 
838
        pos = obj->getAltAzPosGeometric(core);
 
839
        StelUtils::rectToSphe(&azi, &alt, pos);
 
840
        map.insert("altitude-geometric", alt*180./M_PI);
 
841
        map.insert("azimuth-geometric", azi*180./M_PI);
 
842
 
 
843
        // galactic long/lat in J2000
 
844
        pos = obj->getJ2000GalacticPos(core);
 
845
        StelUtils::rectToSphe(&glong, &glat, pos);
 
846
        map.insert("glong", alt*180./M_PI);
 
847
        map.insert("glat", azi*180./M_PI);
 
848
 
 
849
        // magnitude
 
850
        map.insert("vmag", obj->getVMagnitude(core, false));
 
851
        map.insert("vmage", obj->getVMagnitude(core, true));
 
852
 
 
853
        // angular size
 
854
        map.insert("size", obj->getAngularSize(core));
 
855
 
 
856
        // english name or designation & localized name
 
857
        map.insert("name", obj->getEnglishName());
 
858
        map.insert("localized-name", obj->getNameI18n());
 
859
 
 
860
        return map;
 
861
}
 
862
 
 
863
 
769
864
void StelMainScriptAPI::clear(const QString& state)
770
865
{
771
866
        LandscapeMgr* lmgr = GETSTELMODULE(LandscapeMgr);