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