private void CreateGraph()
    {
        m_graphView      = new SimpleGraphView();
        m_graphView.name = "simple graph view";
        m_graphView.StretchToParentSize();
        m_graphView.SetEnabled(true);

        this.rootVisualElement.Add(m_graphView);
    }
        /// <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;
        }
        /// <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;
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxSelectionBehavior"/> class.
        /// </summary>
        /// <param name="pParent">The behavior parent view.</param>
        /// <param name="pSelectionBoxCanvas">The canvas containing the box.</param>
        public BoxSelectionBehavior(SimpleGraphView pParent, Canvas pSelectionBoxCanvas)
            : base(pParent)
        {
            this.SelectionBoxCanvas = pSelectionBoxCanvas;
            this.SelectionBoxCanvas.Visibility = Visibility.Collapsed;
            this.SelectionBox.Visibility = Visibility.Collapsed;

            this.mIsLeftMouseButtonDownOnView = false;
            this.mIsDraggingSelectionBox = false;
            this.DragThreshold = 0.1;

            // Registering on the event used to draw the box.
            this.ParentView.MouseDown += this.OnParentViewMouseDown;
            this.ParentView.MouseMove += this.OnParentViewMouseMove;
            this.ParentView.MouseUp += this.OnParentViewMouseUp;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxSelectionBehavior"/> class.
        /// </summary>
        /// <param name="pParent">The behavior parent view.</param>
        /// <param name="pSelectionBoxCanvas">The canvas containing the box.</param>
        public BoxSelectionBehavior(SimpleGraphView pParent, Canvas pSelectionBoxCanvas)
            : base(pParent)
        {
            this.SelectionBoxCanvas            = pSelectionBoxCanvas;
            this.SelectionBoxCanvas.Visibility = Visibility.Collapsed;
            this.SelectionBox.Visibility       = Visibility.Collapsed;

            this.mIsLeftMouseButtonDownOnView = false;
            this.mIsDraggingSelectionBox      = false;
            this.DragThreshold = 0.1;

            // Registering on the event used to draw the box.
            this.ParentView.MouseDown += this.OnParentViewMouseDown;
            this.ParentView.MouseMove += this.OnParentViewMouseMove;
            this.ParentView.MouseUp   += this.OnParentViewMouseUp;
        }
Example #6
0
        /// <summary>
        /// Releases the dragged item as the drag process ends.
        /// </summary>
        private static void ReleaseDraggedItem()
        {
            if (sDraggedItem == null)
            {
                return;
            }

            SimpleGraphView lParentCanvas = sDraggedItem.FindVisualParent <SimpleGraphView>();

            if (lParentCanvas == null)
            {
                return;
            }

            lParentCanvas.MouseMove -= OnParentCanvasMouseMove;
            lParentCanvas.MouseUp   -= OnParentCanvasMouseUp;

            sDraggedItem.ReleaseMouseCapture();
            sDraggedItem  = null;
            sDragStartPos = null;
        }
Example #7
0
        /// <summary>
        /// Handles the mouse move event when the drag process is started.
        /// </summary>
        /// <param name="pEventArgs">The mouse move event arguments.</param>
        private static void HandleDragItem(MouseEventArgs pEventArgs)
        {
            if (sDraggedItem == null)
            {
                return;
            }

            SimpleGraphView lParentCanvas = sDraggedItem.FindVisualParent <SimpleGraphView>();

            if (lParentCanvas == null)
            {
                return;
            }

            if (sDragStartPos != null && sDraggedItem != null && pEventArgs.LeftButton == MouseButtonState.Pressed)
            {
                Point lCanvasPos  = pEventArgs.GetPosition(lParentCanvas);
                Point lNewItemPos = new Point(lCanvasPos.X - sDragStartPos.Value.X, lCanvasPos.Y - sDragStartPos.Value.Y);
                sDraggedItem.SetCanvasPosition(lNewItemPos);
            }
        }
Example #8
0
        /// <summary>
        /// Delegate called when the mouse is down on a graph view item.
        /// </summary>
        /// <param name="pSender">The item of interest.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private static void OnItemMouseDown(object pSender, MouseButtonEventArgs pEventArgs)
        {
            AGraphItem lItem = pSender as AGraphItem;

            if (lItem == null)
            {
                return;
            }

            SimpleGraphView lParentCanvas = lItem.FindVisualParent <SimpleGraphView>();

            if (lParentCanvas == null)
            {
                return;
            }

            // Sometimes the mouse goes faster than the item. Its up to the canvas then to continue the drag
            lParentCanvas.MouseMove += OnParentCanvasMouseMove;
            lParentCanvas.MouseUp   += OnParentCanvasMouseUp;

            sDraggedItem  = lItem;
            sDragStartPos = pEventArgs.GetPosition(lItem);
            lItem.CaptureMouse();
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AGraphViewBehavior"/> class.
 /// </summary>
 /// <param name="pParent">The behavior parent view.</param>
 protected AGraphViewBehavior(SimpleGraphView pParent)
 {
     this.ParentView = pParent;
 }
Example #10
0
        /// <summary>
        /// Method called when the control template is applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // Getting the parts of the control.
            this.mZoomAndPanControl = this.GetTemplateChild(PART_ZOOM_AND_PAN_CONTROL) as TooledZoomAndPanControl;
            this.mSimpleGraphView = this.GetTemplateChild(PART_SIMPLE_GRAPH_VIEW) as SimpleGraphView;
            this.mOverview = this.GetTemplateChild(PART_OVERVIEW) as SimpleGraphView;

            if (this.mZoomAndPanControl == null || this.mSimpleGraphView == null || this.mOverview == null)
            {
                throw new Exception("GraphView control template not correctly defined.");
            }

            this.mSimpleGraphView.SelectionChanged += this.OnSimpleGraphViewSelectionChanged;
        }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AGraphViewBehavior"/> class.
 /// </summary>
 /// <param name="pParent">The behavior parent view.</param>
 protected AGraphViewBehavior(SimpleGraphView pParent)
 {
     this.ParentView = pParent;
 }