Loading...
Searching...
No Matches
grapherOptions.h
Go to the documentation of this file.
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_VDF_GRAPHER_OPTIONS_H
8#define PXR_EXEC_VDF_GRAPHER_OPTIONS_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
16#include "pxr/exec/vdf/object.h"
17
18#include "pxr/base/tf/hashmap.h"
19#include "pxr/base/tf/stl.h"
20
21#include <functional>
22#include <string>
23#include <vector>
24
25PXR_NAMESPACE_OPEN_SCOPE
26
27class VdfNode;
28
36{
37
38public:
39
47 DisplayStyleFull = 0,
48 DisplayStyleNoLabels,
49 DisplayStyleSummary
50 };
51
56 using NodeFilterCallback = std::function<
57 bool (const VdfNode &nodeToFilter)>;
58
62 using NodeStyleCallback = std::function<
64 const VdfNode &node,
65 const VdfConnectionVector &drawnIn,
66 const VdfConnectionVector &drawnOut)>;
67
71 struct NodeLimit {
72 NodeLimit(const VdfNode *n, int maxin, int maxout) :
73 node(n),
74 maxInDepth(maxin),
75 maxOutDepth(maxout)
76 {}
77
78 const VdfNode *node;
79 int maxInDepth;
80 int maxOutDepth;
81 };
82
83 typedef std::vector<NodeLimit> NodeLimitVector;
84
85public:
86
87 VDF_API
89
93 void SetDrawMasks(bool drawMasks) { _drawMasks = drawMasks; }
94
99 void SetDrawAffectsMasks(bool drawMasks) { _drawAffectsMasks = drawMasks; }
100
103 bool GetDrawMasks() const { return _drawMasks; }
104
107 bool GetDrawAffectsMasks() const { return _drawAffectsMasks; }
108
112 void SetPrintSingleOutputs(bool enable) {
113 _printSingleOutputs = enable; }
114
118 return _printSingleOutputs; }
119
124 void SetPageSize(double width, double height) {
125 _pageWidth = width;
126 _pageHeight = height;
127 }
128
131 double GetPageHeight() const { return _pageHeight; }
132
135 double GetPageWidth() const { return _pageWidth; }
136
144 void SetUniqueIds(bool uniqueIds) { _uniqueIds = uniqueIds; }
145
148 bool GetUniqueIds() const { return _uniqueIds; }
149
152 void SetOmitUnconnectedSpecs(bool omit) { _omitUnconnectedSpecs = omit; }
153
157 bool GetOmitUnconnectedSpecs() const { return _omitUnconnectedSpecs; }
158
162 void SetDrawColorizedConnectionsOnly(bool drawColorizedConnectionsOnly) {
163 _drawColorizedConnectionsOnly = drawColorizedConnectionsOnly;
164 }
165
170 return _drawColorizedConnectionsOnly;
171 }
172
179 void AddNodeToGraph(const VdfNode &node, int maxInDepth, int maxOutDepth) {
180 _nodesToGraph.push_back(NodeLimit(&node, maxInDepth, maxOutDepth));
181 }
182
188 void SetColor(const VdfObjectPtr &object, const TfToken &color) {
189
190 if (!color.IsEmpty())
191 _objectColors[object] = color;
192 }
193
196 TfToken GetColor(const VdfObjectPtr &object) const {
197 return TfMapLookupByValue(_objectColors, object, TfToken());
198 }
199
203 void SetAnnotation(const VdfObjectPtr &object, const std::string &text) {
204 _objectAnnotations[object] = text;
205 }
206
210 std::string GetAnnotation(const VdfObjectPtr &object) const {
211 return TfMapLookupByValue(_objectAnnotations, object, std::string());
212 }
213
216 const NodeLimitVector &GetNodesToGraph() const { return _nodesToGraph; }
217
224 _nodeFilterCallback = callback;
225 }
226
229 return _nodeFilterCallback;
230 }
231
236 _nodeStyleCallback = callback;
237 }
238
242 return _nodeStyleCallback;
243 }
244
251 VDF_API
252 static bool DebugNameFilter(
253 const std::vector<std::string> &nameList,
254 bool includeIfInNameList,
255 const VdfNode &node );
256
260 _displayStyle = style;
261 }
262
265 DisplayStyle GetDisplayStyle() const { return _displayStyle; }
266
267private:
268
269 // Draws the masks on the connections if true.
270 bool _drawMasks;
271
272 // Draws the affects masks on outputs if true.
273 bool _drawAffectsMasks;
274
275 // The width of the page
276 double _pageWidth;
277
278 // The height of the page
279 double _pageHeight;
280
281 // Determines whether or not unique IDs are used.
282 bool _uniqueIds;
283
284 // The subset of nodes to draw. If this list is empty, everything
285 // in the network is drawn.
286 NodeLimitVector _nodesToGraph;
287
288 // The callback used to filter nodes out of the graph.
289 NodeFilterCallback _nodeFilterCallback;
290
291 // The callback used to style nodes.
292 NodeStyleCallback _nodeStyleCallback;
293
294 // The display style for the nodes
295 DisplayStyle _displayStyle;
296
297 // If true, nodes that have a single output, will render that output.
298 bool _printSingleOutputs;
299
300 // Map of colored objects to color name.
301 TfHashMap<VdfObjectPtr, TfToken, VdfObjectPtr::HashFunctor> _objectColors;
302
303 // Map of annotated objects to annotation.
304 TfHashMap<VdfObjectPtr, std::string, VdfObjectPtr::HashFunctor> _objectAnnotations;
305
306 // If true, unconnected inputs/outputs will be omitted.
307 bool _omitUnconnectedSpecs;
308
309 // If true, draw connections with explicitly SetColor() only.
310 bool _drawColorizedConnectionsOnly;
311};
312
313PXR_NAMESPACE_CLOSE_SCOPE
314
315#endif
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:288
This class can be used to configure aspects of VdfGrapher's output.
void SetDrawColorizedConnectionsOnly(bool drawColorizedConnectionsOnly)
When drawColorizedConnectionsOnly is set, only connections that have a color set via SetColor() will ...
void SetDrawMasks(bool drawMasks)
When drawMasks is true, the masks on the connections will be drawn.
void SetNodeStyleCallback(const NodeStyleCallback &callback)
Sets the callback used used to style nodes.
void AddNodeToGraph(const VdfNode &node, int maxInDepth, int maxOutDepth)
Adds node to the list of nodes to be graphed.
DisplayStyle
The display styles for nodes.
void SetOmitUnconnectedSpecs(bool omit)
When omit is set, unconnected specs will be omitted.
void SetNodeFilterCallback(const NodeFilterCallback &callback)
Sets the callback used used to filter nodes out of the graph.
const NodeLimitVector & GetNodesToGraph() const
Returns the list of nodes that should be graphed.
bool GetUniqueIds() const
Returns whether or not the graph should use unique ids.
std::function< bool(const VdfNode &nodeToFilter)> NodeFilterCallback
This typedef describes the function signature for callbacks used to filter nodes out of the graph.
TfToken GetColor(const VdfObjectPtr &object) const
Returns the color for object or the empty TfToken if none was set.
const NodeFilterCallback & GetNodeFilterCallback() const
Returns the callback used to filter nodes out of the graph.
void SetDisplayStyle(DisplayStyle style)
Sets the default display style for nodes.
DisplayStyle GetDisplayStyle() const
Returns the default display style for a node.
void SetPrintSingleOutputs(bool enable)
When enable is false, nodes containing only a single output, won't render their full connector to red...
const NodeStyleCallback & GetNodeStyleCallback() const
Returns the (optional) callback used to style nodes.
void SetUniqueIds(bool uniqueIds)
When uniqueIds is false, the graph will be printed without using unique ids for node names and ports.
void SetPageSize(double width, double height)
Sets the desired size of the page output.
void SetAnnotation(const VdfObjectPtr &object, const std::string &text)
Sets an annotation text for object which gets rendered for the object.
bool GetOmitUnconnectedSpecs() const
Returns whether or not the produced graph should include unconnected specs (ie.
std::string GetAnnotation(const VdfObjectPtr &object) const
Returns the annotation for object or the empty string if none was set.
bool GetPrintSingleOutputs() const
Returns true, if skipping single outputs is enabled.
double GetPageHeight() const
Returns the page height.
bool GetDrawColorizedConnectionsOnly() const
Returns whether connections that have not a color set via SetColor() should not be drawn.
std::function< DisplayStyle(const VdfNode &node, const VdfConnectionVector &drawnIn, const VdfConnectionVector &drawnOut)> NodeStyleCallback
This callback is used to determine what style a specific node should be rendered with regardless what...
bool GetDrawAffectsMasks() const
Returns whether or not masks will be draw on the connections.
double GetPageWidth() const
Returns the page width.
void SetDrawAffectsMasks(bool drawMasks)
When drawMasks is true, the affects masks on node outputs will be drawn.
void SetColor(const VdfObjectPtr &object, const TfToken &color)
Sets a color for object which can be a connection or node.
bool GetDrawMasks() const
Returns whether or not masks will be draw on the connections.
static VDF_API bool DebugNameFilter(const std::vector< std::string > &nameList, bool includeIfInNameList, const VdfNode &node)
Filters nodes based on debug names, when used as a NodeFilterCallback.
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:53
An universal class to represent pointers to various Vdf types.
Definition: object.h:40
const Result TfMapLookupByValue(Container const &map, Key const &key, const Result &defaultValue)
Checks if an item exists in a map or a TfHashMap.
Definition: stl.h:95
This struct is used to allow the grapher to graph a subset of the nodes.