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