[Kstars-devel] [kstars] kstars: Add a method to return an abbreviated direction string from a dms

Akarsh Simha akarsh.simha at kdemail.net
Mon Sep 3 06:46:25 UTC 2012


Git commit 90b274d929719b31f88532254ad76702966fe8b1 by Akarsh Simha.
Committed on 03/09/2012 at 08:44.
Pushed by asimha into branch 'master'.

Add a method to return an abbreviated direction string from a dms
angle, measured from north, towards east.

This method can be used to translate Azimuths and Position Angles into
human-readable format.

CCMAIL: kstars-devel at kde.org

M  +32   -0    kstars/ksutils.cpp
M  +14   -0    kstars/ksutils.h

http://commits.kde.org/kstars/90b274d929719b31f88532254ad76702966fe8b1

diff --git a/kstars/ksutils.cpp b/kstars/ksutils.cpp
index 33fd024..6b5114e 100644
--- a/kstars/ksutils.cpp
+++ b/kstars/ksutils.cpp
@@ -128,3 +128,35 @@ QString KSUtils::getDSSURL( const dms &ra, const dms &dec, float width, float he
     return ( URLprefix + RAString + DecString + SizeString + URLsuffix );
 
 }
+
+QString KSUtils::toDirectionString( dms angle ) {
+    // TODO: Instead of doing it this way, it would be nicer to
+    // compute the string to arbitrary precision. Although that will
+    // not be easy to localize.  (Consider, for instance, Indian
+    // languages that have special names for the intercardinal points)
+    // -- asimha
+
+    static const char *directions[] = {
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "N"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "NNE"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "NE"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "ENE"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "E"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "ESE"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "SE"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "SSE"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "S"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "SSW"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "SW"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "WSW"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "W"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "WNW"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "NW"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "NNW"),
+        I18N_NOOP2( "Abbreviated cardinal / intercardinal etc. direction", "N"),
+    };
+
+    int index = (int)( (angle.Degrees() + 11.25) / 22.5); // A number between 0 and 16 (inclusive), 16 meaning the same thing as zero.
+
+    return i18nc( "Abbreviated cardinal / intercardinal etc. direction", directions[ index ] );
+}
diff --git a/kstars/ksutils.h b/kstars/ksutils.h
index 4b825bd..9c0d8b0 100644
--- a/kstars/ksutils.h
+++ b/kstars/ksutils.h
@@ -113,6 +113,20 @@ namespace KSUtils {
      *@note This method resets height and width to fall within the range accepted by DSS
      */
     QString getDSSURL( const dms &ra, const dms &dec, float width = 0, float height = 0 );
+
+    /**
+     *@short Return a string corresponding to an angle specifying direction
+     *
+     * The angle must measure direction from North, towards East. Both
+     * the azimuth and position angle follow this convention, so this
+     * method can be used to return a string corresponding to the
+     * general heading of a given azimuth / position angle.
+     *
+     *@param angle angle as dms (measured from North, towards East)
+     *@return A localized string corresponding to the approximate direction (eg: NNW)
+     */
+    QString toDirectionString( dms angle );
+
 }
 
 #endif



More information about the Kstars-devel mailing list