|
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: ÑMnrpMapImageService class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32math.h> |
|
21 #include <e32property.h> |
|
22 #include <eikenv.h> |
|
23 #include <gdi.h> |
|
24 |
|
25 #include <lbsposition.h> |
|
26 |
|
27 #include <EPos_CPosLandmark.h> |
|
28 #include <epos_poslandmarkserialization.h> |
|
29 |
|
30 #include <mnmapimage.h> |
|
31 #include <mnmapimageparams.h> |
|
32 #include <mnmapimageservicebase.h> |
|
33 |
|
34 #include "debug.h" |
|
35 #include "mnrpengine.h" |
|
36 #include "mnrpappuiback.h" |
|
37 #include "mnrpappserverback.h" |
|
38 #include "mnrpmapmodel.h" |
|
39 #include "mnrpmapimageservice.h" |
|
40 |
|
41 const TInt KTextFontHeightInTwips = 100; |
|
42 const TInt KItemFontHeightInTwips = 120; |
|
43 |
|
44 const TTimeIntervalMicroSeconds32 KProcessingDelay = 200 * 1000; |
|
45 |
|
46 // ======== LOCAL FUNCTIONS ======== |
|
47 |
|
48 extern void CoordinateToString( TReal aCoord, TDes& aStr ); |
|
49 |
|
50 // ======== MEMBER FUNCTIONS ======== |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CMnrpMapImageService* CMnrpMapImageService::NewL( CMnrpEngine& aEngine ) |
|
56 { |
|
57 CMnrpMapImageService* self = new (ELeave) CMnrpMapImageService( aEngine ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CMnrpMapImageService::CMnrpMapImageService( CMnrpEngine& aEngine ) |
|
68 : iEngine( aEngine ) |
|
69 { |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CMnrpMapImageService::~CMnrpMapImageService() |
|
76 { |
|
77 if ( iProcessor ) |
|
78 { |
|
79 iProcessor->Cancel(); |
|
80 delete iProcessor; |
|
81 } |
|
82 delete iModel; |
|
83 DestroyFonts(); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CMnrpMapImageService::ConstructL() |
|
90 { |
|
91 BaseConstructL(); |
|
92 |
|
93 iEikon = CEikonEnv::Static(); |
|
94 CreateFonts(); |
|
95 |
|
96 iModel = CMnrpMapModel::NewL( iEngine ); |
|
97 iProcessor = CPeriodic::NewL( CActive::EPriorityIdle ); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CMnrpMapImageService::LeaveIfBusyL() |
|
104 { |
|
105 if ( iProcessor->IsActive() ) |
|
106 { |
|
107 LOG("CMnRefProviderMapViewService::LeaveIfBusyL BUSY"); |
|
108 User::Leave( KErrInUse ); |
|
109 } |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CMnrpMapImageService::StartProcessingL() |
|
116 { |
|
117 iProcessor->Start( KProcessingDelay, KProcessingDelay, |
|
118 TCallBack( CMnrpMapImageService::MapImageProcessingCallBack, this ) ); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 TInt CMnrpMapImageService::MapImageProcessingCallBack( TAny* aPtr ) |
|
125 { |
|
126 CMnrpMapImageService* self = |
|
127 static_cast<CMnrpMapImageService*> ( aPtr ); |
|
128 |
|
129 TRAP_IGNORE( self->HandleMapImageCompletedL() ); |
|
130 return EFalse; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CMnrpMapImageService::HandleMapImageCompletedL() |
|
137 { |
|
138 iProcessor->Cancel(); |
|
139 TInt err = KErrNone; |
|
140 TRAP( err, FinishProcessingL() ); |
|
141 if ( err ) |
|
142 { |
|
143 CompleteRequest( err ); |
|
144 } |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CMnrpMapImageService::RenderL() |
|
151 { |
|
152 TMnMapImageParams& params = MapImageParams(); |
|
153 |
|
154 if ( params.Direction() != 0 || |
|
155 params.ImageType() != TMnMapImageParams::ETypeVectorMap ) |
|
156 { |
|
157 User::Leave( KErrNotSupported ); |
|
158 } |
|
159 |
|
160 CFbsBitmap& bitmap = TargetBitmap(); |
|
161 |
|
162 iModel->SetScreenSize( params.Size() ); |
|
163 iModel->UpdateModelL( *this ); |
|
164 iModel->RenderL( bitmap, TRect( params.Size() ), iTextFont, iItemFont ); |
|
165 |
|
166 // complete request |
|
167 params.SetProjectionId(0); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CMnrpMapImageService::CreateFonts() |
|
174 { |
|
175 CGraphicsDevice* screenDevice = iEikon->ScreenDevice(); |
|
176 |
|
177 const CFont* denseFont = iEikon->DenseFont(); |
|
178 TFontSpec fs = denseFont->FontSpecInTwips(); |
|
179 |
|
180 fs.iHeight = KTextFontHeightInTwips; |
|
181 screenDevice->GetNearestFontInTwips( iTextFont, fs ); |
|
182 |
|
183 fs.iHeight = KItemFontHeightInTwips; |
|
184 screenDevice->GetNearestFontInTwips( iItemFont, fs ); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CMnrpMapImageService::DestroyFonts() |
|
191 { |
|
192 CGraphicsDevice* screenDevice = iEikon->ScreenDevice(); |
|
193 |
|
194 screenDevice->ReleaseFont( iItemFont ); |
|
195 screenDevice->ReleaseFont( iTextFont ); |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 void CMnrpMapImageService::FinishProcessingL() |
|
202 { |
|
203 LOG1("FinishProcessingL in, cursvc %d", iCurrentService); |
|
204 TCoordinate coord; |
|
205 switch ( iCurrentService ) |
|
206 { |
|
207 case ERender: |
|
208 { |
|
209 RenderL(); |
|
210 } |
|
211 break; |
|
212 |
|
213 default: |
|
214 User::Leave( KErrGeneral ); |
|
215 } |
|
216 |
|
217 iCurrentService = ENone; |
|
218 CompleteRendering(); |
|
219 LOG("FinishProcessingL out"); |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // From class CMnMapImageServiceBase |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 void CMnrpMapImageService::HandleRenderingL() |
|
227 { |
|
228 LeaveIfBusyL(); |
|
229 |
|
230 iCurrentService = ERender; |
|
231 StartProcessingL(); |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // From class CMnServiceBase |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 void CMnrpMapImageService::DoCancel() |
|
239 { |
|
240 iProcessor->Cancel(); |
|
241 iCurrentService = ENone; |
|
242 } |
|
243 |