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.
 
 getRenderer ()
 Get 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 391 of file JsMaterialXNodeEditor.js.

392 {
393 return this.monitoring;
394 }

◆ 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 }

◆ getRenderer()

MxGraphMonitor::getRenderer ( )

Get the renderer for the monitor.

Returns
The renderer for the monitor.

Definition at line 370 of file JsMaterialXNodeEditor.js.

371 {
372 return this.renderer;
373 }

◆ monitorGraph()

MxGraphMonitor::monitorGraph ( theGraph,
monitor )

Core monitoring of graph changes.

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

Definition at line 500 of file JsMaterialXNodeEditor.js.

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

382 {
383 this.monitoring = monitor;
384 }

◆ setOnConnectionChange()

MxGraphMonitor::setOnConnectionChange ( callback)

Set connection change callback.

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

Definition at line 402 of file JsMaterialXNodeEditor.js.

403 {
404 if (callback)
405 {
406 this.onConnectionChange = callback;
407 }
408 }
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 416 of file JsMaterialXNodeEditor.js.

417 {
418 if (callback)
419 {
420 this.onNodeAdded = callback;
421 }
422 }
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 472 of file JsMaterialXNodeEditor.js.

473 {
474 if (callback)
475 {
476 this.onNodeDeselected = callback;
477 }
478 }
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 430 of file JsMaterialXNodeEditor.js.

431 {
432 if (callback)
433 {
434 this.onNodeRemoved = callback;
435 }
436 }
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 444 of file JsMaterialXNodeEditor.js.

445 {
446 if (callback)
447 {
448 this.onNodeRenamed = callback;
449 }
450 }
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 458 of file JsMaterialXNodeEditor.js.

459 {
460 if (callback)
461 {
462 this.onNodeSelected = callback;
463 }
464 }
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 486 of file JsMaterialXNodeEditor.js.

487 {
488 if (callback)
489 {
490 this.onPropertyChanged = callback;
491 }
492 }
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: