HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  // Return the menu feel for others to use:
49  virtual UI_Menu *getStateMenu(int ortho = 0);
50 
51  // Return a selector menu (if applicable).
52  virtual UI_Menu *getSelectorMenu();
53 
54  // Return an extra RMB menu (if applicable).
55  virtual UI_Menu *getExtraStateMenu();
56 
57  // Enter or exit this state.
58  virtual int enter(BM_EntryType how =
60  virtual void exit (void) = 0;
61 
62  // Interrupt or resume this state:
63  virtual void interrupt(BM_SimpleState * = 0);
64  virtual void resume (BM_SimpleState * = 0);
65 
66  // Deal with the events the modeler has sent me. Return 1 if consumed
67  // and 0 otherwise.
68  virtual int handleMouseEvent (UI_Event *event) = 0;
69  virtual int handleArrowEvent (UI_Event *event) = 0;
70  virtual int handleKeyEvent (UI_Event *event);
71  virtual int handleParameterEvent (UI_Event *event);
72 
73  // The state might contain some geometry it wants to display, but may not
74  // want it to be part of the main gdp. This method allows the state to
75  // "sneak in" this special geometry that it might have (eg. a rubber band
76  // when building curves). The feel of the workbench calls this method when
77  // it draws itself.
78  virtual void render(RE_Render *r, int x, int y);
79 
80  // Allows the state to draw things into the overlay plane, if it exists.
81  virtual void overlayRender(RE_Render *r, int x, int y);
82 
83  // These two function are used to get the different toolboxes
84  // that are defined by the different levels of subclassing.
85  //
86  // getToolboxCount returns the total number of toolboxes defined
87  // by this class (including all the ones defined by it's base classes)
88  // and getToolbox is used to query for each of them.
89  virtual int getToolboxCount() const;
90  virtual UI_Feel *getToolbox(int index) const;
91 
92  // The name of this class:
93  virtual const char *className(void) const;
94 
95  // Is this simple state a handle?
96  virtual int isHandle() const = 0;
97 
98  void setVolatileViewport(BM_Viewport *view)
99  { myVolatileViewport = view; }
100  BM_Viewport *getVolatileViewport() const
101  { return myVolatileViewport; }
102 
103  // This needs to be available at the BM_SimpleState level, because
104  // when a state is resumed it may query whether it's coming back from
105  // a modifier state. A proper implementation is in BM_State.
106  virtual int isModifier(void) const { return 0; }
107 
108  // Classes derived from us will need to access the sceneManager:
109  BM_SceneManager &sceneManager(void) { return mySceneManager; }
110  const BM_SceneManager &sceneManager(void) const { return mySceneManager; }
111 
112  // Query or set the previous state, if any
114  { myPrevState = state; }
116  { return myPrevState; }
118  { return myPrevState; }
119 
120  virtual const char *replaceCursor(const char *newcursor);
121 
122  const char * getCurrentCursor() const
123  { return myCursor; }
124 
125  // Query the viewport mask to determine which viewports we can
126  // act in.
127  unsigned int getViewportMask() const { return myViewportMask; }
128 
130  { return myUndoWorkerFinder; }
131 
132 protected:
133  // handle events coming from state popup menus
134  virtual void handlePopupMenuEvent(UI_Event *event);
135 
136  // handle an event from either the popup menu or the keyboard - perform the
137  // action on the specified viewport
138  virtual int handleKeyTypeEvent(UI_Event *event,
139  BM_Viewport &viewport);
140 
141  // Push or pop the cursor if one is defined and if we're running the UI
142  void pushCursor(void);
143  void popCursor (void);
144  void setCursor (void);
145  void setCursor (const char *cursorname);
146 
147  // Allow derived classes to override the cursor set by base classes.
148  // Don't confuse this method with setCursor.
149  void setDefaultCursor(const char *cursorname);
150 
151  // Initialize the app, wire the interface, tie all the UI values, etc:
152  void initializeUI();
153 
154  // Do the AP_Interface thing (called by initializeUI()):
155  virtual void initApplication(UI_Manager *, int c, const char **v);
156 
157  // Return the name of the UI file containing the menu, toolbox, or any
158  // other UI gadgets the SimpleState may have.
159  virtual void getUIFileName(UT_String &full_path_and_name) const;
160 
161  // Set or get the mouse button. It's a stash we might find useful
162  // occasionally.
163  void mouseDown(UI_Event *event);
164  int mouseDown(void) const { return myMouseDown; }
165 
166 
167  // These two functions are provided for all the BM_SimpleState based
168  // handles and states that need to manage an undo block that begins in one
169  // function but ends in another function (or another instance of the same
170  // function).
171  //
172  // However, they can only handle ONE block at a time. No nesting
173  // of calls to beginDistributedUndo!
174  void beginDistributedUndoBlock(const char *operation,
175  UT_UndoBlockType blocktype);
176  void endDistributedUndoBlock();
177  bool inDistributedUndoBlock();
178 
179  // Set the viewport mask for the viewport types we will act in.
180  void setViewportMask(unsigned mask)
181  { myViewportMask = mask; }
182 
183  // set/remove flags that cause handleMouseEvent to be called when mouse
184  // buttons are pressed
185  int getClickInterest();
186  void addClickInterest(int buttons);
187  void removeClickInterest(int buttons);
188 
189  // redraw the scene
190  void redrawScene();
191 
192 private:
193  BM_SceneManager &mySceneManager;// The sceneManager I'm a state of.
194  const char *myCursor; // the name of our cursor.
195  BM_SimpleState *myPrevState; // The state we're preempting
196  BM_Viewport *myVolatileViewport; // the viewport that events
197  // dealing with menus and other
198  // volatile handles should go to
199  UI_Feel *myMenuGadget; // the feel that holds the menu
200  UI_Feel *myOrthoMenuGadget;// the feel that holds the menu to
201  // be used in ortho viewports
202 
203  int myDistributedUndoBlockLevel;
204 
205  UI_Feel *mySimpleToolbox;
206 
207  unsigned int myViewportMask; // bit mask for viewports in which
208  // we need to handle events.
209 
210  int myMouseDown; // mouse button down on START or PICKED
211 
212  UT_UndoWorkerFinder<BM_SimpleState> myUndoWorkerFinder;
213 
214  UT_Array<RE_Cursor*> myCursorStack;
215 };
216 
217 #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()