rechrshp.cpp

Go to the documentation of this file.
00001 // $Id: rechrshp.cpp 1688 2006-08-10 12:05:20Z gerry $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 /********************************************************************************************
00099 
00100 >   rechrshp.cpp
00101 
00102     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00103     Created:    06/06/96
00104     Purpose:    Implementation of an base class record handler for regular shapes.
00105 
00106 ********************************************************************************************/
00107 
00108 #include "camtypes.h"
00109 
00110 #include "nodershp.h"
00111 
00112 //#include "cxfdefs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "cxftags.h"
00114 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "cxfrech.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 
00117 #include "rechrshp.h"
00118 
00119 // to match the declare in the header file
00120 CC_IMPLEMENT_DYNAMIC(RegularShapeRecordHandler, CamelotRecordHandler);
00121 
00122 /********************************************************************************************
00123 
00124 >   UINT32 *RegularShapeRecordHandler::GetTagList()
00125 
00126     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00127     Created:    07/06/96
00128     Inputs:     -
00129     Returns:    UINT32* to an array of records handled by this class.
00130     Purpose:    Returns an array of records handled by this class.
00131     See Also:   <???>
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 >   BOOL RegularShapeRecordHandler::HandleRecord(CXaraFileRecord *pCXaraFileRecord)
00146 
00147     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00148     Created:    07/06/96
00149     Inputs:     pCXaraFileRecord - pointer to a CXaraFileRecord to read
00150     Returns:    TRUE if successful, FALSE otherwise
00151     Purpose:    Reads a regular shape record from a CXaraFile.
00152 
00153 ********************************************************************************************/
00154 
00155 BOOL RegularShapeRecordHandler::HandleRecord(CXaraFileRecord *pCXaraFileRecord)
00156 {
00157     BOOL ok;
00158 
00159     // see kernel/cxftags.h for a description of the differences between these two tags - ach
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 >   BOOL RegularShapeRecordHandler::ReadShapeGeneralPhase1(pCXaraFileRecord)
00176     BOOL RegularShapeRecordHandler::ReadShapeGeneralPhase2(pCXaraFileRecord)
00177 
00178     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00179     Created:    07/06/96
00180     Inputs:     pCXaraFileRecord - pointer to a CXaraFileRecord to read
00181     Returns:    TRUE if successful, FALSE otherwise
00182     Purpose:    <???>
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 >   BOOL RegularShapeRecordHandler::ReadShapeInvalid(CXaraFileRecord *pCXaraFileRecord)
00303 
00304     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00305     Created:    07/06/96
00306     Inputs:     pCXaraFileRecord - points to a CXaraFileRecord to read
00307     Returns:    FALSE
00308     Purpose:    Called when this class is asked to read a record it doesn't know about. We
00309                 raise an ERROR3 and return FALSE.
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 >   BOOL RegularShapeRecordHandler::SetupShape(NodeRegularShape *pShape);
00322     BOOL RegularShapeRecordhandler::InvalidateCache(NodeRegularShape *pShape);
00323     
00324     BOOL RegularShapeRecordHandler::SetCentrePoint(NodeRegularShape *pShape, const DocCoord & CentrePoint);
00325     BOOL RegularShapeRecordHandler::SetMajorAxis(NodeRegularShape *pShape, const DocCoord & MajorAxis);
00326     BOOL RegularShapeRecordHandler::SetMinorAxis(NodeRegularShape *pShape, const DocCoord & MinorAxis);
00327     BOOL RegularShapeRecordHandler::SetHeightAndWidth(NodeRegularShape *pShape, const INT32 & Height, const INT32 & Width);
00328     BOOL RegularShapeRecordHandler::SetNumberOfSides(NodeRegularShape *pShape, const INT32 & NumSides);
00329     BOOL RegularShapeRecordHandler::SetCurvature(NodeRegularShape *pShape, const double & Curvature);
00330     BOOL RegularShapeRecordHandler::SetPrimaryCurvature(NodeRegularShape *pShape, const double & PrimaryCurvature);
00331     BOOL RegularShapeRecordHandler::SetSecondaryCurvature(NodeRegularShape *pShape, const double & SecondaryCurvature);
00332     BOOL RegularShapeRecordHandler::SetStellationRadius(NodeRegularShape *pShape, const double & StellationRadius);
00333     BOOL RegularShapeRecordHandler::SetStellationOffset(NodeRegularShape *pShape, const double & StellationOffset);
00334     BOOL RegularShapeRecordHandler::SetEdgePath(NodeRegularShape *pShape, const Path & NewPath);
00335     BOOL RegularShapeRecordHandler::SetPrimaryEdgePath(NodeRegularShape *pShape, const Path & NewPrimaryPath);
00336     BOOL RegularShapeRecordHandler::SetSecondaryEdgePath(NodeRegularShape *pShape, const Path & NewSecondaryPath);
00337     BOOL RegularShapeRecordHandler::SetTransformMatrix(NodeRegularShape *pShape, const Matrix & NewMatrix);
00338     BOOL RegularShapeRecordHandler::SetCircular(NodeRegularShape *pShape, const BOOL & IsCircular);
00339     BOOL RegularShapeRecordHandler::SetStellated(NodeRegularShape *pShape, const BOOL & IsStellated);
00340     BOOL RegularShapeRecordHandler::SetPrimaryCurvature(NodeRegularShape *pShape, const BOOL & Value); 
00341     BOOL RegularShapeRecordHandler::SetStellationCurvature(NodeRegularShape *pShape, const BOOL & Value);
00342     
00343     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00344     Created:    06/06/96
00345     Inputs:     xxx     - information to set
00346                 pShape  - regular shape to alter
00347     Returns:    -
00348     Purpose:    Functions to set various pieces of information in a regular shape.
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();    // Identity transform
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 // sets the centre point of the shape (after transformation, rather than the UT centre
00373 // point, which should always be DocCoord(0,0). since this should be set before any
00374 // of the following functions get called, we just set the transform to a translation to
00375 // this point
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 // sets the untransformed major axis of the shape.
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 // sets the untransformed minor axis of the shape.
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 // sets the height and width of the shape. if this function gets called, we assume that the shape has
00413 // no rotation or skew, so the MajorAxis = (0, Height), MinorAxis = (Width, 0)
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 >   BOOL RegularShapeRecordHandler:SetFlags(NodeRegularShape *pShape, const BYTE & Value);
00505 
00506     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00507     Created:    13/06/96
00508     Inputs:     pShape  - node regular shape to write to
00509                 BYTE x  - flags information to write
00510     Returns:    TRUE if successful, FALSE otherwise
00511     Purpose:    Sets various flags in node regular shapes.
00512 
00513 ********************************************************************************************/
00514 
00515 BOOL RegularShapeRecordHandler::SetFlags(NodeRegularShape *pShape, const BYTE & Value)
00516 {
00517     // !!HACK!! constants embedded in code
00518     // !!HACK!! see CXaraFileRegularShape::GetFlags for the other code which needs to
00519     // !!HACK!! understand how the flags are packed into the byte.
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 >   void GetRecordDescriptionText(CXaraFileRecord* pCXaraFileRecord,StringBase* Str);
00531 
00532 
00533     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00534     Created:    04/07/96
00535     Inputs:     pCXaraFileRecord - CXaraFileRecord holding the record in question
00536                 Str - StringBase to add our information to
00537     Returns:    -
00538     Purpose:    Returns textual information on this record
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         // Call base class first
00548         // This outputs the tag and size
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     //if (ok) ok = pRecord->ReadPath(&(pShape->EdgePath1));
00591     //if (ok) ok = pRecord->ReadPath(&(pShape->EdgePath2));
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     //if (ok) ok = pRecord->ReadPath(&(pShape->EdgePath1));
00641     //if (ok) ok = pRecord->ReadPath(&(pShape->EdgePath2));
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 

Generated on Sat Nov 10 03:46:42 2007 for Camelot by  doxygen 1.4.4