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

« back to all changes in this revision

Viewing changes to src/constellation_mgr.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:
1
 
/*
2
 
 * Stellarium
3
 
 * Copyright (C) 2002 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
 
// Class used to manage group of constellation
21
 
 
22
 
#include <iostream>
23
 
#include <fstream>
24
 
#include <vector>
25
 
 
26
 
#include "constellation_mgr.h"
27
 
#include "constellation.h"
28
 
#include "hip_star_mgr.h"
29
 
#include "hip_star.h"
30
 
#include "stel_utility.h"
31
 
 
32
 
// constructor which loads all data from appropriate files
33
 
ConstellationMgr::ConstellationMgr(HipStarMgr *_hip_stars) : 
34
 
        asterFont(NULL),
35
 
        hipStarMgr(_hip_stars),
36
 
        selected(NULL),
37
 
        flagNames(0),
38
 
        flagLines(0),
39
 
        flagArt(0),
40
 
        flagBoundaries(0)
41
 
{
42
 
        assert(hipStarMgr);
43
 
        isolateSelected = false;
44
 
}
45
 
 
46
 
ConstellationMgr::~ConstellationMgr()
47
 
{
48
 
        vector<Constellation *>::iterator iter;
49
 
        for (iter = asterisms.begin(); iter != asterisms.end(); iter++)
50
 
        {
51
 
                delete(*iter);
52
 
        }
53
 
 
54
 
        if (asterFont) delete asterFont;
55
 
        asterFont = NULL;
56
 
 
57
 
        vector<vector<Vec3f> *>::iterator iter1;
58
 
        for (iter1 = allBoundarySegments.begin(); iter1 != allBoundarySegments.end(); ++iter1)
59
 
        {
60
 
                delete (*iter1);
61
 
        }
62
 
        allBoundarySegments.clear();
63
 
}
64
 
 
65
 
void ConstellationMgr::setFlagGravityLabel(bool g) {Constellation::gravityLabel = g;}
66
 
 
67
 
void ConstellationMgr::setLineColor(const Vec3f& c) {Constellation::lineColor = c;}
68
 
Vec3f ConstellationMgr::getLineColor() const {return Constellation::lineColor;}
69
 
 
70
 
void ConstellationMgr::setBoundaryColor(const Vec3f& c) {Constellation::boundaryColor = c;}
71
 
Vec3f ConstellationMgr::getBoundaryColor() const {return Constellation::boundaryColor;}
72
 
 
73
 
void ConstellationMgr::setLabelColor(const Vec3f& c) {Constellation::labelColor = c;}
74
 
Vec3f ConstellationMgr::getLabelColor() const {return Constellation::labelColor;}
75
 
 
76
 
void ConstellationMgr::setFont(float font_size, const string& ttfFileName)
77
 
{
78
 
        if (asterFont) delete asterFont;
79
 
        asterFont = new s_font(font_size, ttfFileName);
80
 
        assert(asterFont);
81
 
}
82
 
 
83
 
// Load line and art data from files
84
 
void ConstellationMgr::loadLinesAndArt(const string &fileName, const string &artfileName, const string &boundaryfileName, LoadingBar& lb)
85
 
{
86
 
        
87
 
        std::ifstream inf(fileName.c_str());
88
 
 
89
 
        if (!inf.is_open())
90
 
        {
91
 
                printf("Can't open constellation data file %s\n", fileName.c_str());
92
 
                assert(0);
93
 
        }
94
 
 
95
 
        // delete existing data, if any
96
 
        vector < Constellation * >::iterator iter;
97
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
98
 
        {
99
 
                delete(*iter);
100
 
        }
101
 
        asterisms.clear();
102
 
 
103
 
        Constellation *cons = NULL;
104
 
 
105
 
        string record;
106
 
        int line=0;
107
 
        while(!std::getline(inf, record).eof())
108
 
        {
109
 
                line++;
110
 
                if (record.size()!=0 && record[0]=='#')
111
 
                        continue;
112
 
                cons = new Constellation;
113
 
                if(cons->read(record, hipStarMgr))
114
 
                {
115
 
                        asterisms.push_back(cons);
116
 
                } else
117
 
                { 
118
 
                        cerr << "ERROR on line " << line << "of " << fileName.c_str() << endl;
119
 
                        delete cons;
120
 
                }
121
 
        }
122
 
        inf.close();
123
 
 
124
 
        // Set current states
125
 
        setFlagArt(flagArt);
126
 
        setFlagLines(flagLines);
127
 
        setFlagNames(flagNames);        
128
 
        setFlagBoundaries(flagBoundaries);      
129
 
 
130
 
 
131
 
        FILE *fic = fopen(artfileName.c_str(), "r");
132
 
        if (!fic)
133
 
        {
134
 
                cerr << "Can't open " << artfileName.c_str() << endl;
135
 
                return; // no art, but still loaded constellation data
136
 
        }
137
 
 
138
 
        // Read the constellation art file with the following format :
139
 
        // ShortName texture_file x1 y1 hp1 x2 y2 hp2
140
 
        // Where :
141
 
        // shortname is the international short name (i.e "Lep" for Lepus)
142
 
        // texture_file is the graphic file of the art texture
143
 
        // x1 y1 are the x and y texture coordinates in pixels of the star of hipparcos number hp1
144
 
        // x2 y2 are the x and y texture coordinates in pixels of the star of hipparcos number hp2
145
 
        // The coordinate are taken with (0,0) at the top left corner of the image file
146
 
        char shortname[20];
147
 
        char texfile[255];
148
 
        unsigned int x1, y1, x2, y2, x3, y3, hp1, hp2, hp3;
149
 
        int texSize;
150
 
        
151
 
        char tmpstr[2000];
152
 
        int total = 0;
153
 
 
154
 
        // determine total number to be loaded for percent complete display
155
 
        while (fgets(tmpstr, 2000, fic)) {++total;}
156
 
        rewind(fic);
157
 
 
158
 
        int current = 0;
159
 
 
160
 
        while (!feof(fic))
161
 
        {
162
 
                if (fscanf(fic, "%s %s %u %u %u %u %u %u %u %u %u\n", shortname, texfile, &x1, &y1, &hp1, &x2, &y2, &hp2, &x3, &y3, &hp3) != 11)
163
 
                {
164
 
                        if (feof(fic))
165
 
                        {
166
 
                                // Empty constellation file
167
 
                                fclose(fic);
168
 
                                return;         // no art is OK
169
 
                        }
170
 
                        cerr << "Error while loading art for constellation " <<  shortname << endl;;
171
 
                        assert(0);
172
 
                }
173
 
 
174
 
                // Draw loading bar
175
 
                lb.SetMessage(_("Loading Constellation Art: ") + StelUtility::intToWstring(current+1) + L"/" + StelUtility::intToWstring(total));
176
 
                lb.Draw((float)(current+1)/total);
177
 
                
178
 
                cons = NULL;
179
 
                cons = findFromAbbreviation(shortname);
180
 
                if (!cons)
181
 
                {
182
 
                        cerr << "ERROR : Can't find constellation called : " << shortname << endl;
183
 
                }
184
 
                else
185
 
                {
186
 
                        cons->art_tex = new s_texture(texfile);
187
 
                        texSize = cons->art_tex->getSize();
188
 
 
189
 
                        Vec3f s1 = hipStarMgr->searchHP(hp1)->getObsJ2000Pos();
190
 
                        Vec3f s2 = hipStarMgr->searchHP(hp2)->getObsJ2000Pos();
191
 
                        Vec3f s3 = hipStarMgr->searchHP(hp3)->getObsJ2000Pos();
192
 
 
193
 
                        // To transform from texture coordinate to 2d coordinate we need to find X with XA = B
194
 
                        // A formed of 4 points in texture coordinate, B formed with 4 points in 3d coordinate
195
 
                        // We need 3 stars and the 4th point is deduced from the other to get an normal base
196
 
                        // X = B inv(A)
197
 
                        Vec3f s4 = s1 + (s2 - s1) ^ (s3 - s1);
198
 
                        Mat4f B(s1[0], s1[1], s1[2], 1, s2[0], s2[1], s2[2], 1, s3[0], s3[1], s3[2], 1, s4[0], s4[1], s4[2], 1);
199
 
                        Mat4f A(x1, texSize - y1, 0.f, 1.f, x2, texSize - y2, 0.f, 1.f, x3, texSize - y3, 0.f, 1.f, x1, texSize - y1, texSize, 1.f);
200
 
                        Mat4f X = B * A.inverse();
201
 
 
202
 
                        cons->art_vertex[0] = Vec3f(X * Vec3f(0, 0, 0));
203
 
                        cons->art_vertex[1] = Vec3f(X * Vec3f(texSize / 2, 0, 0));
204
 
                        cons->art_vertex[2] = Vec3f(X * Vec3f(texSize / 2, texSize / 2, 0));
205
 
                        cons->art_vertex[3] = Vec3f(X * Vec3f(0, texSize / 2, 0));
206
 
                        cons->art_vertex[4] = Vec3f(X * Vec3f(texSize / 2 + texSize / 2, 0, 0));
207
 
                        cons->art_vertex[5] = Vec3f(X * Vec3f(texSize / 2 + texSize / 2, texSize / 2, 0));
208
 
                        cons->art_vertex[6] = Vec3f(X * Vec3f(texSize / 2 + texSize / 2, texSize / 2 + texSize / 2, 0));
209
 
                        cons->art_vertex[7] = Vec3f(X * Vec3f(texSize / 2 + 0, texSize / 2 + texSize / 2, 0));
210
 
                        cons->art_vertex[8] = Vec3f(X * Vec3f(0, texSize / 2 + texSize / 2, 0));
211
 
 
212
 
                        current++;
213
 
                }
214
 
        }
215
 
        fclose(fic);
216
 
        
217
 
        loadBoundaries(boundaryfileName);
218
 
        
219
 
}
220
 
 
221
 
void ConstellationMgr::draw(Projector * prj, Navigator * nav) const
222
 
{
223
 
        prj->set_orthographic_projection();
224
 
        draw_lines(prj);
225
 
        draw_names(prj);
226
 
        draw_art(prj, nav);
227
 
        drawBoundaries(prj);
228
 
        prj->reset_perspective_projection();
229
 
}
230
 
 
231
 
// Draw constellations art textures
232
 
void ConstellationMgr::draw_art(Projector * prj, Navigator * nav) const
233
 
{
234
 
        glBlendFunc(GL_ONE, GL_ONE);
235
 
        glEnable(GL_TEXTURE_2D);
236
 
        glEnable(GL_BLEND);
237
 
        glEnable(GL_CULL_FACE);
238
 
 
239
 
        vector < Constellation * >::const_iterator iter;
240
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
241
 
        {
242
 
                (*iter)->draw_art_optim(prj, nav);
243
 
        }
244
 
 
245
 
        glDisable(GL_CULL_FACE);
246
 
}
247
 
 
248
 
// Draw constellations lines
249
 
void ConstellationMgr::draw_lines(Projector * prj) const
250
 
{
251
 
        glDisable(GL_TEXTURE_2D);
252
 
    glDisable(GL_BLEND);
253
 
 
254
 
        vector < Constellation * >::const_iterator iter;
255
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
256
 
        {
257
 
                (*iter)->draw_optim(prj);
258
 
        }
259
 
}
260
 
 
261
 
// Draw the names of all the constellations
262
 
void ConstellationMgr::draw_names(Projector * prj) const
263
 
{
264
 
        glEnable(GL_BLEND);
265
 
        glEnable(GL_TEXTURE_2D);
266
 
        
267
 
        glBlendFunc(GL_ONE, GL_ONE);
268
 
        // if (draw_mode == DM_NORMAL) glBlendFunc(GL_ONE, GL_ONE);
269
 
        // else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // charting
270
 
        
271
 
        vector < Constellation * >::const_iterator iter;
272
 
        for (iter = asterisms.begin(); iter != asterisms.end(); iter++)
273
 
        {
274
 
                // Check if in the field of view
275
 
                if (prj->project_j2000_check((*iter)->XYZname, (*iter)->XYname))
276
 
                        (*iter)->draw_name(asterFont, prj);
277
 
        }
278
 
}
279
 
 
280
 
Constellation *ConstellationMgr::is_star_in(const HipStar * s) const
281
 
{
282
 
        vector < Constellation * >::const_iterator iter;
283
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
284
 
        {
285
 
                // Check if the star is in one of the constellation
286
 
                if ((*iter)->is_star_in(s))
287
 
                        return (*iter);
288
 
        }
289
 
        return NULL;
290
 
}
291
 
 
292
 
Constellation *ConstellationMgr::findFromAbbreviation(const string & abbreviation) const
293
 
{
294
 
        // search in uppercase only
295
 
        string tname = abbreviation;
296
 
        transform(tname.begin(), tname.end(), tname.begin(),::toupper);
297
 
        
298
 
        vector < Constellation * >::const_iterator iter;
299
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
300
 
        {
301
 
                // Check if the star is in one of the constellation
302
 
                if (string((*iter)->abbreviation) == tname)
303
 
                        return (*iter);
304
 
        }
305
 
        return NULL;
306
 
}
307
 
 
308
 
 
309
 
/** 
310
 
 * @brief Read constellation names from the given file
311
 
 * @param namesFile Name of the file containing the constellation names in english
312
 
 */
313
 
void ConstellationMgr::loadNames(const string& namesFile)
314
 
{
315
 
        // Constellation not loaded yet
316
 
        if (asterisms.empty()) return;
317
 
        
318
 
        // clear previous names
319
 
        vector < Constellation * >::const_iterator iter;
320
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
321
 
        {
322
 
                (*iter)->englishName.clear();
323
 
        }
324
 
 
325
 
        // read in translated common names from file
326
 
        ifstream commonNameFile(namesFile.c_str());
327
 
        if (!commonNameFile.is_open())
328
 
        {
329
 
                cerr << "Can't open file" << namesFile << endl;
330
 
                return;
331
 
        }
332
 
        
333
 
        // find matching constellation and update name
334
 
        string record;
335
 
        string tmpShortName;
336
 
        Constellation *aster;
337
 
        while (!std::getline(commonNameFile, record).eof())
338
 
        {
339
 
 
340
 
                if( record != "") {
341
 
                        istringstream in(record); 
342
 
                        in >> tmpShortName;
343
 
 
344
 
                        //      cout << "working on short name " << tmpShortName << endl;
345
 
 
346
 
                        aster = findFromAbbreviation(tmpShortName);
347
 
                        if (aster != NULL)
348
 
                                {
349
 
                                        // Read the names in english
350
 
                                        aster->englishName = record.substr(tmpShortName.length()+1,record.length()).c_str();
351
 
                                }
352
 
                }
353
 
        }
354
 
        commonNameFile.close();
355
 
 
356
 
}
357
 
 
358
 
//! @brief Update i18 names from english names according to current locale
359
 
//! The translation is done using gettext with translated strings defined in translations.h
360
 
void ConstellationMgr::translateNames(Translator& trans)
361
 
{
362
 
        vector < Constellation * >::const_iterator iter;
363
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
364
 
        {
365
 
                (*iter)->nameI18 = trans.translate((*iter)->englishName.c_str());
366
 
                //cout << (*iter)->englishName.c_str() << " -> " << StelUtility::wstringToString((*iter)->nameI18) << endl;
367
 
        }
368
 
}
369
 
 
370
 
// update faders
371
 
void ConstellationMgr::update(int delta_time)
372
 
{
373
 
        vector < Constellation * >::const_iterator iter;
374
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
375
 
        {
376
 
                (*iter)->update(delta_time);
377
 
    }
378
 
}
379
 
 
380
 
 
381
 
void ConstellationMgr::setArtIntensity(float _max)
382
 
{
383
 
        artMaxIntensity = _max;
384
 
        vector < Constellation * >::const_iterator iter;
385
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
386
 
                (*iter)->art_fader.set_max_value(_max);
387
 
}
388
 
 
389
 
void ConstellationMgr::setArtFadeDuration(float duration)
390
 
{
391
 
        artFadeDuration = duration;
392
 
        vector < Constellation * >::const_iterator iter;
393
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
394
 
                (*iter)->art_fader.set_duration((int) (duration * 1000.f));
395
 
}
396
 
 
397
 
void ConstellationMgr::setFlagLines(bool b)
398
 
{
399
 
        flagLines = b;
400
 
        if (selected && isolateSelected)
401
 
        {
402
 
                selected->setFlagLines(b);
403
 
        }
404
 
        else
405
 
        {
406
 
                vector < Constellation * >::const_iterator iter;
407
 
                for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
408
 
                        (*iter)->setFlagLines(b);
409
 
        }
410
 
}
411
 
 
412
 
void ConstellationMgr::setFlagBoundaries(bool b)
413
 
{
414
 
        flagBoundaries = b;
415
 
        if (selected && isolateSelected)
416
 
        {
417
 
                selected->setFlagBoundaries(b);
418
 
        }
419
 
        else
420
 
        {
421
 
                vector < Constellation * >::const_iterator iter;
422
 
                for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
423
 
                        (*iter)->setFlagBoundaries(b);
424
 
        }
425
 
}
426
 
 
427
 
void ConstellationMgr::setFlagArt(bool b)
428
 
{
429
 
        flagArt = b;
430
 
        if (selected && isolateSelected)
431
 
        {
432
 
                selected->setFlagArt(b);
433
 
        }
434
 
        else
435
 
        {
436
 
                vector < Constellation * >::const_iterator iter;
437
 
                for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
438
 
                        (*iter)->setFlagArt(b);
439
 
        }
440
 
}
441
 
 
442
 
 
443
 
void ConstellationMgr::setFlagNames(bool b)
444
 
{
445
 
        flagNames = b;
446
 
        if (selected && isolateSelected)
447
 
        {
448
 
                selected->setFlagName(b);
449
 
        }
450
 
        else
451
 
        {
452
 
                vector < Constellation * >::const_iterator iter;
453
 
                for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
454
 
                        (*iter)->setFlagName(b);
455
 
        }
456
 
}
457
 
 
458
 
void ConstellationMgr::setSelectedConst(Constellation * c)
459
 
{
460
 
        // update states for other constellations to fade them out
461
 
        if (c != NULL)
462
 
        {
463
 
                Constellation* cc;
464
 
                // Propagate old parameters new newly selected constellation
465
 
                if (selected) cc=selected;
466
 
                else cc=*(asterisms.begin());
467
 
                c->setFlagLines(cc->getFlagLines());
468
 
                c->setFlagName(cc->getFlagName());
469
 
                c->setFlagArt(cc->getFlagArt());
470
 
                c->setFlagBoundaries(cc->getFlagBoundaries());
471
 
                selected = c;
472
 
                                
473
 
                if (isolateSelected)
474
 
                {
475
 
                    vector < Constellation * >::const_iterator iter;
476
 
                    for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
477
 
                    {
478
 
                if ((*iter) != selected)
479
 
                    {
480
 
                        (*iter)->setFlagLines(false);
481
 
                            (*iter)->setFlagName(false);
482
 
                            (*iter)->setFlagArt(false);
483
 
                            (*iter)->setFlagBoundaries(false);
484
 
                        }
485
 
             }
486
 
             Constellation::singleSelected = true;
487
 
        }
488
 
                else
489
 
                {
490
 
                        vector < Constellation * >::const_iterator iter;
491
 
                        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
492
 
                        {
493
 
                                        (*iter)->setFlagLines(c->getFlagLines());
494
 
                                        (*iter)->setFlagName(c->getFlagName());
495
 
                                        (*iter)->setFlagArt(c->getFlagArt());
496
 
                            (*iter)->setFlagBoundaries(c->getFlagBoundaries());
497
 
                        }
498
 
             Constellation::singleSelected = false;
499
 
                }
500
 
        }
501
 
        else
502
 
        {
503
 
                if (selected==NULL) return;
504
 
                vector < Constellation * >::const_iterator iter;
505
 
                for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
506
 
                {
507
 
                        if ((*iter) != selected)
508
 
                        {
509
 
                                (*iter)->setFlagLines(selected->getFlagLines());
510
 
                                (*iter)->setFlagName(selected->getFlagName());
511
 
                                (*iter)->setFlagArt(selected->getFlagArt());
512
 
                                (*iter)->setFlagBoundaries(selected->getFlagBoundaries());
513
 
                        }
514
 
                }
515
 
                selected = NULL;
516
 
        }
517
 
}
518
 
 
519
 
// Load from file 
520
 
bool ConstellationMgr::loadBoundaries(const string& boundaryFile)
521
 
{
522
 
        Constellation *cons = NULL;
523
 
        unsigned int i, j;
524
 
        
525
 
        vector<vector<Vec3f> *>::iterator iter;
526
 
        for (iter = allBoundarySegments.begin(); iter != allBoundarySegments.end(); ++iter)
527
 
        {
528
 
                delete (*iter);
529
 
        }
530
 
        allBoundarySegments.clear();
531
 
 
532
 
    cout << "Loading Constellation boundary data...";
533
 
        // Modified boundary file by Torsten Bronger with permission
534
 
        // http://pp3.sourceforge.net
535
 
        
536
 
    ifstream dataFile;
537
 
        dataFile.open(boundaryFile.c_str());
538
 
    if (!dataFile.is_open())
539
 
    {
540
 
        cerr << "Boundary file " << boundaryFile << " not found" << endl;
541
 
        return false;
542
 
    }
543
 
 
544
 
        float DE, RA;
545
 
        float oDE, oRA;
546
 
        Vec3f XYZ;
547
 
        unsigned num, numc;
548
 
        vector<Vec3f> *points = NULL;
549
 
        string consname;
550
 
        i = 0;
551
 
        while (!dataFile.eof()) 
552
 
        {
553
 
                points = new vector<Vec3f>;
554
 
 
555
 
                num = 0;
556
 
                dataFile >> num;
557
 
                if(num == 0) continue;  // empty line
558
 
 
559
 
                for (j=0;j<num;j++)
560
 
                {
561
 
                        dataFile >> RA >> DE;
562
 
 
563
 
                        oRA =RA;
564
 
                        oDE= DE;
565
 
 
566
 
                        RA*=M_PI/12.;     // Convert from hours to rad
567
 
                        DE*=M_PI/180.;    // Convert from deg to rad
568
 
 
569
 
                        // Calc the Cartesian coord with RA and DE
570
 
                sphe_to_rect(RA,DE,XYZ);
571
 
                        points->push_back(XYZ);
572
 
                }
573
 
                
574
 
                // this list is for the de-allocation
575
 
                allBoundarySegments.push_back(points);
576
 
 
577
 
                dataFile >> numc;  
578
 
                // there are 2 constellations per boundary
579
 
                
580
 
                for (j=0;j<numc;j++)
581
 
                {
582
 
                        dataFile >> consname;
583
 
                        // not used?
584
 
                        if (consname == "SER1" || consname == "SER2") consname = "SER";
585
 
                        
586
 
                        cons = findFromAbbreviation(consname);
587
 
                                if (!cons) cout << "ERROR : Can't find constellation called : " << consname << endl;
588
 
                        else cons->isolatedBoundarySegments.push_back(points);
589
 
                }
590
 
 
591
 
                if (cons) cons->sharedBoundarySegments.push_back(points);
592
 
                i++;
593
 
 
594
 
        }
595
 
    dataFile.close();
596
 
        cout << "(" << i << " segments loaded)" << endl;
597
 
    delete points;
598
 
    
599
 
    return true;
600
 
}
601
 
 
602
 
// Draw constellations lines
603
 
void ConstellationMgr::drawBoundaries(Projector * prj) const
604
 
{
605
 
        glDisable(GL_TEXTURE_2D);
606
 
    glDisable(GL_BLEND);
607
 
 
608
 
        glLineStipple(2, 0x3333);
609
 
        glEnable(GL_LINE_STIPPLE);
610
 
 
611
 
        vector < Constellation * >::const_iterator iter;
612
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
613
 
        {
614
 
                (*iter)->draw_boundary_optim(prj);
615
 
        }
616
 
        glDisable(GL_LINE_STIPPLE);
617
 
}
618
 
 
619
 
unsigned int ConstellationMgr::getFirstSelectedHP(void) {
620
 
  if (selected) return selected->asterism[0]->get_hp_number();
621
 
  return 0;
622
 
}
623
 
 
624
 
//! Return the matching constellation object's pointer if exists or NULL
625
 
//! @param nameI18n The case sensistive constellation name
626
 
Constellation* ConstellationMgr::searchByNameI18n(const wstring& nameI18n) const
627
 
{
628
 
        wstring objw = nameI18n;
629
 
        transform(objw.begin(), objw.end(), objw.begin(), ::toupper);
630
 
        
631
 
        vector <Constellation*>::const_iterator iter;
632
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
633
 
        {
634
 
                wstring objwcap = (*iter)->nameI18;
635
 
                transform(objwcap.begin(), objwcap.end(), objwcap.begin(), ::toupper);
636
 
                if (objwcap==objw) return *iter;
637
 
        }
638
 
        return NULL;
639
 
}
640
 
 
641
 
//! Find and return the list of at most maxNbItem objects auto-completing the passed object I18n name
642
 
vector<wstring> ConstellationMgr::listMatchingObjectsI18n(const wstring& objPrefix, unsigned int maxNbItem) const
643
 
{
644
 
        vector<wstring> result;
645
 
        if (maxNbItem==0) return result;
646
 
                
647
 
        wstring objw = objPrefix;
648
 
        transform(objw.begin(), objw.end(), objw.begin(), ::toupper);
649
 
        
650
 
        vector < Constellation * >::const_iterator iter;
651
 
        for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
652
 
        {
653
 
                wstring constw = (*iter)->getNameI18().substr(0, objw.size());
654
 
                transform(constw.begin(), constw.end(), constw.begin(), ::toupper);
655
 
                if (constw==objw)
656
 
                {
657
 
                        result.push_back((*iter)->getNameI18());
658
 
                        if (result.size()==maxNbItem)
659
 
                                return result;
660
 
                }
661
 
        }
662
 
        return result;
663
 
}