Merge lp:~alexwolf/stellarium/scripts-output into lp:stellarium

Proposed by Alexander Wolf
Status: Merged
Merged at revision: 6946
Proposed branch: lp:~alexwolf/stellarium/scripts-output
Merge into: lp:stellarium
Diff against target: 600 lines (+273/-61)
11 files modified
src/CMakeLists.txt (+2/-0)
src/gui/ScriptConsole.cpp (+17/-2)
src/gui/ScriptConsole.hpp (+1/-0)
src/gui/scriptConsole.ui (+70/-5)
src/main.cpp (+11/-0)
src/scripting/StelMainScriptAPI.cpp (+59/-52)
src/scripting/StelMainScriptAPI.hpp (+4/-0)
src/scripting/StelScriptMgr.cpp (+7/-0)
src/scripting/StelScriptMgr.hpp (+8/-2)
src/scripting/StelScriptOutput.cpp (+44/-0)
src/scripting/StelScriptOutput.hpp (+50/-0)
To merge this branch: bzr merge lp:~alexwolf/stellarium/scripts-output
Reviewer Review Type Date Requested Status
gzotti Approve
Fabien Chéreau Pending
Stellarium Pending
Review via email: mp+230235@code.launchpad.net

Description of the change

Added new feature to scripting engine: support of output data into a separate file from scripts

To post a comment you must log in.
Revision history for this message
gzotti (georg-zotti) wrote :

I rarely have used the script console (not lack of interest - it's a great feature, just not for me currently...). What shall I test? Any test script included that uses the new feature and shows usage syntax?

review: Needs Information
Revision history for this message
Alexander Wolf (alexwolf) wrote :

A long time the only way getting tabulated data from scripts for using outside Stellarium was using debug mode: e.g. core.debug("some text"); Now I introduce second output channel from scripts - core.output("some text");. You can use within scripts core.debug() for debugging messages and core.output() for data.

Typical case for the new feature - getting table coordinates of celestial body as function of time.

Revision history for this message
gzotti (georg-zotti) wrote :

Sounds good. But can you maybe add a practical example, e.g. scripts/ephemeris-file-for-selected.ssc or so, that could provide as usage example: 1 month of day-to-day RA/Dec/mag/distance/... values of the currently selected object (ideally of Planet class or subclasses thereof). Else I don't know whether any potential user (me included ;-) will understand what to do/how to use it. As I said, I am not a frequent user of the scripts, although I find them a valuable feature.

In the source file I see the output goes into <USERDIR>/output.txt. Maybe a way to set filename in the script would be possible? This would allow having several similar scripts for objects of interest that can be called without further editing?

Revision history for this message
Alexander Wolf (alexwolf) wrote :

Just put it into script console and run :)

core.setDate("2014-01-01T12:00:00", "utc");
core.output("Day\t|\tRA\t|\tDE\t|\tMagnitude");
for(i=0;i<365;i++)
{
 data = core.getObjectInfo("Mars");
 core.output(i+"\t|"+data["ra"]+"\t|"+data["dec"]+"\t|"+data["vmag"]);
 core.setDate("+1day");
 core.wait(0.1);
}

Revision history for this message
Alexander Wolf (alexwolf) wrote :

Or:

core.setJDay(2456600);
core.output("JD\t|Delta T");
core.output("======================");
for(i=0;i<500;i++)
{
 core.output(core.getJDay()+"\t|"+core.getDeltaT());
 core.setJDay(core.getJDay()+100);
 core.wait(0.1);
}

Revision history for this message
Alexander Wolf (alexwolf) wrote :

output file name is hard coded for security reason

Revision history for this message
gzotti (georg-zotti) wrote :

OK, I get syntax errors in the scripts. Just the one line with "output" works, though, that was the main point.
Another suggestion if creating with filename not possible: As I see it, the file gets reset on every start. Maybe make it configurable to allow appending? This would be useful for intermittent work on long observation lists, ephemerides etc, which one would like to collect for later use. Catastrophic for those users if file gets reset just with a restart of Stellarium.

6945. By Alexander Wolf

introduced new option - main/use_separate_output_file

Revision history for this message
Alexander Wolf (alexwolf) wrote :

I introduce new config option - main/use_separate_output_file - to enable create a new file for output for each start of Stellarium.

By default main/use_separate_output_file=false and Stellarium use one output.txt file

Revision history for this message
gzotti (georg-zotti) wrote :

OK, also a good solution!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-07-26 13:16:21 +0000
+++ src/CMakeLists.txt 2014-08-12 09:52:27 +0000
@@ -252,6 +252,8 @@
252252
253IF(ENABLE_SCRIPTING)253IF(ENABLE_SCRIPTING)
254 SET(stellarium_lib_SRCS ${stellarium_lib_SRCS}254 SET(stellarium_lib_SRCS ${stellarium_lib_SRCS}
255 scripting/StelScriptOutput.hpp
256 scripting/StelScriptOutput.cpp
255 scripting/StelScriptMgr.cpp257 scripting/StelScriptMgr.cpp
256 scripting/StratoscriptPreprocessor.cpp258 scripting/StratoscriptPreprocessor.cpp
257 scripting/StelScriptMgr.hpp259 scripting/StelScriptMgr.hpp
258260
=== modified file 'src/gui/ScriptConsole.cpp'
--- src/gui/ScriptConsole.cpp 2014-04-19 12:01:08 +0000
+++ src/gui/ScriptConsole.cpp 2014-08-12 09:52:27 +0000
@@ -89,6 +89,7 @@
89 connect(ui->quickrunCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(quickRun(int)));89 connect(ui->quickrunCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(quickRun(int)));
90 connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptStopped()), this, SLOT(scriptEnded()));90 connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptStopped()), this, SLOT(scriptEnded()));
91 connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptDebug(const QString&)), this, SLOT(appendLogLine(const QString&)));91 connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptDebug(const QString&)), this, SLOT(appendLogLine(const QString&)));
92 connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptOutput(const QString&)), this, SLOT(appendOutputLine(const QString&)));
92#ifndef ENABLE_STRATOSCRIPT_COMPAT93#ifndef ENABLE_STRATOSCRIPT_COMPAT
93 ui->preprocessSTSButton->setHidden(true);94 ui->preprocessSTSButton->setHidden(true);
94#else95#else
@@ -140,6 +141,8 @@
140 if (ui->tabs->currentIndex() == 0)141 if (ui->tabs->currentIndex() == 0)
141 ui->scriptEdit->clear();142 ui->scriptEdit->clear();
142 else if (ui->tabs->currentIndex() == 1)143 else if (ui->tabs->currentIndex() == 1)
144 ui->logBrowser->clear();
145 else if (ui->tabs->currentIndex() == 2)
143 ui->outputBrowser->clear();146 ui->outputBrowser->clear();
144}147}
145148
@@ -179,7 +182,7 @@
179void ScriptConsole::runScript()182void ScriptConsole::runScript()
180{183{
181 ui->tabs->setCurrentIndex(1);184 ui->tabs->setCurrentIndex(1);
182 ui->outputBrowser->setHtml("");185 ui->logBrowser->setHtml("");
183 QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc");186 QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc");
184 QString fileName;187 QString fileName;
185 if (file.open()) {188 if (file.open()) {
@@ -221,7 +224,7 @@
221void ScriptConsole::scriptEnded()224void ScriptConsole::scriptEnded()
222{225{
223 qDebug() << "ScriptConsole::scriptEnded";226 qDebug() << "ScriptConsole::scriptEnded";
224 QString html = ui->outputBrowser->toHtml();227 QString html = ui->logBrowser->toHtml();
225 appendLogLine(QString("Script finished at %1").arg(QDateTime::currentDateTime().toString()));228 appendLogLine(QString("Script finished at %1").arg(QDateTime::currentDateTime().toString()));
226 ui->runButton->setEnabled(true);229 ui->runButton->setEnabled(true);
227 ui->stopButton->setEnabled(false);230 ui->stopButton->setEnabled(false);
@@ -229,6 +232,17 @@
229232
230void ScriptConsole::appendLogLine(const QString& s)233void ScriptConsole::appendLogLine(const QString& s)
231{234{
235 QString html = ui->logBrowser->toHtml();
236 html.replace(QRegExp("^\\s+"), "");
237 // if (html!="")
238 // html += "<br />";
239
240 html += s;
241 ui->logBrowser->setHtml(html);
242}
243
244void ScriptConsole::appendOutputLine(const QString& s)
245{
232 QString html = ui->outputBrowser->toHtml();246 QString html = ui->outputBrowser->toHtml();
233 html.replace(QRegExp("^\\s+"), "");247 html.replace(QRegExp("^\\s+"), "");
234 // if (html!="")248 // if (html!="")
@@ -238,6 +252,7 @@
238 ui->outputBrowser->setHtml(html);252 ui->outputBrowser->setHtml(html);
239}253}
240254
255
241void ScriptConsole::includeBrowse()256void ScriptConsole::includeBrowse()
242{257{
243 ui->includeEdit->setText(QFileDialog::getExistingDirectory(&StelMainView::getInstance(), 258 ui->includeEdit->setText(QFileDialog::getExistingDirectory(&StelMainView::getInstance(),
244259
=== modified file 'src/gui/ScriptConsole.hpp'
--- src/gui/ScriptConsole.hpp 2012-02-13 18:59:16 +0000
+++ src/gui/ScriptConsole.hpp 2014-08-12 09:52:27 +0000
@@ -44,6 +44,7 @@
44 void preprocessScript();44 void preprocessScript();
45 void scriptEnded();45 void scriptEnded();
46 void appendLogLine(const QString& s);46 void appendLogLine(const QString& s);
47 void appendOutputLine(const QString& s);
47 void includeBrowse();48 void includeBrowse();
48 void quickRun(int idx);49 void quickRun(int idx);
49 void rowColumnChanged();50 void rowColumnChanged();
5051
=== modified file 'src/gui/scriptConsole.ui'
--- src/gui/scriptConsole.ui 2012-02-20 10:28:26 +0000
+++ src/gui/scriptConsole.ui 2014-08-12 09:52:27 +0000
@@ -17,7 +17,16 @@
17 <property name="spacing">17 <property name="spacing">
18 <number>0</number>18 <number>0</number>
19 </property>19 </property>
20 <property name="margin">20 <property name="leftMargin">
21 <number>0</number>
22 </property>
23 <property name="topMargin">
24 <number>0</number>
25 </property>
26 <property name="rightMargin">
27 <number>0</number>
28 </property>
29 <property name="bottomMargin">
21 <number>0</number>30 <number>0</number>
22 </property>31 </property>
23 <item>32 <item>
@@ -139,7 +148,16 @@
139 <property name="spacing">148 <property name="spacing">
140 <number>0</number>149 <number>0</number>
141 </property>150 </property>
142 <property name="margin">151 <property name="leftMargin">
152 <number>0</number>
153 </property>
154 <property name="topMargin">
155 <number>0</number>
156 </property>
157 <property name="rightMargin">
158 <number>0</number>
159 </property>
160 <property name="bottomMargin">
143 <number>0</number>161 <number>0</number>
144 </property>162 </property>
145 <item>163 <item>
@@ -220,7 +238,7 @@
220 </size>238 </size>
221 </property>239 </property>
222 <property name="toolTip">240 <property name="toolTip">
223 <string>clear script</string>241 <string>clear</string>
224 </property>242 </property>
225 <property name="text">243 <property name="text">
226 <string/>244 <string/>
@@ -372,7 +390,16 @@
372 <string>Script</string>390 <string>Script</string>
373 </attribute>391 </attribute>
374 <layout class="QVBoxLayout" name="verticalLayout_3">392 <layout class="QVBoxLayout" name="verticalLayout_3">
375 <property name="margin">393 <property name="leftMargin">
394 <number>0</number>
395 </property>
396 <property name="topMargin">
397 <number>0</number>
398 </property>
399 <property name="rightMargin">
400 <number>0</number>
401 </property>
402 <property name="bottomMargin">
376 <number>0</number>403 <number>0</number>
377 </property>404 </property>
378 <item>405 <item>
@@ -396,12 +423,50 @@
396 </item>423 </item>
397 </layout>424 </layout>
398 </widget>425 </widget>
426 <widget class="QWidget" name="logTab">
427 <attribute name="title">
428 <string>Log</string>
429 </attribute>
430 <layout class="QVBoxLayout" name="verticalLayout_5">
431 <property name="leftMargin">
432 <number>0</number>
433 </property>
434 <property name="topMargin">
435 <number>0</number>
436 </property>
437 <property name="rightMargin">
438 <number>0</number>
439 </property>
440 <property name="bottomMargin">
441 <number>0</number>
442 </property>
443 <item>
444 <widget class="QTextBrowser" name="logBrowser">
445 <property name="font">
446 <font>
447 <family>DejaVu Sans Mono</family>
448 <pointsize>8</pointsize>
449 </font>
450 </property>
451 </widget>
452 </item>
453 </layout>
454 </widget>
399 <widget class="QWidget" name="outputTab">455 <widget class="QWidget" name="outputTab">
400 <attribute name="title">456 <attribute name="title">
401 <string>Output</string>457 <string>Output</string>
402 </attribute>458 </attribute>
403 <layout class="QVBoxLayout" name="verticalLayout_4">459 <layout class="QVBoxLayout" name="verticalLayout_4">
404 <property name="margin">460 <property name="leftMargin">
461 <number>0</number>
462 </property>
463 <property name="topMargin">
464 <number>0</number>
465 </property>
466 <property name="rightMargin">
467 <number>0</number>
468 </property>
469 <property name="bottomMargin">
405 <number>0</number>470 <number>0</number>
406 </property>471 </property>
407 <item>472 <item>
408473
=== modified file 'src/main.cpp'
--- src/main.cpp 2014-08-01 18:48:38 +0000
+++ src/main.cpp 2014-08-12 09:52:27 +0000
@@ -25,6 +25,9 @@
25#include "CLIProcessor.hpp"25#include "CLIProcessor.hpp"
26#include "StelIniParser.hpp"26#include "StelIniParser.hpp"
27#include "StelUtils.hpp"27#include "StelUtils.hpp"
28#ifndef DISABLE_SCRIPTING
29#include "StelScriptOutput.hpp"
30#endif
2831
29#include <QDebug>32#include <QDebug>
3033
@@ -289,6 +292,14 @@
289 Q_ASSERT(confSettings);292 Q_ASSERT(confSettings);
290 qDebug() << "Config file is: " << QDir::toNativeSeparators(configFileFullPath);293 qDebug() << "Config file is: " << QDir::toNativeSeparators(configFileFullPath);
291294
295 #ifndef DISABLE_SCRIPTING
296 QString outputFile = StelFileMgr::getUserDir()+"/output.txt";
297 if (confSettings->value("main/use_separate_output_file", false).toBool())
298 outputFile = StelFileMgr::getUserDir()+"/output-"+QDateTime::currentDateTime().toString("yyyyMMdd-HHmmss")+".txt";
299 StelScriptOutput::init(outputFile);
300 #endif
301
302
292 // Override config file values from CLI.303 // Override config file values from CLI.
293 CLIProcessor::parseCLIArgsPostConfig(argList, confSettings);304 CLIProcessor::parseCLIArgsPostConfig(argList, confSettings);
294305
295306
=== modified file 'src/scripting/StelMainScriptAPI.cpp'
--- src/scripting/StelMainScriptAPI.cpp 2014-01-15 07:13:40 +0000
+++ src/scripting/StelMainScriptAPI.cpp 2014-08-12 09:52:27 +0000
@@ -361,34 +361,34 @@
361}361}
362362
363void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,363void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,
364 double ra0, double dec0,364 double ra0, double dec0,
365 double ra1, double dec1,365 double ra1, double dec1,
366 double ra2, double dec2,366 double ra2, double dec2,
367 double ra3, double dec3,367 double ra3, double dec3,
368 double minRes, double maxBright, bool visible)368 double minRes, double maxBright, bool visible)
369{369{
370 QString path = "scripts/" + filename;370 QString path = "scripts/" + filename;
371 emit(requestLoadSkyImage(id, path, ra0, dec0, ra1, dec1, ra2, dec2, ra3, dec3, minRes, maxBright, visible));371 emit(requestLoadSkyImage(id, path, ra0, dec0, ra1, dec1, ra2, dec2, ra3, dec3, minRes, maxBright, visible));
372}372}
373373
374void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,374void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,
375 const QString& ra0, const QString& dec0,375 const QString& ra0, const QString& dec0,
376 const QString& ra1, const QString& dec1,376 const QString& ra1, const QString& dec1,
377 const QString& ra2, const QString& dec2,377 const QString& ra2, const QString& dec2,
378 const QString& ra3, const QString& dec3,378 const QString& ra3, const QString& dec3,
379 double minRes, double maxBright, bool visible)379 double minRes, double maxBright, bool visible)
380{380{
381 loadSkyImage(id, filename,381 loadSkyImage(id, filename,
382 StelUtils::getDecAngle(ra0) *180./M_PI, StelUtils::getDecAngle(dec0)*180./M_PI,382 StelUtils::getDecAngle(ra0) *180./M_PI, StelUtils::getDecAngle(dec0)*180./M_PI,
383 StelUtils::getDecAngle(ra1) *180./M_PI, StelUtils::getDecAngle(dec1)*180./M_PI,383 StelUtils::getDecAngle(ra1) *180./M_PI, StelUtils::getDecAngle(dec1)*180./M_PI,
384 StelUtils::getDecAngle(ra2) *180./M_PI, StelUtils::getDecAngle(dec2)*180./M_PI,384 StelUtils::getDecAngle(ra2) *180./M_PI, StelUtils::getDecAngle(dec2)*180./M_PI,
385 StelUtils::getDecAngle(ra3) *180./M_PI, StelUtils::getDecAngle(dec3)*180./M_PI,385 StelUtils::getDecAngle(ra3) *180./M_PI, StelUtils::getDecAngle(dec3)*180./M_PI,
386 minRes, maxBright, visible);386 minRes, maxBright, visible);
387}387}
388388
389void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,389void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,
390 double ra, double dec, double angSize, double rotation,390 double ra, double dec, double angSize, double rotation,
391 double minRes, double maxBright, bool visible)391 double minRes, double maxBright, bool visible)
392{392{
393 Vec3f XYZ;393 Vec3f XYZ;
394 static const float RADIUS_NEB = 1.;394 static const float RADIUS_NEB = 1.;
@@ -396,15 +396,15 @@
396 XYZ*=RADIUS_NEB;396 XYZ*=RADIUS_NEB;
397 float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180);397 float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180);
398 Mat4f matPrecomp = Mat4f::translation(XYZ) *398 Mat4f matPrecomp = Mat4f::translation(XYZ) *
399 Mat4f::zrotation(ra*M_PI/180.) *399 Mat4f::zrotation(ra*M_PI/180.) *
400 Mat4f::yrotation(-dec*M_PI/180.) *400 Mat4f::yrotation(-dec*M_PI/180.) *
401 Mat4f::xrotation(rotation*M_PI/180.);401 Mat4f::xrotation(rotation*M_PI/180.);
402402
403 Vec3f corners[4];403 Vec3f corners[4];
404 corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize);404 corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize);
405 corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize);405 corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize);
406 corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize);406 corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize);
407 corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize);407 corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize);
408408
409 // convert back to ra/dec (radians)409 // convert back to ra/dec (radians)
410 Vec3f cornersRaDec[4];410 Vec3f cornersRaDec[4];
@@ -412,38 +412,40 @@
412 StelUtils::rectToSphe(&cornersRaDec[i][0], &cornersRaDec[i][1], corners[i]);412 StelUtils::rectToSphe(&cornersRaDec[i][0], &cornersRaDec[i][1], corners[i]);
413413
414 loadSkyImage(id, filename,414 loadSkyImage(id, filename,
415 cornersRaDec[0][0]*180./M_PI, cornersRaDec[0][1]*180./M_PI,415 cornersRaDec[0][0]*180./M_PI, cornersRaDec[0][1]*180./M_PI,
416 cornersRaDec[1][0]*180./M_PI, cornersRaDec[1][1]*180./M_PI,416 cornersRaDec[1][0]*180./M_PI, cornersRaDec[1][1]*180./M_PI,
417 cornersRaDec[3][0]*180./M_PI, cornersRaDec[3][1]*180./M_PI,417 cornersRaDec[3][0]*180./M_PI, cornersRaDec[3][1]*180./M_PI,
418 cornersRaDec[2][0]*180./M_PI, cornersRaDec[2][1]*180./M_PI,418 cornersRaDec[2][0]*180./M_PI, cornersRaDec[2][1]*180./M_PI,
419 minRes, maxBright, visible);419 minRes, maxBright, visible);
420}420}
421421
422422
423423
424void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,424void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename,
425 const QString& ra, const QString& dec, double angSize, double rotation,425 const QString& ra, const QString& dec,
426 double minRes, double maxBright, bool visible)426 double angSize, double rotation,
427 double minRes, double maxBright, bool visible)
427{428{
428 loadSkyImage(id, filename, StelUtils::getDecAngle(ra)*180./M_PI,429 loadSkyImage(id, filename, StelUtils::getDecAngle(ra)*180./M_PI,
429 StelUtils::getDecAngle(dec)*180./M_PI, angSize,430 StelUtils::getDecAngle(dec)*180./M_PI, angSize,
430 rotation, minRes, maxBright, visible);431 rotation, minRes, maxBright, visible);
431}432}
432433
433void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename,434void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename,
434 double alt0, double azi0,435 double alt0, double azi0,
435 double alt1, double azi1,436 double alt1, double azi1,
436 double alt2, double azi2,437 double alt2, double azi2,
437 double alt3, double azi3,438 double alt3, double azi3,
438 double minRes, double maxBright, bool visible)439 double minRes, double maxBright, bool visible)
439{440{
440 QString path = "scripts/" + filename;441 QString path = "scripts/" + filename;
441 emit(requestLoadSkyImageAltAz(id, path, alt0, azi0, alt1, azi1, alt2, azi2, alt3, azi3, minRes, maxBright, visible));442 emit(requestLoadSkyImageAltAz(id, path, alt0, azi0, alt1, azi1, alt2, azi2, alt3, azi3, minRes, maxBright, visible));
442}443}
443444
444void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename,445void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename,
445 double alt, double azi, double angSize, double rotation,446 double alt, double azi,
446 double minRes, double maxBright, bool visible)447 double angSize, double rotation,
448 double minRes, double maxBright, bool visible)
447{449{
448 Vec3f XYZ;450 Vec3f XYZ;
449 static const float RADIUS_NEB = 1.;451 static const float RADIUS_NEB = 1.;
@@ -452,15 +454,15 @@
452 XYZ*=RADIUS_NEB;454 XYZ*=RADIUS_NEB;
453 float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180);455 float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180);
454 Mat4f matPrecomp = Mat4f::translation(XYZ) *456 Mat4f matPrecomp = Mat4f::translation(XYZ) *
455 Mat4f::zrotation((180-azi)*M_PI/180.) *457 Mat4f::zrotation((180-azi)*M_PI/180.) *
456 Mat4f::yrotation(-alt*M_PI/180.) *458 Mat4f::yrotation(-alt*M_PI/180.) *
457 Mat4f::xrotation((rotation+90)*M_PI/180.);459 Mat4f::xrotation((rotation+90)*M_PI/180.);
458460
459 Vec3f corners[4];461 Vec3f corners[4];
460 corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize);462 corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize);
461 corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize);463 corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize);
462 corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize);464 corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize);
463 corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize);465 corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize);
464466
465 // convert back to alt/azi (radians)467 // convert back to alt/azi (radians)
466 Vec3f cornersAltAz[4];468 Vec3f cornersAltAz[4];
@@ -468,11 +470,11 @@
468 StelUtils::rectToSphe(&cornersAltAz[i][0], &cornersAltAz[i][1], corners[i]);470 StelUtils::rectToSphe(&cornersAltAz[i][0], &cornersAltAz[i][1], corners[i]);
469471
470 loadSkyImageAltAz(id, filename,472 loadSkyImageAltAz(id, filename,
471 cornersAltAz[0][0]*180./M_PI, cornersAltAz[0][1]*180./M_PI,473 cornersAltAz[0][0]*180./M_PI, cornersAltAz[0][1]*180./M_PI,
472 cornersAltAz[1][0]*180./M_PI, cornersAltAz[1][1]*180./M_PI,474 cornersAltAz[1][0]*180./M_PI, cornersAltAz[1][1]*180./M_PI,
473 cornersAltAz[3][0]*180./M_PI, cornersAltAz[3][1]*180./M_PI,475 cornersAltAz[3][0]*180./M_PI, cornersAltAz[3][1]*180./M_PI,
474 cornersAltAz[2][0]*180./M_PI, cornersAltAz[2][1]*180./M_PI,476 cornersAltAz[2][0]*180./M_PI, cornersAltAz[2][1]*180./M_PI,
475 minRes, maxBright, visible);477 minRes, maxBright, visible);
476}478}
477479
478void StelMainScriptAPI::removeSkyImage(const QString& id)480void StelMainScriptAPI::removeSkyImage(const QString& id)
@@ -622,6 +624,11 @@
622 StelApp::getInstance().getScriptMgr().debug(s);624 StelApp::getInstance().getScriptMgr().debug(s);
623}625}
624626
627void StelMainScriptAPI::output(const QString &s)
628{
629 StelApp::getInstance().getScriptMgr().output(s);
630}
631
625double StelMainScriptAPI::jdFromDateString(const QString& dt, const QString& spec)632double StelMainScriptAPI::jdFromDateString(const QString& dt, const QString& spec)
626{633{
627 StelCore *core = StelApp::getInstance().getCore();634 StelCore *core = StelApp::getInstance().getCore();
628635
=== modified file 'src/scripting/StelMainScriptAPI.hpp'
--- src/scripting/StelMainScriptAPI.hpp 2013-08-04 06:13:29 +0000
+++ src/scripting/StelMainScriptAPI.hpp 2014-08-12 09:52:27 +0000
@@ -614,6 +614,10 @@
614 //! @param s the message to be displayed on the console.614 //! @param s the message to be displayed on the console.
615 void debug(const QString& s);615 void debug(const QString& s);
616616
617 //! print an output message from script
618 //! @param s the message to be displayed on the output file.
619 void output(const QString& s);
620
617 //! Get the current application language.621 //! Get the current application language.
618 //! @return two letter language code, e.g. "en", or "de" and so on.622 //! @return two letter language code, e.g. "en", or "de" and so on.
619 QString getAppLanguage();623 QString getAppLanguage();
620624
=== modified file 'src/scripting/StelScriptMgr.cpp'
--- src/scripting/StelScriptMgr.cpp 2014-07-13 05:52:52 +0000
+++ src/scripting/StelScriptMgr.cpp 2014-08-12 09:52:27 +0000
@@ -19,6 +19,7 @@
19 */19 */
2020
2121
22#include "StelScriptOutput.hpp"
22#include "StelScriptMgr.hpp"23#include "StelScriptMgr.hpp"
23#include "StelMainScriptAPI.hpp"24#include "StelMainScriptAPI.hpp"
24#include "StelModuleMgr.hpp"25#include "StelModuleMgr.hpp"
@@ -423,6 +424,12 @@
423 emit(scriptDebug(msg));424 emit(scriptDebug(msg));
424}425}
425426
427void StelScriptMgr::output(const QString &msg)
428{
429 StelScriptOutput::writeLog(msg);
430 emit(scriptOutput(msg));
431}
432
426void StelScriptMgr::scriptEnded()433void StelScriptMgr::scriptEnded()
427{434{
428 if (engine.hasUncaughtException())435 if (engine.hasUncaughtException())
429436
=== modified file 'src/scripting/StelScriptMgr.hpp'
--- src/scripting/StelScriptMgr.hpp 2014-04-10 02:47:02 +0000
+++ src/scripting/StelScriptMgr.hpp 2014-08-12 09:52:27 +0000
@@ -136,10 +136,14 @@
136 //! execution rate.136 //! execution rate.
137 double getScriptRate();137 double getScriptRate();
138138
139 //! cause the emission of the scriptDebug signal. This is so that functions in139 //! cause the emission of the scriptDebug signal. This is so that functions in
140 //! StelMainScriptAPI can explicitly send information to the ScriptConsole140 //! StelMainScriptAPI can explicitly send information to the ScriptConsole
141 void debug(const QString& msg);141 void debug(const QString& msg);
142142
143 //! cause the emission of the scriptOutput signal. This is so that functions in
144 //! StelMainScriptAPI can explicitly send information to the ScriptConsole
145 void output(const QString& msg);
146
143 //! Pause a running script.147 //! Pause a running script.
144 void pauseScript();148 void pauseScript();
145149
@@ -155,7 +159,9 @@
155 //! Notification when a script has stopped running 159 //! Notification when a script has stopped running
156 void scriptStopped();160 void scriptStopped();
157 //! Notification of a script event - warnings, current execution line etc.161 //! Notification of a script event - warnings, current execution line etc.
158 void scriptDebug(const QString&);162 void scriptDebug(const QString&);
163 //! Notification of a script event - output line.
164 void scriptOutput(const QString&);
159165
160private:166private:
161 // Utility functions for preprocessor167 // Utility functions for preprocessor
162168
=== added file 'src/scripting/StelScriptOutput.cpp'
--- src/scripting/StelScriptOutput.cpp 1970-01-01 00:00:00 +0000
+++ src/scripting/StelScriptOutput.cpp 2014-08-12 09:52:27 +0000
@@ -0,0 +1,44 @@
1/*
2 * Stellarium
3 * Copyright (C) 2014 Alexander Wolf
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#include "StelScriptOutput.hpp"
21#include <QDebug>
22
23// Init statics variables.
24QFile StelScriptOutput::outputFile;
25QString StelScriptOutput::outputText;
26
27void StelScriptOutput::init(const QString& outputFilePath)
28{
29 outputFile.setFileName(outputFilePath);
30 if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text | QIODevice::Unbuffered))
31 qDebug() << "ERROR: Cannot open output.txt file";
32}
33
34void StelScriptOutput::deinit()
35{
36 outputFile.close();
37}
38
39void StelScriptOutput::writeLog(QString msg)
40{
41 msg += "\n";
42 outputFile.write(qPrintable(msg), msg.size());
43 outputText += msg;
44}
045
=== added file 'src/scripting/StelScriptOutput.hpp'
--- src/scripting/StelScriptOutput.hpp 1970-01-01 00:00:00 +0000
+++ src/scripting/StelScriptOutput.hpp 2014-08-12 09:52:27 +0000
@@ -0,0 +1,50 @@
1/*
2 * Stellarium
3 * Copyright (C) 2014 Alexander Wolf
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 STELSCRIPTOUTPUT_HPP
21#define STELSCRIPTOUTPUT_HPP
22
23#include "config.h"
24
25#include <QString>
26#include <QFile>
27
28//! @class StelScriptOutput
29//! Class wit only static members used to manage output for Stellarium scripts.
30class StelScriptOutput
31{
32public:
33 //! Create and initialize the log file.
34 //! Prepend system information before any output.
35 static void init(const QString& outputFilePath);
36
37 //! Deinitialize the output file.
38 //! Must be called after init() was called.
39 static void deinit();
40
41 //! Write the message plus a newline to the output file at $USERDIR/output.txt.
42 //! @param msg message to write.
43 static void writeLog(QString msg);
44
45private:
46 static QFile outputFile;
47 static QString outputText;
48};
49
50#endif // STELSCRIPTOUTPUT_HPP