~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to src/stel_ui_tuiconf.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <iomanip>
25
25
#include <string>
26
26
#include "stel_ui.h"
27
 
#include "stellastro.h"
28
 
#include "sky_localizer.h"
 
27
#include "StarMgr.hpp"
 
28
#include "ConstellationMgr.hpp"
 
29
#include "SolarSystem.hpp"
 
30
#include "NebulaMgr.hpp"
 
31
#include "StelApp.hpp"
 
32
#include "StelCore.hpp"
 
33
#include "script_mgr.h"
 
34
#include "stel_command_interface.h"
 
35
#include "LandscapeMgr.hpp"
 
36
#include "GridLinesMgr.hpp"
 
37
#include "MilkyWay.hpp"
 
38
#include "MovementMgr.hpp"
 
39
#include "StelObjectMgr.hpp"
 
40
#include "StelModuleMgr.hpp"
 
41
#include "StelLocaleMgr.hpp"
 
42
#include "StelSkyCultureMgr.hpp"
 
43
#include "Navigator.hpp"
 
44
#include "Observer.hpp"
 
45
#include "StelFileMgr.hpp"
 
46
#include "InitParser.hpp"
 
47
#include <QTextStream>
 
48
#include <QFile>
29
49
 
30
50
// Draw simple gravity text ui.
31
51
void StelUI::draw_gravity_ui(void)
35
55
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
36
56
        glEnable(GL_BLEND);
37
57
 
38
 
        int x = core->getViewportPosX() + core->getViewportWidth()/2;
39
 
        int y = core->getViewportPosY() + core->getViewportHeight()/2;
 
58
        int x = core->getProjection()->getViewportPosX() + core->getProjection()->getViewportWidth()/2;
 
59
        int y = core->getProjection()->getViewportPosY() + core->getProjection()->getViewportHeight()/2;
40
60
        //      int shift = (int)(M_SQRT2 / 2 * MY_MIN(core->getViewportWidth()/2, core->getViewportHeight()/2));
41
 
        int shift = MY_MIN(core->getViewportWidth()/2, core->getViewportHeight()/2);
 
61
        int shift = MY_MIN(core->getProjection()->getViewportWidth()/2, core->getProjection()->getViewportHeight()/2);
42
62
 
43
63
        if (FlagShowTuiDateTime)
44
64
        {
45
 
                double jd = core->getJDay();
46
 
                wostringstream os;
 
65
                double jd = core->getNavigation()->getJDay();
 
66
                
 
67
                QString str;
 
68
                QTextStream os(&str);
47
69
 
48
 
                os << app->get_printable_date_local(jd) << L" " << app->get_printable_time_local(jd);
 
70
                os << QString::fromStdWString(app->getLocaleMgr().get_printable_date_local(jd) + L" " + app->getLocaleMgr().get_printable_time_local(jd));
49
71
 
50
72
                // label location if not on earth
51
 
                if(core->getObservatory().getHomePlanetEnglishName() != "Earth") {
52
 
                        os << L" " << _(core->getObservatory().getHomePlanetEnglishName());
 
73
                if(core->getObservatory()->getHomePlanetEnglishName() != "Earth") {
 
74
                        os << " ";
 
75
                        os << q_(core->getObservatory()->getHomePlanetEnglishName().c_str());
53
76
                }
54
77
 
55
 
                if (FlagShowFov) os << L" fov " << setprecision(3) << core->getFov();
56
 
                if (FlagShowFps) os << L"  FPS " << app->fps;
 
78
                if (FlagShowFov)
 
79
                {
 
80
                        os.setRealNumberPrecision(3);
 
81
                        os << " fov " << core->getProjection()->getFov();
 
82
                }
 
83
                if (FlagShowFps) os << "  FPS " << app->getFps();
57
84
 
58
85
                glColor3f(0.5,1,0.5);
59
 
                core->printGravity(tuiFont, x - shift + 38, y - 38, os.str(), 0);
 
86
                core->getProjection()->drawText(tuiFont, x - shift + 38, y - 38, str.toStdWString(), 0, 0, 0, false);
60
87
        }
61
88
 
62
 
        if (core->getFlagHasSelected() && FlagShowTuiShortObjInfo)
 
89
        if (app->getStelObjectMgr().getWasSelected() && FlagShowTuiShortObjInfo)
63
90
        {
64
 
            wstring info = core->getSelectedObjectShortInfo();
65
 
                glColor3fv(core->getSelectedObjectInfoColor());
66
 
                core->printGravity(tuiFont, x + shift - 38, 
67
 
                                                   y + 38, info, 0);
 
91
            wstring info = app->getStelObjectMgr().getSelectedObject()[0]->getShortInfoString(core->getNavigation());
 
92
                glColor3fv(app->getStelObjectMgr().getSelectedObject()[0]->getInfoColor());
 
93
                core->getProjection()->drawText(tuiFont, x + shift - 38, y + 38, info, 0, 0, 0, false);
68
94
        }
69
95
}
70
96
 
73
99
// since lose states - try localizeTui() instead
74
100
void StelUI::init_tui(void)
75
101
{
 
102
        LandscapeMgr* lmgr = (LandscapeMgr*)app->getModuleMgr().getModule("LandscapeMgr");
 
103
        
76
104
        // Menu root branch
77
105
        ScriptDirectoryRead = 0;
78
106
 
79
107
        // If already initialized before, delete existing objects
80
108
        if(tui_root) delete tui_root;
81
 
        if(tuiFont) delete tuiFont;
82
 
 
83
 
        // Load standard font based on app locale
84
 
        string fontFile, tmpstr;
85
 
        float fontScale, tmpfloat;
86
 
 
87
 
        core->getFontForLocale(app->getAppLanguage(), fontFile, fontScale, tmpstr, tmpfloat);
88
 
 
89
 
        tuiFont = new s_font(BaseFontSize*fontScale, fontFile);
90
 
        if (!tuiFont)
91
 
        {
92
 
                printf("ERROR WHILE CREATING FONT\n");
93
 
                exit(-1);
94
 
        }
95
 
 
96
109
        tui_root = new s_tui::Branch();
97
110
 
98
111
        // Submenus
122
135
        tui_location_altitude = new s_tui::Integer_item(-500, 10000, 0,wstring(L"1.3 ") );
123
136
        tui_location_altitude->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_setlocation));
124
137
 
125
 
        // experimental
 
138
        // Home planet only changed if hit enter to accept because
 
139
        // switching planet instantaneously as select is hard on a planetarium audience
126
140
        tui_location_planet = new s_tui::MultiSet2_item<wstring>(wstring(L"1.4 ") );
127
 
        tui_location_planet->addItemList(core->getPlanetHashString());
128
 
        tui_location_planet->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_location_change_planet));
 
141
        SolarSystem* ssmgr = (SolarSystem*)app->getModuleMgr().getModule("SolarSystem");
 
142
        tui_location_planet->addItemList(ssmgr->getPlanetHashString());
 
143
        //      tui_location_planet->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_location_change_planet));
 
144
        tui_location_planet->set_OnTriggerCallback(callback<void>(this, &StelUI::tui_cb_location_change_planet));
129
145
 
130
146
        tui_menu_location->addComponent(tui_location_latitude);
131
147
        tui_menu_location->addComponent(tui_location_longitude);
135
151
        // 2. Time
136
152
        tui_time_skytime = new s_tui::Time_item(wstring(L"2.1 ") );
137
153
        tui_time_skytime->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_sky_time));
138
 
        tui_time_settmz = new s_tui::Time_zone_item(core->getDataDir() + "zone.tab", wstring(L"2.2 ") );
 
154
        try
 
155
        {
 
156
                tui_time_settmz = new s_tui::Time_zone_item(QFile::encodeName(app->getFileMgr().findFile("data/zone.tab")).constData(), wstring(L"2.2 "));
 
157
        }
 
158
        catch(exception &e)
 
159
        {
 
160
                cerr << "ERROR locating zone file: " << e.what() << endl;
 
161
        }
139
162
        tui_time_settmz->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_settimezone));
140
 
        tui_time_settmz->settz(app->get_custom_tz_name());
 
163
        tui_time_settmz->settz(app->getLocaleMgr().get_custom_tz_name());
 
164
 
 
165
        tui_time_day_key = new s_tui::MultiSet2_item<wstring>(wstring(L"2.2 ") );
 
166
        tui_time_day_key->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_day_key));
 
167
 
141
168
        tui_time_presetskytime = new s_tui::Time_item(wstring(L"2.3 ") );
142
169
        tui_time_presetskytime->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb1));
143
170
        tui_time_startuptime = new s_tui::MultiSet2_item<wstring>(wstring(L"2.4 ") );
156
183
 
157
184
        tui_menu_time->addComponent(tui_time_skytime);
158
185
        tui_menu_time->addComponent(tui_time_settmz);
 
186
        tui_menu_time->addComponent(tui_time_day_key);
159
187
        tui_menu_time->addComponent(tui_time_presetskytime);
160
188
        tui_menu_time->addComponent(tui_time_startuptime);
161
189
        tui_menu_time->addComponent(tui_time_displayformat);
169
197
        tui_menu_general->addComponent(tui_general_sky_culture);
170
198
 
171
199
        tui_general_sky_locale = new s_tui::MultiSet_item<wstring>(wstring(L"3.2 ") );
172
 
        tui_general_sky_locale->addItemList(StelUtility::stringToWstring(Translator::getAvailableLanguagesCodes(core->getLocaleDir())));
 
200
        tui_general_sky_locale->addItemList(Translator::getAvailableLanguagesNamesNative(app->getFileMgr().getLocaleDir()).toStdWString());
173
201
 
174
202
        tui_general_sky_locale->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_tui_general_change_sky_locale));
175
203
        tui_menu_general->addComponent(tui_general_sky_locale);
178
206
        // 4. Stars
179
207
        tui_stars_show = new s_tui::Boolean_item(false, wstring(L"4.1 ") );
180
208
        tui_stars_show->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_stars));
181
 
        tui_star_magscale = new s_tui::Decimal_item(1,30, 1, wstring(L"4.2 ") );
 
209
        tui_star_magscale = new s_tui::Decimal_item(0,30, 1, wstring(L"4.2 "), 0.1 );
182
210
        tui_star_magscale->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_stars));
183
211
        tui_star_labelmaxmag = new s_tui::Decimal_item(-1.5, 10., 2, wstring(L"4.3 ") );
184
212
        tui_star_labelmaxmag->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_stars));
185
213
        tui_stars_twinkle = new s_tui::Decimal_item(0., 1., 0.3, wstring(L"4.4 "), 0.1);
186
214
        tui_stars_twinkle->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_stars));
 
215
//      tui_star_limitingmag = new s_tui::Decimal_item(0., 7., 6.5, wstring(L"4.5 "), 0.1);
 
216
//      tui_star_limitingmag->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_stars));
187
217
 
188
218
        tui_menu_stars->addComponent(tui_stars_show);
189
219
        tui_menu_stars->addComponent(tui_star_magscale);
190
220
        tui_menu_stars->addComponent(tui_star_labelmaxmag);
191
221
        tui_menu_stars->addComponent(tui_stars_twinkle);
 
222
// TODO tui_menu_stars->addComponent(tui_star_limitingmag);
 
223
 
192
224
 
193
225
        // 5. Colors
194
226
        tui_colors_const_line_color = new s_tui::Vector_item(wstring(L"5.1 "));
253
285
 
254
286
 
255
287
        // 5. Effects
 
288
        tui_effect_light_pollution = new s_tui::Decimal_item(0, 30, 1, wstring(L"5.9 "), 0.1 );
 
289
        tui_effect_light_pollution->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_effects));
 
290
        tui_menu_effects->addComponent(tui_effect_light_pollution);
 
291
 
256
292
        tui_effect_landscape = new s_tui::MultiSet_item<wstring>(wstring(L"5.1 ") );
257
 
        tui_effect_landscape->addItemList(StelUtility::stringToWstring(Landscape::get_file_content(core->getDataDir() + "landscapes.ini")));
 
293
        tui_effect_landscape->addItemList(lmgr->getAllLandscapeNames().toStdWString());
258
294
 
259
295
        tui_effect_landscape->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_tui_effect_change_landscape));
260
296
        tui_menu_effects->addComponent(tui_effect_landscape);
267
303
        tui_effect_pointobj->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_effects));
268
304
        tui_menu_effects->addComponent(tui_effect_pointobj);
269
305
 
270
 
        tui_effect_object_scale = new s_tui::Decimal_item(0, 25, 1, wstring(L"5.4 ") + _("Magnitude Sizing Multiplier: "), 0.1);
 
306
        tui_effect_object_scale = new s_tui::Decimal_item(0, 25, 1, wstring(L"5.4 "), 0.05);
271
307
        tui_effect_object_scale->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_effects));
272
308
        tui_menu_effects->addComponent(tui_effect_object_scale);
273
309
 
274
 
        tui_effect_milkyway_intensity = new s_tui::Decimal_item(0, 100, 1, wstring(L"5.5 "), .5);
 
310
        tui_effect_milkyway_intensity = new s_tui::Decimal_item(0, 100, 1, wstring(L"5.5 "), .1);
275
311
        tui_effect_milkyway_intensity->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_effects_milkyway_intensity));
276
312
        tui_menu_effects->addComponent(tui_effect_milkyway_intensity);
277
313
 
287
323
        tui_effect_cursor_timeout->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_effects));
288
324
        tui_menu_effects->addComponent(tui_effect_cursor_timeout);
289
325
 
 
326
        tui_effect_landscape_sets_location = new s_tui::Boolean_item(lmgr->getFlagLandscapeSetsLocation(), wstring(L"6.10 "));
 
327
        tui_effect_landscape_sets_location->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_effects));
 
328
        tui_menu_effects->addComponent(tui_effect_landscape_sets_location);
290
329
 
 
330
        
291
331
        // 6. Scripts
292
332
        tui_scripts_local = new s_tui::MultiSet_item<wstring>(wstring(L"6.1 ") );
293
333
        //      tui_scripts_local->addItemList(wstring(TUI_SCRIPT_MSG) + wstring(L"\n") 
294
 
        //                             + StelUtility::stringToWstring(app->scripts->get_script_list(core->getDataDir() + "scripts/"))); 
 
334
        //                             + StelUtils::stringToWstring(scripts->get_script_list(core->getDataDir() + "scripts/"))); 
295
335
        tui_scripts_local->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_scripts_local));
296
336
        tui_menu_scripts->addComponent(tui_scripts_local);
297
337
 
306
346
        tui_admin_loaddefault->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_admin_load_default));
307
347
        tui_admin_savedefault = new s_tui::ActionConfirm_item(wstring(L"7.2 ") );
308
348
        tui_admin_savedefault->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_admin_save_default));
309
 
        tui_admin_updateme = new s_tui::Action_item(wstring(L"7.3 ") );
 
349
        tui_admin_shutdown = new s_tui::ActionConfirm_item(wstring(L"7.3 ") );
 
350
        tui_admin_shutdown->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_admin_shutdown));
 
351
        tui_admin_updateme = new s_tui::ActionConfirm_item(wstring(L"7.4 ") );
310
352
        tui_admin_updateme->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_admin_updateme));
311
353
        tui_menu_administration->addComponent(tui_admin_loaddefault);
312
354
        tui_menu_administration->addComponent(tui_admin_savedefault);
 
355
        tui_menu_administration->addComponent(tui_admin_shutdown);
313
356
        tui_menu_administration->addComponent(tui_admin_updateme);
314
357
 
315
 
        tui_admin_setlocale = new s_tui::MultiSet_item<wstring>(L"7.4 ");
316
 
        tui_admin_setlocale->addItemList(StelUtility::stringToWstring(Translator::getAvailableLanguagesCodes(core->getLocaleDir())));
 
358
        tui_admin_setlocale = new s_tui::MultiSet_item<wstring>(L"7.5 ");
 
359
        tui_admin_setlocale->addItemList(Translator::getAvailableLanguagesNamesNative(app->getFileMgr().getLocaleDir()).toStdWString());
317
360
        tui_admin_setlocale->set_OnChangeCallback(callback<void>(this, &StelUI::tui_cb_admin_set_locale));
318
361
        tui_menu_administration->addComponent(tui_admin_setlocale);
319
362
 
325
368
// Update fonts, labels and lists for a new app locale
326
369
void StelUI::localizeTui(void)
327
370
{
328
 
 
329
 
        cout << "Localizing TUI for locale: " << app->getAppLanguage() << endl;
330
 
        if(tuiFont) delete tuiFont;
331
 
 
332
 
        // Load standard font based on app locale
333
 
        string fontFile, tmpstr;
334
 
        float fontScale, tmpfloat;
335
 
 
336
 
        core->getFontForLocale(app->getAppLanguage(), fontFile, fontScale, tmpstr, tmpfloat);
337
 
 
338
 
        tuiFont = new s_font(BaseFontSize*fontScale, fontFile);
339
 
        if (!tuiFont)
340
 
        {
341
 
                printf("ERROR WHILE CREATING FONT\n");
342
 
                exit(-1);
343
 
        }
 
371
        ScriptMgr* scripts = (ScriptMgr*)StelApp::getInstance().getModuleMgr().getModule("ScriptMgr");
 
372
        
 
373
        cout << "Localizing TUI for locale: " << qPrintable(app->getLocaleMgr().getAppLanguage()) << endl;
344
374
 
345
375
        if(!tui_root) return;  // not initialized yet
346
376
 
358
388
        tui_location_longitude->setLabel(wstring(L"1.2 ") + _("Longitude: "));
359
389
        tui_location_altitude->setLabel(wstring(L"1.3 ") + _("Altitude (m): "));
360
390
        tui_location_planet->setLabel(wstring(L"1.4 ") + _("Solar System Body: "));
361
 
        tui_location_planet->replaceItemList(core->getPlanetHashString(),0);
 
391
        SolarSystem* ssmgr = (SolarSystem*)app->getModuleMgr().getModule("SolarSystem");
 
392
        tui_location_planet->replaceItemList(ssmgr->getPlanetHashString(),0);
362
393
 
363
394
        // 2. Time
364
395
        tui_time_skytime->setLabel(wstring(L"2.1 ") + _("Sky Time: "));
365
396
        tui_time_settmz->setLabel(wstring(L"2.2 ") + _("Set Time Zone: "));
366
 
        tui_time_presetskytime->setLabel(wstring(L"2.3 ") + _("Preset Sky Time: "));
367
 
        tui_time_startuptime->setLabel(wstring(L"2.4 ") + _("Sky Time At Start-up: "));
 
397
        tui_time_day_key->setLabel(wstring(L"2.3 ") + _("Day keys: "));
 
398
        tui_time_day_key->replaceItemList(_("Calendar") + wstring(L"\ncalendar\n") 
 
399
                                          + _("Sidereal") + wstring(L"\nsidereal\n"), 0);
 
400
        tui_time_presetskytime->setLabel(wstring(L"2.4 ") + _("Preset Sky Time: "));
 
401
        tui_time_startuptime->setLabel(wstring(L"2.5 ") + _("Sky Time At Start-up: "));
368
402
        tui_time_startuptime->replaceItemList(_("Actual Time") + wstring(L"\nActual\n") 
369
403
                                                                                  + _("Preset Time") + wstring(L"\nPreset\n"), 0);
370
 
        tui_time_displayformat->setLabel(wstring(L"2.5 ") + _("Time Display Format: "));
371
 
        tui_time_dateformat->setLabel(wstring(L"2.6 ") + _("Date Display Format: "));
 
404
        tui_time_displayformat->setLabel(wstring(L"2.6 ") + _("Time Display Format: "));
 
405
        tui_time_dateformat->setLabel(wstring(L"2.7 ") + _("Date Display Format: "));
372
406
 
373
407
        // 3. General settings
374
408
 
375
409
        // sky culture goes here
376
410
        tui_general_sky_culture->setLabel(wstring(L"3.1 ") + _("Sky Culture: "));
377
 
        tui_general_sky_culture->replaceItemList(core->getSkyCultureHash(), 0);  // human readable names
 
411
        tui_general_sky_culture->replaceItemList(app->getSkyCultureMgr().getSkyCultureHash(), 0);  // human readable names
378
412
        // wcout << "sky culture list is: " << core->getSkyCultureHash() << endl;
379
413
 
380
414
        tui_general_sky_locale->setLabel(wstring(L"3.2 ") + _("Sky Language: "));
381
415
 
382
416
        // 4. Stars
383
417
        tui_stars_show->setLabel(wstring(L"4.1 ") + _("Show: "), _("Yes"),_("No"));
384
 
        tui_star_magscale->setLabel(wstring(L"4.2 ") + _("Star Magnitude Multiplier: "));
 
418
        tui_star_magscale->setLabel(wstring(L"4.2 ") + _("Star Value Multiplier: "));
385
419
        tui_star_labelmaxmag->setLabel(wstring(L"4.3 ") + _("Maximum Magnitude to Label: "));
386
420
        tui_stars_twinkle->setLabel(wstring(L"4.4 ") + _("Twinkling: "));
 
421
        //tui_star_limitingmag->setLabel(wstring(L"4.5 ") + _("Limiting Magnitude: "));
387
422
 
388
423
        // 5. Colors
389
424
        tui_colors_const_line_color->setLabel(wstring(L"5.1 ") + _("Constellation Lines") + L": ");
390
425
        tui_colors_const_label_color->setLabel(wstring(L"5.2 ") + _("Constellation Names")+L": ");
391
426
        tui_colors_const_art_intensity->setLabel(wstring(L"5.3 ") + _("Constellation Art Intensity") + L": ");
392
427
        tui_colors_const_boundary_color->setLabel(wstring(L"5.4 ") + _("Constellation Boundaries") + L": ");
393
 
        tui_colors_cardinal_color->setLabel(wstring(L"5.5 ") + _("Cardinal Points")+L": " + L": ");
 
428
        tui_colors_cardinal_color->setLabel(wstring(L"5.5 ") + _("Cardinal Points")+ L": ");
394
429
        tui_colors_planet_names_color->setLabel(wstring(L"5.6 ") + _("Planet Names") + L": ");
395
430
        tui_colors_planet_orbits_color->setLabel(wstring(L"5.7 ") + _("Planet Orbits") + L": ");
396
431
        tui_colors_object_trails_color->setLabel(wstring(L"5.8 ") + _("Planet Trails") + L": ");
404
439
 
405
440
 
406
441
        // 6. Effects
407
 
        tui_effect_landscape->setLabel(wstring(L"6.1 ") + _("Landscape: "));
408
 
        tui_effect_manual_zoom->setLabel(wstring(L"6.2 ") + _("Manual zoom: "), _("Yes"),_("No"));
409
 
        tui_effect_pointobj->setLabel(wstring(L"6.3 ") + _("Object Sizing Rule: "), _("Point"),_("Magnitude"));
410
 
        tui_effect_object_scale->setLabel(wstring(L"6.4 ") + _("Magnitude Sizing Multiplier: "));
411
 
        tui_effect_milkyway_intensity->setLabel(wstring(L"6.5 ") + _("Milky Way intensity: "));
412
 
        tui_effect_nebulae_label_magnitude->setLabel(wstring(L"6.6 ") + _("Maximum Nebula Magnitude to Label: "));
413
 
        tui_effect_zoom_duration->setLabel(wstring(L"6.7 ") + _("Zoom Duration: "));
414
 
        tui_effect_cursor_timeout->setLabel(wstring(L"6.8 ") + _("Cursor Timeout: "));
 
442
        tui_effect_light_pollution->setLabel(wstring(L"6.1 ") + _("Light Pollution Luminance: "));
 
443
        tui_effect_landscape->setLabel(wstring(L"6.2 ") + _("Landscape: "));
 
444
        tui_effect_manual_zoom->setLabel(wstring(L"6.3 ") + _("Manual zoom: "), _("Yes"),_("No"));
 
445
        tui_effect_pointobj->setLabel(wstring(L"6.4 ") + _("Object Sizing Rule: "), _("Point"),_("Magnitude"));
 
446
        tui_effect_object_scale->setLabel(wstring(L"6.5 ") + _("Magnitude Scaling Multiplier: "));
 
447
        tui_effect_milkyway_intensity->setLabel(wstring(L"6.6 ") + _("Milky Way intensity: "));
 
448
        tui_effect_nebulae_label_magnitude->setLabel(wstring(L"6.7 ") + _("Maximum Nebula Magnitude to Label: "));
 
449
        tui_effect_zoom_duration->setLabel(wstring(L"6.8 ") + _("Zoom Duration: "));
 
450
        tui_effect_cursor_timeout->setLabel(wstring(L"6.9 ") + _("Cursor Timeout: "));
 
451
        tui_effect_landscape_sets_location->setLabel(wstring(L"6.10 ") + _("Setting Landscape Sets Location: "), _("Yes"),_("No"));
415
452
 
416
453
        // 7. Scripts
417
454
        tui_scripts_local->setLabel(wstring(L"7.1 ") + _("Local Script: "));
418
455
        tui_scripts_local->replaceItemList(_(TUI_SCRIPT_MSG) + wstring(L"\n") 
419
 
                                                                           + StelUtility::stringToWstring(app->scripts->get_script_list(core->getDataDir() + "scripts/")), 0); 
 
456
                        + StelUtils::stringToWstring(scripts->get_script_list("scripts")), 0); 
420
457
        tui_scripts_removeable->setLabel(wstring(L"7.2 ") + _("CD/DVD Script: "));
421
458
        tui_scripts_removeable->replaceItemList(_(TUI_SCRIPT_MSG), 0);
422
459
 
423
460
        // 8. Administration
424
461
        tui_admin_loaddefault->setLabel(wstring(L"8.1 ") + _("Load Default Configuration: "));
425
462
        tui_admin_savedefault->setLabel(wstring(L"8.2 ") + _("Save Current Configuration as Default: "));
426
 
        tui_admin_updateme->setLabel(wstring(L"8.3 ") + _("Update me via Internet: "));
427
 
        tui_admin_setlocale->setLabel(wstring(L"8.4 ") + _("Set UI Locale: "));
 
463
        tui_admin_shutdown->setLabel(wstring(L"8.3 ") + _("Shut Down: "));
 
464
        tui_admin_updateme->setLabel(wstring(L"8.4 ") + _("Update me via Internet: "));
 
465
        tui_admin_setlocale->setLabel(wstring(L"8.5 ") + _("Set UI Locale: "));
428
466
}
429
467
 
430
468
 
437
475
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
438
476
        glEnable(GL_BLEND);
439
477
        
440
 
        int x = core->getViewportPosX() + core->getViewportWidth()/2;
441
 
        int y = core->getViewportPosY() + core->getViewportHeight()/2;
442
 
        int shift = (int)(M_SQRT2 / 2 * MY_MIN(core->getViewportWidth()/2, core->getViewportHeight()/2));
 
478
        int x = core->getProjection()->getViewportPosX() + core->getProjection()->getViewportWidth()/2;
 
479
        int y = core->getProjection()->getViewportPosY() + core->getProjection()->getViewportHeight()/2;
 
480
        int shift = (int)(M_SQRT2 / 2 * MY_MIN(core->getProjection()->getViewportWidth()/2, core->getProjection()->getViewportHeight()/2));
443
481
        
444
 
        if(!core->getFlagGravityLabels()) {
 
482
        if(!core->getProjection()->getFlagGravityLabels()) {
445
483
                // for horizontal tui move to left edge of screen kludge
446
484
                shift = 0;
447
 
                x = core->getViewportPosX() + int(0.1*core->getViewportWidth());
448
 
                y = core->getViewportPosY() + int(0.1*core->getViewportHeight());
 
485
                x = core->getProjection()->getViewportPosX() + int(0.1*core->getProjection()->getViewportWidth());
 
486
                y = core->getProjection()->getViewportPosY() + int(0.1*core->getProjection()->getViewportHeight());
449
487
        }
450
488
 
451
489
        if (tui_root)
452
490
        {
453
491
                glColor3f(0.5,1,0.5);
454
 
                core->printGravity(tuiFont, x+shift - 30, y-shift + 38, s_tui::stop_active + tui_root->getString(), 0);
 
492
                core->getProjection()->drawText(tuiFont, x+shift - 30, y-shift + 38, s_tui::stop_active + tui_root->getString(), 0, 0, 0, false);
455
493
        }
456
494
}
457
495
 
458
 
int StelUI::handle_keys_tui(Uint16 key, s_tui::S_TUI_VALUE state)
 
496
int StelUI::handle_keys_tui(Uint16 key, Uint8 state)
459
497
{
460
 
        return tui_root->onKey(key, state);
 
498
        if (!FlagShowTuiMenu)
 
499
        {
 
500
                return 0;
 
501
        }
 
502
        if (state==Stel_KEYDOWN && key=='m')
 
503
        {
 
504
                // leave tui menu
 
505
                FlagShowTuiMenu = false;
 
506
 
 
507
                // If selected a script in tui, run that now
 
508
                if(SelectedScript!="")
 
509
                {
 
510
                        // build up a command string
 
511
                        string cmd;
 
512
                        if (SelectedScriptDirectory!="")
 
513
                                cmd = "script action play filename \"" +  SelectedScript + "\" path \"" + SelectedScriptDirectory + "/scripts/\"";
 
514
                        else
 
515
                        {
 
516
                                try
 
517
                                {
 
518
                                        QString theParent = app->getFileMgr().findFile(QString("scripts/") + SelectedScript.c_str());
 
519
                                        theParent = app->getFileMgr().dirName(theParent);
 
520
                                        cmd = "script action play filename \"" + SelectedScript 
 
521
                                                + "\" path \"" + QFile::encodeName(theParent).constData() + "/\"";
 
522
                                }
 
523
                                catch(exception& e)
 
524
                                {
 
525
                                        cerr << "ERROR while executing script " << SelectedScript << ": " << e.what() << endl;
 
526
                                }
 
527
                        }
 
528
                        
 
529
                        // now execute the command
 
530
                        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
 
531
                        if ( cmd != "" )
 
532
                                commander->execute_command(cmd);
 
533
                        else
 
534
                                cerr << "ERROR while executing script" << endl;
 
535
                }
 
536
 
 
537
                // clear out now
 
538
                SelectedScriptDirectory = SelectedScript = "";
 
539
                return 1;
 
540
        }
 
541
        tui_root->onKey(key, state);
 
542
        return 1;
461
543
}
462
544
 
463
545
// Update all the core parameters with values taken from the tui widgets
464
546
void StelUI::tui_cb1(void)
465
547
{
466
548
        // 2. Date & Time
467
 
        app->PresetSkyTime              = tui_time_presetskytime->getJDay();
468
 
        app->StartupTimeMode            = StelUtility::wstringToString(tui_time_startuptime->getCurrent());
469
 
 
 
549
        core->getNavigation()->setPresetSkyTime(tui_time_presetskytime->getJDay());
 
550
        core->getNavigation()->setStartupTimeMode(StelUtils::wstringToString(tui_time_startuptime->getCurrent()));
470
551
}
471
552
 
472
553
// Update all the tui widgets with values taken from the core parameters
473
554
void StelUI::tui_update_widgets(void)
474
555
{
 
556
        if (!initialised)
 
557
                return;
 
558
 
475
559
        if (!FlagShowTuiMenu) return;
476
560
        
 
561
        StarMgr* smgr = (StarMgr*)app->getModuleMgr().getModule("StarMgr");
 
562
        ConstellationMgr* cmgr = (ConstellationMgr*)app->getModuleMgr().getModule("ConstellationMgr");
 
563
        NebulaMgr* nmgr = (NebulaMgr*)app->getModuleMgr().getModule("NebulaMgr");
 
564
        SolarSystem* ssmgr = (SolarSystem*)app->getModuleMgr().getModule("SolarSystem");
 
565
        MilkyWay* mw = (MilkyWay*)app->getModuleMgr().getModule("MilkyWay");
 
566
        LandscapeMgr* lmgr = (LandscapeMgr*)app->getModuleMgr().getModule("LandscapeMgr");
 
567
        GridLinesMgr* grlmgr = (GridLinesMgr*)app->getModuleMgr().getModule("GridLinesMgr");
 
568
        MovementMgr* mvmgr = (MovementMgr*)app->getModuleMgr().getModule("MovementMgr");
 
569
        
477
570
        // 1. Location
478
 
        tui_location_latitude->setValue(core->getObservatory().get_latitude());
479
 
        tui_location_longitude->setValue(core->getObservatory().get_longitude());
480
 
        tui_location_altitude->setValue(core->getObservatory().get_altitude());
481
 
        tui_location_planet->setValue(StelUtility::stringToWstring(core->getObservatory().getHomePlanetEnglishName()));
 
571
        tui_location_latitude->setValue(core->getObservatory()->get_latitude());
 
572
        tui_location_longitude->setValue(core->getObservatory()->get_longitude());
 
573
        tui_location_altitude->setValue(core->getObservatory()->get_altitude());
 
574
 
482
575
 
483
576
        // 2. Date & Time
484
 
        tui_time_skytime->setJDay(core->getJDay() + app->get_GMT_shift(core->getJDay())*JD_HOUR);
485
 
        tui_time_settmz->settz(app->get_custom_tz_name());
486
 
        tui_time_presetskytime->setJDay(app->PresetSkyTime);
487
 
        tui_time_startuptime->setCurrent(StelUtility::stringToWstring(app->StartupTimeMode));
488
 
        tui_time_displayformat->setCurrent(StelUtility::stringToWstring(app->get_time_format_str()));
489
 
        tui_time_dateformat->setCurrent(StelUtility::stringToWstring(app->get_date_format_str()));
 
577
        tui_time_skytime->setJDay(core->getNavigation()->getJDay() + app->getLocaleMgr().get_GMT_shift(core->getNavigation()->getJDay())*JD_HOUR);
 
578
        tui_time_settmz->settz(app->getLocaleMgr().get_custom_tz_name());
 
579
        tui_time_day_key->setCurrent(StelUtils::stringToWstring(getDayKeyMode()));
 
580
        tui_time_presetskytime->setJDay(core->getNavigation()->getPresetSkyTime());
 
581
        tui_time_startuptime->setCurrent(StelUtils::stringToWstring(core->getNavigation()->getStartupTimeMode()));
 
582
        tui_time_displayformat->setCurrent(StelUtils::stringToWstring(app->getLocaleMgr().get_time_format_str()));
 
583
        tui_time_dateformat->setCurrent(StelUtils::stringToWstring(app->getLocaleMgr().get_date_format_str()));
490
584
 
491
585
        // 3. general
492
 
        tui_general_sky_culture->setValue(StelUtility::stringToWstring(core->getSkyCultureDir()));
493
 
        tui_general_sky_locale->setValue(StelUtility::stringToWstring(core->getSkyLanguage()));
 
586
        tui_general_sky_culture->setValue(app->getSkyCultureMgr().getSkyCultureDir().toStdWString());
 
587
        tui_general_sky_locale->setValue(app->getLocaleMgr().getSkyLanguage().toStdWString());
494
588
 
495
589
        // 4. Stars
496
 
        tui_stars_show->setValue(core->getFlagStars());
497
 
        tui_star_labelmaxmag->setValue(core->getMaxMagStarName());
498
 
        tui_stars_twinkle->setValue(core->getStarTwinkleAmount());
499
 
        tui_star_magscale->setValue(core->getStarMagScale());
 
590
        tui_stars_show->setValue(smgr->getFlagStars());
 
591
        tui_star_labelmaxmag->setValue(smgr->getMaxMagName());
 
592
        tui_stars_twinkle->setValue(smgr->getTwinkleAmount());
 
593
        tui_star_magscale->setValue(smgr->getMagScale());
 
594
// TODO tui_star_limitingmag->setValue(core->getStarLimitingMag());
 
595
 
500
596
 
501
597
        // 5. Colors
502
 
        tui_colors_const_line_color->setVector(core->getColorConstellationLine());
503
 
        tui_colors_const_label_color->setVector(core->getColorConstellationNames());
504
 
        tui_colors_cardinal_color->setVector(core->getColorCardinalPoints());
505
 
        tui_colors_const_art_intensity->setValue(core->getConstellationArtIntensity());
506
 
        tui_colors_const_boundary_color->setVector(core->getColorConstellationBoundaries());
507
 
        tui_colors_planet_names_color->setVector(core->getColorPlanetsNames());
508
 
        tui_colors_planet_orbits_color->setVector(core->getColorPlanetsOrbits());
509
 
        tui_colors_object_trails_color->setVector(core->getColorPlanetsTrails());
510
 
        tui_colors_meridian_color->setVector(core->getColorMeridianLine());
511
 
        tui_colors_azimuthal_color->setVector(core->getColorAzimutalGrid());
512
 
        tui_colors_equatorial_color->setVector(core->getColorEquatorGrid());
513
 
        tui_colors_equator_color->setVector(core->getColorEquatorLine());
514
 
        tui_colors_ecliptic_color->setVector(core->getColorEclipticLine());
515
 
        tui_colors_nebula_label_color->setVector(core->getColorNebulaLabels());
516
 
        tui_colors_nebula_circle_color->setVector(core->getColorNebulaCircle());
 
598
        tui_colors_const_line_color->setVector(cmgr->getLinesColor());
 
599
        tui_colors_const_label_color->setVector(cmgr->getNamesColor());
 
600
        tui_colors_const_art_intensity->setValue(cmgr->getArtIntensity());
 
601
        tui_colors_const_boundary_color->setVector(cmgr->getBoundariesColor());
 
602
        tui_colors_cardinal_color->setVector(lmgr->getColorCardinalPoints());
 
603
        tui_colors_planet_names_color->setVector(ssmgr->getNamesColor());
 
604
        tui_colors_planet_orbits_color->setVector(ssmgr->getOrbitsColor());
 
605
        tui_colors_object_trails_color->setVector(ssmgr->getTrailsColor());
 
606
        tui_colors_meridian_color->setVector(grlmgr->getColorMeridianLine());
 
607
        tui_colors_azimuthal_color->setVector(grlmgr->getColorAzimutalGrid());
 
608
        tui_colors_equatorial_color->setVector(grlmgr->getColorEquatorGrid());
 
609
        tui_colors_equator_color->setVector(grlmgr->getColorEquatorLine());
 
610
        tui_colors_ecliptic_color->setVector(grlmgr->getColorEclipticLine());
 
611
        tui_colors_nebula_label_color->setVector(nmgr->getNamesColor());
 
612
        tui_colors_nebula_circle_color->setVector(nmgr->getCirclesColor());
517
613
 
518
614
 
519
615
        // 6. effects
520
 
        tui_effect_landscape->setValue(StelUtility::stringToWstring(core->getObservatory().get_landscape_name()));
521
 
        tui_effect_pointobj->setValue(core->getFlagPointStar());
522
 
        tui_effect_zoom_duration->setValue(core->getAutomoveDuration());
523
 
        tui_effect_manual_zoom->setValue(core->getFlagManualAutoZoom());
524
 
        tui_effect_object_scale->setValue(core->getStarScale());
525
 
        tui_effect_milkyway_intensity->setValue(core->getMilkyWayIntensity());
 
616
        tui_effect_light_pollution->setValue(lmgr->getAtmosphereLightPollutionLuminance());
 
617
        tui_effect_landscape->setValue(lmgr->getLandscapeName().toStdWString());
 
618
        tui_effect_pointobj->setValue(smgr->getFlagPointStar());
 
619
        tui_effect_zoom_duration->setValue(mvmgr->getAutoMoveDuration());
 
620
        tui_effect_manual_zoom->setValue(mvmgr->getFlagManualAutoZoom());
 
621
        tui_effect_object_scale->setValue(smgr->getScale());
 
622
        tui_effect_milkyway_intensity->setValue(mw->getIntensity());
526
623
        tui_effect_cursor_timeout->setValue(MouseCursorTimeout);
527
 
        tui_effect_nebulae_label_magnitude->setValue(core->getNebulaMaxMagHints());
 
624
        tui_effect_nebulae_label_magnitude->setValue(nmgr->getMaxMagHints());
 
625
        tui_effect_landscape_sets_location->setValue(lmgr->getFlagLandscapeSetsLocation());
528
626
 
529
627
 
530
628
        // 7. Scripts
531
629
        // each fresh time enter needs to reset to select message
532
 
        if(app->SelectedScript=="") {
 
630
        if(SelectedScript=="") {
533
631
                tui_scripts_local->setCurrent(_(TUI_SCRIPT_MSG));
534
632
                
535
633
                if(ScriptDirectoryRead) {
541
639
        }
542
640
 
543
641
        // 8. admin
544
 
        tui_admin_setlocale->setValue( StelUtility::stringToWstring(app->getAppLanguage()) );
 
642
        tui_admin_setlocale->setValue(app->getLocaleMgr().getAppLanguage().toStdWString());
545
643
 
546
644
}
547
645
 
553
651
{
554
652
        // Don't call the script anymore coz it's pointless
555
653
        // system( ( core->getDataDir() + "script_set_time_zone " + tui_time_settmz->getCurrent() ).c_str() );
556
 
        app->set_custom_tz_name(tui_time_settmz->gettz());
 
654
        app->getLocaleMgr().set_custom_tz_name(tui_time_settmz->gettz());
557
655
}
558
656
 
559
657
// Set time format mode
560
658
void StelUI::tui_cb_settimedisplayformat(void)
561
659
{
562
 
        app->set_time_format_str(StelUtility::wstringToString(tui_time_displayformat->getCurrent()));
563
 
        app->set_date_format_str(StelUtility::wstringToString(tui_time_dateformat->getCurrent()));
 
660
        app->getLocaleMgr().set_time_format_str(StelUtils::wstringToString(tui_time_displayformat->getCurrent()));
 
661
        app->getLocaleMgr().set_date_format_str(StelUtils::wstringToString(tui_time_dateformat->getCurrent()));
564
662
}
565
663
 
566
664
// 7. Administration actions functions
568
666
// Load default configuration
569
667
void StelUI::tui_cb_admin_load_default(void)
570
668
{
571
 
        app->init();
 
669
        //app->init();
 
670
        tuiUpdateIndependentWidgets(); 
572
671
}
573
672
 
574
673
// Save to default configuration
575
674
void StelUI::tui_cb_admin_save_default(void)
576
675
{
577
 
        app->saveCurrentConfig(app->getConfigFile());
 
676
        try
 
677
        {
 
678
                saveCurrentConfig(app->getConfigFilePath());
 
679
        }
 
680
        catch(exception& e)
 
681
        {
 
682
                cerr << "ERROR: could not save config.ini file: " << e.what() << endl;
 
683
        }
578
684
 
579
 
        system( ( core->getDataDir() + "script_save_config " ).c_str() );
 
685
        try
 
686
        {
 
687
                system( QFile::encodeName(app->getFileMgr().findFile("data/script_save_config ")).constData());
 
688
        }
 
689
        catch(exception& e)
 
690
        {
 
691
                cerr << "ERROR while calling script_save_config: " << e.what() << endl;
 
692
        }
580
693
}
581
694
 
582
695
// Launch script for internet update
583
696
void StelUI::tui_cb_admin_updateme(void)
584
697
{
585
 
        system( ( core->getDataDir() + "script_internet_update" ).c_str() );
 
698
        try
 
699
        {
 
700
                system( QFile::encodeName(app->getFileMgr().findFile("data/script_internet_update ")).constData());
 
701
        }
 
702
        catch(exception& e)
 
703
        {
 
704
                cerr << "ERROR while calling script_internet_update: " << e.what() << endl;
 
705
        }
 
706
}
 
707
 
 
708
 
 
709
// Launch script for shutdown, then exit
 
710
void StelUI::tui_cb_admin_shutdown(void)
 
711
{
 
712
        try
 
713
        {
 
714
                system( QFile::encodeName(app->getFileMgr().findFile("data/script_shutdown ")).constData());
 
715
        }
 
716
        catch(exception& e)
 
717
        {
 
718
                cerr << "ERROR while calling script_shutdown: " << e.what() << endl;
 
719
        }
 
720
        app->terminateApplication();
586
721
}
587
722
 
588
723
// Set a new landscape skin
589
724
void StelUI::tui_cb_tui_effect_change_landscape(void)
590
725
{
591
 
        app->commander->execute_command(string("set landscape_name " +  StelUtility::wstringToString(tui_effect_landscape->getCurrent())));
 
726
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
 
727
        commander->execute_command(string("set landscape_name \"" +  StelUtils::wstringToString(tui_effect_landscape->getCurrent()) + "\""));
592
728
}
593
729
 
594
730
 
595
731
// Set a new sky culture
596
732
void StelUI::tui_cb_tui_general_change_sky_culture(void) {
597
 
 
 
733
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
598
734
        //      core->setSkyCulture(tui_general_sky_culture->getCurrent());
599
 
        app->commander->execute_command( string("set sky_culture ") + StelUtility::wstringToString(tui_general_sky_culture->getCurrent()));
 
735
        commander->execute_command( string("set sky_culture ") + StelUtils::wstringToString(tui_general_sky_culture->getCurrent()));
600
736
}
601
737
 
602
738
// Set a new sky locale
603
739
void StelUI::tui_cb_tui_general_change_sky_locale(void) {
 
740
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
604
741
        // wcout << "set sky locale to " << tui_general_sky_locale->getCurrent() << endl;
605
 
        app->commander->execute_command( string("set sky_locale " + StelUtility::wstringToString(tui_general_sky_locale->getCurrent())));
 
742
        commander->execute_command( string("set sky_locale " + StelUtils::wstringToString(tui_general_sky_locale->getCurrent())));
606
743
}
607
744
 
608
745
 
609
 
#define SCRIPT_REMOVEABLE_DISK "/tmp/scripts/"
610
 
 
611
746
// callback for changing scripts from removeable media
612
747
void StelUI::tui_cb_scripts_removeable() {
613
 
  
614
748
  if(!ScriptDirectoryRead) {
 
749
                ScriptMgr* scripts = (ScriptMgr*)StelApp::getInstance().getModuleMgr().getModule("ScriptMgr");
615
750
          // read scripts from mounted disk
616
 
          string script_list = app->scripts->get_script_list(SCRIPT_REMOVEABLE_DISK);
617
 
          tui_scripts_removeable->replaceItemList(_(TUI_SCRIPT_MSG) + wstring(L"\n") + StelUtility::stringToWstring(script_list),0);
 
751
          string script_list = scripts->get_script_list(scripts->get_removable_media_path());
 
752
          tui_scripts_removeable->replaceItemList(_(TUI_SCRIPT_MSG) + wstring(L"\n") + StelUtils::stringToWstring(script_list),0);
618
753
          ScriptDirectoryRead = 1;
619
754
  } 
620
755
 
621
756
  if(tui_scripts_removeable->getCurrent()==_(TUI_SCRIPT_MSG)) {
622
 
          app->SelectedScript = "";
 
757
          SelectedScript = "";
623
758
  } else {
624
 
          app->SelectedScript = StelUtility::wstringToString(tui_scripts_removeable->getCurrent());
625
 
          app->SelectedScriptDirectory = SCRIPT_REMOVEABLE_DISK;
 
759
                ScriptMgr* scripts = (ScriptMgr*)StelApp::getInstance().getModuleMgr().getModule("ScriptMgr");
 
760
          SelectedScript = StelUtils::wstringToString(tui_scripts_removeable->getCurrent());
 
761
          SelectedScriptDirectory = scripts->get_removable_media_path().toStdString();
626
762
          // to avoid confusing user, clear out local script selection as well
627
763
          tui_scripts_local->setCurrent(_(TUI_SCRIPT_MSG));
628
764
  } 
629
765
}
630
766
 
631
 
 
632
 
// callback for changing scripts from local directory
633
 
void StelUI::tui_cb_scripts_local() {
634
 
  
635
 
        if(tui_scripts_local->getCurrent()!=_(TUI_SCRIPT_MSG)){
636
 
    app->SelectedScript = StelUtility::wstringToString(tui_scripts_local->getCurrent());
637
 
    app->SelectedScriptDirectory = core->getDataDir() + "scripts/";
638
 
    // to reduce confusion for user, clear out removeable script selection as well
639
 
    if(ScriptDirectoryRead) tui_scripts_removeable->setCurrent(_(TUI_SCRIPT_MSG));
640
 
  } else {
641
 
    app->SelectedScript = "";
642
 
  }
 
767
/****************************************************************************
 
768
 callback for changing scripts from local directory
 
769
****************************************************************************/
 
770
void StelUI::tui_cb_scripts_local() {  
 
771
        if(tui_scripts_local->getCurrent()!=_(TUI_SCRIPT_MSG))
 
772
        {
 
773
                SelectedScript = StelUtils::wstringToString(tui_scripts_local->getCurrent());
 
774
                SelectedScriptDirectory = "";
 
775
                // to reduce confusion for user, clear out removeable script selection as well
 
776
                if(ScriptDirectoryRead) 
 
777
                        tui_scripts_removeable->setCurrent(_(TUI_SCRIPT_MSG));
 
778
        } 
 
779
        else
 
780
        {
 
781
                SelectedScript = "";
 
782
        }
643
783
}
644
784
 
645
785
 
646
786
// change UI locale
647
787
void StelUI::tui_cb_admin_set_locale() {
648
788
 
649
 
        app->setAppLanguage(StelUtility::wstringToString(tui_admin_setlocale->getCurrent()));
 
789
        app->getLocaleMgr().setAppLanguage(QString::fromStdWString(tui_admin_setlocale->getCurrent()));
650
790
}
651
791
 
652
792
 
653
793
void StelUI::tui_cb_effects_milkyway_intensity() {
654
 
 
 
794
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
655
795
        std::ostringstream oss;
656
796
        oss << "set milky_way_intensity " << tui_effect_milkyway_intensity->getValue();
657
 
        app->commander->execute_command(oss.str());
 
797
        commander->execute_command(oss.str());
658
798
}
659
799
 
660
800
void StelUI::tui_cb_setlocation() {
661
 
        
 
801
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
662
802
        std::ostringstream oss;
663
803
        oss << "moveto lat " << tui_location_latitude->getValue() 
664
804
                << " lon " <<  tui_location_longitude->getValue()
665
805
                << " alt " << tui_location_altitude->getValue();
666
 
        app->commander->execute_command(oss.str());
 
806
        commander->execute_command(oss.str());
667
807
 
668
808
}
669
809
 
670
810
 
671
811
void StelUI::tui_cb_stars()
672
812
{
 
813
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
 
814
        
673
815
        // 4. Stars
674
816
        std::ostringstream oss;
675
817
 
676
818
        oss << "flag stars " << tui_stars_show->getValue();
677
 
        app->commander->execute_command(oss.str());
 
819
        commander->execute_command(oss.str());
678
820
 
679
821
        oss.str("");
680
822
        oss << "set max_mag_star_name " << tui_star_labelmaxmag->getValue();
681
 
        app->commander->execute_command(oss.str());
 
823
        commander->execute_command(oss.str());
682
824
 
683
825
        oss.str("");
684
826
        oss << "set star_twinkle_amount " << tui_stars_twinkle->getValue();
685
 
        app->commander->execute_command(oss.str());
 
827
        commander->execute_command(oss.str());
686
828
 
687
829
        oss.str("");
688
830
        oss << "set star_mag_scale " << tui_star_magscale->getValue();
689
 
        app->commander->execute_command(oss.str());
 
831
        commander->execute_command(oss.str());
 
832
/* TODO
 
833
        oss.str("");
 
834
        oss << "set star_limiting_mag " << tui_star_limitingmag->getValue();
 
835
        commander->execute_command(oss.str());
 
836
*/
690
837
 
691
838
}
692
839
 
693
840
void StelUI::tui_cb_effects()
694
841
{
695
 
 
 
842
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
 
843
        
696
844
        // 5. effects
697
845
        std::ostringstream oss;
698
846
 
699
847
        oss << "flag point_star " << tui_effect_pointobj->getValue();
700
 
        app->commander->execute_command(oss.str());
 
848
        commander->execute_command(oss.str());
701
849
 
702
850
        oss.str("");
703
851
        oss << "set auto_move_duration " << tui_effect_zoom_duration->getValue();
704
 
        app->commander->execute_command(oss.str());
 
852
        commander->execute_command(oss.str());
705
853
 
706
854
        oss.str("");
707
855
        oss << "flag manual_zoom " << tui_effect_manual_zoom->getValue();
708
 
        app->commander->execute_command(oss.str());
 
856
        commander->execute_command(oss.str());
709
857
 
710
858
        oss.str("");
711
859
        oss << "set star_scale " << tui_effect_object_scale->getValue();
712
 
        app->commander->execute_command(oss.str());
 
860
        commander->execute_command(oss.str());
713
861
 
714
862
        MouseCursorTimeout = tui_effect_cursor_timeout->getValue();  // never recorded
715
863
 
 
864
        oss.str("");
 
865
        oss << "set light_pollution_luminance " << tui_effect_light_pollution->getValue();
 
866
        commander->execute_command(oss.str());
 
867
 
 
868
        oss.str("");
 
869
        oss << "flag landscape_sets_location " << tui_effect_landscape_sets_location->getValue();
 
870
        commander->execute_command(oss.str());
 
871
 
716
872
}
717
873
 
718
874
 
719
875
// set sky time
720
876
void StelUI::tui_cb_sky_time()
721
877
{
 
878
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
722
879
        std::ostringstream oss;
723
 
        oss << "date local " << StelUtility::wstringToString(tui_time_skytime->getDateString());
724
 
        app->commander->execute_command(oss.str());
 
880
        oss << "date local " << StelUtils::wstringToString(tui_time_skytime->getDateString());
 
881
        commander->execute_command(oss.str());
725
882
}
726
883
 
727
884
 
728
885
// set nebula label limit
729
886
void StelUI::tui_cb_effects_nebulae_label_magnitude()
730
887
{
 
888
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");
731
889
        std::ostringstream oss;
732
890
        oss << "set max_mag_nebula_name " << tui_effect_nebulae_label_magnitude->getValue();
733
 
        app->commander->execute_command(oss.str());
 
891
        commander->execute_command(oss.str());
734
892
}
735
893
 
736
894
 
737
895
void StelUI::tui_cb_change_color()
738
896
{
739
 
        core->setColorConstellationLine( tui_colors_const_line_color->getVector() );
740
 
        core->setColorConstellationNames( tui_colors_const_label_color->getVector() );
741
 
        core->setColorCardinalPoints( tui_colors_cardinal_color->getVector() );
742
 
        core->setConstellationArtIntensity(tui_colors_const_art_intensity->getValue() );
743
 
        core->setColorConstellationBoundaries(tui_colors_const_boundary_color->getVector() );
744
 
        // core->setColorStarNames(
745
 
        // core->setColorStarCircles(
746
 
        core->setColorPlanetsOrbits(tui_colors_planet_orbits_color->getVector() );
747
 
        core->setColorPlanetsNames(tui_colors_planet_names_color->getVector() );
748
 
        core->setColorPlanetsTrails(tui_colors_object_trails_color->getVector() );
749
 
        core->setColorAzimutalGrid(tui_colors_azimuthal_color->getVector() );
750
 
        core->setColorEquatorGrid(tui_colors_equatorial_color->getVector() );
751
 
        core->setColorEquatorLine(tui_colors_equator_color->getVector() );
752
 
        core->setColorEclipticLine(tui_colors_ecliptic_color->getVector() );
753
 
        core->setColorMeridianLine(tui_colors_meridian_color->getVector() );
754
 
        core->setColorNebulaLabels(tui_colors_nebula_label_color->getVector() );
755
 
        core->setColorNebulaCircle(tui_colors_nebula_circle_color->getVector() );
756
 
 
757
 
 
 
897
        ConstellationMgr* cmgr = (ConstellationMgr*)app->getModuleMgr().getModule("ConstellationMgr");
 
898
        NebulaMgr* nmgr = (NebulaMgr*)app->getModuleMgr().getModule("NebulaMgr");
 
899
        SolarSystem* ssmgr = (SolarSystem*)app->getModuleMgr().getModule("SolarSystem");
 
900
        LandscapeMgr* lmgr = (LandscapeMgr*)app->getModuleMgr().getModule("LandscapeMgr");
 
901
        GridLinesMgr* grlmgr = (GridLinesMgr*)app->getModuleMgr().getModule("GridLinesMgr");
 
902
        
 
903
        cmgr->setLinesColor( tui_colors_const_line_color->getVector() );
 
904
        cmgr->setNamesColor( tui_colors_const_label_color->getVector() );
 
905
        cmgr->setArtIntensity(tui_colors_const_art_intensity->getValue() );
 
906
        cmgr->setBoundariesColor(tui_colors_const_boundary_color->getVector() );
 
907
        
 
908
        lmgr->setColorCardinalPoints( tui_colors_cardinal_color->getVector() );
 
909
        
 
910
        ssmgr->setOrbitsColor(tui_colors_planet_orbits_color->getVector() );
 
911
        ssmgr->setNamesColor(tui_colors_planet_names_color->getVector() );
 
912
        ssmgr->setTrailsColor(tui_colors_object_trails_color->getVector() );
 
913
        grlmgr->setColorAzimutalGrid(tui_colors_azimuthal_color->getVector() );
 
914
        grlmgr->setColorEquatorGrid(tui_colors_equatorial_color->getVector() );
 
915
        grlmgr->setColorEquatorLine(tui_colors_equator_color->getVector() );
 
916
        grlmgr->setColorEclipticLine(tui_colors_ecliptic_color->getVector() );
 
917
        grlmgr->setColorMeridianLine(tui_colors_meridian_color->getVector() );
 
918
        
 
919
        nmgr->setNamesColor(tui_colors_nebula_label_color->getVector() );
 
920
        nmgr->setCirclesColor(tui_colors_nebula_circle_color->getVector() );
758
921
}
759
922
 
760
923
 
761
924
void StelUI::tui_cb_location_change_planet()
762
925
{
763
 
        //      core->setHomePlanet( StelUtility::wstringToString( tui_location_planet->getCurrent() ) );
764
 
        app->commander->execute_command(string("set home_planet \"") + 
765
 
                                                                        StelUtility::wstringToString( tui_location_planet->getCurrent() ) +
 
926
        //      core->setHomePlanet( StelUtils::wstringToString( tui_location_planet->getCurrent() ) );
 
927
        //      wcout << "set home planet " << tui_location_planet->getCurrent() << endl;
 
928
        StelCommandInterface* commander = (StelCommandInterface*)StelApp::getInstance().getModuleMgr().getModule("StelCommandInterface");       
 
929
        commander->execute_command(string("set home_planet \"") + 
 
930
                                                                        StelUtils::wstringToString( tui_location_planet->getCurrent() ) +
766
931
                                                                        "\"");
767
932
}
 
933
 
 
934
 
 
935
void StelUI::tui_cb_day_key() 
 
936
{
 
937
 
 
938
        setDayKeyMode( StelUtils::wstringToString(tui_time_day_key->getCurrent()) );
 
939
        //      cout << "Set from tui value DayKeyMode to " << app->DayKeyMode << endl;
 
940
}
 
941
 
 
942
 
 
943
// Update widgets that don't always match current settings with current settings
 
944
void StelUI::tuiUpdateIndependentWidgets(void) { 
 
945
 
 
946
        // Called when open tui menu
 
947
 
 
948
        // Since some tui options don't immediately affect actual settings
 
949
        // reset those options to the current values now
 
950
        // (can not do this in tui_update_widgets)
 
951
 
 
952
        tui_location_planet->setValue(StelUtils::stringToWstring(core->getObservatory()->getHomePlanetEnglishName()));
 
953
 
 
954
        // Reread local script directory (in case new files)
 
955
        ScriptMgr* scripts = (ScriptMgr*)StelApp::getInstance().getModuleMgr().getModule("ScriptMgr");
 
956
        tui_scripts_local->replaceItemList(_(TUI_SCRIPT_MSG) + wstring(L"\n") 
 
957
                        + StelUtils::stringToWstring(scripts->get_script_list("scripts")), 0); 
 
958
 
 
959
        // also clear out script lists as media may have changed
 
960
        ScriptDirectoryRead = 0;
 
961
 
 
962
}
 
963
 
 
964
 
 
965
// Saves all current settings
 
966
void StelUI::saveCurrentConfig(const QString& confFile)
 
967
{
 
968
        // No longer resaves everything, just settings user can change through UI
 
969
 
 
970
        StelSkyCultureMgr* skyCultureMgr = &app->getSkyCultureMgr();
 
971
        StelLocaleMgr* localeMgr = &app->getLocaleMgr();
 
972
        StelModuleMgr* moduleMgr = &app->getModuleMgr();
 
973
        GridLinesMgr* grlmgr = (GridLinesMgr*)app->getModuleMgr().getModule("GridLinesMgr");
 
974
        MovementMgr* mvmgr = (MovementMgr*)app->getModuleMgr().getModule("MovementMgr");
 
975
        
 
976
        cout << "Saving configuration file " << confFile.toUtf8().data() << " ..." << endl;
 
977
        InitParser conf;
 
978
        conf.load(confFile);
 
979
 
 
980
        // Main section
 
981
        conf.set_str    ("main:version", PACKAGE_VERSION);
 
982
 
 
983
        // localization section
 
984
        conf.set_str    ("localization:sky_culture", skyCultureMgr->getSkyCultureDir());
 
985
        conf.set_str    ("localization:sky_locale", localeMgr->getSkyLanguage());
 
986
        conf.set_str    ("localization:app_locale", localeMgr->getAppLanguage());
 
987
        conf.set_str    ("localization:time_display_format", localeMgr->get_time_format_str().c_str());
 
988
        conf.set_str    ("localization:date_display_format", localeMgr->get_date_format_str().c_str());
 
989
        if (localeMgr->get_tz_format() == StelLocaleMgr::S_TZ_CUSTOM)
 
990
        {
 
991
                conf.set_str("localization:time_zone", localeMgr->get_custom_tz_name().c_str());
 
992
        }
 
993
        if (localeMgr->get_tz_format() == StelLocaleMgr::S_TZ_SYSTEM_DEFAULT)
 
994
        {
 
995
                conf.set_str("localization:time_zone", "system_default");
 
996
        }
 
997
        if (localeMgr->get_tz_format() == StelLocaleMgr::S_TZ_GMT_SHIFT)
 
998
        {
 
999
                conf.set_str("localization:time_zone", "gmt+x");
 
1000
        }
 
1001
 
 
1002
        // viewing section
 
1003
        ConstellationMgr* cmgr = (ConstellationMgr*)moduleMgr->getModule("ConstellationMgr");
 
1004
        conf.set_boolean("viewing:flag_constellation_drawing", cmgr->getFlagLines());
 
1005
        conf.set_boolean("viewing:flag_constellation_name", cmgr->getFlagNames());
 
1006
        conf.set_boolean("viewing:flag_constellation_art", cmgr->getFlagArt());
 
1007
        conf.set_boolean("viewing:flag_constellation_boundaries", cmgr->getFlagBoundaries());
 
1008
        conf.set_boolean("viewing:flag_constellation_pick", cmgr->getFlagIsolateSelected());
 
1009
        conf.set_double ("viewing:constellation_art_intensity", cmgr->getArtIntensity());
 
1010
        conf.set_double ("viewing:constellation_art_fade_duration", cmgr->getArtFadeDuration());
 
1011
        conf.set_str    ("color:const_lines_color", StelUtils::vec3f_to_str(cmgr->getLinesColor()).c_str());
 
1012
        conf.set_str    ("color:const_names_color", StelUtils::vec3f_to_str(cmgr->getNamesColor()).c_str());
 
1013
        conf.set_str    ("color:const_boundary_color", StelUtils::vec3f_to_str(cmgr->getBoundariesColor()).c_str());
 
1014
                
 
1015
        SolarSystem* ssmgr = (SolarSystem*)moduleMgr->getModule("SolarSystem");
 
1016
        LandscapeMgr* lmgr = (LandscapeMgr*)moduleMgr->getModule("LandscapeMgr");
 
1017
        conf.set_double("viewing:moon_scale", ssmgr->getMoonScale());
 
1018
        conf.set_boolean("viewing:flag_equatorial_grid", grlmgr->getFlagEquatorGrid());
 
1019
        conf.set_boolean("viewing:flag_azimutal_grid", grlmgr->getFlagAzimutalGrid());
 
1020
        conf.set_boolean("viewing:flag_equator_line", grlmgr->getFlagEquatorLine());
 
1021
        conf.set_boolean("viewing:flag_ecliptic_line", grlmgr->getFlagEclipticLine());
 
1022
        conf.set_boolean("viewing:flag_cardinal_points", lmgr->getFlagCardinalsPoints());
 
1023
        conf.set_boolean("viewing:flag_meridian_line", grlmgr->getFlagMeridianLine());
 
1024
        conf.set_boolean("viewing:flag_moon_scaled", ssmgr->getFlagMoonScale());
 
1025
        conf.set_double("viewing:light_pollution_luminance", lmgr->getAtmosphereLightPollutionLuminance());
 
1026
 
 
1027
        // Landscape section
 
1028
        conf.set_boolean("landscape:flag_landscape", lmgr->getFlagLandscape());
 
1029
        conf.set_boolean("landscape:flag_atmosphere", lmgr->getFlagAtmosphere());
 
1030
        conf.set_boolean("landscape:flag_fog", lmgr->getFlagFog());
 
1031
        //      conf.set_double ("viewing:atmosphere_fade_duration", core->getAtmosphereFadeDuration());
 
1032
 
 
1033
        // Star section
 
1034
        StarMgr* smgr = (StarMgr*)moduleMgr->getModule("StarMgr");
 
1035
        conf.set_double ("stars:star_scale", smgr->getScale());
 
1036
        conf.set_double ("stars:star_mag_scale", smgr->getMagScale());
 
1037
        conf.set_boolean("stars:flag_point_star", smgr->getFlagPointStar());
 
1038
        conf.set_double ("stars:max_mag_star_name", smgr->getMaxMagName());
 
1039
        conf.set_boolean("stars:flag_star_twinkle", smgr->getFlagTwinkle());
 
1040
        conf.set_double ("stars:star_twinkle_amount", smgr->getTwinkleAmount());
 
1041
        conf.set_boolean("astro:flag_stars", smgr->getFlagStars());
 
1042
        conf.set_boolean("astro:flag_star_name", smgr->getFlagNames());
 
1043
 
 
1044
        // Color section
 
1045
        NebulaMgr* nmgr = (NebulaMgr*)moduleMgr->getModule("NebulaMgr");
 
1046
        conf.set_str    ("color:azimuthal_color", StelUtils::vec3f_to_str(grlmgr->getColorAzimutalGrid()).c_str());
 
1047
        conf.set_str    ("color:equatorial_color", StelUtils::vec3f_to_str(grlmgr->getColorEquatorGrid()).c_str());
 
1048
        conf.set_str    ("color:equator_color", StelUtils::vec3f_to_str(grlmgr->getColorEquatorLine()).c_str());
 
1049
        conf.set_str    ("color:ecliptic_color", StelUtils::vec3f_to_str(grlmgr->getColorEclipticLine()).c_str());
 
1050
        conf.set_str    ("color:meridian_color", StelUtils::vec3f_to_str(grlmgr->getColorMeridianLine()).c_str());
 
1051
        conf.set_str    ("color:nebula_label_color", StelUtils::vec3f_to_str(nmgr->getNamesColor()).c_str());
 
1052
        conf.set_str    ("color:nebula_circle_color", StelUtils::vec3f_to_str(nmgr->getCirclesColor()).c_str());
 
1053
        conf.set_str    ("color:cardinal_color", StelUtils::vec3f_to_str(lmgr->getColorCardinalPoints()).c_str());
 
1054
        conf.set_str    ("color:planet_names_color", StelUtils::vec3f_to_str(ssmgr->getNamesColor()).c_str());
 
1055
        conf.set_str    ("color:planet_orbits_color", StelUtils::vec3f_to_str(ssmgr->getOrbitsColor()).c_str());
 
1056
        conf.set_str    ("color:object_trails_color", StelUtils::vec3f_to_str(ssmgr->getTrailsColor()).c_str());
 
1057
 
 
1058
        // gui section
 
1059
        conf.set_double("gui:mouse_cursor_timeout",getMouseCursorTimeout());
 
1060
        conf.set_str    ("gui:day_key_mode", getDayKeyMode().c_str());
 
1061
 
 
1062
        // Text ui section
 
1063
        conf.set_boolean("tui:flag_show_gravity_ui", getFlagShowGravityUi());
 
1064
        conf.set_boolean("tui:flag_show_tui_datetime", getFlagShowTuiDateTime());
 
1065
        conf.set_boolean("tui:flag_show_tui_short_obj_info", getFlagShowTuiShortObjInfo());
 
1066
 
 
1067
        // Navigation section
 
1068
        conf.set_boolean("navigation:flag_manual_zoom", mvmgr->getFlagManualAutoZoom());
 
1069
        conf.set_double ("navigation:auto_move_duration", mvmgr->getAutoMoveDuration());
 
1070
        conf.set_double ("navigation:zoom_speed", mvmgr->getZoomSpeed());
 
1071
        conf.set_double ("navigation:preset_sky_time", core->getNavigation()->getPresetSkyTime());
 
1072
        conf.set_str    ("navigation:startup_time_mode", core->getNavigation()->getStartupTimeMode().c_str());
 
1073
 
 
1074
        // Astro section
 
1075
        conf.set_boolean("astro:flag_object_trails", ssmgr->getFlagTrails());
 
1076
        conf.set_boolean("astro:flag_bright_nebulae", nmgr->getFlagBright());
 
1077
        conf.set_boolean("astro:flag_nebula", nmgr->getFlagShow());
 
1078
        conf.set_boolean("astro:flag_nebula_name", nmgr->getFlagHints());
 
1079
        conf.set_double("astro:max_mag_nebula_name", nmgr->getMaxMagHints());
 
1080
        conf.set_boolean("astro:flag_planets", ssmgr->getFlagPlanets());
 
1081
        conf.set_boolean("astro:flag_planets_hints", ssmgr->getFlagHints());
 
1082
        conf.set_boolean("astro:flag_planets_orbits", ssmgr->getFlagOrbits());
 
1083
 
 
1084
        MilkyWay* mw = (MilkyWay*)moduleMgr->getModule("MilkyWay");
 
1085
        conf.set_boolean("astro:flag_milky_way", mw->getFlagShow());
 
1086
        conf.set_double("astro:milky_way_intensity", mw->getIntensity());
 
1087
 
 
1088
        // Save observatory info
 
1089
        core->getObservatory()->setConf(conf, "init_location");
 
1090
 
 
1091
        conf.save(confFile);
 
1092
}
 
1093
 
 
1094