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 #include "camtypes.h"
00104 #include "pathndge.h"
00105
00106
00107
00108 #include "nodepath.h"
00109 #include "opnudge.h"
00110
00111 #include "pathedit.h"
00112
00113
00114 #include "ophist.h"
00115
00116 DECLARE_SOURCE("$Revision: 1282 $");
00117
00118 CC_IMPLEMENT_DYNCREATE(OpPathNudge,TransOperation)
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 #define IMPLEMENT_OPPATHNUDGE_CLASS(DIR,X_NUDGE_FACTOR,Y_NUDGE_FACTOR,UNDO_IDS) \
00153 CC_IMPLEMENT_DYNCREATE(OpPathNudge ## DIR,OpPathNudge) \
00154 void OpPathNudge ## DIR::Do(OpDescriptor* pOpDesc) \
00155 { \
00156 X_NudgeFactor = X_NUDGE_FACTOR; \
00157 Y_NudgeFactor = Y_NUDGE_FACTOR; \
00158 NudgeUndoIDS = UNDO_IDS; \
00159 OpPathNudge::Do(pOpDesc); \
00160 } \
00161
00162 IMPLEMENT_OPPATHNUDGE_CLASS (Up1,0,1,_R(IDS_UNDO_NUDGE_UP))
00163 IMPLEMENT_OPPATHNUDGE_CLASS (Up5,0,5,_R(IDS_UNDO_NUDGE_UP))
00164 IMPLEMENT_OPPATHNUDGE_CLASS (Up10,0,10,_R(IDS_UNDO_NUDGE_UP))
00165 IMPLEMENT_OPPATHNUDGE_CLASS (UpFifth,0,0.2,_R(IDS_UNDO_NUDGE_UP))
00166 IMPLEMENT_OPPATHNUDGE_CLASS (UpPixel1,0,1,_R(IDS_UNDO_NUDGE_UP))
00167 IMPLEMENT_OPPATHNUDGE_CLASS (UpPixel10,0,10,_R(IDS_UNDO_NUDGE_UP))
00168
00169
00170 IMPLEMENT_OPPATHNUDGE_CLASS (Down1,0,-1,_R(IDS_UNDO_NUDGE_DOWN))
00171 IMPLEMENT_OPPATHNUDGE_CLASS (Down5,0,-5,_R(IDS_UNDO_NUDGE_DOWN))
00172 IMPLEMENT_OPPATHNUDGE_CLASS (Down10,0,-10,_R(IDS_UNDO_NUDGE_DOWN))
00173 IMPLEMENT_OPPATHNUDGE_CLASS (DownFifth,0,-0.2,_R(IDS_UNDO_NUDGE_DOWN))
00174 IMPLEMENT_OPPATHNUDGE_CLASS (DownPixel1 ,0,-1,_R(IDS_UNDO_NUDGE_DOWN))
00175 IMPLEMENT_OPPATHNUDGE_CLASS (DownPixel10,0,-10,_R(IDS_UNDO_NUDGE_DOWN))
00176
00177 IMPLEMENT_OPPATHNUDGE_CLASS (Left1,-1,0,_R(IDS_UNDO_NUDGE_LEFT))
00178 IMPLEMENT_OPPATHNUDGE_CLASS (Left5,-5,0,_R(IDS_UNDO_NUDGE_LEFT))
00179 IMPLEMENT_OPPATHNUDGE_CLASS (Left10,-10,0,_R(IDS_UNDO_NUDGE_LEFT))
00180 IMPLEMENT_OPPATHNUDGE_CLASS (LeftFifth,-0.2,0,_R(IDS_UNDO_NUDGE_LEFT))
00181 IMPLEMENT_OPPATHNUDGE_CLASS (LeftPixel1 ,-1,0,_R(IDS_UNDO_NUDGE_LEFT))
00182 IMPLEMENT_OPPATHNUDGE_CLASS (LeftPixel10,-10,0,_R(IDS_UNDO_NUDGE_LEFT))
00183
00184
00185 IMPLEMENT_OPPATHNUDGE_CLASS (Right1,1,0,_R(IDS_UNDO_NUDGE_RIGHT))
00186 IMPLEMENT_OPPATHNUDGE_CLASS (Right5,5,0,_R(IDS_UNDO_NUDGE_RIGHT))
00187 IMPLEMENT_OPPATHNUDGE_CLASS (Right10,10,0,_R(IDS_UNDO_NUDGE_RIGHT))
00188 IMPLEMENT_OPPATHNUDGE_CLASS (RightFifth,0.2,0,_R(IDS_UNDO_NUDGE_RIGHT))
00189 IMPLEMENT_OPPATHNUDGE_CLASS (RightPixel1,1,0,_R(IDS_UNDO_NUDGE_RIGHT))
00190 IMPLEMENT_OPPATHNUDGE_CLASS (RightPixel10,10,0,_R(IDS_UNDO_NUDGE_RIGHT))
00191
00192 #define new CAM_DEBUG_NEW
00193
00194 MILLIPOINT OpPathNudge::NudgeStep = 2835;
00195 double OpPathNudge::X_NudgeFactor = 1;
00196 double OpPathNudge::Y_NudgeFactor = 0;
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 void OpPathNudge::Do(OpDescriptor* pOpDesc)
00212 {
00213 NudgeStep = OpNudge::GetNudgeStep();
00214
00215
00216 FIXED16 ScaledPixelWidth, ScaledPixelHeight;
00217 GetWorkingView()->GetScaledPixelSize(&ScaledPixelWidth, &ScaledPixelHeight) ;
00218 PixelNudge=ScaledPixelWidth.MakeDouble() ;
00219
00220
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
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
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
00281 if (pNode != NULL)
00282 ok = DoStartTransOp(FALSE, NULL);
00283
00284 while (ok && pNode!=NULL)
00285 {
00286
00287 if ( IS_A(pNode,NodePath) && (((NodePath*)pNode)->InkPath.IsSubSelection()) )
00288 {
00289
00290 ThisPath = (NodePath*)pNode;
00291
00292
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
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
00317
00318
00319
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
00346 pNode = Selection->FindFirst();
00347
00348 while (ok && pNode!=NULL)
00349 {
00350 if (IS_A(pNode,NodePath))
00351 {
00352
00353 Trans2DMatrix* TransMat = new Trans2DMatrix(Offset.x, Offset.y);
00354
00355
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 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 void OpPathNudge::GetOpName(String_256* OpName)
00402 {
00403 *OpName = String_256(NudgeUndoIDS);
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 void OpPathNudge::PerformMergeProcessing()
00421 {
00422 if (pOurDoc==NULL)
00423 {
00424 ERROR3("This operation had no document pointer");
00425 return;
00426 }
00427
00428
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
00438 Operation* pPrevOp = pOpHist->FindPrevToLastOp();
00439 if ((pPrevOp != NULL) && pPrevOp->IS_KIND_OF(OpPathNudge))
00440 {
00441 BOOL PerformMerge = TRUE;
00442
00443
00444 UINT32 NumPrevActions = pPrevOp->GetUndoActionList()->GetCount();
00445 UINT32 NumOurActions = GetUndoActionList()->GetCount();
00446 PerformMerge = (NumPrevActions == NumOurActions);
00447
00448
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
00457 PerformMerge = (pPrevAction->GetRuntimeClass() == pOurAction->GetRuntimeClass());
00458
00459
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
00470
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
00479 if (PerformMerge)
00480 {
00481
00482 pOpHist->DeleteLastOp();
00483 }
00484 }
00485 }
00486 }