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 Node
add(Node node)
Adds a node to this graph.NodeConnection
add(NodeConnection connection)
Adds aNodeConnection
without checking if it already exists.void
add(NodeGraph b)
Add allNode
s andNodeConnection
s from one model to this model.void
bumpUpIndexableID()
EveryNode
andNodeConnection
has a unique ID.void
clear()
Empty the model.int
countNodesOfClass(java.lang.Class<?> c)
Return the number of instances of class c or its subclasses.NodeGraph
deepCopy()
Returns a deep copy of thisNodeGraph
by using the JSON serialization methods.Node
findNodeWithUniqueName(java.lang.String uniqueName)
Returns the Node that matches the unique name, or null.java.awt.Rectangle
getBounds()
Calculates and returns the smallestRectangle
that contains allNode
s.java.util.List<NodeConnection>
getConnections()
java.util.List<NodeConnection>
getConnectionsBetweenTheseNodes(java.util.List<Node> selectedNodes)
Returns allNodeConnection
s that are only connected between the given set of nodes.NodeConnectionPointInfo
getFirstNearbyConnection(java.awt.Point point, double r)
Return the first connection point found within radius of a pointNodeConnection
getMatchingConnection(NodeConnection connection)
Searches thisNodeGraph
for an equivalentNodeConnection
.java.util.List<Node>
getNodes()
java.util.List<Node>
getNodesInRectangle(java.awt.geom.Rectangle2D searchArea)
Returns aList
of allNode
s that intersect the given rectangleint
indexOfNode(java.lang.Class<Add> c)
Return the index within the list of nodes of the first occurrence of class c.int
indexOfNode(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.boolean
isEmpty()
Returns true if the node list is empty.void
remove(Node n)
Remove aNode
and all associatedNodeConnection
s from the model.void
remove(NodeConnection c)
Remove oneNodeConnection
from this graph.void
removeConnectionsToNode(Node n)
Remove allNodeConnection
s from the model associated with a givenNode
java.lang.String
toString()
void
update()
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
List
of all theNodeConnection
s 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 aNode
and all associatedNodeConnection
s from the model.- Parameters:
n
- the subject to be removed.
-
add
Adds aNodeConnection
without checking if it already exists.- Parameters:
connection
- the item to add.- Returns:
- the same connection for convenient method chaining.
-
remove
Remove oneNodeConnection
from this graph.- Parameters:
c
- the item to remove.
-
removeConnectionsToNode
Remove allNodeConnection
s from the model associated with a givenNode
- Parameters:
n
- the subject from which all connections should be removed.
-
getMatchingConnection
Searches thisNodeGraph
for an equivalentNodeConnection
.- Parameters:
connection
- the item to match.- Returns:
- returns the matching
NodeConnection
or null.
-
toString
public java.lang.String toString()- Overrides:
toString
in 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
NodeConnectionPointInfo
describing 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()EveryNode
andNodeConnection
has 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 allNode
s andNodeConnection
s from one model to this model.- Parameters:
b
- the model to add.
-
deepCopy
Returns a deep copy of thisNodeGraph
by using the JSON serialization methods.- Returns:
- the
NodeGraph
copy
-
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 aList
of allNode
s that intersect the given rectangle- Parameters:
searchArea
- the search area- Returns:
- a
List
of allNode
s 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 allNodeConnection
s that are only connected between the given set of nodes.- Parameters:
selectedNodes
- the set of nodes to check- Returns:
- all
NodeConnection
s that are only connected between the given set of nodes.
-
getBounds
public java.awt.Rectangle getBounds()Calculates and returns the smallestRectangle
that contains allNode
s. If there are no Nodes in this graph then nothing is done.- Returns:
- the smallest
Rectangle
that contains allNode
s, or null.
-