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