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  void copyFrom(OP_Input* other);
94 
95  void getId(int &id);
96  void setId(int id);
98  { return myId; }
99 
100  void clearIndirectInput();
101 
102  bool getPicked() const;
103  bool getOnPickedPath(bool through_pinned_dots = true) const;
104  int setPicked(bool picked,
105  bool send_change_event = true,
106  bool save_undo = true);
107 
108 private:
109  // Wire the input
110  void setInput(OP_Node *node, unsigned outputIdx);
111  void setNamedInput(OP_Node *node,
112  const OP_ConnectorId* output_name);
113  void setInputReference(const char *label,
114  unsigned outputIdx);
115  void setNamedInputReference(const char *label,
116  const OP_ConnectorId* output_name);
117 
118  // Take care of the input's forward link when attaching inputs
119  void setMyNode(OP_Node *input_node, unsigned outputIdx);
120  void setMyNodeNamed(OP_Node *input_node,
121  const OP_ConnectorId* outputName,
122  bool allow_soft_fail = false);
123 
124  void resolveLegacyOutputIndex(OP_Node* using_node);
125 
126  void setIndirectInput(OP_IndirectInput *input);
127 
128  // Utility functions used by getOnPickedPath.
129  bool inputPathPicked(bool through_pinned_dots) const;
130  bool outputPathPicked(bool through_pinned_dots) const;
131 
132  // User-specifiable names that can be set on a per-input basis.
133  void getUserEditableDataKeys(UT_StringArray &keys) const;
134  const UT_OptionEntry *getUserEditableData(const UT_StringRef &key) const;
135  void setUserEditableData(const UT_StringHolder &key,
137  void setUserEditableDataDefault(const UT_Options &options);
138  bool saveUserEditableData(UT_JSONWriter &w) const;
139  bool loadUserEditableData(UT_JSONParser &p);
140 
141  // Only we are allowed to call our assignment operator.
142  OP_Input &operator=(const OP_Input &other) = default;
143 
144  OP_NetworkBoxItem *myOwner;
145  OP_Node *myNode;
146  int myUnresolvedLegacyOutputIndex;
147  OP_ConnectorId myNodeOutputName;
148 
149  OP_IndirectInput *myIndirectInput;
150  UT_String myNodeReference;
151  UT_Options *myUserEditableData;
152 
153  OP_ConnectorId myId;
154 
155  // Temporary, for transition purposes only. OP_Node::getOutputFromName() is
156  // currently very slow for nodes with, say, 2048 outputs. So we cache this
157  // for now, but we should really get rid of indices altogether.
158  int myCachedNodeOutputIdx;
159 
160  // Flag indicating we are in the middle of resolving our reference.
161  bool myResolvingReference;
162  // Flag indicating this is an indirect input.
163  bool myIndirectFlag;
164  // Controls the visibility of this input (in VOPs only).
165  bool myVisibleFlag;
166  // Holds whether or not this connection is selected.
167  bool myPicked;
168 
169  friend class OP_Node;
170  friend class OP_Dot;
171 };
172 
173 #endif
174 
OP_NetworkBoxItem * getOwnerItem() const
Definition: OP_Input.h:49
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
GLenum GLenum GLenum input
Definition: glew.h:14162
bool isConnected() const
Definition: OP_Input.h:72
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:88
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
OP_ConnectorId getId() const
Definition: OP_Input.h:97
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
long long int64
Definition: SYS_Types.h:116
GLfloat GLfloat p
Definition: glew.h:16656
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
GLsizei const GLfloat * value
Definition: glcorearb.h:823
bool isIndirect() const
Definition: OP_Input.h:75
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
void setIsVisible(bool value)
Definition: OP_Input.h:86