HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BM_ParmState.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: BM_ParmState.h ( Direct manipulation library, C++)
7  *
8  * COMMENTS:
9  * The base class of a BM state/handle that supports parameters.
10  */
11 
12 #ifndef __BM_ParmState_H__
13 #define __BM_ParmState_H__
14 
15 #include "BM_API.h"
16 #include <UT/UT_String.h>
17 #include "BM_SimpleState.h"
18 #include <CH/CH_ExprLanguage.h>
19 
20 
21 class PRM_Template;
22 class PRM_ParmList;
23 class PRM_Parm;
24 class PRM_PresetInfo;
25 class PSI2_DialogPRM;
26 class PSI2_DialogPRMExported;
27 class BM_ParmStateUndo;
28 class UT_StringHolder;
29 
30 
32 {
33  // Rather than putting the undo code in this file, it's in a friend class.
34  // BM_ParmStateUndo needs access to parameter() method to save and
35  // load its value.
36  friend class BM_ParmStateUndo;
37 
38 public:
39  // Class constructor and destructor. 'name' is the name of the state.
40  BM_ParmState(BM_SceneManager &app, const char *cursor,
41  const char *vname = 0,
42  const char *english = 0,
43  const char *const *vnames = 0,
44  UI_EventMethod const *vmethods = 0);
45  ~BM_ParmState() override;
46 
47  // Query the name of the state:
48  const UT_String &name() const { return myName; }
49  const UT_String &english() const { return myEnglishName; }
50 
51  // The name of this class:
52  const char *className() const override;
53 
54  // In case you need to know what the dialog is:
55  virtual void prepareDialogForDisplay() const;
56  virtual int hasDialog () const;
57  virtual UI_Feel *dialogFeel() const;
58  int getToolboxCount() const override;
59  UI_Feel *getToolbox(int index) const override;
60 
61  // This gets the extra copy of the dialog feel. We need this as handle's
62  // dialogs are in two places, and our UI library can't mulitparent.
63  // Note that this is only non-null if isHandle is 1.
64  UI_Feel *extraDialogFeel() const;
65 
66  // Initialize the app, wire the interface, tie all the UI values, etc:
67  // This method should only be called by the BM_ResourceManager when the
68  // state is created.
69  virtual void initializeUI(PRM_Template *tmpl=0);
70 
71 
72  virtual bool getStateParmNames(UT_StringArray &ret, const char* prefix=nullptr );
73  virtual bool evalStateParm(const char *name, UT_StringHolder &ret);
74  virtual bool setStateParm(const char *name, const UT_StringHolder &val);
75  virtual bool pressStateButton(const char *name);
76 
77  // Refresh all the parms if the dialog exists
78  void refreshParms();
79 
80 protected:
81  // Returns a preset type name to be used when saving preset info and dialogs.
82  virtual const char *getPresetTypeName() const = 0;
83 
84  // Do the AP_Interface thing (called by initializeUI()):
85  void initApplication(
86  UI_Manager *,
87  int,
88  const char **) override;
89 
90  // Return various things needed for the interaction with the dialog:
91  const PRM_Parm *parameter(const char *name) const;
92  PRM_Parm *parameter(const char *name);
93  PRM_ParmList *parameters() const { return myParmList; }
94  UI_Value *parmValue() const { return myParmVal; }
95 
96  // Figure out the parameter given its name or index in the parm list:
97  const PRM_Parm *parameter(int index) const;
98  PRM_Parm *parameter(int index);
99 
100  // Get or set the values of various types of PRM parameters:
101  void setParm(const char *name, const UT_String &value,
102  CH_StringMeaning meaning,
103  fpreal t=0, int refresh=1);
104  void setParm(const char *name, int value, fpreal t=0,
105  int refresh=1);
106  void setParm(const char *name, fpreal value, fpreal t=0,
107  int refresh=1);
108  void setXYParm (const char *name,
109  fpreal x,fpreal y,
110  fpreal t=0, int refresh=1);
111  void setXYZParm(const char *name,
112  fpreal x, fpreal y, fpreal z,
113  fpreal t=0, int refresh=1);
114  void setParm(int index, const UT_String &v,
115  CH_StringMeaning meaning,
116  fpreal t=0, int refresh=1);
117  void setParm(int index, int value, fpreal t=0,
118  int refresh=1);
119  void setParm(int index, fpreal value, fpreal t=0,
120  int refresh=1);
121  void setXYParm (int index, fpreal x, fpreal y,fpreal t=0,
122  int refresh=1);
123  void setXYZParm(int index, fpreal x, fpreal y, fpreal z,
124  fpreal t=0, int refresh=1);
125 
126  bool parmExists( const char *name ) const;
127  bool parmExists( int index ) const;
128 
129  void getParm(const char *name, UT_String &value,
130  fpreal t=0) const;
131  void getParm(const char *name, UT_StringHolder &value,
132  fpreal t=0) const;
133  void getParm(const char *name, int &value,
134  fpreal t=0) const;
135  void getParm(const char *name, bool &value,
136  fpreal t=0) const
137  {
138  int v;
139  getParm(name, v, t);
140  value = (v != 0);
141  }
142  void getParm(const char *name, fpreal &value,
143  fpreal t=0) const;
144  void getXYParm (const char *name, fpreal &x, fpreal &y,
145  fpreal t=0) const;
146  void getXYParm (const char *name, int &x, int &y,
147  fpreal t=0) const;
148  void getXYZParm(const char *n,
149  fpreal &x, fpreal &y, fpreal &z,
150  fpreal t=0) const;
151  void getParm(int index, UT_String &value, fpreal t=0) const;
152  void getParm(int index, UT_StringHolder &value,
153  fpreal t=0) const;
154  void getParm(int index, int &value, fpreal t=0) const;
155  void getParm(int index, bool &value, fpreal t=0) const
156  {
157  int v;
158  getParm(index, v, t);
159  value = (v != 0);
160  }
161  void getParm(int index, fpreal &value, fpreal t=0) const;
162  void getXYParm (int index, fpreal &x, fpreal &y,
163  fpreal t=0) const;
164  void getXYParm (int index, int &x, int &y, fpreal t=0) const;
165  void getXYZParm(int index,
166  fpreal &x, fpreal &y, fpreal &z,
167  fpreal t=0) const;
168 
169  // Overwrite the defaults of the given parm:
170  void overwriteParmDefault (const char *name, fpreal t=0);
171  void overwriteXYParmDefault (const char *name, fpreal t=0);
172  void overwriteXYZParmDefault(const char *name, fpreal t=0);
173  void overwriteParmDefault (int index, fpreal t=0);
174  void overwriteXYParmDefault (int index, fpreal t=0);
175  void overwriteXYZParmDefault(int index, fpreal t=0);
176  void overwriteParmDefaults();
177 
178  // Enable or disable parameters: Return 0 if nothing has changed.
179  virtual int disableParms();
180  int enableParm(const char *name, int onoff, int refresh=1);
181  int enableParm(int index, int onoff, int refresh=1);
182 
183  // Show/hide parmeters. Returns true if changed.
184  bool setVisibleState(int pi, bool state, bool refresh=true);
185  bool setVisibleState(const char *pn, bool state,
186  bool refresh=true);
187 
188  // Refresh parm if the dialog exists
189  void refreshParm (int index);
190 
191  // callback that reacts to changes in dialog values (after
192  // the parameter has been changed)
193  int handleParameterEvent(UI_Event *event) override;
194 
195  // save the parameter data for undo/redo if the mySaveParmForUndoFlag
196  // is turned on or the force parameter is true. Returns true
197  // if parm was saved for undo, or false otherwise (e.g., if undo
198  // manager is not accepting for undo)
199  bool saveParmForUndo( int index, bool force = false );
200 
201  // this method is invoked before a parameter is changed by a dialog.
202  // This method was added, because the parameter could not be saved for
203  // undo, before the parameter was changed. This method is invoked
204  // before a parameter is changed by objects other than derived
205  // from BM_ParmState
206  virtual int handleSaveParmForUndo( int index );
207 
208  // is called after a parameter has changed the value due to
209  // the execution of an undo for that parameter
210  virtual int handleParameterUndo( int parm_index );
211 
212  // access and modify the flag that determines whether parameter
213  // gets saved for undo before it is modified
215  { return mySaveParmForUndoFlag; };
216  void setSaveParmForUndoFlag( int onoff)
217  { mySaveParmForUndoFlag = (onoff != 0); };
218 
219  PSI2_DialogPRM* getParmDialog();
220 
221 private:
222  // static method registered with the dialog and used by the dialog
223  // to save parameter for und before the parameter is modified.
224  // This method invokes virtual handleSaveParmForUndo(), so that
225  // the derived classes can decide whether to save the parameter
226  // for undo or not.
227  static void saveParmForUndoCallback( void * state,
228  int parm_index )
229  {
230  ((BM_ParmState *)state)->handleSaveParmForUndo(
231  parm_index );
232  }
233 
234  void handleParameterEventVoidRet(UI_Event *event)
235  { handleParameterEvent(event); }
236  void handleToolboxParameterEvent(UI_Event *event);
237  void parameterChanged(UI_Event *event);
238 
239  // data
240 
241  UT_String myName; // name
242  UT_String myEnglishName; // name in English
243 
244  PSI2_DialogPRMExported *myParmToolbox;
245  PRM_ParmList *myParmList; // the parms inside the dialog
246  UI_Value *myParmVal; // value to communicate with parms
247  UI_Value *myToolboxParmVal;
248  PSI2_DialogPRM *myParmDialog; // the dialog that holds the parms
249  PSI2_DialogPRM *myExtraParmDialog; // an extra copy of that dialog.
250  PRM_PresetInfo *myPresetInfo;
251 
252  unsigned myOwnParmsFlag:1, // own its parm list and dialog?
253  mySaveParmForUndoFlag:1; //should save parm for undo?
254 };
255 
256 #endif
int getSaveParmForUndoFlag()
Definition: BM_ParmState.h:214
CH_StringMeaning
const GLdouble * v
Definition: glcorearb.h:837
GLsizei const GLfloat * value
Definition: glcorearb.h:824
void setSaveParmForUndoFlag(int onoff)
Definition: BM_ParmState.h:216
virtual int handleParameterEvent(UI_Event *event)
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
void getParm(int index, bool &value, fpreal t=0) const
Definition: BM_ParmState.h:155
GLint y
Definition: glcorearb.h:103
const UT_String & name() const
Definition: BM_ParmState.h:48
struct _cl_event * event
Definition: glcorearb.h:2961
GLdouble n
Definition: glcorearb.h:2008
void getParm(const char *name, bool &value, fpreal t=0) const
Definition: BM_ParmState.h:135
const char * className() const override
UI_Value * parmValue() const
Definition: BM_ParmState.h:94
GLuint const GLchar * name
Definition: glcorearb.h:786
void initializeUI()
GLint GLenum GLint x
Definition: glcorearb.h:409
#define BM_API
Definition: BM_API.h:10
GLdouble t
Definition: glad.h:2397
virtual UI_Feel * getToolbox(int index) const
SIM_API const UT_StringHolder force
__hostdev__ constexpr T pi()
Pi constant taken from Boost to match old behaviour.
Definition: NanoVDB.h:976
const UT_String & english() const
Definition: BM_ParmState.h:49
fpreal64 fpreal
Definition: SYS_Types.h:283
void initApplication(UI_Manager *, int, const char **) override
GLuint index
Definition: glcorearb.h:786
GLuint GLfloat * val
Definition: glcorearb.h:1608
void(UI_Object::* UI_EventMethod)(UI_Event *)
Definition: UI_Object.h:36
UT_String myName
Definition: AP_Interface.h:281
virtual int getToolboxCount() const
state
Definition: core.h:2289
PRM_ParmList * parameters() const
Definition: BM_ParmState.h:93