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 *scene_manager,
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  UT_ValArray<BM_OpHandleLink const*> piListByParmName(const char* parm_name) const;
96 
97  // Return the the operator name linked to the state. Defaults to the
98  // state template name.
99  // NOTE: This method is required in several places in Houdini where
100  // a state is being asked for an operator name. This is likey to be
101  // overriden by python state derived classes as the state name
102  // (template name) is not necessarily the same as the state operator
103  // name.
104  virtual const char* getOperatorName() const;
105 
106 protected:
107  BM_OpView &baseViewer() { return myViewer; }
108  const BM_OpView &baseViewer() const { return myViewer; }
109 
110 
111  // Interrupt this state or resume its activity.
112  void interrupt(BM_SimpleState * = 0) override;
113  void resume (BM_SimpleState * = 0) override;
114 
115  void getKeyResolveInfo(UI_KeyResolveInfo &info) override;
116 
117  // deal with events coming from either the popup menus or the keyboard
118  int handleKeyTypeEvent(int key, UI_Event *event,
119  BM_Viewport &viewport) override;
120  // Handle transitory key presses.
121  bool handleTransitoryKey(const UI_Event &event,
122  int hotkey_id) override;
123 
124  // Create a PI and add it to the list of PI's. If add_button is set,
125  // a button is added to turn the PI on and off, and the makePIVisible
126  // method is called when the button is pressed. This button is added
127  // to the specified folder. On success, the index of the newly added
128  // PI is returned. -1 is returned on failure.
129  int createPI(const char *pi_name, int opnum = -1,
130  const char *description = 0);
131 
132  // allows base class to react when a new PI is created, appended or removed
133  virtual void onCreatePI(PI_OpHandleLink *pi);
134  virtual void onAppendPI(PI_OpHandleLink *pi);
135  virtual void onRemovePI(PI_OpHandleLink *pi);
136 
137  // Append an already existing PI and reflect it it our UI:
138  int appendPI(BM_OpHandleLink *pi, int opnum = -1);
139  virtual void removePI(int pi_idx);
140  void removeAllLinkedPIs();
141  void removeLinkedPIByDescription(const char* descr_name);
142 
143  BM_OpHandleLink *pi(int index);
144  const BM_OpHandleLink *pi(int index) const;
145  BM_OpHandleLink *pi(const char *name);
146  const BM_OpHandleLink *pi(const char *name) const;
147 
148  const char *piDescription(int index) const;
149  int piOpnum(int index) const;
150  int numPIs() const { return myPIs.entries(); }
151 
152  // This method is called whenever the button is pressed to turn a PI
153  // on or off. It does not need to redraw the workbench. It does nothing
154  // in this base class.
155  virtual void makePIVisible(int pi_idx, int onoff);
156 
157  // Methods to combine different dialogs into the dialog for this state.
158  int appendFolder(const char *folder_name);
159  void appendFeelToFolder(const char *folder_name,
160  UI_Feel *child_feel);
161  int appendDialogToFolder(const char *folder_name,
162  BM_ParmState &state_or_handle);
163  int appendDialogToFolder(const char *folder_name,
164  OP_Node &op_node,
165  PRM_Template::PRM_Export export_level);
166  int appendThisStateDialogToFolder(const char *folder_name);
167  int appendDividerToFolder(const char *folder_name);
168  int appendTextToFolder(
169  const char *folder_name, const char *text,
170  UI_LookType look_type = UI_LOOK_HEADING_TEXT);
171  int removeDialog(BM_ParmState &state);
172  int removeDialog(OP_Node &op_node,
173  PRM_Template::PRM_Export export_level);
174  int removeFolder(const char *name, bool only_if_empty=false);
175 
176  // A subset of methods similar to the above. Use these methods if
177  // you need to remove the UI items individually with removeCachedUIItems.
178  // NOTE: The UI items are stored per folder_name and a unique cache_id.
179  int appendDialogToFolder(const char *folder_name,
180  BM_ParmState &state_or_handle, BM_Handle* handle);
181  int appendDividerToFolder(const char *folder_name, BM_Handle* handle);
182  int appendTextToFolder(const char *folder_name, const char *text,
183  UI_LookType look_type, BM_Handle* handle);
184 
185  // Remove the UI items from a cache populated with the above methods.
186  int removeCachedUIItems(const char *folder_name, BM_Handle* handle);
187 
188  // Switches the UI to look at the folder given by name (if it exists)
189  void switchToFolder(const char *name);
190 
191  // callback that is called when a dialog is deleted. It clears
192  // any pointers that may become stale.
193  virtual void handleDialogDeleted( OPUI_Dialog *deleted_dialog );
194 
195  // This will remove all the dialogs which this state has created.
196  // It is virtual as some derived states may have extra dialogs.
197  virtual void removeAllDialogs();
198  void handlePIVisibilityChange(UI_Event *event);
199 
200  // Make the new, not-yet-connected node an output of the inputnode.
201  // If not branching off, move inputnode's outputs to newnode's
202  // output list.
203  void connectNode(OP_Node &newnode, OP_Node &inputnode,
204  int input_idx = 0, int branch_off = 0);
205 
206  // Stamp the node with the name of this state:
207  void stampNode(OP_Node &newnode);
208 
209  // Return 1 if the node is generated by a state that matches our name,
210  // or if the node's name matches our name:
211  virtual int matchesNode(OP_Node &node) const = 0;
212 
213  BM_OpView &myViewer;
214 
218  SI_Folders *myFolders;
219 
220  static const char *STATE_DIALOG_FOLDER;
221  static const char *HANDLES_FOLDER;
222  static const char *OP_DIALOG_FOLDER;
224 
225 private:
226  // callback that is called when a dialog is deleted. It clears
227  // any pointers that may become stale.
228  void dialogDeletedCallback( UI_Event* event );
229 
230  void buildStateParmPrefix(UT_WorkBuffer &buf, BM_OpHandleLink *pii, BM_Handle *h);
231  BM_ParmState* findStateParm( UT_String &name );
232 
233  opbm_UIInfo* uiInfo(char const* folder_name, int64 cache_id);
234 
235  UT_Map<std::pair<int32 /*folder id*/, int64 /*ui cache id*/>, opbm_UIInfo> myUIInfoMap;
236 };
237 
238 #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:109
SI_Folders * myFolders
Definition: BM_OpState.h:218
UT_ValArray< opbm_PIContext * > myPIs
Definition: BM_OpState.h:216
virtual UI_Feel * dialogFeel() const
static const char * HANDLES_FOLDER
Definition: BM_OpState.h:221
UI_LookType
Definition: UI_Types.h:150
UT_ValArray< UI_Feel * > myMiscFeels
Definition: BM_OpState.h:217
struct _cl_event * event
Definition: glcorearb.h:2961
#define BM_DEFAULT_CURSOR
Definition: BM_OpState.h:38
BM_OpView & myViewer
Definition: BM_OpState.h:213
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:222
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:215
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:220
__hostdev__ constexpr T pi()
Pi constant taken from Boost to match old behaviour.
Definition: NanoVDB.h:976
const BM_OpView & baseViewer() const
Definition: BM_OpState.h:108
fpreal64 fpreal
Definition: SYS_Types.h:278
GLuint index
Definition: glcorearb.h:786
GLuint GLfloat * val
Definition: glcorearb.h:1608
BM_OpView & baseViewer()
Definition: BM_OpState.h:107
void interrupt(BM_SimpleState *state=0) override
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:223
virtual int handleKeyTypeEvent(int key, UI_Event *event, BM_Viewport &viewport)
state
Definition: core.h:2289
int numPIs() const
Definition: BM_OpState.h:150
const char * className() const override