MaterialXLab API  0.0.1
APIs For MaterialXLab Libraries
Loading...
Searching...
No Matches
MxGraphMonitor Class Reference

This class provides a monitoring interface for the graph editor. More...

Inheritance diagram for MxGraphMonitor:
MxMaterialXMonitor

Public Member Functions

 constructor (name)
 
 debugMessage (text, path)
 Output a debug message to the console.
 
 getPath (node, parentGraph)
 Get a '/' separated path.
 
 onDocumentChange (attribute, value, prevValue)
 Callback for when a scene / document level change is made.
 
 onConnectionChange (node, parentGraph)
 Callback for when a connection changes in the graph.
 
 onConnectOutput (slot, input_type, input, target_node, target_slot, node)
 Callback for connection to output.
 
 onConnectInput (target_slot, output_type, output, source, slot, node)
 Callback for connection to output.
 
 onNodeAdded (node, parentGraph)
 Callback for when a node is added to the graph.
 
 onNodeRemoved (node, parentGraph)
 Callback for when a node is removed from the graph.
 
 getParentPath (node)
 Get the parent path of a node.
 
 onNodeRenamed (node, newName)
 Callback for when a node is renamed in the graph.
 
 onNodeSelected (node, parentGraph)
 Callback for when a node is selected in the graph.
 
 onNodeDeselected (node, parentGraph)
 Callback for when a node is deselected in the graph.
 
 onPropertyChanged (nodeName, propertyName, newValue, previousValue, node)
 Callback for when a property changes on a node in the graph.
 
 onPropertyInfoChanged (nodeName, propertyName, propertyInfoName, newValue, previousValue, node)
 Callback for when a property info changes on a node in the graph.
 
 getName ()
 Get the name of the monitor.
 
 setRenderer (theRenderer)
 Set the renderer for the monitor.
 
 setMonitoring (monitor)
 Set the monitoring state of the monitor.
 
 getMonitoring ()
 Get the monitoring state of the monitor.
 
 setOnConnectionChange (callback)
 Set connection change callback.
 
 setOnNodeAdded (callback)
 Set node added callback.
 
 setOnNodeRemoved (callback)
 Set node removed callback.
 
 setOnNodeRenamed (callback)
 Set node renamed callback.
 
 setOnNodeSelected (callback)
 Set node selected callback.
 
 setOnNodeDeselected (callback)
 Set node deselected callback.
 
 setOnPropertyChanged (callback)
 Set property changed callback.
 
 monitorGraph (theGraph, monitor)
 Core monitoring of graph changes.
 

Detailed Description

This class provides a monitoring interface for the graph editor.

It will monitor the following changes to the graph:

  • Connection changed
  • Node added
  • Node removed
  • Node renamed
  • Node selected
  • Node deselected
  • Property changed
  • Property info changed

Definition at line 25 of file JsMaterialXNodeEditor.js.

Member Function Documentation

◆ constructor()

MxGraphMonitor::constructor ( name)

Definition at line 27 of file JsMaterialXNodeEditor.js.

28 {
29 this.name = name;
30 this.debug = true;
31 this.monitoring = true;
32 this.renderer = null;
33 }

◆ debugMessage()

MxGraphMonitor::debugMessage ( text,
path )

Output a debug message to the console.

Parameters
text- The text to output.
path- The path to output.
Returns
{void}

Definition at line 41 of file JsMaterialXNodeEditor.js.

42 {
43 if (this.debug) {
44 console.log(text + path);
45 }
46 }

◆ getMonitoring()

MxGraphMonitor::getMonitoring ( )

Get the monitoring state of the monitor.

Returns
The monitoring state of the monitor.

Definition at line 382 of file JsMaterialXNodeEditor.js.

383 {
384 return this.monitoring;
385 }

◆ getName()

MxGraphMonitor::getName ( )

Get the name of the monitor.

Returns
The name of the monitor.

Definition at line 350 of file JsMaterialXNodeEditor.js.

351 {
352 return this.name;
353 }

◆ getParentPath()

MxGraphMonitor::getParentPath ( node)

Get the parent path of a node.

Parameters
node- The node to get the parent path for.
Returns
The parent path of the node.

Definition at line 215 of file JsMaterialXNodeEditor.js.

216 {
217 let path = '';
218 var is_subgraph = graphcanvas.graph._is_subgraph;
219 if (is_subgraph) {
220 path = graphcanvas.graph._subgraph_node.title + '/';
221 }
222 else
223 {
224 if (node.graph)
225 {
226 is_subgraph = node.graph._is_subgraph;
227 if (is_subgraph) {
228 path = node.graph._subgraph_node.title + '/';
229 }
230 }
231 }
232 return path;
233 }
var graphcanvas

◆ getPath()

MxGraphMonitor::getPath ( node,
parentGraph )

Get a '/' separated path.

Parameters
node- The node to get the path for.
parentGraph- The parent graph of the node.
Returns
The path of the node.

Definition at line 54 of file JsMaterialXNodeEditor.js.

54 {
55
56 let path = '';
57 if (parentGraph.length > 0)
58 path = path + parentGraph + '/'
59 path += node.title;
60 return path;
61 }

◆ monitorGraph()

MxGraphMonitor::monitorGraph ( theGraph,
monitor )

Core monitoring of graph changes.

Parameters
theGraph- The graph to monitor.
monitor- The monitoring state.

Definition at line 491 of file JsMaterialXNodeEditor.js.

492 {
493 // Update monitor state
494 this.monitoring = monitor;
495
496 if (!theGraph)
497 return;
498
499 theGraph.onConnectionChange = null;
500 theGraph.onNodeAdded = null;
501 theGraph.onNodeRemoved = null;
502
503 if (monitor) {
504
505 console.log('> Monitor graph: ', graph.title? graph.title : 'ROOT')
506
507 var that = this;
508
509 theGraph.onConnectionChange = function (node) {
510 let parentGraph = '';
511 var is_subgraph = node.graph._is_subgraph;
512 if (is_subgraph)
513 parentGraph = graphcanvas.graph._subgraph_node.title;
514 that.onConnectionChange(node, parentGraph);
515
516 var selected = graphcanvas.selected_nodes;
517 for (var s in selected) {
518 //console.log('update selected node:', selected[s].title);
519 MxShadingGraphEditor.theEditor.updatePropertyPanel(selected[s]);
520 break;
521 }
522 }
523
524 theGraph.onNodeAdded = function (node) {
525 let parentGraph = '';
526
527 if (node.type == 'graph/subgraph') {
528 // Use MaterialX naming for subgraphs
529
530 // Scan the subgraph for any nodes which are not in the node inputs list.
531 var node_subgraph = node.subgraph;
532 var node_graph = node.graph;
533 if (node_subgraph) {
534 //console.log('** Scan subgraph: ', node_subgraph)
535 for (var i in node_subgraph._nodes) {
536 let theNode = node_subgraph._nodes[i];
537 if (!node_graph.findNodeByTitle(theNode.title)) {
538 if (theNode.nodedef_node == 'input') {
539 node.addInput(theNode.title, theNode.nodedef_type);
540 //console.log('--> Promote input node to subgraph node.', theNode.title);
541 }
542 else if (theNode.nodedef_node == 'output') {
543 //console.log('--> Promote output node to subgraph node.', theNode.title);
544 node.addOutput(theNode.title, theNode.nodedef_type);
545 }
546 }
547 }
548 }
549 }
550
551 node.title = MxShadingGraphEditor.theEditor.handler.createValidName(node.title)
552 node.setSize(node.computeSize());
553 //console.log('-> Node Added:', node, '. Type:', node.type, '. Graph:', node.graph._2458graph);
554
555 // Expose node as an input or output on the subgraph
556 var is_subgraph = node.graph._is_subgraph;
557 if (is_subgraph) {
558 parentGraph = graphcanvas.graph._subgraph_node.title;
559
560 if (node.nodedef_node == 'input') {
561 //console.log('Adding input node to subgraph.', node.title, node.graph);
562 node.graph.addInput(node.title, node.nodedef_type);
563 }
564 else if (node.nodedef_node == 'output') {
565 //console.log('Adding output node to subgraph.');
566 node.graph.addOutput(node.title, node.nodedef_type);
567 }
568 }
569
570 if (node.type == 'graph/subgraph') {
571 that.monitorGraph(node.subgraph, monitor);
572 }
573
574 that.onNodeAdded(node, parentGraph);
575 }
576
577 //console.log('Monitor graph remove:', theGraph.title);
578 theGraph.onNodeRemoved = function (node) {
579
580 let parentGraph = '';
581 /* This is too late the graph reference has already been removed */
582 var is_subgraph = graphcanvas.graph._is_subgraph;
583 if (is_subgraph) {
584 parentGraph = graphcanvas.graph._subgraph_node.title;
585 if (node.nodedef_node == 'input') {
586 //console.log('Removing input node from subgraph.', parentGraph);
587 graphcanvas.graph.removeInput(node.title);
588 }
589 else if (node.nodedef_node == 'output') {
590 //console.log('Removing output node from subgraph.', parentGraph);
591 graphcanvas.graph.removeOutput(node.title);
592 }
593 }
594
595 that.onNodeRemoved(node, parentGraph);
596 }
597
598 for (var i in theGraph._nodes) {
599 var node = theGraph._nodes[i];
600 if (node.type == 'graph/subgraph') {
601 console.log('> Monitor subgraph:', node.title);
602 that.monitorGraph(node.subgraph, monitor);
603 node.onConnectInput = MxShadingGraphEditor.theEditor.onConnectInput;
604 }
605 }
606 }
607 }
This class is a wrapper around the LiteGraph library to provide a MaterialX node editor.

◆ onConnectInput()

MxGraphMonitor::onConnectInput ( target_slot,
output_type,
output,
source,
slot,
node )

Callback for connection to output.

Parameters
target_slot- The target slot that was connected.
output_type- The type of the output.
output- The output that was connected.
source- The source node of the connection.
slot- The slot of the source node.
node- The node where the connection was made.
Returns
{void}

Definition at line 140 of file JsMaterialXNodeEditor.js.

140 {
141
142 if (!this.monitoring)
143 {
144 return;
145 }
146
147 // checker -> input
148 if (this.debug) {
149 let sourcePath = this.getPath(source, this.getParentPath(source));
150 let sourceOutput = output.name;
151 let targetPath = this.getPath(node, this.getParentPath(node));
152 let targetInput = node.inputs[target_slot].name;
153
154 this.debugMessage('Monitor> Input connection change: ' +
155 sourcePath + "[" + slot + "]." + sourceOutput + ' to: ' +
156 targetPath + "[" + target_slot + "]." + targetInput + " (" + output_type + ")", "");
157 }
158 }
debugMessage(text, path)
Output a debug message to the console.
getPath(node, parentGraph)
Get a '/' separated path.
getParentPath(node)
Get the parent path of a node.

◆ onConnectionChange()

MxGraphMonitor::onConnectionChange ( node,
parentGraph )

Callback for when a connection changes in the graph.

Parameters
node- The node where the connection changed.
parentGraph- The parent graph of the node.
Returns
{void}

Definition at line 88 of file JsMaterialXNodeEditor.js.

89 {
90 if (!this.monitoring)
91 {
92 return;
93 }
94
95 if (this.debug) {
96 this.debugMessage('Monitor> Connection change: ', this.getPath(node, parentGraph));
97 }
98 }

◆ onConnectOutput()

MxGraphMonitor::onConnectOutput ( slot,
input_type,
input,
target_node,
target_slot,
node )

Callback for connection to output.

Parameters
slot- The slot that was connected.
input_type- The type of the input.
input- The input that was connected.
target_node- The target node of the connection.
target_slot- The target slot of the connection.
node- The node where the connection was made.
Returns
{void}

Definition at line 110 of file JsMaterialXNodeEditor.js.

111 {
112 if (!this.monitoring)
113 {
114 return;
115 }
116
117 if (this.debug) {
118 let targetPath = this.getPath(node, this.getParentPath(node));
119 let targetOutput = node.outputs[slot].name;
120 let sourcePath = this.getPath(target_node, this.getParentPath(target_node));
121 let sourceInput = input.name;
122
123 this.debugMessage('Monitor> Output connection change: ' +
124 targetPath + "[" + slot + "]." + targetOutput + ' to: ' +
125 sourcePath + "[" + target_slot + "]." + sourceInput + " (" + input_type + ")", "");
126 }
127 }

◆ onDocumentChange()

MxGraphMonitor::onDocumentChange ( attribute,
value,
prevValue )

Callback for when a scene / document level change is made.

Parameters
attribute- The attribute that changed.
value- The new value of the attribute.
prevValue- The previous value of the attribute.
Returns
{void}

Definition at line 70 of file JsMaterialXNodeEditor.js.

71 {
72 if (!this.monitoring)
73 {
74 return;
75 }
76
77 if (this.debug) {
78 this.debugMessage('Monitor> Document attribute "' + attribute + '" changed from: ' + prevValue + ' to: ' + value, '');
79 }
80 }

◆ onNodeAdded()

MxGraphMonitor::onNodeAdded ( node,
parentGraph )

Callback for when a node is added to the graph.

Parameters
node- The node that was added.
parentGraph- The parent graph of the node.

Definition at line 167 of file JsMaterialXNodeEditor.js.

168 {
169 if (!this.monitoring)
170 {
171 return;
172 }
173
174 // Go through all inputs on the node and remove hidden attribute
175 // Needed to allow cut-paste of nodes which were loaded in with
176 // hidden inputs.
177 /* for (let i = 0; i < node.inputs.length; i++) {
178 let input = node.inputs[i];
179 if (input.hidden) {
180 // Remove hidden attribute
181 delete input.hidden;
182 }
183 } */
184
185 if (this.debug) {
186 this.debugMessage('Monitor> Node added: ', this.getPath(node, parentGraph));
187 }
188 }

◆ onNodeDeselected()

MxGraphMonitor::onNodeDeselected ( node,
parentGraph )

Callback for when a node is deselected in the graph.

Parameters
node- The node that was deselected.
parentGraph- The parent graph of the node.
Returns
{void}

Definition at line 283 of file JsMaterialXNodeEditor.js.

284 {
285 if (!this.monitoring)
286 {
287 return;
288 }
289
290 if (this.debug) {
291 //this.debugMessage('-> Node unselected at path: ', this.getPath(node, parentGraph));
292 }
293 }

◆ onNodeRemoved()

MxGraphMonitor::onNodeRemoved ( node,
parentGraph )

Callback for when a node is removed from the graph.

Parameters
node- The node that was removed.
parentGraph- The parent graph of the node.
Returns
{void}

Definition at line 197 of file JsMaterialXNodeEditor.js.

198 {
199 if (!this.monitoring)
200 {
201 return;
202 }
203
204 if (this.debug) {
205 this.debugMessage('Monitor> Node removed: ', this.getPath(node, parentGraph));
206 }
207 }

◆ onNodeRenamed()

MxGraphMonitor::onNodeRenamed ( node,
newName )

Callback for when a node is renamed in the graph.

Parameters
node- The node that was renamed.
newName- The new name of the node.
Returns
{void}

Definition at line 242 of file JsMaterialXNodeEditor.js.

243 {
244 if (!this.monitoring)
245 {
246 return;
247 }
248
249 let parentPath = this.getParentPath(node);
250 let path = parentPath + node.title;
251 let newpath = parentPath + newName;
252 if (this.debug) {
253 this.debugMessage('Monitor> Node renamed: ', path + ' to: ' + newpath);
254 }
255 }

◆ onNodeSelected()

MxGraphMonitor::onNodeSelected ( node,
parentGraph )

Callback for when a node is selected in the graph.

Parameters
node- The node that was selected.
parentGraph- The parent graph of the node.
Returns
{void}

Definition at line 264 of file JsMaterialXNodeEditor.js.

265 {
266 if (!this.monitoring)
267 {
268 return;
269 }
270
271 if (this.debug) {
272 this.debugMessage('Monitor> Node selected: ', this.getPath(node, parentGraph));
273 }
274 }

◆ onPropertyChanged()

MxGraphMonitor::onPropertyChanged ( nodeName,
propertyName,
newValue,
previousValue,
node )

Callback for when a property changes on a node in the graph.

Parameters
nodeName- The name of the node.
propertyName- The name of the property that changed.
newValue- The new value of the property.
previousValue- The previous value of the property.
node- The node where the property changed.
Returns
{void}

Definition at line 305 of file JsMaterialXNodeEditor.js.

306 {
307 if (!this.monitoring)
308 {
309 return;
310 }
311
312 let path = this.getParentPath(node) + nodeName;
313 if (this.debug) {
314 console.log('Monitor> Property changed:', path, '. Property: ' + propertyName +
315 '. Value: ' + newValue + '. Previous Value: ' + previousValue, '. Category:', node.nodedef_node);
316 }
317 }

◆ onPropertyInfoChanged()

MxGraphMonitor::onPropertyInfoChanged ( nodeName,
propertyName,
propertyInfoName,
newValue,
previousValue,
node )

Callback for when a property info changes on a node in the graph.

Parameters
nodeName- The name of the node.
propertyName- The name of the property that changed.
propertyInfoName- The name of the property info that changed.
newValue- The new value of the property info.
previousValue- The previous value of the property info.
node- The node where the property info changed.
Returns
{void}

Definition at line 330 of file JsMaterialXNodeEditor.js.

331 {
332 if (!this.monitoring)
333 {
334 return;
335 }
336
337 let path = this.getParentPath(node) + nodeName;
338 if (this.debug) {
339 console.log('Monitor> Property Info changed:', path, '. Property: ' + propertyName +
340 '. Property Info: ' + propertyInfoName +
341 '. Value: ' + newValue + '. Previous Value: ' + previousValue, '. Category:', node.nodedef_node);
342 }
343 }

◆ setMonitoring()

MxGraphMonitor::setMonitoring ( monitor)

Set the monitoring state of the monitor.

Parameters
monitor- The monitoring state to set.
Returns
{void}

Definition at line 372 of file JsMaterialXNodeEditor.js.

373 {
374 this.monitoring = monitor;
375 }

◆ setOnConnectionChange()

MxGraphMonitor::setOnConnectionChange ( callback)

Set connection change callback.

Parameters
callback- The callback to set.
Returns
{void}

Definition at line 393 of file JsMaterialXNodeEditor.js.

394 {
395 if (callback)
396 {
397 this.onConnectionChange = callback;
398 }
399 }
onConnectionChange(node, parentGraph)
Callback for when a connection changes in the graph.

◆ setOnNodeAdded()

MxGraphMonitor::setOnNodeAdded ( callback)

Set node added callback.

Parameters
callback- The callback to set.
Returns
{void}

Definition at line 407 of file JsMaterialXNodeEditor.js.

408 {
409 if (callback)
410 {
411 this.onNodeAdded = callback;
412 }
413 }
onNodeAdded(node, parentGraph)
Callback for when a node is added to the graph.

◆ setOnNodeDeselected()

MxGraphMonitor::setOnNodeDeselected ( callback)

Set node deselected callback.

Parameters
callback- The callback to set.
Returns
{void}

Definition at line 463 of file JsMaterialXNodeEditor.js.

464 {
465 if (callback)
466 {
467 this.onNodeDeselected = callback;
468 }
469 }
onNodeDeselected(node, parentGraph)
Callback for when a node is deselected in the graph.

◆ setOnNodeRemoved()

MxGraphMonitor::setOnNodeRemoved ( callback)

Set node removed callback.

Parameters
callback- The callback to set.
Returns
{void}

Definition at line 421 of file JsMaterialXNodeEditor.js.

422 {
423 if (callback)
424 {
425 this.onNodeRemoved = callback;
426 }
427 }
onNodeRemoved(node, parentGraph)
Callback for when a node is removed from the graph.

◆ setOnNodeRenamed()

MxGraphMonitor::setOnNodeRenamed ( callback)

Set node renamed callback.

Parameters
callback- The callback to set.
Returns
{void}

Definition at line 435 of file JsMaterialXNodeEditor.js.

436 {
437 if (callback)
438 {
439 this.onNodeRenamed = callback;
440 }
441 }
onNodeRenamed(node, newName)
Callback for when a node is renamed in the graph.

◆ setOnNodeSelected()

MxGraphMonitor::setOnNodeSelected ( callback)

Set node selected callback.

Parameters
callback- The callback to set.
Returns
{void}

Definition at line 449 of file JsMaterialXNodeEditor.js.

450 {
451 if (callback)
452 {
453 this.onNodeSelected = callback;
454 }
455 }
onNodeSelected(node, parentGraph)
Callback for when a node is selected in the graph.

◆ setOnPropertyChanged()

MxGraphMonitor::setOnPropertyChanged ( callback)

Set property changed callback.

Parameters
callback- The callback to set.
Returns
{void}

Definition at line 477 of file JsMaterialXNodeEditor.js.

478 {
479 if (callback)
480 {
481 this.onPropertyChanged = callback;
482 }
483 }
onPropertyChanged(nodeName, propertyName, newValue, previousValue, node)
Callback for when a property changes on a node in the graph.

◆ setRenderer()

MxGraphMonitor::setRenderer ( theRenderer)

Set the renderer for the monitor.

Parameters
theRenderer- The renderer to set.
Returns
{void}

Definition at line 361 of file JsMaterialXNodeEditor.js.

362 {
363 this.renderer = theRenderer
364 }

The documentation for this class was generated from the following file: