|
|
|
|
|
|
|
|
|
|
public virtual void ReplaceWith(IGraph other) |
|
|
|
{ |
|
|
|
// Current tactic is to remove all nodes and edges and then re-add them, such that depending systems
|
|
|
|
// will re-initialize with new references.
|
|
|
|
{ |
|
|
|
// Remove the edge if it doesn't exist in the other graph.
|
|
|
|
if (!other.ContainsNodeGuid(edge.inputSlot.nodeGuid) || !other.GetEdges(edge.inputSlot).Any(otherEdge => otherEdge.outputSlot.Equals(edge.outputSlot))) |
|
|
|
removedNodeEdges.Add(edge); |
|
|
|
} |
|
|
|
removedNodeEdges.Add(edge); |
|
|
|
// Remove all nodes and re-add them.
|
|
|
|
using (var removedNodesPooledObject = ListPool<Guid>.GetDisposable()) |
|
|
|
{ |
|
|
|
var removedNodeGuids = removedNodesPooledObject.value; |
|
|
|
|
|
|
|
|
|
|
ValidateGraph(); |
|
|
|
|
|
|
|
// Add nodes from other graph which don't exist in this one.
|
|
|
|
{ |
|
|
|
if (!ContainsNodeGuid(node.guid)) |
|
|
|
AddNodeNoValidate(node); |
|
|
|
} |
|
|
|
AddNodeNoValidate(node); |
|
|
|
// Add edges from other graph which don't exist in this one.
|
|
|
|
{ |
|
|
|
if (!GetEdges(edge.inputSlot).Any(otherEdge => otherEdge.outputSlot.Equals(edge.outputSlot))) |
|
|
|
ConnectNoValidate(edge.outputSlot, edge.inputSlot); |
|
|
|
} |
|
|
|
ConnectNoValidate(edge.outputSlot, edge.inputSlot); |
|
|
|
|
|
|
|
ValidateGraph(); |
|
|
|
} |
|
|
|