Ejemplo n.º 1
0
 /// <summary>
 /// Este metodo es llamado cuando una conexion debe ser pintada.
 /// </summary>
 /// <param name="gr">Objeto Graphics utilizado para pintar.</param>
 /// <param name="connection">La conexion que se quiere visualizar.</param>
 protected virtual void DrawConnection(Graphics gr, Connection connection)
 {
     if (connection.To != null)
     DrawFreeConnection(gr, connection, connection.To.Position, connection.To.Orientation);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Permite agregar una nueva conexion al conjunto de conexiones de este elemento.
        /// </summary>
        /// <param name="outputPinIndex">Indice del pin de salida a partir del cual sale la conexion (varias conexiones pueden salir del mismo pin).</param>
        /// <param name="label">Etiqueta de texto para la conexion.</param>
        protected void AddConnection(int outputPinIndex, string label)
        {
            Connection newConnection = new Connection(ValidOutputs[outputPinIndex], null);
             newConnection.Label = label;

             _Connections.Add(newConnection);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Este metodo se llama cuando se desea pintar una conexion que está "suelta" hasta un punto.
 /// </summary>
 /// <param name="gr">Objeto Graphics utilizado para pintar.</param>
 /// <param name="connection">Conexion que se desea visualizar.</param>
 /// <param name="freePoint">Punto de llegada de la conexion.</param>
 /// <param name="orientation">Orientacion por la que se quiere llegar la linea. Digamos, que la linea llegue al punto final viniendo de arriba.</param>
 protected internal virtual void DrawFreeConnection(Graphics gr, Connection connection, Point freePoint, PinOrientation orientation)
 {
     DrawDirectConnector(gr, connection.From.Position, freePoint, true);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Accion que se produce cuando se selecciona una conexion.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void item_Click(object sender, EventArgs e)
 {
     var item = sender as MenuItem;
      // recuperar la conexion de la propiedad Tag.
      var connection = item.Tag as Connection;
      modifyingConnection = connection;
      isConnecting = true;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Metodo que se invoca cuando se presiona un boton del mouse.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            lastMousePlace = FromClientToCanvas(e.Location);

             ChartElement nextSelected = null;

             foreach (ChartElement c in Charts)
            if (c.Display.Contains(FromClientToCanvas(e.Location)))
               nextSelected = c;

             if (SelectedItem != null) SelectedItem.Selected = false;
             SelectedItem = nextSelected;
             if (SelectedItem != null) SelectedItem.Selected = true;

             if (e.Button == MouseButtons.Right)
             {
            isConnecting = false;
            modifyingConnection = null;

            if (SelectedItem != null)
            {
               ContextMenu cm = GetContextMenuFor(SelectedItem);
               ContextMenu = cm;
            }
            else
            {
               ContextMenu cm = GetGlobalContextMenu(FromClientToCanvas(e.Location));
               ContextMenu = cm;
            }
             }
             else
             {
            if (isConnecting)
            {
               Pin nearestInput = null;
               if (SelectedItem != null)
                  foreach (Pin input in SelectedItem.ValidInputs)
                     if (nearestInput == null ||
                         Distance(input.Position, FromClientToCanvas(e.Location)) <
                         Distance(nearestInput.Position, FromClientToCanvas(e.Location)))
                        nearestInput = input;

               modifyingConnection.To = nearestInput;
               isConnecting = false;
               modifyingConnection = null;
            }
             }

             Invalidate();

             base.OnMouseDown(e);
        }
        /// <summary>
        /// Metodo que se invoca cuando se presiona un boton del mouse.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            lastMousePlace = FromClientToCanvas (e.Location);

            ChartElement nextSelected = null;

            foreach (ChartElement c in Charts)
                if (c.Display.Contains(FromClientToCanvas(e.Location)))
                    nextSelected = c;

            if (SelectedItem != null) SelectedItem.Selected = false;
            SelectedItem = nextSelected;
            if (SelectedItem != null) SelectedItem.Selected = true;

            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                isConnecting = false;
                modifyingConnection = null;

                if (SelectedItem != null)
                {
                    ContextMenu cm = GetContextMenuFor(SelectedItem);
                    this.ContextMenu = cm;
                }
                else
                {
                    ContextMenu cm = GetGlobalContextMenu(FromClientToCanvas(e.Location));
                    this.ContextMenu = cm;
                }
            }
            else
            {
                if (isConnecting)
                {
                    Pin nearestInput = null;
                    if (SelectedItem != null)
                        foreach (Pin input in SelectedItem.ValidInputs)
                            if (nearestInput == null || Distance(input.Position, FromClientToCanvas (e.Location)) < Distance(nearestInput.Position, FromClientToCanvas (e.Location)))
                                nearestInput = input;

                    var before = modifyingConnection.To;
                  
                    modifyingConnection.To = nearestInput;
                    if(nearestInput!=null) //le pongo el padre
                    {
                        ((BayesianNodeChartElement) nearestInput.ChartElement).Parents.Add((BayesianNodeChartElement)modifyingConnection.From.ChartElement);
                        ((BayesianNodeChartElement) nearestInput.ChartElement).Condicional_Probabilities = null;
                    }
                    if (before != null )//le quito el antiguo padre
                    {
                        ((BayesianNodeChartElement) before.ChartElement).Parents.Remove(
                            modifyingConnection.From.ChartElement as BayesianNodeChartElement);
                        ((BayesianNodeChartElement) before.ChartElement).Condicional_Probabilities = null;
                    }
                   

                    isConnecting = false;
                    modifyingConnection = null;
                }
            }

            Invalidate();

            base.OnMouseDown(e);
        }