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  // NB: Subclasses should override handleKeyTypeEvent() instead.
94  virtual int handleKeyEvent (int key,UI_Event *event) final;
95  virtual int handleParameterEvent (UI_Event *event);
96 
97  // The state might contain some geometry it wants to display, but may not
98  // want it to be part of the main gdp. This method allows the state to
99  // "sneak in" this special geometry that it might have (eg. a rubber band
100  // when building curves). The feel of the workbench calls this method when
101  // it draws itself.
102  virtual void render(RE_Render *r, int x, int y);
103 
104  // Allows the state to draw things into the overlay plane, if it exists.
105  virtual void overlayRender(RE_Render *r, int x, int y);
106 
107  // These two function are used to get the different toolboxes
108  // that are defined by the different levels of subclassing.
109  //
110  // getToolboxCount returns the total number of toolboxes defined
111  // by this class (including all the ones defined by it's base classes)
112  // and getToolbox is used to query for each of them.
113  virtual int getToolboxCount() const;
114  virtual UI_Feel *getToolbox(int index) const;
115 
116  // Volatile states can also have toolboxes, but these cannot be queried
117  // by overriding BM_SimpleState::getToolboxCount()/getToolbox(int index)
118  // as the state has not necessarily been entered yet and so we cannot
119  // distinguish a volatile instance from a non-volatile one without the
120  // caller doing so for us. Note that it is possible to have both a
121  // volatile and a nonvolatile instance of the same state simultaneously,
122  // so getVolatileToolbox() should not return the same feel pointer as
123  // getToolbox().
124  //
125  virtual bool isOverlay() const;
126  virtual int getVolatileToolboxCount() const;
127  virtual UI_Feel *getVolatileToolbox(int index) const;
128 
129  // The name of this class:
130  const char *className() const override;
131 
132  // Is this simple state a handle?
133  virtual int isHandle() const = 0;
134 
135  void setVolatileViewport(BM_Viewport *view)
136  { myVolatileViewport = view; }
137  BM_Viewport *getVolatileViewport() const
138  { return myVolatileViewport; }
139 
140  // This needs to be available at the BM_SimpleState level, because
141  // when a state is resumed it may query whether it's coming back from
142  // a modifier state. A proper implementation is in BM_State.
143  virtual int isModifier() const { return 0; }
144 
145  // Classes derived from us will need to access the sceneManager:
146  BM_SceneManager &sceneManager() { return mySceneManager; }
147  const BM_SceneManager &sceneManager() const { return mySceneManager; }
148 
149  // Query or set the previous state, if any
151  { myPrevState = state; }
153  { return myPrevState; }
155  { return myPrevState; }
156 
157  virtual const char *replaceCursor(const char *newcursor);
158 
159  const char * getCurrentCursor() const
160  { return myCursor; }
161 
162  // Query the viewport mask to determine which viewports we can
163  // act in.
164  unsigned int getViewportMask() const { return myViewportMask; }
165 
167  { return myUndoWorkerFinder; }
168 
169  // These two functions are provided for all the BM_SimpleState based
170  // handles and states that need to manage an undo block that begins in one
171  // function but ends in another function (or another instance of the same
172  // function).
173  //
174  // However, they can only handle ONE block at a time. No nesting
175  // of calls to beginDistributedUndo!
176  void beginDistributedUndoBlock(const char *operation,
177  UT_UndoBlockType blocktype,
178  bool ignore_log=false);
179  void endDistributedUndoBlock(bool ignore_log=false);
180  bool inDistributedUndoBlock();
181 
182 protected:
183  // handle events coming from state popup menus
184  virtual void handlePopupMenuEvent(UI_Event *event);
185 
186  // handle an event from either the popup menu or the keyboard - perform the
187  // action on the specified viewport
188  virtual int handleKeyTypeEvent(int key, UI_Event *event,
189  BM_Viewport &viewport);
190 
191  // Push or pop the cursor if one is defined and if we're running the UI
192  void pushCursor();
193  void popCursor();
194  void setCursor();
195  void setCursor(const char *cursorname);
196 
197  // Allow derived classes to override the cursor set by base classes.
198  // Don't confuse this method with setCursor.
199  void setDefaultCursor(const char *cursorname);
200 
201  // Initialize the app, wire the interface, tie all the UI values, etc:
202  void initializeUI();
203 
204  // Do the AP_Interface thing (called by initializeUI()):
205  void initApplication(UI_Manager *,
206  int,
207  const char **) override;
208 
209  // Return the name of the UI file containing the menu, toolbox, or any
210  // other UI gadgets the SimpleState may have.
211  virtual void getUIFileName(UT_String &full_path_and_name) const;
212 
213  // Set or get the mouse button. It's a stash we might find useful
214  // occasionally.
215  void mouseDown(UI_Event *event);
216  int mouseDown() const { return myMouseDown; }
217 
218  // Set the viewport mask for the viewport types we will act in.
219  void setViewportMask(unsigned mask)
220  { myViewportMask = mask; }
221 
222  // set/remove flags that cause handleMouseEvent to be called when mouse
223  // buttons are pressed
224  int getClickInterest();
225  void addClickInterest(int buttons);
226  void removeClickInterest(int buttons);
227 
228  // redraw the scene
229  void redrawScene();
230 
231  // typically called from the derived class dtor to safely close an open undo block
232  void closeOpenUndoBlock();
233 
234 private:
235  BM_SceneManager &mySceneManager;// The sceneManager I'm a state of.
236  const char *myCursor; // the name of our cursor.
237  BM_SimpleState *myPrevState; // The state we're preempting
238  BM_Viewport *myVolatileViewport; // the viewport that events
239  // dealing with menus and other
240  // volatile handles should go to
241  UI_Feel *myMenuGadget; // the feel that holds the menu
242  UI_Feel *myOrthoMenuGadget;// the feel that holds the menu to
243  // be used in ortho viewports
244 
245  int myDistributedUndoBlockLevel;
246 
247  UI_Feel *mySimpleToolbox;
248 
249  unsigned int myViewportMask; // bit mask for viewports in which
250  // we need to handle events.
251 
252  int myMouseDown; // mouse button down on START or PICKED
253 
254  UT_UndoWorkerFinder<BM_SimpleState> myUndoWorkerFinder;
255 
256  UT_Array<RE_Cursor*> myCursorStack;
257 };
258 
259 #endif
const BM_SceneManager & sceneManager() const
const BM_SimpleState * getSavedState() const
const char * className() const override
virtual int isModifier() const
GLuint const GLchar * name
Definition: glcorearb.h:785
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
GLint GLenum GLint x
Definition: glcorearb.h:408
struct _cl_event * event
Definition: glcorearb.h:2960
unsigned int getViewportMask() const
GLint GLuint mask
Definition: glcorearb.h:123
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
virtual void initApplication(UI_Manager *uims, int argc, const char **argv)
virtual void onBeginRMBMenu(UI_Event *)
BM_SceneManager & sceneManager()
GLuint index
Definition: glcorearb.h:785
void(UI_Object::* UI_EventMethod)(UI_Event *)
Definition: UI_Object.h:36
void setSavedState(BM_SimpleState *state)
GLboolean r
Definition: glcorearb.h:1221
BM_SimpleState * getSavedState()
virtual bool canShowStateMenu() const
GLint y
Definition: glcorearb.h:102