locationtriggering/ltclientlib/src/lbtgeocircle.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of class representing a geographical
       
    15 * circular area.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32math.h>
       
    21 #include "lbtgeocircle.h"
       
    22 #include "lbtgeoareabase.h"
       
    23 #include "lbterrors.h"
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 // ======== LOCAL FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CLbtGeoCircle::NewL()
       
    33 //
       
    34 // (other items were commented in a header).
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C   CLbtGeoCircle* CLbtGeoCircle::NewL() 
       
    38     {
       
    39    	CLbtGeoCircle* self = new( ELeave ) CLbtGeoCircle;
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42 	CleanupStack::Pop( self );  
       
    43 	return self;
       
    44     }
       
    45     
       
    46 // ---------------------------------------------------------------------------
       
    47 // CLbtGeoCircle::NewLC()
       
    48 //
       
    49 // (other items were commented in a header).
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C   CLbtGeoCircle* CLbtGeoCircle::NewLC() 
       
    53     {
       
    54    	CLbtGeoCircle* self = new( ELeave ) CLbtGeoCircle;
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     return self;
       
    58     }    
       
    59     
       
    60 // ---------------------------------------------------------------------------
       
    61 // CLbtGeoCircle::NewL(TCoordinate aCenter,
       
    62 //            TReal aRadius)
       
    63 // (other items were commented in a header).
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 
       
    67 EXPORT_C  CLbtGeoCircle* CLbtGeoCircle::NewL( const TCoordinate& aCenter,
       
    68             TReal aRadiusInMeters )
       
    69 
       
    70     {
       
    71 	CLbtGeoCircle* self = new( ELeave ) CLbtGeoCircle;
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL(aCenter,aRadiusInMeters);
       
    74 	CleanupStack::Pop( self );    
       
    75     return self;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CLbtGeoCircle::NewLC(TCoordinate aCenter,
       
    80 //            TReal aRadius)
       
    81 // (other items were commented in a header).
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 
       
    85 EXPORT_C  CLbtGeoCircle* CLbtGeoCircle::NewLC( const TCoordinate& aCenter,
       
    86             TReal aRadiusInMeters )
       
    87 
       
    88     {
       
    89 	CLbtGeoCircle* self = new( ELeave ) CLbtGeoCircle;
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL(aCenter,aRadiusInMeters);
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CLbtGeoCircle::ConstructL()
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CLbtGeoCircle::ConstructL(TCoordinate aCenter,TReal aRadius)
       
   101     {
       
   102     iCenter=aCenter;
       
   103     if(aRadius<0)
       
   104 		User::Panic(KLbtClientPanicCategory,ELbtErrArgument);
       
   105 	iRadius=aRadius;
       
   106     } 
       
   107    
       
   108    
       
   109 // ---------------------------------------------------------------------------
       
   110 // CLbtGeoCircle::ConstructL()
       
   111 // Symbian 2nd phase constructor can leave.
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CLbtGeoCircle::ConstructL()
       
   115     {
       
   116 	iRadius=0;
       
   117 	}
       
   118 // ---------------------------------------------------------------------------
       
   119 // CLbtGeoCircle::Center()
       
   120 // (other items were commented in a header).
       
   121 // ---------------------------------------------------------------------------
       
   122 //    
       
   123 TCoordinate CLbtGeoCircle::Center() const
       
   124     {
       
   125     // To Do : Check if the center has been set or not. If not then lat long values should be NaN
       
   126 	return iCenter;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // From class CLbtGeoAreaBase.
       
   131 // (other items were commented in a header).
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 CLbtGeoAreaBase::TGeoAreaType CLbtGeoCircle::Type() const
       
   135     {
       
   136 	return CLbtGeoAreaBase::ECircle;
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CLbtGeoCircle::SetCenter()
       
   141 // (other items were commented in a header).
       
   142 // ---------------------------------------------------------------------------
       
   143 //  
       
   144 EXPORT_C void CLbtGeoCircle::SetCenter(const TCoordinate& aCenter )
       
   145     {
       
   146     iCenter=aCenter;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CLbtGeoCircle::Radius()
       
   151 // (other items were commented in a header).
       
   152 // ---------------------------------------------------------------------------
       
   153 // 
       
   154 EXPORT_C TReal CLbtGeoCircle::Radius() const
       
   155     {
       
   156 	return iRadius;
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CLbtGeoCircle::SetRadius()
       
   161 // (other items were commented in a header).
       
   162 // ---------------------------------------------------------------------------
       
   163 // 
       
   164 EXPORT_C void CLbtGeoCircle::SetRadius( TReal aRadiusInMeters )
       
   165     {
       
   166 	if(aRadiusInMeters<0)
       
   167 
       
   168 		User::Panic(KLbtClientPanicCategory,ELbtErrArgument);
       
   169 	
       
   170 	iRadius=aRadiusInMeters;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // CLbtGeoCircle::GetAdditionalGeoAreaInfo()
       
   175 // (other items were commented in a header).
       
   176 // ---------------------------------------------------------------------------
       
   177 // 
       
   178 EXPORT_C RPointerArray< CLbtGeoAreaBase >& CLbtGeoCircle::GetAdditionalGeoAreaInfo()
       
   179     {
       
   180     return iAdditionalGeoAreaInfo;
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CLbtGeoCircle::SetAdditionalGeoAreaInfo()
       
   185 // This method is currently not supported.
       
   186 // ---------------------------------------------------------------------------
       
   187 // 
       
   188 EXPORT_C void CLbtGeoCircle::SetAdditionalGeoAreaInfo(CLbtGeoAreaBase* /*aGeoArea*/)
       
   189     {
       
   190     
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // CLbtGeoCircle::CLbtGeoCircle()
       
   195 // Default constructor
       
   196 // ---------------------------------------------------------------------------
       
   197 // 
       
   198 CLbtGeoCircle::CLbtGeoCircle()
       
   199     {
       
   200 	
       
   201     }
       
   202     
       
   203 // ---------------------------------------------------------------------------
       
   204 // CLbtGeoCircle::~CLbtGeoCircle()
       
   205 // Destructor
       
   206 // ---------------------------------------------------------------------------
       
   207 // 
       
   208 CLbtGeoCircle::~CLbtGeoCircle()
       
   209     {
       
   210 	
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CLbtGeoCircle::DoInternalizeL()
       
   215 // (other items were commented in a header).
       
   216 // ---------------------------------------------------------------------------
       
   217 // 
       
   218 EXPORT_C void CLbtGeoCircle::DoInternalizeL(RReadStream& aStream) 
       
   219     {
       
   220 	TReal64 Lat,Long;
       
   221 	TReal Rad;
       
   222 	TReal32 Alt;
       
   223 	Lat=aStream.ReadReal64L();
       
   224 	Long=aStream.ReadReal64L();
       
   225 	
       
   226     Alt=aStream.ReadReal32L();
       
   227     Rad=aStream.ReadReal32L();
       
   228     iCenter.SetCoordinate(Lat,Long,Alt);
       
   229 	iRadius=Rad;
       
   230 	}
       
   231 // ---------------------------------------------------------------------------
       
   232 // CLbtGeoCircle::DoExternalizeL()
       
   233 // (other items were commented in a header).
       
   234 // ---------------------------------------------------------------------------
       
   235 // 
       
   236 EXPORT_C void CLbtGeoCircle::DoExternalizeL(RWriteStream& aStream) const 
       
   237     {
       
   238 	aStream.WriteReal64L(iCenter.Latitude());
       
   239 	aStream.WriteReal64L(iCenter.Longitude());
       
   240 	aStream.WriteReal32L(iCenter.Altitude());
       
   241 
       
   242 	aStream.WriteReal32L(iRadius);
       
   243 	}
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // CLbtGeoCircle::ValidateGeoCircleInfoL()
       
   247 // (other items were commented in a header).
       
   248 // ---------------------------------------------------------------------------
       
   249 // 
       
   250 void CLbtGeoCircle::ValidateCircleInformationL()
       
   251     {
       
   252     if( Math::IsNaN(iCenter.Latitude()) ||
       
   253         Math::IsNaN(iCenter.Longitude())||
       
   254         iRadius == 0 )
       
   255         {
       
   256         User::Leave( KErrArgument );
       
   257         } 
       
   258     }