• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
ksutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ksutils.cpp - K Desktop Planetarium
3  -------------------
4  begin : Mon Jan 7 10:48:09 EST 2002
5  copyright : (C) 2002 by Mark Hollomon
6  email : mhh@mindspring.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "ksutils.h"
19 
20 #include "deepskyobject.h"
21 #include "skyobject.h"
22 #include "Options.h"
23 
24 #include <QFile>
25 #include <qnumeric.h>
26 
27 #include <kstandarddirs.h>
28 #include <KUrl>
29 
30 #include <cmath>
31 
32 bool KSUtils::openDataFile( QFile &file, const QString &s ) {
33  QString FileName = KStandardDirs::locate( "appdata", s );
34  if ( !FileName.isNull() ) {
35  file.setFileName( FileName );
36  return file.open( QIODevice::ReadOnly );
37  }
38  return false;
39 }
40 
41 QString KSUtils::getDSSURL( const SkyPoint * const p ) {
42  const DeepSkyObject *dso = 0;
43  dms ra(0.0), dec(0.0);
44  double height, width;
45 
46  double dss_default_size = Options::defaultDSSImageSize();
47  double dss_padding = Options::dSSPadding();
48 
49  Q_ASSERT( p );
50  Q_ASSERT( dss_default_size > 0.0 && dss_padding >= 0.0 );
51 
52  dso = dynamic_cast<const DeepSkyObject *>( p );
53 
54  // Decide what to do about the height and width
55  if( dso ) {
56  // For deep-sky objects, use their height and width information
57  double a, b, pa;
58  a = dso->a();
59  b = dso->a() * dso->e(); // Use a * e instead of b, since e() returns 1 whenever one of the dimensions is zero. This is important for circular objects
60  pa = dso->pa() * dms::DegToRad;
61 
62  // We now want to convert a, b, and pa into an image
63  // height and width -- i.e. a dRA and dDec.
64  // DSS uses dDec for height and dRA for width. (i.e. "top" is north in the DSS images, AFAICT)
65  // From some trigonometry, assuming we have a rectangular object (worst case), we need:
66  width = a * sin( pa ) + b * cos( pa );
67  height = a * cos( pa ) + b * sin( pa );
68  // 'a' and 'b' are in arcminutes, so height and width are in arcminutes
69 
70  // Pad the RA and Dec, so that we show more of the sky than just the object.
71  height += dss_padding;
72  width += dss_padding;
73  }
74  else {
75  // For a generic sky object, we don't know what to do. So
76  // we just assume the default size.
77  height = width = dss_default_size;
78  }
79  // There's no point in tiny DSS images that are smaller than dss_default_size
80  if( height < dss_default_size )
81  height = dss_default_size;
82  if( width < dss_default_size )
83  width = dss_default_size;
84  // DSS accepts images that are no larger than 75 arcminutes
85  if( height > 75.0 )
86  height = 75.0;
87  if( width > 75.0 )
88  width = 75.0;
89 
90  return getDSSURL( p->ra0(), p->dec0(), width, height );
91 }
92 
93 QString KSUtils::getDSSURL( const dms &ra, const dms &dec, float width, float height, const QString & type) {
94  const QString URLprefix( "http://archive.stsci.edu/cgi-bin/dss_search?v=poss2ukstu_blue" );
95  QString URLsuffix = QString( "&e=J2000&f=%1&c=none&fov=NONE" ).arg(type);
96  const double dss_default_size = Options::defaultDSSImageSize();
97 
98  char decsgn = ( dec.Degrees() < 0.0 ) ? '-' : '+';
99  int dd = abs( dec.degree() );
100  int dm = abs( dec.arcmin() );
101  int ds = abs( dec.arcsec() );
102 
103  // Infinite and NaN sizes are replaced by the default size
104  if( !qIsFinite( height ) )
105  height = dss_default_size;
106  if( !qIsFinite( width ) )
107  width = dss_default_size;
108 
109  // Negative / zero sizes are replaced by the default size
110  if( height <= 0.0 )
111  height = dss_default_size;
112  if( width <= 0.0 )
113  width = dss_default_size;
114 
115  // DSS accepts images that are no larger than 75 arcminutes
116  if( height > 75.0 )
117  height = 75.0;
118  if( width > 75.0 )
119  width = 75.0;
120 
121  QString RAString, DecString, SizeString;
122  DecString = DecString.sprintf( "&d=%c%02d+%02d+%02d", decsgn, dd, dm, ds );
123  RAString = RAString.sprintf( "&r=%02d+%02d+%02d", ra.hour(), ra.minute(), ra.second() );
124  SizeString = SizeString.sprintf( "&h=%02.1f&w=%02.1f", height, width );
125 
126  return ( URLprefix + RAString + DecString + SizeString + URLsuffix );
127 
128 }
129 
130 QString KSUtils::toDirectionString( dms angle ) {
131  // TODO: Instead of doing it this way, it would be nicer to
132  // compute the string to arbitrary precision. Although that will
133  // not be easy to localize. (Consider, for instance, Indian
134  // languages that have special names for the intercardinal points)
135  // -- asimha
136 
137  static const char *directions[] = {
138  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "N"),
139  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "NNE"),
140  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "NE"),
141  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "ENE"),
142  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "E"),
143  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "ESE"),
144  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "SE"),
145  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "SSE"),
146  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "S"),
147  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "SSW"),
148  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "SW"),
149  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "WSW"),
150  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "W"),
151  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "WNW"),
152  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "NW"),
153  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "NNW"),
154  I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "N"),
155  };
156 
157  int index = (int)( (angle.Degrees() + 11.25) / 22.5); // A number between 0 and 16 (inclusive), 16 meaning the same thing as zero.
158 
159  return i18nc( "Abbreviated cardinal / intercardinal etc. direction", directions[ index ] );
160 }
dms::hour
int hour() const
Definition: dms.h:104
SkyPoint::dec0
const dms & dec0() const
Definition: skypoint.h:168
dms::minute
int minute() const
Definition: dms.cpp:174
skyobject.h
deepskyobject.h
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
dms::degree
int degree() const
Definition: dms.h:79
dms::second
int second() const
Definition: dms.cpp:182
SkyPoint::ra0
const dms & ra0() const
Definition: skypoint.h:165
KSUtils::openDataFile
bool openDataFile(QFile &file, const QString &filename)
Attempt to open the data file named filename, using the QFile object "file".
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
DeepSkyObject::a
float a() const
Definition: deepskyobject.h:132
KSUtils::getDSSURL
QString getDSSURL(const SkyPoint *const p)
Create a URL to obtain a DSS image for a given SkyPoint.
i18nc
i18nc("string from libindi, used in the config dialog","100x")
DeepSkyObject::pa
virtual double pa() const
Definition: deepskyobject.h:148
Options::defaultDSSImageSize
static double defaultDSSImageSize()
Get Default size for DSS images.
Definition: Options.h:4426
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
Options.h
DeepSkyObject
Provides all necessary information about a deep-sky object: data inherited from SkyObject (coordinate...
Definition: deepskyobject.h:43
dms::arcsec
int arcsec() const
Definition: dms.cpp:156
KSUtils::toDirectionString
QString toDirectionString(dms angle)
Return a string corresponding to an angle specifying direction.
DeepSkyObject::e
float e() const
Definition: deepskyobject.cpp:81
ksutils.h
Options::dSSPadding
static double dSSPadding()
Get Additional padding around DSS Images of deep-sky objects.
Definition: Options.h:4445
dms::arcmin
int arcmin() const
Definition: dms.cpp:148
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal