Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
6.5 KiB

  1. //======= Copyright � 1996-2006, Valve Corporation, All rights reserved. ======
  2. //
  3. // Maya Undo helper, use it like this
  4. //
  5. // class CMyCmd : MPxCommand
  6. // {
  7. // // ... regular stuff ... //
  8. //
  9. // ValveMaya::CUndo m_undo;
  10. // };
  11. //
  12. // MStatus CMyCmd::doIt( const MArgList &mArgList )
  13. // {
  14. // m_undo.SetArgList( Syntax(), mArgList );
  15. // }
  16. //
  17. // MStatus CMyCmd::redoIt( const MArgList &mArgList )
  18. // {
  19. // // Get at command line args
  20. // m_undo.ArgDatabase().isFlagSet( ... );
  21. //
  22. // // Do operations
  23. // m_undo.SaveCurrentSelection();
  24. // m_undo.DagModifier().createNode( ... );
  25. // m_undo.DagModifierDoIt();
  26. // m_undo.SetAttr( mPlug, value );
  27. //
  28. // /// etc ...
  29. // }
  30. //
  31. // MStatus CMyCmd::undoIt( const MArgList &mArgList )
  32. // {
  33. // m_undo.Undo();
  34. // }
  35. //
  36. // bool CMyCmd::isUndoable()
  37. // {
  38. // return m_undo.IsUndoable();
  39. // }
  40. //
  41. // If there's a need to get fancy, any of the CUndoOp* classes can be
  42. // constructed via 'new' and a boost::shared_ptr< CUndoOp > constructed
  43. // with that pointed can be passed to CUndo::Push(). Note that means
  44. // that the pointer will be managed by boost::shared_ptr so if the
  45. // lifetime of the data needs to be controlled by the caller (it shouldn't)
  46. // then a shared_ptr should be kept
  47. //
  48. // Setting the ArgList and using ArgDatabase doesn't affect the undo/redo
  49. // ability but it's a convnient place to keep that data
  50. //
  51. //=============================================================================
  52. #ifndef VALVEMAYA_UNDO_H
  53. #define VALVEMAYA_UNDO_H
  54. #if defined( _WIN32 )
  55. #pragma once
  56. #endif
  57. // Standard includes
  58. // Maya includes
  59. #include <maya/MArgDatabase.h>
  60. #include <maya/MArgList.h>
  61. #include <maya/MDagModifier.h>
  62. #include <maya/MDagPath.h>
  63. #include <maya/MObject.h>
  64. #include <maya/MPlug.h>
  65. #include <maya/MSelectionList.h>
  66. #include <maya/MStatus.h>
  67. #include <maya/MString.h>
  68. #include <maya/MSyntax.h>
  69. #include <maya/MTransformationMatrix.h>
  70. // Valve includes
  71. #include "tier1/utlstack.h"
  72. namespace ValveMaya
  73. {
  74. // Forward declarations
  75. class CUndoOp;
  76. //=============================================================================
  77. //
  78. //
  79. // CUndo: Undo stack manager class
  80. //
  81. //
  82. //=============================================================================
  83. class CUndo
  84. {
  85. public:
  86. CUndo();
  87. ~CUndo();
  88. void Clear();
  89. MStatus SetArgList(
  90. const MSyntax &mSyntax,
  91. const MArgList &mArgList );
  92. const MArgDatabase &ArgDatabase();
  93. void SaveCurrentSelection();
  94. MDagModifier &DagModifier();
  95. MStatus DagModifierDoIt();
  96. MStatus Connect(
  97. const MPlug &srcP,
  98. const MPlug &dstP,
  99. bool force = false );
  100. bool SetAttr(
  101. MPlug &mPlug,
  102. MObject &val );
  103. bool SetAttr(
  104. MPlug &mPlug,
  105. double val );
  106. bool Lock(
  107. MPlug &mPlug,
  108. bool lock );
  109. void NodeCreated( MObject &nodeObject );
  110. void Push(
  111. CUndoOp *pUndoOp );
  112. bool IsUndoable() const;
  113. MStatus Undo();
  114. protected:
  115. MArgDatabase *m_pArgDatabase;
  116. CUtlStack< CUndoOp * > m_undoStack;
  117. };
  118. //=============================================================================
  119. //
  120. //
  121. // CUndoOp: Undo stack member abstract base class
  122. //
  123. //
  124. //=============================================================================
  125. class CUndoOp
  126. {
  127. public:
  128. virtual ~CUndoOp()
  129. {
  130. }
  131. virtual void Undo() = 0;
  132. };
  133. //=============================================================================
  134. //
  135. //
  136. // CUndoOpDagModifier: Undo stack member Dag Modifier class
  137. //
  138. //
  139. //=============================================================================
  140. class CUndoOpDagModifier : public CUndoOp
  141. {
  142. public:
  143. virtual ~CUndoOpDagModifier()
  144. {
  145. }
  146. virtual void Undo()
  147. {
  148. m_mDagModifier.undoIt();
  149. }
  150. protected:
  151. friend class CUndo;
  152. MDagModifier m_mDagModifier;
  153. };
  154. //=============================================================================
  155. //
  156. //
  157. // CUndoOpSetAttr: Undo stack member for setting attributes
  158. //
  159. //
  160. //=============================================================================
  161. class CUndoOpSetAttr : public CUndoOp
  162. {
  163. public:
  164. CUndoOpSetAttr(
  165. MPlug &mPlug,
  166. MObject &mObjectVal );
  167. CUndoOpSetAttr(
  168. MPlug &mPlug,
  169. double numericVal );
  170. virtual ~CUndoOpSetAttr()
  171. {
  172. }
  173. virtual void Undo();
  174. protected:
  175. MPlug m_mPlug;
  176. MObject m_mObjectVal;
  177. double m_numericVal;
  178. const bool m_numeric;
  179. private:
  180. // Visual C++ is retarded - tell it there's no assignment operator
  181. CUndoOpSetAttr &operator=( const CUndoOpSetAttr &rhs );
  182. };
  183. //=============================================================================
  184. //
  185. //
  186. // CUndoOpSelection: Undo stack member for changing selection
  187. //
  188. //
  189. //=============================================================================
  190. class CUndoOpSelection : public CUndoOp
  191. {
  192. public:
  193. CUndoOpSelection();
  194. virtual ~CUndoOpSelection()
  195. {
  196. }
  197. virtual void Undo();
  198. protected:
  199. MSelectionList m_mSelectionList;
  200. };
  201. //=============================================================================
  202. //
  203. //
  204. // CUndoOpSelection: Undo stack member for locking and unlocking attributes
  205. //
  206. //
  207. //=============================================================================
  208. class CUndoOpLock : public CUndoOp
  209. {
  210. public:
  211. CUndoOpLock(
  212. MPlug &mPlug,
  213. bool lock );
  214. virtual ~CUndoOpLock()
  215. {
  216. }
  217. virtual void Undo();
  218. protected:
  219. MPlug m_mPlug;
  220. const bool m_locked;
  221. private:
  222. // Visual C++ is retarded - tell it there's no assignment operator
  223. CUndoOpLock &operator=( const CUndoOpLock &rhs );
  224. };
  225. //=============================================================================
  226. //
  227. //=============================================================================
  228. class CUndoOpResetRestPosition : public CUndoOp
  229. {
  230. public:
  231. CUndoOpResetRestPosition(
  232. const MDagPath &mDagPath );
  233. virtual ~CUndoOpResetRestPosition()
  234. {
  235. }
  236. virtual void Undo();
  237. protected:
  238. const MDagPath m_mDagPath;
  239. MTransformationMatrix m_matrix;
  240. };
  241. //=============================================================================
  242. // For node creation via something like MFnMesh::create, etc..
  243. //=============================================================================
  244. class CUndoOpNodeCreated : public CUndoOp
  245. {
  246. public:
  247. CUndoOpNodeCreated(
  248. MObject &mObject );
  249. virtual ~CUndoOpNodeCreated()
  250. {
  251. }
  252. virtual void Undo();
  253. protected:
  254. MObject m_nodeObject;
  255. };
  256. }
  257. #endif // VALVEMAYA_UNDO_H