//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ /* file : undoRedoMsgCmd.cpp class: undoRedoMsg ---------------------- This is an example to demonstrate how to listen to undo and redo message events. The syntax of the command is: undoRedoMsg add; undoRedoMsg remove; The add argument causes listening to undo/redo to be turned on. The remove argument causes undo/redo listening to be removed. */ #include #include #include #include #include #include #include #include #define UndoString "Undo" #define RedoString "Redo" // Static array to track the callback ids used static MCallbackIdArray callbackIds; // // The command which adds and removes the // callback listening // class undoRedoMsg : public MPxCommand { public: virtual MStatus doIt( const MArgList& ); void runTests(); static void *creator(); static MSyntax newSyntax(); }; // // Two callbacks - undo/redo // These callbacks should not change // the state of the scene. You can // update UI for modify local variables // etc. in these callbacks. // static void undoCB( void *clientData ) { MString info = "undoCallback : clientData = "; if ( clientData ) info += (unsigned)(MUintPtrSz)clientData; else info += "NULL"; MGlobal::displayInfo( info ); } static void redoCB( void *clientData ) { MString info = "redoCallback : clientData "; if ( clientData ) info += (unsigned)(MUintPtrSz) clientData; else info += "NULL"; MGlobal::displayInfo( info ); } MStatus undoRedoMsg::doIt( const MArgList& args ) { MStatus result = MS::kSuccess; if ( args.length() > 0 ) { MString argStr; unsigned last = args.length(); for ( unsigned i = 0; i < last; i++ ) { args.get( i, argStr ); if ( argStr == "add" ) { MCallbackId undoId = MEventMessage::addEventCallback( UndoString, undoCB, NULL, &result ); if ( MS::kSuccess != result ) return MS::kFailure; callbackIds.append( undoId ); MCallbackId redoId = MEventMessage::addEventCallback( RedoString, redoCB, NULL, &result ); if ( MS::kSuccess != result ) return MS::kFailure; callbackIds.append( redoId ); } else if ( argStr == "remove" ) { if ( MS::kSuccess != MMessage::removeCallbacks( callbackIds ) ) return MS::kFailure; } else { MGlobal::displayInfo("Failure condition"); return MS::kFailure; } } } return result; } // // Creator for the command // void* undoRedoMsg::creator() { return new undoRedoMsg; } // standard initialize and uninitialize functions MStatus initializePlugin(MObject obj) { // Version number may need to change in the future // MFnPlugin pluginFn(obj, "Alias", "6.0"); MStatus status; status = pluginFn.registerCommand("undoRedoMsg", undoRedoMsg::creator); if( !status) status.perror("register Command failed"); return status; } MStatus uninitializePlugin ( MObject obj ) { MFnPlugin pluginFn(obj); MStatus status = MS::kSuccess; // Remove the callbacks in case the command for doing // this has not been done. MMessage::removeCallbacks( callbackIds ); status = pluginFn.deregisterCommand("undoRedoMsg"); return status; }