~ubuntu-branches/ubuntu/precise/stellarium/precise

« back to all changes in this revision

Viewing changes to src/hip_star_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 groups of Stars
21
 
 
22
 
#include <string>
23
 
#include "hip_star_mgr.h"
24
 
#include "hip_star.h"
25
 
#include "s_texture.h"
26
 
#include "grid.h"
27
 
#include "bytes.h"
28
 
#include "stellarium.h"
29
 
#include "navigator.h"
30
 
#include "stel_utility.h"
31
 
#include "translator.h"
32
 
 
33
 
#define RADIUS_STAR 1.
34
 
 
35
 
// construct and load all data
36
 
HipStarMgr::HipStarMgr() :
37
 
        limitingMag(6.5f),
38
 
        starZones(NULL),
39
 
        StarArray(NULL),
40
 
        starArraySize(0), // This is the full data array including HP, HP SAO (not duplicated)
41
 
        starTexture(NULL)
42
 
{
43
 
        starZones = new vector<HipStar*>[HipGrid.getNbPoints()];
44
 
}
45
 
 
46
 
 
47
 
HipStarMgr::~HipStarMgr()
48
 
{
49
 
        delete starTexture;
50
 
        starTexture=NULL;
51
 
 
52
 
///     delete starcTexture;
53
 
///     starcTexture=NULL;
54
 
        
55
 
        delete HipStar::starFont;
56
 
        HipStar::starFont=NULL;
57
 
 
58
 
        delete [] starZones;
59
 
        starZones=NULL;
60
 
 
61
 
        delete [] StarArray;
62
 
        StarArray=NULL;
63
 
 
64
 
        delete [] StarFlatArray;
65
 
        StarFlatArray=NULL;
66
 
}
67
 
 
68
 
void HipStarMgr::setLabelColor(const Vec3f& c) {HipStar::label_color = c;}
69
 
Vec3f HipStarMgr::getLabelColor(void) {return HipStar::label_color;}
70
 
 
71
 
void HipStarMgr::setCircleColor(const Vec3f& c) {HipStar::circle_color = c;}
72
 
Vec3f HipStarMgr::getCircleColor(void) {return HipStar::circle_color;}
73
 
 
74
 
void HipStarMgr::init(float font_size, const string& font_name, const string& hipCatFile,
75
 
        const string& commonNameFile, const string& sciNameFile, LoadingBar& lb)
76
 
{
77
 
        load_data(hipCatFile, lb);
78
 
        load_double(hipCatFile);
79
 
        load_variable(hipCatFile);
80
 
 
81
 
    load_common_names(commonNameFile);
82
 
        load_sci_names(sciNameFile);
83
 
        
84
 
///     starcTexture = new s_texture("starc64x64.png",TEX_LOAD_TYPE_PNG_BLEND3);  // Load star chart texture
85
 
        starTexture = new s_texture("star16x16.png",TEX_LOAD_TYPE_PNG_SOLID);  // Load star texture
86
 
 
87
 
    HipStar::starFont = new s_font(font_size, font_name);
88
 
    if (!HipStar::starFont)
89
 
    {
90
 
            printf("Can't create starFont\n");
91
 
        assert(0);
92
 
    }   
93
 
}
94
 
 
95
 
// Load from file ( create the stream and call the Read function )
96
 
void HipStarMgr::load_data(const string& hipCatFile, LoadingBar& lb)
97
 
{
98
 
    cout << "Loading Hipparcos star data...";
99
 
    FILE * hipFile;
100
 
    hipFile = NULL;
101
 
 
102
 
    hipFile=fopen(hipCatFile.c_str(),"rb");
103
 
    if (!hipFile)
104
 
    {
105
 
        cerr << "ERROR " << hipCatFile << " NOT FOUND" << endl;
106
 
        assert(0);
107
 
    }
108
 
 
109
 
        // Read number of stars in the Hipparcos catalog
110
 
    unsigned int catalogSize=0;
111
 
    fread((char*)&catalogSize,4,1,hipFile);
112
 
    LE_TO_CPU_INT32(catalogSize,catalogSize);
113
 
 
114
 
    starArraySize = catalogSize;//120417;
115
 
 
116
 
    // Create the sequential array
117
 
    StarArray = new HipStar[starArraySize];
118
 
        
119
 
        StarFlatArray = new HipStar*[starArraySize];
120
 
        for (int i=0;i<starArraySize;++i)
121
 
        {
122
 
                StarFlatArray[i] = NULL;
123
 
        }
124
 
        
125
 
        // Read binary file Hipparcos catalog  
126
 
        unsigned int data_drop =0;
127
 
    HipStar * e = NULL;
128
 
    for(int i=0;i<starArraySize;i++)
129
 
    {
130
 
                if (!(i%2000) || (i == starArraySize-1))
131
 
                {
132
 
                        // Draw loading bar
133
 
                        lb.SetMessage(_("Loading Hipparcos catalog:") + StelUtility::intToWstring((i == starArraySize-1 ? starArraySize: i)) + 
134
 
                                L"/" + StelUtility::intToWstring(starArraySize));
135
 
                        lb.Draw((float)i/starArraySize);
136
 
                }
137
 
                
138
 
                e = &StarArray[i];
139
 
                e->HP=(unsigned int)i;
140
 
        if (!e->read(hipFile))
141
 
        {
142
 
                        data_drop++;
143
 
                continue;
144
 
        }
145
 
        starZones[HipGrid.GetNearest(e->XYZ)].push_back(e);
146
 
                StarFlatArray[e->HP]=e;
147
 
    }
148
 
    fclose(hipFile);
149
 
 
150
 
        printf("(%d stars loaded [%d dropped]).\n", starArraySize-data_drop,data_drop);
151
 
 
152
 
    // sort stars by magnitude for faster rendering
153
 
    for(int i=0;i < HipGrid.getNbPoints();i++) {
154
 
      std::sort( starZones[i].begin(), starZones[i].end(), std::not2(HipStarMagComparer()));
155
 
    }
156
 
}
157
 
 
158
 
// Load common names from file 
159
 
int HipStarMgr::load_common_names(const string& commonNameFile)
160
 
{
161
 
        cout << "Load star names from " << commonNameFile << endl;
162
 
 
163
 
        // clear existing names (would be faster if they were in separate array
164
 
        // since relatively few are named)
165
 
    for (int i=0; i<starArraySize; ++i)
166
 
    {
167
 
                StarArray[i].englishCommonName = "";
168
 
                StarArray[i].commonNameI18 = L"";
169
 
    }
170
 
        
171
 
    FILE *cnFile;
172
 
    cnFile=fopen(commonNameFile.c_str(),"r");
173
 
    if (!cnFile)
174
 
    {   
175
 
        cerr << "Warning " << commonNameFile << " not found." << endl;
176
 
        return 0;
177
 
    }
178
 
 
179
 
        common_names_map.clear();
180
 
//    if (!lstCommonNames.empty())
181
 
//    {
182
 
//       lstCommonNames.clear();
183
 
//       lstCommonNamesHP.clear();
184
 
//    }
185
 
        // Assign names to the matching stars, now support spaces in names
186
 
    unsigned int tmp;
187
 
    char line[256];
188
 
    HipStar *star;
189
 
        fgets(line, 256, cnFile);
190
 
        do
191
 
        {
192
 
                sscanf(line,"%u",&tmp);
193
 
                star = searchHP(tmp);
194
 
                if (star)
195
 
                {
196
 
                        char c=line[0];
197
 
                        int i=0;
198
 
                        while(c!='|' && i<256){c=line[i];++i;}
199
 
                        star->englishCommonName =  &(line[i]);
200
 
                        // remove newline
201
 
                        star->englishCommonName.erase(star->englishCommonName.length()-1, 1);
202
 
 
203
 
                        // remove underscores
204
 
                        for (string::size_type j=0;j<star->englishCommonName.length();++j) {
205
 
                                if (star->englishCommonName[j]=='_') star->englishCommonName[j]=' ';
206
 
                        }
207
 
                        star->commonNameI18 = _(star->englishCommonName.c_str());
208
 
            common_names_map.push_back(star);
209
 
                }
210
 
        } while(fgets(line, 256, cnFile));
211
 
 
212
 
    fclose(cnFile);
213
 
    return 1;
214
 
}
215
 
 
216
 
 
217
 
// Load scientific names from file 
218
 
void HipStarMgr::load_sci_names(const string& sciNameFile)
219
 
{
220
 
        // clear existing names (would be faster if they were in separate arrays
221
 
        // since relatively few are named)
222
 
    for (int i=0; i<starArraySize; i++)
223
 
        {
224
 
                StarArray[i].sciName = L"";
225
 
    }
226
 
 
227
 
        FILE *snFile;
228
 
    snFile=fopen(sciNameFile.c_str(),"r");
229
 
    if (!snFile)
230
 
    {   
231
 
        cerr << "Warning " << sciNameFile.c_str() << " not found" << endl;
232
 
        return;
233
 
    }
234
 
 
235
 
        sci_names_map.clear();
236
 
 
237
 
        // Assign names to the matching stars, now support spaces in names
238
 
    unsigned int tmp;
239
 
    char line[256];
240
 
    HipStar *star;
241
 
        fgets(line, 256, snFile);
242
 
        do
243
 
        {
244
 
                sscanf(line,"%u",&tmp);
245
 
                star = searchHP(tmp);
246
 
                if (star && star->sciName==L"")
247
 
                {
248
 
                        char c=line[0];
249
 
                        int i=0;
250
 
                        while(c!='|' && i<256){c=line[i];++i;}
251
 
                        char* tempc = &(line[i]);
252
 
                        while(c!='_' && i<256){c=line[i];++i;}
253
 
                        line[i-1]=' ';
254
 
                        string sciName = tempc;
255
 
                        sciName.erase(sciName.length()-1, 1);
256
 
                        star->sciName = Translator::UTF8stringToWstring(sciName);
257
 
            sci_names_map.push_back(star);
258
 
                }
259
 
        } while(fgets(line, 256, snFile));
260
 
 
261
 
    fclose(snFile);
262
 
}
263
 
 
264
 
// Draw all the stars
265
 
void HipStarMgr::draw(Vec3f equ_vision, ToneReproductor* eye, Projector* prj)
266
 
{
267
 
 
268
 
        // If stars are turned off don't waste time below
269
 
        // projecting all stars just to draw disembodied labels
270
 
        if(!starsFader.getInterstate()) return;
271
 
 
272
 
        // Set temporary static variable for optimization
273
 
        if (flagStarTwinkle) HipStar::twinkle_amount = twinkleAmount;
274
 
        else HipStar::twinkle_amount = 0;
275
 
        HipStar::star_scale = starScale * starsFader.getInterstate();
276
 
        HipStar::star_mag_scale = starMagScale;
277
 
        HipStar::gravity_label = gravityLabel;
278
 
        HipStar::names_brightness = names_fader.getInterstate() 
279
 
                * starsFader.getInterstate();
280
 
        HipStar::eye = eye;
281
 
        HipStar::proj = prj;
282
 
        
283
 
        if (flagPointStar) {
284
 
                // TODO: fade on/off with starsFader
285
 
                if( starsFader.getInterstate())
286
 
                        drawPoint(equ_vision, eye, prj);
287
 
                return;
288
 
        }
289
 
        
290
 
        glEnable(GL_TEXTURE_2D);
291
 
    glEnable(GL_BLEND);
292
 
    
293
 
        // Find the star zones which are in the screen
294
 
        int nbZones=0;
295
 
 
296
 
        // FOV is currently measured vertically, so need to adjust for wide screens
297
 
        // TODO: projector should probably use largest measurement itself
298
 
        float max_fov = MY_MAX( prj->get_fov(), prj->get_fov()*prj->getViewportWidth()/prj->getViewportHeight());
299
 
 
300
 
        nbZones = HipGrid.Intersect(equ_vision, max_fov*M_PI/180.f*1.2f);
301
 
        static int * zoneList = HipGrid.getResult();
302
 
        //      float maxMag = limiting_mag-1 + 60.f/prj->get_fov();
303
 
        float maxMag = limitingMag-1 + 60.f/max_fov;
304
 
 
305
 
    prj->set_orthographic_projection(); // set 2D coordinate
306
 
 
307
 
        // Print all the stars of all the selected zones
308
 
        static vector<HipStar *>::iterator end;
309
 
        static vector<HipStar *>::iterator iter;
310
 
        HipStar* h;
311
 
 
312
 
        // Bind the star texture
313
 
        //if (draw_mode == DM_NORMAL) 
314
 
        glBindTexture (GL_TEXTURE_2D, starTexture->getID());
315
 
        //else glBindTexture (GL_TEXTURE_2D, starcTexture->getID());
316
 
 
317
 
        // Set the draw mode
318
 
        //if (draw_mode == DM_NORMAL) 
319
 
        glBlendFunc(GL_ONE, GL_ONE);
320
 
        //else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // charting
321
 
 
322
 
        Vec3d XY;
323
 
        for(int i=0;i<nbZones;++i)
324
 
        {
325
 
                end = starZones[zoneList[i]].end();
326
 
            for(iter = starZones[zoneList[i]].begin(); iter!=end; ++iter)
327
 
                {
328
 
                        h=*iter;
329
 
                        // If too small, skip and Compute the 2D position and check if in screen
330
 
                        if(h->Mag > maxMag) break;
331
 
                        if(!prj->project_j2000_check(h->XYZ, XY)) continue;
332
 
 
333
 
                        // if (draw_mode == DM_NORMAL)  
334
 
                        //{
335
 
                                h->draw(XY);
336
 
                                if (names_fader.getInterstate() && h->Mag < maxMagStarName)
337
 
                                {
338
 
                                        if (h->draw_name(XY))
339
 
                                                glBindTexture (GL_TEXTURE_2D, starTexture->getID());
340
 
                                }
341
 
                        //}
342
 
                        //else
343
 
//                      {
344
 
//                              h->draw_chart(XY);
345
 
//                              if (names_fader.getInterstate() && h->Mag < maxMagStarName)
346
 
//                              {
347
 
//                                      // need to rebind the star texture after font printing
348
 
//                                      if (h->draw_name(XY))
349
 
//                                              glBindTexture (GL_TEXTURE_2D, starcTexture->getID());
350
 
//                              }
351
 
//                      }
352
 
 
353
 
                }
354
 
        }
355
 
        
356
 
        prj->reset_perspective_projection();
357
 
}
358
 
 
359
 
// Draw all the stars
360
 
void HipStarMgr::drawPoint(Vec3f equ_vision, ToneReproductor* _eye, Projector* prj)
361
 
{
362
 
        glEnable(GL_TEXTURE_2D);
363
 
    glEnable(GL_BLEND);
364
 
    glBindTexture (GL_TEXTURE_2D, starTexture->getID());
365
 
        glBlendFunc(GL_ONE, GL_ONE);
366
 
 
367
 
        // Find the star zones which are in the screen
368
 
        int nbZones=0;
369
 
        nbZones = HipGrid.Intersect(equ_vision, prj->get_fov()*M_PI/180.f*1.2f);
370
 
        int * zoneList = HipGrid.getResult();
371
 
        float maxMag = 5.5f+60.f/prj->get_fov();
372
 
 
373
 
    prj->set_orthographic_projection(); // set 2D coordinate
374
 
 
375
 
        // Print all the stars of all the selected zones
376
 
        static vector<HipStar *>::iterator end;
377
 
        static vector<HipStar *>::iterator iter;
378
 
        HipStar* h;
379
 
        Vec3d XY;
380
 
        for(int i=0;i<nbZones;++i)
381
 
        {
382
 
                end = starZones[zoneList[i]].end();
383
 
                for(iter = starZones[zoneList[i]].begin(); iter!=end; ++iter)
384
 
                {
385
 
                        h=*iter;
386
 
                        // If too small, skip and Compute the 2D position and check if in screen
387
 
                        if(h->Mag>maxMag) break;
388
 
                        if(!prj->project_j2000_check(h->XYZ, XY)) continue;
389
 
                        h->draw_point(XY);
390
 
                        if (!h->commonNameI18.empty() && names_fader.getInterstate() && h->Mag<maxMagStarName)
391
 
                        {
392
 
                                h->draw_name(XY);
393
 
                                //                              glBindTexture (GL_TEXTURE_2D, starTexture->getID());
394
 
                        }
395
 
                }
396
 
        }
397
 
 
398
 
    prj->reset_perspective_projection();
399
 
}
400
 
 
401
 
// Look for a star by XYZ coords
402
 
HipStar * HipStarMgr::search(Vec3f Pos) const
403
 
{
404
 
    Pos.normalize();
405
 
    HipStar * nearest=NULL;
406
 
    float angleNearest=0.;
407
 
 
408
 
    for(int i=0; i<starArraySize; i++)
409
 
    {
410
 
                if (!StarFlatArray[i]) continue;
411
 
                if      (StarFlatArray[i]->XYZ[0]*Pos[0] + StarFlatArray[i]->XYZ[1]*Pos[1] +
412
 
                        StarFlatArray[i]->XYZ[2]*Pos[2]>angleNearest)
413
 
        {
414
 
                        angleNearest = StarFlatArray[i]->XYZ[0]*Pos[0] +
415
 
                                StarFlatArray[i]->XYZ[1]*Pos[1] + StarFlatArray[i]->XYZ[2]*Pos[2];
416
 
                nearest=StarFlatArray[i];
417
 
        }
418
 
    }
419
 
    if (angleNearest>RADIUS_STAR*0.9999)
420
 
    {   
421
 
            return nearest;
422
 
    }
423
 
    else return NULL;
424
 
}
425
 
 
426
 
// Return a stl vector containing the nebulas located inside the lim_fov circle around position v
427
 
vector<StelObject*> HipStarMgr::search_around(Vec3d v, double lim_fov) const
428
 
{
429
 
        vector<StelObject*> result;
430
 
    v.normalize();
431
 
        double cos_lim_fov = cos(lim_fov * M_PI/180.);
432
 
 
433
 
        for(int i=0; i<starArraySize; i++)
434
 
    {
435
 
                if (!StarFlatArray[i]) continue;
436
 
                if (StarFlatArray[i]->XYZ[0]*v[0] + StarFlatArray[i]->XYZ[1]*v[1] + StarFlatArray[i]->XYZ[2]*v[2]>=cos_lim_fov)
437
 
        {
438
 
                        result.push_back(StarFlatArray[i]);
439
 
        }
440
 
    }
441
 
        return result;
442
 
}
443
 
 
444
 
 
445
 
// Load the double stars from the double star file
446
 
bool HipStarMgr::load_double(const string& hipCatFile)
447
 
{
448
 
        char record[1024];
449
 
        string dataDir = hipCatFile;
450
 
    HipStar *e = NULL;
451
 
        int HP;
452
 
        FILE *dataFile;
453
 
        int i=0;
454
 
        
455
 
        unsigned int loc = dataDir.rfind("/");
456
 
        
457
 
        if (loc != string::npos)
458
 
                dataDir = dataDir.substr(0,loc+1);
459
 
 
460
 
    cout << "Loading Hipparcos double stars...";
461
 
        string hipData = dataDir + "double_txt.dat";
462
 
 
463
 
    dataFile = fopen(hipData.c_str(),"r");
464
 
    if (!dataFile)
465
 
    {
466
 
        cerr << "Hipparcos double star data file " << hipData << " not found" << endl;
467
 
                return false;
468
 
    }
469
 
 
470
 
        while (fgets(record,1024,dataFile))
471
 
        {
472
 
                sscanf(record,"%u", &HP);
473
 
                e = StarFlatArray[HP];
474
 
                if (e)
475
 
                {
476
 
                        e->doubleStar = true;
477
 
                }
478
 
                
479
 
                i++;
480
 
        }
481
 
    fclose(dataFile);
482
 
 
483
 
        cout << "(" << i << " stars loaded)" << endl;
484
 
        return true;
485
 
}
486
 
 
487
 
// Load the variable stars from the raw hip file
488
 
bool HipStarMgr::load_variable(const string& hipCatFile)
489
 
{
490
 
        char record[1024];
491
 
        string dataDir = hipCatFile;
492
 
    HipStar *e = NULL;
493
 
        int HP;
494
 
        FILE *dataFile;
495
 
        int i=0;
496
 
        
497
 
        unsigned int loc = dataDir.rfind("/");
498
 
        
499
 
        if (loc != string::npos)
500
 
                dataDir = dataDir.substr(0,loc+1);
501
 
 
502
 
    cout << "Loading Hipparcos periodic variable stars...";
503
 
        string hipData = dataDir+"variable_txt.dat";
504
 
    dataFile = fopen(hipData.c_str(),"r");
505
 
    if (!dataFile)
506
 
    {
507
 
        cerr << "Hipparcos variable star data file " << hipData << " not found" << endl;
508
 
                return false;
509
 
    }
510
 
 
511
 
        while (fgets(record,1024,dataFile))
512
 
        {
513
 
                sscanf(record,"%u", &HP);
514
 
                e = StarFlatArray[HP];
515
 
                if (e)
516
 
                {
517
 
                        e->variableStar = true;
518
 
                }
519
 
                
520
 
                i++;
521
 
        }
522
 
    fclose(dataFile);
523
 
 
524
 
        cout << "(" << i << " stars loaded)" << endl;
525
 
        return true;
526
 
}
527
 
 
528
 
//! @brief Update i18 names from english names according to passed translator
529
 
//! The translation is done using gettext with translated strings defined in translations.h
530
 
void HipStarMgr::translateNames(Translator& trans)
531
 
{
532
 
 
533
 
        // TODO: separate common names vector would be more efficient
534
 
    for (int i=0; i<starArraySize; ++i)
535
 
    {
536
 
                StarArray[i].commonNameI18 = trans.translate(StarArray[i].englishCommonName);
537
 
    }
538
 
 
539
 
}
540
 
 
541
 
 
542
 
HipStar *HipStarMgr::search(const string& name) const
543
 
{
544
 
        const string catalogs("HP HD SAO");
545
 
 
546
 
        string n = name;
547
 
    for (string::size_type i=0;i<n.length();++i)
548
 
        {
549
 
                if (n[i]=='_') n[i]=' ';
550
 
        }       
551
 
        
552
 
        istringstream ss(n);
553
 
        string cat;
554
 
        unsigned int num;
555
 
        
556
 
        ss >> cat;
557
 
        
558
 
        // check if a valid catalog reference
559
 
        if (catalogs.find(cat,0) == string::npos)
560
 
        {
561
 
                // try see if the string is a HP number
562
 
                istringstream cat_to_num(cat);
563
 
                cat_to_num >> num;
564
 
                if (!cat_to_num.fail()) return searchHP(num);
565
 
                return NULL;
566
 
        }
567
 
 
568
 
        ss >> num;
569
 
        if (ss.fail()) return NULL;
570
 
 
571
 
        if (cat == "HP") return searchHP(num);
572
 
        assert(0);
573
 
        return NULL;
574
 
}       
575
 
 
576
 
// Search the star by HP number
577
 
HipStar *HipStarMgr::searchHP(unsigned int _HP) const
578
 
{
579
 
        if (_HP != 0 && _HP < (unsigned int)starArraySize && StarFlatArray[_HP] 
580
 
                && StarFlatArray[_HP]->HP == _HP)
581
 
                return StarFlatArray[_HP];
582
 
    return NULL;
583
 
}
584
 
 
585
 
HipStar* HipStarMgr::searchByNameI18n(const wstring& nameI18n) const
586
 
{
587
 
        wstring objw = nameI18n;
588
 
        transform(objw.begin(), objw.end(), objw.begin(), ::toupper);
589
 
        
590
 
        // Search by HP number if it's an HP formated number
591
 
        // Please help, if you know a better way to do this:
592
 
        if (nameI18n.length() >= 2 && nameI18n[0]==L'H' && nameI18n[1]==L'P')
593
 
        {
594
 
                bool hp_ok = false;
595
 
                wstring::size_type i=2;
596
 
                // ignore spaces
597
 
                for (;i<nameI18n.length();i++)
598
 
                {
599
 
                        if (nameI18n[i] != L' ') break;
600
 
                }
601
 
                // parse the number
602
 
                unsigned int nr = 0;
603
 
                for (;i<nameI18n.length();i++)
604
 
                {
605
 
                        if (hp_ok = (L'0' <= nameI18n[i] && nameI18n[i] <= L'9'))
606
 
                        {
607
 
                                nr = 10*nr+(nameI18n[i]-L'0');
608
 
                        }
609
 
                        else
610
 
                        {
611
 
                                break;
612
 
                        }
613
 
                }
614
 
                if (hp_ok)
615
 
                {
616
 
                        return searchHP(nr);
617
 
                }
618
 
        }
619
 
                
620
 
        // Search by I18n common name
621
 
        std::vector<HipStar*>::const_iterator iter;
622
 
        for (iter=common_names_map.begin();iter!=common_names_map.end();++iter)
623
 
        {
624
 
                wstring objwcap = (*iter)->commonNameI18;
625
 
                transform(objwcap.begin(), objwcap.end(), objwcap.begin(), ::toupper);
626
 
                if (objwcap==objw) return *iter;
627
 
        }
628
 
        
629
 
        // Search by sci name
630
 
        for (iter=sci_names_map.begin();iter!=sci_names_map.end();++iter)
631
 
        {
632
 
                wstring objwcap = (*iter)->sciName;
633
 
                transform(objwcap.begin(), objwcap.end(), objwcap.begin(), ::toupper);
634
 
                if (objwcap==objw) return *iter;
635
 
        }
636
 
        
637
 
        return NULL;
638
 
}
639
 
 
640
 
//! Find and return the list of at most maxNbItem objects auto-completing the passed object I18n name
641
 
vector<wstring> HipStarMgr::listMatchingObjectsI18n(const wstring& objPrefix, unsigned int maxNbItem) const
642
 
{
643
 
        vector<wstring> result;
644
 
        if (maxNbItem==0) return result;
645
 
        
646
 
        wstring objw = objPrefix;
647
 
        transform(objw.begin(), objw.end(), objw.begin(), ::toupper);
648
 
        
649
 
        // Search by common names
650
 
        std::vector<HipStar*>::const_iterator iter;
651
 
        for (iter = common_names_map.begin(); iter != common_names_map.end(); ++iter)
652
 
        {
653
 
                wstring constw = (*iter)->commonNameI18.substr(0, objw.size());
654
 
                transform(constw.begin(), constw.end(), constw.begin(), ::toupper);
655
 
                if (constw==objw)
656
 
                {
657
 
                        result.push_back((*iter)->commonNameI18);
658
 
                }
659
 
        }
660
 
        
661
 
        // Search by sci names
662
 
        for (iter = sci_names_map.begin(); iter != sci_names_map.end(); ++iter)
663
 
        {
664
 
                wstring constw = (*iter)->sciName.substr(0, objw.size());
665
 
                transform(constw.begin(), constw.end(), constw.begin(), ::toupper);
666
 
                if (constw==objw)
667
 
                {
668
 
                        result.push_back((*iter)->sciName);
669
 
                }
670
 
        }
671
 
        
672
 
        sort(result.begin(), result.end());
673
 
        if (result.size()>maxNbItem) result.erase(result.begin()+maxNbItem, result.end());
674
 
        
675
 
        return result;
676
 
}
677
 
 
678
 
 
679
 
//! Define font file name and size to use for star names display
680
 
void HipStarMgr::setFont(float font_size, const string& font_name) {
681
 
 
682
 
        if (HipStar::starFont) delete HipStar::starFont;
683
 
        HipStar::starFont = new s_font(font_size, font_name);
684
 
        assert(HipStar::starFont);
685
 
 
686
 
}