private void UpdateSelection(Collection <ISelectable> itemsToSelect, Rect rubberBand, DiagramDesignerCanvas dCanvas)
        {
            foreach (Control item in dCanvas.Children)
            {
                Rect itemRect   = VisualTreeHelper.GetDescendantBounds(item);
                Rect itemBounds = item.TransformToAncestor(designerCanvas).TransformBounds(itemRect);

                // drag decorator requires this;
                itemBounds.Inflate(-DragDecoratorInflateValue, -DragDecoratorInflateValue);

                if (rubberBand.Contains(itemBounds))
                {
                    if (item is ISelectable)
                    {
                        itemsToSelect.Add(item as ISelectable);
                    }
                }

                if (item is DiagramDesignerItem)
                {
                    DiagramDesignerItem designerItem = item as DiagramDesignerItem;
                    if (designerItem.IsDiagramLink)
                    {
                        continue;
                    }

                    DiagramDesignerCanvas canvas = DiagramHelper.GetChild(designerItem, typeof(DiagramDesignerCanvas)) as DiagramDesignerCanvas;
                    if (canvas != null)
                    {
                        UpdateSelection(itemsToSelect, rubberBand, canvas);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Process selection operation
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            // if mouse button is not pressed we have no drag operation, ...
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.dragStartPoint = null;
            }

            // but if mouse button is pressed and start point value is set we do have one
            if (this.dragStartPoint.HasValue)
            {
                // create connection adorner
                DiagramDesigner designer = DiagramHelper.GetDiagramDesigner(this);
                if (designer != null)
                {
                    AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(designer);
                    if (adornerLayer != null)
                    {
                        DiagramConnectorAdorner adorner = new DiagramConnectorAdorner(designer, this, this.dragStartPoint.Value);
                        if (adorner != null)
                        {
                            adornerLayer.Add(adorner);
                            e.Handled = true;
                        }
                    }
                }
            }
        }
예제 #3
0
        private static void IsSelectedPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            DiagramDesignerItem item = obj as DiagramDesignerItem;

            if (item.DataContext != null)
            {
                if (item != null)
                {
                    DiagramDesigner designer = DiagramHelper.GetDiagramDesigner(item) as DiagramDesigner;
                    if (designer != null)
                    {
                        if ((bool)args.NewValue)
                        {
                            if (!designer.SelectionService.CurrentSelection.Contains(item))
                            {
                                designer.SelectionService.AddToSelection(item, false);
                            }

                            if (item.IsSelected && !item.IsFocused)
                            {
                                item.Focus();
                            }
                        }
                        else
                        {
                            if (designer.SelectionService.CurrentSelection.Contains(item))
                            {
                                designer.SelectionService.RemoveFromSelection(item, false);
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Updates the selection for this item.
        /// </summary>
        /// <param name="bSelect">True if this item should be selected; false otherwise.</param>
        protected virtual void UpdateSelection(bool bSelect)
        {
            DiagramDesigner designer = DiagramHelper.GetDiagramDesigner(this) as DiagramDesigner;

            // update selection
            if (designer != null)
            {
                if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
                {
                    if (bSelect && this.IsSelected)
                    {
                        designer.SelectionService.RemoveFromSelection(this);
                    }
                    else if (!this.IsSelected)
                    {
                        designer.SelectionService.AddToSelection(this);
                    }
                }
                else if (!this.IsSelected && bSelect)
                {
                    designer.SelectionService.SelectItem(this);
                }
                else if (this.IsSelected && !bSelect)
                {
                    designer.SelectionService.RemoveFromSelection(this);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Update selection.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            if (this.DataContext is IDiagramLinkViewModel)
            {
                if (DiagramHelper.GetDiagramDesignerLink((DependencyObject)e.MouseDevice.DirectlyOver) == this)
                {
                    UpdateSelection(true);
                    if (!this.IsFocused)
                    {
                        this.Focus();
                    }

                    e.Handled = false;
                }
            }
            else
            {
                if (DiagramHelper.GetDiagramDesignerItem((DependencyObject)e.MouseDevice.DirectlyOver) == this)
                {
                    UpdateSelection(true);
                    if (!this.IsFocused)
                    {
                        this.Focus();
                    }

                    e.Handled = false;
                }
            }

            //DiagramDesignerCanvas.IgnoreRubberbandSelection = true;
            base.OnPreviewMouseDown(e);
            //DiagramDesignerCanvas.IgnoreRubberbandSelection = false;
        }
        /// <summary>
        /// Contructor.
        /// </summary>
        /// <param name="designerCanvas">Designer items canvas.</param>
        /// <param name="dragStartPoint">Start point.</param>
        public DiagramDesignerRubberbandAdorner(DiagramDesignerCanvas designerCanvas, Point?dragStartPoint)
            : base(designerCanvas)
        {
            this.designerCanvas = designerCanvas;
            this.designer       = DiagramHelper.GetDiagramDesigner(this.designerCanvas);
            this.startPoint     = dragStartPoint;

            rubberbandPen           = new Pen(Brushes.LightSlateGray, 1);
            rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1);
        }
예제 #7
0
 /// <summary>
 /// Verifies if this is the top most container in the canvas hierarchy.
 /// </summary>
 /// <returns>True if this is the top most container; False otherwise.</returns>
 public virtual bool IsTopMostContainer()
 {
     if (DiagramHelper.GetDiagramDesignerItem(this) == null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #8
0
        /// <summary>
        /// Get start point of the possible selection operation.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            DiagramDesigner designer = DiagramHelper.GetDiagramDesigner(this);

            if (designer != null)
            {
                // position relative to DesignerCanvas
                this.dragStartPoint = new Point?(e.GetPosition(designer));
                e.Handled           = true;
            }
        }
예제 #9
0
        /// <summary>
        /// Dragging has started, see if VM is IDiagramLinkViewModel and notify of moving start.
        /// </summary>
        void DragThumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            diagramDesigner   = DiagramHelper.GetDiagramDesigner(this);
            diagramDesignerVM = diagramDesigner.DataContext as IDiagramViewModel;

            selectedItem   = null;
            selectedItemVM = null;

            edgePointVM = this.DataContext as IEdgePointViewModel;

            List <ISelectable> selection = diagramDesigner.SelectionService.CurrentSelection;

            if (selection.Count == 1)
            {
                foreach (ISelectable item in selection)
                {
                    if (item is DiagramDesignerItem)
                    {
                        if ((item as DiagramDesignerItem).IsDiagramLink)
                        {
                            selectedItem = item as DiagramDesignerItem;
                        }
                    }
                }

                // create control to display on the drag adorner
                dragCanvas = new Canvas();
                IDiagramLinkViewModel designerItem = selectedItem.DataContext as IDiagramLinkViewModel;
                selectedItemVM = designerItem;

                AddLinkAnchorAndShape(new PointD(designerItem.StartEdgePoint.X, designerItem.StartEdgePoint.Y),
                                      new PointD(designerItem.EndEdgePoint.X, designerItem.EndEdgePoint.Y));

                // create drag adorner
                if (diagramDesigner != null && selectedItemVM != null && selectedItem != null && edgePointVM != null)
                {
                    AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(diagramDesigner);
                    if (adornerLayer != null)
                    {
                        this.dragAdorner = new DragAdorner(diagramDesigner, dragCanvas, false, 1.0);
                        if (this.dragAdorner != null)
                        {
                            adornerLayer.Add(this.dragAdorner);
                            e.Handled = true;
                        }
                    }
                }
            }
            e.Handled = false;
        }
예제 #10
0
        //private Point? rubberbandSelectionStartPoint = null;

        /*
         * /// <summary>
         * /// Cancels the rubberband selection.
         * /// </summary>
         * public void CancelRubberbandSelection()
         * {
         *  this.rubberbandSelectionStartPoint = null;
         * }*/

        /// <summary>
        /// Set the starting point for a possible rubberband selection. Clear selection if
        /// this is the top most container.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Source == this && e.LeftButton == MouseButtonState.Pressed)
            {
                // in case that this click is the start of a
                // drag operation we cache the start point
                //this.rubberbandSelectionStartPoint = new Point?(e.GetPosition(this));
                DiagramRubberbandSelector.RubberbandSelectionStartPoint = new Point?(e.GetPosition(this));
            }
            if (e.Source == this && IsTopMostContainer())
            {
                DiagramDesigner designer = DiagramHelper.GetDiagramDesigner(this);
                if (designer != null)
                {
                    if (designer.SelectionService.CurrentSelection.Count > 0)
                    {
                        designer.SelectionService.ClearSelection(true);
                    }
                    Focus();
                }
            }
        }
        /// <summary>
        /// Start the drag operation.
        /// </summary>
        private void Start()
        {
            diagramDesigner   = DiagramHelper.GetDiagramDesigner(this);
            diagramDesignerVM = diagramDesigner.DataContext as IDiagramViewModel;

            selectedItems   = new List <DiagramDesignerItem>();
            selectedItemsVM = new List <IDiagramItemViewModel>();

            List <ISelectable> selection = diagramDesigner.SelectionService.CurrentSelection;

            foreach (ISelectable item in selection)
            {
                if (item is DiagramDesignerItem)
                {
                    if (!(item as DiagramDesignerItem).IsDiagramLink)
                    {
                        selectedItems.Add(item as DiagramDesignerItem);
                    }
                }
            }

            // create control to display on the drag adorner
            Canvas canvas = new Canvas();

            foreach (DiagramDesignerItem item in selectedItems)
            {
                IDiagramItemViewModel designerItem = item.DataContext as IDiagramItemViewModel;
                if (designerItem == null)
                {
                    continue;
                }

                selectedItemsVM.Add(designerItem);

                Rectangle r = new Rectangle();
                r.Stroke          = new SolidColorBrush(Colors.Black);
                r.StrokeDashArray = new DoubleCollection();
                r.StrokeDashArray.Add(3);
                r.StrokeDashArray.Add(6);
                r.StrokeThickness = 1.0;
                r.Width           = item.ActualWidth;
                r.Height          = item.ActualHeight;
                r.Margin          = new System.Windows.Thickness(designerItem.AbsoluteLocation.X, designerItem.AbsoluteLocation.Y, 0, 0);
                canvas.Children.Add(r);
            }

            // create drag adorner
            if (diagramDesigner != null)
            {
                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(diagramDesigner);
                if (adornerLayer != null)
                {
                    this.dragAdorner = new DragAdorner(diagramDesigner, canvas, false, 1.0);
                    if (this.dragAdorner != null)
                    {
                        adornerLayer.Add(this.dragAdorner);
                        //e.Handled = true;
                    }
                }
            }
            //e.Handled = false;
        }
        /// <summary>
        /// Start the drag operation.
        /// </summary>
        private void Start()
        {
            if (direction == null)
            {
                if (base.VerticalAlignment == System.Windows.VerticalAlignment.Top)
                {
                    if (base.HorizontalAlignment == System.Windows.HorizontalAlignment.Left)
                    {
                        direction = DiagramItemsResizeDirection.LeftTop;
                    }
                    else if (base.HorizontalAlignment == System.Windows.HorizontalAlignment.Stretch)
                    {
                        direction = DiagramItemsResizeDirection.Top;
                    }
                    else
                    {
                        direction = DiagramItemsResizeDirection.RightTop;
                    }
                }
                else if (base.VerticalAlignment == System.Windows.VerticalAlignment.Bottom)
                {
                    if (base.HorizontalAlignment == System.Windows.HorizontalAlignment.Left)
                    {
                        direction = DiagramItemsResizeDirection.LeftBottom;
                    }
                    else if (base.HorizontalAlignment == System.Windows.HorizontalAlignment.Stretch)
                    {
                        direction = DiagramItemsResizeDirection.Bottom;
                    }
                    else
                    {
                        direction = DiagramItemsResizeDirection.RightBottom;
                    }
                }
                else
                {
                    if (base.HorizontalAlignment == System.Windows.HorizontalAlignment.Left)
                    {
                        direction = DiagramItemsResizeDirection.Left;
                    }
                    else
                    {
                        direction = DiagramItemsResizeDirection.Right;
                    }
                }
            }
            diagramDesigner   = DiagramHelper.GetDiagramDesigner(this);
            diagramDesignerVM = diagramDesigner.DataContext as IDiagramViewModel;

            selectedItems   = new List <DiagramDesignerItem>();
            selectedItemsVM = new List <IDiagramItemViewModel>();

            List <ISelectable> selection = diagramDesigner.SelectionService.CurrentSelection;

            foreach (ISelectable item in selection)
            {
                if (item is DiagramDesignerItem)
                {
                    if (!(item as DiagramDesignerItem).IsDiagramLink)
                    {
                        selectedItems.Add(item as DiagramDesignerItem);
                    }
                }
            }

            // create control to display on the drag adorner
            dragCanvas = new Canvas();
            foreach (DiagramDesignerItem item in selectedItems)
            {
                if (item.DataContext is IDiagramItemViewModel)
                {
                    selectedItemsVM.Add(item.DataContext as IDiagramItemViewModel);
                }

                Rectangle r = new Rectangle();
                r.Stroke          = new SolidColorBrush(Colors.Black);
                r.StrokeDashArray = new DoubleCollection();
                r.StrokeDashArray.Add(3);
                r.StrokeDashArray.Add(6);
                r.StrokeThickness = 1.0;
                r.Width           = item.ActualWidth;
                r.Height          = item.ActualHeight;
                r.Margin          = new System.Windows.Thickness(item.AbsoluteLocation.X, item.AbsoluteLocation.Y, 0, 0);
                dragCanvas.Children.Add(r);
            }

            // create drag adorner
            if (diagramDesigner != null)
            {
                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(diagramDesigner);
                if (adornerLayer != null)
                {
                    this.dragAdorner = new DragAdorner(diagramDesigner, dragCanvas, false, 1.0);
                    if (this.dragAdorner != null)
                    {
                        adornerLayer.Add(this.dragAdorner);
                        //e.Handled = true;
                    }
                }
            }
            //e.Handled = false;
        }