예제 #1
0
 // ----------------------------------------------------------------------
 public static void Select(iCS_EditorObject obj, iCS_IStorage iStorage)
 {
     if (obj == iStorage.SelectedObject)
     {
         return;
     }
     OpenTransaction(iStorage);
     try {
         iStorage.SelectedObject = obj;
         if (obj != null && obj.IsNode && obj.IsParentOf(iStorage.DisplayRoot))
         {
             iCS_UserCommands.SetAsDisplayRoot(obj);
         }
     }
     catch (System.Exception) {
         CancelTransaction(iStorage);
         return;
     }
     CloseTransaction(iStorage, "Select " + obj.DisplayName);
 }
예제 #2
0
 // ======================================================================
 // Connections
 // ----------------------------------------------------------------------
 void DisplayConnections(iCS_EditorObject rootNode)
 {
     IStorage.ForEachRecursiveDepthLast(rootNode,
                                        child => {
         if (child.IsPort)
         {
             var parent    = child.ParentNode;
             var source    = child.ProducerPort;
             var srcParent = source != null ? source.ParentNode : null;
             if (!IStorage.ShowDisplayRootNode)
             {
                 if (parent == rootNode)
                 {
                     return;
                 }
                 if (source != null)
                 {
                     if (srcParent == rootNode)
                     {
                         return;
                     }
                 }
             }
             else
             {
                 if (srcParent != rootNode && !rootNode.IsParentOf(srcParent))
                 {
                     return;
                 }
             }
             if (!parent.IsParentFloating)
             {
                 myGraphics.DrawBinding(child, IStorage);
             }
         }
     }
                                        );
 }
        // ----------------------------------------------------------------------
        bool VerifyNewConnection(iCS_EditorObject fixPort, iCS_EditorObject overlappingPort)
        {
            // Only data ports can be connected together.
            if (!fixPort.IsDataOrControlPort || !overlappingPort.IsDataOrControlPort)
            {
                return(false);
            }

            // Verify for output Mux port creation
            iCS_EditorObject portParent            = fixPort.Parent;
            iCS_EditorObject overlappingPortParent = overlappingPort.Parent;

            if (IsMuxPortKeyDown && overlappingPort.ProducerPort != null)
            {
                // Mux output port creation
                if (overlappingPort.IsOutputPort &&
                    overlappingPort.IsDynamicDataPort &&
                    !overlappingPortParent.IsInstanceNode)
                {
                    var provideNode = overlappingPort.ProducerPort.ParentNode;
                    if (overlappingPortParent.IsParentOf(provideNode) &&
                        overlappingPortParent.IsParentOf(portParent))
                    {
                        CreateMuxPort(fixPort, overlappingPort);
                        return(true);
                    }
                }
                // Mux input port creation
                if (overlappingPort.IsInputPort &&
                    overlappingPort.IsDynamicDataPort)
                {
                    if (!overlappingPortParent.IsParentOf(portParent))
                    {
                        CreateMuxPort(fixPort, overlappingPort);
                        return(true);
                    }
                }
            }

            // Connect function & modules ports together.
            iCS_EditorObject inPort  = null;
            iCS_EditorObject outPort = null;

            bool portIsChildOfOverlapping = IStorage.IsChildOf(portParent, overlappingPortParent);
            bool overlappingIsChildOfPort = IStorage.IsChildOf(overlappingPortParent, portParent);

            if (portIsChildOfOverlapping || overlappingIsChildOfPort)
            {
                if (fixPort.IsInputPort && overlappingPort.IsInputPort)
                {
                    if (portIsChildOfOverlapping)
                    {
                        inPort  = fixPort;
                        outPort = overlappingPort;
                    }
                    else
                    {
                        inPort  = overlappingPort;
                        outPort = fixPort;
                    }
                }
                else if (fixPort.IsOutputPort && overlappingPort.IsOutputPort)
                {
                    if (portIsChildOfOverlapping)
                    {
                        inPort  = overlappingPort;
                        outPort = fixPort;
                    }
                    else
                    {
                        inPort  = fixPort;
                        outPort = overlappingPort;
                    }
                }
                else
                {
                    ShowNotification(new GUIContent("Cannot connect nested node ports from input to output !!!"));
                    return(true);
                }
            }
            else
            {
                inPort  = fixPort.IsInputPort          ? fixPort : overlappingPort;
                outPort = overlappingPort.IsOutputPort ? overlappingPort : fixPort;
            }
            if (inPort != outPort)
            {
                LibraryFunction conversion = null;
                if (VerifyConnectionTypes(inPort, outPort, out conversion))
                {
                    IStorage.SetAndAutoLayoutNewDataConnection(inPort, outPort, conversion);
                }
            }
            else
            {
                string direction = inPort.IsInputPort ? "input" : "output";
                ShowNotification(new GUIContent("Cannot connect an " + direction + " port to an " + direction + " port !!!"));
            }
            return(true);
        }