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_Array.h>
18 #include <UT/UT_OptionEntry.h>
19 #include <UT/UT_String.h>
20 #include <UT/UT_StringHolder.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_Options;
31 
32 #ifdef UT_DEBUG
33 //#define OP_DEBUG_TRACE_NAME_RESOLUTION
34 //#define OP_DEBUG_CHECK_INPUT_CONSISTENCY
35 #endif
36 
38 {
39 public:
41  ~OP_Input();
42 
43  int save(std::ostream &os, int bin,
44  const char* input_name);
45  bool load(UT_IStream &is, const char *path,
46  std::string *input_name_out);
47 
48  // Returns the node that we are an input to.
50  { return myOwner; }
51 
52  // Convert our input string to an actual pointer again
53  void resolveReference();
54  const char *getNodeReference() const
55  { return myNodeReference.isstring()
56  ? myNodeReference.buffer() : ""; }
57 
58  // Get the Node that this input refers to. May return NULL
59  OP_Node *getNode();
60  unsigned getNodeOutputIndex();
61  OP_ConnectorId getNodeOutputName();
62 
63  // Dirty the cached output index of the input node.
64  void dirtyCachedOutputIndex();
65 
66  // Check if there is a Node at the other end of the connection.
67  // Indirect inputs don't count unless they are actually connected
68  // to a node.
69  bool isConnectedToNode() const;
70  // Check if either a node or indirect input (with or without a node
71  // connected indirectly) is connected.
72  bool isConnected() const
73  { return isIndirect() || isConnectedToNode(); }
74 
75  bool isIndirect() const
76  { return myIndirectFlag; }
77  OP_IndirectInput *getIndirect();
78 
79  // Returns the subnet indirect input if there is one, otherwise return
80  // the input node.
81  OP_NetworkBoxItem *getInputItem();
82  unsigned getInputItemOutputIndex();
83 
84  int64 getMemoryUsage(bool inclusive) const;
85 
86  void setIsVisible(bool value)
87  { myVisibleFlag = value; }
88  bool getIsVisible() const
89  { return myVisibleFlag; }
90 
91  // Use this instead of the assignment operator, which is private (and
92  // should not even be called by friend classes).
93  // Similar to an assignment, but steals the connection to the output.
94  void moveFrom(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:49
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
bool isConnected() const
Definition: OP_Input.h:72
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
OP_ConnectorId getId() const
Definition: OP_Input.h:98
long long int64
Definition: SYS_Types.h:116
bool getIsVisible() const
Definition: OP_Input.h:88
Definition: OP_Dot.h:24
const char * getNodeReference() const
Definition: OP_Input.h:54
A map of string to various well defined value types.
Definition: UT_Options.h:84
#define OP_API
Definition: OP_API.h:10
bool isIndirect() const
Definition: OP_Input.h:75
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
Definition: core.h:1131
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
void setIsVisible(bool value)
Definition: OP_Input.h:86