HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BM_SingleOpState.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_SingleOpState.h
7  *
8  * COMMENTS:
9  * This is an "automated" state that links handles with op
10  * parameters.
11  */
12 
13 #ifndef __BM_SingleOpState_H__
14 #define __BM_SingleOpState_H__
15 
16 #include "BM_API.h"
17 #include <UT/UT_IntArray.h>
18 #include <UT/UT_String.h>
19 #include <UT/UT_SymbolTable.h>
20 #include <PRM/PRM_Value.h>
21 #include <PI/PI_ResourceManager.h>
22 #include "BM_OpState.h"
23 
24 class OP_Operator;
25 class OP_Node;
26 class BM_OpHandleLink;
27 class OPUI_Dialog;
28 
29 class BM_UndoSetNode;
30 
32 {
33  friend class BM_UndoSetNode;
34 
35 public:
36  // Class constructor and destructor.
37  BM_SingleOpState(BM_OpView &view, PI_StateTemplate &templ,
38  BM_SceneManager *scene,
39  const char *cursor = BM_DEFAULT_CURSOR);
40  ~BM_SingleOpState() override;
41 
42  // Enter or exit this state.
43  int enter(BM_SimpleState::BM_EntryType how) override;
44  void exit() override;
45  void restart() override;
46 
47  // Similar to enter, but totally from scratch. At this level, it's the
48  // same as doing an enter. It cannot be entered in volatile mode.
50  const GenerateParms &parms) override;
51 
52 
53  // Stop the generation process.
54  void stopGenerating() override;
55 
56  // See how you can handle a node being deleted. If it's an implicit
57  // node we might be OK. Return 0 if we can handle it, -1 if we must
58  // be exited or restarted from scratch.
59  int handleNodeDeleted(OP_Node &node) override;
60 
61  int hasOpNode(const OP_Node &node) const override;
62 
63  void handleOpNetClear() override;
64 
65  // The name and type of this class:
66  const char *className() const override;
67 
68  // Allow the state to access the node so that it can process information.
69  OP_Node *getNode() const;
70 
71  int getToolboxCount() const override;
72  UI_Feel *getToolbox(int index) const override;
73 
74  // Create, link, attach, position, push, and activate a single handle.
75  // NOTE: Typically used in pair with deleteOpHandleLink below for
76  // adding/removing handle links dynamically.
77  void createOpHandleLink(const char* handle_instance_name, const char* settings=nullptr,
78  bool load_settings = true);
79  // Remove a handle link by PI descripton name along with its dialog.
80  // Returns true if successful, false otherwise.
81  bool deleteOpHandleLink(const char* handle_instance_name, bool remove_bindings = false);
82 
83 protected:
84  // Provide the Op to work with. The criteria for which OP to use will
85  // be specific to each network type. This method does NOT overwrite
86  // the myOpNode pointer.
87  virtual OP_Node *getChosenOp() const = 0;
88 
89  // This method is called whenever the button is pressed to turn a PI
90  // on or off. It does not need to redraw the workbench.
91  void makePIVisible(int pi_idx, int onoff) override;
92 
93  // Begin generating (and maybe finish too if you can od it quickly).
94  // This method is called from generate() and is currently empty. You may
95  // not need to redefine it at all.
96  virtual void doGenerate();
97 
98  // Build an OP that matches our name or the name passed into the function
99  // if not nil. This does not set myOpNode.
100  OP_Node *createNode(const char *optype = 0,
101  const char *nettype = 0,
102  OP_Network *parent = 0,
103  int explicitly = 1);
104 
105  // return the node name required for createNode
106  virtual const char* getCreateNodeName() const
107  {
108  return getName();
109  }
110 
111  // Set the work node. This will detach and clean up after the previous
112  // node should there be one.
113  // setNode is virtual because the state may want to do different
114  // things when the node is set, like saving the look of PIs.
115  virtual void setNode(OP_Node *node);
116  void setNodeId(int id);
117 
118  // Make this node current. Derived classes may choose to do other things.
119  virtual void setNodeFlags(OP_Node &node);
120 
121  // Disable the footprint flag of the current node if it has outputs
122  virtual void clearChosenNodeFlags();
123 
124  // The user can dynamically change the bindings from the textport
125  // We need to refresh the current handle in the viewports
126  // cause they could be affected.
127  void refreshBindings(int id, const char *op_type) override;
128  void refreshSettings(int id, const char *op_type) override;
129 
130  // Access to the saved node, ie the node that we may have stashed away
131  // on a restart():
132  OP_Node *savedNode() const { return mySavedOpNode; }
134  {
135  clearRestartInfo();
136  mySavedOpNode = n;
137  }
138 
139  // Generate the parts of the dialog needed before the PI's are created.
140  virtual void initializeDialogs();
141  // Generate the parts of the dialog that can only be created after all the
142  // PI's are created.
143  virtual void completeDialogs();
144 
145  // Return 1 if the node is generated by a state that matches our name,
146  // or if the node's name matches our name:
147  int matchesNode(OP_Node &node) const override;
148 
149  // Removes all the dialogs including our locally defined toolbox.
150  void removeAllDialogs() override;
151 
152  // callback that is called when a dialog is deleted. It clears
153  // any pointers that may become stale.
154  void handleDialogDeleted( OPUI_Dialog *dialog ) override;
155 
156  // The method gets called when reselecting and should be overridden to
157  // add any undos needed to undo reselection.
158  virtual void addAnyReselectionUndos();
159 
160  // Return false from this function to prevent our node from having its
161  // inputs disconnected when we restart this state. Used by DOP data
162  // states, which want to leave inputs connected. The default
163  // implementation returns true.
164  virtual bool disconnectInputsOnRestart() const;
165 
166  void clearOpHandleLinks();
167 
168  // Override this to return false if undesired
169  virtual bool allowOpMaxExportToDialog() const { return true; }
170 
171  // Leaf classes can reimplement to avoid creating selectors by default.
172  virtual bool canCreateSelector() const {return true;}
173 
174 private:
175  // Create, link, attach, position, push, and activate the PI's.
176  void createOpHandleLinks();
177 
178  // Link the parms of the op to all the parms of the PI's.
179  // This method is called from createOpHandleLinks.
180  void linkAllParms();
181 
182  // Link a given (non-input) op parm to a PI, and create the PI if it
183  // doesn't already exist. This method is called from linkNonInputParms.
184  int linkSingleParm(const PI_BindingHandleInfo &bhi,
185  const PI_BindingParmInfo &bpi,
186  OP_Operator &op_type);
187 
188  BM_OpHandleLink * createSingleOpHandleLink(
189  const PI_BindingHandleInfo &bhi);
190 
191  void clearRestartInfo();
192  void saveRestartInfo(const OP_Node &node,
193  const OP_NodeList &implicits);
194  bool restoreRestartInfo(OP_Node &node);
195 
196 protected:
197  // Delete all the PI's. This method ensures that all interests in the
198  // PI's are removed and they are all deactivated.
199  void deleteOpHandleLinks();
200 
201  // data
204  OPUI_Dialog *myOpToolbox;
206 
207  // As long as this state is alive, remember what PIs are visible
209 
214 };
215 
216 #endif
virtual void stopGenerating()
Definition: BM_State.h:228
virtual int matchesNode(OP_Node &node) const =0
const char * className() const override
UT_IntArray myRestartOpInputs
OPUI_Dialog * myOpToolbox
void exit() override
UT_String myRestartInfoFile
int getToolboxCount() const override
virtual bool allowOpMaxExportToDialog() const
virtual void makePIVisible(int pi_idx, int onoff)
UT_BitArray myHandleVisibility
virtual int hasOpNode(const OP_Node &) const
virtual void removeAllDialogs()
virtual void refreshSettings(int id, const char *op_type)
#define BM_DEFAULT_CURSOR
Definition: BM_OpState.h:38
virtual void refreshBindings(int id, const char *op_type)
GLdouble n
Definition: glcorearb.h:2008
const UT_String & getName() const
Return the name passed in the constructor.
Definition: AP_Interface.h:65
UT_SymbolMap< int > myHandleTable
OP_Node * savedNode() const
#define BM_API
Definition: BM_API.h:10
int enter(BM_SimpleState::BM_EntryType how) override
void savedNode(OP_Node *n)
virtual void handleDialogDeleted(OPUI_Dialog *deleted_dialog)
virtual bool canCreateSelector() const
UT_StringArray myRestartOpIndirectInputs
virtual void restart()
GLuint index
Definition: glcorearb.h:786
virtual void handleOpNetClear()
Definition: core.h:982
virtual int handleNodeDeleted(OP_Node &)
virtual const char * getCreateNodeName() const
virtual int generate(BM_SimpleState::BM_EntryType how, const GenerateParms &parms)
UI_Feel * getToolbox(int index) const override