#include <pathndge.h>
Inheritance diagram for OpPathNudge:
Public Member Functions | |
double | GetXPixelDisplacement () |
double | GetYPixelDisplacement () |
virtual void | Do (OpDescriptor *pOpDesc) |
The path nudge op's Do() function. | |
void | GetOpName (String_256 *OpName) |
The GetOpName fn is overridden so that we return back a description appropriate to the type of attribute that the operation applies. | |
virtual void | PerformMergeProcessing () |
If the previous operation was also a path nudge the the undo actions are merged to form one undo step. | |
Static Public Member Functions | |
static BOOL | Init () |
Declares a preference that allows you to clear memory in delete(). | |
static OpState | GetState (String_256 *, OpDescriptor *) |
static double | GetXNudgeDisplacement () |
static double | GetYNudgeDisplacement () |
Protected Attributes | |
UINT32 | NudgeUndoIDS |
Static Protected Attributes | |
static double | X_NudgeFactor |
static double | Y_NudgeFactor = 0 |
Private Member Functions | |
CC_DECLARE_DYNCREATE (OpPathNudge) | |
Private Attributes | |
BOOL | PixelNudgeClass |
double | PixelNudge |
Static Private Attributes | |
static MILLIPOINT | NudgeStep |
Definition at line 118 of file pathndge.h.
|
|
|
The path nudge op's Do() function.
Reimplemented from Operation. Definition at line 211 of file pathndge.cpp. 00212 { 00213 NudgeStep = OpNudge::GetNudgeStep(); 00214 00215 // Get scaled pixel size 00216 FIXED16 ScaledPixelWidth, ScaledPixelHeight; 00217 GetWorkingView()->GetScaledPixelSize(&ScaledPixelWidth, &ScaledPixelHeight) ; 00218 PixelNudge=ScaledPixelWidth.MakeDouble() ; 00219 00220 // Determine the nudge factors based on the OpDescriptor used to invoke the nudge operation 00221 String OpToken = pOpDesc->Token; 00222 00223 if (OpToken == String(OPTOKEN_NUDGEUPPIXEL1)) { PixelNudgeClass = TRUE; } 00224 else if (OpToken == String(OPTOKEN_NUDGEUPPIXEL10)) { PixelNudgeClass = TRUE; } 00225 00226 else if (OpToken == String(OPTOKEN_NUDGEDOWNPIXEL1)) { PixelNudgeClass = TRUE; } 00227 else if (OpToken == String(OPTOKEN_NUDGEDOWNPIXEL10)) { PixelNudgeClass = TRUE; } 00228 00229 else if (OpToken == String(OPTOKEN_NUDGELEFTPIXEL1)) { PixelNudgeClass = TRUE; } 00230 else if (OpToken == String(OPTOKEN_NUDGELEFTPIXEL10)) { PixelNudgeClass = TRUE; } 00231 00232 else if (OpToken == String(OPTOKEN_NUDGERIGHTPIXEL1)) { PixelNudgeClass = TRUE; } 00233 else if (OpToken == String(OPTOKEN_NUDGERIGHTPIXEL10)) { PixelNudgeClass = TRUE; } 00234 00235 else if (OpToken == String(OPTOKEN_NUDGEUP1)) { PixelNudgeClass = FALSE; } 00236 else if (OpToken == String(OPTOKEN_NUDGEUP10)) { PixelNudgeClass = FALSE; } 00237 00238 else if (OpToken == String(OPTOKEN_NUDGEDOWN1)) { PixelNudgeClass = FALSE; } 00239 else if (OpToken == String(OPTOKEN_NUDGEDOWN10)) { PixelNudgeClass = FALSE; } 00240 00241 else if (OpToken == String(OPTOKEN_NUDGELEFT1)) { PixelNudgeClass = FALSE; } 00242 else if (OpToken == String(OPTOKEN_NUDGELEFT10)) { PixelNudgeClass = FALSE; } 00243 00244 else if (OpToken == String(OPTOKEN_NUDGERIGHT1)) { PixelNudgeClass = FALSE; } 00245 else if (OpToken == String(OPTOKEN_NUDGERIGHT10)) { PixelNudgeClass = FALSE; } 00246 00247 00248 00249 // Setup the Offset DocCoord to contain the X and Y translation values 00250 DocCoord Offset; 00251 00252 if (PixelNudgeClass) 00253 { 00254 Offset.x=(INT32)GetXPixelDisplacement(); 00255 Offset.y=(INT32)GetYPixelDisplacement(); 00256 } 00257 00258 else if (!PixelNudgeClass) 00259 { 00260 //TypeCast from double to INT32 00261 Offset.x=(INT32) GetXNudgeDisplacement(); 00262 Offset.y=(INT32) GetYNudgeDisplacement(); 00263 } 00264 00265 00266 SelRange* Selection = GetApplication()->FindSelection(); 00267 Node* pNode = Selection->FindFirst(); 00268 NodePath* ThisPath = NULL; 00269 BOOL HaveNudged = FALSE; 00270 00271 DocRect BoundingBox; 00272 BOOL BoundingBoxValid = FALSE; 00273 00274 PathVerb* Verbs = NULL; 00275 PathFlags* Flags = NULL; 00276 DocCoord* Coords = NULL; 00277 INT32 NumCoords = 0; 00278 BOOL ok = TRUE; 00279 00280 // Only start an undo record if there is work to do! 00281 if (pNode != NULL) 00282 ok = DoStartTransOp(FALSE, NULL); 00283 00284 while (ok && pNode!=NULL) 00285 { 00286 //scan tree for all selected paths 00287 if ( IS_A(pNode,NodePath) && (((NodePath*)pNode)->InkPath.IsSubSelection()) ) 00288 { 00289 // for convenience, cast the pointer to a pointer to a NodePath 00290 ThisPath = (NodePath*)pNode; 00291 00292 // First get pointers to the arrays 00293 ThisPath->InkPath.GetPathArrays(&Verbs, &Coords, &Flags); 00294 NumCoords = ThisPath->InkPath.GetNumCoords(); 00295 BOOL ok = TRUE; 00296 00297 for (INT32 i=0; i<NumCoords && ok; i++) 00298 { 00299 // scan path for all selected endpoints 00300 if (Flags[i].IsEndPoint && Flags[i].IsSelected) 00301 { 00302 DocCoord NewCoord = Coords[i] + Offset; 00303 ok = DoAlterPathElement(ThisPath, i, NewCoord, Flags[i], Verbs[i]); 00304 HaveNudged = TRUE; 00305 00306 if (BoundingBoxValid) 00307 { 00308 BoundingBox.IncludePoint(NewCoord); 00309 } 00310 else 00311 { 00312 BoundingBox = DocRect(NewCoord, NewCoord); 00313 BoundingBoxValid = TRUE; 00314 } 00315 00316 // Also need to nudge the associated control points if the rotate flag is set 00317 // Jim 31/8/96 - Changed to nudge control points always, not just when rotate flag set 00318 // Exeption Don't do the selected moveto in a closed subpath - the end of the 00319 // will alsobe selected, that will handle this situation 00320 if (!(Verbs[i]== PT_MOVETO && ThisPath->InkPath.IsSubPathClosed(i))) 00321 { 00322 INT32 PrevIndex = ThisPath->InkPath.FindPrevControlPoint(i); 00323 if (PrevIndex!=-1 && ok) 00324 { 00325 DocCoord NewCoord = Coords[PrevIndex] + Offset; 00326 ok = DoAlterPathElement(ThisPath, PrevIndex, NewCoord, Flags[PrevIndex], Verbs[PrevIndex]); 00327 } 00328 00329 INT32 NextIndex = ThisPath->InkPath.FindNextControlPoint(i); 00330 if (NextIndex!=-1 && ok) 00331 { 00332 DocCoord NewCoord = Coords[NextIndex] + Offset; 00333 ok = DoAlterPathElement(ThisPath, NextIndex, NewCoord, Flags[NextIndex], Verbs[NextIndex]); 00334 } 00335 } 00336 } 00337 } 00338 } 00339 00340 pNode = Selection->FindNext(pNode); 00341 } 00342 00343 if (ok && !HaveNudged) 00344 { 00345 // No points were selected so we need to move all the selected paths 00346 pNode = Selection->FindFirst(); 00347 00348 while (ok && pNode!=NULL) 00349 { 00350 if (IS_A(pNode,NodePath)) 00351 { 00352 // Construct the translation matrix 00353 Trans2DMatrix* TransMat = new Trans2DMatrix(Offset.x, Offset.y); 00354 00355 // And apply it to the path 00356 ok = DoTransformNode((NodeRenderableInk*)pNode, TransMat); 00357 } 00358 pNode = Selection->FindNext(pNode); 00359 } 00360 00361 if (ok) 00362 { 00363 BoundingBox = Selection->GetBoundingRect(); 00364 BoundingBoxValid = TRUE; 00365 } 00366 } 00367 00368 if (ok) 00369 { 00370 if (BoundingBoxValid) 00371 { 00372 DocView* pDocView = DocView::GetSelected(); 00373 if (pDocView != NULL) 00374 { 00375 pDocView->ScrollToShow(&BoundingBox, Offset); 00376 } 00377 } 00378 } 00379 else 00380 { 00381 InformError(); 00382 FailAndExecute(); 00383 } 00384 00385 End(); 00386 }
|
|
The GetOpName fn is overridden so that we return back a description appropriate to the type of attribute that the operation applies.
Reimplemented from Operation. Definition at line 401 of file pathndge.cpp. 00402 { 00403 *OpName = String_256(NudgeUndoIDS); 00404 }
|
|
Reimplemented from TransOperation. |
|
Definition at line 130 of file pathndge.h. 00130 { return NudgeStep * X_NudgeFactor; }
|
|
Definition at line 132 of file pathndge.h. 00132 { return PixelNudge * X_NudgeFactor;}
|
|
Definition at line 131 of file pathndge.h. 00131 { return NudgeStep * Y_NudgeFactor; }
|
|
Definition at line 133 of file pathndge.h. 00133 { return PixelNudge * Y_NudgeFactor;}
|
|
Declares a preference that allows you to clear memory in delete().
Reimplemented from SimpleCCObject. |
|
If the previous operation was also a path nudge the the undo actions are merged to form one undo step.
Reimplemented from UndoableOperation. Definition at line 420 of file pathndge.cpp. 00421 { 00422 if (pOurDoc==NULL) 00423 { 00424 ERROR3("This operation had no document pointer"); 00425 return; 00426 } 00427 00428 // Obtain a pointer to the operation history for the current document 00429 OperationHistory* pOpHist = &pOurDoc->GetOpHistory(); 00430 if (pOpHist==NULL) 00431 { 00432 ERROR3("This document has no operation history"); 00433 return; 00434 } 00435 ERROR3IF(pOpHist->FindLastOp() != this, "Last Op should be this op"); 00436 00437 // Is operation performed before this a path nudge? Attempt a merge if so 00438 Operation* pPrevOp = pOpHist->FindPrevToLastOp(); 00439 if ((pPrevOp != NULL) && pPrevOp->IS_KIND_OF(OpPathNudge)) 00440 { 00441 BOOL PerformMerge = TRUE; 00442 00443 // Count the number of actions. They must be the same to merge. 00444 UINT32 NumPrevActions = pPrevOp->GetUndoActionList()->GetCount(); 00445 UINT32 NumOurActions = GetUndoActionList()->GetCount(); 00446 PerformMerge = (NumPrevActions == NumOurActions); 00447 00448 // Compare the actions to check we are operating on the same points on the same paths 00449 if (PerformMerge) 00450 { 00451 Action* pPrevAction = (Action*)pPrevOp->GetUndoActionList()->GetHead(); 00452 Action* pOurAction = (Action*)GetUndoActionList()->GetHead(); 00453 00454 while (PerformMerge && pPrevAction!=NULL && pOurAction!=NULL) 00455 { 00456 // Actions must be of the same class 00457 PerformMerge = (pPrevAction->GetRuntimeClass() == pOurAction->GetRuntimeClass()); 00458 00459 // ModifyElementActions must reference the same path and index 00460 if (PerformMerge && IS_A(pPrevAction, ModifyElementAction)) 00461 { 00462 const ModifyElementAction* pPrevModify = (ModifyElementAction*)pPrevAction; 00463 const ModifyElementAction* pOurModify = (ModifyElementAction*)pOurAction; 00464 00465 PerformMerge = (pPrevModify->GetActionPath()==pOurModify->GetActionPath() && 00466 pPrevModify->GetActionIndex()==pOurModify->GetActionIndex()); 00467 } 00468 00469 // If the nudge has used TransformNodeActions don't merge to avoid 00470 // redraw problems 00471 if (PerformMerge && IS_A(pPrevAction, TransformNodeAction)) 00472 PerformMerge = FALSE; 00473 00474 pPrevAction = (Action*)pPrevOp->GetUndoActionList()->GetNext(pPrevAction); 00475 pOurAction = (Action*)GetUndoActionList()->GetNext(pOurAction); 00476 } 00477 00478 // Perform the merge 00479 if (PerformMerge) 00480 { 00481 // In order to merge these two ops we can just throw away this op! 00482 pOpHist->DeleteLastOp(); 00483 } 00484 } 00485 } 00486 }
|
|
Definition at line 153 of file pathndge.h. |
|
Definition at line 150 of file pathndge.h. |
|
Definition at line 155 of file pathndge.h. |
|
Definition at line 154 of file pathndge.h. |
|
Definition at line 147 of file pathndge.h. |
|
Definition at line 148 of file pathndge.h. |