// ---------------------------------------------------------------------- void RebuildDataConnection(iCS_EditorObject outputPort, iCS_EditorObject inputPort) { #if DEBUG Debug.Log("iCanScript: RebuildDataConnection: output= " + outputPort.DisplayName + " input= " + inputPort.DisplayName); #endif // Have we completed rebuilding ... if so return. if (inputPort == outputPort) { return; } var inputNode = inputPort.ParentNode; var outputNode = outputPort.ParentNode; if (inputNode == outputNode) { return; } // outputPort is inside the node with the inputPort. var commonParentNode = GraphInfo.GetCommonParent(outputPort, inputPort); if (inputNode == commonParentNode) { // Rebuild moving down from the common parent towards the output port. var newInputNode = outputPort.ParentNode; while (newInputNode != inputNode && newInputNode.ParentNode != inputNode) { newInputNode = newInputNode.ParentNode; } var existingPort = IStorage.FindPortWithSourceEndPoint(newInputNode, outputPort); if (existingPort != null) { var prevSource = inputPort.ProducerPort; if (prevSource != existingPort) { inputPort.ProducerPort = existingPort; if (prevSource.IsDynamicDataPort && !inputPort.IsPartOfConnection(prevSource)) { IStorage.CleanupHangingConnection(prevSource); } } RebuildDataConnection(outputPort, existingPort); } else { iCS_EditorObject newPort = IStorage.CreatePort(inputPort.DisplayName, newInputNode.InstanceId, inputPort.RuntimeType, VSObjectType.OutDynamicDataPort); IStorage.SetBestPositionForAutocreatedPort(newPort, outputPort.GlobalPosition, inputPort.GlobalPosition); newPort.ProducerPort = inputPort.ProducerPort; inputPort.ProducerPort = newPort; RebuildDataConnection(outputPort, newPort); } return; } var inputNodeParent = inputNode.ParentNode; if (inputNodeParent == commonParentNode) { // Rebuild traversing from moving upwards to downwords. var newDstNode = outputPort.ParentNode; while (newDstNode != commonParentNode && newDstNode.ParentNode != commonParentNode) { newDstNode = newDstNode.ParentNode; } var existingPort = IStorage.FindPortWithSourceEndPoint(newDstNode, outputPort); if (existingPort != null) { var prevSource = inputPort.ProducerPort; if (prevSource != existingPort) { inputPort.ProducerPort = existingPort; if (prevSource.IsDynamicDataPort && !inputPort.IsPartOfConnection(prevSource)) { IStorage.CleanupHangingConnection(prevSource); } } RebuildDataConnection(outputPort, existingPort); } else { iCS_EditorObject newPort = IStorage.CreatePort(inputPort.DisplayName, newDstNode.InstanceId, inputPort.RuntimeType, VSObjectType.OutDynamicDataPort); IStorage.SetBestPositionForAutocreatedPort(newPort, outputPort.GlobalPosition, inputPort.GlobalPosition); newPort.ProducerPort = inputPort.ProducerPort; inputPort.ProducerPort = newPort; RebuildDataConnection(outputPort, newPort); } return; } else { // Rebuilding moving up from the consumer port towards the common parent. var existingPort = IStorage.FindPortWithSourceEndPoint(inputNodeParent, outputPort); if (existingPort != null) { var prevSource = inputPort.ProducerPort; if (prevSource != existingPort) { inputPort.ProducerPort = existingPort; if (prevSource.IsDynamicDataPort && !inputPort.IsPartOfConnection(prevSource)) { IStorage.CleanupHangingConnection(prevSource); } } RebuildDataConnection(outputPort, existingPort); } else { iCS_EditorObject newPort = IStorage.CreatePort(inputPort.DisplayName, inputNodeParent.InstanceId, inputPort.RuntimeType, VSObjectType.InDynamicDataPort); IStorage.SetBestPositionForAutocreatedPort(newPort, outputPort.GlobalPosition, inputPort.GlobalPosition); newPort.ProducerPort = inputPort.ProducerPort; inputPort.ProducerPort = newPort; RebuildDataConnection(outputPort, newPort); } } }