HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_IndirectInput.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_IndirectInput.h (C++)
7  *
8  * COMMENTS: OP_IndirectInput is used to represent a potential link into
9  * one or more node. It esseitnally allows an output connection to be
10  * forwarded to an input connection, which the input or output side
11  * may not exist.
12  */
13 
14 #ifndef _OP_IndirectInput_h_
15 #define _OP_IndirectInput_h_
16 
17 #include "OP_API.h"
18 #include "OP_Value.h"
19 #include "OP_NetworkBoxItem.h"
20 #include <UT/UT_Array.h>
21 #include <UT/UT_Color.h>
22 #include <UT/UT_StringHolder.h>
23 #include <SYS/SYS_Types.h>
24 #include <hboost/function.hpp>
25 #include <iosfwd>
26 
27 class OP_Node;
28 class OP_Network;
29 class OP_PropagateData;
30 
32 {
33 public:
35  ~OP_IndirectInput() override;
36 
37  // Get the item attached directly to this indirect input. May be a node,
38  // or another indirect input.
39  virtual OP_NetworkBoxItem *getInputItem() const = 0;
40  virtual int getInputItemOutputIndex() const = 0;
41 
42  // Get the Node that this input refers to. May return NULL
43  // Follows non-node inputs recursively to find a node.
44  OP_Node *getNode();
45  int getNodeOutputIndex();
46 
47  // We maintain a list of output nodes so that we can do things to
48  // them, like inform them when we're being deleted.
49  unsigned getNOutputs() const
50  { return myOutputs.entries(); }
51  OP_NetworkBoxItem *getOutput(unsigned idx) const
52  { return (idx < getNOutputs()) ? myOutputs(idx) : 0; }
53  void clearOutputs(bool for_delete = false);
54 
55  // Get all nodes connected to this indirect input. if an output is another
56  // indirect input, follow its outputs recursively to find more nodes.
57  void getOutputNodes(UT_Array<OP_Node*> &nodes,
58  bool into_subnets = false) const;
59  // Similar to the above function, but instead of collecting all nodes
60  // into an array, call a function with each node. The "into_subnets"
61  // mode is also not supported. Returns true if any invocation of the
62  // callback ever returns true (which causes an early exit of the whole
63  // traversal).
64  bool traverseOutputNodes(hboost::function
65  <bool (const OP_Node &)> cb) const;
66  // Does a depth first search looking for the first node connected to
67  // this indirect input.
68  OP_Node *getFirstOutputNode() const;
69 
70  //Return the network this item resides in (i.e. getOwner())
71  OP_Network *getParentNetwork() const override;
72  OP_Network *getOwner() const;
73 
74  bool setPicked(bool on_off,
75  bool propagate_parent_event = true) override;
76  bool getPicked() const override;
77 
78  // Position is used by the UI.
79  void setXY(fpreal x, fpreal y) override;
80  fpreal getX() const override
81  { return myPosX; }
82  fpreal getY() const override
83  { return myPosY; }
84 
85  // Flag to indicate that the color for this item should be fetched from
86  // the first output. The set function returns true if the value changed.
87  bool setColor(const UT_Color &color) override;
88  bool setUseColorFromOutput(bool use_output_color);
89  bool getUseColorFromOutput() const;
90  bool setSymbolicColorName(const UT_StringHolder &name);
91  const UT_StringHolder &getSymbolicColorName() const;
92 
93  // The default color for indirect inputs.
94  static UT_Color getDefaultColor();
95 
96  // Return the amount of memory owned by this OP_IndirectInput
97  int64 getMemoryUsage(bool inclusive) const
98  {
99  int64 mem = inclusive ? sizeof(*this) : 0;
100  mem += OP_NetworkBoxItem::getMemoryUsage(false);
101  mem += myOutputs.getMemoryUsage(false);
102  mem += mySymbolicColorName.getMemoryUsage(false);
103  return mem;
104  }
105 
106 protected:
107  // Functions for saving and loading.
108  void initFromIndirect(const OP_IndirectInput &src);
109  void initFromFile(const UT_StringHolder &clrstr,
110  const UT_StringHolder &netboxname,
111  fpreal x,
112  fpreal y);
113  void saveColorString(std::ostream &os) const;
114 
115  // Send change notifications to our outputs.
116  void propagateModification(OP_Node *by_whom,
117  OP_EventType reason,
118  int parm_index,
119  OP_PropagateData &prop_data);
120 
121 private:
122  void addOutput(OP_NetworkBoxItem *item);
123  void delOutput(OP_NetworkBoxItem *item);
124 
125  OP_Network &myOwner;
126  UT_StringHolder mySymbolicColorName;
127  OP_NetworkBoxItemList myOutputs;
128  fpreal myPosX;
129  fpreal myPosY;
130  bool myPicked;
131  bool myUseColorFromOutput;
132 
133  friend class OP_Input;
134  friend class OP_Network;
135 };
136 
137 #endif
virtual bool setColor(const UT_Color &color)
GLenum src
Definition: glew.h:2410
GLuint const GLchar * name
Definition: glew.h:1814
int64 getMemoryUsage(bool inclusive) const
int64 getMemoryUsage(bool inclusive) const
virtual void setXY(fpreal x, fpreal y)=0
fpreal getY() const override
virtual OP_Network * getParentNetwork() const =0
Returns the network that is our parent.
virtual bool setPicked(bool on_off, bool propagate_parent_event=true)=0
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
long long int64
Definition: SYS_Types.h:116
GLuint color
Definition: glew.h:7902
unsigned getNOutputs() const
fpreal64 fpreal
Definition: SYS_Types.h:277
OP_NetworkBoxItem * getOutput(unsigned idx) const
#define OP_API
Definition: OP_API.h:10
OP_EventType
Definition: OP_Value.h:22
virtual bool getPicked() const =0
fpreal getX() const override