Cortex  10.0.0-a4
ParameterisedHolder.h
1 //
3 // Copyright 2010 Dr D Studios Pty Limited (ACN 127 184 954) (Dr. D Studios),
4 // its affiliates and/or its licensors.
5 //
6 // Copyright (c) 2010-2013, Image Engine Design Inc. All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
18 //
19 // * Neither the name of Image Engine Design nor the names of any
20 // other contributors to this software may be used to endorse or
21 // promote products derived from this software without specific prior
22 // written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
37 
38 #ifndef IECOREHOUDINI_PARAMETERISEDHOLDER_H
39 #define IECOREHOUDINI_PARAMETERISEDHOLDER_H
40 
41 #include "IECore/Parameter.h"
42 #include "IECore/CompoundParameter.h"
43 #include "IECore/MessageHandler.h"
44 
45 #include "IECoreHoudini/MessageHandler.h"
46 #include "IECoreHoudini/ParameterisedHolderInterface.h"
47 
48 namespace IECoreHoudini
49 {
50 
52 template<typename BaseType>
53 class ParameterisedHolder : public BaseType, public ParameterisedHolderInterface
54 {
55  public :
56 
57  ParameterisedHolder( OP_Network *net, const char *name, OP_Operator *op );
58  virtual ~ParameterisedHolder();
59 
60  static PRM_Template parameters[];
61  static CH_LocalVariable variables[];
62 
63  static PRM_Name pParameterisedClassCategory;
64  static PRM_Name pParameterisedClassName;
65  static PRM_Name pParameterisedVersion;
66  static PRM_Name pParameterisedSearchPathEnvVar;
67  static PRM_Name pMatchString;
68  static PRM_Name pReloadButton;
69  static PRM_Name pEvaluateParameters;
70  static PRM_Name pSwitcher;
71 
72  static PRM_Default matchStringDefault;
73  static PRM_Default switcherDefaults[];
74 
75  static PRM_ChoiceList classCategoryMenu;
76  static PRM_ChoiceList classNameMenu;
77  static PRM_ChoiceList classVersionMenu;
78 
82 
83  static void buildClassCategoryMenu( void *data, PRM_Name *menu, int maxSize, const PRM_SpareData *, const PRM_Parm * );
86  static void buildClassNameMenu( void *data, PRM_Name *menu, int maxSize, const PRM_SpareData *, const PRM_Parm * );
87  static void buildVersionMenu( void *data, PRM_Name *menu, int maxSize, const PRM_SpareData *, const PRM_Parm * );
88  static int reloadClassCallback( void *data, int index, float time, const PRM_Template *tplate );
89  static int reloadButtonCallback( void *data, int index, float time, const PRM_Template *tplate );
90  static void classNames( const std::string searchPathEnvVar, const std::string &matchString, std::vector<std::string> &names );
91  static void classVersions( const std::string className, const std::string searchPathEnvVar, std::vector<int> &versions );
92  static int defaultClassVersion( const std::string className, const std::string searchPathEnvVar );
94 
95  virtual const char *inputLabel( unsigned pos ) const;
96  virtual unsigned minInputs() const;
97  virtual unsigned maxInputs() const;
98 
101 
102  virtual void setParameterised( IECore::RunTimeTypedPtr p );
106  virtual void setParameterised( const std::string &className, int classVersion, const std::string &searchPathEnvVar );
107  virtual bool hasParameterised();
108  virtual IECore::RunTimeTypedPtr getParameterised();
110  virtual bool setNodeValues();
111  virtual void setParameterisedValues( double time );
113 
114  protected :
115 
118  virtual bool load( UT_IStream &is, const char *ext, const char *path );
119 
120  virtual IECore::MessageHandler *getMessageHandler();
121  virtual void setMessageHandler( IECore::MessageHandler *handler );
122 
126  void updateParameter( IECore::ParameterPtr parm, float now, std::string prefix="", bool top_level=false );
127 
130  virtual void setInputParameterValues( float now ) = 0;
131 
133  virtual void refreshInputConnections() = 0;
134 
138 
140  bool m_dirty;
141 
142  private :
143 
145  void load( const std::string &className, int classVersion, const std::string &searchPathEnvVar, bool updateGUI=true );
146 
148  IECore::RunTimeTypedPtr loadParameterised( const std::string &className, int classVersion, const std::string &searchPathEnvVar );
149 
151  template <class T, class U>
152  void checkForUpdate( bool do_update, T val, IECore::ParameterPtr parm )
153  {
154  if ( do_update )
155  {
156  typename U::Ptr data = IECore::runTimeCast<U>( parm->getValue() );
157  if ( val != data->readable() )
158  {
159  m_dirty = true;
160  }
161  }
162  }
163 
164  IECore::RunTimeTypedPtr m_parameterised;
165 
166  // stores the className of the currently loaded parameterised object (if any)
167  std::string m_loadedClassName;
168 
169  IECore::MessageHandlerPtr m_messageHandler;
170 
171 };
172 
173 } // namespace IECoreHoudini
174 
175 #endif // IECOREHOUDINI_PARAMETERISEDHOLDER_H
void updateParameter(IECore::ParameterPtr parm, float now, std::string prefix="", bool top_level=false)
virtual void setInputParameterValues(float now)=0
virtual bool hasParameterised()
Returns whether or not this node is holding a valid parameterised object.
virtual bool load(UT_IStream &is, const char *ext, const char *path)
std::vector< ParameterPtr > ParameterVector
A type to hold a vector of Parameters.
Definition: CompoundParameter.h:56
The IECoreHoudini namespace holds all the functionality of libIECoreHoudini.
Definition: CoreHoudini.h:51
Definition: ParameterisedHolderInterface.h:46
static void buildClassCategoryMenu(void *data, PRM_Name *menu, int maxSize, const PRM_SpareData *, const PRM_Parm *)
virtual void setParameterised(IECore::RunTimeTypedPtr p)
Definition: MessageHandler.h:58
bool m_dirty
Determines if the node is dirty.
Definition: ParameterisedHolder.h:140
virtual void refreshInputConnections()=0
updates the input connections to match the current loaded parameters
virtual void setParameterisedValues(double time)
Sets the values of the parameters of the held Parameterised object to reflect the values...
Class representing an OP node acting as a holder for the abstract Parameterised class.
Definition: ParameterisedHolder.h:53
virtual IECore::RunTimeTypedPtr getParameterised()
Returns the parameterised object held by this node.
IECore::CompoundParameter::ParameterVector m_inputParameters
Definition: ParameterisedHolder.h:137