HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BM_OpState.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: BM_State.h
7  *
8  * COMMENTS:
9  * This is an "automated" state that links handles with op
10  * parameters.
11  */
12 
13 #ifndef __BM_OpState_H__
14 #define __BM_OpState_H__
15 
16 #include "BM_API.h"
17 #include <UT/UT_SymbolTable.h>
18 #include <UI/UI_LookType.h>
19 #include <PRM/PRM_Template.h>
20 #include "BM_MoveTool.h"
21 #include "BM_State.h"
22 
23 class OP_Node;
24 class BM_OpView;
25 class BM_Handle;
26 class UI_Feel;
27 class SI_Folders;
28 class BM_SceneManager;
29 class OPUI_Dialog;
30 class PI_OpHandleLink;
31 
32 class opbm_DialogInfo; // private to implementation
33 class opbm_PIContext; // private to implementation
34 class opbm_UIInfo; // private to implementation
35 
36 // NOTE: If you change this default cursor, make sure you update
37 // RE/RE_Cursor to reflect it.
38 #define BM_DEFAULT_CURSOR "iris"
39 
40 class BM_API BM_OpState : public BM_State
41 {
42 public:
43  // Class constructor and destructor.
44  BM_OpState(BM_OpView &view, PI_StateTemplate &templ,
45  BM_SceneManager *sceneManager,
46  const char *cursor = BM_DEFAULT_CURSOR);
47  ~BM_OpState() override;
48 
49  // Mouse events are passed on to all visible PI's.
50  int handleMouseEvent (UI_Event *event) override;
51  int handleMouseWheelEvent (UI_Event *event) override;
52 
53  // The name and type of this class:
54  const char *className() const override;
55 
56  void prepareDialogForDisplay() const override;
57  int hasDialog() const override;
58  UI_Feel *dialogFeel() const override;
59 
60  int findPI(BM_OpHandleLink *pi) const override;
61 
62  // Called to give any PIs a chance to update (and optionally reveal) an
63  // invisible handle rather than have the viewer switch to a move tool
64  // state. This method returns true if a handle was updated (i.e. the
65  // viewer should not launch a move tool state).
66  virtual bool updateInvisiblePIHandleForMoveTool(
67  bool (*func)(BM_Handle *handle,
68  BM_MoveTool::Type tool,
69  unsigned vport_mask),
70  BM_MoveTool::Type tool,
71  unsigned vport_mask,
72  bool make_visible);
73 
74  // These set the flag as to whether or not we highlight ops
75  // as we drop them.
76  static int getAutoHighlightFlag() { return theAutoHighlightFlag;}
77  static void setAutoHighlightFlag(int o)
78  { theAutoHighlightFlag = o; }
79  /// Obtains the current global time.
80  fpreal getTime() const;
81 
82  bool getStateParmNames(
83  UT_StringArray &ret,
84  const char* prefix=nullptr ) override;
85  bool evalStateParm(
86  const char *name,
87  UT_StringHolder &ret) override;
88  bool setStateParm(
89  const char *name,
90  const UT_StringHolder &val) override;
91  bool pressStateButton(const char *name) override;
92 
93  BM_OpHandleLink* piByRootDescription(const char *description);
94  BM_OpHandleLink const* piByRootDescription(const char *description) const;
95 
96  // Return the the operator name linked to the state. Defaults to the
97  // state template name.
98  // NOTE: This method is required in several places in Houdini where
99  // a state is being asked for an operator name. This is likey to be
100  // overriden by python state derived classes as the state name
101  // (template name) is not necessarily the same as the state operator
102  // name.
103  virtual const char* getOperatorName() const;
104 
105 protected:
106  BM_OpView &baseViewer() { return myViewer; }
107  const BM_OpView &baseViewer() const { return myViewer; }
108 
109 
110  // Interrupt this state or resume its activity.
111  void interrupt(BM_SimpleState * = 0) override;
112  void resume (BM_SimpleState * = 0) override;
113 
114  void getKeyResolveInfo(UI_KeyResolveInfo &info) override;
115 
116  // deal with events coming from either the popup menus or the keyboard
117  int handleKeyTypeEvent(int key, UI_Event *event,
118  BM_Viewport &viewport) override;
119  // Handle transitory key presses.
120  bool handleTransitoryKey(const UI_Event &event,
121  int hotkey_id) override;
122 
123  // Create a PI and add it to the list of PI's. If add_button is set,
124  // a button is added to turn the PI on and off, and the makePIVisible
125  // method is called when the button is pressed. This button is added
126  // to the specified folder. On success, the index of the newly added
127  // PI is returned. -1 is returned on failure.
128  int createPI(const char *pi_name, int opnum = -1,
129  const char *description = 0);
130 
131  // allows base class to react when a new PI is created, appended or removed
132  virtual void onCreatePI(PI_OpHandleLink *pi);
133  virtual void onAppendPI(PI_OpHandleLink *pi);
134  virtual void onRemovePI(PI_OpHandleLink *pi);
135 
136  // Append an already existing PI and reflect it it our UI:
137  int appendPI(BM_OpHandleLink *pi, int opnum = -1);
138  virtual void removePI(int pi_idx);
139  void removeAllLinkedPIs();
140  void removeLinkedPIByDescription(const char* descr_name);
141 
142  BM_OpHandleLink *pi(int index);
143  const BM_OpHandleLink *pi(int index) const;
144  BM_OpHandleLink *pi(const char *name);
145  const BM_OpHandleLink *pi(const char *name) const;
146 
147  const char *piDescription(int index) const;
148  int piOpnum(int index) const;
149  int numPIs() const { return myPIs.entries(); }
150 
151  // This method is called whenever the button is pressed to turn a PI
152  // on or off. It does not need to redraw the workbench. It does nothing
153  // in this base class.
154  virtual void makePIVisible(int pi_idx, int onoff);
155 
156  // Methods to combine different dialogs into the dialog for this state.
157  int appendFolder(const char *folder_name);
158  void appendFeelToFolder(const char *folder_name,
159  UI_Feel *child_feel);
160  int appendDialogToFolder(const char *folder_name,
161  BM_ParmState &state_or_handle);
162  int appendDialogToFolder(const char *folder_name,
163  OP_Node &op_node,
164  PRM_Template::PRM_Export export_level);
165  int appendThisStateDialogToFolder(const char *folder_name);
166  int appendDividerToFolder(const char *folder_name);
167  int appendTextToFolder(
168  const char *folder_name, const char *text,
169  UI_LookType look_type = UI_LOOK_HEADING_TEXT);
170  int removeDialog(BM_ParmState &state);
171  int removeDialog(OP_Node &op_node,
172  PRM_Template::PRM_Export export_level);
173  int removeFolder(const char *name, bool only_if_empty=false);
174 
175  // A subset of methods similar to the above. Use these methods if
176  // you need to remove the UI items individually with removeCachedUIItems.
177  // NOTE: The UI items are stored per folder_name and a unique cache_id.
178  int appendDialogToFolder(const char *folder_name,
179  BM_ParmState &state_or_handle, BM_Handle* handle);
180  int appendDividerToFolder(const char *folder_name, BM_Handle* handle);
181  int appendTextToFolder(const char *folder_name, const char *text,
182  UI_LookType look_type, BM_Handle* handle);
183 
184  // Remove the UI items from a cache populated with the above methods.
185  int removeCachedUIItems(const char *folder_name, BM_Handle* handle);
186 
187  // Switches the UI to look at the folder given by name (if it exists)
188  void switchToFolder(const char *name);
189 
190  // callback that is called when a dialog is deleted. It clears
191  // any pointers that may become stale.
192  virtual void handleDialogDeleted( OPUI_Dialog *deleted_dialog );
193 
194  // This will remove all the dialogs which this state has created.
195  // It is virtual as some derived states may have extra dialogs.
196  virtual void removeAllDialogs();
197  void handlePIVisibilityChange(UI_Event *event);
198 
199  // Make the new, not-yet-connected node an output of the inputnode.
200  // If not branching off, move inputnode's outputs to newnode's
201  // output list.
202  void connectNode(OP_Node &newnode, OP_Node &inputnode,
203  int input_idx = 0, int branch_off = 0);
204 
205  // Stamp the node with the name of this state:
206  void stampNode(OP_Node &newnode);
207 
208  // Return 1 if the node is generated by a state that matches our name,
209  // or if the node's name matches our name:
210  virtual int matchesNode(OP_Node &node) const = 0;
211 
212  BM_OpView &myViewer;
213 
217  SI_Folders *myFolders;
218 
219  static const char *STATE_DIALOG_FOLDER;
220  static const char *HANDLES_FOLDER;
221  static const char *OP_DIALOG_FOLDER;
223 
224 private:
225  // callback that is called when a dialog is deleted. It clears
226  // any pointers that may become stale.
227  void dialogDeletedCallback( UI_Event* event );
228 
229  void buildStateParmPrefix(UT_WorkBuffer &buf, BM_OpHandleLink *pii, BM_Handle *h);
230  BM_ParmState* findStateParm( UT_String &name );
231 
232  opbm_UIInfo* uiInfo(char const* folder_name, int64 cache_id);
233 
234  UT_Map<std::pair<int32 /*folder id*/, int64 /*ui cache id*/>, opbm_UIInfo> myUIInfoMap;
235 };
236 
237 #endif
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
int int32
Definition: SYS_Types.h:39
Unsorted map container.
Definition: UT_Map.h:107
SI_Folders * myFolders
Definition: BM_OpState.h:217
UT_ValArray< opbm_PIContext * > myPIs
Definition: BM_OpState.h:215
virtual UI_Feel * dialogFeel() const
static const char * HANDLES_FOLDER
Definition: BM_OpState.h:220
UI_LookType
Definition: UI_Types.h:150
UT_ValArray< UI_Feel * > myMiscFeels
Definition: BM_OpState.h:216
struct _cl_event * event
Definition: glcorearb.h:2961
#define BM_DEFAULT_CURSOR
Definition: BM_OpState.h:38
BM_OpView & myViewer
Definition: BM_OpState.h:212
static int getAutoHighlightFlag()
Definition: BM_OpState.h:76
virtual int handleMouseWheelEvent(UI_Event *event)
virtual bool setStateParm(const char *name, const UT_StringHolder &val)
void resume(BM_SimpleState *state=0) override
virtual bool getStateParmNames(UT_StringArray &ret, const char *prefix=nullptr)
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
static const char * OP_DIALOG_FOLDER
Definition: BM_OpState.h:221
virtual int findPI(BM_OpHandleLink *pi) const
virtual bool handleTransitoryKey(const UI_Event &, int)
Definition: BM_State.h:247
#define BM_API
Definition: BM_API.h:10
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
virtual bool pressStateButton(const char *name)
UT_ValArray< opbm_DialogInfo * > myDialogs
Definition: BM_OpState.h:214
GLenum func
Definition: glcorearb.h:783
static void setAutoHighlightFlag(int o)
Definition: BM_OpState.h:77
static const char * STATE_DIALOG_FOLDER
Definition: BM_OpState.h:219
const BM_OpView & baseViewer() const
Definition: BM_OpState.h:107
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
GLuint GLfloat * val
Definition: glcorearb.h:1608
BM_OpView & baseViewer()
Definition: BM_OpState.h:106
void interrupt(BM_SimpleState *state=0) override
constexpr T pi()
Pi constant taken from Boost to match old behaviour.
Definition: Math.h:119
Definition: core.h:982
int handleMouseEvent(UI_Event *event) override
virtual bool evalStateParm(const char *name, UT_StringHolder &ret)
virtual int hasDialog() const
virtual void getKeyResolveInfo(UI_KeyResolveInfo &info)
virtual void prepareDialogForDisplay() const
static int theAutoHighlightFlag
Definition: BM_OpState.h:222
virtual int handleKeyTypeEvent(int key, UI_Event *event, BM_Viewport &viewport)
int numPIs() const
Definition: BM_OpState.h:149
const char * className() const override