HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UNI_Graph.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: UNI_Graph.h ( UNI Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UNI_Graph_h__
13 #define __UNI_Graph_h__
14 
15 #include "UNI_API.h"
16 #include "UNI_Include.h"
17 #include <UT/UT_Array.h>
18 #include <UT/UT_Color.h>
19 #include <UT/UT_Function.h>
20 #include <UT/UT_IntrusivePtr.h>
21 #include <UT/UT_NonCopyable.h>
22 #include <UT/UT_Map.h>
23 #include <UT/UT_Ramp.h>
24 #include <UT/UT_StringArray.h>
25 #include <UT/UT_StringHolder.h>
26 #include <UT/UT_StringMap.h>
27 #include <UT/UT_OptionEntry.h>
28 #include <UT/UT_UniquePtr.h>
29 #include <UT/UT_Vector2.h>
30 #include <iostream>
31 
32 class UNI_Graph;
33 class UNI_GraphHandle;
34 
36 {
37  INPUTS,
38  OUTPUTS
39 };
40 
41 using UNI_SelectableItemID = std::variant<UNI_NodeID,
42  UNI_WireID,
43  UNI_StickyNoteID,
45 
46 // ============================================================================
47 /// Different types of changes that can be generated by a session graph.
48 /// This is a bit field
50 {
51 public:
53  : myValue(value)
54  {}
55 
57  { return UNI_GraphChangeType(myValue | other.myValue); }
59  { return UNI_GraphChangeType(myValue & other.myValue); }
60  bool operator==(int value) const
61  { return (myValue == value); }
62  bool operator!=(int value) const
63  { return (myValue != value); }
64 
65  bool isSet() const
66  { return myValue != NONE; }
67  bool isSet(exint value) const
68  { return ((myValue & value) != 0); }
69 
70  // Nothing changed - callbacks will not be invoked:
71  static constexpr exint NONE = 0;
72  // Something not covered by any other change type:
73  static constexpr exint GENERIC = (1 << 0);
74  // The topology of the graph was changed (eg, added new nodes,
75  // new connection wires to ports, or deleted old nodes/wires, etc.):
76  static constexpr exint TOPOLOGY = (1 << 1);
77  // The name of a node has changed:
78  static constexpr exint NAME = (1 << 2);
79  // The signature of a node has changed:
80  static constexpr exint SIGNATURE = (1 << 3);
81  // A parameter on the graph or a node changed:
82  static constexpr exint PARAMETER = (1 << 4);
83  // Changed node selection or current node:
84  static constexpr exint SELECTION = (1 << 5);
85  // The graph is about to be deleted (deleting a
86  // Node in the graph is a TOPOLOGY change):
87  static constexpr exint DELETED = (1 << 6);
88  // An aspect of the graph's UI changed (eg, wire drawing style):
89  static constexpr exint UI = (1 << 7);
90 
91  // NB: When adding new event types, you must also update UTformatBuffer().
92 
93 private:
94  /// Internal numeric representation of the graph change type.
95  int myValue;
96 };
97 
98 size_t UNI_API
99 UTformatBuffer(char *buffer, size_t buffer_size, const UNI_GraphChangeType &t);
100 
101 // ============================================================================
102 /// Intrusive pointer definition.
105 /// Special parm value type indicating an invalid/unset value type.
107 /// Special parm value type indicating the parm should be returned to its
108 /// default value.
110 /// Simple data type that allows passing a ramp along with a specification of
111 /// whether it is a color ramp or float ramp.
112 using UNI_RampParmValue = std::pair<bool, UT_Ramp>;
113 /// Variant data type that holds all the parm value types allowed in UNI parms.
114 using UNI_ParmValue = std::variant<
117  bool,
118  int64,
119  fpreal64,
120  UT_Vector2D,
121  UT_Vector3D,
122  UT_Vector4D,
123  UT_Matrix3D,
124  UT_Matrix4D,
127 
128 // ============================================================================
129 /// Removes the graph from the lookup table and deletes it.
131 {
132  /// Destroys the UNI graph removing it from the Houdini session.
133  void operator()(UNI_Graph* graph);
134 };
135 
136 // ============================================================================
137 /// A class that represents a UNI graph within the GUI layer, used by
138 /// node network editor classes (FUSE/OPUI/HOMF) to implement user interactions.
139 /// UNI graphs are available globally in a Houdini session, using graph ID
140 /// and static method UNI_Graph::findGraph() in this class.
142  : public UT_IntrusiveRefCounter<UNI_Graph, UNI_GraphDeleter>
143 {
144 protected:
145  /// Constructor.
146  /// Intended to be used by only the (static) factory functions
147  /// in the sub-classes, which create UNI_Graph instances.
148  /// The constructor assigns a unique session ID to the graph and registers
149  /// it in the internal look-up table; the destructor removes it from there.
150  /// Subclass factory functions wrap the created graph in a UNI_GraphHandle,
151  /// which takes ownership of it.
152  UNI_Graph();
153 
154 private:
155  /// The graph deleter is a friend so that, when the last handle referencing
156  /// the graph is released, it can send out the "deleted" change
157  /// notification and then destroy the graph (whose destructor removes it
158  /// from the look-up table).
159  friend UNI_GraphDeleter;
160 
161 public:
162  /// Returns a UNI graph given its ID. Returns a null if not found.
163  static UNI_Graph * findGraph( UNI_GraphID id );
164 
165  /// Non-copyable. An internal map should be the sole owner of graph objects,
166  /// since we are using ID and handles to identify them and track life span.
168 
169  /// Destructor.
170  virtual ~UNI_Graph();
171 
172  /// Returns the unique ID of this graph in the current Houdini session.
173  /// Note, this ID can change from session to session, so should not be
174  /// serialized or saved for persistence outside of the session.
175  UNI_GraphID graphID() const
176  { return myGraphID; }
177 
178  /// @{ Control whether this graph is editable.
179  bool isEditable() const
180  { return myIsEditable; }
181  void setEditable(bool editable)
182  { myIsEditable = editable; }
183  /// @}
184 
185  /// Returns the name of the graph. Used for human readability and UI
186  /// presentation.
187  virtual UT_StringHolder name() const = 0;
188  /// Returns true if the graph has no nodes.
189  virtual bool isEmpty() const = 0;
190  /// Returns the ID of the root node.
191  /// Ie, the ID of the parent of the top-level nodes in the graph.
192  virtual UNI_NodeID rootNode() const = 0;
193 
194  /// @{ The drawing style of the connection wires in the graph.
195  virtual UNI_WireStyle wireStyle() const = 0;
196  virtual void setWireStyle(UNI_WireStyle wire_style) = 0;
197  /// @}
198 
199  /// @{ Returns true if the given ID refers to a valid item in this graph.
200  virtual bool isValid( UNI_NodeID node_id ) const = 0;
201  virtual bool isValid( UNI_PortID port_id ) const = 0;
202  virtual bool isValid( UNI_WireID wire_id ) const = 0;
203  virtual bool isValid( UNI_StickyNoteID note_id ) const = 0;
204  /// @}
205 
206  /// @{ Generic functions related to entity naming.
207  virtual bool isValidName(const UT_StringRef &name) const = 0;
208  virtual bool isNameInUse(UNI_NodeID parent_id,
209  const UT_StringRef &name) const = 0;
210  virtual UT_StringHolder findUniqueName(UNI_NodeID parent_id,
211  const UT_StringHolder &name) const = 0;
212  /// @}
213 
214  /// @{ APIs for getting information about a node.
215  /// Returns the parent of the given node. Ie, nodes can be nested, so
216  /// this returns the node inside which the given child node lives.
217  virtual UNI_NodeID parentNode( UNI_NodeID node_id ) const = 0;
218  /// Returns true if the given node is a subnet (can have child nodes).
219  virtual bool isSubnet( UNI_NodeID node_id ) const = 0;
220  /// Returns true if the given node can be modified (ie, is inside
221  /// an editable subnet). Ie, it can be connected to a new source,
222  /// and its parameters can be set.
223  virtual bool isEditable( UNI_NodeID node_id ) const = 0;
224  /// Returns true if the subnet inside the given parent node can be modified.
225  /// Eg, new connections can be made between children,
226  /// their parameters can be set, etc.
227  virtual bool isEditableSubnet( UNI_NodeID parent_id ) const = 0;
228  /// Returns the children nodes that live inside the given parent node.
229  virtual UNI_NodeIDList childNodes( UNI_NodeID parent_id ) const = 0;
230  /// Finds the node at the specified path relative to the given node.
231  /// If the path is an absolute path, the from_id isn't used.
232  virtual UNI_NodeID findNode( UNI_NodeID from_id,
233  const UT_StringRef &path) const = 0;
234  /// The name of a node.
235  virtual UT_StringHolder name( UNI_NodeID node_id ) const = 0;
236  /// The full path of the node.
237  virtual UT_StringHolder path( UNI_NodeID node_id ) const = 0;
238  /// The category name of the node.
239  virtual UT_StringHolder categoryName( UNI_NodeID node_id ) const = 0;
240  /// The type name of the node.
241  virtual UT_StringHolder typeName( UNI_NodeID node_id ) const = 0;
242  /// The name of the current signature of the given node.
243  virtual UT_StringHolder signatureName( UNI_NodeID node_id ) const =0;
244  /// Returns true if the node has many signatures to choose from.
245  virtual bool isMultiSignature( UNI_NodeID node_id ) const = 0;
246  /// The list of function signature names this node (or node's type) offers.
247  /// If @p compatible_only is true, the list contains signatures whose
248  /// input/output types are compatible with current wire connections
249  /// on the node; otherwise, resturns all available signatures.
250  /// If @p force_include_current is true, the list will include the
251  /// current node signature name eve if it may not be part of official list.
252  virtual UT_Array<UNI_Signature>
253  signatures( UNI_NodeID node_id,
254  bool compatible_only,
255  bool force_include_current) const = 0;
256  /// The help URL for the node.
257  /// Used for UT_HelpManager::openURL() which accepts protocols such as
258  /// "http://u.r.l", "hdox://u.r.l", "operator:category/name", etc.
259  virtual UT_StringHolder helpURL( UNI_NodeID node_id ) const = 0;
260  /// The position of the node in the graph editor.
261  virtual UT_Vector2D position( UNI_NodeID node_id ) const = 0;
262  /// The color tint of the node in the graph editor.
263  virtual UT_Color color( UNI_NodeID node_id ) const = 0;
264  /// Returns the icon name for the given node.
265  virtual UT_StringHolder iconName( UNI_NodeID node_id ) const = 0;
266  /// The user-authored comment for a node.
267  virtual UT_StringHolder comment( UNI_NodeID node_id ) const = 0;
268  /// The list of tags associated with a node.
269  virtual UT_StringArray tags( UNI_NodeID node_id ) const = 0;
270  /// The parameter descriptions for the specified node. This is used to
271  /// build a parm dialog.
272  virtual UT_StringHolder parmDialogScript( UNI_NodeID node_id ) const = 0;
273  /// Get the value of a parm on this node.
274  virtual UNI_ParmValue parmValue( UNI_NodeID node_id,
275  const UT_StringRef &parm_name ) const = 0;
276  /// Return true if there is a port corresponding to this parm, and that
277  /// port is connected, resulting in this parm having no effect.
278  virtual bool parmOverriddenByConnection( UNI_NodeID node_id,
279  const UT_StringRef &parm_name ) const = 0;
280  /// @}
281 
282  /// @{ Input ports of a node.
283  virtual int numberOfInputPorts( UNI_NodeID node_id ) const = 0;
284  virtual UNI_PortIDList inputPorts( UNI_NodeID node_id ) const = 0;
285  virtual UNI_PortID inputPort( UNI_NodeID node_id,
286  int port_index ) const = 0;
287  virtual int findInputPortIndex( UNI_NodeID node_id,
288  UNI_PortID port_id ) const = 0;
289  /// @}
290 
291  /// @{ Output ports of a node.
292  virtual int numberOfOutputPorts( UNI_NodeID node_id ) const = 0;
293  virtual UNI_PortIDList outputPorts( UNI_NodeID node_id ) const = 0;
294  virtual UNI_PortID outputPort( UNI_NodeID node_id,
295  int port_index ) const = 0;
296  virtual int findOutputPortIndex( UNI_NodeID node_id,
297  UNI_PortID port_id ) const = 0;
298  /// @}
299 
300  /// Return true if a node has a variable number of inputs or outputs.
301  /// This does not include "subports" in APEX, which are not individually
302  /// named and are not "real" ports.
303  virtual bool hasDynamicPorts( UNI_NodeID node_id ) const = 0;
304 
305  /// @{ Some graphs allow wiring directly from a container node to nodes
306  /// inside the container. In this case, wireDirectlyToContainer will return
307  /// true. The other methods here are for controlling the appearance of the
308  /// UI for making connections to the container node when inside that
309  /// container.
310  virtual bool wireDirectlyToContainer() const = 0;
311  virtual UT_Vector2D containerConnectPosition( UNI_NodeID parent_id,
312  UNI_ContainerConnectType contype ) const = 0;
313  virtual UT_Color containerConnectColor( UNI_NodeID parent_id,
314  UNI_ContainerConnectType contype ) const = 0;
315  /// @}
316 
317  /// @{ APIs for dealing with Ports.
318  /// Returns the node that owns the specified port.
319  virtual UNI_NodeID ownerNode( UNI_PortID port_id ) const = 0;
320  /// Returns what kind of a port this is: input or output.
321  virtual UNI_PortKind portKind( UNI_PortID port_id ) const = 0;
322  /// Returns whether the port accepts subports.
323  virtual bool portAcceptsSubPorts( UNI_PortID port_id ) const = 0;
324  /// Returns whether the port is a subport.
325  virtual bool portIsSubPort( UNI_PortID port_id ) const = 0;
326  /// Returns the "outer port" of a subport.
327  virtual UNI_PortID outerPort( UNI_PortID port_id ) const = 0;
328  /// Returns the port to which wires must connect in order to serve as
329  /// the src wire for a subnet's output port. Returns an empty list if
330  /// the provided port isn't an output port of a subnet node.
331  virtual UNI_PortIDList subnetOutputPorts( UNI_PortID port_id ) const = 0;
332  /// Returns the port to which wires must connect in order to act as
333  /// a dst wire from a subnet's input port. Returns an empty list if
334  /// the provided port isn't an input port of a subnet node.
335  virtual UNI_PortIDList subnetInputPorts( UNI_PortID port_id ) const = 0;
336  /// The name of the port. Some ports can be renamed.
337  virtual UT_StringHolder name( UNI_PortID port_id ) const = 0;
338  /// Some graphs support setting port names.
339  virtual bool canSetName( UNI_PortID port_id ) const = 0;
340  /// The label of the port. Some ports can be renamed.
341  virtual UT_StringHolder label( UNI_PortID port_id ) const = 0;
342  /// Returns the data type name for the given port.
343  virtual UT_StringHolder typeName( UNI_PortID port_id ) const = 0;
344  /// Returns the UI color name for the given port.
345  /// The color name should adhere to the UIgetMiscColor() conventions.
346  /// This method allows for color scheme adjustment of the actual color.
347  virtual UT_StringHolder colorName( UNI_PortID port_id ) const = 0;
348  /// Returns the visual shape of the port in the UI.
349  virtual UNI_PortShape shape( UNI_PortID port_id ) const = 0;
350  /// Returns the wires that live directly inside the given parent node.
351  virtual UNI_WireIDList childWires( UNI_NodeID parent_id ) const = 0;
352  /// @}
353 
354  /// @{ Return the wires that connect to a given port.
355  virtual UNI_WireIDList srcWires( UNI_PortID port_id ) const = 0;
356  virtual UNI_WireIDList dstWires( UNI_PortID port_id ) const = 0;
357  /// @}
358 
359  /// @{ Get the start (src) and end (dst) ports for a wire.
360  /// Note that either an input or output port may be the start or end
361  /// point of a wire. The permissibility and meaning of this will depend
362  /// on the specific graph implementation.
363  virtual UNI_PortID srcPort( UNI_WireID wire_id ) const = 0;
364  virtual UNI_PortID dstPort( UNI_WireID wire_id ) const = 0;
365  /// @}
366 
367  /// @{ APIs for dealing with Sticky Notes.
368  /// Returns the sticky notes that live inside the given parent node.
369  virtual UNI_StickyNoteIDList childStickyNotes( UNI_NodeID parent_id ) const = 0;
370  /// Find the sticky note at a path relative to a starting node.
371  virtual UNI_StickyNoteID findStickyNote( UNI_NodeID from_id,
372  const UT_StringRef &path) const = 0;
373  /// The name of a sticky note.
374  virtual UT_StringHolder name( UNI_StickyNoteID note_id ) const = 0;
375  /// The full path of the sticky note.
376  virtual UT_StringHolder path( UNI_StickyNoteID note_id ) const = 0;
377  /// Returns the id of the node that contains this sticky note.
378  virtual UNI_NodeID ownerNode( UNI_StickyNoteID note_id ) const = 0;
379  /// Returns the sticky note's contents.
380  virtual UT_StringHolder text( UNI_StickyNoteID note_id ) const = 0;
381  /// Returns the sticky note's text (foreground) color.
382  virtual UT_Color textColor( UNI_StickyNoteID note_id ) const = 0;
383  /// Returns the sticky note's text size.
384  virtual float textSize( UNI_StickyNoteID note_id ) const = 0;
385  /// Returns the sticky note's (background) color.
386  virtual UT_Color color( UNI_StickyNoteID note_id ) const = 0;
387  /// Returns the sticky note's position in the graph editor.
388  virtual UT_Vector2D position( UNI_StickyNoteID note_id ) const = 0;
389  /// Returns the sticky note's size (width & height).
390  virtual UT_Vector2D size( UNI_StickyNoteID note_id ) const = 0;
391  /// Returns true if the sticky note is collapsed (minimized).
392  virtual bool isCollapsed( UNI_StickyNoteID note_id ) const = 0;
393  /// Returns true if the background of the sticky note is not drawn,
394  /// effectively making it transparent.
395  virtual bool isBackgroundHidden( UNI_StickyNoteID note_id ) const = 0;
396  /// @}
397 
398  /// Fill the supplied output stream with data that can be used to make
399  /// copies of the specified items.
400  virtual bool copyItems(UNI_NodeID parent_id,
401  const UNI_NodeIDList &node_ids,
402  const UNI_StickyNoteIDList &note_ids,
403  std::ostream &os) const = 0;
404 
405  /// @{ Functions for tracking the current and selected nodes and wires.
406  UNI_NodeID currentChildNode( UNI_NodeID parent_id );
407  const UT_Array<UNI_SelectableItemID> &selectedItems() const;
408  template<typename T> UT_Array<T> selectedItemsOfType() const
409  {
410  UT_Array<T> items;
411  for (auto &&item : mySelectedItems)
412  if (auto *t_id = std::get_if<T>(&item))
413  items.append(*t_id);
414  return items;
415  }
416  bool isItemSelected(UNI_SelectableItemID id);
417  void addSelectedItem(UNI_SelectableItemID id);
418  void removeSelectedItem(UNI_SelectableItemID id);
419  void clearSelection();
420  /// @}
421 
422  /// Callback method signature when a session graph changes.
423  /// The third argument indicates whether it's the outermost block
424  /// of nested change blocks.
425  /// The callbacks are run on any change in the graph, whether it
426  /// occurs in outermost or inner nested scopes. It's up to the callback
427  /// to check and decide whether to handle the change immediately
428  /// or postpone it until the outmost block is done.
429  /// Each callback is invoked with the union of all change type
430  /// that occured until then, including any nested change blocks.
431  using ChangeCallback =
434 
435  /// @{ Functions for managing callbacks that are invoked when this
436  /// graph changes.
437  ChangeCallbackID addChangeCallback(const UNI_Graph::ChangeCallback &cb);
438  void removeChangeCallback(ChangeCallbackID id);
439  /// @}
440 
441  /// @{ Utility class for invoking a graph's change callbacks.
442  /// See the comment about ChangeCallback function.
444  {
445  public:
447  explicit ChangeBlock(UNI_Graph &graph,
448  UNI_GraphChangeType change_type);
449  ~ChangeBlock();
450 
451  /// Clear the graph; used only when the graph has been deleted.
452  void resetGraph()
453  { myGraph = nullptr; }
454 
455  /// Returns the graph that changed.
456  UNI_Graph *graph() const
457  { return myGraph; }
458 
459  /// Returns the types of changes that occurred in the graph.
461  { return myChangeType; }
462 
463  /// Reports a change that occurred in the graph.
465  { myChangeType = myChangeType | change_type; }
466 
467  private:
468  UNI_Graph *myGraph; // The graph that changed.
469  UNI_GraphChangeType myChangeType; // Kind of change in the graph.
470  };
471  /// @}
472 
473 protected:
474  /// All non-const methods are protected, and should only be called by
475  /// these friend classes. This ensures that the proper change notifications
476  /// are sent out without subclasses ever having to worry about them.
477  friend class UNI_Node;
478  friend class UNI_Port;
479  friend class UNI_Wire;
480  friend class UNI_StickyNote;
481 
482  /// Create a new node inside the provided node.
483  virtual UNI_NodeID
484  createNode( UNI_NodeID parent_id,
485  const UT_StringHolder &node_name,
486  const UT_StringHolder &node_type_name,
487  const UT_StringHolder &signature_name = UT_StringHolder() ) = 0;
488 
489  /// Create a subnet inside the provided node, and pre-populates it with
490  /// input and output ports that match the supplied port ids. The subnet
491  /// input and output ports will be ordered the same way they are in the
492  /// provided arrays.
493  virtual UNI_NodeID createSubnet( UNI_NodeID parent_id,
494  const UT_StringHolder &subnet_node_name,
495  const UNI_PortIDList &create_input_ports,
496  const UNI_PortIDList &create_output_ports) = 0;
497  /// Set the name of a node.
498  virtual void setName( UNI_NodeID node_id,
499  const UT_StringHolder &name ) = 0;
500  /// Sets the new signature on a node.
501  virtual void setSignature( UNI_NodeID node_id,
502  const UT_StringHolder &signature_name ) = 0;
503  /// Ensures the signatures and port types are up-to-date for
504  /// all the nodes downstream of the given node.
505  /// If @p update_node is true, the given node and its ports are updated too.
506  virtual void updateDownstreamPortTypes( UNI_NodeID node_id,
507  bool update_node ) = 0;
508  /// Ensures the node signatures and port types are up-to-date for
509  /// all the nodes downstream of the given port.
510  /// If @p update_port is true, the given port is updated too.
511  virtual void updateDownstreamPortTypes( UNI_PortID port_id,
512  bool update_port ) = 0;
513  /// Set the position of the node in the graph editor.
514  virtual void setPosition( UNI_NodeID node_id,
515  const UT_Vector2D &pos ) = 0;
516  /// Set the color tint of the node in the graph editor.
517  virtual void setColor( UNI_NodeID node_id,
518  const UT_Color &clr ) = 0;
519  /// Set the user-authored comment for a node.
520  virtual void setComment( UNI_NodeID node_id,
521  const UT_StringHolder &comment ) = 0;
522  /// Set the list of tags associated with a node.
523  virtual void setTags( UNI_NodeID node_id,
524  const UT_StringArray &tags ) = 0;
525  /// Set the value of a parm on this node.
526  virtual void setParmValue( UNI_NodeID node_id,
527  const UT_StringRef &parm_name,
528  const UNI_ParmValue &value ) = 0;
529  /// Destroy a node.
530  virtual void destroy( UNI_NodeID node_id ) = 0;
531 
532  /// Set the position of the special "connect to my container"
533  /// UI element in the graph editor.
534  virtual void setContainerConnectPosition( UNI_NodeID parent_id,
535  UNI_ContainerConnectType contype,
536  const UT_Vector2D &pos ) = 0;
537  /// Set the color of the special "connect to my container"
538  /// UI element in the graph editor.
539  virtual void setContainerConnectColor( UNI_NodeID parent_id,
540  UNI_ContainerConnectType contype,
541  const UT_Color &clr ) = 0;
542 
543  /// Set the name of the port. Some ports can be renamed.
544  virtual void setName( UNI_PortID port_id,
545  const UT_StringHolder &name ) = 0;
546  /// Connect two ports.
547  virtual UNI_WireID createWire( UNI_PortID src, UNI_PortID dst ) = 0;
548 
549  /// Disconnect two ports.
550  virtual void destroy( UNI_WireID wire_id ) = 0;
551 
552  /// Create a new sticky note inside the provided node.
553  virtual UNI_StickyNoteID createStickyNote( UNI_NodeID parent_id,
554  const UT_StringHolder &name ) = 0;
555  /// Set the name of a sticky note.
556  virtual void setName( UNI_StickyNoteID note_id,
557  const UT_StringHolder &name ) = 0;
558  /// Set the position of the sticky note in the graph editor.
559  virtual void setPosition( UNI_StickyNoteID note_id,
560  const UT_Vector2D &pos ) = 0;
561  /// Set the size of the sticky note in the graph editor.
562  virtual void setSize( UNI_StickyNoteID note_id,
563  const UT_Vector2D &size ) = 0;
564  /// Set the color of the sticky note background in the graph editor.
565  virtual void setColor( UNI_StickyNoteID note_id,
566  const UT_Color &clr ) = 0;
567  /// Set the sticky note text in the graph editor.
568  virtual void setText( UNI_StickyNoteID note_id,
569  const UT_StringHolder &text ) = 0;
570  /// Set the color of the sticky note text in the graph editor.
571  virtual void setTextColor( UNI_StickyNoteID note_id,
572  const UT_Color &clr ) = 0;
573  /// Set the size of the sticky note text in the graph editor.
574  virtual void setTextSize( UNI_StickyNoteID note_id,
575  const float size ) = 0;
576  /// Returns true if the sticky note is collapsed (minimized).
577  virtual void setCollapsed( UNI_StickyNoteID note_id,
578  bool collapsed ) = 0;
579  /// Returns true if the background of the sticky note is not drawn,
580  /// effectively making it transparent.
581  virtual void setBackgroundHidden( UNI_StickyNoteID note_id,
582  bool hidden ) = 0;
583  /// Destroy a sticky note.
584  virtual void destroy( UNI_StickyNoteID note_id ) = 0;
585 
586  /// Paste the contents of the supplied stream (generated by calling
587  /// copyItems) into the specified parent network.
588  virtual bool pasteItems(UNI_NodeID parent_id,
589  UNI_NodeIDList &node_ids,
590  UNI_StickyNoteIDList &note_ids,
591  std::istream &is,
592  UT_StringMap<UT_StringHolder> *rename_map) = 0;
593 
594  /// Force handling of any pending change callbacks. We may need to do this
595  /// in cases where the implementation of a subclass function requires an
596  /// immediate update to the data that drives the graph. One example
597  /// is HUSD_MaterialUniGraph::pasteItems.
598  void forceTriggerChangeCallbacks(
599  const UNI_GraphChangeType &
600  add_change_type = UNI_GraphChangeType());
601 
602 private:
603  /// Run all our callbacks. Should only be invoked by the
604  /// UNI_Graph::ChangeBlock destructor.
605  void runCallbacks( UNI_GraphChangeType change_type );
606 
607  /// A number uniquely identifying this UNI graph in the current session.
608  UNI_GraphID myGraphID;
609 
610  /// Bookkeeping selection state of graph items.
611  UT_Array<UNI_SelectableItemID> mySelectedItems;
612 
613  /// Keeps track of the current node in each subnet.
614  UT_Map<UNI_NodeID, UNI_NodeID> myCurrentChildNodeIDs;
615 
616  /// @{ Data for managing change callbacks.
618  UT_Array<ChangeBlock *> myChangeBlocks;
619  UNI_GraphChangeType myAccumulatedChangeType;
620  /// @}
621 
622  /// True if the graph can be edited; false for read-only graphs.
623  bool myIsEditable = true;
624 };
625 
626 
627 #endif
void setEditable(bool editable)
Control whether this graph is editable.
Definition: UNI_Graph.h:181
UT_Array< T > selectedItemsOfType() const
Functions for tracking the current and selected nodes and wires.
Definition: UNI_Graph.h:408
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
UT_Matrix4T< fpreal64 > UT_Matrix4D
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
static constexpr exint UI
Definition: UNI_Graph.h:89
UNI_InvalidParmValue
Special parm value type indicating an invalid/unset value type.
Definition: UNI_Graph.h:106
void setName(const UT_StringHolder &name)
static constexpr exint GENERIC
Definition: UNI_Graph.h:73
UT_Vector2T< fpreal64 > UT_Vector2D
static constexpr exint PARAMETER
Definition: UNI_Graph.h:82
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
bool isSet() const
Definition: UNI_Graph.h:65
int64 exint
Definition: SYS_Types.h:125
static constexpr exint DELETED
Definition: UNI_Graph.h:87
void setTextSize(const float size)
void setBackgroundHidden(bool hidden)
void setText(const UT_StringHolder &text)
UNI_GraphID graphID() const
Definition: UNI_Graph.h:175
A reference counter base class for use with UT_IntrusivePtr.
#define UNI_API
Definition: UNI_API.h:11
GLuint buffer
Definition: glcorearb.h:660
std::pair< bool, UT_Ramp > UNI_RampParmValue
Definition: UNI_Graph.h:112
OutGridT const XformOp bool bool
bool operator==(int value) const
Definition: UNI_Graph.h:60
double fpreal64
Definition: SYS_Types.h:201
bool isEditable() const
Control whether this graph is editable.
Definition: UNI_Graph.h:179
static constexpr exint NONE
Definition: UNI_Graph.h:71
UT_StringHolder text() const
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
UNI_PortKind
Specifies the port kind, ie, wheter it is an input or an output port.
Definition: UNI_Include.h:21
Wrapper around hboost::intrusive_ptr.
UNI_GraphChangeType operator&(const UNI_GraphChangeType &other)
Definition: UNI_Graph.h:58
long long int64
Definition: SYS_Types.h:116
int ChangeCallbackID
Definition: UNI_Graph.h:433
UT_Function< void(UNI_Graph &, UNI_GraphChangeType, bool)> ChangeCallback
Definition: UNI_Graph.h:432
UT_Vector3T< fpreal64 > UT_Vector3D
GLuint const GLchar * name
Definition: glcorearb.h:786
std::variant< UNI_InvalidParmValue, UNI_DefaultParmValue, bool, int64, fpreal64, UT_Vector2D, UT_Vector3D, UT_Vector4D, UT_Matrix3D, UT_Matrix4D, UT_StringHolder, UNI_RampParmValue > UNI_ParmValue
Variant data type that holds all the parm value types allowed in UNI parms.
Definition: UNI_Graph.h:126
bool isSet(exint value) const
Definition: UNI_Graph.h:67
std::function< T > UT_Function
Definition: UT_Function.h:37
static constexpr exint SELECTION
Definition: UNI_Graph.h:84
MX_CORE_API bool isValidName(const string &name)
Return true if the given string is a valid MaterialX name.
exint append()
Definition: UT_Array.h:142
GLdouble t
Definition: glad.h:2397
std::variant< UNI_NodeID, UNI_WireID, UNI_StickyNoteID, UNI_ContainerConnectType > UNI_SelectableItemID
Definition: UNI_Graph.h:44
UNI_ContainerConnectType
Definition: UNI_Graph.h:35
UN_API UN_PortID srcPort(const UN_GraphData *graph_data, UN_PortID dst_port_id)
void addChangeType(UNI_GraphChangeType change_type)
Reports a change that occurred in the graph.
Definition: UNI_Graph.h:464
GLsizeiptr size
Definition: glcorearb.h:664
GLenum GLenum dst
Definition: glcorearb.h:1793
void setTextColor(const UT_Color &clr)
UNI_GraphChangeType(int value=NONE)
Definition: UNI_Graph.h:52
Removes the graph from the lookup table and deletes it.
Definition: UNI_Graph.h:130
static constexpr exint NAME
Definition: UNI_Graph.h:78
void setPosition(const UT_Vector2D &pos)
UNI_WireStyle
Definition: UNI_Include.h:38
GLuint color
Definition: glcorearb.h:1261
static constexpr exint SIGNATURE
Definition: UNI_Graph.h:80
size_t UNI_API UTformatBuffer(char *buffer, size_t buffer_size, const UNI_GraphChangeType &t)
UNI_DefaultParmValue
Definition: UNI_Graph.h:109
void setColor(const UT_Color &clr)
SIM_API const UT_StringHolder position
UNI_PortShape
Specifies the visual shape of the port in the UI.
Definition: UNI_Include.h:29
void resetGraph()
Clear the graph; used only when the graph has been deleted.
Definition: UNI_Graph.h:452
UNI_GraphChangeType changeType() const
Returns the types of changes that occurred in the graph.
Definition: UNI_Graph.h:460
void setCollapsed(bool collapsed)
UNI_GraphChangeType operator|(const UNI_GraphChangeType &other)
Definition: UNI_Graph.h:56
UN_API UN_WireIDList srcWires(const UN_GraphData *graph_data, UN_NodeID node_id, UN_PortKind port_kind)
UNI_Graph * graph() const
Returns the graph that changed.
Definition: UNI_Graph.h:456
UT_Vector4T< fpreal64 > UT_Vector4D
UN_API UN_PortID dstPort(const UN_GraphData *graph_data, UN_PortID src_port_id)
void setSize(const UT_Vector2D &size)
UN_API UN_WireIDList dstWires(const UN_GraphData *graph_data, UN_NodeID node_id, UN_PortKind port_kind)
bool operator!=(int value) const
Definition: UNI_Graph.h:62
UT_Matrix3T< fpreal64 > UT_Matrix3D
GLenum src
Definition: glcorearb.h:1793
static constexpr exint TOPOLOGY
Definition: UNI_Graph.h:76