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;
                        }
                    }
                }
            }
        }
Example #2
0
        void DragThumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            DesignerItem designerItem = VisualItemHelper.VisualUpwardSearch <DesignerItem>(this) as DesignerItem;

            if (designerItem != null)
            {
                EntityDiagramControl entityControl = VisualItemHelper.FindChild <EntityDiagramControl>(designerItem);
                if (entityControl != null)
                {
                    entityControl.UpdateConnections();
                }
            }
        }
        public void UpdateSourceAndSink()
        {
            DiagramRelationshipViewModel view = DataContext as DiagramRelationshipViewModel;

            if (view != null)
            {
                DesignerCanvas       designer      = VisualItemHelper.VisualUpwardSearch <DesignerCanvas>(this) as DesignerCanvas;
                EntityDiagramControl sourceControl = VisualItemHelper.FindChild <EntityDiagramControl>(designer, view.SourceDiagramEntityViewModel) as EntityDiagramControl;
                EntityDiagramControl sinkControl   = VisualItemHelper.FindChild <EntityDiagramControl>(designer, view.SinkDiagramEntityViewModel) as EntityDiagramControl;
                if (sourceControl != null && sinkControl != null)
                {
                    Source = sourceControl.GetBestConnector(sinkControl, false);
                    Sink   = sinkControl.GetBestConnector(sourceControl, true);
                }
            }
        }
Example #4
0
        private static void CalculateDragLimits(DesignerCanvas designer, IEnumerable <IDiagramWorkspaceViewModel> selectedDesignerItems, out double minLeft, out double minTop, out double minDeltaHorizontal, out double minDeltaVertical)
        {
            minLeft            = double.MaxValue;
            minTop             = double.MaxValue;
            minDeltaHorizontal = double.MaxValue;
            minDeltaVertical   = double.MaxValue;

            // drag limits are set by these parameters: canvas top, canvas left, minHeight, minWidth
            // calculate min value for each parameter for each item
            foreach (IDiagramWorkspaceViewModel item in selectedDesignerItems)
            {
                DesignerItem itemControl = VisualItemHelper.FindChild <DesignerItem>(designer, item) as DesignerItem;
                if (itemControl != null)
                {
                    minLeft = double.IsNaN(item.X) ? 0 : Math.Min(item.X, minLeft);
                    minTop  = double.IsNaN(item.Y) ? 0 : Math.Min(item.Y, minTop);

                    minDeltaVertical   = Math.Min(minDeltaVertical, itemControl.ActualHeight - itemControl.MinHeight);
                    minDeltaHorizontal = Math.Min(minDeltaHorizontal, itemControl.ActualWidth - itemControl.MinWidth);
                }
            }
        }
Example #5
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;
                }
            }
        }