S60 3rd Edition SDK for Symbian OS
Example Applications Guide

LandmarksUtils.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : LandmarksViewDialog.cpp
00004 *  Part of     : Landmark Reference Application
00005 *  Interface   : -
00006 *  Description : Implements the CLandmarksViewDialog class
00007 *  Version     : 1.0
00008 *
00009 *  Copyright (c) 2004-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include <e32std.h>
00018 #include <e32math.h>
00019 
00020 #include "LandmarksUtils.h"
00021 #include "LandmarksCommonData.h"
00022 
00023 // ============================= STATIC FUNCTIONS ===============================
00024 
00025 // -----------------------------------------------------------------------------
00026 // LandmarksUtils::FloatToDesL
00027 // -----------------------------------------------------------------------------
00028 //
00029 void LandmarksUtils::FloatToDesL(TReal aFloat, TDes& aDes, TRealFormat aRealFormat)
00030     {
00031     if (Math::IsNaN(aFloat))
00032         {
00033         aDes = KNullDesC;
00034         }
00035     else
00036         {
00037         User::LeaveIfError(aDes.Num(aFloat, aRealFormat));
00038         }
00039     }
00040 
00041 // -----------------------------------------------------------------------------
00042 // LandmarksUtils::FloatToDesL
00043 // -----------------------------------------------------------------------------
00044 //
00045 void LandmarksUtils::LatLongToDes(TReal aFloat, TDes& aDes)
00046     {
00047     if (Math::IsNaN(aFloat))
00048         {
00049         aDes = KNullDesC;
00050         }
00051     else
00052         {
00053         aDes.Format(KLatLongFormat, aFloat);
00054         }
00055     }
00056 
00057 // -----------------------------------------------------------------------------
00058 // LandmarksUtils::FloatToDesL
00059 // -----------------------------------------------------------------------------
00060 //
00061 void LandmarksUtils::LatLongFloatToDegMinSecDesL(TReal aLatLong, TDes& aDes)
00062     {
00063     if (!Math::IsNaN(aLatLong))
00064         {
00065         // Convert to deg min sec
00066         SDegMinSec degMinSec;
00067 
00068         // Fetch degrees
00069         User::LeaveIfError(Math::Int(degMinSec.iDegrees, Abs(aLatLong)));
00070 
00071         // Fetch minutes
00072         TReal minutes = (Abs(aLatLong) - degMinSec.iDegrees) * KMinutesPerDegree;
00073         User::LeaveIfError(Math::Int(degMinSec.iMinutes, minutes));
00074 
00075         // Fetch seconds
00076         degMinSec.iSeconds = 
00077             ((minutes - degMinSec.iMinutes) * KSecondsPerMinute);
00078 
00079         // Check if seconds is going to be rounded to 60
00080         const TReal KMaxSeconds = 59.999;
00081         if (degMinSec.iSeconds > KMaxSeconds)
00082             {
00083             degMinSec.iSeconds = 0;
00084             degMinSec.iMinutes++;
00085             if (degMinSec.iMinutes == KMinutesPerDegree)
00086                 {
00087                 degMinSec.iMinutes = 0;
00088                 degMinSec.iDegrees++;
00089                 // We do not need to check if degress > 90 or if degrees > 180.
00090                 // Landmarks FW takes care of that.
00091                 }
00092             }
00093 
00094         // Format output descriptor
00095         if (aLatLong >= 0)
00096             {
00097             aDes.Format(KListBoxLatLongFormat, &KPositiveSign, 
00098                 degMinSec.iDegrees, KDegreeSign, degMinSec.iMinutes, 
00099                 degMinSec.iSeconds);
00100             }
00101         else
00102             {
00103             aDes.Format(KListBoxLatLongFormat, &KNegativeSign, 
00104                 Abs(degMinSec.iDegrees), KDegreeSign, Abs(degMinSec.iMinutes), 
00105                 Abs(degMinSec.iSeconds));
00106             }
00107         }
00108     else
00109         {
00110         aDes.Zero();
00111         }
00112     }
00113 
00114 // -----------------------------------------------------------------------------
00115 // LandmarksUtils::Panic
00116 // -----------------------------------------------------------------------------
00117 //
00118 void LandmarksUtils::Panic(TInt aReason)
00119     {
00120     _LIT(KPanic, "LmRefApp bug");
00121     User::Panic(KPanic, aReason);
00122     }
00123 

© Nokia 2006

Back to top