SavePathArraysAction Class Reference

Given a path, save the paths array data, ie all its verbs, coords and flags on the undo. Use DoRecord(Operation*, ActionList*,Path*) to save the path. More...

#include <pathedit.h>

Inheritance diagram for SavePathArraysAction:

Action ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 SavePathArraysAction ()
 Constructor for the action to store a path on the undo.
 ~SavePathArraysAction ()
 destructor for the action to store a path on the undo
virtual ActionCode Execute ()
 This function executes the SavePath action which will create an opposite action record dependent on whether we're undoing or redoing. It will swap the saved information about the path between the executing action record and the arrays of the path.

Static Public Member Functions

static ActionCode DoRecord (Operation *pOp, ActionList *pActionList, Path *pPath)
 Use this function to get the SavePathArraysAction going. It is far simpler and less error prone than calling SavePathArraysAction::Init directly.
static ActionCode Init (Operation *pOp, ActionList *pActionList, Path *Path, Action **NewAction, BOOL CreateArrays=TRUE)
 The actions static init function. The purpose of this function is to create instances of SavePathsArrayAction. Hence it static nature. It seems strange that you can call a function inside a class to create another instance of that class, but thats what really happens here. We pass back a pointer to the action if we've succeeded in creating it. This particular action init function also creates some external arrays to save a paths data in. You need to call the function with CreateArrays set to TRUE, to get it to save the paths arrays. It needs this parameter because the very same function is called within the execution of a previously created savepath action which incidently sets CreateArrays to FALSE. (You can get a serious headache thinking about this one). The idea is really to create the save arrays once, when this init function is called and swap them between undo and redo actions, killing them off only when the last thread is destructed.

Private Member Functions

ActionCode SetUpArrays (Path *pPath, Operation *pOp)
BOOL SavePathArrays (Path *pPath, Operation *pOp, PathFlags **pFlags, PathVerb **pVerbs, DocCoord **pCoords)
 Creates three arrays and copies the input paths verbs, coords and flags into these. If successfull it will return pointers to these arrays in pFlags, pVerbs and pCoords.
void SwapPathArrays ()
 Swaps the path array data with that saved in the action record.

Private Attributes

PathChangedPath
PathVerbChangedVerbs
PathFlagsChangedFlags
DocCoordChangedCoords

Detailed Description

Given a path, save the paths array data, ie all its verbs, coords and flags on the undo. Use DoRecord(Operation*, ActionList*,Path*) to save the path.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95

Definition at line 936 of file pathedit.h.


Constructor & Destructor Documentation

SavePathArraysAction::SavePathArraysAction  ) 
 

Constructor for the action to store a path on the undo.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95

Definition at line 10039 of file pathedit.cpp.

10040 {
10041     ChangedPath   = NULL;
10042     ChangedVerbs  = NULL;
10043     ChangedFlags  = NULL;
10044     ChangedCoords = NULL;
10045 }

SavePathArraysAction::~SavePathArraysAction  ) 
 

destructor for the action to store a path on the undo

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95

Definition at line 10058 of file pathedit.cpp.

10059 {
10060     if (ChangedVerbs)
10061         CCFree(ChangedVerbs);
10062     if (ChangedCoords)
10063         CCFree(ChangedCoords);
10064     if (ChangedFlags)
10065         CCFree(ChangedFlags);
10066 }


Member Function Documentation

ActionCode SavePathArraysAction::DoRecord Operation pOp,
ActionList pActionList,
Path pPath
[static]
 

Use this function to get the SavePathArraysAction going. It is far simpler and less error prone than calling SavePathArraysAction::Init directly.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95
Parameters:
pOp is the currently running operation [INPUTS] pActionList = a pointer ot the action list to which the action should be appended pPath = a pointer to the path whose data will be saved.
NewAction = a pointer to a pointer to an action, allowing the function [OUTPUTS] to return a pointer to the created action
Returns:
ActionCode, one of AC_OK, AC_NO_RECORD or AC_FAIL

Errors: -

See also:
For a full explanation of this action see SavePathArraysAction::Init()

Definition at line 10090 of file pathedit.cpp.

10091 {
10092     SavePathArraysAction* SaveAction;
10093     ActionCode Act = SavePathArraysAction::Init(pOp, pActionList, pPath, (Action**)&SaveAction, TRUE);
10094     return Act;
10095 }

ActionCode SavePathArraysAction::Execute  )  [virtual]
 

This function executes the SavePath action which will create an opposite action record dependent on whether we're undoing or redoing. It will swap the saved information about the path between the executing action record and the arrays of the path.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95
Parameters:
- [INPUTS]
Returns:
one of AC_OK, AC_NORECORD, AC_FAIL

Reimplemented from Action.

Definition at line 10207 of file pathedit.cpp.

10208 {
10209     // first try to create an opposite action
10210     SavePathArraysAction* SaveAction;
10211     
10212     ActionCode Act;
10213     Act = SavePathArraysAction::Init(pOperation, pOppositeActLst, ChangedPath, (Action**)(&SaveAction), FALSE);
10214     if (Act == AC_FAIL)
10215         return AC_FAIL;
10216 
10217     // swap over the path data between this action record and the path.
10218     SwapPathArrays();
10219 
10220     // and update the new actions array pointers
10221     if (SaveAction!=NULL)
10222     {
10223         SaveAction->ChangedFlags = ChangedFlags;
10224         SaveAction->ChangedVerbs = ChangedVerbs;
10225         SaveAction->ChangedCoords = ChangedCoords;
10226 
10227         // make sure we clear these pointer vals before the destructor does
10228         // as we're sharing the arrays.
10229         ChangedVerbs  = NULL;
10230         ChangedCoords = NULL;
10231         ChangedFlags  = NULL;
10232     }
10233 
10234     return Act;
10235 }

ActionCode SavePathArraysAction::Init Operation pOp,
ActionList pActionList,
Path pPath,
Action **  NewAction,
BOOL  CreateArrays = TRUE
[static]
 

The actions static init function. The purpose of this function is to create instances of SavePathsArrayAction. Hence it static nature. It seems strange that you can call a function inside a class to create another instance of that class, but thats what really happens here. We pass back a pointer to the action if we've succeeded in creating it. This particular action init function also creates some external arrays to save a paths data in. You need to call the function with CreateArrays set to TRUE, to get it to save the paths arrays. It needs this parameter because the very same function is called within the execution of a previously created savepath action which incidently sets CreateArrays to FALSE. (You can get a serious headache thinking about this one). The idea is really to create the save arrays once, when this init function is called and swap them between undo and redo actions, killing them off only when the last thread is destructed.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95
Parameters:
pOp = a pointer to the operation to which this action belongs [INPUTS] pActionList = the action list to which this action should be added pPath = a pointer to the path whose data will be saved. CreateArrays= a boolean which should always be TRUE except for when this action is being executed by the undo/redo system.
NewAction = a pointer to a pointer to an action, allowing the function [OUTPUTS] to return a pointer to the created action
Returns:
ActionCode, one of AC_OK, AC_NO_RECORD or AC_FAIL
See also:
SavePathArraysAction::DoRecord()

Definition at line 10136 of file pathedit.cpp.

10141 {
10142     ERROR1IF(pPath==NULL,AC_FAIL,"SavePathArraysAction::Init() passed a NULL path pointer");
10143 
10144     UINT32 NumElements = pPath->GetNumCoords();
10145     UINT32 ActSize = sizeof(SavePathArraysAction) + NumElements*(sizeof(PathVerb) + 
10146                                                                 sizeof(PathFlags) +
10147                                                                 sizeof(DocCoord) );
10148 
10149     ActionCode Ac = Action::Init( pOp, pActionList, ActSize, CC_RUNTIME_CLASS(SavePathArraysAction), NewAction);
10150 
10151     SavePathArraysAction* CreatedAction = (SavePathArraysAction*)(*NewAction);
10152     if (CreatedAction!=NULL)
10153     {
10154         CreatedAction->ChangedPath = pPath;
10155         if (CreateArrays)
10156             CreatedAction->SetUpArrays(pPath,pOp);
10157     }
10158     return Ac;
10159 }

BOOL SavePathArraysAction::SavePathArrays Path pPath,
Operation pOp,
PathFlags **  pFlags,
PathVerb **  pVerbs,
DocCoord **  pCoords
[private]
 

Creates three arrays and copies the input paths verbs, coords and flags into these. If successfull it will return pointers to these arrays in pFlags, pVerbs and pCoords.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95
Parameters:
pPath = a pointer to the path to save [INPUTS] pOp = the current operation pointer Outputs pFlags points to a copied flags array, set to NULL if failed pVerbs points to a copied verb array, set to NULL if failed pCoords points to a copied coord array, set to NULL if failed
Returns:
TRUE if the paths arrays have been saved FALSE if not

Definition at line 10261 of file pathedit.cpp.

10266 {   
10267     UINT32 NumElements = pPath->GetNumCoords();
10268     PathFlags* DFlags;
10269     PathVerb* DVerbs;
10270     DocCoord* DCoords;
10271 
10272     ALLOC_WITH_FAIL(DVerbs,(PathVerb*) CCMalloc(NumElements * sizeof(PathVerb)),pOp);
10273     ALLOC_WITH_FAIL(DCoords,(DocCoord*) CCMalloc(NumElements * sizeof(DocCoord)),pOp);
10274     ALLOC_WITH_FAIL(DFlags,(PathFlags*) CCMalloc(NumElements * sizeof(PathFlags)),pOp);
10275 
10276     if (!DVerbs || !DCoords || !DFlags)
10277     {
10278         if (DVerbs)  CCFree(DVerbs);
10279         if (DCoords) CCFree(DCoords);
10280         if (DFlags)  CCFree(DFlags);
10281 
10282         *pFlags=NULL;
10283         *pVerbs=NULL;
10284         *pCoords=NULL;
10285 
10286         return FALSE;
10287     }
10288 
10289     // Now copy the data from the path into the arrays
10290     DocCoord*  SCoords = pPath->GetCoordArray();
10291     PathFlags* SFlags  = pPath->GetFlagArray();
10292     PathVerb*  SVerbs  = pPath->GetVerbArray();
10293 
10294     // Copy all the data
10295     memmove((void*)(DCoords), (void*)(SCoords), NumElements*sizeof(DocCoord));
10296     memmove((void*)(DVerbs),  (void*)(SVerbs),  NumElements*sizeof(PathVerb));
10297     memmove((void*)(DFlags),  (void*)(SFlags),  NumElements*sizeof(PathFlags));
10298 
10299     *pFlags = DFlags;
10300     *pVerbs = DVerbs;
10301     *pCoords = DCoords;
10302 
10303     return TRUE;
10304 }

ActionCode SavePathArraysAction::SetUpArrays Path pPath,
Operation pOp
[private]
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95
Parameters:
pPath = pointer to the path to save [INPUTS] pOp = pointer to the current operation
Returns:
one of AC_OK, AC_NORECORD, AC_FAIL

Definition at line 10176 of file pathedit.cpp.

10177 {
10178     if (ChangedFlags!=NULL || ChangedVerbs!=NULL || ChangedCoords!=NULL)
10179     {
10180         ENSURE(TRUE,"SavePathArraysAction::SetUpArrays() failed");
10181         return AC_FAIL;
10182     }
10183 
10184     if (!SavePathArrays(pPath, pOp, &ChangedFlags, &ChangedVerbs, &ChangedCoords))
10185         return AC_FAIL;
10186 
10187     return AC_OK;
10188 }

void SavePathArraysAction::SwapPathArrays  )  [private]
 

Swaps the path array data with that saved in the action record.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95
Parameters:
- [INPUTS]
Returns:
-

Definition at line 10319 of file pathedit.cpp.

10320 {
10321     INT32 NumElements = ChangedPath->GetNumCoords();
10322     PathVerb*  Verbs  = ChangedPath->GetVerbArray();
10323     DocCoord*  Coords = ChangedPath->GetCoordArray();
10324     PathFlags* Flags  = ChangedPath->GetFlagArray();
10325 
10326     PathVerb TempVerb;
10327     DocCoord TempCoord;
10328     PathFlags TempFlag;
10329     
10330     for (INT32 i=0; i<NumElements; i++)
10331     {
10332         TempVerb=Verbs[i];   Verbs[i]=ChangedVerbs[i];   ChangedVerbs[i]=TempVerb;
10333         TempCoord=Coords[i]; Coords[i]=ChangedCoords[i]; ChangedCoords[i]=TempCoord;
10334         TempFlag=Flags[i];   Flags[i]=ChangedFlags[i];   ChangedFlags[i]=TempFlag;
10335     }
10336 }


Member Data Documentation

DocCoord* SavePathArraysAction::ChangedCoords [private]
 

Definition at line 968 of file pathedit.h.

PathFlags* SavePathArraysAction::ChangedFlags [private]
 

Definition at line 967 of file pathedit.h.

Path* SavePathArraysAction::ChangedPath [private]
 

Definition at line 965 of file pathedit.h.

PathVerb* SavePathArraysAction::ChangedVerbs [private]
 

Definition at line 966 of file pathedit.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:00:38 2007 for Camelot by  doxygen 1.4.4