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  const OP_Node *getNode() const;
46  int getNodeOutputIndex();
47 
48  // We maintain a list of output nodes so that we can do things to
49  // them, like inform them when we're being deleted.
50  unsigned getNOutputs() const
51  { return myOutputs.entries(); }
52  OP_NetworkBoxItem *getOutput(unsigned idx) const
53  { return (idx < getNOutputs()) ? myOutputs(idx) : 0; }
54  void clearOutputs(bool for_delete = false);
55 
56  // Get all nodes connected to this indirect input. if an output is another
57  // indirect input, follow its outputs recursively to find more nodes.
58  void getOutputNodes(UT_Array<OP_Node*> &nodes,
59  bool into_subnets = false) const;
60  // Similar to the above function, but instead of collecting all nodes
61  // into an array, call a function with each node. The "into_subnets"
62  // mode is also not supported. Returns true if any invocation of the
63  // callback ever returns true (which causes an early exit of the whole
64  // traversal).
65  bool traverseOutputNodes(hboost::function
66  <bool (const OP_Node &)> cb) const;
67  // Does a depth first search looking for the first node connected to
68  // this indirect input.
69  OP_Node *getFirstOutputNode() const;
70 
71  //Return the network this item resides in (i.e. getOwner())
72  OP_Network *getParentNetwork() const override;
73  OP_Network *getOwner() const;
74 
75  bool setPicked(bool on_off,
76  bool propagate_parent_event = true) override;
77  bool getPicked() const override;
78 
79  // Position is used by the UI.
80  void setXY(fpreal x, fpreal y) override;
81  fpreal getX() const override
82  { return myPosX; }
83  fpreal getY() const override
84  { return myPosY; }
85 
86  // Flag to indicate that the color for this item should be fetched from
87  // the first output. The set function returns true if the value changed.
88  bool setColor(const UT_Color &color) override;
89  bool setUseColorFromOutput(bool use_output_color);
90  bool getUseColorFromOutput() const;
91  bool setSymbolicColorName(const UT_StringHolder &name);
92  const UT_StringHolder &getSymbolicColorName() const;
93 
94  // The default color for indirect inputs.
95  static UT_Color getDefaultColor();
96 
97  // Return the amount of memory owned by this OP_IndirectInput
98  int64 getMemoryUsage(bool inclusive) const
99  {
100  int64 mem = inclusive ? sizeof(*this) : 0;
101  mem += OP_NetworkBoxItem::getMemoryUsage(false);
102  mem += myOutputs.getMemoryUsage(false);
103  mem += mySymbolicColorName.getMemoryUsage(false);
104  return mem;
105  }
106 
107 protected:
108  // Functions for saving and loading.
109  void initFromIndirect(const OP_IndirectInput &src);
110  void initFromFile(const UT_StringHolder &clrstr,
111  const UT_StringHolder &netboxname,
112  fpreal x,
113  fpreal y);
114  void saveColorString(std::ostream &os) const;
115 
116  // Send change notifications to our outputs.
117  void propagateModification(OP_Node *by_whom,
118  OP_EventType reason,
119  int parm_index,
120  OP_PropagateData &prop_data);
121 
122 private:
123  void addOutput(OP_NetworkBoxItem *item);
124  void delOutput(OP_NetworkBoxItem *item);
125 
126  OP_Network &myOwner;
127  UT_StringHolder mySymbolicColorName;
128  OP_NetworkBoxItemList myOutputs;
129  fpreal myPosX;
130  fpreal myPosY;
131  bool myPicked;
132  bool myUseColorFromOutput;
133 
134  friend class OP_Input;
135  friend class OP_Network;
136 };
137 
138 #endif
virtual bool setColor(const UT_Color &color)
int64 getMemoryUsage(bool inclusive) const
int64 getMemoryUsage(bool inclusive) const
virtual void setXY(fpreal x, fpreal y)=0
fpreal getY() const override
GLint y
Definition: glcorearb.h:103
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
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
GLint GLenum GLint x
Definition: glcorearb.h:409
unsigned getNOutputs() const
GLuint color
Definition: glcorearb.h:1261
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
GLenum src
Definition: glcorearb.h:1793