HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_NetworkBoxItem.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_NetworkBoxItem.h (OP Library, C++)
7  *
8  * COMMENTS: The base class for anything which can go into a OP_NetworkBox.
9  * The only requirements for these classes are that they have an
10  * absolute X and Y position.
11  */
12 
13 #ifndef __OP_NetworkBoxItem__
14 #define __OP_NetworkBoxItem__
15 
16 #include "OP_API.h"
17 #include "OP_ItemId.h"
18 #include "OP_DataTypes.h"
19 #include <UT/UT_Color.h>
20 #include <UT/UT_NonCopyable.h>
21 #include <UT/UT_Set.h>
22 #include <UT/UT_ValArray.h>
23 #include <UT/UT_WorkBuffer.h>
24 #include <SYS/SYS_Types.h>
25 
26 #define OP_NO_OWNER_NETWORK_BOX "__NO_OWNER_NETWORK_BOX__"
27 #define OP_PATH_HAS_NETPATH (true)
28 #define OP_PATH_HAS_NO_NETPATH (false)
29 #define OP_PATH_HAS_PACKETEXT (true)
30 #define OP_PATH_HAS_NO_PACKETEXT (false)
31 
32 class OP_Network;
33 class OP_NetworkBox;
34 class OP_NetworkBoxItem;
35 class OP_Node;
36 class UT_String;
37 
39 
41 {
42 public:
44  virtual ~OP_NetworkBoxItem();
45 
46  /// Get and set the position of this item. Units are absolute, as opposed
47  /// to relative units found in OPUI.
48  virtual void setXY(fpreal x, fpreal y) = 0;
49  virtual fpreal getX() const = 0;
50  virtual fpreal getY() const = 0;
51  virtual fpreal getW() const = 0;
52  virtual fpreal getH() const = 0;
53 
54  /// Set the node's location with setXY(), but first check if the new
55  /// position is valid. Also update any netboxes containing this node
56  /// and send an OP_UI_MOVED event.
57  bool setXYWithBoundsChecks(fpreal x, fpreal y);
58  void validateSafeBounds(fpreal &x, fpreal &y);
59  void validateSafeBounds(fpreal &x, fpreal &y,
60  fpreal &w, fpreal &h);
61 
62  /// The following methods return the safe extents of the position of items.
63  static fpreal getMaxSafeX() { return 1e6; }
64  static fpreal getMinSafeX() { return -1e6; }
65  static fpreal getMaxSafeY() { return 1e6; }
66  static fpreal getMinSafeY() { return -1e6; }
67 
68  /// Set the node's location to a "good" position, using either the input
69  /// or output nodes as the basis for the decision of what "good" means.
70  /// The keepcentered flag tells us to move every item in our parent
71  /// network _except_ us. The moveconnected flag causes this function to
72  /// move items connected to the other side of this item to avoid overlaps
73  /// when we move this item.
74  void moveToGoodPosition(bool relativetoinputs = true,
75  bool moveinputs = true,
76  bool moveoutputs = true,
77  bool moveunconnected = true);
78 
79  /// The owner box of an OP_NetworkBoxItem is the OP_NetworkBox which
80  /// it's held in.
81  /// If a box has no owner, its owner box will be returned as NULL.
82  /// Owner box is NULL by default on construction.
83  void setOwnerBox(OP_NetworkBox *box);
84  OP_NetworkBox *getOwnerBox() const;
85  bool hasOwnerBox(const OP_NetworkBoxItem *item) const;
86 
87  /// Returns the highest level owner box that is minimized. In other words,
88  /// the netbox that contains this item that is visible in a network editor.
89  OP_NetworkBox *getMinimizedOwnerBox() const;
90 
91  virtual bool setPicked(bool on_off,
92  bool propagate_parent_event = true) = 0;
93  virtual bool getPicked() const = 0;
94 
95  ///Returns the network that is our parent
96  virtual OP_Network *getParentNetwork() const = 0;
97 
98  /// Sets 'str' to be the path from 'parent' to this item. Pass in NULL for
99  /// 'parent' if you'd like the full path returned.
101  const OP_Node *parent) const
102  {
103  UT_WorkBuffer tmp;
104  getPathFromParent(tmp, parent);
105  tmp.copyIntoString(str);
106  }
107  void getPathFromParent(UT_WorkBuffer &str,
108  const OP_Node *parent) const;
109  /// Returns the path of this item relative to 'base_item'
110  void getRelativePathTo(const OP_NetworkBoxItem *base_item,
111  UT_String &result) const;
112 
113  /// Accessors for color used in the network view.
114  virtual UT_Color getColor() const
115  { return myColor; }
116  virtual bool setColor(const UT_Color &color);
117 
118  /// Our children should implement this and return what type of item they are
119  virtual OP_ItemType getItemType() const = 0;
120 
121  /// Basically the same as OP_Node::getName(), but abstracted to a higher
122  /// level so we can call it on all items.
123  virtual const UT_String &getItemName() const = 0;
124  virtual bool setItemName(const UT_String &name) = 0;
125 
126  /// Functions to get hip-file-unique ids for any item type.
127  virtual int64 getItemUniqueId() const = 0;
128  static OP_NetworkBoxItem *lookupItem(const OP_ItemType &type, int64 id);
129  static OP_NetworkBoxItem *lookupItem(const OP_ItemId &id);
130 
131  /// Basically the same as OP_Node::getExpose(), but abstracted to a higher
132  /// level so we can call it on all items.
133  virtual bool getItemExpose() const
134  { return true; }
135  virtual void setItemExpose(bool expose)
136  { }
137 
138  /// getCreator is similar to getParentNetwork but it climbs the tree to
139  /// find the network that originally created this network type. This
140  /// means that if you're down in a sub-network you climb right up to the
141  /// parent of all the sub-nets. For SOPs this will return the object,
142  /// for COPs the icenet, for TOPs the Shader, for CHOPs the chopnet,
143  /// for POPs the popnet. If the parent tree is truncated for some reason,
144  /// we return whatever node is at the top.
145  OP_Network *getCreator() const;
146 
147  /// Get the first parent node which has a VOP_CodeGenerator (i.e. has
148  /// getVopCodeGenerator() defined.
149  OP_Network *getCodeCreator() const;
150 
151  /// Fills an array with all network box items connected to this item.
152  void getConnectedItems(
153  OP_NetworkBoxItemList &connected,
154  bool inputs, bool recursive,
155  bool include_this_item) const;
156 
157  /// Returns the amount of memory owned by this OP_NetworkBoxItem
158  /// (JUST this class; not subclasses)
159  int64 getMemoryUsage(bool inclusive) const
160  {
161  int64 mem = inclusive ? sizeof(*this) : 0;
162  return mem;
163  }
164 
165 protected:
166  /// Allow subclasses direct access to myColor to allow them to edit this
167  /// color without risk of generating undo blocks or change events.
169 
170 private:
171  class ItemCycle;
172 
173  /// Returns all the node and indirect input items contained by this
174  /// network box, and any network boxes contained by this network box.
175  void getContainedItems(OP_NetworkBoxItemList &items) const;
176 
177  /// Fills an array with all network box items connected to this item.
178  /// Deals with network boxes in a way that prevents issues of items
179  /// being double-moved.
180  void getConnectedItemsForMove(
181  OP_NetworkBoxItemList &items,
182  bool inputs, bool recursive) const;
183 
184  /// Helper functions for the above two functions.
185  static void addItemToTable(const OP_NetworkBoxItem *item,
187  OP_NetworkBoxItemList *connectedlist,
188  bool inputs, bool recursive,
189  ItemCycle &cycle);
190  static void getConnectedItems(const OP_NetworkBoxItem *item,
192  OP_NetworkBoxItemList *connectedlist,
193  bool inputs, bool recursive,
194  ItemCycle &cycle);
195  static void getContainedItems(const OP_NetworkBox *box,
196  OP_NetworkBoxItemList &items);
197 
198  OP_NetworkBox *myOwnerBox;
199 };
200 
201 #endif
202 
Definition: UT_Set.h:58
int64 getMemoryUsage(bool inclusive) const
GLint y
Definition: glcorearb.h:103
void copyIntoString(UT_String &str) const
**But if you need a result
Definition: thread.h:613
UT_Set< const OP_NetworkBoxItem * > OP_EnclosedItems
OP_ItemType
Definition: OP_ItemId.h:28
void getPathFromParent(UT_String &str, const OP_Node *parent) const
long long int64
Definition: SYS_Types.h:116
static fpreal getMaxSafeY()
static fpreal getMaxSafeX()
The following methods return the safe extents of the position of items.
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void setItemExpose(bool expose)
GLint GLenum GLint x
Definition: glcorearb.h:409
virtual bool getItemExpose() const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GLuint color
Definition: glcorearb.h:1261
fpreal64 fpreal
Definition: SYS_Types.h:277
static fpreal getMinSafeY()
#define OP_API
Definition: OP_API.h:10
virtual UT_Color getColor() const
Accessors for color used in the network view.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
type
Definition: core.h:1059
static fpreal getMinSafeX()