HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_ChoiceList.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_ChoiceList.h (Parameter Library)
7  *
8  * COMMENTS:
9  * Used to supply choices of values for parameters.
10  * In a UI environment, these will be used to create menus.
11  * You can use a PRM_Item list instead of a PRM_Name list if
12  * you want to include icons in the menu.
13  *
14  * It is important to be careful when using integer string tokens
15  * in ordinal menus. Strings that fail to match any token will be
16  * processed as a string representation of an integer, which could
17  * result in unexpected behaviour when attempting to load hip files
18  * saved with obsolete menu tokens. However, when the menu has a
19  * PRM_CHOICELIST_USE_TOKEN flag, it uses menu item token values, and
20  * it will always be processed as a string representation rather than
21  * an item index, thus making the behaviour uniform and expected.
22  */
23 
24 #ifndef __PRM_ChoiceList__
25 #define __PRM_ChoiceList__
26 
27 #include "PRM_API.h"
28 #include <UT/UT_String.h>
29 #include <CH/CH_ExprLanguage.h>
30 #include "PRM_ParmOwner.h"
31 
32 class PRM_Name;
33 class PRM_Item;
34 class PRM_Parm;
35 class PRM_ParmOwner;
36 class PRM_SpareData;
37 
39 {
40  PRM_CHOICELIST_REPLACE = 0x0001, // replaces value
41  PRM_CHOICELIST_TOGGLE = 0x0002, // basically a bitfield (for
42  // strings and ordinals only)
43  PRM_CHOICELIST_APPEND = 0x0004, // appends to string
44  PRM_CHOICELIST_WILD = 0x0008, // handles * intelligently
45  PRM_CHOICELIST_USE_TOKEN = 0x0010, // token (not index) is value
46 
47  PRM_CHOICELIST_EXCLUSIVE = 0x1000, // user can only use choices
48 
49  // define some commonly used types
52 };
53 
54 
55 /// This is a callback function that is used to generate dynamic items for
56 /// PRM_ChoiceList.
57 ///
58 /// @param thedata Pointer to the node it was called on
59 /// @param thechoicenames[out] Array of PRM_Name objects to be filled
60 /// @param thelistsize Number of items in @c thechoicenames
61 /// @param thespareptr PRM_SpareData object for the parameter this
62 /// was invoked from.
63 /// @param theparm PRM_Parm object that this was invoked from
64 typedef void (* PRM_ChoiceGenFunc)(
65  void *thedata,
66  PRM_Name *thechoicenames,
67  int thelistsize,
68  const PRM_SpareData *thespareptr,
69  const PRM_Parm *theparm);
71  void *thedata,
72  PRM_Item *thechoiceitems,
73  int thelistsize,
74  const PRM_SpareData *thespareptr,
75  const PRM_Parm *theparm);
76 
78 {
79 public:
80  // Names
81  PRM_ChoiceList(PRM_ChoiceListType thetype, PRM_Name *thechoicenames);
83 
84  // Items
85  PRM_ChoiceList(PRM_ChoiceListType thetype, PRM_Item *thechoiceitem);
87 
88  // Script interface.
89  PRM_ChoiceList(PRM_ChoiceListType thetype, const char *thescript,
90  CH_ScriptLanguage language = CH_HSCRIPT);
91 
92 
93  bool usesItems() const { return myUseItems; }
94 
96  { return myUseItems
97  ? (PRM_Name*)0 : myChoiceNames; }
99  { return const_cast<PRM_Item*>(
100  static_cast<PRM_ChoiceList const*>(
101  this)->choiceItemsPtr()); }
102 
103  PRM_Item const *choiceItemsPtr() const
104  { return myUseItems
105  ? myChoiceItems : (PRM_Item*)0; }
106 
107  void getChoiceNames(const PRM_Name *&thechoicenames,
108  void *thedata = 0,
109  const PRM_SpareData *theSparePtr = 0,
110  const PRM_Parm *theParm = 0,
111  bool block_errors = false) const;
112 
113  void getChoiceItems(const PRM_Item *&thechoiceitems,
114  void *thedata = 0,
115  const PRM_SpareData *theSparePtr = 0,
116  const PRM_Parm *theParm = 0,
117  bool block_errors = false) const;
118 
119  bool tokenFromIndex(
120  UT_String &result,
121  exint index,
122  void *data = nullptr,
123  const PRM_SpareData *spare = nullptr,
124  const PRM_Parm *parm = nullptr) const;
125 
126  const UT_String &getScript() const;
127  CH_ScriptLanguage getScriptLanguage() const;
128  bool isDynamic() const;
129 
131  { return myType; }
133  { return myChoiceGenerator; }
134  int getSize(const PRM_Parm *parm) const
135  {
136  // myStaticChoiceSize is used for static number of
137  // items, regardless of myUseItems.
138  if (myChoiceNames)
139  return myStaticChoiceSize;
140  else
141  return getSizeSlow(parm);
142  }
143 
144  /// NOTE: Based on the lack of destructor, PRM_ChoiceList does NOT
145  /// own *myChoiceNames or *myChoiceItems, but ownership semantics
146  /// are bonkers in these mysterious lands of PRM.
147  int64 getMemoryUsage(bool inclusive) const
148  {
149  return (inclusive ? sizeof(*this) : 0)
150  + myScript.getMemoryUsage(false);
151  }
152 
153  /// Recompute myStaticChoiceSize from myChoiceNames or myChoiceItems
154  void updateStaticChoiceSize();
155 
156 private:
157  void getChoiceNamesFromScript(
158  UT_Array<PRM_Name> &names,
159  const PRM_Parm *parm,
160  bool block_errors) const;
161  void getChoiceNamesFromHscriptScript(
162  UT_Array<PRM_Name> &names,
163  const PRM_Parm &parm) const;
164  void getChoiceNamesFromPythonScript(
165  UT_Array<PRM_Name> &names,
166  const PRM_Parm &parm) const;
167  int getSizeSlow(const PRM_Parm *parm) const;
168 
169  PRM_ChoiceListType myType;
170 
171  bool myUseItems; // names or items
172 
173  int myStaticChoiceSize;
174 
175  union
176  {
179  };
180 
181  union
182  {
185  };
186 
187  UT_String myScript;
188  CH_ScriptLanguage myScriptLanguage;
189 };
190 
191 #endif
192 
PRM_ChoiceItemGenFunc myChoiceItemGenerator
PRM_Name * choiceNamesPtr()
PRM_Item * myChoiceItems
void
Definition: png.h:1083
int64 exint
Definition: SYS_Types.h:125
PRM_Item const * choiceItemsPtr() const
PRM_ChoiceListType
**But if you need a result
Definition: thread.h:613
PRM_ChoiceGenFunc getChoiceGenerator() const
void(* PRM_ChoiceGenFunc)(void *thedata, PRM_Name *thechoicenames, int thelistsize, const PRM_SpareData *thespareptr, const PRM_Parm *theparm)
int64 getMemoryUsage(bool inclusive) const
PRM_ChoiceListType getType() const
PRM_Name * myChoiceNames
PRM_Item * choiceItemsPtr()
long long int64
Definition: SYS_Types.h:116
void(* PRM_ChoiceItemGenFunc)(void *thedata, PRM_Item *thechoiceitems, int thelistsize, const PRM_SpareData *thespareptr, const PRM_Parm *theparm)
PRM_ChoiceGenFunc myChoiceGenerator
GLuint index
Definition: glcorearb.h:786
int getSize(const PRM_Parm *parm) const
#define PRM_API
Definition: PRM_API.h:10
bool usesItems() const
Definition: format.h:895
CH_ScriptLanguage