Cortex  10.0.0-a4
ParameterHandler.h
1 //
3 // Copyright (c) 2007-2011, 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 IE_COREMAYA_PARAMETERHANDLER_H
36 #define IE_COREMAYA_PARAMETERHANDLER_H
37 
38 #include <map>
39 
40 #include "IECore/RefCounted.h"
41 #include "IECore/TypeIds.h"
42 #include "IECore/Object.h"
43 #include "IECore/Parameter.h"
44 
45 #include "maya/MObject.h"
46 #include "maya/MString.h"
47 #include "maya/MPlug.h"
48 
49 namespace IECoreMaya
50 {
51 
52 class ParameterHandler;
53 IE_CORE_DECLAREPTR( ParameterHandler );
54 
58 {
59 
60  public :
61 
66  static MPlug create( IECore::ConstParameterPtr parameter, const MString &plugName, MObject &node );
72  static MStatus update( IECore::ConstParameterPtr parameter, MPlug &plug );
74  static MStatus setValue( IECore::ConstParameterPtr parameter, MPlug &plug );
76  static MStatus setValue( const MPlug &plug, IECore::ParameterPtr parameter );
79  static MStatus restore( const MPlug &plug, IECore::ParameterPtr parameter );
80 
81  virtual ~ParameterHandler();
82 
83  template<class T>
84  struct Description
85  {
89  Description( IECore::TypeId parameterType, IECore::TypeId dataType = IECore::InvalidTypeId);
90  };
91 
92  protected:
93 
94  friend class ObjectParameterHandler;
95 
97  static ConstParameterHandlerPtr create( IECore::ConstParameterPtr parameter );
99  static ConstParameterHandlerPtr create( IECore::ConstObjectPtr object );
101  static ConstParameterHandlerPtr create( IECore::TypeId id );
102 
106  MPlug finishCreating( IECore::ConstParameterPtr parameter, MPlug &plug ) const;
108  MPlug finishCreating( IECore::ConstParameterPtr parameter, MObject &attribute, MObject &node ) const;
109 
115  MStatus finishUpdating( IECore::ConstParameterPtr parameter, MPlug &plug ) const;
117  MStatus finishUpdating( IECore::ConstParameterPtr parameter, MObject &attribute, MObject &node ) const;
118 
119  virtual MPlug doCreate( IECore::ConstParameterPtr parameter, const MString &plugName, MObject &node ) const = 0;
120  virtual MStatus doUpdate( IECore::ConstParameterPtr parameter, MPlug &plug ) const = 0;
121  virtual MStatus doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const = 0;
122  virtual MStatus doSetValue( const MPlug &plug, IECore::ParameterPtr parameter ) const = 0;
123  virtual MStatus doRestore( const MPlug &plug, IECore::ParameterPtr parameter ) const;
124 
125  private:
126 
127  static void registerHandler( IECore::TypeId parameterType, IECore::TypeId dataType, ConstParameterHandlerPtr handler );
128 
129  typedef std::map<IECore::TypeId, ConstParameterHandlerPtr> HandlerMap;
130 
131  static HandlerMap &handlers();
132 };
133 
134 } // namespace IECoreMaya
135 
136 #include "IECoreMaya/ParameterHandler.inl"
137 
138 #endif // IE_COREMAYA_PARAMETERHANDLER_H
static MStatus restore(const MPlug &plug, IECore::ParameterPtr parameter)
static MStatus setValue(IECore::ConstParameterPtr parameter, MPlug &plug)
Sets the value of plug to reflect the value of parameter.
MStatus finishUpdating(IECore::ConstParameterPtr parameter, MPlug &plug) const
Definition: ParameterHandler.h:57
static MPlug create(IECore::ConstParameterPtr parameter, const MString &plugName, MObject &node)
TypeId
Definition: TypeIds.h:46
MPlug finishCreating(IECore::ConstParameterPtr parameter, MPlug &plug) const
The IECoreMaya namespace holds all the functionality of libIECoreMaya.
Definition: BoolParameterHandler.h:44
Definition: RefCounted.h:124
static MStatus update(IECore::ConstParameterPtr parameter, MPlug &plug)