HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_ScriptParm.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_Parm.h ( PRM Library, C++)
7  *
8  * COMMENTS: Scripted version of a parameter. This class is typically
9  * created by reading a script. It contains all the relevant
10  * information to create a PRM_Template.
11  */
12 
13 #ifndef __PRM_ScriptParm__
14 #define __PRM_ScriptParm__
15 
16 #include "PRM_API.h"
17 #include "PRM_Conditional.h"
18 #include "PRM_Default.h"
19 #include "PRM_Template.h"
20 #include <UT/UT_Array.h>
21 #include <UT/UT_NonCopyable.h>
22 #include <UT/UT_StringArray.h>
23 
24 class DS_Stream;
25 class PRM_SpareData;
26 class PRM_ScriptPage;
27 class PRM_ScriptParm;
28 class PRM_Default;
29 class PRM_Range;
30 class PRM_ChoiceList;
31 class PRM_ScriptImports;
32 
34 {
35 public:
37  bool asmultiparm = false);
38  virtual ~PRM_ScriptGroup();
39 
41 
42  void addPage(PRM_ScriptPage *page)
43  { myPages.append(page); }
44 
45  int getPageCount() const
46  { return myPages.entries(); }
48  { return myPages(idx); }
49 
51  {
52  if (!mySizes) buildSizes();
53  return mySizes;
54  }
55 
56  bool isMultiParm() const
57  { return myMultiParmFlag; }
58 
60  { return myMultiType; }
61  void setMultiType(PRM_MultiType multitype)
62  { myMultiType = multitype; }
63 
64  int computeTemplateSize();
65 
66  void fillTemplate(PRM_Template *array, int &idx,
67  PRM_ScriptImports *&imports,
68  int nest_level);
69 
71  {
72  if (!myGroupConditional)
73  buildConditionals();
74  return myGroupConditional;
75  }
76 
77 protected:
78  // This will build the defaults by counting the number of parameters in
79  // each page and allocating a correct default.
80  void buildSizes();
81  void buildConditionals();
82 
89 };
90 
92 {
93 public:
95  virtual ~PRM_ScriptParm();
96 
98 
99  enum
100  {
101  PRM_SPARM_REQUIRED = 0x001,// Parm is required (not an option)
102  PRM_SPARM_DIRECTION = 0x002,// Represents a direction jack
103  PRM_SPARM_COLOR = 0x004,// Represents a color
104  PRM_SPARM_OBJECT = 0x008,// Object parameter (needs menu)
105  PRM_SPARM_RENDERER = 0x010,// Renderer parameter (needs menu)
106  PRM_SPARM_ANIMSTRING = 0x020,// Int/Flt parm has a string default
107  PRM_SPARM_OBJECTLIST = 0x040,// Object list
108  PRM_SPARM_EMBED = 0x080,// Embedded parmlist
109  PRM_SPARM_LOGARITHMIC = 0x100,// Logarithmic slider
110  PRM_SPARM_OBSOLETE = 0x200,// Obsolete parameter
111  PRM_SPARM_EXPERIMENTAL = 0x400,// Experimental parameter
112  PRM_SPARM_ALLFLAGS = 0x7FF // All flags
113  };
114 
115  int parse(DS_Stream &is, int multiparm_depth);
116  int parseGroup(DS_Stream &is,
117  PRM_ScriptPage *page,
118  const char *grouptype,
119  int multiparm_depth);
120  bool parseMultiParm(DS_Stream &is,
121  PRM_MultiType multitype,
122  PRM_ScriptPage *page,
123  int multiparm_depth);
124  int parseGroupAttribute(DS_Stream &is);
125  int parseRange(DS_Stream &is);
126 
127  void appendScriptParms(
129 
130  void setFlag(unsigned flag) { myFlag |= flag; }
131  void clearFlag(unsigned flag) { myFlag &= ~flag; }
132  unsigned getFlag(unsigned bit) const { return myFlag & bit;}
133 
134  PRM_ScriptGroup *getGroup() const { return myGroup; }
135  PRM_Name &getName() { return myName; }
136  const PRM_Name &getName() const { return myName; }
137  const PRM_Type &getType() const { return myType; }
138  PRM_TypeExtended getTypeExtended() const{ return myTypeExtended; }
139  PRM_MultiType getMultiType() const { return myMultiType; }
140  const PRM_Default *getDefaults() const
141  { return myDefaults.entries() ? &myDefaults(0)
142  : (const PRM_Default*)NULL; }
144  { return myDefaults.entries() ? &myDefaults(0)
145  : (PRM_Default*)NULL; }
146  PRM_Range *getRange() const { return myRange; }
147  int getSize() const { return myVectorSize; }
148  PRM_ChoiceList *getMenu() const { return myMenu; }
149  const UT_String &getOption() const { return myOption; }
150  const UT_String &getHelpText() const { return myHelpText; }
151  PRM_ConditionalGroup&getConditionalGroup() { return myConditionalGroup; }
152  PRM_Template *getMultiTemplate();
153  bool getBaseParm() const { return myBaseParm; }
154 
155  PRM_SpareData *getSpareData(bool create=false);
156 
157  bool hasObsoleteGroup() const { return myObsoleteGroup!=0; }
158  PRM_ScriptParm *createObsoleteGroupParm();
159 
160  /// Clear any type or extended type settings related to joining. Returns
161  /// true if any settings were changed.
162  bool clearJoinNext();
163 
164  /// Some parameter dialogs require options for every parameter.
165  void enforceOptions();
166 
167  /// Inserts double backslashes to protect verbatim strings in script files.
168  /// If `wrap_in_quotes` is set to true, then protectString() and
169  /// protectStrcat() will wrap the string in double quotes when necessary
170  /// (i.e. string contains whitespace or a double quote).
171  static const char *protectString(
172  const char *s, int handlenull=0);
173  static const char *protectString(
174  const char *s, int handlenull,
175  bool wrap_in_quotes);
176  static void protectStrcat(
177  UT_WorkBuffer &dest, const char *s,
178  int handlenull=0);
179  static void protectStrcat(
180  UT_WorkBuffer &dest, const char *s,
181  int handlenull, bool wrap_in_quotes);
182 
183  int computeTemplateSize();
184  void fillTemplate(PRM_Template *array, int &idx,
185  PRM_ScriptImports *&imports,
186  int nest_level);
187 
188  static bool parseConditional(DS_Stream &is,
189  PRM_Conditional &cond);
190 
191  static void registerDefaultScriptCallback(PRM_Callback cb);
192 protected:
193  virtual PRM_ScriptGroup *newGroup(bool asmultiparm = false);
194  virtual PRM_ScriptPage *newPage();
195 
196  virtual int handleUnknown(DS_Stream &is, UT_String &token);
197 
198  // By default returns whatever was registered as the
199  // default callback.
200  virtual PRM_Callback getScriptParmCallback() const;
201  virtual bool wantsParametersAnimatable() const;
202  int buildMultiParmTemplate(
203  PRM_ScriptImports *&imports,
204  int nest_level);
205 
206  int parseMenu(DS_Stream &is);
207  int parseAttribute(DS_Stream &is);
208  int parseDefaults(DS_Stream &is, int isstring);
209  void clearMenu();
210  void clearDefaults();
211 
212  static bool parseConditionalInfo(DS_Stream &is,
213  PRM_Conditional &cond);
214 
231  unsigned myFlag;
235 
236  // This option string is used for command building (DS_Command).
238 
239  static const char *theTokens[];
240  static int theNumParms[];
241 };
242 
243 #endif
244 
PRM_Range * myRange
const UT_String & getOption() const
unsigned getFlag(unsigned bit) const
void
Definition: png.h:1083
PRM_ScriptPage * getPage(int idx)
int getSize() const
void clearFlag(unsigned flag)
PRM_Name & getName()
GLdouble s
Definition: glad.h:3009
bool hasObsoleteGroup() const
PRM_Default * getDefaults()
PRM_ChoiceList * myMenu
const PRM_Default * getDefaults() const
PRM_Template * myMultiTemplate
UT_String myHelpText
PRM_MultiType getMultiType() const
UT_Array< PRM_Default > myDefaults
const PRM_Type & getType() const
PRM_TypeExtended myTypeExtended
PRM_Range * getRange() const
PRM_MultiType myMultiType
void setMultiType(PRM_MultiType multitype)
void setFlag(unsigned flag)
PRM_ConditionalGroup & getConditionalGroup()
UT_ValArray< PRM_ScriptPage * > myPages
PRM_TypeExtended getTypeExtended() const
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
const UT_String & getHelpText() const
bool isMultiParm() const
PRM_ConditionalSwitcher * getGroupConditional()
PRM_MultiType getMultiType() const
PRM_MultiType myMultiType
PRM_Default * getDefaults()
PRM_ConditionalGroup myConditionalGroup
bool getBaseParm() const
PRM_Name * myMenuNames
PRM_ConditionalSwitcher * myGroupConditional
GA_API const UT_StringHolder parms
PRM_ScriptParm * myOwner
UT_String myOption
PRM_TypeExtended
Definition: PRM_Type.h:521
This class allow setting multiple conditionals for a PRM_Template.
PRM_ScriptGroup * myGroup
PRM_ChoiceList * getMenu() const
UT_StringArray myDefaultStrings
const PRM_Name & getName() const
PRM_ScriptGroup * myObsoleteGroup
#define PRM_API
Definition: PRM_API.h:10
int getPageCount() const
PRM_SpareData * mySpareData
PRM_Default * mySizes
PRM_MultiType
This type enum defines the different types of multi (dynamic) parameters.
Definition: PRM_Type.h:426
PRM_ScriptGroup * getGroup() const