OpCloseNodePaths Class Reference

This operation is for closing all the open selected paths. More...

#include <pathedit.h>

Inheritance diagram for OpCloseNodePaths:

OpNodePathAddEndpoint OpNodePathEditBlob SelOperation UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpCloseNodePaths ()
void DoWithParam (OpDescriptor *pOpDesc, OpParam *pOpParam)
 Closes all the selected open paths whose ends are selected.

Static Public Member Functions

static BOOL Init ()
 Adds the operation to the list of all known operations.
static OpState GetState (String_256 *Description, OpDescriptor *)
 Find out the state of the operation at the specific time. Greyed unless there is an open path with the start or end selected.

Protected Member Functions

BOOL CloseThisPath (NodePath *pPath)
 Sets up the member variables and then calls OpNodePathAddEndpoint::CompleteThisPath to do all the work in closing the path.

Static Protected Member Functions

static BOOL IsThisPathCloseable (NodePath *pPath)
 Finds out wether a path can be autoclosed. It can if it is not closed and the first or last endpoints in the last sub-path are selected.

Detailed Description

This operation is for closing all the open selected paths.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/12/95

Definition at line 374 of file pathedit.h.


Constructor & Destructor Documentation

OpCloseNodePaths::OpCloseNodePaths  )  [inline]
 

Definition at line 379 of file pathedit.h.

00379 : OpNodePathAddEndpoint() { };


Member Function Documentation

BOOL OpCloseNodePaths::CloseThisPath NodePath pPath  )  [protected]
 

Sets up the member variables and then calls OpNodePathAddEndpoint::CompleteThisPath to do all the work in closing the path.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/12/95
Parameters:
pPath - the path to close [INPUTS]
- [OUTPUTS]
Returns:
TRUE/FALSE for success/failure

Definition at line 10675 of file pathedit.cpp.

10676 {
10677     PathFlags* Flags = NULL;
10678     PathVerb* Verbs = NULL;
10679     DocCoord* Coords = NULL;
10680     pPath->InkPath.GetPathArrays(&Verbs, &Coords, &Flags);
10681     ERROR2IF( (Flags==NULL) || (Verbs==NULL) || (Coords==NULL), FALSE, "Path array pointer was NULL");
10682     INT32 NumCoords = pPath->InkPath.GetNumCoords();
10683 
10684     // Setup all member variables relating to this path
10685     InsertPosition = NumCoords-1;
10686     OriginalPath = pPath;
10687     StartMousePos = Coords[NumCoords-1];
10688     LastMousePos = Coords[NumCoords-1];
10689     StartSpread = pPath->FindParentSpread();
10690     UpdatePoint = -1;
10691     ERROR2IF( StartSpread==NULL, FALSE, "Path was not on a spread");
10692     
10693     // We also need to make a version of the path that we can change
10694     BOOL ok = BuildEditPath(LastMousePos);
10695 
10696     if (ok)
10697         ok = CompleteThisPath(StartMousePos);
10698 
10699     EditPath.ClearPath();
10700     
10701     return ok;
10702 }

void OpCloseNodePaths::DoWithParam OpDescriptor pOpDesc,
OpParam pOpParam
[virtual]
 

Closes all the selected open paths whose ends are selected.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/12/95
Parameters:
pOpParam->Param1 = TRUE = close with curve, FALSE = close with line [INPUTS] pOpParam->Param2 = TRUE = close with smooth, FALSE = close with cusp
- [OUTPUTS]
Returns:
-

Reimplemented from Operation.

Definition at line 10609 of file pathedit.cpp.

10610 {
10611     BeginSlowJob();
10612 
10613     BOOL ok = TRUE;
10614     AddCurveFlag = pOpParam->Param1;
10615     AddSmoothFlag = pOpParam->Param2;
10616     IsPathClosing = TRUE;
10617     
10618     // Start the sel operation
10619     if (ok)
10620         ok = DoStartSelOp(TRUE, TRUE);
10621 
10622     // Get the selection range and the first selected object
10623     SelRange* pSelection = GetApplication()->FindSelection();
10624     Node* pSelNode = pSelection->FindFirst();
10625 
10626     // Test all selected objects
10627     while (ok && (pSelNode != NULL))
10628     {
10629         if (pSelNode->IsNodePath())
10630         {
10631             if (IsThisPathCloseable((NodePath*)pSelNode))
10632             {
10633                 NodePath *pPath = (NodePath*)pSelNode;
10634 //              BOOL skip = FALSE;
10635 
10636                 // Create and send a change message about this path edit
10637                 ObjChangeParam ObjChange(OBJCHANGE_STARTING,ObjChangeFlags(), pPath, this);
10638                 if (pPath->AllowOp(&ObjChange))
10639                     ok = CloseThisPath(pPath);
10640             }
10641         }
10642 
10643         pSelNode = pSelection->FindNext(pSelNode);
10644     }
10645 
10646     // Inform all the parents of this node that it has been changed.
10647     if (ok)
10648     {
10649         ObjChangeParam ObjFinished(OBJCHANGE_FINISHED, ObjChangeFlags(), NULL, this);
10650         ok = UpdateChangedNodes(&ObjFinished);
10651     }
10652 
10653     if (!ok)
10654     {
10655         FailAndExecute();
10656         InformError();
10657     }
10658 
10659     End();
10660 }

OpState OpCloseNodePaths::GetState String_256 Description,
OpDescriptor
[static]
 

Find out the state of the operation at the specific time. Greyed unless there is an open path with the start or end selected.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/12/95
Parameters:
- [OUTPUTS]
Returns:
The state of the operation, so that menu items (ticks and greying can be done properly

Reimplemented from OpNodePathAddEndpoint.

Definition at line 10569 of file pathedit.cpp.

10570 {
10571     OpState Blobby(FALSE, TRUE);        // unticked and greyed
10572 
10573     // Get the selection range and the first selected object
10574     SelRange* pSelection = GetApplication()->FindSelection();
10575     ERROR2IF(pSelection == NULL, Blobby, "No SelRange!");
10576     Node* pSelNode = pSelection->FindFirst();
10577 
10578     // Test all selected objects
10579     while (pSelNode != NULL)
10580     {
10581         if (pSelNode->IsNodePath())
10582         {
10583             if (IsThisPathCloseable((NodePath*)pSelNode))
10584             {
10585                 Blobby.Greyed = FALSE;
10586                 break;
10587             }
10588         }
10589 
10590         pSelNode = pSelection->FindNext(pSelNode);
10591     }
10592 
10593     return Blobby;
10594 }

BOOL OpCloseNodePaths::Init void   )  [static]
 

Adds the operation to the list of all known operations.

> StorePathSubSelStateAction::StorePathSubSelStateAction()

Author: Peter Created: 9/11/95 Purpose: Constructor. Initalises member variables !/ StorePathSubSelStateAction::StorePathSubSelStateAction() { pStatePath = NULL; pIndexArray = NULL; NumStoredIndexes = 0; RecordingSelected = TRUE; }

/*! > StorePathSubSelStateAction::~StorePathSubSelStateAction()

Author: Peter Created: 9/11/95 Purpose: Destructor. Frees claimed memory !/ StorePathSubSelStateAction::~StorePathSubSelStateAction() { if (pIndexArray != NULL) CCFree(pIndexArray); }

/*! > static ActionCode StorePathSubSelStateAction::DoRecord(Operation* pOp, ActionList* pActionList, Path* pPath) Author: Peter Created: 9/11/95 Inputs: pOp = a pointer to the current operation pActionList = a pointer to the action list to which the action should be appended pPath = a pointer to the path whose data will be saved. Outputs: Sets up action, recording the sub-selection state. Returns: ActionCode, one of AC_OK, AC_NO_RECORD or AC_FAIL Purpose: Use this function to the sub-selection state of a path in your operation. It's a wrapper around StorePathSubSelStateAction::Init. Errors: - SeeAlso: StorePathSubSelStateAction::Init() !/ ActionCode StorePathSubSelStateAction::DoRecord(Operation* pOp, ActionList* pActionList, Path* pPath) { StorePathSubSelStateAction* SaveAction = NULL; return StorePathSubSelStateAction::Init(pOp, pActionList, pPath, (Action**)&SaveAction); }

/*! > static ActionCode StorePathSubSelStateAction::Init(Operation* pOp, ActionList* pActionList, Path* pPath, Action** NewAction) Author: Peter Created: 9/11/95 Inputs: pOp = a pointer to the operation to which this action belongs pActionList = the action list to which this action should be added pPath = a pointer to the path whose data will be saved. Outputs: The action is created, the path state is stored and the action is inserted into the actionlist Returns: ActionCode, one of AC_OK, AC_NO_RECORD or AC_FAIL Purpose: The purpose of this function is to create instances of StorePathSubSelStateAction. The action stores the sub-selection state of the given path. It either stores the indexes of the selected endpoints, or the unselected ones, depending on which will use less memory. NOTE: Don't call this function directly - call DoRecord() SeeAlso: StorePathSubSelStateAction::DoRecord() !/ ActionCode StorePathSubSelStateAction::Init(Operation* pOp, ActionList* pActionList, Path* pPath, Action** NewAction) { ERROR2IF((pPath==NULL) || (pOp==NULL) || (pActionList==NULL), AC_FAIL, "StorePathSubSelStateAction::Init() passed a NULL pointer");

// Work out how much memory the action array will require const UINT32 NumElements = pPath->GetNumCoords(); // Number of elements in the path PathFlags* pFlags = pPath->GetFlagArray(); // Pointer to the element flags UINT32 SelectedPoints = 0; // Count of selected endpoints UINT32 UnselectedPoints = 0; // Count of unselected endpoints. for (UINT32 loop = 0; loop<NumElements; loop++) { if (pFlags[loop].IsEndPoint) { if (pFlags[loop].IsSelected) SelectedPoints++; else UnselectedPoints++; } } const UINT32 ArraySize = sizeof(UINT32) * __min(SelectedPoints,UnselectedPoints);

// Create the action object UINT32 ActSize = sizeof(SavePathArraysAction) + ArraySize; ActionCode Ac = Action::Init( pOp, pActionList, ActSize, CC_RUNTIME_CLASS(StorePathSubSelStateAction), NewAction);

// Complete the setup of the action if ((Ac == AC_OK) && (*NewAction != NULL)) { StorePathSubSelStateAction* CreatedAction = (StorePathSubSelStateAction*)(*NewAction); CreatedAction->pStatePath = pPath; CreatedAction->RecordingSelected = (SelectedPoints < UnselectedPoints); CreatedAction->NumStoredIndexes = __min(SelectedPoints,UnselectedPoints);

// Store the indexes of the selected or unselected points if (ArraySize > 0) { // Claim memory for the array (theoritically this wont fail as Init ensured there was enough) ALLOC_WITH_FAIL(CreatedAction->pIndexArray, ((UINT32*)CCMalloc(ArraySize)), pOp); if (CreatedAction->pIndexArray != NULL) { pFlags = pPath->GetFlagArray(); // Recache flag array pointer (it may have moved) UINT32 ArrayIndex = 0;

// Store the index of the endpoints whose selection state matches what we are storing for (UINT32 loop = 0; loop<NumElements; loop++) { if (pFlags[loop].IsEndPoint && (pFlags[loop].IsSelected == CreatedAction->RecordingSelected) ) CreatedAction->pIndexArray[ArrayIndex++] = loop; } } else CreatedAction->RecordingSelected = FALSE; // Deselect the lot } }

return Ac; }

/*! > ActionCode StorePathSubSelStateAction::Execute()

Author: Peter Created: 9/11/95 Inputs: - Returns: one of AC_OK, AC_NORECORD, AC_FAIL Purpose: This function creates a new action to store the path sub-selection state the sets the sub-selection state to the one in the stored arrays !/ ActionCode StorePathSubSelStateAction::Execute() { ERROR2IF(pStatePath == NULL, AC_FAIL, "Path pointer was NULL");

// first try to create an opposite action StorePathSubSelStateAction* SaveAction; ActionCode Act = StorePathSubSelStateAction::Init(pOperation, pOppositeActLst, pStatePath, (Action**)(&SaveAction)); if (Act == AC_FAIL) return AC_FAIL;

// now set the path sub-selection state to what we have recorded. const UINT32 NumElements = pStatePath->GetNumCoords(); // Number of elements in the path PathFlags* pFlags = pStatePath->GetFlagArray(); // Pointer to the element flags if (pIndexArray == NULL) { // Set all the endpoints to the stored selection state if (RecordingSelected) pStatePath->ClearSubSelection(); else pStatePath->SetAllSubSelection(); } else { // Set indexed endpoints to the stored selection state, and the others to the opposite UINT32 ArrayIndex = 0; for (UINT32 loop = 0; loop<NumElements; loop++) { if (pFlags[loop].IsEndPoint) { if ((ArrayIndex < NumStoredIndexes) && (pIndexArray[ArrayIndex] == loop)) { pFlags[loop].IsSelected = RecordingSelected; ArrayIndex ++; } else pFlags[loop].IsSelected = !RecordingSelected; } } }

// Clean up the control points selection state pStatePath->EnsureSelection(TRUE);

return Act; }

/*!

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/12/95
Returns:
TRUE if all went OK, FALSE if initalisation failed

Reimplemented from OpNodePathAddEndpoint.

Definition at line 10549 of file pathedit.cpp.

10550 {
10551     const INT32 HID_AUTOCLOSEPATHS = 0;
10552     BTNOP( AUTOCLOSEPATHS, OpCloseNodePaths, ARRANGE)
10553     return TRUE;                                             
10554 }

BOOL OpCloseNodePaths::IsThisPathCloseable NodePath pPath  )  [static, protected]
 

Finds out wether a path can be autoclosed. It can if it is not closed and the first or last endpoints in the last sub-path are selected.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/12/95
Parameters:
pPath - a pointer to a path [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the path can be autoclosed, FALSE if not

Definition at line 10717 of file pathedit.cpp.

10718 {
10719     BOOL Closeable = FALSE;
10720     PathFlags* Flags = NULL;
10721     PathVerb* Verbs = NULL;
10722     pPath->InkPath.GetPathArrays(&Verbs, NULL, &Flags);
10723     if ((Flags==NULL) || (Verbs==NULL))
10724     {
10725         ERROR3("Path array pointer was NULL");
10726         return FALSE;
10727     }
10728     INT32 NumCoords = pPath->InkPath.GetNumCoords();
10729 
10730     // See if the end of the (last sub-path of the) path is open
10731     if (!(Verbs[NumCoords-1] & PT_CLOSEFIGURE))
10732     {
10733         // Get the coord of the start of the sub-path
10734         INT32 SubPathStart = NumCoords-1;
10735         pPath->InkPath.FindStartOfSubPath(&SubPathStart);
10736 
10737         // Is the path longer than one line and is the first or last point selected?
10738         if (SubPathStart < (NumCoords-2))
10739             Closeable = (Flags[NumCoords-1].IsSelected || Flags[SubPathStart].IsSelected);
10740     }
10741 
10742     return Closeable;
10743 }


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:44 2007 for Camelot by  doxygen 1.4.4