예제 #1
0
        /// <summary>
        /// Delegate called when the control is initialized.
        /// </summary>
        /// <param name="pEventArgs">The event arguments.</param>
        protected override void OnInitialized(EventArgs pEventArgs)
        {
            NodeViewModel lNodeViewModel = this.DataContext as NodeViewModel;

            if (lNodeViewModel == null)
            {
                return;
            }

            SimpleGraphView lParentGraphView = this.FindVisualParent <SimpleGraphView>();

            if (lParentGraphView == null)
            {
                return;
            }

            NodeView lNodeView = lParentGraphView.GetContainerForViewModel <NodeViewModel, NodeView>(lNodeViewModel);

            if (lNodeView != null)
            {
                AdornerLayeredCanvas lCanvas = this.FindVisualParent <AdornerLayeredCanvas>();
                if (lCanvas != null)
                {
                    // Creating the adorner layer.
                    AdornerLayer lLayer = lCanvas.AdornerLayer;

                    // Adding the adorner to the layer.
                    lLayer.Add(new InfosAdorner(lNodeView));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Delegate called when the control is initialized.
        /// </summary>
        /// <param name="pEventArgs">The event arguments.</param>
        protected override void OnInitialized(EventArgs pEventArgs)
        {
            PortViewModel lPortViewModel = this.DataContext as PortViewModel;

            if (lPortViewModel == null)
            {
                return;
            }

            PortContainer lParentContainer = this.FindVisualParent <PortContainer>();

            if (lParentContainer == null)
            {
                return;
            }

            PortView lPortView = lParentContainer.GetContainerForViewModel(lPortViewModel);

            if (lPortView != null)
            {
                AdornerLayeredCanvas lCanvas = this.FindVisualParent <AdornerLayeredCanvas>();
                if (lCanvas != null)
                {
                    // Creating the adorner layer.
                    AdornerLayer lLayer = lCanvas.AdornerLayer;

                    // Creating the adorner and propagating this control background.
                    this.mAdorner = new ConnectorAdorner(lPortView);
                    this.UpdateConnectorsBackground();

                    // Adding the adorner to the layer.
                    lLayer.Add(this.mAdorner);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// This method is called when the layout changes.
        /// </summary>
        /// <param name="pSender">The event sender.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private void OnLayoutUpdated(object pSender, EventArgs pEventArgs)
        {
            AdornerLayeredCanvas lParentCanvas = this.FindVisualParent <AdornerLayeredCanvas>();

            if (lParentCanvas != null)
            {
                // Get centre position of this Connector relative to the DesignerCanvas.
                this.Position = this.TransformToVisual(lParentCanvas.AdornerLayer).Transform(new Point(this.ActualWidth / 2, this.ActualHeight / 2));
            }
        }
예제 #4
0
        /// <summary>
        /// This method is called when a mouse button up occured on the adorner.
        /// </summary>
        /// <param name="pEventArgs">The event arguments</param>
        protected override void OnMouseUp(MouseButtonEventArgs pEventArgs)
        {
            // Release the mouse capture.
            if (this.IsMouseCaptured)
            {
                this.ReleaseMouseCapture();
            }

            // Getting the position.
            Point lHitPoint = pEventArgs.GetPosition(this);

            AdornerLayeredCanvas lParentCanvas = this.AdornedElement as AdornerLayeredCanvas;

            if (lParentCanvas != null)
            {
                // Remove the adorner.
                AdornerLayer lLayer = lParentCanvas.AdornerLayer;
                if (lLayer != null)
                {
                    lLayer.Remove(this);
                }

                // Hitting the target connector.
                InputConnector lTargetConnector = lParentCanvas.HitControl <InputConnector>(lHitPoint);
                if (lTargetConnector != null)
                {
                    GraphViewModel lGraphViewModel = lParentCanvas.DataContext as GraphViewModel;
                    if (lGraphViewModel != null)
                    {
                        PortViewModel lTargetViewModel = lTargetConnector.ParentPort.Content as PortViewModel;
                        PortViewModel lSourceViewModel = this.mSourceConnector.ParentPort.Content as PortViewModel;
                        if (lTargetViewModel != null && lSourceViewModel.CanBeConnectedTo(lTargetViewModel))
                        {
                            ConnectionViewModel lConnectionViewModel = new ConnectionViewModel();
                            lConnectionViewModel.Output = lSourceViewModel;
                            lConnectionViewModel.Input  = lTargetViewModel;
                            lGraphViewModel.AddConnection(lConnectionViewModel);
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Delegate called when the control is initialized.
        /// </summary>
        /// <param name="pEventArgs">The event arguments.</param>
        protected override void OnInitialized(EventArgs pEventArgs)
        {
            // The adorned port view is given to the control by the DataContext property.
            PortView lPortView = this.DataContext as PortView;

            if (lPortView != null)
            {
                AdornerLayeredCanvas lCanvas = this.FindVisualParent <AdornerLayeredCanvas>();
                if (lCanvas != null)
                {
                    // Creating the adorner layer.
                    AdornerLayer lLayer = lCanvas.AdornerLayer;

                    // Creating the adorner and propagating this control background.
                    this.Adorner = new ConnectorsAdorner(lPortView);
                    this.UpdateConnectorsBackground();

                    // Adding the adorner to the layer.
                    lLayer.Add(this.Adorner);
                }
            }
        }
예제 #6
0
 /// <summary>
 /// Delegate called when this control is loaded.
 /// </summary>
 /// <param name="pSender">The event sender.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 private void OnLoaded(object pSender, RoutedEventArgs pEventArgs)
 {
     this.mDrawingArea = this.FindVisualChild <AdornerLayeredCanvas>("PART_DrawingArea");
 }