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_Template.h"
18 #include "PRM_Default.h"
19 #include "PRM_Conditional.h"
20 #include <UT/UT_Array.h>
21 #include <UT/UT_StringArray.h>
22 
23 class DS_Stream;
24 class PRM_SpareData;
25 class PRM_ScriptPage;
26 class PRM_ScriptParm;
27 class PRM_Default;
28 class PRM_Range;
29 class PRM_ChoiceList;
30 class PRM_ScriptImports;
31 
33 public:
35  bool asmultiparm = false);
36  virtual ~PRM_ScriptGroup();
37 
38  void addPage(PRM_ScriptPage *page)
39  { myPages.append(page); }
40 
41  int getPageCount() const
42  { return myPages.entries(); }
44  { return myPages(idx); }
45 
47  {
48  if (!mySizes) buildSizes();
49  return mySizes;
50  }
51 
52  bool isMultiParm() const
53  { return myMultiParmFlag; }
54 
56  { return myMultiType; }
57  void setMultiType(PRM_MultiType multitype)
58  { myMultiType = multitype; }
59 
60  int computeTemplateSize();
61 
62  void fillTemplate(PRM_Template *array, int &idx,
63  PRM_ScriptImports *&imports,
64  int nest_level);
65 
67  {
68  if (!myGroupConditional)
69  buildConditionals();
70  return myGroupConditional;
71  }
72 
73 protected:
74  // This will build the defaults by counting the number of parameters in
75  // each page and allocating a correct default.
76  void buildSizes();
77  void buildConditionals();
78 
85 };
86 
88 public:
90  virtual ~PRM_ScriptParm();
91 
92  enum {
93  PRM_SPARM_REQUIRED = 0x001,// Parm is required (not an option)
94  PRM_SPARM_DIRECTION = 0x002,// Represents a direction jack
95  PRM_SPARM_COLOR = 0x004,// Represents a color
96  PRM_SPARM_OBJECT = 0x008,// Object parameter (needs menu)
97  PRM_SPARM_RENDERER = 0x010,// Renderer parameter (needs menu)
98  PRM_SPARM_ANIMSTRING = 0x020,// Int/Flt parm has a string default
99  PRM_SPARM_OBJECTLIST = 0x040,// Object list
100  PRM_SPARM_EMBED = 0x080,// Embedded parmlist
101  PRM_SPARM_LOGARITHMIC = 0x100,// Logarithmic slider
102  PRM_SPARM_OBSOLETE = 0x200,// Obsolete parameter
103  PRM_SPARM_EXPERIMENTAL = 0x400,// Experimental parameter
104  PRM_SPARM_ALLFLAGS = 0x7FF // All flags
105  };
106 
107  int parse(DS_Stream &is, int multiparm_depth);
108  int parseGroup(DS_Stream &is,
109  PRM_ScriptPage *page,
110  const char *grouptype,
111  int multiparm_depth);
112  bool parseMultiParm(DS_Stream &is,
113  PRM_MultiType multitype,
114  PRM_ScriptPage *page,
115  int multiparm_depth);
116  int parseGroupAttribute(DS_Stream &is);
117  int parseRange(DS_Stream &is);
118 
119  void appendScriptParms(
121 
122  void setFlag(unsigned flag) { myFlag |= flag; }
123  void clearFlag(unsigned flag) { myFlag &= ~flag; }
124  unsigned getFlag(unsigned bit) const { return myFlag & bit;}
125 
126  PRM_ScriptGroup *getGroup() const { return myGroup; }
127  PRM_Name &getName() { return myName; }
128  const PRM_Name &getName() const { return myName; }
129  const PRM_Type &getType() const { return myType; }
130  PRM_TypeExtended getTypeExtended() const{ return myTypeExtended; }
131  PRM_MultiType getMultiType() const { return myMultiType; }
132  const PRM_Default *getDefaults() const
133  { return myDefaults.entries() ? &myDefaults(0)
134  : (const PRM_Default*)NULL; }
136  { return myDefaults.entries() ? &myDefaults(0)
137  : (PRM_Default*)NULL; }
138  PRM_Range *getRange() const { return myRange; }
139  int getSize() const { return myVectorSize; }
140  PRM_ChoiceList *getMenu() const { return myMenu; }
141  const UT_String &getOption() const { return myOption; }
142  const UT_String &getHelpText() const { return myHelpText; }
143  PRM_ConditionalGroup&getConditionalGroup() { return myConditionalGroup; }
144  PRM_Template *getMultiTemplate();
145  bool getBaseParm() const { return myBaseParm; }
146 
147  PRM_SpareData *getSpareData(bool create=false);
148 
149  bool hasObsoleteGroup() const { return myObsoleteGroup!=0; }
150  PRM_ScriptParm *createObsoleteGroupParm();
151 
152  /// Clear any type or extended type settings related to joining. Returns
153  /// true if any settings were changed.
154  bool clearJoinNext();
155 
156  /// Some parameter dialogs require options for every parameter.
157  void enforceOptions();
158 
159  /// Inserts double backslashes to protect verbatim strings in script files.
160  /// If `wrap_in_quotes` is set to true, then protectString() and
161  /// protectStrcat() will wrap the string in double quotes when necessary
162  /// (i.e. string contains whitespace or a double quote).
163  static const char *protectString(
164  const char *s, int handlenull=0);
165  static const char *protectString(
166  const char *s, int handlenull,
167  bool wrap_in_quotes);
168  static void protectStrcat(
169  UT_WorkBuffer &dest, const char *s,
170  int handlenull=0);
171  static void protectStrcat(
172  UT_WorkBuffer &dest, const char *s,
173  int handlenull, bool wrap_in_quotes);
174 
175  int computeTemplateSize();
176  void fillTemplate(PRM_Template *array, int &idx,
177  PRM_ScriptImports *&imports,
178  int nest_level);
179 
180  static bool parseConditional(DS_Stream &is,
181  PRM_Conditional &cond);
182 
183  static void registerDefaultScriptCallback(PRM_Callback cb);
184 protected:
185  virtual PRM_ScriptGroup *newGroup(bool asmultiparm = false);
186  virtual PRM_ScriptPage *newPage();
187 
188  virtual int handleUnknown(DS_Stream &is, UT_String &token);
189 
190  // By default returns whatever was registered as the
191  // default callback.
192  virtual PRM_Callback getScriptParmCallback() const;
193  virtual bool wantsParametersAnimatable() const;
194  int buildMultiParmTemplate(
195  PRM_ScriptImports *&imports,
196  int nest_level);
197 
198  int parseMenu(DS_Stream &is);
199  int parseAttribute(DS_Stream &is);
200  int parseDefaults(DS_Stream &is, int isstring);
201  void clearMenu();
202  void clearDefaults();
203 
204  static bool parseConditionalInfo(DS_Stream &is,
205  PRM_Conditional &cond);
206 
223  unsigned myFlag;
227 
228  // This option string is used for command building (DS_Command).
230 
231  static const char *theTokens[];
232  static int theNumParms[];
233 };
234 
235 #endif
236 
PRM_Range * myRange
const UT_String & getOption() const
unsigned getFlag(unsigned bit) const
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
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
PRM_ScriptParm * myOwner
UT_String myOption
PRM_TypeExtended
Definition: PRM_Type.h:510
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
void addPage(PRM_ScriptPage *page)
#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:417
PRM_ScriptGroup * getGroup() const