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