/// <summary> /// Método que dibuja una conexión en un panel específico /// </summary> /// <param name="drawArea">Panel en donde se va a dibujar la conexión</param> public void DrawConnection(Panel drawArea) { if (drawArea == null) { throw new ArgumentNullException("drawArea", "drawArea can not be null"); } ConnectionPointWpf source = this.Source as ConnectionPointWpf; ConnectionPointWpf target = this.Target as ConnectionPointWpf; Canvas canvas = new Canvas(); LineGeometry myLineGeometry = new LineGeometry(); Point fromPoint, toPoint; fromPoint = source.UIElement.TranslatePoint(source.CentralPoint, drawArea); toPoint = target.UIElement.TranslatePoint(target.CentralPoint, drawArea); myLineGeometry.StartPoint = fromPoint; myLineGeometry.EndPoint = toPoint; System.Windows.Shapes.Path myPath = new System.Windows.Shapes.Path(); myPath.Stroke = Brushes.Black; myPath.StrokeThickness = 4; myPath.Data = myLineGeometry; canvas.Children.Add(myPath); canvas.MouseRightButtonUp += new System.Windows.Input.MouseButtonEventHandler(myCanvas_MouseRightButtonUp); GenerateContextMenu(canvas); this.MyCanvas = canvas; drawArea.Children.Insert(0, canvas); }
/// <summary> /// Función que contruye un canvas para el FormMenuItemWpf. /// </summary> public void MakeCanvas() { ConnectionPointWpf outputConnectionPoint = this.OutputConnectionPoint as ConnectionPointWpf; outputConnectionPoint.MakeCanvas(); // Agrega los eventos a los puntos de conexión. if (!ConnectionPointClickAttached) { ConnectionPointClickAttached = true; outputConnectionPoint.Click += new EventHandler(outputConnectionPoint_Click); } // Crea el grupo de canvas Canvas groupItemCanvas = Utilities.CanvasFromXaml("CanvasMenuItem.xaml"); groupItemCanvas.Width = this.Width; groupItemCanvas.Height = this.Height; // Agrega los hijos al canvas groupItemCanvas.Children.Add(outputConnectionPoint.MyCanvas); ((TextBlock)groupItemCanvas.FindName("Label")).Text = this.Text; Canvas.SetLeft(outputConnectionPoint.MyCanvas, groupItemCanvas.Width); Canvas.SetTop(outputConnectionPoint.MyCanvas, groupItemCanvas.Height / 4); this.myCanvas = groupItemCanvas; }
/// <summary> /// Contructor. /// </summary> /// <param name="from">ConnectionPoint origen del ConnectionWpf</param> /// <param name="target">ConnectionPoint destino del ConnectionWpf</param> public ConnectionWpf(ConnectionPointWpf from, ConnectionPointWpf target) : base(from, target) { if (from == null) { throw new ArgumentNullException("from", "from can not be null"); } if (target == null) { throw new ArgumentNullException("target", "target can not be null"); } }
/// <summary> /// Función llamada cuando se presiona un punto de conexión /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void myWidget_ConnectionClick(object sender, ConnectionPointClickEventArgs e) { if (IsMakeConnectionAction) { Component tempComponent = sender as Component; ConnectionPointWpf connectionPoint = e.ConnectionPoint as ConnectionPointWpf; // Si es una conexión if (ConnectionWidgetFrom == null) { Error errorSingleOutput = VerifySingleOutputConnection(tempComponent); if (errorSingleOutput != null) { Util.ShowErrorDialog(errorSingleOutput.Description, UtnEmall.ServerManager.Properties.Resources.ConnectionErrors); return; } ConnectionWidgetFrom = tempComponent; ConnectionPointFrom = connectionPoint; windowsDesigner.textBlockStatusBar.Text = UtnEmall.ServerManager.Properties.Resources.SelectFormTargetConnection; return; } // // else { ConnectionWidgetTarget = tempComponent; ConnectionPointTarget = connectionPoint; Error connectionError = CheckDuplicatedConnection(); if (connectionError != null) { Util.ShowErrorDialog(connectionError.Description, "Error"); windowsDesigner.textBlockStatusBar.Text = "."; isMakeConnectionAction = false; return; } Collection <Error> connectionErrors = CheckConnection(); if (connectionErrors.Count > 0) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.ConnectionErrors, connectionErrors); windowsDesigner.textBlockStatusBar.Text = "."; isMakeConnectionAction = false; return; } Collection <Error> errors = VerifyConnection(); if (errors.Count > 0) { Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.ConnectionErrors, errors); windowsDesigner.textBlockStatusBar.Text = "."; windowsDesigner.textBlockStatusBar.UpdateLayout(); isMakeConnectionAction = false; return; } CreateConnection(); RedrawConnections(); isMakeConnectionAction = false; windowsDesigner.textBlockStatusBar.Text = "."; } } }
/// <summary> ///Constructor. /// </summary> /// <param name="text">Texto a mostrarse en el FormMenuItemWpf.</param> /// <param name="name">Fuente del FormMenuItemWpf.</param> public FormMenuItemWpf(string text, string help, FontName name) : base(text, help, name) { OutputConnectionPoint = new ConnectionPointWpf(ConnectionPointType.Output, this); }