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