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 );
32 out <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
33 <<
"<kml xmlns=\"http://www.opengis.net/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 );
70 index = starsLine.
mid( 0, 4 ).
toInt();
77 longitude = ( raHH + raMM / 60.0 + raSS / 3600.0 ) * 15.0 - 180.0;
80 double deSign = ( decString.
mid( 0, 1 ) ==
"-" ) ? -1.0 : 1.0;
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() );
98 while ( !streamConstellations.
atEnd() ) {
99 name = streamConstellations.
readLine();
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";
158 while( j != hash.
end() && j.
key() == starIndexes.
at(i).toInt() ) {
159 out <<
" " << j.
value().first <<
"," << j.
value().second <<
" \n";
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[])
iterator insert(const Key &key, const T &value)
const Key key(const T &value) const
QString readLine(qint64 maxlen)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const T & at(int i) const
double toDouble(bool *ok) const
void exit(int returnCode)
void append(const T &value)
int toInt(bool *ok, int base) const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
const T value(const Key &key) const
iterator find(const Key &key)
QString mid(int position, int n) const