Beispiel #1
0
        // ----------------------------------------------------------------------
        public void RebuildStateConnection(iCS_EditorObject fromStatePort, iCS_EditorObject toStatePort)
        {
            if (fromStatePort == null || toStatePort == null)
            {
                return;
            }
            var commonParent = GraphInfo.GetCommonParent(fromStatePort, toStatePort);

            if (commonParent == null)
            {
                Debug.LogWarning("iCanScript: Unable to find common parent after relocating state !!!");
                return;
            }
            var transitionPackage = GetTransitionPackage(toStatePort);

            if (transitionPackage == null)
            {
                return;
            }
            if (transitionPackage.ParentNode == commonParent)
            {
                return;
            }
            ChangeParent(transitionPackage, commonParent);
            LayoutTransitionPackage(transitionPackage);
        }
        // -------------------------------------------------------------------------
        iCS_EditorObject[] FilterMultiSelectionUnderSameParent()
        {
            var multiSelectedObjects = GetMultiSelectedObjects();

            if (multiSelectedObjects == null || multiSelectedObjects.Length == 0)
            {
                Debug.LogWarning("No selected object found!!!");
                return(null);
            }
            // Find common parent.
            if (multiSelectedObjects.Length == 1)
            {
                return(multiSelectedObjects);
            }
            var commonParent = GraphInfo.GetCommonParent(multiSelectedObjects);
            // Special case for when the common parent is one of the selected objects.
            List <iCS_EditorObject> valid = new List <iCS_EditorObject>();

            foreach (var obj in multiSelectedObjects)
            {
                if (obj == commonParent)
                {
                    valid.Add(obj);
                }
            }
            if (valid.Count != 0)
            {
                return(valid.ToArray());
            }
            // Find the proper node just below common parent.
            foreach (var o in multiSelectedObjects)
            {
                var obj = o;
                while (obj.ParentNode != null && obj.ParentNode != commonParent)
                {
                    obj = obj.ParentNode;
                }
                if (obj.ParentNode == commonParent)
                {
                    valid.Add(obj);
                }
            }

            /*
             *  TODO : Filter for uniqu entries.
             */
            return(valid.ToArray());
        }
        // ----------------------------------------------------------------------
        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);
                }
            }
        }