1 // StarPlot - A program for interactively viewing 3D maps of stellar positions. 2 // Copyright (C) 2000 Kevin B. McCarty 3 // 4 // This program is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License 6 // as published by the Free Software Foundation; either version 2 7 // of the License, or (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 19 // 20 // stararray.h - The Star Array class. Not much more than a container class 21 // for stars, with the ability to read and filter a text data file on the fly. 22 // 23 24 #ifndef _STAR_ARRAY_H_ 25 #define _STAR_ARRAY_H_ 26 27 #include "../../lib/compat.h" 28 #include "star.h" 29 #include <iostream> 30 #include <fstream> 31 #include <vector> 32 #include <string> 33 #include <cstdlib> 34 #include <cstdio> 35 36 // A typedef to specify the kind of change made to ArrayRules when 37 // setting a new set of rules: 38 enum star_changetype_t { 39 FILE_CHANGE, LOCATION_CHANGE, RADIUS_CHANGE, 40 COORDINATE_CHANGE, FILTER_CHANGE, ORIENTATION_CHANGE, 41 DECORATIONS_CHANGE, UNITS_CHANGE, NO_CHANGE 42 }; 43 44 // Specify the character used to separate records in the data files 45 const char RECORD_DELIMITER = '$'; 46 47 // and the number of stars on the display to label, if the "Landmark Stars" 48 // option is checked 49 const size_t DISPLAY_N_STARS = 8; 50 51 // Do not load more than this number of stars into memory at once, to 52 // avoid DOS'ing oneself. Note that 1000 stars ~ 1 megabyte RAM 53 const size_t MAX_STARS = 20000; 54 55 // offsets of star symbols in legend from the position 56 // {x = width - 75, y = 0} for spectral classes in the order 57 // O, B, A, F, G, K, M, D, unknown, non-stellar, Wolf-Rayet 58 #define LEGEND_OFFSETS_SIZE 11 59 const unsigned int LEGEND_OFFSETS[LEGEND_OFFSETS_SIZE][2] = 60 { {0, 40}, {0, 55}, {0, 70}, {0, 85}, {30, 40}, {30, 55}, 61 {30, 70}, {30, 85}, {80, 115}, {80, 100}, {0, 25} }; 62 63 64 class StarArray { 65 private: 66 typedef std::vector<Star>::iterator iterator; 67 68 std::vector<Star> Array; 69 size_t TotalStars; 70 Rules ArrayRules; 71 72 StarArray(const StarArray &rhs); // these should never 73 StarArray & operator= (const StarArray &rhs); // be implemented. 74 75 void toCelestial(); // convert coordinates for all the stars, 76 void toGalactic(); // as specified. Not public because they should 77 // only be controlled by StarArray::SetRules(). 78 79 void Read(std::ifstream &); // reads and filters data file 80 void Sort(); // sorts the array by x-position in local coords 81 82 // draws a chart legend item 83 void drawlegenditem(StarViewer *sv, color_t color, unsigned int number, 84 unsigned int x, unsigned int y, unsigned int r, 85 const std::string &text, int relx = 10, int rely = 5) 86 const; 87 88 // draw the legend 89 void drawlegend(StarViewer *sv) const; 90 91 // functions to draw the chart grid 92 void drawgridnorth(StarViewer *sv, unsigned int wX, unsigned int wY, 93 unsigned int pixelradius) const; 94 void drawgridsouth(StarViewer *sv, unsigned int wX, unsigned int wY, 95 unsigned int pixelradius) const; 96 void drawgridequator(StarViewer *sv, unsigned int wX, unsigned int wY, 97 unsigned int pixelradius) const; 98 99 public: StarArray()100 StarArray() : Array() { TotalStars = 0; } 101 // no other constructors needed, memory management is automatic in STL 102 103 // some traditional STL thingies 104 typedef std::vector<Star>::const_iterator const_iterator; size()105 inline size_t size() const { return Array.size(); } begin()106 inline const const_iterator begin() const { return Array.begin(); } end()107 inline const const_iterator end() const { return Array.end(); } 108 totalstars()109 inline size_t totalstars() const { return TotalStars; } 110 inline Star & operator [] (size_t i) { return Array[i]; } 111 112 // look up stars containing a certain substring in their names and create 113 // a StarArray of them (ignores the Rules member) 114 void Search(const std::string &searchstring, StringList filelist, 115 const Rules &rules, bool casesensitive = false, 116 bool exactmatch /* i.e. not a substring */ = false, 117 bool exitonmatch /* i.e. return only one match */ = false); 118 119 // set rules for filtering and update the Array of stars using those rules 120 // (default: if type of change is not supplied, assume the most radical 121 // change) 122 bool SetRules(const Rules &rules, star_changetype_t ruleschange=FILE_CHANGE); 123 124 // displays all the stars, plus a grid and some other decorations 125 void Display(StarViewer *sv) const; 126 127 // plots the stars on an HR diagram in range dimmag - brightmag 128 void Diagram(StarViewer *sv, double brightmag, double dimmag) const; 129 }; 130 131 #endif 132