private void UpdateSelection()
        {
            IDiagramWorkspaceViewModel designerView = designerCanvas.DataContext as IDiagramWorkspaceViewModel;

            if (designerView != null)
            {
                Rect rubberBand = new Rect(startPoint.Value, endPoint.Value);
                foreach (IDiagramWorkspaceViewModel item in designerView.Items)
                {
                    Control itemControl = VisualItemHelper.FindChild <DesignerItem>(designerCanvas, item) as Control;
                    // TODO: selecting connections creates issues
                    //if (itemControl == null)
                    //{
                    //    itemControl = VisualItemHelper.FindChild<Connection>(designerCanvas, item) as Control;
                    //}
                    if (itemControl != null)
                    {
                        Rect itemRect   = VisualTreeHelper.GetDescendantBounds(itemControl);
                        Rect itemBounds = itemControl.TransformToAncestor(designerCanvas).TransformBounds(itemRect);

                        if (rubberBand.Contains(itemBounds))
                        {
                            item.IsSelected = true;
                        }
                        else
                        {
                            item.IsSelected = false;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseDown(e);
            DesignerCanvas             designer     = VisualItemHelper.VisualUpwardSearch <DesignerCanvas>(this) as DesignerCanvas;
            IDiagramWorkspaceViewModel designerView = null;

            if (designer != null)
            {
                // update selection
                designerView = designer.DataContext as IDiagramWorkspaceViewModel;
                if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
                {
                    if (this.IsSelected)
                    {
                        this.IsSelected = false;
                    }
                    else
                    {
                        this.IsSelected = true;
                    }
                }
                else if (!this.IsSelected)
                {
                    if (designerView != null)
                    {
                        designerView.ClearSelectedItems();
                    }
                    this.IsSelected = true;
                }
            }
            e.Handled = false;
        }
Ejemplo n.º 3
0
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem   designerItem = VisualItemHelper.VisualUpwardSearch <DesignerItem>(this) as DesignerItem;
            DesignerCanvas designer     = VisualItemHelper.VisualUpwardSearch <DesignerCanvas>(designerItem) as DesignerCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                IDiagramWorkspaceViewModel designerView = designer.DataContext as IDiagramWorkspaceViewModel;
                if (designerView != null)
                {
                    double minLeft = double.MaxValue;
                    double minTop  = double.MaxValue;

                    foreach (IDiagramWorkspaceViewModel item in designerView.SelectedItems.OfType <IDiagramEntityWorkspaceViewModel>())
                    {
                        minLeft = double.IsNaN(item.X) ? 0 : Math.Min(item.X, minLeft);
                        minTop  = double.IsNaN(item.Y) ? 0 : Math.Min(item.Y, minTop);
                    }

                    double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
                    double deltaVertical   = Math.Max(-minTop, e.VerticalChange);

                    // move diagram entities (TODO: handle arcs later or a separate view model interface for arcs)
                    foreach (IDiagramEntityWorkspaceViewModel item in designerView.SelectedItems.OfType <IDiagramEntityWorkspaceViewModel>())
                    {
                        item.X += deltaHorizontal;
                        item.Y += deltaVertical;
                        if (item.ZIndex < designerView.ZIndex)
                        {
                            item.ZIndex = ++designerView.ZIndex;
                        }
                    }

                    designer.InvalidateMeasure();
                    e.Handled = true;
                }
            }
        }
Ejemplo n.º 4
0
        void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem   designerItem = VisualItemHelper.VisualUpwardSearch <DesignerItem>(this) as DesignerItem;
            DesignerCanvas designer     = VisualItemHelper.VisualUpwardSearch <DesignerCanvas>(designerItem) as DesignerCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                IDiagramWorkspaceViewModel designerView = designer.DataContext as IDiagramWorkspaceViewModel;
                if (designerView != null)
                {
                    double minLeft, minTop, minDeltaHorizontal, minDeltaVertical;
                    double dragDeltaVertical, dragDeltaHorizontal;

                    CalculateDragLimits(designer, designerView.SelectedItems.OfType <DiagramEntityViewModel>(), out minLeft, out minTop,
                                        out minDeltaHorizontal, out minDeltaVertical);

                    // resize diagram entities (TODO: handle arcs later or a separate view model interface for arcs)
                    foreach (IDiagramEntityWorkspaceViewModel item in designerView.SelectedItems.OfType <IDiagramEntityWorkspaceViewModel>())
                    {
                        DesignerItem itemControl = VisualItemHelper.FindChild <DesignerItem>(designer, item) as DesignerItem;
                        if (itemControl != null)
                        {
                            switch (base.VerticalAlignment)
                            {
                            case VerticalAlignment.Bottom:
                                dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical);
                                item.Height       = Math.Max(MinHeight, itemControl.ActualHeight - dragDeltaVertical);
                                break;

                            case VerticalAlignment.Top:
                                dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical);
                                item.Y           += dragDeltaVertical;
                                item.Height       = Math.Max(MinHeight, itemControl.ActualHeight - dragDeltaVertical);
                                break;

                            default:
                                break;
                            }

                            switch (base.HorizontalAlignment)
                            {
                            case HorizontalAlignment.Left:
                                dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal);
                                item.X    += dragDeltaHorizontal;
                                item.Width = Math.Max(MinWidth, itemControl.ActualWidth - dragDeltaHorizontal);
                                break;

                            case HorizontalAlignment.Right:
                                dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal);
                                item.Width          = Math.Max(MinWidth, itemControl.ActualWidth - dragDeltaHorizontal);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    e.Handled = true;
                }
            }
        }