HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BM_SimpleState.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: Base Direct manipulation library (C++)
7  *
8  * COMMENTS:
9  * The base class of a general state.
10  *
11  */
12 
13 #ifndef __BM_SimpleState_H__
14 #define __BM_SimpleState_H__
15 
16 #include "BM_API.h"
17 #include <UT/UT_UndoManager.h>
18 #include <UT/UT_UndoWorkerFinder.h>
19 #include <UI/UI_Keyboard.h>
20 #include <SI/AP_Interface.h>
21 
22 class UT_String;
23 class RE_Render;
24 class RE_Cursor;
25 class UI_Feel;
26 class UI_Menu;
27 class BM_SceneManager;
28 class BM_Viewport;
29 
30 #define BM_STATE 0x00000000
31 #define BM_HANDLE 0x10000000
32 
34 {
35 public:
36  enum BM_EntryType { BM_FULLTIME_ENTRY = 0x01,
37  BM_OVERLAY_ENTRY = 0x02
38  };
39 
40  // Class constructor and destructor. 'name' is the name of the state.
41  BM_SimpleState(BM_SceneManager &app, const char *cursor,
42  const char *name = 0,
43  const char *const *vnames = 0,
44  UI_EventMethod const *vmethods = 0);
45 
46  virtual ~BM_SimpleState(void);
47 
48  // Returns the icon name and label that should appear in the viewer
49  // operation controls bar when we are in this state. The default
50  // implementation extracts this information from the state template.
51  virtual const char *getOperationBarIconName() const;
52  virtual const char *getOperationBarLabel() const;
53  virtual const char *getHotkeyString() const;
54 
55  // Return the menu feel for others to use:
56  virtual UI_Menu *getStateMenu(int ortho = 0);
57 
58  // Return a selector menu (if applicable).
59  virtual UI_Menu *getSelectorMenu();
60 
61  // Return an extra RMB menu (if applicable).
62  virtual UI_Menu *getExtraStateMenu();
63 
64  // Enter or exit this state.
65  virtual int enter(BM_EntryType how =
67  virtual void exit (void) = 0;
68 
69  // Interrupt or resume this state:
70  virtual void interrupt(BM_SimpleState * = 0);
71  virtual void resume (BM_SimpleState * = 0);
72 
73  // Deal with the events the modeler has sent me. Return 1 if consumed
74  // and 0 otherwise.
75  virtual int handleMouseEvent (UI_Event *event) = 0;
76  virtual int handleArrowEvent (UI_Event *event) = 0;
77  virtual int handleKeyEvent (UI_Event *event);
78  virtual int handleParameterEvent (UI_Event *event);
79 
80  // The state might contain some geometry it wants to display, but may not
81  // want it to be part of the main gdp. This method allows the state to
82  // "sneak in" this special geometry that it might have (eg. a rubber band
83  // when building curves). The feel of the workbench calls this method when
84  // it draws itself.
85  virtual void render(RE_Render *r, int x, int y);
86 
87  // Allows the state to draw things into the overlay plane, if it exists.
88  virtual void overlayRender(RE_Render *r, int x, int y);
89 
90  // These two function are used to get the different toolboxes
91  // that are defined by the different levels of subclassing.
92  //
93  // getToolboxCount returns the total number of toolboxes defined
94  // by this class (including all the ones defined by it's base classes)
95  // and getToolbox is used to query for each of them.
96  virtual int getToolboxCount() const;
97  virtual UI_Feel *getToolbox(int index) const;
98 
99  // Volatile states can also have toolboxes, but these cannot be queried
100  // by overriding BM_SimpleState::getToolboxCount()/getToolbox(int index)
101  // as the state has not necessarily been entered yet and so we cannot
102  // distinguish a volatile instance from a non-volatile one without the
103  // caller doing so for us. Note that it is possible to have both a
104  // volatile and a nonvolatile instance of the same state simultaneously,
105  // so getVolatileToolbox() should not return the same feel pointer as
106  // getToolbox().
107  //
108  virtual bool isOverlay() const;
109  virtual int getVolatileToolboxCount() const;
110  virtual UI_Feel *getVolatileToolbox(int index) const;
111 
112  // The name of this class:
113  virtual const char *className(void) const;
114 
115  // Is this simple state a handle?
116  virtual int isHandle() const = 0;
117 
118  void setVolatileViewport(BM_Viewport *view)
119  { myVolatileViewport = view; }
120  BM_Viewport *getVolatileViewport() const
121  { return myVolatileViewport; }
122 
123  // This needs to be available at the BM_SimpleState level, because
124  // when a state is resumed it may query whether it's coming back from
125  // a modifier state. A proper implementation is in BM_State.
126  virtual int isModifier(void) const { return 0; }
127 
128  // Classes derived from us will need to access the sceneManager:
129  BM_SceneManager &sceneManager(void) { return mySceneManager; }
130  const BM_SceneManager &sceneManager(void) const { return mySceneManager; }
131 
132  // Query or set the previous state, if any
134  { myPrevState = state; }
136  { return myPrevState; }
138  { return myPrevState; }
139 
140  virtual const char *replaceCursor(const char *newcursor);
141 
142  const char * getCurrentCursor() const
143  { return myCursor; }
144 
145  // Query the viewport mask to determine which viewports we can
146  // act in.
147  unsigned int getViewportMask() const { return myViewportMask; }
148 
150  { return myUndoWorkerFinder; }
151 
152  // These two functions are provided for all the BM_SimpleState based
153  // handles and states that need to manage an undo block that begins in one
154  // function but ends in another function (or another instance of the same
155  // function).
156  //
157  // However, they can only handle ONE block at a time. No nesting
158  // of calls to beginDistributedUndo!
159  void beginDistributedUndoBlock(const char *operation,
160  UT_UndoBlockType blocktype,
161  bool ignore_log=false);
162  void endDistributedUndoBlock(bool ignore_log=false);
163  bool inDistributedUndoBlock();
164 
165 protected:
166  // handle events coming from state popup menus
167  virtual void handlePopupMenuEvent(UI_Event *event);
168 
169  // handle an event from either the popup menu or the keyboard - perform the
170  // action on the specified viewport
171  virtual int handleKeyTypeEvent(UI_Event *event,
172  BM_Viewport &viewport);
173 
174  // Push or pop the cursor if one is defined and if we're running the UI
175  void pushCursor(void);
176  void popCursor (void);
177  void setCursor (void);
178  void setCursor (const char *cursorname);
179 
180  // Allow derived classes to override the cursor set by base classes.
181  // Don't confuse this method with setCursor.
182  void setDefaultCursor(const char *cursorname);
183 
184  // Initialize the app, wire the interface, tie all the UI values, etc:
185  void initializeUI();
186 
187  // Do the AP_Interface thing (called by initializeUI()):
188  virtual void initApplication(UI_Manager *, int c, const char **v);
189 
190  // Return the name of the UI file containing the menu, toolbox, or any
191  // other UI gadgets the SimpleState may have.
192  virtual void getUIFileName(UT_String &full_path_and_name) const;
193 
194  // Set or get the mouse button. It's a stash we might find useful
195  // occasionally.
196  void mouseDown(UI_Event *event);
197  int mouseDown(void) const { return myMouseDown; }
198 
199  // Set the viewport mask for the viewport types we will act in.
200  void setViewportMask(unsigned mask)
201  { myViewportMask = mask; }
202 
203  // set/remove flags that cause handleMouseEvent to be called when mouse
204  // buttons are pressed
205  int getClickInterest();
206  void addClickInterest(int buttons);
207  void removeClickInterest(int buttons);
208 
209  // redraw the scene
210  void redrawScene();
211 
212  // typically called from the derived class dtor to safely close an open undo block
213  void closeOpenUndoBlock();
214 
215 private:
216  BM_SceneManager &mySceneManager;// The sceneManager I'm a state of.
217  const char *myCursor; // the name of our cursor.
218  BM_SimpleState *myPrevState; // The state we're preempting
219  BM_Viewport *myVolatileViewport; // the viewport that events
220  // dealing with menus and other
221  // volatile handles should go to
222  UI_Feel *myMenuGadget; // the feel that holds the menu
223  UI_Feel *myOrthoMenuGadget;// the feel that holds the menu to
224  // be used in ortho viewports
225 
226  int myDistributedUndoBlockLevel;
227 
228  UI_Feel *mySimpleToolbox;
229 
230  unsigned int myViewportMask; // bit mask for viewports in which
231  // we need to handle events.
232 
233  int myMouseDown; // mouse button down on START or PICKED
234 
235  UT_UndoWorkerFinder<BM_SimpleState> myUndoWorkerFinder;
236 
237  UT_Array<RE_Cursor*> myCursorStack;
238 };
239 
240 #endif
const BM_SimpleState * getSavedState() const
const GLdouble * v
Definition: glcorearb.h:836
BM_SceneManager & sceneManager(void)
GLint GLuint mask
Definition: glcorearb.h:123
GLint y
Definition: glcorearb.h:102
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
const BM_SceneManager & sceneManager(void) const
struct _cl_event * event
Definition: glcorearb.h:2960
unsigned int getViewportMask() const
const UT_UndoWorkerFinder< BM_SimpleState > & undoWorkerFinder() const
UT_UndoBlockType
void setViewportMask(unsigned mask)
const char * getCurrentCursor() const
GLuint const GLchar * name
Definition: glcorearb.h:785
void setVolatileViewport(BM_Viewport *view)
#define BM_API
Definition: BM_API.h:10
BM_Viewport * getVolatileViewport() const
virtual void initApplication(UI_Manager *uims, int argc, const char **argv)
virtual int isModifier(void) const
GLuint index
Definition: glcorearb.h:785
GLint GLenum GLint x
Definition: glcorearb.h:408
void(UI_Object::* UI_EventMethod)(UI_Event *)
Definition: UI_Object.h:42
virtual const char * className() const
GLboolean r
Definition: glcorearb.h:1221
int mouseDown(void) const
void setSavedState(BM_SimpleState *state)
BM_SimpleState * getSavedState()