java.lang.Object
com.marginallyclever.nodegraphcore.Graph

public class NodeGraph
extends java.lang.Object
NodeGraph contains the Nodes, and NodeConnections
Since:
2022-02-01
  • Constructor Details

    • NodeGraph

      public NodeGraph()
      Constructor for subclasses to call. Creates an empty NodeGraph.
  • Method Details

    • update

      public 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.
    • getNodes

      public java.util.List<Node> getNodes()
      Returns:
      a List of all the Nodes within this NodeGraph. It is not a copy! Use with caution.
    • getConnections

      public java.util.List<NodeConnection> getConnections()
      Returns:
      a List of all the NodeConnections within this NodeGraph. It is not a copy! Use with caution.
    • add

      public Node add​(Node node)
      Adds a node to this graph.
      Parameters:
      node - the subject
      Returns:
      the same node for convenient method chaining.
    • remove

      public void remove​(Node n)
      Remove a Node and all associated NodeConnections from the model.
      Parameters:
      n - the subject to be removed.
    • add

      public NodeConnection add​(NodeConnection connection)
      Adds a NodeConnection without checking if it already exists.
      Parameters:
      connection - the item to add.
      Returns:
      the same connection for convenient method chaining.
    • remove

      public void remove​(NodeConnection c)
      Remove one NodeConnection from this graph.
      Parameters:
      c - the item to remove.
    • removeConnectionsToNode

      public void removeConnectionsToNode​(Node n)
      Remove all NodeConnections from the model associated with a given Node
      Parameters:
      n - the subject from which all connections should be removed.
    • getMatchingConnection

      public NodeConnection getMatchingConnection​(NodeConnection connection)
      Searches this NodeGraph for an equivalent NodeConnection.
      Parameters:
      connection - the item to match.
      Returns:
      returns the matching NodeConnection or null.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • clear

      public void clear()
      Empty the model.
    • getFirstNearbyConnection

      public NodeConnectionPointInfo getFirstNearbyConnection​(java.awt.Point point, double r)
      Return the first connection point found within radius of a point
      Parameters:
      point - center of search area
      r - radius limit
      Returns:
      a NodeConnectionPointInfo describing the point found or null.
    • findNodeWithUniqueName

      public Node findNodeWithUniqueName​(java.lang.String uniqueName)
      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()
      Every Node and NodeConnection 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

      public void add​(NodeGraph b)
      Add all Nodes and NodeConnections from one model to this model.
      Parameters:
      b - the model to add.
    • deepCopy

      public NodeGraph deepCopy()
      Returns a deep copy of this NodeGraph by using the JSON serialization methods.
      Returns:
      the NodeGraph copy
    • indexOfNode

      public int indexOfNode​(java.lang.Class<Add> c)
      Return the index within the list of nodes of the first occurrence of class c. Comparisons are done using isInstance() 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

      public 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. Comparisons are done using isInstance() 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 using isInstance() and may count subclasses.
      Parameters:
      c - the class to match
      Returns:
      the number of instances of class c or its subclasses.
    • getNodesInRectangle

      public java.util.List<Node> getNodesInRectangle​(java.awt.geom.Rectangle2D searchArea)
      Returns a List of all Nodes that intersect the given rectangle
      Parameters:
      searchArea - the search area
      Returns:
      a List of all Nodes 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 all NodeConnections 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 smallest Rectangle that contains all Nodes. If there are no Nodes in this graph then nothing is done.
      Returns:
      the smallest Rectangle that contains all Nodes, or null.