mapnavproviderrefapp/inc/mnrpmapmodel.h
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  CMnrpMapModel class definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MNRP_MAPMODEL_H
       
    20 #define MNRP_MAPMODEL_H
       
    21 
       
    22 #include <coecntrl.h>
       
    23 #include "mnrppositionrequest.h"
       
    24 #include "EPos_Landmarks.h"
       
    25 
       
    26 class CFbsBitmap;
       
    27 class CImageDecoder;
       
    28 
       
    29 class CPosLandmark;
       
    30 class CPosLandmarkDatabase;
       
    31 class CPosLmCategoryManager;
       
    32 
       
    33 class CMnrpMapViewService;
       
    34 #ifdef RD_MAPNAV_BITMAP_ACCESS
       
    35 class CMnrpMapImageService;
       
    36 class TMnMapImageParams;
       
    37 #endif
       
    38 class CMnrpEngine;
       
    39 
       
    40 class MImageLoaderObserver;
       
    41 
       
    42 /** Point with real coordinates */
       
    43 class TRealPoint
       
    44     {
       
    45     public:
       
    46         TRealPoint();
       
    47         TRealPoint( TReal aX, TReal aY );
       
    48         TRealPoint( TCoordinate aCoordinate );
       
    49 
       
    50         TRealPoint operator+( const TRealPoint& aRight );
       
    51         TRealPoint operator-( const TRealPoint& aRight );
       
    52         TRealPoint operator*( const TReal& aRight );
       
    53         TRealPoint operator/( const TReal& aRight );
       
    54 
       
    55         void Set( TReal aX, TReal aY );
       
    56         TCoordinate Coordinate();
       
    57         TBool IsValid();
       
    58 
       
    59         TReal iX; // matches longitude in this model
       
    60         TReal iY; // matches latitude in this model
       
    61     };
       
    62 
       
    63 /** Model observer class */
       
    64 class MMapModelObserver
       
    65     {
       
    66     public:
       
    67         virtual void HandleModelUpdateL() =0;
       
    68     };
       
    69 
       
    70 /** Data model for MapView.
       
    71  *  This implementation shows map as rectangle and does not support
       
    72  *  passing its borders. It displays POIs from Engine and client's
       
    73  *	landmarks, which define view area, if not specified by client.
       
    74  */
       
    75 class CMnrpMapModel : public CBase, public MMnrpPositionObserver
       
    76     {
       
    77     public:
       
    78         IMPORT_C static CMnrpMapModel* NewL(
       
    79             MMapModelObserver& aObserver,
       
    80             CMnrpEngine& aEngine );
       
    81 
       
    82         IMPORT_C static CMnrpMapModel* NewL(
       
    83             CMnrpEngine& aEngine );
       
    84 
       
    85         IMPORT_C ~CMnrpMapModel();
       
    86 
       
    87 		/** Service calls it when new ShowOnMap request comes
       
    88 		 *	from client */
       
    89         IMPORT_C void UpdateModelL( CMnrpMapViewService& aService );
       
    90 
       
    91 #ifdef RD_MAPNAV_BITMAP_ACCESS
       
    92 		/** Service calls it when new RenderImage request comes
       
    93 		 *	from client */
       
    94         IMPORT_C void UpdateModelL( const CMnrpMapImageService& aService );
       
    95 
       
    96 		/** Plugin calls it when new CoordinateConversion request comes
       
    97 		 *	from client */
       
    98         IMPORT_C void UpdateModel( const TMnMapImageParams& aParams );
       
    99 #endif
       
   100 		/** Defines dimensions of view used for map display.
       
   101 		 *	this information is used to convert absolute coordinates
       
   102 		 *	to screen coordinates. Absolute coordinates are plain
       
   103 		 *	latitude and longitude degrees.
       
   104 		 */
       
   105         IMPORT_C void SetScreenSize( TSize aScreenSize );
       
   106 
       
   107         IMPORT_C void RenderL(
       
   108             CFbsBitmap& aBitmap,
       
   109             TRect aTargetRect,
       
   110             CFont* aTextFont,
       
   111             CFont* aItemFont ) const;
       
   112         
       
   113         IMPORT_C TInt NumIgnoredLandmarks();
       
   114 
       
   115 		/** Draw item.
       
   116 		 *	It is a POI or client's landmark, holds coordinates
       
   117 		 *	and associated text and icon.
       
   118 		 */
       
   119         class CDrawItem : public CBase
       
   120             {
       
   121             public:
       
   122             	/** Constructs from landmark instance */
       
   123                 static CDrawItem* NewLC( const CPosLandmark& );
       
   124             	/** Constructs from linked landmark. If landmark
       
   125             	 *	does not have icon, it tries to get icon of its
       
   126             	 *	category, if only single category is assigned.
       
   127             	 */
       
   128                 static CDrawItem* NewLC(
       
   129                     const CPosLandmark& aLm,
       
   130                     CPosLmCategoryManager& aCatman );
       
   131 
       
   132                 ~CDrawItem();
       
   133 
       
   134                 const TDesC& Text() { return *iText; };
       
   135                 TPoint& Position() { return iScreenPosition; };
       
   136                 TRealPoint AbsolutePosition() { return iAbsolutePosition; };
       
   137                 CFbsBitmap* Bitmap() { return iBitmap; };
       
   138                 CFbsBitmap* Mask() { return iMask; };
       
   139                 TBool IsPoi() { return iOwnPoi; };
       
   140                 
       
   141                 void SetAbsolutePosition( const TLocality& aLocality );
       
   142 
       
   143             private:
       
   144                 HBufC*      iText;
       
   145                	/** Absolute coordinates - lat,lon */
       
   146                 TRealPoint  iAbsolutePosition;
       
   147                 /** Coordinates on screen (pixels) */
       
   148                 TPoint      iScreenPosition;
       
   149                 CFbsBitmap* iBitmap;
       
   150                 CFbsBitmap* iMask;
       
   151                 /** Whether it is client's landmark or internal POI */
       
   152                 TBool       iOwnPoi;
       
   153 
       
   154             friend class CMnrpMapModel;
       
   155             };
       
   156 		/** Returns all items, that can be shown on screen. Screen
       
   157 		 *	coordinates are updated according to current scale and viewport */
       
   158         TArray<CDrawItem*> Items() const;
       
   159 
       
   160 		/** Describes grid to show */
       
   161         class TGrid
       
   162             {
       
   163             public:
       
   164             	/** Reference grid point (screen) */
       
   165                 TPoint iReference;
       
   166                 /** Distance between grid lines (screen)*/
       
   167                 TInt iGridStep;
       
   168 
       
   169             	/** Coordinate of reference grid point (absolute) */
       
   170                 TCoordinate iAbsoluteReference;
       
   171                 /** Distance between grid lines (absolute) */
       
   172                 TReal iAbsoluteGridStep;
       
   173             };
       
   174 
       
   175         /** Returns grid for current viewport and scale */
       
   176         void GetGrid( TGrid& aGrid ) const;
       
   177 
       
   178         /** Information about current location */
       
   179         class TCurrentLocation
       
   180             {
       
   181             public:
       
   182             	/** Screen coordinates */
       
   183                 TPoint  iLocation;
       
   184             	/** Error radius in screen units - pixels */
       
   185                 TInt    iErrorRadius;
       
   186 
       
   187                 /** Absolute coordinates */
       
   188                 TCoordinate iAbsoluteLocation;
       
   189             	/** Error radius in degrees */
       
   190                 TReal       iAbsoluteErrorDegrees;
       
   191 
       
   192                 TBool       iIsValid;
       
   193             };
       
   194 
       
   195         /** Returns current location */
       
   196         IMPORT_C TCurrentLocation CurrentLocation() const;
       
   197 
       
   198 		// Zooming
       
   199         IMPORT_C void Zoom( TReal aZoomRate );
       
   200 
       
   201 		// View movement
       
   202         IMPORT_C void MoveTo( TCoordinate aTarget );
       
   203 
       
   204         // Reset-kind of action, moves to world center
       
   205         IMPORT_C void GoCenter();
       
   206 
       
   207 		/** Converts absolute units to screen */
       
   208         IMPORT_C TPoint AbsoluteToScreen( TCoordinate aAbsolutePoint ) const;
       
   209         IMPORT_C TInt AbsoluteToScreen( TReal aDistance ) const;
       
   210 
       
   211 		/** Converts screen coords to absolute */
       
   212         IMPORT_C TCoordinate ScreenToAbsolute( TPoint aScreenPoint ) const;
       
   213         IMPORT_C TReal ScreenToAbsolute( TInt aDistance ) const;
       
   214 
       
   215 		// Viewport in absolute units - degrees
       
   216         IMPORT_C TReal Left() const;
       
   217         IMPORT_C TReal Top() const;
       
   218         IMPORT_C TReal Right() const;
       
   219         IMPORT_C TReal Bottom() const;
       
   220         IMPORT_C TReal Width() const;
       
   221         IMPORT_C TReal Height() const;
       
   222         IMPORT_C TCoordinate Center() const;
       
   223 
       
   224     protected:
       
   225 		/** Converts absolute coords to screen */
       
   226         TPoint AbsoluteToScreen( TRealPoint aAbsolutePoint ) const;
       
   227 
       
   228     protected:  // from MMnrpPositionObserver
       
   229 
       
   230 		/** Forces map view update when new position comes */
       
   231         void HandlePositionRequestCompletedL( TInt aError );
       
   232 
       
   233     private:
       
   234 
       
   235         void ConstructL();
       
   236         CMnrpMapModel( MMapModelObserver& aObserver, CMnrpEngine& aEngine );
       
   237         CMnrpMapModel( CMnrpEngine& aEngine );
       
   238 
       
   239         void AddCitiesL();
       
   240 
       
   241 		/** Includes given draw item into bounding box */
       
   242         void AdjustBoundingBox( CDrawItem& aItem, TRealPoint& aMin, TRealPoint& aMax );
       
   243         
       
   244         /** Verifies if draw item has position. If not, tries geocoding.
       
   245          *  Updates the item if position is found from geocoding.
       
   246          *  @return ETrue if position is found (possibly from geocoding), EFalse otherwise */
       
   247         TBool CheckDrawItemHasPositionL( CDrawItem& aItem, const CPosLandmark& aLandmark );
       
   248 
       
   249 		/** Adjusts viewport if movement or zooming goes beyond the borders */
       
   250         void CheckBorders();
       
   251 
       
   252         TReal MaxScale() const;
       
   253         TRect CursorMargin();
       
   254 
       
   255 		// Grid drawing
       
   256         void DrawGrid(
       
   257             CFbsBitGc& aGc,
       
   258             const TSize& aBoxSize,
       
   259             CMnrpMapModel::TGrid& aGrid ) const;
       
   260 
       
   261         void DrawVerticalLine( CFbsBitGc& aGc, TInt aX, TSize aBoxSize ) const;
       
   262         void DrawHorizontalLine( CFbsBitGc& aGc, TInt aY, TSize aBoxSize ) const;
       
   263 
       
   264 		/** Draws drawable items */
       
   265         void DrawLandmarks(
       
   266             CFbsBitGc& aGc,
       
   267             CFont& aFont,
       
   268             const TSize& aBoxSize,
       
   269             TBool aSwitchColorAndShadow ) const;
       
   270 
       
   271 		/** Draws current location */
       
   272         void DrawCurrentLocation(
       
   273             CFbsBitGc& aGc,
       
   274             const TSize& aBoxSize ) const;
       
   275 
       
   276     private:
       
   277         CMnrpPositionRequest*           iPositionRequest;
       
   278         TPositionInfo                   iPosInfo;
       
   279 
       
   280         TSize                           iScreenSize;
       
   281         TRealPoint                      iViewOrigin;
       
   282 
       
   283         TReal                           iScale; // 1 == 1 degree per pixel
       
   284 
       
   285         MMapModelObserver*              iObserver;
       
   286 
       
   287         mutable RPointerArray<CDrawItem> iDrawItems;
       
   288 
       
   289         CMnrpEngine&            		iEngine;
       
   290 
       
   291         TBool                           iUseCurrentLocationAsOrigin;
       
   292         TBool                           iShowCurrentLocation;
       
   293 
       
   294         CFont*                          iTextFont;
       
   295         CFont*                          iItemFont;
       
   296         
       
   297         TInt 							iNumIgnoredLandmarks; 
       
   298     };
       
   299 
       
   300 #endif // MNRP_MAPMODEL_H
       
   301