00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 #include "camtypes.h"
00109
00110 #include "nodershp.h"
00111
00112
00113 #include "cxftags.h"
00114
00115
00116
00117 #include "rechrshp.h"
00118
00119
00120 CC_IMPLEMENT_DYNAMIC(RegularShapeRecordHandler, CamelotRecordHandler);
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 UINT32 *RegularShapeRecordHandler::GetTagList()
00136 {
00137 static UINT32 TagList[] = {TAG_REGULAR_SHAPE_PHASE_1,
00138 TAG_REGULAR_SHAPE_PHASE_2,
00139 CXFRH_TAG_LIST_END};
00140 return &TagList[0];
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 BOOL RegularShapeRecordHandler::HandleRecord(CXaraFileRecord *pCXaraFileRecord)
00156 {
00157 BOOL ok;
00158
00159
00160 switch (pCXaraFileRecord->GetTag())
00161 {
00162 case TAG_REGULAR_SHAPE_PHASE_1 : ok = ReadShapeGeneralPhase1(pCXaraFileRecord);
00163 break;
00164 case TAG_REGULAR_SHAPE_PHASE_2 : ok = ReadShapeGeneralPhase2(pCXaraFileRecord);
00165 break;
00166 default : ok = ReadShapeInvalid(pCXaraFileRecord);
00167 break;
00168 }
00169
00170 return ok;
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 BOOL RegularShapeRecordHandler::ReadShapeGeneralPhase1(CXaraFileRecord *pCXaraFileRecord)
00187 {
00188 BOOL ok = TRUE;
00189
00190 NodeRegularShape * pShape;
00191 BYTE Flags;
00192 UINT16 NumberOfSides;
00193 DocCoord UTCentrePoint;
00194 DocCoord MajorAxis;
00195 DocCoord MinorAxis;
00196 Matrix TransformMatrix;
00197 double StellationRadius;
00198 double StellationOffset;
00199 double PrimaryCurvature;
00200 double SecondaryCurvature;
00201
00202 pShape = new NodeRegularShape;
00203
00204 if (ok) ok = SetupShape(pShape);
00205
00206 if (ok) ok = pCXaraFileRecord->ReadBYTE(&Flags);
00207 if (ok) ok = SetFlags(pShape, Flags);
00208
00209 if (ok) ok = pCXaraFileRecord->ReadUINT16(&NumberOfSides);
00210 if (ok) ok = SetNumberOfSides(pShape, NumberOfSides);
00211
00212 if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&UTCentrePoint,0,0);
00213 if (ok) ok = SetUTCentrePoint(pShape, UTCentrePoint);
00214
00215 if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MajorAxis,0,0);
00216 if (ok) ok = SetMajorAxis(pShape, MajorAxis);
00217
00218 if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MinorAxis,0,0);
00219 if (ok) ok = SetMinorAxis(pShape, MinorAxis);
00220
00221 if (ok) ok = pCXaraFileRecord->ReadMatrix(&TransformMatrix);
00222 if (ok) ok = SetTransformMatrix(pShape, TransformMatrix);
00223
00224 if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&StellationRadius);
00225 if (ok) ok = SetStellationRadius(pShape, StellationRadius);
00226
00227 if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&StellationOffset);
00228 if (ok) ok = SetStellationOffset(pShape, StellationOffset);
00229
00230 if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&PrimaryCurvature);
00231 if (ok) ok = SetPrimaryCurvature(pShape, PrimaryCurvature);
00232
00233 if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&SecondaryCurvature);
00234 if (ok) ok = SetSecondaryCurvature(pShape, SecondaryCurvature);
00235
00236 if (ok) ok = pCXaraFileRecord->ReadPath(&(pShape->EdgePath1));
00237 if (ok) ok = pCXaraFileRecord->ReadPath(&(pShape->EdgePath2));
00238
00239 if (ok) ok = InvalidateCache(pShape);
00240 if (ok) ok = InsertNode(pShape);
00241
00242 return ok;
00243 }
00244
00245 BOOL RegularShapeRecordHandler::ReadShapeGeneralPhase2(CXaraFileRecord *pCXaraFileRecord)
00246 {
00247 BOOL ok = TRUE;
00248
00249 NodeRegularShape * pShape;
00250 BYTE Flags;
00251 UINT16 NumberOfSides;
00252 DocCoord MajorAxis;
00253 DocCoord MinorAxis;
00254 Matrix TransformMatrix;
00255 double StellationRadius;
00256 double StellationOffset;
00257 double PrimaryCurvature;
00258 double SecondaryCurvature;
00259
00260 pShape = new NodeRegularShape;
00261
00262 if (ok) ok = SetupShape(pShape);
00263
00264 if (ok) ok = pCXaraFileRecord->ReadBYTE(&Flags);
00265 if (ok) ok = SetFlags(pShape, Flags);
00266
00267 if (ok) ok = pCXaraFileRecord->ReadUINT16(&NumberOfSides);
00268 if (ok) ok = SetNumberOfSides(pShape, NumberOfSides);
00269
00270 if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MajorAxis,0,0);
00271 if (ok) ok = SetMajorAxis(pShape, MajorAxis);
00272
00273 if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MinorAxis,0,0);
00274 if (ok) ok = SetMinorAxis(pShape, MinorAxis);
00275
00276 if (ok) ok = pCXaraFileRecord->ReadMatrix(&TransformMatrix);
00277 if (ok) ok = SetTransformMatrix(pShape, TransformMatrix);
00278
00279 if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&StellationRadius);
00280 if (ok) ok = SetStellationRadius(pShape, StellationRadius);
00281
00282 if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&StellationOffset);
00283 if (ok) ok = SetStellationOffset(pShape, StellationOffset);
00284
00285 if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&PrimaryCurvature);
00286 if (ok) ok = SetPrimaryCurvature(pShape, PrimaryCurvature);
00287
00288 if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&SecondaryCurvature);
00289 if (ok) ok = SetSecondaryCurvature(pShape, SecondaryCurvature);
00290
00291 if (ok) ok = pCXaraFileRecord->ReadPath(&(pShape->EdgePath1));
00292 if (ok) ok = pCXaraFileRecord->ReadPath(&(pShape->EdgePath2));
00293
00294 if (ok) ok = InvalidateCache(pShape);
00295 if (ok) ok = InsertNode(pShape);
00296
00297 return ok;
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 BOOL RegularShapeRecordHandler::ReadShapeInvalid(CXaraFileRecord *pCXaraFileRecord)
00314 {
00315 ERROR3("Attempt to read an invalid shape.");
00316 return FALSE;
00317 }
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 BOOL RegularShapeRecordHandler::SetupShape(NodeRegularShape *pShape)
00353 {
00354 DocCoord Origin = DocCoord(0,0);
00355
00356 pShape->SetCentrePoint(Origin);
00357 pShape->SetMinorAxes(Origin);
00358 pShape->SetMajorAxes(Origin);
00359
00360 Matrix m = Matrix();
00361 pShape->SetTransformMatrix(&m);
00362
00363 return pShape->SetUpShape();
00364 }
00365
00366 BOOL RegularShapeRecordHandler::InvalidateCache(NodeRegularShape *pShape)
00367 {
00368 pShape->InvalidateCache();
00369 return TRUE;
00370 }
00371
00372
00373
00374
00375
00376 BOOL RegularShapeRecordHandler::SetCentrePoint(NodeRegularShape *pShape, const DocCoord & CentrePoint)
00377 {
00378 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00379
00380 Matrix m = Matrix(CentrePoint);
00381 pShape->SetTransformMatrix(&m);
00382
00383 return TRUE;
00384 }
00385
00386 BOOL RegularShapeRecordHandler::SetUTCentrePoint(NodeRegularShape *pShape, const DocCoord & CentrePoint)
00387 {
00388 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00389
00390 pShape->SetCentrePoint(CentrePoint);
00391 return TRUE;
00392 }
00393
00394
00395 BOOL RegularShapeRecordHandler::SetMajorAxis(NodeRegularShape *pShape, const DocCoord & MajorAxis)
00396 {
00397 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00398
00399 pShape->SetMajorAxes(MajorAxis);
00400 return TRUE;
00401 }
00402
00403
00404 BOOL RegularShapeRecordHandler::SetMinorAxis(NodeRegularShape *pShape, const DocCoord & MinorAxis)
00405 {
00406 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00407
00408 pShape->SetMinorAxes(MinorAxis);
00409 return TRUE;
00410 }
00411
00412
00413
00414 BOOL RegularShapeRecordHandler::SetHeightAndWidth(NodeRegularShape *pShape, const INT32 & Height, const INT32 & Width)
00415 {
00416 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00417
00418 SetMajorAxis(pShape, DocCoord(0, Height/2));
00419 SetMinorAxis(pShape, DocCoord(Width/2, 0));
00420 return TRUE;
00421 }
00422
00423 BOOL RegularShapeRecordHandler::SetNumberOfSides(NodeRegularShape *pShape, const INT32 & NumberOfSides)
00424 {
00425 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00426
00427 pShape->SetNumSides(NumberOfSides);
00428 return TRUE;
00429 }
00430
00431 BOOL RegularShapeRecordHandler::SetCurvature(NodeRegularShape *pShape, const double & Curvature)
00432 {
00433 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00434
00435 pShape->SetPrimaryCurveToPrimary(Curvature);
00436 return TRUE;
00437 }
00438
00439 BOOL RegularShapeRecordHandler::SetPrimaryCurvature(NodeRegularShape *pShape, const double & PrimaryCurvature)
00440 {
00441 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00442
00443 pShape->SetPrimaryCurveToPrimary(PrimaryCurvature);
00444 return TRUE;
00445 }
00446
00447 BOOL RegularShapeRecordHandler::SetSecondaryCurvature(NodeRegularShape *pShape, const double & SecondaryCurvature)
00448 {
00449 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00450
00451 pShape->SetStellCurveToStell(SecondaryCurvature);
00452 return TRUE;
00453 }
00454
00455 BOOL RegularShapeRecordHandler::SetStellationRadius(NodeRegularShape *pShape, const double & StellationRadius)
00456 {
00457 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00458
00459 pShape->SetStellRadiusToPrimary(StellationRadius);
00460 return TRUE;
00461 }
00462
00463 BOOL RegularShapeRecordHandler::SetStellationOffset(NodeRegularShape *pShape, const double & StellationOffset)
00464 {
00465 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00466
00467 pShape->SetStellationRatio(StellationOffset);
00468 return TRUE;
00469 }
00470
00471 BOOL RegularShapeRecordHandler::SetTransformMatrix(NodeRegularShape *pShape, const Matrix & NewMatrix)
00472 {
00473 pShape->SetTransformMatrix(&NewMatrix);
00474 return TRUE;
00475 }
00476
00477 BOOL RegularShapeRecordHandler::SetIsCircular(NodeRegularShape *pShape, const BOOL & IsCircular)
00478 {
00479 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00480
00481 pShape->SetCircular(IsCircular);
00482 return TRUE;
00483 }
00484
00485 BOOL RegularShapeRecordHandler::SetIsStellated(NodeRegularShape *pShape, const BOOL & IsStellated)
00486 {
00487 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00488
00489 pShape->SetStellated(IsStellated);
00490 return TRUE;
00491 }
00492
00493 BOOL RegularShapeRecordHandler::SetIsRounded(NodeRegularShape * pShape, const BOOL & IsRounded)
00494 {
00495 ERROR2IF(pShape==NULL, FALSE, "parameter pShape == NULL");
00496
00497 pShape->SetPrimaryCurvature(IsRounded);
00498 pShape->SetStellationCurvature(IsRounded);
00499 return TRUE;
00500 }
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515 BOOL RegularShapeRecordHandler::SetFlags(NodeRegularShape *pShape, const BYTE & Value)
00516 {
00517
00518
00519
00520 if ((Value & 0x1) == 0x1) pShape->SetCircular(TRUE);
00521 if ((Value & 0x2) == 0x2) pShape->SetStellated(TRUE);
00522 if ((Value & 0x4) == 0x4) pShape->SetPrimaryCurvature(TRUE);
00523 if ((Value & 0x8) == 0x8) pShape->SetStellationCurvature(TRUE);
00524
00525 return TRUE;
00526 }
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542 #ifdef XAR_TREE_DIALOG
00543 void RegularShapeRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord, StringBase *pStr)
00544 {
00545 if (pRecord != NULL && pStr != NULL)
00546 {
00547
00548
00549 CamelotRecordHandler::GetRecordDescriptionText(pRecord,pStr);
00550
00551 switch (pRecord->GetTag())
00552 {
00553 case TAG_REGULAR_SHAPE_PHASE_1 : DescribeShapeGeneralPhase1(pRecord, pStr); break;
00554 case TAG_REGULAR_SHAPE_PHASE_2 : DescribeShapeGeneralPhase2(pRecord, pStr); break;
00555 default : DescribeInvalid(pRecord, pStr); break;
00556 }
00557 }
00558 }
00559
00560 void RegularShapeRecordHandler::DescribeShapeGeneralPhase1(CXaraFileRecord *pRecord, StringBase *pStr)
00561 {
00562 if (pRecord == NULL || pStr == NULL)
00563 return;
00564
00565 TCHAR s[512];
00566
00567 BOOL ok = TRUE;
00568
00569 BYTE Flags;
00570 UINT16 NumberOfSides;
00571 DocCoord UTCentrePoint;
00572 DocCoord MajorAxis;
00573 DocCoord MinorAxis;
00574 Matrix TransformMatrix;
00575 double StellationRadius;
00576 double StellationOffset;
00577 double PrimaryCurvature;
00578 double SecondaryCurvature;
00579
00580 if (ok) ok = pRecord->ReadBYTE(&Flags);
00581 if (ok) ok = pRecord->ReadUINT16(&NumberOfSides);
00582 if (ok) ok = pRecord->ReadCoordTrans(&UTCentrePoint,0,0);
00583 if (ok) ok = pRecord->ReadCoordTrans(&MajorAxis,0,0);
00584 if (ok) ok = pRecord->ReadCoordTrans(&MinorAxis,0,0);
00585 if (ok) ok = pRecord->ReadMatrix(&TransformMatrix);
00586 if (ok) ok = pRecord->ReadDOUBLE(&StellationRadius);
00587 if (ok) ok = pRecord->ReadDOUBLE(&StellationOffset);
00588 if (ok) ok = pRecord->ReadDOUBLE(&PrimaryCurvature);
00589 if (ok) ok = pRecord->ReadDOUBLE(&SecondaryCurvature);
00590
00591
00592
00593 (*pStr) += _T("General regular shape (Phase 1)\r\n\r\n");
00594 camSprintf(s,_T("Flags\t\t= %x\r\n"),Flags);
00595 (*pStr) += s;
00596 camSprintf(s,_T("Number of sides\t= %d\r\n"),NumberOfSides);
00597 (*pStr) += s;
00598 camSprintf(s,_T("Centre point\t= %d, %d\r\n"),UTCentrePoint.x,UTCentrePoint.y);
00599 (*pStr) += s;
00600 camSprintf(s,_T("Major axis\t\t= %d, %d\r\n"),MajorAxis.x,MajorAxis.y);
00601 (*pStr) += s;
00602 camSprintf(s,_T("Minor axis\t\t= %d, %d\r\n"),MinorAxis.x,MinorAxis.y);
00603 (*pStr) += s;
00604 camSprintf(s,_T("Stellation radius\t= %f\r\n"),StellationRadius);
00605 (*pStr) += s;
00606 camSprintf(s,_T("Primary curvature\t= %f\r\n"),PrimaryCurvature);
00607 (*pStr) += s;
00608 camSprintf(s,_T("Secondary curvature\t= %f\r\n"),SecondaryCurvature);
00609 (*pStr) += s;
00610 }
00611
00612 void RegularShapeRecordHandler::DescribeShapeGeneralPhase2(CXaraFileRecord *pRecord, StringBase *pStr)
00613 {
00614 if (pRecord == NULL || pStr == NULL)
00615 return;
00616
00617 TCHAR s[512];
00618
00619 BOOL ok = TRUE;
00620
00621 BYTE Flags;
00622 UINT16 NumberOfSides;
00623 DocCoord MajorAxis;
00624 DocCoord MinorAxis;
00625 Matrix TransformMatrix;
00626 double StellationRadius;
00627 double StellationOffset;
00628 double PrimaryCurvature;
00629 double SecondaryCurvature;
00630
00631 if (ok) ok = pRecord->ReadBYTE(&Flags);
00632 if (ok) ok = pRecord->ReadUINT16(&NumberOfSides);
00633 if (ok) ok = pRecord->ReadCoordTrans(&MajorAxis,0,0);
00634 if (ok) ok = pRecord->ReadCoordTrans(&MinorAxis,0,0);
00635 if (ok) ok = pRecord->ReadMatrix(&TransformMatrix);
00636 if (ok) ok = pRecord->ReadDOUBLE(&StellationRadius);
00637 if (ok) ok = pRecord->ReadDOUBLE(&StellationOffset);
00638 if (ok) ok = pRecord->ReadDOUBLE(&PrimaryCurvature);
00639 if (ok) ok = pRecord->ReadDOUBLE(&SecondaryCurvature);
00640
00641
00642
00643 (*pStr) += _T("General regular shape (Phase 2)\r\n\r\n");
00644 camSprintf(s,_T("Flags\t\t= %x\r\n"),Flags);
00645 (*pStr) += s;
00646 camSprintf(s,_T("Number of sides\t= %d\r\n"),NumberOfSides);
00647 (*pStr) += s;
00648 camSprintf(s,_T("Major axis\t\t= %d, %d\r\n"),MajorAxis.x,MajorAxis.y);
00649 (*pStr) += s;
00650 camSprintf(s,_T("Minor axis\t\t= %d, %d\r\n"),MinorAxis.x,MinorAxis.y);
00651 (*pStr) += s;
00652 camSprintf(s,_T("Stellation radius\t= %f\r\n"),StellationRadius);
00653 (*pStr) += s;
00654 camSprintf(s,_T("Stellation offset\t= %f\r\n"),StellationOffset);
00655 (*pStr) += s;
00656 camSprintf(s,_T("Primary curvature\t= %f\r\n"),PrimaryCurvature);
00657 (*pStr) += s;
00658 camSprintf(s,_T("Secondary curvature\t= %f\r\n"),SecondaryCurvature);
00659 (*pStr) += s;
00660 }
00661
00662 void RegularShapeRecordHandler::DescribeInvalid(CXaraFileRecord *pRecord, StringBase *pStr)
00663 {
00664 if (pRecord == NULL || pStr == NULL)
00665 return;
00666
00667 (*pStr) += _T("Invalid regular shape\r\n");
00668 }
00669 #endif
00670