/// <summary>
        /// Initializes a new instance of the <see cref="ConnectionCreationBehavior"/> class.
        /// </summary>
        /// <param name="pParent">The behavior parent view.</param>
        /// <param name="pWorkingCanvas">The canvas containing the connection line to work with.</param>
        public ConnectionCreationBehavior(SimpleGraphView pParent, Canvas pWorkingCanvas)
            : base(pParent)
        {
            this.WorkingCanvas = pWorkingCanvas;
            this.WorkingCanvas.Visibility = Visibility.Collapsed;
            this.ConnectingLine.Visibility = Visibility.Collapsed;

            this.mSourceConnector = null;
            this.mTargetConnector = null;
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConnectingLineAdorner"/> class.
        /// </summary>
        /// <param name="pElement">The parent element.</param>
        /// <param name="pSourceConnector">The source connector.</param>
        public ConnectingLineAdorner(UIElement pElement, OutputConnector pSourceConnector)
            : base(pElement)
        {
            this.Cursor = Cursors.Cross;
            this.mSourceConnector = pSourceConnector;

            // Creating the line contained in the adorner.
            this.mVisualChildren = new VisualCollection(this);
            this.mVisualChildren.Add(new ConnectingLine() { From = pSourceConnector.Position });
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConnectingLineAdorner"/> class.
        /// </summary>
        /// <param name="pElement">The parent element.</param>
        /// <param name="pSourceConnector">The source connector.</param>
        public ConnectingLineAdorner(UIElement pElement, OutputConnector pSourceConnector)
            : base(pElement)
        {
            this.Cursor           = Cursors.Cross;
            this.mSourceConnector = pSourceConnector;

            // Creating the line contained in the adorner.
            this.mVisualChildren = new VisualCollection(this);
            this.mVisualChildren.Add(new ConnectingLine()
            {
                From = pSourceConnector.Position
            });
        }
        /// <summary>
        /// Starts the connection creation process from the given source connector.
        /// </summary>
        /// <param name="pSource">The source connector.</param>
        public void StartCreation(OutputConnector pSource)
        {
            // Updating the source.
            this.mSourceConnector = pSource;

            // Making the working canvas visible and updating the line position.
            this.ConnectingLine.From = this.mSourceConnector.Position;
            this.ConnectingLine.To = this.mSourceConnector.Position;
            this.WorkingCanvas.Visibility = Visibility.Visible;
            this.ConnectingLine.Visibility = Visibility.Visible;

            // Listening to the mouse move and up of the canvas to update the line.
            this.WorkingCanvas.CaptureMouse();
            this.WorkingCanvas.MouseMove -= this.OnWorkingCanvasMouseMove;
            this.WorkingCanvas.MouseMove += this.OnWorkingCanvasMouseMove;
            this.WorkingCanvas.MouseUp -= this.OnWorkingCanvasMouseUp;
            this.WorkingCanvas.MouseUp += this.OnWorkingCanvasMouseUp;
        }
        /// <summary>
        /// Delegate called when the mouse isup on the working canvas.
        /// </summary>
        /// <param name="pSender">The event sender.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private void OnWorkingCanvasMouseUp(object pSender, MouseButtonEventArgs pEventArgs)
        {
            // Release the mouse capture.
            this.WorkingCanvas.ReleaseMouseCapture();
            this.WorkingCanvas.MouseMove -= this.OnWorkingCanvasMouseMove;
            this.WorkingCanvas.MouseUp -= this.OnWorkingCanvasMouseUp;
            this.WorkingCanvas.Visibility = Visibility.Collapsed;
            this.ConnectingLine.Visibility = Visibility.Collapsed;

            // Trying to create the final connection.
            if (this.mSourceConnector != null && this.mTargetConnector != null)
            {
                // Both defined means the connection can be created. Test have been made in the mouse move event handler.
                GraphViewModel lGraphViewModel = this.ParentView.DataContext as GraphViewModel;
                if (lGraphViewModel == null)
                {
                    return;
                }

                PortViewModel lSourceViewModel = this.mSourceConnector.ParentPort.Content as PortViewModel;
                PortViewModel lTargetViewModel = this.mTargetConnector.ParentPort.Content as PortViewModel;

                ConnectionViewModel lConnectionViewModel = new ConnectionViewModel();
                lConnectionViewModel.Output = lSourceViewModel;
                lConnectionViewModel.Input = lTargetViewModel;
                lGraphViewModel.AddConnection(lConnectionViewModel);
            }

            // Forget the reference on connectors.
            this.mSourceConnector = null;
            this.mTargetConnector = null;
        }