#include <pathedit.h>
Inheritance diagram for SavePathArraysAction:
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 | |
Path * | ChangedPath |
PathVerb * | ChangedVerbs |
PathFlags * | ChangedFlags |
DocCoord * | ChangedCoords |
Definition at line 936 of file pathedit.h.
|
Constructor for the action to store a path on the undo.
Definition at line 10039 of file pathedit.cpp. 10040 { 10041 ChangedPath = NULL; 10042 ChangedVerbs = NULL; 10043 ChangedFlags = NULL; 10044 ChangedCoords = NULL; 10045 }
|
|
destructor for the action to store a path on the undo
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 }
|
|
Use this function to get the SavePathArraysAction going. It is far simpler and less error prone than calling SavePathArraysAction::Init directly.
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 }
|
|
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.
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 }
|
|
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.
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 }
|
|
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.
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 }
|
|
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 }
|
|
Swaps the path array data with that saved in the action record.
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 }
|
|
Definition at line 968 of file pathedit.h. |
|
Definition at line 967 of file pathedit.h. |
|
Definition at line 965 of file pathedit.h. |
|
Definition at line 966 of file pathedit.h. |