/// <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>
        /// 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);
        }
예제 #3
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;
        }
        /// <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;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="designer">Diagram designer.</param>
        /// <param name="sourceConnector">Source item of the relationship.</param>
        /// <param name="startPoint">Start point.</param>
        public DiagramConnectorAdorner(DiagramDesigner designer, DiagramConnector sourceConnector, Point startPoint)
            : base(designer)
        {
            this.diagramDesigner = designer;
            if (this.diagramDesigner.DataContext is IDiagramViewModel)
                diagramDesignerVM = this.diagramDesigner.DataContext as IDiagramViewModel;
            this.sourceConnector = sourceConnector;
            this.startPoint = startPoint;

            sourceItem = sourceConnector.DiagramItem;
            //if (sourceConnector.DiagramItem is ISelectable)
            //    this.sourceElement = (sourceConnector.DiagramItem as ISelectable).SelectedData;

            drawingPen = new Pen(Brushes.LightSlateGray, 1);
            drawingPen.LineJoin = PenLineJoin.Round;
            
            this.Cursor = Cursors.Cross;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="designer">Diagram designer.</param>
        /// <param name="sourceConnector">Source item of the relationship.</param>
        /// <param name="startPoint">Start point.</param>
        public DiagramConnectorAdorner(DiagramDesigner designer, DiagramConnector sourceConnector, Point startPoint)
            : base(designer)
        {
            this.diagramDesigner = designer;
            if (this.diagramDesigner.DataContext is IDiagramViewModel)
            {
                diagramDesignerVM = this.diagramDesigner.DataContext as IDiagramViewModel;
            }
            this.sourceConnector = sourceConnector;
            this.startPoint      = startPoint;

            sourceItem = sourceConnector.DiagramItem;
            //if (sourceConnector.DiagramItem is ISelectable)
            //    this.sourceElement = (sourceConnector.DiagramItem as ISelectable).SelectedData;

            drawingPen          = new Pen(Brushes.LightSlateGray, 1);
            drawingPen.LineJoin = PenLineJoin.Round;

            this.Cursor = Cursors.Cross;
        }
예제 #7
0
        private static void SelectedItemsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            DiagramDesigner designer = obj as DiagramDesigner;

            if (designer != null)
            {
                if (designer.SelectedItems == null)
                {
                    designer.SelectionService.ClearSelection(false);
                }
                else
                {
                    if (designer.SelectedItems.Count == 0)
                    {
                        designer.SelectionService.ClearSelection(false);
                    }
                    else
                    {
                        // TODO
                    }
                }
            }
        }
예제 #8
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()
        {
            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;
        }
        /// <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>
 /// Constructor.
 /// </summary>
 /// <param name="diagramDesigner">Designer for which this service is to be initialized.</param>
 public DiagramDesignerSelectionService(DiagramDesigner diagramDesigner)
 {
     this.currentSelection = new List<ISelectable>();
     this.diagramDesigner = diagramDesigner;
 }
예제 #12
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="diagramDesigner">Designer for which this service is to be initialized.</param>
 public DiagramDesignerSelectionService(DiagramDesigner diagramDesigner)
 {
     this.currentSelection = new List <ISelectable>();
     this.diagramDesigner  = diagramDesigner;
 }
        /// <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;
        }