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