HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DS_ParmReader.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: DS_ParmReader.h ( PRM Library, C++ )
7  *
8  * COMMENTS: Generic parameter reader for the generation of dialog scripts
9  * for script shaders
10  */
11 
12 #ifndef __DS_ParmReader__
13 #define __DS_ParmReader__
14 
15 #include "PRM_API.h"
16 #include <SYS/SYS_Types.h>
17 #include <UT/UT_ValArray.h>
18 #include <UT/UT_String.h>
19 #include "PRM_Type.h"
20 #include <CH/CH_ExprLanguage.h>
21 
22 class UT_StringArray;
23 
24 class PRM_Range;
25 
26 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27 
29 {
30 public:
31 
32  DS_DefaultValue( const fpreal32 *fp, int size );
33  DS_DefaultValue( const fpreal64 *fp, int size );
34  DS_DefaultValue( const int32 *ip, int size );
35  DS_DefaultValue( const int64 *ip, int size );
36  DS_DefaultValue( const char *sp[],
37  const CH_StringMeaning *meanings,
38  int size );
40  DS_DefaultValue(const UT_Fpreal64Array &values);
41  DS_DefaultValue(const UT_Int32Array &values);
42  DS_DefaultValue(const UT_Int64Array &values);
43  DS_DefaultValue(const UT_StringArray &values,
44  const CH_StringMeaning *meaning);
45 
46  ~DS_DefaultValue();
47 
48  int copy( const fpreal32 *fp, int size );
49  int copy( const fpreal64 *fp, int size );
50  int copy( const int32 *ip, int size );
51  int copy( const int64 *ip, int size );
52  int copy( const char *sp[],
53  const CH_StringMeaning *meanings,
54  int size);
55  int copy( const UT_Int32Array &v);
56  int copy( const UT_Int64Array &v);
57  int copy( const UT_Fpreal32Array &v);
58  int copy( const UT_Fpreal64Array &v);
59  int copy( const UT_StringArray &v,
60  const CH_StringMeaning *meanings);
61 
62  fpreal *getFloat() const { return myFloat; }
63  int *getInteger() const { return myInteger; }
64  const char *getString(int idx) const { return myStrings[idx]; }
66  { return myStringMeanings[idx]; }
67 
68  int getSize() const { return mySize; };
69 
70 private:
71  void initZero();
72  void cleanup();
73 
74  fpreal *myFloat;
75  int *myInteger;
76  char **myStrings;
77  CH_StringMeaning *myStringMeanings;
78 
79  int mySize;
80 };
81 
82 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 
85 public:
86  DS_MenuChoice( const char *value, const char *label)
87  : myValue( 0 ),
88  myLabel( 0 )
89  {
90  if ( value ) myValue = ::strdup( value );
91  if ( label ) myLabel = ::strdup( label );
92  };
94  {
95  if ( myValue ) ::free( myValue );
96  if ( myLabel ) ::free( myLabel );
97  };
98 
99  const char *getValue() const { return myValue; }
100  const char *getLabel() const { return myLabel; }
101 
102 private:
103  char *myValue;
104  char *myLabel;
105 };
106 
108 public:
109  DS_AttributeValue(const char *token, const char *value)
110  : myToken(0), myValue(0)
111  {
112  if (token) myToken = ::strdup(token);
113  if (value) myValue = ::strdup(value);
114  }
116  {
117  if (myToken) ::free(myToken);
118  if (myValue) ::free(myValue);
119  }
120 
121  const char *getToken() const { return myToken; }
122  const char *getValue() const { return myValue; }
123 
124 private:
125  char *myToken;
126  char *myValue;
127 };
128 
130 public:
131  DS_HandleBinding(const char *channelname, const char *type,
132  const char *desc, const char *label,
133  const char *default_settings)
134  : myChannelName(0), myType(0), myDesc(0), myLabel(0)
135  {
136  if (channelname) myChannelName = ::strdup(channelname);
137  if (type) myType = ::strdup(type);
138  if (desc) myDesc = ::strdup(desc);
139  if (label) myLabel = ::strdup(label);
140  if (default_settings)
141  myDefaultSettings = ::strdup(default_settings);
142  }
144  {
145  if (myChannelName) ::free(myChannelName);
146  if (myType) ::free(myType);
147  if (myDesc) ::free(myDesc);
148  if (myLabel) ::free(myLabel);
149  if (myDefaultSettings) ::free(myDefaultSettings);
150  }
151 
152  const char *getChannelName() const { return myChannelName; }
153  const char *getType() const { return myType; }
154  const char *getDesc() const { return myDesc; }
155  const char *getLabel() const { return myLabel; }
156  const char *getDefaultSettings() const { return myDefaultSettings; }
157 
158 private:
159  char *myChannelName, *myType, *myDesc, *myLabel, *myDefaultSettings;
160 };
161 
163 public:
164  DS_SelectorBinding(const char *parm_name,
165  const char *type, const char *prompt, const char *desc,
166  const char *mask, int dragging,
167  const char *menu, int asterisk,
168  int input_index=-1, int input_required=0)
169  : myParmName(0), myType(0), myDesc(0), myPrompt(0), myMask(0), myMenu(0)
170  {
171  myDragging = dragging;
172  myAsterisk = asterisk;
173  myInputIndex = input_index;
174  myInputRequired = input_required;
175  if (parm_name) myParmName = ::strdup(parm_name);
176  if (type) myType = ::strdup(type);
177  if (prompt) myPrompt = ::strdup(prompt);
178  if (desc) myDesc = ::strdup(desc);
179  if (mask) myMask = ::strdup(mask);
180  if (menu) myMenu = ::strdup(menu);
181  }
183  {
184  if (myParmName) ::free(myParmName);
185  if (myType) ::free(myType);
186  if (myPrompt) ::free(myPrompt);
187  if (myDesc) ::free(myDesc);
188  if (myMenu) ::free(myMenu);
189  if (myMask) ::free(myMask);
190  }
191 
192  const char *getParmName() const { return myParmName; }
193  const char *getType() const { return myType; }
194  const char *getPrompt() const { return myPrompt; }
195  const char *getDesc() const { return myDesc; }
196  const char *getPrimMask() const { return myMask; }
197  int getDragging() const { return myDragging; }
198  const char *getMenu() const { return myMenu; }
199  int getAsterisk() const { return myAsterisk; }
200  int getInputIndex() const { return myInputIndex; }
201  int getInputRequired() const { return myInputRequired; }
202 
203 private:
204  char *myParmName, *myType, *myPrompt, *myDesc, *myMask, *myMenu;
205  int myDragging, myAsterisk;
206  int myInputIndex, myInputRequired;
207 };
208 
210 {
211 public:
213  ~DS_DisableInfo();
214 
215  void addInfo(const char *parm, const char *value)
216  { myControlParm.append( ::strdup(parm) );
217  myControlValue.append( ::strdup(value) ); }
218 
221 };
222 
228 
229 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
230 
232 {
233 public:
234  DS_ParmInfo( const char *token );
235  ~DS_ParmInfo();
236 
237  void addHelpText(const char *text);
238 
239  UT_String myToken; // Actual parm name
247  unsigned myFlag;
249 
258 
259  unsigned int mySize; // Vector size (1, 3, 4, 9, 16, etc.)
262 
264  UT_String myDisableWhen; // New style (with {})
265  UT_String myHideWhen; // New style (with {})
266 
267  bool setTypeByToken( const char *token );
268  const char *getTypeToken() const;
269 
270  void setInvisible();
271  bool isInvisible() const;
272 
273  void setLogarithmic(bool flag);
274  bool isLogarithmic() const;
275 
276  // Arrays get translated into multi-parms
277  bool getIsArray() const { return myIsArray; }
278  void setIsArray(bool f) { myIsArray = f; }
279 
280  void setFlag( unsigned flag ) { myFlag |= flag; }
281  void clearFlag( unsigned flag = (unsigned)-1 ){ myFlag &= ~flag; }
282  unsigned getFlag( unsigned flag ) const { return myFlag & flag; }
283 private:
284  bool myIsArray; // Represented as a multi-parm
285 };
286 
288 
289 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
290 
292 {
293 public:
294 
295  // the constructor expects the parms "d:g:cl"
296  DS_ParmReader( unsigned doGroups = 0,
297  unsigned color = 0,
298  unsigned lightChan = 1 );
299  virtual ~DS_ParmReader();
300 
301  virtual const char *getClassName() const;
302 
303  // File IO
304  // all return 0 to indicate error
305  virtual int open( const char *fileName ) = 0;
306  virtual void close() = 0;
307 
308  // parse will read the given script file, and extract information on
309  // the parameters that are present in the script.
310  // parse will return the number of parameters it has successfully found.
311  // returns 0 to indicate error
312  virtual int parse() = 0;
313 
314  // The following must be filled out by derived classes.
315  // NAME and LABEL provide the name(s) for the scripted function.
316  // HELP is the help messages that were included in the script to be
317  // displayed in the UI to aid the user
318  virtual const char *getScriptTypeName() = 0;
319  virtual const char *getScriptName() = 0;
320  virtual const char *getScriptLabel() = 0;
321  virtual const char *getScriptHelp() = 0;
322  virtual const char *getScriptInfo() = 0;
323  virtual const char *getInputLabel(int /*idx*/) { return ""; }
324  virtual int getNumInputLabels() const { return 0; }
325  virtual const char *getRenderMask() { return ""; }
326 
327  // returns the number of parms the reader found from the script
328  int numParms() { return myParms.entries(); }
329 
330  // given an index, return the information on the index'th parm
331  // return 0 to indicate error
332  virtual DS_ParmInfo *getParmInfo( const int index );
333 
334  // let others know if we care about grouping of params
335  int isDoingGroups() const { return myDoGroups; }
336  void setGroupSize(int g) { myGroupSize = g; }
337  int getGroupSize() const { return myGroupSize; }
338  UT_StringList &getGroups() { return myGroups; }
339  DS_SelectorList &getUnboundSelectors() { return myUnboundSelectors; }
340  DS_SelectorList &getReservedSelectors() { return myReservedSelectors; }
341  DS_HandleList &getReservedHandles() { return myReservedHandles; }
342  DS_HandleList &getBoundHandles() { return myBoundHandles; }
343 
344 protected:
345  DS_ParmInfoList myParms;
351 
352  short myDoGroups;
353  short myGroupSize;
354  short myColorFlag;
355  short myLightChan;
356 };
357 
358 #endif
359 
DS_SelectorList myReservedSelectors
DS_HandleList myBoundHandles
DS_HandleList myHandles
DS_DefaultValue * myDefault
void setFlag(unsigned flag)
virtual const char * getRenderMask()
fpreal * getFloat() const
Definition: DS_ParmReader.h:62
const char * getPrimMask() const
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
DS_SelectorBinding * mySelector
void clearFlag(unsigned flag=(unsigned)-1)
DS_HandleList & getBoundHandles()
const char * getValue() const
UT_String myRenderManType
CH_StringMeaning
int getInputRequired() const
const GLdouble * v
Definition: glcorearb.h:836
const char * getDesc() const
DS_AttributeValue(const char *token, const char *value)
GLuint color
Definition: glcorearb.h:1260
const char * getMenu() const
const char * getPrompt() const
GLboolean GLboolean g
Definition: glcorearb.h:1221
GLint GLuint mask
Definition: glcorearb.h:123
UT_String myLabel
DS_SelectorList myUnboundSelectors
DS_SelectorBinding(const char *parm_name, const char *type, const char *prompt, const char *desc, const char *mask, int dragging, const char *menu, int asterisk, int input_index=-1, int input_required=0)
unsigned int mySize
const char * getValue() const
Definition: DS_ParmReader.h:99
DS_SelectorList & getUnboundSelectors()
UT_String myGroup
const char * getParmName() const
UT_ValArray< DS_SelectorBinding * > DS_SelectorList
UT_String myMenuScript
PRM_MultiType myMultiType
GLsizeiptr size
Definition: glcorearb.h:663
int getDragging() const
DS_HandleBinding(const char *channelname, const char *type, const char *desc, const char *label, const char *default_settings)
UT_ValArray< DS_MenuChoice * > DS_Menu
long long int64
Definition: SYS_Types.h:106
virtual int getNumInputLabels() const
png_FILE_p fp
Definition: png.h:2028
GLfloat f
Definition: glcorearb.h:1925
DS_AttributeList myAttributes
UT_StringList myGroups
UT_StringList & getGroups()
void setGroupSize(int g)
PRM_Type myType
UT_String myToken
const char * getDesc() const
CH_ScriptLanguage myMenuScriptLanguage
double fpreal64
Definition: SYS_Types.h:191
const char * getLabel() const
UT_ValArray< DS_AttributeValue * > DS_AttributeList
DS_SelectorList & getReservedSelectors()
int getAsterisk() const
const char * getType() const
DS_HandleList & getReservedHandles()
unsigned getFlag(unsigned flag) const
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1601
UT_ValArray< DS_DisableInfo * > DS_DisableList
UT_String myOpFilter
void setIsArray(bool f)
int int32
Definition: SYS_Types.h:34
virtual int open(float queuesize)
DS_DisableList myDisableInfo
UT_String myCallback
int isDoingGroups() const
DS_Menu myMenu
UT_ValArray< DS_HandleBinding * > DS_HandleList
const char * getDefaultSettings() const
virtual const char * getInputLabel(int)
unsigned myFlag
bool getIsArray() const
UT_Array< char * > myControlParm
GLsizei const GLfloat * value
Definition: glcorearb.h:823
DS_MenuChoice(const char *value, const char *label)
Definition: DS_ParmReader.h:86
double fpreal
Definition: SYS_Types.h:269
const char * getChannelName() const
int getSize() const
Definition: DS_ParmReader.h:68
DS_ParmInfoList myParms
PRM_Range * myRange
CH_StringMeaning getStringMeaning(int idx) const
Definition: DS_ParmReader.h:65
DS_HandleList myReservedHandles
UT_Array< char * > myControlValue
virtual void close()
GLuint index
Definition: glcorearb.h:785
void addInfo(const char *parm, const char *value)
UT_String myHelpText
const char * getString(int idx) const
Definition: DS_ParmReader.h:64
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
const char * getToken() const
const char * getLabel() const
png_infop png_uint_32 flag
Definition: png.h:2242
const char * getType() const
#define PRM_API
Definition: PRM_API.h:10
UT_ValArray< DS_ParmInfo * > DS_ParmInfoList
UT_String myDisableWhen
int getInputIndex() const
float fpreal32
Definition: SYS_Types.h:190
int * getInteger() const
Definition: DS_ParmReader.h:63
UT_String myHideWhen
PRM_MultiType
This type enum defines the different types of multi (dynamic) parameters.
Definition: PRM_Type.h:417
CH_ScriptLanguage
int getGroupSize() const