[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [marble] src: - Improve the Astro-Coordinate Grid (Right Ascension / Declination)
From:       Torsten Rahn <rahn () kde ! org>
Date:       2013-01-14 1:28:46
Message-ID: 20130114012846.63F86A6091 () git ! kde ! org
[Download RAW message or body]

Git commit 8763562aca3599eee50055f2296df663ea62c3a5 by Torsten Rahn.
Committed on 14/01/2013 at 02:24.
Pushed by rahn into branch 'master'.

- Improve the Astro-Coordinate Grid (Right Ascension / Declination)

- Don't show the Meridian
- Support dynamic grid with gridlines for hours, minutes, seconds
- Fast rendering
- Proper lonToString for Right Ascension
- Activate Astro Notation/Grid automatically with sky map themes.

M  +55   -11   src/lib/geodata/data/GeoDataCoordinates.cpp
M  +49   -31   src/plugins/render/graticule/GraticulePlugin.cpp

http://commits.kde.org/marble/8763562aca3599eee50055f2296df663ea62c3a5

diff --git a/src/lib/geodata/data/GeoDataCoordinates.cpp \
b/src/lib/geodata/data/GeoDataCoordinates.cpp index 18e7569..4e884f7 100644
--- a/src/lib/geodata/data/GeoDataCoordinates.cpp
+++ b/src/lib/geodata/data/GeoDataCoordinates.cpp
@@ -1000,15 +1000,63 @@ QString GeoDataCoordinates::lonToString( qreal lon, \
                GeoDataCoordinates::Notation
             lonString += QString(" %L3'").arg(lonMinF, precision + 1, 'f', precision \
- 2, QChar('0') );  }
     }
-    else if ( notation == Astro ) {
-        lonString = QString::number( lon );
-        lonString += QString( "%1" ).arg( "h 0\' 0\"" );
-        return lonString;
-    }
-    else // notation = GeoDataCoordinates::Decimal
+    else if ( notation == GeoDataCoordinates::Decimal )
     {
         lonString = QString::fromUtf8("%L1\xc2\xb0").arg(lonDegF, 4 + precision, \
format, precision, QChar(' ') );  }
+    else if ( notation == GeoDataCoordinates::Astro )
+    {
+        lon = (lon >= 0) ? lon : lon + 360;
+
+        qreal lonHourF = ( unit == Degree ) ? fabs( lon/15.0  ) : fabs( \
(qreal)(lon/15.0) * RAD2DEG ); +        int lonHour = (int) lonHourF;
+        qreal lonMinF = 60 * (lonHourF - lonHour);
+        int lonMin = (int) lonMinF;
+        qreal lonSecF = 60 * (lonMinF - lonMin);
+        int lonSec = (int) lonSecF;
+
+        // Adjustment for fuzziness (like 49.999999999999999999999)
+        if ( precision == 0 ) {
+            lonHour = qRound( lonHourF );
+        } else if ( precision <= 2 ) {
+            lonMin = qRound( lonMinF );
+        } else if ( precision <= 4 ) {
+            lonSec = qRound( lonSecF );
+        } else {
+            lonSec = lonSecF = qRound( lonSecF * qPow( 10, precision - 4 ) ) / qPow( \
10, precision - 4 ); +        }
+
+        if (lonSec > 59 ) {
+            lonSec = lonSecF = 0;
+            lonMin = lonMinF = lonMinF + 1;
+        }
+        if (lonMin > 59) {
+            lonMin = lonMinF = 0;
+            lonHour = lonHourF = lonHourF + 1;
+        }
+
+        // Evaluate the string
+        lonString = QString::fromUtf8("%1h").arg(lonHour, 3, 10, QChar(' ') );
+
+        if ( precision == 0 ) {
+            return lonString;
+        }
+
+        lonString += QString(" %2\'").arg(lonMin, 2, 10, QChar('0') );
+
+        if ( precision < 3 ) {
+            return lonString;
+        }
+
+        // Includes -1 case!
+        if ( precision < 5 ) {
+            lonString += QString(" %3\"").arg(lonSec, 2, 'f', 0, QChar('0') );
+            return lonString;
+        }
+
+        lonString += QString(" %L3\"").arg(lonSecF, precision - 1, 'f', precision - \
4, QChar('0') ); +        return lonString;
+    }
 
     return lonString + weString;
 }
@@ -1032,7 +1080,7 @@ QString GeoDataCoordinates::latToString( qreal lat, \
GeoDataCoordinates::Notation  // Take care of -1 case
     precision = ( precision < 0 ) ? 5 : precision;
     
-    if ( notation == DMS || notation == DM ) {
+    if ( notation == DMS || notation == DM || notation == Astro) {
         int latDeg = (int) latDegF;
         qreal latMinF = 60 * (latDegF - latDeg);
         int latMin = (int) latMinF;
@@ -1094,10 +1142,6 @@ QString GeoDataCoordinates::latToString( qreal lat, \
                GeoDataCoordinates::Notation
             latString += QString(" %L3'").arg(latMinF, precision + 1, 'f', precision \
- 2, QChar('0') );  }
     }
-    else if ( notation == Astro ) {
-        latString = QString::fromUtf8("%L1\xc2\xb0").arg(latDegF, 4 + precision, \
                format, precision, QChar(' ') );
-        return latString;
-    }
     else // notation = GeoDataCoordinates::Decimal
     {
         latString = QString::fromUtf8("%L1\xc2\xb0").arg(latDegF, 4 + precision, \
                format, precision, QChar(' ') );
diff --git a/src/plugins/render/graticule/GraticulePlugin.cpp \
b/src/plugins/render/graticule/GraticulePlugin.cpp index 84017ad..093d501 100644
--- a/src/plugins/render/graticule/GraticulePlugin.cpp
+++ b/src/plugins/render/graticule/GraticulePlugin.cpp
@@ -328,13 +328,6 @@ void GraticulePlugin::renderGrid( GeoPainter *painter, \
ViewportParams *viewport,  LineStart | IgnoreYMargin */ );
 
         return;
-    } else if ( m_currentNotation == GeoDataCoordinates::Astro ) {
-        renderLatitudeLines( painter, viewLatLonAltBox,
-                             10.0, LineStart | IgnoreYMargin );
-        renderLongitudeLines( painter, viewLatLonAltBox, 15.0,
-                              0.0, 0.0, LineCenter | IgnoreXMargin );
-
-        return;
     }
 
     // Render the normal grid
@@ -378,8 +371,11 @@ void GraticulePlugin::renderGrid( GeoPainter *painter, \
                ViewportParams *viewport,
     renderLatitudeLine( painter, 0.0, viewLatLonAltBox, tr( "Equator" ) );
 
     // Render the Prime Meridian and Antimeridian
-    renderLongitudeLine( painter, 0.0, viewLatLonAltBox, 0.0, 0.0, tr( "Prime \
                Meridian" ) );
-    renderLongitudeLine( painter, 180.0, viewLatLonAltBox, 0.0, 0.0, tr( \
"Antimeridian" ) ); +    GeoDataCoordinates::Notation notation = \
GeoDataCoordinates::defaultNotation(); +    if (marbleModel()->planet()->id() != \
"sky" && notation != GeoDataCoordinates::Astro) { +        renderLongitudeLine( \
painter, 0.0, viewLatLonAltBox, 0.0, 0.0, tr( "Prime Meridian" ) ); +        \
renderLongitudeLine( painter, 180.0, viewLatLonAltBox, 0.0, 0.0, tr( "Antimeridian" ) \
); +    }
 
     QPen tropicsPen = tropicsCirclePen;
     if (   painter->mapQuality() != OutlineQuality
@@ -599,24 +595,6 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
 
     GeoDataCoordinates::Notation notation = GeoDataCoordinates::defaultNotation();
 
-    if ( notation == GeoDataCoordinates::Astro ) {
-
-        qreal hrStep = step;
-        qreal hour;
-        QString label;
-
-        while ( hrStep <= 360.0 ) {
-            hour = hrStep / 360.0 * 24.0;
-            label = GeoDataCoordinates::lonToString( ( hour == 24 ) ? 0 : hour,
-                                                     notation,
-                                                     GeoDataCoordinates::Degree );
-            renderLongitudeLine( painter, hrStep, viewLatLonAltBox, northPolarGap,
-                                southPolarGap, label, labelPositionFlags );
-            hrStep += step;
-        }
-        return;
-    }
-
     // Longitude
     qreal westLon = viewLatLonAltBox.west( GeoDataCoordinates::Degree );
     qreal eastLon = viewLatLonAltBox.east( GeoDataCoordinates::Degree );
@@ -634,6 +612,10 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
             if ( notation == GeoDataCoordinates::UTM ) {
                 int zoneNumber = static_cast<int>( itStep / 6.0 ) + 30;
                 label = QString::number( zoneNumber );
+            } else if ( marbleModel()->planet()->id() == "sky" ) {
+                label = GeoDataCoordinates::lonToString( itStep,
+                                  GeoDataCoordinates::Astro, \
GeoDataCoordinates::Degree, +                                  -1, 'g' );
             } else {
                 label = GeoDataCoordinates::lonToString( itStep,
                                   notation, GeoDataCoordinates::Degree,
@@ -671,6 +653,10 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
             if ( notation == GeoDataCoordinates::UTM ) {
                 int zoneNumber = static_cast<int>( itStep / 6.0 ) + 30;
                 label = QString::number( zoneNumber );
+            } else if ( marbleModel()->planet()->id() == "sky" ) {
+                label = GeoDataCoordinates::lonToString( itStep,
+                                  GeoDataCoordinates::Astro, \
GeoDataCoordinates::Degree, +                                  -1, 'g' );
             } else {
                 label = GeoDataCoordinates::lonToString( itStep,
                                   notation, GeoDataCoordinates::Degree,
@@ -705,6 +691,10 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
             if ( notation == GeoDataCoordinates::UTM ) {
                 int zoneNumber = static_cast<int>( itStep / 6.0 ) + 30;
                 label = QString::number( zoneNumber );
+            } else if ( marbleModel()->planet()->id() == "sky" ) {
+                label = GeoDataCoordinates::lonToString( itStep,
+                                  GeoDataCoordinates::Astro, \
GeoDataCoordinates::Degree, +                                  -1, 'g' );
             } else {
                 label = GeoDataCoordinates::lonToString( itStep,
                                   notation, GeoDataCoordinates::Degree,
@@ -734,7 +724,35 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
 
 void GraticulePlugin::initLineMaps( GeoDataCoordinates::Notation notation)
 {
-    /* Define Upper Bound keys and associated values: */
+    /* Define Upper Bound keys and associated values:
+       The key number is the globe radius in pixel.
+       The value number is the amount of grid lines for the full range.
+
+       Example: up to a 100 pixel radius the globe is covered
+       with 4 longitude lines (4 half-circles).
+     */
+
+    if (marbleModel()->planet()->id() == "sky" || notation == \
GeoDataCoordinates::Astro) { +        m_normalLineMap[100]     = 4;          // 6h
+        m_normalLineMap[1000]    = 12;          // 2h
+        m_normalLineMap[2000]   = 24;         // 1h
+        m_normalLineMap[4000]   = 48;         // 30 min
+        m_normalLineMap[8000]   = 96;         // 15 min
+        m_normalLineMap[16000]  = 288;        // 5 min
+        m_normalLineMap[100000]  = 24 * 60;     // 1 min
+        m_normalLineMap[200000]  = 24 * 60 * 2; // 30 sec
+        m_normalLineMap[400000]  = 24 * 60 * 4; // 15 sec
+        m_normalLineMap[1200000] = 24 * 60 * 12; // 5 sec
+        m_normalLineMap[6000000] = 24 * 60 * 60; // 1 sec
+        m_normalLineMap[12000000] = 24 * 60 * 60 * 2; // 0.5 sec
+        m_normalLineMap[24000000] = 24 * 60 * 60 * 4; // 0.25 sec
+
+        m_boldLineMap[1000]     = 0;        // 0h
+        m_boldLineMap[2000]    = 4;         //  6h
+        m_boldLineMap[16000]    = 24;       //  30 deg
+        return;
+    }
+
     m_normalLineMap[100]     = 4;          // 90 deg
     m_normalLineMap[1000]    = 12;          // 30 deg
     m_normalLineMap[4000]   = 36;         // 10 deg
@@ -742,9 +760,9 @@ void GraticulePlugin::initLineMaps( GeoDataCoordinates::Notation \
notation)  m_normalLineMap[64000]  = 360;         //  1 deg
     m_normalLineMap[128000] = 720;        //  0.5 deg
 
-    m_boldLineMap[1000]     = 0;         //  1 deg
-    m_boldLineMap[4000]    = 12;         //  1 deg
-    m_boldLineMap[16000]   = 36;         //  1 deg
+    m_boldLineMap[1000]     = 0;         //  0 deg
+    m_boldLineMap[4000]    = 12;         //  30 deg
+    m_boldLineMap[16000]   = 36;         //  10 deg
 
     switch ( notation )
     {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic