Cortex  10.0.0-a4
ParameterisedHolderModificationCmd.h
1 //
3 // Copyright (c) 2010, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IECOREMAYA_PARAMETERISEDHOLDERMODIFICATIONCMD_H
36 #define IECOREMAYA_PARAMETERISEDHOLDERMODIFICATIONCMD_H
37 
38 #include <algorithm>
39 
40 #include "maya/MPxCommand.h"
41 #include "maya/MSyntax.h"
42 #include "maya/MStringArray.h"
43 
44 #include "IECore/CompoundData.h"
45 
46 #include "IECoreMaya/ParameterisedHolderInterface.h"
47 #include "IECoreMaya/MArrayIter.h"
48 
49 namespace IECoreMaya
50 {
51 
52 // This class has two purposes :
53 //
54 // 1) It is used by FnParameterisedHolder.setParameterised() to implement
55 // changing of the held class in an undoable way.
56 //
57 // 2) It is used by FnParameterisedHolder.parameterModificationContext()
58 // for the changing of the classes held by ClassParameter and ClassVectorParameter,
59 // and the setting of Parameter values. It must be implemented here as a command
60 // so that we can support undo for these operations.
61 //
62 // Under no circumstances should this class or the command it creates be
63 // used directly - it should be considered to be a private implementation
64 // detail of FnParameterisedHolder.
65 class ParameterisedHolderModificationCmd : public MPxCommand
66 {
67 
68  public :
69 
70  ParameterisedHolderModificationCmd();
71  virtual ~ParameterisedHolderModificationCmd();
72 
73  static void *creator();
74 
75  virtual bool isUndoable() const;
76  virtual bool hasSyntax() const;
77 
78  virtual MStatus doIt( const MArgList &argList );
79  virtual MStatus undoIt();
80  virtual MStatus redoIt();
81 
82  private :
83 
84  void restoreClassParameterStates( const IECore::CompoundData *classes, IECore::Parameter *parameter, const std::string &parentParameterPath );
85  void storeParametersWithNewValues( const IECore::Object *originalValue, const IECore::Object *newValue, const std::string &parameterPath );
86  void setNodeValuesForParametersWithNewValues() const;
87  void setNodeValue( IECore::Parameter *parameter ) const;
88  void despatchSetParameterisedCallbacks() const;
89  void despatchClassSetCallbacks() const;
90  IECore::Parameter *parameterFromPath( IECore::ParameterisedInterface *parameterised, const std::string &path ) const;
91 
92  MObject m_node;
93  ParameterisedHolderInterface *m_parameterisedHolder;
94 
95  IECore::ConstCompoundDataPtr m_originalClasses;
96  IECore::ConstCompoundDataPtr m_newClasses;
97 
98  IECore::ConstObjectPtr m_originalValues;
99  IECore::ConstObjectPtr m_newValues;
100  std::set<std::string> m_parametersWithNewValues;
101 
102  bool m_changingClass;
103  MString m_originalClassName;
104  int m_originalClassVersion;
105  MString m_originalSearchPathEnvVar;
106 
107  MString m_newClassName;
108  int m_newClassVersion;
109  MString m_newSearchPathEnvVar;
110 
111  // When using FnParameterisedHolder.classParameterModificationContext(), it is too late
112  // to calculate the state to undo back to in this command, so that state
113  // is passed in from the context manager instead. we also pass in the new values and
114  // classes for simplicity.
115  static IECore::ConstObjectPtr g_originalValue;
116  static IECore::ConstCompoundDataPtr g_originalClasses;
117  static IECore::ConstObjectPtr g_newValue;
118  static IECore::ConstCompoundDataPtr g_newClasses;
119  friend void IECoreMaya::parameterisedHolderAssignModificationState( IECore::ObjectPtr originalValue, IECore::CompoundDataPtr originalClasses, IECore::ObjectPtr newValue, IECore::CompoundDataPtr newClasses );
120 };
121 
122 }
123 
124 #endif // IECOREMAYA_PARAMETERISEDHOLDERMODIFICATIONCMD_H
Definition: Parameter.h:53
Definition: ParameterisedInterface.h:50
Definition: CompoundData.h:47
Definition: Object.h:104
The IECoreMaya namespace holds all the functionality of libIECoreMaya.
Definition: BoolParameterHandler.h:44