Class NodeGraph
java.lang.Object
com.marginallyclever.nodegraphcore.Graph
public class NodeGraph
extends java.lang.Object
- Since:
 - 2022-02-01
 
- 
Constructor Summary
Constructors Constructor Description NodeGraph()Constructor for subclasses to call. - 
Method Summary
Modifier and Type Method Description Nodeadd(Node node)Adds a node to this graph.NodeConnectionadd(NodeConnection connection)Adds aNodeConnectionwithout checking if it already exists.voidadd(NodeGraph b)Add allNodes andNodeConnections from one model to this model.voidbumpUpIndexableID()EveryNodeandNodeConnectionhas a unique ID.voidclear()Empty the model.intcountNodesOfClass(java.lang.Class<?> c)Return the number of instances of class c or its subclasses.NodeGraphdeepCopy()Returns a deep copy of thisNodeGraphby using the JSON serialization methods.NodefindNodeWithUniqueName(java.lang.String uniqueName)Returns the Node that matches the unique name, or null.java.awt.RectanglegetBounds()Calculates and returns the smallestRectanglethat contains allNodes.java.util.List<NodeConnection>getConnections()java.util.List<NodeConnection>getConnectionsBetweenTheseNodes(java.util.List<Node> selectedNodes)Returns allNodeConnections that are only connected between the given set of nodes.NodeConnectionPointInfogetFirstNearbyConnection(java.awt.Point point, double r)Return the first connection point found within radius of a pointNodeConnectiongetMatchingConnection(NodeConnection connection)Searches thisNodeGraphfor an equivalentNodeConnection.java.util.List<Node>getNodes()java.util.List<Node>getNodesInRectangle(java.awt.geom.Rectangle2D searchArea)Returns aListof allNodes that intersect the given rectangleintindexOfNode(java.lang.Class<Add> c)Return the index within the list of nodes of the first occurrence of class c.intindexOfNode(java.lang.Class<Add> c, int fromIndex)Return the index within the list of nodes of the first occurrence of class c, starting the search at the specified index.booleanisEmpty()Returns true if the node list is empty.voidremove(Node n)Remove aNodeand all associatedNodeConnections from the model.voidremove(NodeConnection c)Remove oneNodeConnectionfrom this graph.voidremoveConnectionsToNode(Node n)Remove allNodeConnections from the model associated with a givenNodejava.lang.StringtoString()voidupdate()Updates only dirty nodes. Transmits dirty node outputs to connected inputs. Sets all outputs to clean. The method does not analyze the directed graph to run nodes in an "intelligent" way.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
- 
Constructor Details
- 
NodeGraph
public NodeGraph()Constructor for subclasses to call. Creates an emptyNodeGraph. 
 - 
 - 
Method Details
- 
update
public void update()- Updates only dirty nodes.
 - Transmits dirty node outputs to connected inputs.
 - Sets all outputs to clean.
 
 - 
getNodes
 - 
getConnections
- Returns:
 - a 
Listof all theNodeConnections within thisNodeGraph. It is not a copy! Use with caution. 
 - 
add
Adds a node to this graph.- Parameters:
 node- the subject- Returns:
 - the same node for convenient method chaining.
 
 - 
remove
Remove aNodeand all associatedNodeConnections from the model.- Parameters:
 n- the subject to be removed.
 - 
add
Adds aNodeConnectionwithout checking if it already exists.- Parameters:
 connection- the item to add.- Returns:
 - the same connection for convenient method chaining.
 
 - 
remove
Remove oneNodeConnectionfrom this graph.- Parameters:
 c- the item to remove.
 - 
removeConnectionsToNode
Remove allNodeConnections from the model associated with a givenNode- Parameters:
 n- the subject from which all connections should be removed.
 - 
getMatchingConnection
Searches thisNodeGraphfor an equivalentNodeConnection.- Parameters:
 connection- the item to match.- Returns:
 - returns the matching 
NodeConnectionor null. 
 - 
toString
public java.lang.String toString()- Overrides:
 toStringin classjava.lang.Object
 - 
clear
public void clear()Empty the model. - 
getFirstNearbyConnection
Return the first connection point found within radius of a point- Parameters:
 point- center of search arear- radius limit- Returns:
 - a 
NodeConnectionPointInfodescribing the point found or null. 
 - 
findNodeWithUniqueName
Returns the Node that matches the unique name, or null.- Parameters:
 uniqueName- the string to match.- Returns:
 - the Node that matches the unique name, or null.
 
 - 
bumpUpIndexableID
public void bumpUpIndexableID()EveryNodeandNodeConnectionhas a unique ID. If the model has just been restored from a file then the static unique ID will be wrong. This method bumps the first available unique ID up to the largest value found. Then the next attempt to create a unique item will be safe. - 
add
Add allNodes andNodeConnections from one model to this model.- Parameters:
 b- the model to add.
 - 
deepCopy
Returns a deep copy of thisNodeGraphby using the JSON serialization methods.- Returns:
 - the 
NodeGraphcopy 
 - 
indexOfNode
Return the index within the list of nodes of the first occurrence of class c. Comparisons are done usingisInstance()and may return subclasses.- Parameters:
 c- the class to match.- Returns:
 - the index within the list of nodes of the first occurrence of class c, or -1.
 
 - 
indexOfNode
Return the index within the list of nodes of the first occurrence of class c, starting the search at the specified index. Comparisons are done usingisInstance()and may return subclasses.- Parameters:
 c- the class to match.fromIndex- the index to start the search from.- Returns:
 - the index within the list of nodes of the first occurrence of class c, or -1.
 
 - 
countNodesOfClass
public int countNodesOfClass(java.lang.Class<?> c)Return the number of instances of class c or its subclasses. Comparisons are done usingisInstance()and may count subclasses.- Parameters:
 c- the class to match- Returns:
 - the number of instances of class c or its subclasses.
 
 - 
getNodesInRectangle
Returns aListof allNodes that intersect the given rectangle- Parameters:
 searchArea- the search area- Returns:
 - a 
Listof allNodes that intersect the given rectangle 
 - 
isEmpty
public boolean isEmpty()Returns true if the node list is empty.- Returns:
 - true if the node list is empty.
 
 - 
getConnectionsBetweenTheseNodes
public java.util.List<NodeConnection> getConnectionsBetweenTheseNodes(java.util.List<Node> selectedNodes)Returns allNodeConnections that are only connected between the given set of nodes.- Parameters:
 selectedNodes- the set of nodes to check- Returns:
 - all 
NodeConnections that are only connected between the given set of nodes. 
 - 
getBounds
public java.awt.Rectangle getBounds()Calculates and returns the smallestRectanglethat contains allNodes. If there are no Nodes in this graph then nothing is done.- Returns:
 - the smallest 
Rectanglethat contains allNodes, or null. 
 
 -