Cortex  10.0.0-a4
ParameterisedHolder.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_PARAMETERISEDHOLDER_H
36 #define IE_COREMAYA_PARAMETERISEDHOLDER_H
37 
38 class MPxNode;
39 class MPxLocatorNode;
40 class MPxDeformerNode;
41 class MPxObjectSet;
42 class MPxFieldNode;
43 class MPxSurfaceShape;
44 class MPxComponentShape;
45 class MPxImagePlane;
46 
47 #include "IECore/Parameterised.h"
48 
49 #include "IECoreMaya/ParameterisedHolderInterface.h"
50 #include "IECoreMaya/MStringLess.h"
51 #include "IECoreMaya/PostLoadCallback.h"
52 
53 namespace IECoreMaya
54 {
55 
69 template< typename BaseType >
70 class ParameterisedHolder : public BaseType, public ParameterisedHolderInterface
71 {
72 
73  public:
74 
76  virtual ~ParameterisedHolder();
77 
78  static void *creator();
79  static MStatus initialize();
80 
83  static MTypeId id;
84  static MString typeName;
85 
86  virtual void postConstructor();
87  virtual MStatus setDependentsDirty( const MPlug &plug, MPlugArray &plugArray );
88  virtual MStatus shouldSave( const MPlug &plug, bool &isSaving );
89 
92 
93  virtual MStatus setParameterised( IECore::RunTimeTypedPtr p );
97  virtual MStatus setParameterised( const std::string &className, int classVersion, const std::string &searchPathEnvVar );
98  virtual MStatus updateParameterised();
99  virtual IECore::RunTimeTypedPtr getParameterised( std::string *className = 0, int *classVersion = 0, std::string *searchPathEnvVar = 0 );
100  virtual MStatus setNodeValues();
101  virtual MStatus setNodeValue( IECore::ParameterPtr pa );
102  virtual MStatus setParameterisedValues();
103  virtual MStatus setParameterisedValue( IECore::ParameterPtr pa );
104  virtual MPlug parameterPlug( IECore::ConstParameterPtr parameter );
105  virtual IECore::ParameterPtr plugParameter( const MPlug &plug );
107 
110  static MObject aParameterisedClassName;
111  static MObject aParameterisedVersion;
112  static MObject aParameterisedSearchPathEnvVar;
114 
115  protected :
116 
119  MStatus setParameterisedValues( bool lazy );
121  MStatus createOrUpdateAttribute( IECore::ParameterPtr parameter, const MString &attributeName, bool callRestore=false );
122 
123  private:
124 
125  IECore::RunTimeTypedPtr loadClass( const MString &className, int classVersion, const MString &searchPathEnvVar );
126 
129  MStatus createAndRemoveAttributes( bool callRestore = false );
130  // Makes (or updates existing) attributes for each parameter. Also fills in the two maps below.
131  // This method is called by getParameterised(), so you should call that before expecting the maps
132  // to be up to date.
133  MStatus createAttributesWalk( IECore::ConstCompoundParameterPtr parameter, const std::string &rootName, bool callRestore );
134  typedef std::map<IECore::ParameterPtr, MString> ParameterToAttributeNameMap;
135  ParameterToAttributeNameMap m_parametersToAttributeNames;
136  typedef std::map<MString, IECore::ParameterPtr> AttributeNameToParameterMap;
137  AttributeNameToParameterMap m_attributeNamesToParameters;
138 
139  MStatus removeUnecessaryAttributes();
140 
141  void nonNetworkedConnections( const MPlug &plug, MPlugArray &connectionsFromPlug, MPlugArray &connectionsToPlug ) const;
142 
143  typedef std::set<IECore::ParameterPtr> ParameterSet;
145  ParameterSet m_dirtyParameters;
146 
147  bool setParameterisedValuesWalk( bool lazy, IECore::ParameterPtr parameter, MStatus &status );
148 
149  // We use this callback to instantiate the held Parameterised object once a scene had loaded.
150  // We need to do it at this point as things like the OpHolder need it in place before compute()
151  // is called (we can't instantiate it during compute as it may mean adding or removing attributes).
152  class PLCB : public PostLoadCallback
153  {
154  public:
155  PLCB( ParameterisedHolder<BaseType> *node );
156  protected:
157 
159 
160  void postLoad();
161  };
162  IE_CORE_DECLAREPTR( PLCB );
163 
164  PLCBPtr m_plcb;
165 
166  protected :
167 
168  IECore::RunTimeTypedPtr m_parameterised;
169  bool m_failedToLoad; // to avoid constantly trying to reload things that aren't there
170 
171  static const std::string g_attributeNamePrefix; // a prefix used to denote attributes that represent parameters
172 
173 };
174 
175 typedef ParameterisedHolder<MPxNode> ParameterisedHolderNode;
176 typedef ParameterisedHolder<MPxLocatorNode> ParameterisedHolderLocator;
177 typedef ParameterisedHolder<MPxDeformerNode> ParameterisedHolderDeformer;
178 typedef ParameterisedHolder<MPxFieldNode> ParameterisedHolderField;
179 typedef ParameterisedHolder<MPxObjectSet> ParameterisedHolderSet;
180 typedef ParameterisedHolder<MPxSurfaceShape> ParameterisedHolderSurfaceShape;
181 typedef ParameterisedHolder<MPxComponentShape> ParameterisedHolderComponentShape;
182 typedef ParameterisedHolder<MPxImagePlane> ParameterisedHolderImagePlane;
183 
184 }
185 
186 #endif // IE_COREMAYA_PARAMETERISEDHOLDERNODE_H
MStatus createOrUpdateAttribute(IECore::ParameterPtr parameter, const MString &attributeName, bool callRestore=false)
Creates an attribute to represent the specified parameter, or updates an existing attribute...
virtual MStatus setParameterisedValues()
Definition: ParameterisedHolderInterface.h:48
virtual MStatus setParameterisedValue(IECore::ParameterPtr pa)
static MTypeId id
Definition: ParameterisedHolder.h:83
virtual MStatus updateParameterised()
virtual IECore::ParameterPtr plugParameter(const MPlug &plug)
virtual MStatus setNodeValue(IECore::ParameterPtr pa)
The IECoreMaya namespace holds all the functionality of libIECoreMaya.
Definition: BoolParameterHandler.h:44
virtual MStatus setParameterised(IECore::RunTimeTypedPtr p)
Definition: PostLoadCallback.h:50
virtual IECore::RunTimeTypedPtr getParameterised(std::string *className=0, int *classVersion=0, std::string *searchPathEnvVar=0)
virtual MPlug parameterPlug(IECore::ConstParameterPtr parameter)
virtual MStatus setNodeValues()
Definition: ParameterisedHolder.h:70