~ubuntu-branches/debian/jessie/stellarium/jessie

« back to all changes in this revision

Viewing changes to src/StelApp.cpp

Tags: upstream-0.9.0
Import upstream version 0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Stellarium
 
3
 * Copyright (C) 2006 Fabien Chereau
 
4
 * 
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 * 
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 * 
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
18
 */
 
19
 
 
20
#include "StelApp.hpp"
 
21
 
 
22
#include "StelCore.hpp"
 
23
#include "ViewportDistorter.hpp"
 
24
#include "StelUtils.hpp"
 
25
#include "stel_command_interface.h"
 
26
#include "stel_ui.h"
 
27
#include "StelTextureMgr.hpp"
 
28
#include "LoadingBar.hpp"
 
29
#include "StelObjectMgr.hpp"
 
30
#include "image_mgr.h"
 
31
#include "TelescopeMgr.hpp"
 
32
#include "ConstellationMgr.hpp"
 
33
#include "NebulaMgr.hpp"
 
34
#include "LandscapeMgr.hpp"
 
35
#include "GridLinesMgr.hpp"
 
36
#include "MilkyWay.hpp"
 
37
#include "MeteorMgr.hpp"
 
38
#include "StarMgr.hpp"
 
39
#include "SolarSystem.hpp"
 
40
#include "InitParser.hpp"
 
41
#include "Projector.hpp"
 
42
 
 
43
#include "StelModuleMgr.hpp"
 
44
#include "StelFontMgr.hpp"
 
45
#include "StelLocaleMgr.hpp"
 
46
#include "StelSkyCultureMgr.hpp"
 
47
#include "MovementMgr.hpp"
 
48
#include "StelFileMgr.hpp"
 
49
 
 
50
#include <cstdlib>
 
51
 
 
52
// Initialize static variables
 
53
StelApp* StelApp::singleton = NULL;
 
54
 
 
55
/*************************************************************************
 
56
 Create and initialize the main Stellarium application.
 
57
*************************************************************************/
 
58
StelApp::StelApp(int argc, char** argv) :
 
59
        maxfps(10000.f), core(NULL), fps(0), frame(0), timefr(0), 
 
60
        timeBase(0), ui(NULL), draw_mode(StelApp::DM_NORMAL), initialized(false)
 
61
{
 
62
        scripts=0;
 
63
        commander=0;
 
64
        distorter=0;
 
65
        skyCultureMgr=0;
 
66
        localeMgr=0;
 
67
        fontManager=0;
 
68
        stelObjectMgr=0;
 
69
        textureMgr=0;
 
70
        moduleMgr=0;
 
71
 
 
72
        // Can't create 2 StelApp instances
 
73
        assert(!singleton);
 
74
        singleton = this;
 
75
        
 
76
        // C++-ize argv for use with StelUtils::argsHaveOption... functions
 
77
        for(int i=0; i<argc; i++) { argList.push_back(argv[i]); }
 
78
                
 
79
        stelFileMgr = new StelFileMgr();
 
80
        
 
81
        // Check if the user directory exists, and create it if necessary
 
82
        stelFileMgr->checkUserDir();
 
83
        
 
84
        // Check some command-line options
 
85
        try
 
86
        {
 
87
                setConfigFile(StelUtils::argsHaveOptionWithArg<string>(argList, "-c", "--config-file", "config.ini"));
 
88
        }
 
89
        catch(exception& e)
 
90
        {
 
91
                cerr << "ERROR: while looking for --config-file option: " << e.what() << ". Using \"config.ini\"" << endl;
 
92
                setConfigFile("config.ini");            
 
93
        }
 
94
        cout << "config file is: " << configFile << endl;
 
95
        
 
96
        if (!stelFileMgr->exists(configFile))
 
97
        {
 
98
                cerr << "config file \"" << configFile << "\" does not exist - copying the default file." << endl;
 
99
                copyDefaultConfigFile();
 
100
        }
 
101
        
 
102
        textureMgr = new StelTextureMgr();
 
103
        localeMgr = new StelLocaleMgr();
 
104
        
 
105
        string fontMapFile("");
 
106
        try 
 
107
        {
 
108
                fontMapFile = stelFileMgr->findFile("data/fontmap.dat");
 
109
        }
 
110
        catch(exception& e)
 
111
        {
 
112
                cerr << "ERROR when locating font map file: " << e.what() << endl;
 
113
        }
 
114
        fontManager = new StelFontMgr(fontMapFile);
 
115
        
 
116
        skyCultureMgr = new StelSkyCultureMgr();
 
117
        moduleMgr = new StelModuleMgr();
 
118
        
 
119
        core = new StelCore();
 
120
        commander = new StelCommandInterface(core, this);
 
121
        scripts = new ScriptMgr(commander);
 
122
        time_multiplier = 1;
 
123
        distorter = 0;
 
124
}
 
125
 
 
126
/*************************************************************************
 
127
 Deinitialize and destroy the main Stellarium application.
 
128
*************************************************************************/
 
129
StelApp::~StelApp()
 
130
{
 
131
        delete ui; ui=NULL;
 
132
        delete scripts; scripts=NULL;
 
133
        delete commander; commander=NULL;
 
134
        delete core; core=NULL;
 
135
        if (distorter) {delete distorter; distorter=NULL;}
 
136
        delete skyCultureMgr; skyCultureMgr=NULL;
 
137
        delete localeMgr; localeMgr=NULL;
 
138
        delete fontManager; fontManager=NULL;
 
139
        delete stelObjectMgr; stelObjectMgr=NULL;
 
140
        delete stelFileMgr; stelFileMgr=NULL;
 
141
        
 
142
        // Delete all the modules
 
143
        for (StelModuleMgr::Iterator iter=moduleMgr->begin();iter!=moduleMgr->end();++iter)
 
144
        {
 
145
                delete *iter;
 
146
                *iter = NULL;
 
147
        }
 
148
 
 
149
        delete textureMgr; textureMgr=NULL;
 
150
        delete moduleMgr; moduleMgr=NULL;
 
151
}
 
152
 
 
153
/*************************************************************************
 
154
 Return the full name of stellarium, i.e. "stellarium 0.9.0"
 
155
*************************************************************************/
 
156
std::string StelApp::getApplicationName()
 
157
{
 
158
        return string("Stellarium")+" "+PACKAGE_VERSION;
 
159
}
 
160
 
 
161
void StelApp::setViewPortDistorterType(const string &type)
 
162
{
 
163
        if (type != getViewPortDistorterType()) setResizable(type == "none");
 
164
        if (distorter)
 
165
        {
 
166
                delete distorter;
 
167
                distorter = 0;
 
168
        }
 
169
        InitParser conf;
 
170
        conf.load(getConfigFilePath());
 
171
        distorter = ViewportDistorter::create(type,getScreenW(),getScreenH(),
 
172
                                              core->getProjection(),conf);
 
173
}
 
174
 
 
175
string StelApp::getViewPortDistorterType() const
 
176
{
 
177
        if (distorter) return distorter->getType();
 
178
        return "none";
 
179
}
 
180
 
 
181
 
 
182
void StelApp::init()
 
183
{
 
184
        Translator::initSystemLanguage();
 
185
 
 
186
        // Load language codes
 
187
        try
 
188
        {
 
189
                Translator::initIso639_1LanguageCodes(stelFileMgr->findFile("data/iso639-1.utf8"));
 
190
        }
 
191
        catch(exception& e)
 
192
        {
 
193
                cerr << "ERROR while loading translations: " << e.what() << endl;
 
194
        }
 
195
        
 
196
        // Initialize video device and other sdl parameters
 
197
        InitParser conf;
 
198
        string confPath;
 
199
        try
 
200
        {
 
201
                confPath = getConfigFilePath();
 
202
        }
 
203
        catch(exception& e)
 
204
        {
 
205
                cerr << "ERROR finding config file: " << e.what() << endl;
 
206
        }
 
207
        conf.load(confPath);
 
208
 
 
209
        // Main section
 
210
        string version = conf.get_str("main:version");
 
211
        if (version!=string(PACKAGE_VERSION))
 
212
        {
 
213
                std::istringstream istr(version);
 
214
                char tmp;
 
215
                int v1 =0;
 
216
                int v2 =0;
 
217
                istr >> v1 >> tmp >> v2;
 
218
 
 
219
                // Config versions less than 0.6.0 are not supported, otherwise we will try to use it
 
220
                if( v1 == 0 && v2 < 6 )
 
221
                {
 
222
                        // The config file is too old to try an importation
 
223
                        cout << "The current config file is from a version too old for parameters to be imported (" 
 
224
                                        << (version.empty() ? "<0.6.0" : version.c_str())
 
225
                                        << ")." << endl 
 
226
                                        << "It will be replaced by the default config file." << endl;
 
227
 
 
228
            copyDefaultConfigFile();
 
229
            conf.load(configFile);  // Read new config
 
230
                }
 
231
                else
 
232
                {
 
233
                        cout << "Attempting to use an existing older config file." << endl;
 
234
                }
 
235
        }
 
236
 
 
237
        // Create openGL context first
 
238
        string iconPath;
 
239
        try
 
240
        {
 
241
                iconPath = stelFileMgr->findFile("data/icon.bmp");
 
242
        }
 
243
        catch(exception& e)
 
244
        {
 
245
                cerr << "ERROR when trying to locate icon file: " << e.what() << endl;
 
246
        }
 
247
        initOpenGL(conf.get_int("video:screen_w"), conf.get_int("video:screen_h"), conf.get_int("video:bbp_mode"), conf.get_boolean("video:fullscreen"), iconPath);
 
248
 
 
249
        // Initialize AFTER creation of openGL context
 
250
        textureMgr->init(conf);
 
251
 
 
252
        // Clear screen, this fixes a strange artifact at loading time in the upper corner.
 
253
        glClearColor(0.0, 0.0, 0.0, 0.0);
 
254
        glClear(GL_COLOR_BUFFER_BIT);
 
255
        swapGLBuffers();
 
256
        glClear(GL_COLOR_BUFFER_BIT);
 
257
        
 
258
        maxfps = conf.get_double ("video","maximum_fps",10000);
 
259
        minfps = conf.get_double ("video","minimum_fps",10000);
 
260
 
 
261
        scripts->set_allow_ui( conf.get_boolean("gui","flag_script_allow_ui",0) );
 
262
 
 
263
        core->initProj(conf);
 
264
 
 
265
        LoadingBar lb(core->getProjection(), 12., "logo24bits.png",
 
266
                      getScreenW(), getScreenH(),
 
267
                      StelUtils::stringToWstring(PACKAGE_VERSION), 45, 320, 121);
 
268
 
 
269
        // Stel Object Data Base manager
 
270
        stelObjectMgr = new StelObjectMgr();
 
271
        stelObjectMgr->init(conf, lb);
 
272
 
 
273
        localeMgr->init(conf);
 
274
        skyCultureMgr->init(conf);
 
275
        
 
276
        ImageMgr* script_images = new ImageMgr();
 
277
        script_images->init(conf, lb);
 
278
        StelApp::getInstance().getModuleMgr().registerModule(script_images);
 
279
        
 
280
        // Init the solar system first
 
281
        SolarSystem* ssystem = new SolarSystem();
 
282
        ssystem->init(conf, lb);
 
283
        StelApp::getInstance().getModuleMgr().registerModule(ssystem);
 
284
        
 
285
        // Load hipparcos stars & names
 
286
        StarMgr* hip_stars = new StarMgr();
 
287
        hip_stars->init(conf, lb);
 
288
        StelApp::getInstance().getModuleMgr().registerModule(hip_stars);        
 
289
        
 
290
        core->init(conf, lb);
 
291
 
 
292
        // Init nebulas
 
293
        NebulaMgr* nebulas = new NebulaMgr();
 
294
        nebulas->init(conf, lb);
 
295
        StelApp::getInstance().getModuleMgr().registerModule(nebulas);
 
296
        
 
297
        // Init milky way
 
298
        MilkyWay* milky_way = new MilkyWay();
 
299
        milky_way->init(conf, lb);
 
300
        StelApp::getInstance().getModuleMgr().registerModule(milky_way);
 
301
        
 
302
        // Telescope manager
 
303
        TelescopeMgr* telescope_mgr = new TelescopeMgr();
 
304
        telescope_mgr->init(conf, lb);
 
305
        StelApp::getInstance().getModuleMgr().registerModule(telescope_mgr);
 
306
        
 
307
        // Constellations
 
308
        ConstellationMgr* asterisms = new ConstellationMgr(hip_stars);
 
309
        asterisms->init(conf, lb);
 
310
        StelApp::getInstance().getModuleMgr().registerModule(asterisms);
 
311
        
 
312
        // Landscape, atmosphere & cardinal points section
 
313
        LandscapeMgr* landscape = new LandscapeMgr();
 
314
        landscape->init(conf, lb);
 
315
        StelApp::getInstance().getModuleMgr().registerModule(landscape);
 
316
 
 
317
        GridLinesMgr* gridLines = new GridLinesMgr();
 
318
        gridLines->init(conf, lb);
 
319
        StelApp::getInstance().getModuleMgr().registerModule(gridLines);
 
320
        
 
321
        // Meteors
 
322
        MeteorMgr* meteors = new MeteorMgr(10, 60);
 
323
        meteors->init(conf, lb);
 
324
        StelApp::getInstance().getModuleMgr().registerModule(meteors);
 
325
 
 
326
//ugly fix by johannes: call skyCultureMgr->init twice so that
 
327
// star names are loaded again
 
328
        skyCultureMgr->init(conf);
 
329
        ui = new StelUI(core, this);
 
330
        ui->init(conf);
 
331
        ui->init_tui();  // don't reinit tui since probably called from there
 
332
        
 
333
        // Initialisation of the color scheme
 
334
        draw_mode = draw_mode=DM_NIGHT;  // fool caching
 
335
        setVisionModeNormal();
 
336
        if (conf.get_boolean("viewing:flag_night")) setVisionModeNight();
 
337
 
 
338
        setViewPortDistorterType(conf.get_str("video","distorter","none"));
 
339
 
 
340
        // Load dynamic external modules
 
341
        int i=1;
 
342
        while (true)
 
343
        {
 
344
                ostringstream oss;
 
345
                oss << "external_modules:module" << i; 
 
346
                if (conf.find_entry(oss.str()))
 
347
                {
 
348
                        StelModule* m = moduleMgr->loadExternalPlugin(conf.get_str(oss.str()));
 
349
                        if (m!=NULL)
 
350
                        {
 
351
                                m->init(conf, lb);
 
352
                                moduleMgr->registerModule(m);
 
353
                        }
 
354
                }
 
355
                else
 
356
                        break;
 
357
                i++;
 
358
        }
 
359
        
 
360
        // Generate dependency Lists for all modules
 
361
        moduleMgr->generateCallingLists();
 
362
        
 
363
        if (conf.find_entry("files:removable_media_path"))
 
364
        {
 
365
                scripts->set_removable_media_path(conf.get_str("files:removable_media_path"));
 
366
        }
 
367
        else
 
368
        {
 
369
                scripts->set_removable_media_path("");
 
370
        }
 
371
        
 
372
        // play startup script, if available
 
373
        scripts->play_startup_script();
 
374
        
 
375
        initialized = true;
 
376
}
 
377
 
 
378
void StelApp::update(int delta_time)
 
379
{
 
380
     if (!initialized)
 
381
        return;
 
382
        
 
383
        textureMgr->update();
 
384
        
 
385
        ++frame;
 
386
        timefr+=delta_time;
 
387
        if (timefr-timeBase > 1000)
 
388
        {
 
389
                fps=frame*1000.0/(timefr-timeBase);                             // Calc the FPS rate
 
390
                frame = 0;
 
391
                timeBase+=1000;
 
392
        }
 
393
 
 
394
        // change time rate if needed to fast forward scripts
 
395
        delta_time *= time_multiplier;
 
396
 
 
397
        // keep audio position updated if changing time multiplier
 
398
        if(!scripts->is_paused()) commander->update(delta_time);
 
399
 
 
400
        // run command from a running script
 
401
        scripts->update(delta_time);
 
402
 
 
403
  assert(ui);
 
404
        ui->update((double)delta_time/1000);
 
405
 
 
406
        core->update(delta_time);
 
407
 
 
408
        if(!scripts->is_paused()) ((ImageMgr*)moduleMgr->getModule("image_mgr"))->update(delta_time);
 
409
        
 
410
        // Send the event to every StelModule
 
411
        std::vector<StelModule*> modList = moduleMgr->getCallOrders("update");
 
412
        //cerr << "-------" << endl;
 
413
        for (std::vector<StelModule*>::iterator i=modList.begin();i!=modList.end();++i)
 
414
        {
 
415
                //cerr << (*i)->getModuleID() << endl;
 
416
                (*i)->update((double)delta_time/1000);
 
417
 
 
418
        }
 
419
        
 
420
        stelObjectMgr->update((double)delta_time/1000);
 
421
}
 
422
 
 
423
//! Main drawinf function called at each frame
 
424
double StelApp::draw(int delta_time)
 
425
{
 
426
     if (!initialized)
 
427
        return 0.;
 
428
        
 
429
    // clear areas not redrawn by main viewport (i.e. fisheye square viewport)
 
430
        // (because ui can draw outside the main viewport)
 
431
        glClear(GL_COLOR_BUFFER_BIT);
 
432
 
 
433
        distorter->prepare();
 
434
 
 
435
        core->preDraw(delta_time);
 
436
 
 
437
        // Render all the main objects of stellarium
 
438
        double squaredDistance = 0.;
 
439
        // Send the event to every StelModule
 
440
        std::vector<StelModule*> modList = moduleMgr->getCallOrders("draw");
 
441
        for (std::vector<StelModule*>::iterator i=modList.begin();i!=modList.end();++i)
 
442
        {
 
443
                double d = (*i)->draw(core->getProjection(), core->getNavigation(), core->getToneReproducer());
 
444
                if (d>squaredDistance)
 
445
                        squaredDistance = d;
 
446
        }
 
447
 
 
448
        stelObjectMgr->draw(core->getProjection(), core->getNavigation(), core->getToneReproducer());
 
449
 
 
450
        core->postDraw();
 
451
 
 
452
        // Draw the Text ui into the predistorted image
 
453
        ui->draw(core->getProjection(), core->getNavigation(), core->getToneReproducer());
 
454
 
 
455
        distorter->distort();
 
456
 
 
457
        // Draw the Graphical ui
 
458
        ui->drawGui();
 
459
 
 
460
        return squaredDistance;
 
461
}
 
462
 
 
463
/*************************************************************************
 
464
 Call this when the size of the GL window has changed
 
465
*************************************************************************/
 
466
void StelApp::glWindowHasBeenResized(int w, int h)
 
467
{
 
468
        if (core && core->getProjection())
 
469
                core->getProjection()->windowHasBeenResized(getScreenW(),getScreenH());
 
470
        if (ui)
 
471
                ui->resize();
 
472
        // Send the event to every StelModule
 
473
        for (StelModuleMgr::Iterator iter=moduleMgr->begin();iter!=moduleMgr->end();++iter)
 
474
        {
 
475
                (*iter)->glWindowHasBeenResized(w, h);
 
476
        }
 
477
}
 
478
 
 
479
// Handle mouse clics
 
480
int StelApp::handleClick(int x, int y, Uint8 button, Uint8 state, StelMod mod)
 
481
{
 
482
        const int ui_x = x;
 
483
        const int ui_y = y;
 
484
        y = getScreenH() - 1 - y;
 
485
        distorter->distortXY(x,y);
 
486
 
 
487
        if (ui->handle_clic(ui_x, ui_y, button, state, mod)) return 1;
 
488
 
 
489
        // Send the event to every StelModule
 
490
        std::vector<StelModule*> modList = moduleMgr->getCallOrders("handleMouseClicks");
 
491
        for (std::vector<StelModule*>::iterator i=modList.begin();i!=modList.end();++i)
 
492
        {
 
493
                if ((*i)->handleMouseClicks(x, y, button, state, mod)==true)
 
494
                        return 1;
 
495
        }
 
496
        
 
497
        // Manage the event for the main window
 
498
        {
 
499
                // Deselect the selected object
 
500
                if (button==Stel_BUTTON_RIGHT && state==Stel_MOUSEBUTTONUP)
 
501
                {
 
502
                        commander->execute_command("select");
 
503
                        return 1;
 
504
                }
 
505
                MovementMgr* mvmgr = (MovementMgr*)getModuleMgr().getModule("movements");
 
506
                if (button==Stel_BUTTON_LEFT && state==Stel_MOUSEBUTTONUP && !mvmgr->getHasDragged())
 
507
                {
 
508
#ifdef MACOSX
 
509
                        // CTRL + left clic = right clic for 1 button mouse
 
510
                        if (mod & StelMod_CTRL)
 
511
                        {
 
512
                                commander->execute_command("select");
 
513
                                return 1;
 
514
                        }
 
515
 
 
516
                        // Try to select object at that position
 
517
                        getStelObjectMgr().findAndSelect(core, x, y, mod & StelMod_META);
 
518
#else
 
519
                        getStelObjectMgr().findAndSelect(core, x, y, mod & StelMod_CTRL);
 
520
#endif
 
521
                        // If an object was selected update informations
 
522
                        if (getStelObjectMgr().getWasSelected())
 
523
                        {
 
524
                                ((MovementMgr*)moduleMgr->getModule("movements"))->setFlagTracking(false);
 
525
                                ui->updateInfoSelectString();
 
526
                        }
 
527
                }
 
528
        }
 
529
        
 
530
        return 0;
 
531
}
 
532
 
 
533
// Handle mouse move
 
534
int StelApp::handleMove(int x, int y, StelMod mod)
 
535
{
 
536
        const int ui_x = x;
 
537
        const int ui_y = y;
 
538
        y = getScreenH() - 1 - y;
 
539
        distorter->distortXY(x,y);
 
540
        
 
541
        // Send the event to every StelModule
 
542
        std::vector<StelModule*> modList = moduleMgr->getCallOrders("handleMouseMoves");
 
543
        for (std::vector<StelModule*>::iterator i=modList.begin();i!=modList.end();++i)
 
544
        {
 
545
                if ((*i)->handleMouseMoves(x, y, mod)==true)
 
546
                        return 1;
 
547
        }
 
548
        
 
549
        return ui->handle_move(ui_x,ui_y, mod);
 
550
}
 
551
 
 
552
// Handle key press and release
 
553
int StelApp::handleKeys(StelKey key, StelMod mod, Uint16 unicode, Uint8 state)
 
554
{
 
555
 
 
556
        // Standard keys should not be able to be hijacked by modules - Rob
 
557
        // (this could be debated)
 
558
        if (ui->handle_keys_tui(key, state)) return 1;
 
559
 
 
560
        if (ui->handle_keysGUI(key, mod, unicode, state)) return 1;
 
561
 
 
562
        // Send the event to every StelModule
 
563
        std::vector<StelModule*> modList = moduleMgr->getCallOrders("handleKeys");
 
564
        for (std::vector<StelModule*>::iterator i=modList.begin();i!=modList.end();++i)
 
565
        {
 
566
                if ((*i)->handleKeys(key, mod, unicode, state)==true)
 
567
                        return 1;
 
568
        }
 
569
 
 
570
        // Non widget key handling
 
571
        return ui->handle_keys(key, mod, unicode, state);
 
572
}
 
573
 
 
574
 
 
575
//! Set the drawing mode in 2D for drawing in the full screen
 
576
void StelApp::set2DfullscreenProjection() const
 
577
{
 
578
        glViewport(0,0,getScreenW(),getScreenH());
 
579
        glMatrixMode(GL_PROJECTION);            // projection matrix mode
 
580
        glPushMatrix();                                         // store previous matrix
 
581
        glLoadIdentity();
 
582
        glOrtho(0,getScreenW(),0,getScreenH(),-1,1);    // set a 2D orthographic projection
 
583
        glMatrixMode(GL_MODELVIEW);                     // modelview matrix mode
 
584
        glPushMatrix();
 
585
        glLoadIdentity();
 
586
        glScalef(1, -1, 1);                                     // invert the y axis, down is positive
 
587
        glTranslatef(0, -getScreenH(), 0);              // move the origin from the bottom left corner to the upper left corner
 
588
}
 
589
 
 
590
void StelApp::setConfigFile(const string& configName)
 
591
{
 
592
        try
 
593
        {
 
594
                configFile = stelFileMgr->findFile(configName, StelFileMgr::FLAGS(StelFileMgr::WRITABLE|StelFileMgr::FILE));
 
595
                return;
 
596
        }
 
597
        catch(exception& e)
 
598
        {
 
599
                //cerr << "DEBUG StelApp::setConfigFile could not locate writable config file " << configName << endl;
 
600
        }
 
601
        
 
602
        try
 
603
        {
 
604
                configFile = stelFileMgr->findFile(configName, StelFileMgr::FILE);      
 
605
                return;
 
606
        }
 
607
        catch(exception& e)
 
608
        {
 
609
                //cerr << "DEBUG StelApp::setConfigFile could not find read only config file " << configName << endl;
 
610
        }               
 
611
        
 
612
        try
 
613
        {
 
614
                configFile = stelFileMgr->findFile(configName, StelFileMgr::NEW);
 
615
                //cerr << "DEBUG StelApp::setConfigFile found NEW file path: " << configFile << endl;
 
616
                return;
 
617
        }
 
618
        catch(exception& e)
 
619
        {
 
620
                cerr << "ERROR StelApp::setConfigFile could not find or create configuration file " << configName << endl;
 
621
                exit(1);
 
622
        }
 
623
}
 
624
 
 
625
void StelApp::copyDefaultConfigFile()
 
626
{
 
627
        string defaultConfigFilePath;
 
628
        try
 
629
        {
 
630
                defaultConfigFilePath = stelFileMgr->findFile("data/default_config.ini");
 
631
        }
 
632
        catch(exception& e)
 
633
        {
 
634
                cerr << "ERROR (copyDefaultConfigFile): failed to locate data/default_config.ini.  Please check your installation." << endl;
 
635
                exit(1);
 
636
        }
 
637
        
 
638
        StelFileMgr::copy(defaultConfigFilePath, configFile);
 
639
        if (!stelFileMgr->exists(configFile))
 
640
        {
 
641
                cerr << "ERROR (copyDefaultConfigFile): failed to copy file " << defaultConfigFilePath << " to " << configFile << ". You could try to copy it by hand." << endl;
 
642
                exit(1);
 
643
        }
 
644
}
 
645
 
 
646
//! Restore previous projection mode
 
647
void StelApp::restoreFrom2DfullscreenProjection() const
 
648
{
 
649
        glMatrixMode(GL_PROJECTION);            // Restore previous matrix
 
650
        glPopMatrix();
 
651
        glMatrixMode(GL_MODELVIEW);
 
652
        glPopMatrix();
 
653
}
 
654
 
 
655
// Set the colorscheme for all the modules
 
656
void StelApp::setColorScheme(const std::string& fileName, const std::string& section)
 
657
{
 
658
        InitParser conf;
 
659
        conf.load(fileName);
 
660
        
 
661
        // Send the event to every StelModule
 
662
        for (StelModuleMgr::Iterator iter=moduleMgr->begin();iter!=moduleMgr->end();++iter)
 
663
        {
 
664
                (*iter)->setColorScheme(conf, section);
 
665
        }
 
666
        
 
667
        ui->setColorScheme(conf, section);
 
668
}
 
669
 
 
670
//! Set flag for activating night vision mode
 
671
void StelApp::setVisionModeNight()
 
672
{
 
673
        if (!getVisionModeNight())
 
674
        {
 
675
                setColorScheme(getConfigFilePath(), "night_color");
 
676
        }
 
677
        draw_mode=DM_NIGHT;
 
678
}
 
679
 
 
680
//! Set flag for activating chart vision mode
 
681
// ["color" section name used for easier backward compatibility for older configs - Rob]
 
682
void StelApp::setVisionModeNormal()
 
683
{
 
684
        if (!getVisionModeNormal())
 
685
        {
 
686
                setColorScheme(getConfigFilePath(), "color");
 
687
        }
 
688
        draw_mode=DM_NORMAL;
 
689
}
 
690
 
 
691
void StelApp::recordCommand(string commandline)
 
692
{
 
693
        scripts->record_command(commandline);
 
694
}
 
695
 
 
696
 
 
697
// Update translations and font everywhere in the program
 
698
void StelApp::updateAppLanguage()
 
699
{
 
700
        // update translations and font in tui
 
701
        if (ui)
 
702
                ui->localizeTui();
 
703
}
 
704
 
 
705
 
 
706
// Update translations and font for sky everywhere in the program
 
707
void StelApp::updateSkyLanguage()
 
708
{
 
709
        // Send the event to every StelModule
 
710
        for (StelModuleMgr::Iterator iter=moduleMgr->begin();iter!=moduleMgr->end();++iter)
 
711
        {
 
712
                (*iter)->updateI18n();
 
713
        }
 
714
}
 
715
 
 
716
// Update and reload sky culture informations everywhere in the program
 
717
void StelApp::updateSkyCulture()
 
718
{
 
719
        LoadingBar lb(core->getProjection(), 12., "logo24bits.png",
 
720
     core->getProjection()->getViewportWidth(), core->getProjection()->getViewportHeight(),
 
721
      StelUtils::stringToWstring(PACKAGE_VERSION), 45, 320, 121);
 
722
        // Send the event to every StelModule
 
723
        for (StelModuleMgr::Iterator iter=moduleMgr->begin();iter!=moduleMgr->end();++iter)
 
724
        {
 
725
                (*iter)->updateSkyCulture(lb);
 
726
        }
 
727
}