RefMgrAddDeleteRestore< T > Class Template Reference
 
 
 
RefMgrAddDeleteRestore< T > Class Template Reference

#include <referencemgr.h>

Inheritance diagram for RefMgrAddDeleteRestore< T >:
RestoreObj ReferenceMaker InterfaceServer Animatable MaxHeapOperators InterfaceServer Noncopyable MaxHeapOperators MaxHeapOperators

Class Description

template<class T>
class RefMgrAddDeleteRestore< T >

Restore class for RefTarget class Note, Do not use this class as this is used by the internal system only.

This class will be removed in future versions of the SDK. The template type must be class RefTarget (or derived from it). This handles undo and redo special in the RefMgr class. This is because the system needs to save the object that it is storing along with the reference. This overrides DeleteReference to add a special undo record to the undo stack.

Public Member Functions

  RefMgrAddDeleteRestore (RefMgr< T > *mgr, int which, RefTargetHandle ref)
  ~RefMgrAddDeleteRestore ()
virtual Class_ID  ClassID ()
  Retrieves a constant that uniquely identifies the plugin class.
virtual void  GetClassName (MSTR &s)
  Retrieves the name of the plugin class.
void  Restore (int isUndo)
  Restore handles both undo and redo.
void  Redo ()
MSTR  Description ()
virtual RefResult  NotifyRefChanged (Interval changeInt, RefTargetHandle hTarget, PartID &partID, RefMessage message)
  Receives and responds to messages.
virtual int  NumRefs ()
  Returns the total number of references this ReferenceMaker can hold.
virtual RefTargetHandle  GetReference (int i)
  Returns the 'i-th' reference.
virtual BOOL  CanTransferReference (int i)
  Tells whether this reference can be transfered.

Protected Member Functions

virtual void  SetReference (int i, RefTargetHandle rtarg)
  Stores a ReferenceTarget as its 'i-th' reference`.

Constructor & Destructor Documentation

RefMgrAddDeleteRestore ( RefMgr< T > *  mgr,
int  which,
RefTargetHandle  ref 
) [inline]
                : mMgr(NULL), mRefTarg(which < 0 ? NULL : mgr->GetRefTarget(which)), mRef(ref), undone(FALSE)
        {
                ReplaceReference(0, mgr);
                if (mRefTarg != NULL)
                        mRefTarg->SetHeld(true);
        }
~RefMgrAddDeleteRestore ( ) [inline]
        {
                if (mRefTarg != NULL) {
                        if (mMgr != NULL)
                                mMgr->RemoveRef(mRefTarg);
                        delete mRefTarg;
                }
                DeleteAllRefs();
        }

Member Function Documentation

virtual Class_ID ClassID ( ) [inline, virtual]

Retrieves a constant that uniquely identifies the plugin class.

This method must return the unique ID for the plugin class. If two ClassIDs conflict, the system will only load the first conflicting one it finds. A program (gencid.exe) is provided to generate unique class id values.

Returns:
A class id that uniquely identifies a plugin class
See also:
Class ClassID, List of Class IDs.

Reimplemented from Animatable.

{ return Class_ID(0x102f266c, 0x23492667); }
virtual void GetClassName ( MSTR s ) [inline, virtual]

Retrieves the name of the plugin class.

This name is usually used internally for debugging purposes. For Material plug-ins this method is used to put up the material "type" name in the Material Editor.

Parameters:
s Reference to a string filled in with the name of the plugin class

Reimplemented from ReferenceMaker.

{ s = _M("RefMgrAddDeleteRestore"); }
void Restore ( int  isUndo ) [inline, virtual]

Restore handles both undo and redo.

It swaps mRefTarg with any reference already in the RefMgr. Really should implement both Restore and Redo, but doing so breaks compatibility. So Restore needs to check to see whether it is really doing a Restore or a Redo. In some cases, Restore can be called twice in a row, with no interleaving Redo(). For example, theHold.Restore();theHold.Cancel(); No know case of Redo being called twice in a row, but play it safe. member variable 'undone' used as interlock

Implements RestoreObj.

        {
                int isUndo2;
                BOOL isInRestore = theHold.Restoring(isUndo2);
                if (isInRestore)  // really doing a restore
                {
                        if (undone) return;
                        undone = TRUE;
                }
                else  // really doing a redo
                {
                        if (!undone) return;
                        undone = FALSE;
                }
                if (mMgr != NULL) {
                        if (mRefTarg == NULL) {
                                int i = mMgr->FindRefTargetHandleIndex(mRef);
                                if (i >= 0) {
                                        mRefTarg = mMgr->mRefTargetPtrs[i];
                                        mRefTarg->SetHeld(true);
                                        mMgr->mRefTargetPtrs.Delete(i, 1);
                                }
                        } else {
                                mMgr->RemoveRef(mRefTarg);
                                mRefTarg->SetRefTargetHandle(mRef);
                                mMgr->mRefTargetPtrs.Append(1, &mRefTarg, 3);
                                mRefTarg->SetHeld(false);
                                mRefTarg = NULL;
                        }
                }
        }
void Redo ( ) [inline, virtual]
Remarks:
This method is called when the user selects the Redo command. The developer should restore the database to the state prior to the last Undo command.

Implements RestoreObj.

{ Restore(false); }
MSTR Description ( ) [inline, virtual]
Remarks:
This method is used internally to 3ds Max in debugging only. It is used to display a symbolic name for the restore object.
Returns:
The name of the restore object.
Default Implementation:
{ return MSTR(_M("---")); }

Reimplemented from RestoreObj.

{ return _M("RefMgrAddDeleteRestore"); }
virtual RefResult NotifyRefChanged ( Interval  changeInt,
RefTargetHandle  hTarget,
PartID partID,
RefMessage  message 
) [inline, virtual]

Receives and responds to messages.

A plugin which makes references must implement a method to receive and respond to messages broadcast by its dependents. This is done by implementing NotifyRefChanged(). The plugin developer usually implements this method as a switch statement where each case is one of the messages the plugin needs to respond to. The Method StdNotifyRefChanged calls this, which can change the partID to new value. If it doesn't depend on the particular message& partID, it should return REF_DONTCARE.

  • For developer that need to update a dialog box with data about an object you reference note the following related to this method: This method may be called many times. For instance, say you have a dialog box that displays data about an object you reference. This method will get called many time during the drag operations on that object. If you updated the display every time you'd wind up with a lot of 'flicker' in the dialog box. Rather than updating the dialog box each time, you should just invalidate the window in response to the NotifyRefChanged() call. Then, as the user drags the mouse your window will still receive paint messages. If the scene is complex the user may have to pause (but not let up on the mouse) to allow the paint message to go through since they have a low priority. This is the way many windows in 3ds Max work.
Parameters:
changeInt - This is the interval of time over which the message is active. Currently, all plug-ins will receive FOREVER for this interval.
hTarget - This is the handle of the reference target the message was sent by. The reference maker uses this handle to know specifically which reference target sent the message.
partID - This contains information specific to the message passed in. Some messages don't use the partID at all. See the section List of Reference Messages for more information about the meaning of the partID for some common messages.
message - The message parameters passed into this method is the specific message which needs to be handled.
Returns:
The return value from this method is of type RefResult. This is usually REF_SUCCEED indicating the message was processed. Sometimes, the return value may be REF_STOP. This return value is used to stop the message from being propagated to the dependents of the item.

Implements ReferenceMaker.

        {
                switch (message) {
                case REFMSG_TARGET_DELETED:
                        mMgr = NULL;
                        break;
                }

                return REF_SUCCEED;
        }
virtual int NumRefs ( ) [inline, virtual]

Returns the total number of references this ReferenceMaker can hold.

The plugin implements this method to indicate the total number of of references it can make. This includes all references whether they are NULL (inactive) or non-NULL (active) at the time when this method is called. A plugin can hold a variable number of references, thus the return value of this method is not to be cached and reused by client code.

Returns:
The total number of references this plugin can hold. The default implementation is return 0.

Reimplemented from ReferenceMaker.

{ return 1; }
virtual RefTargetHandle GetReference ( int  i ) [inline, virtual]

Returns the 'i-th' reference.

The plugin implements this method to return its 'i-th' reference. The plug-in simply keeps track of its references using an integer index for each one. This method is normally called by the system.

Parameters:
i - The index of the reference to retrieve. Valid values are from 0 to NumRefs()-1.
Returns:
The reference handle of the 'i-th' reference. Note that different calls to this method with the same 'i' value can result in different reference handles being retrieved, as the plugin changes the scene objects it references as its 'i-th' reference.

Reimplemented from ReferenceMaker.

{ return i == 0 ? mMgr : NULL; }
virtual void SetReference ( int  i,
RefTargetHandle  rtarg 
) [inline, protected, virtual]

Stores a ReferenceTarget as its 'i-th' reference`.

The plugin implements this method to store the reference handle passed to it as its 'i-th' reference. In its implementation of this method, the plugin should simply assign the reference handle passed in as a parameter to the member variable that holds the 'i-th' reference. Other reference handling methods such as ReferenceMaker::DeleteReference(), or ReferenceMaker::ReplaceReference() should not be called from within this method. The plugin itself or other plugins should not call this method directly. The system will call this method when a new reference is created or an existing one is replaced by calling ReferenceMaker::ReplaceReference().

Parameters:
i - The index of the reference to store. Valid values are from 0 to NumRefs()-1.
rtarg - The reference handle to store.

Reimplemented from ReferenceMaker.

        {
                if (i == 0)
                        mMgr = static_cast<RefMgr<T>*>(rtarg);
        }
virtual BOOL CanTransferReference ( int  i ) [inline, virtual]

Tells whether this reference can be transfered.

A ReferenceMaker can choose not to let ReferenceTarget::TransferReferences() affect it. Note that plugins probably should not use this. It is used by certain system objects that have references.

Parameters:
i - Currently not used.
Returns:
Default to return TRUE

Reimplemented from ReferenceMaker.

{ return FALSE; }