Merge lp:~alexwolf/stellarium/scripts-output into lp:stellarium
- scripts-output
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
gzotti | Approve | ||
Fabien Chéreau | Pending | ||
Stellarium | Pending | ||
Review via email: mp+230235@code.launchpad.net |
Commit message
Description of the change
Added new feature to scripting engine: support of output data into a separate file from scripts
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.
gzotti (georg-zotti) wrote : | # |
Sounds good. But can you maybe add a practical example, e.g. scripts/
In the source file I see the output goes into <USERDIR>
Alexander Wolf (alexwolf) wrote : | # |
Just put it into script console and run :)
core.setDate(
core.output(
for(i=0;i<365;i++)
{
data = core.getObjectI
core.output(
core.setDate(
core.wait(0.1);
}
Alexander Wolf (alexwolf) wrote : | # |
Or:
core.setJDay(
core.output(
core.output(
for(i=0;i<500;i++)
{
core.output(
core.setJDay(
core.wait(0.1);
}
Alexander Wolf (alexwolf) wrote : | # |
output file name is hard coded for security reason
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
Alexander Wolf (alexwolf) wrote : | # |
I introduce new config option - main/use_
By default main/use_
gzotti (georg-zotti) wrote : | # |
OK, also a good solution!
Preview Diff
1 | === modified file 'src/CMakeLists.txt' | |||
2 | --- src/CMakeLists.txt 2014-07-26 13:16:21 +0000 | |||
3 | +++ src/CMakeLists.txt 2014-08-12 09:52:27 +0000 | |||
4 | @@ -252,6 +252,8 @@ | |||
5 | 252 | 252 | ||
6 | 253 | IF(ENABLE_SCRIPTING) | 253 | IF(ENABLE_SCRIPTING) |
7 | 254 | SET(stellarium_lib_SRCS ${stellarium_lib_SRCS} | 254 | SET(stellarium_lib_SRCS ${stellarium_lib_SRCS} |
8 | 255 | scripting/StelScriptOutput.hpp | ||
9 | 256 | scripting/StelScriptOutput.cpp | ||
10 | 255 | scripting/StelScriptMgr.cpp | 257 | scripting/StelScriptMgr.cpp |
11 | 256 | scripting/StratoscriptPreprocessor.cpp | 258 | scripting/StratoscriptPreprocessor.cpp |
12 | 257 | scripting/StelScriptMgr.hpp | 259 | scripting/StelScriptMgr.hpp |
13 | 258 | 260 | ||
14 | === modified file 'src/gui/ScriptConsole.cpp' | |||
15 | --- src/gui/ScriptConsole.cpp 2014-04-19 12:01:08 +0000 | |||
16 | +++ src/gui/ScriptConsole.cpp 2014-08-12 09:52:27 +0000 | |||
17 | @@ -89,6 +89,7 @@ | |||
18 | 89 | connect(ui->quickrunCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(quickRun(int))); | 89 | connect(ui->quickrunCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(quickRun(int))); |
19 | 90 | connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptStopped()), this, SLOT(scriptEnded())); | 90 | connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptStopped()), this, SLOT(scriptEnded())); |
20 | 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&))); |
21 | 92 | connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptOutput(const QString&)), this, SLOT(appendOutputLine(const QString&))); | ||
22 | 92 | #ifndef ENABLE_STRATOSCRIPT_COMPAT | 93 | #ifndef ENABLE_STRATOSCRIPT_COMPAT |
23 | 93 | ui->preprocessSTSButton->setHidden(true); | 94 | ui->preprocessSTSButton->setHidden(true); |
24 | 94 | #else | 95 | #else |
25 | @@ -140,6 +141,8 @@ | |||
26 | 140 | if (ui->tabs->currentIndex() == 0) | 141 | if (ui->tabs->currentIndex() == 0) |
27 | 141 | ui->scriptEdit->clear(); | 142 | ui->scriptEdit->clear(); |
28 | 142 | else if (ui->tabs->currentIndex() == 1) | 143 | else if (ui->tabs->currentIndex() == 1) |
29 | 144 | ui->logBrowser->clear(); | ||
30 | 145 | else if (ui->tabs->currentIndex() == 2) | ||
31 | 143 | ui->outputBrowser->clear(); | 146 | ui->outputBrowser->clear(); |
32 | 144 | } | 147 | } |
33 | 145 | 148 | ||
34 | @@ -179,7 +182,7 @@ | |||
35 | 179 | void ScriptConsole::runScript() | 182 | void ScriptConsole::runScript() |
36 | 180 | { | 183 | { |
37 | 181 | ui->tabs->setCurrentIndex(1); | 184 | ui->tabs->setCurrentIndex(1); |
39 | 182 | ui->outputBrowser->setHtml(""); | 185 | ui->logBrowser->setHtml(""); |
40 | 183 | QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc"); | 186 | QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc"); |
41 | 184 | QString fileName; | 187 | QString fileName; |
42 | 185 | if (file.open()) { | 188 | if (file.open()) { |
43 | @@ -221,7 +224,7 @@ | |||
44 | 221 | void ScriptConsole::scriptEnded() | 224 | void ScriptConsole::scriptEnded() |
45 | 222 | { | 225 | { |
46 | 223 | qDebug() << "ScriptConsole::scriptEnded"; | 226 | qDebug() << "ScriptConsole::scriptEnded"; |
48 | 224 | QString html = ui->outputBrowser->toHtml(); | 227 | QString html = ui->logBrowser->toHtml(); |
49 | 225 | appendLogLine(QString("Script finished at %1").arg(QDateTime::currentDateTime().toString())); | 228 | appendLogLine(QString("Script finished at %1").arg(QDateTime::currentDateTime().toString())); |
50 | 226 | ui->runButton->setEnabled(true); | 229 | ui->runButton->setEnabled(true); |
51 | 227 | ui->stopButton->setEnabled(false); | 230 | ui->stopButton->setEnabled(false); |
52 | @@ -229,6 +232,17 @@ | |||
53 | 229 | 232 | ||
54 | 230 | void ScriptConsole::appendLogLine(const QString& s) | 233 | void ScriptConsole::appendLogLine(const QString& s) |
55 | 231 | { | 234 | { |
56 | 235 | QString html = ui->logBrowser->toHtml(); | ||
57 | 236 | html.replace(QRegExp("^\\s+"), ""); | ||
58 | 237 | // if (html!="") | ||
59 | 238 | // html += "<br />"; | ||
60 | 239 | |||
61 | 240 | html += s; | ||
62 | 241 | ui->logBrowser->setHtml(html); | ||
63 | 242 | } | ||
64 | 243 | |||
65 | 244 | void ScriptConsole::appendOutputLine(const QString& s) | ||
66 | 245 | { | ||
67 | 232 | QString html = ui->outputBrowser->toHtml(); | 246 | QString html = ui->outputBrowser->toHtml(); |
68 | 233 | html.replace(QRegExp("^\\s+"), ""); | 247 | html.replace(QRegExp("^\\s+"), ""); |
69 | 234 | // if (html!="") | 248 | // if (html!="") |
70 | @@ -238,6 +252,7 @@ | |||
71 | 238 | ui->outputBrowser->setHtml(html); | 252 | ui->outputBrowser->setHtml(html); |
72 | 239 | } | 253 | } |
73 | 240 | 254 | ||
74 | 255 | |||
75 | 241 | void ScriptConsole::includeBrowse() | 256 | void ScriptConsole::includeBrowse() |
76 | 242 | { | 257 | { |
77 | 243 | ui->includeEdit->setText(QFileDialog::getExistingDirectory(&StelMainView::getInstance(), | 258 | ui->includeEdit->setText(QFileDialog::getExistingDirectory(&StelMainView::getInstance(), |
78 | 244 | 259 | ||
79 | === modified file 'src/gui/ScriptConsole.hpp' | |||
80 | --- src/gui/ScriptConsole.hpp 2012-02-13 18:59:16 +0000 | |||
81 | +++ src/gui/ScriptConsole.hpp 2014-08-12 09:52:27 +0000 | |||
82 | @@ -44,6 +44,7 @@ | |||
83 | 44 | void preprocessScript(); | 44 | void preprocessScript(); |
84 | 45 | void scriptEnded(); | 45 | void scriptEnded(); |
85 | 46 | void appendLogLine(const QString& s); | 46 | void appendLogLine(const QString& s); |
86 | 47 | void appendOutputLine(const QString& s); | ||
87 | 47 | void includeBrowse(); | 48 | void includeBrowse(); |
88 | 48 | void quickRun(int idx); | 49 | void quickRun(int idx); |
89 | 49 | void rowColumnChanged(); | 50 | void rowColumnChanged(); |
90 | 50 | 51 | ||
91 | === modified file 'src/gui/scriptConsole.ui' | |||
92 | --- src/gui/scriptConsole.ui 2012-02-20 10:28:26 +0000 | |||
93 | +++ src/gui/scriptConsole.ui 2014-08-12 09:52:27 +0000 | |||
94 | @@ -17,7 +17,16 @@ | |||
95 | 17 | <property name="spacing"> | 17 | <property name="spacing"> |
96 | 18 | <number>0</number> | 18 | <number>0</number> |
97 | 19 | </property> | 19 | </property> |
99 | 20 | <property name="margin"> | 20 | <property name="leftMargin"> |
100 | 21 | <number>0</number> | ||
101 | 22 | </property> | ||
102 | 23 | <property name="topMargin"> | ||
103 | 24 | <number>0</number> | ||
104 | 25 | </property> | ||
105 | 26 | <property name="rightMargin"> | ||
106 | 27 | <number>0</number> | ||
107 | 28 | </property> | ||
108 | 29 | <property name="bottomMargin"> | ||
109 | 21 | <number>0</number> | 30 | <number>0</number> |
110 | 22 | </property> | 31 | </property> |
111 | 23 | <item> | 32 | <item> |
112 | @@ -139,7 +148,16 @@ | |||
113 | 139 | <property name="spacing"> | 148 | <property name="spacing"> |
114 | 140 | <number>0</number> | 149 | <number>0</number> |
115 | 141 | </property> | 150 | </property> |
117 | 142 | <property name="margin"> | 151 | <property name="leftMargin"> |
118 | 152 | <number>0</number> | ||
119 | 153 | </property> | ||
120 | 154 | <property name="topMargin"> | ||
121 | 155 | <number>0</number> | ||
122 | 156 | </property> | ||
123 | 157 | <property name="rightMargin"> | ||
124 | 158 | <number>0</number> | ||
125 | 159 | </property> | ||
126 | 160 | <property name="bottomMargin"> | ||
127 | 143 | <number>0</number> | 161 | <number>0</number> |
128 | 144 | </property> | 162 | </property> |
129 | 145 | <item> | 163 | <item> |
130 | @@ -220,7 +238,7 @@ | |||
131 | 220 | </size> | 238 | </size> |
132 | 221 | </property> | 239 | </property> |
133 | 222 | <property name="toolTip"> | 240 | <property name="toolTip"> |
135 | 223 | <string>clear script</string> | 241 | <string>clear</string> |
136 | 224 | </property> | 242 | </property> |
137 | 225 | <property name="text"> | 243 | <property name="text"> |
138 | 226 | <string/> | 244 | <string/> |
139 | @@ -372,7 +390,16 @@ | |||
140 | 372 | <string>Script</string> | 390 | <string>Script</string> |
141 | 373 | </attribute> | 391 | </attribute> |
142 | 374 | <layout class="QVBoxLayout" name="verticalLayout_3"> | 392 | <layout class="QVBoxLayout" name="verticalLayout_3"> |
144 | 375 | <property name="margin"> | 393 | <property name="leftMargin"> |
145 | 394 | <number>0</number> | ||
146 | 395 | </property> | ||
147 | 396 | <property name="topMargin"> | ||
148 | 397 | <number>0</number> | ||
149 | 398 | </property> | ||
150 | 399 | <property name="rightMargin"> | ||
151 | 400 | <number>0</number> | ||
152 | 401 | </property> | ||
153 | 402 | <property name="bottomMargin"> | ||
154 | 376 | <number>0</number> | 403 | <number>0</number> |
155 | 377 | </property> | 404 | </property> |
156 | 378 | <item> | 405 | <item> |
157 | @@ -396,12 +423,50 @@ | |||
158 | 396 | </item> | 423 | </item> |
159 | 397 | </layout> | 424 | </layout> |
160 | 398 | </widget> | 425 | </widget> |
161 | 426 | <widget class="QWidget" name="logTab"> | ||
162 | 427 | <attribute name="title"> | ||
163 | 428 | <string>Log</string> | ||
164 | 429 | </attribute> | ||
165 | 430 | <layout class="QVBoxLayout" name="verticalLayout_5"> | ||
166 | 431 | <property name="leftMargin"> | ||
167 | 432 | <number>0</number> | ||
168 | 433 | </property> | ||
169 | 434 | <property name="topMargin"> | ||
170 | 435 | <number>0</number> | ||
171 | 436 | </property> | ||
172 | 437 | <property name="rightMargin"> | ||
173 | 438 | <number>0</number> | ||
174 | 439 | </property> | ||
175 | 440 | <property name="bottomMargin"> | ||
176 | 441 | <number>0</number> | ||
177 | 442 | </property> | ||
178 | 443 | <item> | ||
179 | 444 | <widget class="QTextBrowser" name="logBrowser"> | ||
180 | 445 | <property name="font"> | ||
181 | 446 | <font> | ||
182 | 447 | <family>DejaVu Sans Mono</family> | ||
183 | 448 | <pointsize>8</pointsize> | ||
184 | 449 | </font> | ||
185 | 450 | </property> | ||
186 | 451 | </widget> | ||
187 | 452 | </item> | ||
188 | 453 | </layout> | ||
189 | 454 | </widget> | ||
190 | 399 | <widget class="QWidget" name="outputTab"> | 455 | <widget class="QWidget" name="outputTab"> |
191 | 400 | <attribute name="title"> | 456 | <attribute name="title"> |
192 | 401 | <string>Output</string> | 457 | <string>Output</string> |
193 | 402 | </attribute> | 458 | </attribute> |
194 | 403 | <layout class="QVBoxLayout" name="verticalLayout_4"> | 459 | <layout class="QVBoxLayout" name="verticalLayout_4"> |
196 | 404 | <property name="margin"> | 460 | <property name="leftMargin"> |
197 | 461 | <number>0</number> | ||
198 | 462 | </property> | ||
199 | 463 | <property name="topMargin"> | ||
200 | 464 | <number>0</number> | ||
201 | 465 | </property> | ||
202 | 466 | <property name="rightMargin"> | ||
203 | 467 | <number>0</number> | ||
204 | 468 | </property> | ||
205 | 469 | <property name="bottomMargin"> | ||
206 | 405 | <number>0</number> | 470 | <number>0</number> |
207 | 406 | </property> | 471 | </property> |
208 | 407 | <item> | 472 | <item> |
209 | 408 | 473 | ||
210 | === modified file 'src/main.cpp' | |||
211 | --- src/main.cpp 2014-08-01 18:48:38 +0000 | |||
212 | +++ src/main.cpp 2014-08-12 09:52:27 +0000 | |||
213 | @@ -25,6 +25,9 @@ | |||
214 | 25 | #include "CLIProcessor.hpp" | 25 | #include "CLIProcessor.hpp" |
215 | 26 | #include "StelIniParser.hpp" | 26 | #include "StelIniParser.hpp" |
216 | 27 | #include "StelUtils.hpp" | 27 | #include "StelUtils.hpp" |
217 | 28 | #ifndef DISABLE_SCRIPTING | ||
218 | 29 | #include "StelScriptOutput.hpp" | ||
219 | 30 | #endif | ||
220 | 28 | 31 | ||
221 | 29 | #include <QDebug> | 32 | #include <QDebug> |
222 | 30 | 33 | ||
223 | @@ -289,6 +292,14 @@ | |||
224 | 289 | Q_ASSERT(confSettings); | 292 | Q_ASSERT(confSettings); |
225 | 290 | qDebug() << "Config file is: " << QDir::toNativeSeparators(configFileFullPath); | 293 | qDebug() << "Config file is: " << QDir::toNativeSeparators(configFileFullPath); |
226 | 291 | 294 | ||
227 | 295 | #ifndef DISABLE_SCRIPTING | ||
228 | 296 | QString outputFile = StelFileMgr::getUserDir()+"/output.txt"; | ||
229 | 297 | if (confSettings->value("main/use_separate_output_file", false).toBool()) | ||
230 | 298 | outputFile = StelFileMgr::getUserDir()+"/output-"+QDateTime::currentDateTime().toString("yyyyMMdd-HHmmss")+".txt"; | ||
231 | 299 | StelScriptOutput::init(outputFile); | ||
232 | 300 | #endif | ||
233 | 301 | |||
234 | 302 | |||
235 | 292 | // Override config file values from CLI. | 303 | // Override config file values from CLI. |
236 | 293 | CLIProcessor::parseCLIArgsPostConfig(argList, confSettings); | 304 | CLIProcessor::parseCLIArgsPostConfig(argList, confSettings); |
237 | 294 | 305 | ||
238 | 295 | 306 | ||
239 | === modified file 'src/scripting/StelMainScriptAPI.cpp' | |||
240 | --- src/scripting/StelMainScriptAPI.cpp 2014-01-15 07:13:40 +0000 | |||
241 | +++ src/scripting/StelMainScriptAPI.cpp 2014-08-12 09:52:27 +0000 | |||
242 | @@ -361,34 +361,34 @@ | |||
243 | 361 | } | 361 | } |
244 | 362 | 362 | ||
245 | 363 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, | 363 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, |
251 | 364 | double ra0, double dec0, | 364 | double ra0, double dec0, |
252 | 365 | double ra1, double dec1, | 365 | double ra1, double dec1, |
253 | 366 | double ra2, double dec2, | 366 | double ra2, double dec2, |
254 | 367 | double ra3, double dec3, | 367 | double ra3, double dec3, |
255 | 368 | double minRes, double maxBright, bool visible) | 368 | double minRes, double maxBright, bool visible) |
256 | 369 | { | 369 | { |
257 | 370 | QString path = "scripts/" + filename; | 370 | QString path = "scripts/" + filename; |
258 | 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)); |
259 | 372 | } | 372 | } |
260 | 373 | 373 | ||
261 | 374 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, | 374 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, |
267 | 375 | const QString& ra0, const QString& dec0, | 375 | const QString& ra0, const QString& dec0, |
268 | 376 | const QString& ra1, const QString& dec1, | 376 | const QString& ra1, const QString& dec1, |
269 | 377 | const QString& ra2, const QString& dec2, | 377 | const QString& ra2, const QString& dec2, |
270 | 378 | const QString& ra3, const QString& dec3, | 378 | const QString& ra3, const QString& dec3, |
271 | 379 | double minRes, double maxBright, bool visible) | 379 | double minRes, double maxBright, bool visible) |
272 | 380 | { | 380 | { |
273 | 381 | loadSkyImage(id, filename, | 381 | loadSkyImage(id, filename, |
279 | 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, |
280 | 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, |
281 | 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, |
282 | 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, |
283 | 386 | minRes, maxBright, visible); | 386 | minRes, maxBright, visible); |
284 | 387 | } | 387 | } |
285 | 388 | 388 | ||
286 | 389 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, | 389 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, |
289 | 390 | double ra, double dec, double angSize, double rotation, | 390 | double ra, double dec, double angSize, double rotation, |
290 | 391 | double minRes, double maxBright, bool visible) | 391 | double minRes, double maxBright, bool visible) |
291 | 392 | { | 392 | { |
292 | 393 | Vec3f XYZ; | 393 | Vec3f XYZ; |
293 | 394 | static const float RADIUS_NEB = 1.; | 394 | static const float RADIUS_NEB = 1.; |
294 | @@ -396,15 +396,15 @@ | |||
295 | 396 | XYZ*=RADIUS_NEB; | 396 | XYZ*=RADIUS_NEB; |
296 | 397 | float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180); | 397 | float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180); |
297 | 398 | Mat4f matPrecomp = Mat4f::translation(XYZ) * | 398 | Mat4f matPrecomp = Mat4f::translation(XYZ) * |
301 | 399 | Mat4f::zrotation(ra*M_PI/180.) * | 399 | Mat4f::zrotation(ra*M_PI/180.) * |
302 | 400 | Mat4f::yrotation(-dec*M_PI/180.) * | 400 | Mat4f::yrotation(-dec*M_PI/180.) * |
303 | 401 | Mat4f::xrotation(rotation*M_PI/180.); | 401 | Mat4f::xrotation(rotation*M_PI/180.); |
304 | 402 | 402 | ||
305 | 403 | Vec3f corners[4]; | 403 | Vec3f corners[4]; |
310 | 404 | corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); | 404 | corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); |
311 | 405 | corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); | 405 | corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); |
312 | 406 | corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); | 406 | corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); |
313 | 407 | corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); | 407 | corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); |
314 | 408 | 408 | ||
315 | 409 | // convert back to ra/dec (radians) | 409 | // convert back to ra/dec (radians) |
316 | 410 | Vec3f cornersRaDec[4]; | 410 | Vec3f cornersRaDec[4]; |
317 | @@ -412,38 +412,40 @@ | |||
318 | 412 | StelUtils::rectToSphe(&cornersRaDec[i][0], &cornersRaDec[i][1], corners[i]); | 412 | StelUtils::rectToSphe(&cornersRaDec[i][0], &cornersRaDec[i][1], corners[i]); |
319 | 413 | 413 | ||
320 | 414 | loadSkyImage(id, filename, | 414 | loadSkyImage(id, filename, |
326 | 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, |
327 | 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, |
328 | 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, |
329 | 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, |
330 | 419 | minRes, maxBright, visible); | 419 | minRes, maxBright, visible); |
331 | 420 | } | 420 | } |
332 | 421 | 421 | ||
333 | 422 | 422 | ||
334 | 423 | 423 | ||
335 | 424 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, | 424 | void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, |
338 | 425 | const QString& ra, const QString& dec, double angSize, double rotation, | 425 | const QString& ra, const QString& dec, |
339 | 426 | double minRes, double maxBright, bool visible) | 426 | double angSize, double rotation, |
340 | 427 | double minRes, double maxBright, bool visible) | ||
341 | 427 | { | 428 | { |
342 | 428 | loadSkyImage(id, filename, StelUtils::getDecAngle(ra)*180./M_PI, | 429 | loadSkyImage(id, filename, StelUtils::getDecAngle(ra)*180./M_PI, |
345 | 429 | StelUtils::getDecAngle(dec)*180./M_PI, angSize, | 430 | StelUtils::getDecAngle(dec)*180./M_PI, angSize, |
346 | 430 | rotation, minRes, maxBright, visible); | 431 | rotation, minRes, maxBright, visible); |
347 | 431 | } | 432 | } |
348 | 432 | 433 | ||
349 | 433 | void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename, | 434 | void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename, |
355 | 434 | double alt0, double azi0, | 435 | double alt0, double azi0, |
356 | 435 | double alt1, double azi1, | 436 | double alt1, double azi1, |
357 | 436 | double alt2, double azi2, | 437 | double alt2, double azi2, |
358 | 437 | double alt3, double azi3, | 438 | double alt3, double azi3, |
359 | 438 | double minRes, double maxBright, bool visible) | 439 | double minRes, double maxBright, bool visible) |
360 | 439 | { | 440 | { |
361 | 440 | QString path = "scripts/" + filename; | 441 | QString path = "scripts/" + filename; |
362 | 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)); |
363 | 442 | } | 443 | } |
364 | 443 | 444 | ||
365 | 444 | void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename, | 445 | void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename, |
368 | 445 | double alt, double azi, double angSize, double rotation, | 446 | double alt, double azi, |
369 | 446 | double minRes, double maxBright, bool visible) | 447 | double angSize, double rotation, |
370 | 448 | double minRes, double maxBright, bool visible) | ||
371 | 447 | { | 449 | { |
372 | 448 | Vec3f XYZ; | 450 | Vec3f XYZ; |
373 | 449 | static const float RADIUS_NEB = 1.; | 451 | static const float RADIUS_NEB = 1.; |
374 | @@ -452,15 +454,15 @@ | |||
375 | 452 | XYZ*=RADIUS_NEB; | 454 | XYZ*=RADIUS_NEB; |
376 | 453 | float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180); | 455 | float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180); |
377 | 454 | Mat4f matPrecomp = Mat4f::translation(XYZ) * | 456 | Mat4f matPrecomp = Mat4f::translation(XYZ) * |
381 | 455 | Mat4f::zrotation((180-azi)*M_PI/180.) * | 457 | Mat4f::zrotation((180-azi)*M_PI/180.) * |
382 | 456 | Mat4f::yrotation(-alt*M_PI/180.) * | 458 | Mat4f::yrotation(-alt*M_PI/180.) * |
383 | 457 | Mat4f::xrotation((rotation+90)*M_PI/180.); | 459 | Mat4f::xrotation((rotation+90)*M_PI/180.); |
384 | 458 | 460 | ||
385 | 459 | Vec3f corners[4]; | 461 | Vec3f corners[4]; |
390 | 460 | corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); | 462 | corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); |
391 | 461 | corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); | 463 | corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); |
392 | 462 | corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); | 464 | corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); |
393 | 463 | corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); | 465 | corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); |
394 | 464 | 466 | ||
395 | 465 | // convert back to alt/azi (radians) | 467 | // convert back to alt/azi (radians) |
396 | 466 | Vec3f cornersAltAz[4]; | 468 | Vec3f cornersAltAz[4]; |
397 | @@ -468,11 +470,11 @@ | |||
398 | 468 | StelUtils::rectToSphe(&cornersAltAz[i][0], &cornersAltAz[i][1], corners[i]); | 470 | StelUtils::rectToSphe(&cornersAltAz[i][0], &cornersAltAz[i][1], corners[i]); |
399 | 469 | 471 | ||
400 | 470 | loadSkyImageAltAz(id, filename, | 472 | loadSkyImageAltAz(id, filename, |
406 | 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, |
407 | 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, |
408 | 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, |
409 | 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, |
410 | 475 | minRes, maxBright, visible); | 477 | minRes, maxBright, visible); |
411 | 476 | } | 478 | } |
412 | 477 | 479 | ||
413 | 478 | void StelMainScriptAPI::removeSkyImage(const QString& id) | 480 | void StelMainScriptAPI::removeSkyImage(const QString& id) |
414 | @@ -622,6 +624,11 @@ | |||
415 | 622 | StelApp::getInstance().getScriptMgr().debug(s); | 624 | StelApp::getInstance().getScriptMgr().debug(s); |
416 | 623 | } | 625 | } |
417 | 624 | 626 | ||
418 | 627 | void StelMainScriptAPI::output(const QString &s) | ||
419 | 628 | { | ||
420 | 629 | StelApp::getInstance().getScriptMgr().output(s); | ||
421 | 630 | } | ||
422 | 631 | |||
423 | 625 | double StelMainScriptAPI::jdFromDateString(const QString& dt, const QString& spec) | 632 | double StelMainScriptAPI::jdFromDateString(const QString& dt, const QString& spec) |
424 | 626 | { | 633 | { |
425 | 627 | StelCore *core = StelApp::getInstance().getCore(); | 634 | StelCore *core = StelApp::getInstance().getCore(); |
426 | 628 | 635 | ||
427 | === modified file 'src/scripting/StelMainScriptAPI.hpp' | |||
428 | --- src/scripting/StelMainScriptAPI.hpp 2013-08-04 06:13:29 +0000 | |||
429 | +++ src/scripting/StelMainScriptAPI.hpp 2014-08-12 09:52:27 +0000 | |||
430 | @@ -614,6 +614,10 @@ | |||
431 | 614 | //! @param s the message to be displayed on the console. | 614 | //! @param s the message to be displayed on the console. |
432 | 615 | void debug(const QString& s); | 615 | void debug(const QString& s); |
433 | 616 | 616 | ||
434 | 617 | //! print an output message from script | ||
435 | 618 | //! @param s the message to be displayed on the output file. | ||
436 | 619 | void output(const QString& s); | ||
437 | 620 | |||
438 | 617 | //! Get the current application language. | 621 | //! Get the current application language. |
439 | 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. |
440 | 619 | QString getAppLanguage(); | 623 | QString getAppLanguage(); |
441 | 620 | 624 | ||
442 | === modified file 'src/scripting/StelScriptMgr.cpp' | |||
443 | --- src/scripting/StelScriptMgr.cpp 2014-07-13 05:52:52 +0000 | |||
444 | +++ src/scripting/StelScriptMgr.cpp 2014-08-12 09:52:27 +0000 | |||
445 | @@ -19,6 +19,7 @@ | |||
446 | 19 | */ | 19 | */ |
447 | 20 | 20 | ||
448 | 21 | 21 | ||
449 | 22 | #include "StelScriptOutput.hpp" | ||
450 | 22 | #include "StelScriptMgr.hpp" | 23 | #include "StelScriptMgr.hpp" |
451 | 23 | #include "StelMainScriptAPI.hpp" | 24 | #include "StelMainScriptAPI.hpp" |
452 | 24 | #include "StelModuleMgr.hpp" | 25 | #include "StelModuleMgr.hpp" |
453 | @@ -423,6 +424,12 @@ | |||
454 | 423 | emit(scriptDebug(msg)); | 424 | emit(scriptDebug(msg)); |
455 | 424 | } | 425 | } |
456 | 425 | 426 | ||
457 | 427 | void StelScriptMgr::output(const QString &msg) | ||
458 | 428 | { | ||
459 | 429 | StelScriptOutput::writeLog(msg); | ||
460 | 430 | emit(scriptOutput(msg)); | ||
461 | 431 | } | ||
462 | 432 | |||
463 | 426 | void StelScriptMgr::scriptEnded() | 433 | void StelScriptMgr::scriptEnded() |
464 | 427 | { | 434 | { |
465 | 428 | if (engine.hasUncaughtException()) | 435 | if (engine.hasUncaughtException()) |
466 | 429 | 436 | ||
467 | === modified file 'src/scripting/StelScriptMgr.hpp' | |||
468 | --- src/scripting/StelScriptMgr.hpp 2014-04-10 02:47:02 +0000 | |||
469 | +++ src/scripting/StelScriptMgr.hpp 2014-08-12 09:52:27 +0000 | |||
470 | @@ -136,10 +136,14 @@ | |||
471 | 136 | //! execution rate. | 136 | //! execution rate. |
472 | 137 | double getScriptRate(); | 137 | double getScriptRate(); |
473 | 138 | 138 | ||
475 | 139 | //! cause the emission of the scriptDebug signal. This is so that functions in | 139 | //! cause the emission of the scriptDebug signal. This is so that functions in |
476 | 140 | //! StelMainScriptAPI can explicitly send information to the ScriptConsole | 140 | //! StelMainScriptAPI can explicitly send information to the ScriptConsole |
477 | 141 | void debug(const QString& msg); | 141 | void debug(const QString& msg); |
478 | 142 | 142 | ||
479 | 143 | //! cause the emission of the scriptOutput signal. This is so that functions in | ||
480 | 144 | //! StelMainScriptAPI can explicitly send information to the ScriptConsole | ||
481 | 145 | void output(const QString& msg); | ||
482 | 146 | |||
483 | 143 | //! Pause a running script. | 147 | //! Pause a running script. |
484 | 144 | void pauseScript(); | 148 | void pauseScript(); |
485 | 145 | 149 | ||
486 | @@ -155,7 +159,9 @@ | |||
487 | 155 | //! Notification when a script has stopped running | 159 | //! Notification when a script has stopped running |
488 | 156 | void scriptStopped(); | 160 | void scriptStopped(); |
489 | 157 | //! Notification of a script event - warnings, current execution line etc. | 161 | //! Notification of a script event - warnings, current execution line etc. |
491 | 158 | void scriptDebug(const QString&); | 162 | void scriptDebug(const QString&); |
492 | 163 | //! Notification of a script event - output line. | ||
493 | 164 | void scriptOutput(const QString&); | ||
494 | 159 | 165 | ||
495 | 160 | private: | 166 | private: |
496 | 161 | // Utility functions for preprocessor | 167 | // Utility functions for preprocessor |
497 | 162 | 168 | ||
498 | === added file 'src/scripting/StelScriptOutput.cpp' | |||
499 | --- src/scripting/StelScriptOutput.cpp 1970-01-01 00:00:00 +0000 | |||
500 | +++ src/scripting/StelScriptOutput.cpp 2014-08-12 09:52:27 +0000 | |||
501 | @@ -0,0 +1,44 @@ | |||
502 | 1 | /* | ||
503 | 2 | * Stellarium | ||
504 | 3 | * Copyright (C) 2014 Alexander Wolf | ||
505 | 4 | * | ||
506 | 5 | * This program is free software; you can redistribute it and/or | ||
507 | 6 | * modify it under the terms of the GNU General Public License | ||
508 | 7 | * as published by the Free Software Foundation; either version 2 | ||
509 | 8 | * of the License, or (at your option) any later version. | ||
510 | 9 | * | ||
511 | 10 | * This program is distributed in the hope that it will be useful, | ||
512 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
513 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
514 | 13 | * GNU General Public License for more details. | ||
515 | 14 | * | ||
516 | 15 | * You should have received a copy of the GNU General Public License | ||
517 | 16 | * along with this program; if not, write to the Free Software | ||
518 | 17 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. | ||
519 | 18 | */ | ||
520 | 19 | |||
521 | 20 | #include "StelScriptOutput.hpp" | ||
522 | 21 | #include <QDebug> | ||
523 | 22 | |||
524 | 23 | // Init statics variables. | ||
525 | 24 | QFile StelScriptOutput::outputFile; | ||
526 | 25 | QString StelScriptOutput::outputText; | ||
527 | 26 | |||
528 | 27 | void StelScriptOutput::init(const QString& outputFilePath) | ||
529 | 28 | { | ||
530 | 29 | outputFile.setFileName(outputFilePath); | ||
531 | 30 | if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text | QIODevice::Unbuffered)) | ||
532 | 31 | qDebug() << "ERROR: Cannot open output.txt file"; | ||
533 | 32 | } | ||
534 | 33 | |||
535 | 34 | void StelScriptOutput::deinit() | ||
536 | 35 | { | ||
537 | 36 | outputFile.close(); | ||
538 | 37 | } | ||
539 | 38 | |||
540 | 39 | void StelScriptOutput::writeLog(QString msg) | ||
541 | 40 | { | ||
542 | 41 | msg += "\n"; | ||
543 | 42 | outputFile.write(qPrintable(msg), msg.size()); | ||
544 | 43 | outputText += msg; | ||
545 | 44 | } | ||
546 | 0 | 45 | ||
547 | === added file 'src/scripting/StelScriptOutput.hpp' | |||
548 | --- src/scripting/StelScriptOutput.hpp 1970-01-01 00:00:00 +0000 | |||
549 | +++ src/scripting/StelScriptOutput.hpp 2014-08-12 09:52:27 +0000 | |||
550 | @@ -0,0 +1,50 @@ | |||
551 | 1 | /* | ||
552 | 2 | * Stellarium | ||
553 | 3 | * Copyright (C) 2014 Alexander Wolf | ||
554 | 4 | * | ||
555 | 5 | * This program is free software; you can redistribute it and/or | ||
556 | 6 | * modify it under the terms of the GNU General Public License | ||
557 | 7 | * as published by the Free Software Foundation; either version 2 | ||
558 | 8 | * of the License, or (at your option) any later version. | ||
559 | 9 | * | ||
560 | 10 | * This program is distributed in the hope that it will be useful, | ||
561 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
562 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
563 | 13 | * GNU General Public License for more details. | ||
564 | 14 | * | ||
565 | 15 | * You should have received a copy of the GNU General Public License | ||
566 | 16 | * along with this program; if not, write to the Free Software | ||
567 | 17 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. | ||
568 | 18 | */ | ||
569 | 19 | |||
570 | 20 | #ifndef STELSCRIPTOUTPUT_HPP | ||
571 | 21 | #define STELSCRIPTOUTPUT_HPP | ||
572 | 22 | |||
573 | 23 | #include "config.h" | ||
574 | 24 | |||
575 | 25 | #include <QString> | ||
576 | 26 | #include <QFile> | ||
577 | 27 | |||
578 | 28 | //! @class StelScriptOutput | ||
579 | 29 | //! Class wit only static members used to manage output for Stellarium scripts. | ||
580 | 30 | class StelScriptOutput | ||
581 | 31 | { | ||
582 | 32 | public: | ||
583 | 33 | //! Create and initialize the log file. | ||
584 | 34 | //! Prepend system information before any output. | ||
585 | 35 | static void init(const QString& outputFilePath); | ||
586 | 36 | |||
587 | 37 | //! Deinitialize the output file. | ||
588 | 38 | //! Must be called after init() was called. | ||
589 | 39 | static void deinit(); | ||
590 | 40 | |||
591 | 41 | //! Write the message plus a newline to the output file at $USERDIR/output.txt. | ||
592 | 42 | //! @param msg message to write. | ||
593 | 43 | static void writeLog(QString msg); | ||
594 | 44 | |||
595 | 45 | private: | ||
596 | 46 | static QFile outputFile; | ||
597 | 47 | static QString outputText; | ||
598 | 48 | }; | ||
599 | 49 | |||
600 | 50 | #endif // STELSCRIPTOUTPUT_HPP |
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?