Exemplo n.º 1
0
        void Connection_Unloaded(object sender, RoutedEventArgs e)
        {
            // do some housekeeping when Connection is unloaded

            // remove event handler
            if (source != null)
            {
                source.PropertyChanged -= new PropertyChangedEventHandler(OnConnectorPositionChanged);
            }
            if (sink != null)
            {
                sink.PropertyChanged -= new PropertyChangedEventHandler(OnConnectorPositionChanged);
            }

            // remove adorner
            if (this.connectionAdorner != null)
            {
                DesignerCanvas designer = VisualItemHelper.VisualUpwardSearch <DesignerCanvas>(this) as DesignerCanvas;
                if (designer != null)
                {
                    AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(designer);
                    if (adornerLayer != null)
                    {
                        adornerLayer.Remove(this.connectionAdorner);
                        this.connectionAdorner = null;
                    }
                }
            }
        }
Exemplo 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;
        }
Exemplo n.º 3
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();
                }
            }
        }
Exemplo n.º 4
0
 protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
 {
     base.OnMouseDown(e);
     if (DataContext is IWorkspaceViewModel)
     {
         (DataContext as IWorkspaceViewModel).SetSelected();
         DesignerItem control = VisualItemHelper.VisualUpwardSearch <DesignerItem>(this) as DesignerItem;
         if (control != null)
         {
             control.Focus();
         }
     }
 }
Exemplo n.º 5
0
        private void ShowAdorner()
        {
            // the ConnectionAdorner is created once for each Connection
            if (this.connectionAdorner == null)
            {
                DesignerCanvas designer = VisualItemHelper.VisualUpwardSearch <DesignerCanvas>(this) as DesignerCanvas;

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(designer);
                if (adornerLayer != null)
                {
                    this.connectionAdorner = new ConnectionAdorner(designer, this);
                    adornerLayer.Add(this.connectionAdorner);
                }
            }
            this.connectionAdorner.Visibility = Visibility.Visible;
        }
Exemplo n.º 6
0
        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);
                }
            }
        }
Exemplo n.º 7
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;
                }
            }
        }
Exemplo n.º 8
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;
                }
            }
        }