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 myUseItems
100  ? myChoiceItems : (PRM_Item*)0; }
101 
102  void getChoiceNames(const PRM_Name *&thechoicenames,
103  void *thedata = 0,
104  const PRM_SpareData *theSparePtr = 0,
105  const PRM_Parm *theParm = 0) const;
106 
107  void getChoiceItems(const PRM_Item *&thechoiceitems,
108  void *thedata = 0,
109  const PRM_SpareData *theSparePtr = 0,
110  const PRM_Parm *theParm = 0) const;
111 
112  bool tokenFromIndex(
113  UT_String &result,
114  exint index,
115  void *data = nullptr,
116  const PRM_SpareData *spare = nullptr,
117  const PRM_Parm *parm = nullptr) const;
118 
119  const UT_String &getScript() const;
120  CH_ScriptLanguage getScriptLanguage() const;
121  bool isDynamic() const;
122 
124  { return myType; }
126  { return myChoiceGenerator; }
127  int getSize(const PRM_Parm *parm) const
128  {
129  // myStaticChoiceSize is used for static number of
130  // items, regardless of myUseItems.
131  if (myChoiceNames)
132  return myStaticChoiceSize;
133  else
134  return getSizeSlow(parm);
135  }
136 
137  /// NOTE: Based on the lack of destructor, PRM_ChoiceList does NOT
138  /// own *myChoiceNames or *myChoiceItems, but ownership semantics
139  /// are bonkers in these mysterious lands of PRM.
140  int64 getMemoryUsage(bool inclusive) const
141  {
142  return (inclusive ? sizeof(*this) : 0)
143  + myScript.getMemoryUsage(false);
144  }
145 
146 private:
147  void getChoiceNamesFromScript(
148  UT_Array<PRM_Name> &names,
149  const PRM_Parm *parm) const;
150  void getChoiceNamesFromHscriptScript(
151  UT_Array<PRM_Name> &names,
152  const PRM_Parm &parm) const;
153  void getChoiceNamesFromPythonScript(
154  UT_Array<PRM_Name> &names,
155  const PRM_Parm &parm) const;
156  int getSizeSlow(const PRM_Parm *parm) const;
157 
158  PRM_ChoiceListType myType;
159 
160  bool myUseItems; // names or items
161 
162  int myStaticChoiceSize;
163 
164  union
165  {
168  };
169 
170  union
171  {
174  };
175 
176  UT_String myScript;
177  CH_ScriptLanguage myScriptLanguage;
178 };
179 
180 #endif
181 
PRM_ChoiceItemGenFunc myChoiceItemGenerator
PRM_Name * choiceNamesPtr()
PRM_Item * myChoiceItems
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
PRM_ChoiceListType
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
long long int64
Definition: SYS_Types.h:107
int64 exint
Definition: SYS_Types.h:116
PRM_Item * choiceItemsPtr()
GLboolean * data
Definition: glcorearb.h:130
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:785
int getSize(const PRM_Parm *parm) const
#define PRM_API
Definition: PRM_API.h:10
bool usesItems() const
CH_ScriptLanguage