// ----------------------------------------------------------------------
 public bool UntilMatchingChild(iCS_EditorObject parent, Func <iCS_EditorObject, bool> cond)
 {
     DetectUndoRedo();
     if (parent == null)
     {
         return(EditorObjects[0].UntilMatchingChild(child => cond(child)));
     }
     else
     {
         return(parent.UntilMatchingChild(child => cond(child)));
     }
 }
Ejemplo n.º 2
0
        // ----------------------------------------------------------------------
        public void SetNewDataConnection(iCS_EditorObject inPort, iCS_EditorObject outPort, LibraryFunction conversion = null)
        {
            iCS_EditorObject inParentNode   = inPort.ParentNode;
            iCS_EditorObject outParentNode  = outPort.ParentNode;
            iCS_EditorObject inGrandParent  = inParentNode.ParentNode;
            iCS_EditorObject outGrandParent = outParentNode.ParentNode;

            // No need to create module ports if both connected nodes are under the same parent.
            if (inGrandParent == outGrandParent || inGrandParent == outParentNode || inParentNode == outGrandParent)
            {
                SetSource(inPort, outPort, conversion);
                OptimizeDataConnection(inPort, outPort);
                return;
            }
            // Create inPort if inParent is not part of the outParent hierarchy.
            bool inParentSeen = false;

            for (iCS_EditorObject op = outGrandParent.ParentNode; op != null; op = op.ParentNode)
            {
                if (inGrandParent == op)
                {
                    inParentSeen = true;
                    break;
                }
            }
            if (!inParentSeen && inGrandParent != null)
            {
                var sourcePort           = inPort.ProducerPort;
                iCS_EditorObject newPort = null;
                // Attempt to reuse existing ports.
                if (sourcePort != null && sourcePort.ParentNode == inGrandParent && conversion == null)
                {
                    newPort = sourcePort;
                }
                else
                {
                    newPort = CreatePort(inPort.DisplayName, inGrandParent.InstanceId, outPort.RuntimeType, VSObjectType.InDynamicDataPort);
                    SetSource(inPort, newPort, conversion);
                    SetBestPositionForAutocreatedPort(newPort, inPort.GlobalPosition, outPort.GlobalPosition);
                }
                SetNewDataConnection(newPort, outPort);
                OptimizeDataConnection(inPort, outPort);
                return;
            }
            // Create outPort if outParent is not part of the inParent hierarchy.
            bool outParentSeen = false;

            for (iCS_EditorObject ip = inGrandParent.ParentNode; ip != null; ip = ip.ParentNode)
            {
                if (outGrandParent == ip)
                {
                    outParentSeen = true;
                    break;
                }
            }
            if (!outParentSeen && outGrandParent != null)
            {
                // Attempt to reuse existing port.
                iCS_EditorObject newPort = null;
                if (conversion == null &&
                    outGrandParent.UntilMatchingChild(
                        p => {
                    if (p.IsPort && p.ProducerPort == outPort)
                    {
                        newPort = p;
                        return(true);
                    }
                    return(false);
                }
                        )
                    )
                {
                }
                else
                {
                    newPort = CreatePort(outPort.DisplayName, outGrandParent.InstanceId, outPort.RuntimeType, VSObjectType.OutDynamicDataPort);
                    SetSource(newPort, outPort, conversion);
                    SetBestPositionForAutocreatedPort(newPort, inPort.GlobalPosition, outPort.GlobalPosition);
                }
                SetNewDataConnection(inPort, newPort);
                OptimizeDataConnection(inPort, outPort);
                return;
            }
            // Should never happen ... just connect the ports.
            SetSource(inPort, outPort, conversion);
            OptimizeDataConnection(inPort, outPort);
        }
 // ----------------------------------------------------------------------
 public bool DoesPortExist(iCS_EditorObject node, string portName, Type valueType, VSObjectType portType)
 {
     return(node.UntilMatchingChild(p => p.DisplayName == portName && p.ObjectType == portType && p.RuntimeType == valueType));
 }