HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PRM_RampUtils.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: PRM_RampUtils.h (Parameter Library)
7  */
8 
9 #ifndef __PRM_RampUtils_h__
10 #define __PRM_RampUtils_h__
11 
12 #include "PRM_API.h"
13 #include "PRM_Parm.h"
14 #include <SYS/SYS_Types.h>
15 
16 class UT_Ramp;
17 
18 /// Utility functions for working with ramp parameters.
20 {
21 public:
22  /// Helper enumeration for stating the type of value that should be set
23  /// when updating multi-parms from ramps.
25  {
27  PRM_FLOAT_TYPE
28  };
29 
30  /// Helper class for passing data to callback functions
31  /// when updating multi-parms from ramps.
32  class ValueData
33  {
34  public:
35  inline ValueData(
36  void *callee, fpreal t, PRM_Parm &p, int vector_index, int val,
37  bool set_key);
38  inline ValueData(
39  void *callee, fpreal t, PRM_Parm &p, int vector_index, fpreal val,
40  bool set_key);
41 
42  inline void *callee() const;
43  inline fpreal time() const;
44  inline PRM_Parm &parm() const;
45  inline int vectorIndex() const;
46  inline PRM_ValueType valueType() const;
47  inline int intValue() const;
48  inline fpreal floatValue() const;
49  inline bool setKey() const;
50 
51  private:
52  void *myCallee;
53  fpreal myTime;
54  PRM_Parm &myParm;
55  int myVectorIndex;
56  PRM_ValueType myValueType;
57  bool mySetKey;
58  int myIntValue;
59  fpreal myFloatValue;
60  };
61 
62  /// Callback function which sets values when updating multi-parms from
63  /// ramps.
64  typedef void (*SetValueCB)(ValueData value_info);
65 
66  /// Update ramp value from a multi parm.
67  static void updateRampFromMultiParm(
68  fpreal t, const PRM_Parm &m, UT_Ramp *ramp,
69  bool *time_dep = NULL, DEP_MicroNode *depnode = NULL);
70 
71  /// Update multi parm from a ramp value.
72  static void updateMultiParmFromRamp(
73  fpreal t, const UT_Ramp &ramp, PRM_Parm &m, bool add_wrap,
74  bool set_key);
75 
76  /// Update multi parm from a ramp value.
77  /// This method version takes in a callback function that sets the values
78  /// in the multi parm.
79  static void updateMultiParmFromRamp(
80  fpreal t, const UT_Ramp &ramp, PRM_Parm &m, bool add_wrap,
81  bool set_key, SetValueCB set_value_cb, void *cb_callee);
82 
83  /// Write out the ramp parameter values as an encoding of ramp defaults.
84  static void setRampDefaultFromParm(UT_OStringStream &defaults_os,
85  const PRM_Parm &ramp_parm);
86 
87  /// Parse the ramp defaults and set them as values on the parameter
88  static void getRampParmFromDefault(PRM_Parm &ramp_parm,
89  const char *defaults_string);
90 
91  /// Get the basis, positions, value (as component sequence array), and
92  /// value tuple size that define the ramp parameter value.
93  static void getRampValuesFromParm(
94  UT_DoubleArray &values, int &tuple_size,
95  UT_DoubleArray &keys, UT_StringArray &basis,
96  const UT_Ramp &ramp, bool is_rgb);
97 
98  /// Construct the string that defines the ramp default value based
99  /// on provided basis, positions, and value arrays.
100  static void getRampDefaultString(UT_WorkBuffer &wbuf,
101  const UT_DoubleArray &values, int tuple_size,
102  const UT_DoubleArray *keys,
103  const UT_StringArray *basis);
104 };
105 
106 // ==========================================================================
107 // PRM_RampUtils::ValueData implementation.
108 // ==========================================================================
110  void *callee, fpreal t, PRM_Parm &p, int vector_index, int val,
111  bool set_key)
112  : myCallee(callee)
113  , myTime(t)
114  , myParm(p)
115  , myVectorIndex(vector_index)
116  , myValueType(PRM_RampUtils::PRM_INT_TYPE)
117  , myIntValue(val)
118  , myFloatValue(0.0)
119  , mySetKey(set_key)
120 {
121 }
122 
124  void *callee, fpreal t, PRM_Parm &p, int vector_index, fpreal val,
125  bool set_key)
126  : myCallee(callee)
127  , myTime(t)
128  , myParm(p)
129  , myVectorIndex(vector_index)
130  , myValueType(PRM_RampUtils::PRM_FLOAT_TYPE)
131  , myIntValue(0)
132  , myFloatValue(val)
133  , mySetKey(set_key)
134 {
135 }
136 
137 inline void *
138 PRM_RampUtils::ValueData::callee() const { return myCallee; }
139 
140 inline fpreal
141 PRM_RampUtils::ValueData::time() const { return myTime; }
142 
143 inline PRM_Parm &
144 PRM_RampUtils::ValueData::parm() const { return myParm; }
145 
146 inline int
147 PRM_RampUtils::ValueData::vectorIndex() const { return myVectorIndex; }
148 
150 PRM_RampUtils::ValueData::valueType() const { return myValueType; }
151 
152 inline int
153 PRM_RampUtils::ValueData::intValue() const { return myIntValue; }
154 
155 inline fpreal
156 PRM_RampUtils::ValueData::floatValue() const { return myFloatValue; }
157 
158 inline bool
159 PRM_RampUtils::ValueData::setKey() const { return mySetKey; }
160 
161 #endif
ValueData(void *callee, fpreal t, PRM_Parm &p, int vector_index, int val, bool set_key)
PRM_Parm & parm() const
PRM_ValueType valueType() const
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
An output stream object that owns its own string buffer storage.
fpreal floatValue() const
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1601
void * callee() const
double fpreal
Definition: SYS_Types.h:269
Utility class for containing a color ramp.
Definition: UT_Ramp.h:84
GLuint GLfloat * val
Definition: glcorearb.h:1607
Utility functions for working with ramp parameters.
Definition: PRM_RampUtils.h:19
#define PRM_API
Definition: PRM_API.h:10