1 /* |
|
2 * Copyright (c) 2005-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "T_DataPolygonFiller.h" |
|
20 #include "T_GraphicsUtil.h" |
|
21 |
|
22 _LIT(KDataClassname, "CPolygonFiller"); |
|
23 |
|
24 /// Fields |
|
25 _LIT(KFldScanLine, "scanline"); |
|
26 _LIT(KFldPointList, "pointlist"); |
|
27 _LIT(KFldFillRule, "fillrule"); |
|
28 _LIT(KFldUsage, "usage"); |
|
29 _LIT(KFldnumPoints, "numpoints"); |
|
30 _LIT(KFldExpectedScanLine, "expectedscanline"); |
|
31 _LIT(KFldExpectedStart, "expectedstart"); |
|
32 _LIT(KFldExpectedEnd, "expectedend"); |
|
33 _LIT(KFldExpectedExists, "expectedexists"); |
|
34 /// Commands |
|
35 _LIT(KCmdnewL, "new"); |
|
36 _LIT(KCmdConstructL, "Construct"); |
|
37 _LIT(KCmdDestructorGeneral, "~"); |
|
38 _LIT(KCmdDestructor, "~CPolygonFiller"); |
|
39 _LIT(KCmdReset, "Reset"); |
|
40 _LIT(KCmdGetNextPixelRun, "GetNextPixelRun"); |
|
41 _LIT(KCmdGetNextPixelRunOnSpecifiedScanLine, "GetNextPixelRunOnSpecifiedScanLine"); |
|
42 |
|
43 //Log |
|
44 _LIT(KLogErrNum, "Error=%d"); |
|
45 _LIT(KLogInfoCmdnewL, "execute new CPolygonFiller()"); |
|
46 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
47 _LIT(KLogInfoCmdDestructor1, "execute ~CPolygonFiller()"); |
|
48 _LIT(KLogInfoCmdConstruct1, "execute Construct(TPoint*, TInt, TFillRule,TUsage)"); |
|
49 _LIT(KLogInfoCmdConstruct2, "execute Construct(CArrayFix<TPoint>*, TFillRule,TUsage)"); |
|
50 _LIT(KLogInfoCmdReset, "execute Reset()"); |
|
51 _LIT(KLogInfoCmdGetNextPixelRun, "execute GetNextPixelRun()"); |
|
52 _LIT(KLogInfoCmdGetNextPixelRunOnSpecifiedScanLine, "execute GetNextPixelRunOnSpecifiedScanLine()"); |
|
53 _LIT(KLogInfoNotCheckThePosition, "Won't check the position on the scan line in the test case"); |
|
54 CT_DataPolygonFiller* CT_DataPolygonFiller::NewL() |
|
55 { |
|
56 CT_DataPolygonFiller* ret = new (ELeave) CT_DataPolygonFiller(); |
|
57 CleanupStack::PushL(ret); |
|
58 ret->ConstructL(); |
|
59 CleanupStack::Pop(ret); |
|
60 return ret; |
|
61 } |
|
62 |
|
63 CT_DataPolygonFiller::CT_DataPolygonFiller() |
|
64 : iPolygonFiller(NULL) |
|
65 { |
|
66 } |
|
67 |
|
68 void CT_DataPolygonFiller::ConstructL() |
|
69 { |
|
70 iPointsArray=NULL; |
|
71 iPoints=NULL; |
|
72 } |
|
73 |
|
74 CT_DataPolygonFiller::~CT_DataPolygonFiller() |
|
75 { |
|
76 DestroyData(); |
|
77 |
|
78 delete iPointsArray; |
|
79 iPointsArray=NULL; |
|
80 |
|
81 delete[] iPoints; |
|
82 iPoints=NULL; |
|
83 } |
|
84 |
|
85 TAny* CT_DataPolygonFiller::GetObject() |
|
86 { |
|
87 return iPolygonFiller; |
|
88 } |
|
89 |
|
90 void CT_DataPolygonFiller::SetObjectL(TAny* aAny) |
|
91 { |
|
92 DestroyData(); |
|
93 iPolygonFiller = static_cast<CPolygonFiller*> (aAny); |
|
94 } |
|
95 |
|
96 void CT_DataPolygonFiller::DisownObjectL() |
|
97 { |
|
98 iPolygonFiller = NULL; |
|
99 } |
|
100 |
|
101 void CT_DataPolygonFiller::DestroyData() |
|
102 { |
|
103 DoCmdDestructor(); |
|
104 } |
|
105 |
|
106 |
|
107 /** |
|
108 * Process a command read from the ini file |
|
109 * |
|
110 * @param aCommand the command to process |
|
111 * @param aSection the entry in the ini file requiring the command to be processed |
|
112 * @return ETrue if the command is processed |
|
113 */ |
|
114 TBool CT_DataPolygonFiller::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt) |
|
115 { |
|
116 TBool ret = ETrue; |
|
117 |
|
118 if ( aCommand==KCmdDestructorGeneral || aCommand==KCmdDestructor ) |
|
119 { |
|
120 DoCmdDestructor(); |
|
121 } |
|
122 else if ( aCommand==KCmdnewL || aCommand==KDataClassname ) |
|
123 { |
|
124 DoCmdnewL(); |
|
125 } |
|
126 else if(aCommand==KCmdConstructL) |
|
127 { |
|
128 DoCmdConstructL(aSection); |
|
129 } |
|
130 else if ( aCommand==KCmdReset ) |
|
131 { |
|
132 DoCmdReset(); |
|
133 } |
|
134 else if ( aCommand==KCmdGetNextPixelRun ) |
|
135 { |
|
136 DoCmdGetNextPixelRun(aSection); |
|
137 } |
|
138 else if ( aCommand==KCmdGetNextPixelRunOnSpecifiedScanLine ) |
|
139 { |
|
140 DoCmdGetNextPixelRunOnSpecifiedScanLine(aSection); |
|
141 } |
|
142 else |
|
143 { |
|
144 ret=EFalse; |
|
145 } |
|
146 return ret; |
|
147 } |
|
148 |
|
149 void CT_DataPolygonFiller::DoCmdnewL() |
|
150 { |
|
151 DestroyData(); |
|
152 TInt err = KErrNone; |
|
153 INFO_PRINTF1(KLogInfoCmdnewL); |
|
154 TRAP(err, iPolygonFiller = new (ELeave) CPolygonFiller()); |
|
155 if ( err!=KErrNone ) |
|
156 { |
|
157 ERR_PRINTF2(KLogErrNum, err); |
|
158 SetError(err); |
|
159 } |
|
160 } |
|
161 |
|
162 void CT_DataPolygonFiller::DoCmdConstructL(const TDesC& aSection) |
|
163 { |
|
164 TBool dataOk=ETrue; |
|
165 TInt datNumPoints=0; |
|
166 TInt err=0; |
|
167 CGraphicsContext::TFillRule datFillRule=CGraphicsContext::EAlternate; |
|
168 CPolygonFiller::TUsage datUsage=CPolygonFiller::EGetAllPixelRunsSequentially; |
|
169 |
|
170 CT_GraphicsUtil::ReadFillRule(*this, aSection, KFldFillRule, datFillRule); |
|
171 CT_GraphicsUtil::ReadTUsage(*this,aSection,KFldUsage,datUsage); |
|
172 |
|
173 //Use TPoint parameter to construct if the number of points in the list is assigned. |
|
174 if (GetIntFromConfig(aSection, KFldnumPoints, datNumPoints)) |
|
175 { |
|
176 iPoints=new (ELeave) TPoint[datNumPoints]; |
|
177 if ( !GetPointListFromConfig(aSection, KFldPointList, datNumPoints, iPoints)) |
|
178 { |
|
179 ERR_PRINTF2(KLogMissingParameter, &KFldPointList()); |
|
180 SetBlockResult(EFail); |
|
181 } |
|
182 else |
|
183 { |
|
184 // Execute command and log parameters |
|
185 INFO_PRINTF1(KLogInfoCmdConstruct1); |
|
186 iPolygonFiller->Construct(iPoints, datNumPoints, datFillRule, datUsage); |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 iPointsArray=new (ELeave) CArrayFixFlat<TPoint>(1); |
|
192 TBool hasPointList=GetPointListFromConfigL(aSection, KFldPointList, *iPointsArray); |
|
193 |
|
194 if ( !hasPointList ) |
|
195 { |
|
196 ERR_PRINTF2(KLogMissingParameter, &KFldPointList()); |
|
197 SetBlockResult(EFail); |
|
198 } |
|
199 else |
|
200 { |
|
201 // Execute command and log parameters |
|
202 INFO_PRINTF1(KLogInfoCmdConstruct2); |
|
203 iPolygonFiller->Construct(iPointsArray,datFillRule,datUsage); |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 void CT_DataPolygonFiller::DoCmdDestructor() |
|
209 { |
|
210 INFO_PRINTF1(KLogInfoCmdDestructor1); |
|
211 delete iPolygonFiller; |
|
212 iPolygonFiller = NULL; |
|
213 } |
|
214 |
|
215 void CT_DataPolygonFiller::DoCmdReset() |
|
216 { |
|
217 INFO_PRINTF1(KLogInfoCmdReset); |
|
218 iPolygonFiller->Reset(); |
|
219 } |
|
220 |
|
221 void CT_DataPolygonFiller::DoCmdGetNextPixelRun(const TDesC& aSection) |
|
222 { |
|
223 TBool relExists,expectedExists; |
|
224 TInt relScanLine,relStart,relEnd,expectedScanLine,expectedStart,expectedEnd; |
|
225 INFO_PRINTF1(KLogInfoCmdGetNextPixelRun); |
|
226 iPolygonFiller->GetNextPixelRun(relExists,relScanLine,relStart,relEnd); |
|
227 //Verify the scanline is expected |
|
228 if(!GetBoolFromConfig(aSection,KFldExpectedExists,expectedExists)) |
|
229 { |
|
230 ERR_PRINTF2(KLogMissingParameter, &KFldExpectedExists); |
|
231 SetBlockResult(EFail); |
|
232 } |
|
233 else if(relExists!=expectedExists) |
|
234 { |
|
235 ERR_PRINTF3(_L("The returned Exists value is not as expected, expected: %d, result: %d"), expectedExists , relExists); |
|
236 SetBlockResult(EFail); |
|
237 } |
|
238 if(!GetIntFromConfig(aSection,KFldExpectedScanLine,expectedScanLine)) |
|
239 { |
|
240 ERR_PRINTF2(KLogMissingParameter, &KFldExpectedScanLine); |
|
241 SetBlockResult(EFail); |
|
242 } |
|
243 else if(relScanLine!=expectedScanLine) |
|
244 { |
|
245 ERR_PRINTF3(_L("The returned Scanline value is not as expected, expected: %d, result: %d"), expectedScanLine , relScanLine); |
|
246 SetBlockResult(EFail); |
|
247 } |
|
248 //Verify the start position on the scan line |
|
249 if(!GetIntFromConfig(aSection,KFldExpectedStart,expectedStart)) |
|
250 { |
|
251 INFO_PRINTF1(KLogInfoNotCheckThePosition); |
|
252 |
|
253 } |
|
254 else if(relStart!=expectedStart) |
|
255 { |
|
256 ERR_PRINTF3(_L("The returned Start Position value is not as expected, expected: %d, result: %d"), expectedStart , relStart); |
|
257 SetBlockResult(EFail); |
|
258 } |
|
259 //Verify the end position on the scan line |
|
260 if(!GetIntFromConfig(aSection,KFldExpectedEnd,expectedEnd)) |
|
261 { |
|
262 INFO_PRINTF1(KLogInfoNotCheckThePosition); |
|
263 |
|
264 } |
|
265 else if(relEnd!=expectedEnd) |
|
266 { |
|
267 ERR_PRINTF3(_L("The returned End Position value is not as expected, expected: %d, result: %d"), expectedEnd , relEnd); |
|
268 SetBlockResult(EFail); |
|
269 } |
|
270 } |
|
271 |
|
272 void CT_DataPolygonFiller::DoCmdGetNextPixelRunOnSpecifiedScanLine(const TDesC& aSection) |
|
273 { |
|
274 TInt datScanLine=0; |
|
275 TBool relExists,expectedExists; |
|
276 TInt relStart,relEnd,expectedStart,expectedEnd; |
|
277 |
|
278 if (!GetIntFromConfig(aSection, KFldScanLine, datScanLine)) |
|
279 { |
|
280 ERR_PRINTF2(KLogMissingParameter, &KFldScanLine); |
|
281 SetBlockResult(EFail); |
|
282 } |
|
283 INFO_PRINTF1(KLogInfoCmdGetNextPixelRunOnSpecifiedScanLine); |
|
284 iPolygonFiller->GetNextPixelRunOnSpecifiedScanLine(relExists,datScanLine,relStart,relEnd); |
|
285 if(!GetBoolFromConfig(aSection,KFldExpectedExists,expectedExists)) |
|
286 { |
|
287 ERR_PRINTF2(KLogMissingParameter, &KFldExpectedExists); |
|
288 SetBlockResult(EFail); |
|
289 } |
|
290 else if(relExists!=expectedExists) |
|
291 { |
|
292 ERR_PRINTF3(_L("The returned Exists value is not as expected, expected: %d, result: %d"), expectedExists , relExists); |
|
293 SetBlockResult(EFail); |
|
294 } |
|
295 //Verify the start position on the scan line |
|
296 if(!GetIntFromConfig(aSection,KFldExpectedStart,expectedStart)) |
|
297 { |
|
298 INFO_PRINTF1(KLogInfoNotCheckThePosition); |
|
299 |
|
300 } |
|
301 else if(relStart!=expectedStart) |
|
302 { |
|
303 ERR_PRINTF3(_L("The returned Start Position value is not as expected, expected: %d, result: %d"), expectedStart , relStart); |
|
304 SetBlockResult(EFail); |
|
305 } |
|
306 //Verify the end position on the scan line |
|
307 if(!GetIntFromConfig(aSection,KFldExpectedEnd,expectedEnd)) |
|
308 { |
|
309 INFO_PRINTF1(KLogInfoNotCheckThePosition); |
|
310 |
|
311 } |
|
312 else if(relEnd!=expectedEnd) |
|
313 { |
|
314 ERR_PRINTF3(_L("The returned End Position value is not as expected, expected: %d, result: %d"), expectedEnd , relEnd); |
|
315 SetBlockResult(EFail); |
|
316 } |
|
317 } |
|
318 |
|