15 #include <QApplication>
16 #include <QStringList>
22 using namespace Marble;
24 int main(
int argc,
char *argv[])
28 QFile file(
"constellations.kml" );
29 file.open( QIODevice::WriteOnly );
30 QTextStream out( &file );
32 out <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
33 <<
"<kml xmlns=\"http://earth.google.com/kml/2.2\" hint=\"target=sky\"> \n"
35 <<
" <Style id=\"lineStyle1\"> \n"
37 <<
" <color>ffffffff</color> \n"
40 <<
" <Style id=\"lineStyle2\"> \n"
42 <<
" <color>ffff0000</color> \n"
45 <<
" <Style id=\"iconStyle\"> \n"
48 <<
" <href></href> \n"
53 QFile starsData(
"catalog.dat" );
54 QFile constellationsData(
"constellations.dat" );
56 if ( starsData.open( QFile::ReadOnly ) && constellationsData.open( QFile::ReadOnly ) ) {
58 QTextStream streamConstellations( &constellationsData );
59 QTextStream streamStars( &starsData );
61 QHash<int, QPair<qreal, qreal> > hash;
67 QPair<qreal, qreal> pair;
69 starsLine = streamStars.readLine();
70 index = starsLine.mid( 0, 4 ).toInt();
72 QString recString = starsLine.mid( 75, 6 );
73 double raHH = recString.mid( 0, 2 ).toDouble();
74 double raMM = recString.mid( 2, 2 ).toDouble();
75 double raSS = recString.mid( 4, 2 ).toDouble();
77 longitude = ( raHH + raMM / 60.0 + raSS / 3600.0 ) * 15.0 - 180.0;
79 QString decString = starsLine.mid( 83, 7 );
80 double deSign = ( decString.mid( 0, 1 ) ==
"-" ) ? -1.0 : 1.0;
81 double deHH = decString.mid( 1, 2 ).toDouble();
82 double deMM = decString.mid( 3, 2 ).toDouble();
83 double deSS = decString.mid( 5, 2 ).toDouble();
85 double deValue = deSign * ( deHH + deMM / 60.0 + deSS / 3600.0 );
89 pair.first = longitude;
90 pair.second = latitude;
92 hash.insert( index, pair );
93 }
while ( !starsLine.isNull() );
97 QStringList starIndexes;
98 while ( !streamConstellations.atEnd() ) {
99 name = streamConstellations.readLine();
102 if ( name.isNull() ) {
108 if ( name.startsWith(
'#' ) ) {
112 indexList = streamConstellations.readLine();
115 if ( indexList.isNull() ) {
119 out <<
" <Placemark> \n"
120 <<
" <styleUrl>#lineStyle1</styleUrl> \n"
121 <<
" <MultiGeometry> \n"
122 <<
" <LineString> \n"
123 <<
" <coordinates> \n";
125 starIndexes = indexList.split(
" " );
129 int numberOfStars = 0;
130 for (
int i = 0; i < starIndexes.size(); ++i ) {
131 if ( starIndexes.at(i) ==
"-1" ) {
132 out <<
" </coordinates> \n"
133 <<
" </LineString> \n"
134 <<
" <LineString> \n"
135 <<
" <coordinates> \n";
136 }
else if ( starIndexes.at(i) ==
"-2" ) {
137 out <<
" </coordinates> \n"
138 <<
" </LineString> \n"
139 <<
" </MultiGeometry> \n"
140 <<
" </Placemark> \n"
142 <<
" <styleUrl>#lineStyle2</styleUrl> \n"
143 <<
" <MultiGeometry> \n"
144 <<
" <LineString> \n"
145 <<
" <coordinates> \n";
146 }
else if ( starIndexes.at(i) ==
"-3" ) {
147 out <<
" </coordinates> \n"
148 <<
" </LineString> \n"
149 <<
" </MultiGeometry> \n"
150 <<
" </Placemark> \n"
152 <<
" <styleUrl>#lineStyle1</styleUrl> \n"
153 <<
" <MultiGeometry> \n"
154 <<
" <LineString> \n"
155 <<
" <coordinates> \n";
157 QHash<int, QPair<qreal, qreal> >::const_iterator j = hash.find( starIndexes.at(i).toInt() );
158 while( j != hash.end() && j.key() == starIndexes.at(i).toInt() ) {
159 out <<
" " << j.value().first <<
"," << j.value().second <<
" \n";
160 x.append( cos( j.value().first *
DEG2RAD ) * cos( j.value().second *
DEG2RAD ) );
161 y.append( sin( j.value().first *
DEG2RAD ) * cos( j.value().second *
DEG2RAD ) );
162 z.append( sin( j.value().second *
DEG2RAD ) );
168 out <<
" </coordinates> \n"
169 <<
" </LineString> \n"
170 <<
" </MultiGeometry> \n"
171 <<
" </Placemark> \n";
176 for (
int s = 0; s < numberOfStars; ++s ) {
182 xMean = xMean / numberOfStars;
183 yMean = yMean / numberOfStars;
184 zMean = zMean / numberOfStars;
186 qreal labelLongitude =
RAD2DEG * atan2( yMean, xMean );
187 qreal labelLatitude =
RAD2DEG * atan2( zMean, sqrt( xMean * xMean + yMean * yMean ) );
189 out <<
" <Placemark> \n"
190 <<
" <styleUrl>#iconStyle</styleUrl> \n"
191 <<
" <name>" << name <<
"</name> \n"
193 <<
" <coordinates>" << labelLongitude <<
"," << labelLatitude <<
"</coordinates> \n"
195 <<
" </Placemark> \n";
199 out <<
"</Document> \n"
202 constellationsData.close();
int main(int argc, char *argv[])