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