HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_Input.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: OP_Input.h (C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef _OP_Input_h_
13 #define _OP_Input_h_
14 
15 #include "OP_API.h"
16 #include "OP_ConnectorId.h"
17 #include "OP_DataTypes.h"
18 #include <UT/UT_Array.h>
19 #include <UT/UT_Optional.h>
20 #include <UT/UT_OptionEntry.h>
21 #include <UT/UT_String.h>
22 #include <UT/UT_StringHolder.h>
23 #include <iosfwd>
24 #include <string>
25 
26 class OP_Node;
27 class OP_Network;
28 class OP_IndirectInput;
29 class OP_NetworkBoxItem;
30 class UT_JSONParser;
31 class UT_JSONWriter;
32 class UT_Options;
33 
34 #ifdef UT_DEBUG
35 //#define OP_DEBUG_TRACE_NAME_RESOLUTION
36 //#define OP_DEBUG_CHECK_INPUT_CONSISTENCY
37 #endif
38 
40 {
41 public:
43  ~OP_Input();
44 
45  int save(std::ostream &os, int bin,
46  const char* input_name);
47  bool load(UT_IStream &is, const char *path,
48  std::string *input_name_out);
49 
50  // Returns the node that we are an input to.
52  { return myOwner; }
53 
54  // Convert our input string to an actual pointer again
55  void resolveReference();
56  const char *getNodeReference() const
57  { return myNodeReference.isstring()
58  ? myNodeReference.buffer() : ""; }
59 
60  // Get the Node that this input refers to. May return NULL
61  OP_Node *getNode();
62  OP_OutputIdx getNodeOutputIndex();
63  OP_ConnectorId getNodeOutputName();
64 
65  // Dirty the cached output index of the input node.
66  void dirtyCachedOutputIndex();
67 
68  // Check if there is a Node at the other end of the connection.
69  // Indirect inputs don't count unless they are actually connected
70  // to a node.
71  bool isConnectedToNode() const;
72  // Check if either a node or indirect input (with or without a node
73  // connected indirectly) is connected.
74  bool isConnected() const
75  { return isIndirect() || isConnectedToNode(); }
76 
77  bool isIndirect() const
78  { return myIndirectFlag; }
79  OP_IndirectInput *getIndirect();
80 
81  // Returns the subnet indirect input if there is one, otherwise return
82  // the input node.
83  OP_NetworkBoxItem *getInputItem();
84  OP_OutputIdx getInputItemOutputIndex();
85 
86  int64 getMemoryUsage(bool inclusive) const;
87 
88  void setIsVisible(bool value)
89  { myVisibleFlag = value; }
90  bool getIsVisible() const
91  { return myVisibleFlag; }
92 
93  // Use this instead of the assignment operator, which is private (and
94  // should not even be called by friend classes).
95  // Similar to an assignment, but steals the connection to the output.
96  void moveFrom(OP_Input* other);
97 
98  void getId(int &id);
99  void setId(int id);
101  { return myId; }
102 
103  void clearIndirectInput();
104 
105  bool getPicked() const;
106  bool getOnPickedPath(bool through_pinned_dots = true) const;
107  int setPicked(bool picked,
108  bool send_change_event = true,
109  bool save_undo = true);
110  // Wire the input
111  void setInput(OP_Node *node, OP_OutputIdx outputIdx);
112 
113 private:
114  void setNamedInput(OP_Node *node,
115  const OP_ConnectorId* output_name);
116  void setInputReference(const char *label,
117  OP_OutputIdx outputIdx);
118  void setNamedInputReference(const char *label,
119  const OP_ConnectorId* output_name);
120 
121  // Take care of the input's forward link when attaching inputs
122  void setMyNode(OP_Node *input_node, OP_OutputIdx outputIdx);
123  void setMyNodeNamed(OP_Node *input_node,
124  const OP_ConnectorId* outputName,
125  bool allow_soft_fail = false);
126 
127  void resolveLegacyOutputIndex(OP_Node* using_node);
128 
129  void setIndirectInput(OP_IndirectInput *input);
130 
131  // Utility functions used by getOnPickedPath.
132  bool inputPathPicked(bool through_pinned_dots) const;
133  bool outputPathPicked(bool through_pinned_dots) const;
134 
135  // User-specifiable names that can be set on a per-input basis.
136  void getUserEditableDataKeys(UT_StringArray &keys) const;
137  const UT_OptionEntry *getUserEditableData(const UT_StringRef &key) const;
138  void setUserEditableData(const UT_StringHolder &key,
140  void setUserEditableDataDefault(const UT_Options &options);
141  bool saveUserEditableData(UT_JSONWriter &w) const;
142  bool loadUserEditableData(UT_JSONParser &p);
143 
144  // Only we are allowed to call our assignment operator.
145  OP_Input &operator=(const OP_Input &other) = default;
146 
147  OP_NetworkBoxItem *myOwner;
148  OP_Node *myNode;
149  UT_Optional<OP_OutputIdx> myUnresolvedLegacyOutputIndex;
150  OP_ConnectorId myNodeOutputName;
151 
152  OP_IndirectInput *myIndirectInput;
153  UT_String myNodeReference;
154  UT_Options *myUserEditableData;
155 
156  OP_ConnectorId myId;
157 
158  // Temporary, for transition purposes only. OP_Node::getOutputFromName() is
159  // currently very slow for nodes with, say, 2048 outputs. So we cache this
160  // for now, but we should really get rid of indices altogether.
161  UT_Optional<OP_OutputIdx> myCachedNodeOutputIdx;
162 
163  // Flag indicating we are in the middle of resolving our reference.
164  bool myResolvingReference;
165  // Flag indicating this is an indirect input.
166  bool myIndirectFlag;
167  // Controls the visibility of this input (in VOPs only).
168  bool myVisibleFlag;
169  // Holds whether or not this connection is selected.
170  bool myPicked;
171 
172  friend class OP_Node;
173  friend class OP_Dot;
174 };
175 
176 #endif
177 
OP_NetworkBoxItem * getOwnerItem() const
Definition: OP_Input.h:51
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
bool isConnected() const
Definition: OP_Input.h:74
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
OP_ConnectorId getId() const
Definition: OP_Input.h:100
long long int64
Definition: SYS_Types.h:116
bool getIsVisible() const
Definition: OP_Input.h:90
Definition: OP_Dot.h:24
const char * getNodeReference() const
Definition: OP_Input.h:56
A map of string to various well defined value types.
Definition: UT_Options.h:84
LeafData & operator=(const LeafData &)=delete
#define OP_API
Definition: OP_API.h:10
int OP_OutputIdx
Definition: OP_DataTypes.h:185
bool isIndirect() const
Definition: OP_Input.h:77
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
void setIsVisible(bool value)
Definition: OP_Input.h:88