/// <summary>
        /// Handles the creation of a new connection. It does not allow a connection
        /// from a intput connector to a output connector (it must be other way around)
        /// </summary>
        /// <param name="Sender">Sender of the event</param>
        /// <param name="e">Event parameters</param>
        /// <returns>
        /// If true, the connection is added by the Netron library,
        /// otherwise no connection is added
        /// </returns>
        /// <remarks>
        /// Little trick is used with checking if the connection has the right direction
        /// (from output to input). Because the output connector in Ferda is always
        /// Connection type and the input connector is always FerdaConnector type, we can
        /// check it by is
        /// </remarks>
        protected bool FerdaDesktop_OnNewConnection(object Sender, ConnectionEventArgs e)
        {
            //checking if the connection has the right direction
            if (e.From is FerdaConnector)
            {
                //a message is throw to the user
                //MessageBox.Show(ResManager.GetString("DesktopBadConnectionDescription"),
                //    ResManager.GetString("DesktopBadConnectionCaption"));
                return false;
            }
            if (!(e.To is FerdaConnector))
            {
                //a message is throw to the user
                MessageBox.Show(ResManager.GetString("DesktopBadConnectionDescription"),
                    ResManager.GetString("DesktopBadConnectionCaption"));
                return false;
            }

            //I have the right connection and now I am checking the type consistency
            IBoxModule fromBox = ((BoxNode)e.From.BelongsTo).Box;
            IBoxModule toBox = ((BoxNode)e.To.BelongsTo).Box;
            Modules.SocketInfo toSocket = ((FerdaConnector)e.To).Socket;

            //checking the good socket Types
            Modules.BoxType [] goodBoxTypes = toSocket.socketType;

            bool contains = false;
            foreach (Modules.BoxType boxType in goodBoxTypes)
            {
                if (fromBox.HasBoxType(boxType))
                {
                    contains = true;
                    break;
                }
            }

            if (contains)
            {
                //adding the connection to the ProjectManager
                if (toBox.TryWriteEnter())
                {
                    try
                    {
                        toBox.SetConnection(toSocket.name, fromBox);
                    }
                    catch (BadTypeError)
                    {
                        //showing the messageBox
                        MessageBox.Show(ResManager.GetString("DesktopBadConnectionInvalidType"),
                            ResManager.GetString("DesktopBadConnectionCaption"));
                        toBox.WriteExit();
                        return false;
                    }
                    catch (ConnectionExistsError)
                    {
                        //showing the messageBox
                        MessageBox.Show(ResManager.GetString("DesktopMoreThanOneErrorText"),
                            ResManager.GetString("DesktopBadConnectionCaption"));
                        toBox.WriteExit();
                        return false;
                    }
                    toBox.WriteExit();
                }
                else
                {
                    FrontEndCommon.CannotWriteToBox(toBox, ResManager);
                    return false;
                }
            }
            else
            {
                //showing the messageBox
                MessageBox.Show(ResManager.GetString("DesktopBadConnectionInvalidType"),
                    ResManager.GetString("DesktopBadConnectionCaption"));
                return false;
            }

            RefreshBoxNames();
            archiveDisplayer.Adapt();
            return true;
        }
Beispiel #2
0
 private bool graphControl1_OnNewConnection(object sender, Netron.GraphLib.ConnectionEventArgs e)
 {
     return(true);
 }
 private bool mConnections_OnConnectionRemoved(object sender, ConnectionEventArgs e)
 {
     this.paintables.Remove(e.Connection);
     this.SortPaintables();
     return(true);
 }