mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BlockConnector : ContentControl
|
||||
{
|
||||
public ConnectorOrientation Orientation { get; set; }
|
||||
|
||||
public ConnectorInfoBase Info
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Content is ConnectorInfoBase connectorInfo)
|
||||
return connectorInfo;
|
||||
|
||||
return this.DataContext as ConnectorInfoBase;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class BlockBorder : Border
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,22 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
using System.Xml;
|
||||
using System.Linq;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Resources;
|
||||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -29,7 +37,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return DiagramServicesProvider.Instance.Provider;
|
||||
}
|
||||
}
|
||||
private ConnectionViewModel _partialConnection;
|
||||
private ConnectionViewModel partialConnection;
|
||||
|
||||
private Point? rubberbandSelectionStartPoint = null;
|
||||
|
||||
@@ -55,10 +63,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
Point point = sourceDataItem.MiddlePosition;
|
||||
|
||||
_partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), LineDrawMode, RouterMode);
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), LineDrawMode, RouterMode);
|
||||
|
||||
_viewModel.Add(_partialConnection);
|
||||
_partialConnection.ZIndex = -1;
|
||||
_viewModel.Add(partialConnection);
|
||||
partialConnection.ZIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,30 +91,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemsContainer _sourceItemsContainer;
|
||||
public ItemsContainer SourceItemsContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sourceItemsContainer;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_sourceItemsContainer != value)
|
||||
{
|
||||
_sourceItemsContainer = value;
|
||||
if (_sourceItemsContainer != null)
|
||||
{
|
||||
ItemsContainerInfo sourceDataItem = _sourceItemsContainer.Info;
|
||||
|
||||
sourceDataItem.DataItem.RemoveChild(_sourceItemsContainer.DragObject);
|
||||
|
||||
EnterMove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode DrawMode
|
||||
{
|
||||
@@ -483,7 +467,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
_partialConnection.SinkConnectorInfo = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y);
|
||||
partialConnection.SinkConnectorInfo = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y);
|
||||
|
||||
SinkConnector = HitTesting(currentPoint);
|
||||
if (SinkConnector?.Info?.CanAttachTo(SourceConnector?.Info) == false)
|
||||
@@ -493,24 +477,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (_viewModel.DiagramOption.SnappingOption.EnableSnapping)
|
||||
{
|
||||
var nearPort = _viewModel.FindNearPortToAttachTo(_partialConnection);
|
||||
var nearPort = _viewModel.FindNearPortToAttachTo(partialConnection);
|
||||
if (nearPort != null)
|
||||
{
|
||||
_partialConnection.SinkConnectorInfo = nearPort;
|
||||
partialConnection.SinkConnectorInfo = nearPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (SourceItemsContainer != null)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
SourceItemsContainer.DragObject.Left = currentPoint.X - SourceItemsContainer.DragOffset.X;
|
||||
SourceItemsContainer.DragObject.Top = currentPoint.Y - SourceItemsContainer.DragOffset.Y;
|
||||
|
||||
_viewModel.PreviewNearBlock(new System.Collections.Generic.List<BlockDesignerItemViewModel> { SourceItemsContainer.DragObject });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if mouse button is not pressed we have no drag operation, ...
|
||||
@@ -552,10 +526,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
ConnectorInfoBase sinkDataItem = SinkConnector.Info;
|
||||
|
||||
_viewModel.Delete(_partialConnection);
|
||||
_viewModel.Delete(partialConnection);
|
||||
_viewModel.AddCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, LineDrawMode, RouterMode));
|
||||
}
|
||||
else if (_partialConnection.IsFullConnection)//自动连接模式
|
||||
else if (partialConnection.IsFullConnection)//自动连接模式
|
||||
{
|
||||
_viewModel.ClearNearPort();
|
||||
}
|
||||
@@ -564,26 +538,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Point currentPoint = e.GetPosition(this);
|
||||
ConnectorInfoBase sinkDataItem = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y);
|
||||
|
||||
_viewModel.Delete(_partialConnection);
|
||||
_viewModel.Delete(partialConnection);
|
||||
_viewModel.AddCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, LineDrawMode, RouterMode));
|
||||
}
|
||||
else
|
||||
{
|
||||
//Need to remove last item as we did not finish drawing the path
|
||||
_viewModel.Delete(_partialConnection);
|
||||
_viewModel.Delete(partialConnection);
|
||||
}
|
||||
}
|
||||
else if (SourceItemsContainer != null)
|
||||
{
|
||||
_viewModel.FinishNearBlock(new System.Collections.Generic.List<BlockDesignerItemViewModel> { SourceItemsContainer.DragObject });
|
||||
ExitCursor();
|
||||
}
|
||||
|
||||
SourceConnector = null;
|
||||
SinkConnector = null;
|
||||
_partialConnection = null;
|
||||
|
||||
SourceItemsContainer = null;
|
||||
partialConnection = null;
|
||||
|
||||
_service.DrawModeViewModel.ResetDrawMode();
|
||||
}
|
||||
@@ -657,36 +624,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnDragOver(DragEventArgs e)
|
||||
{
|
||||
DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
|
||||
if (dragObject != null && (dragObject.ContentType == typeof(BlockDesignerItemViewModel) || dragObject.ContentType.IsSubclassOf(typeof(BlockDesignerItemViewModel))))
|
||||
{
|
||||
var position = e.GetPosition(this);
|
||||
|
||||
BlockDesignerItemViewModel itemBase = Activator.CreateInstance(dragObject.ContentType) as BlockDesignerItemViewModel;
|
||||
itemBase.Text = dragObject.Text;
|
||||
itemBase.Icon = dragObject.Icon;
|
||||
itemBase.ColorViewModel = CopyHelper.Mapper(dragObject.ColorViewModel);
|
||||
if (dragObject.DesiredSize != null)
|
||||
{
|
||||
itemBase.ItemWidth = dragObject.DesiredSize.Value.Width;
|
||||
itemBase.ItemHeight = dragObject.DesiredSize.Value.Height;
|
||||
}
|
||||
if (dragObject.DesiredMinSize != null)
|
||||
{
|
||||
itemBase.MinItemWidth = dragObject.DesiredMinSize.Value.Width;
|
||||
itemBase.MinItemHeight = dragObject.DesiredMinSize.Value.Height;
|
||||
}
|
||||
itemBase.Left = Math.Max(0, position.X - itemBase.GetItemWidth() / 2);
|
||||
itemBase.Top = Math.Max(0, position.Y - itemBase.GetItemHeight() / 2);
|
||||
|
||||
_viewModel.PreviewNearBlock(new System.Collections.Generic.List<BlockDesignerItemViewModel> { itemBase });
|
||||
}
|
||||
|
||||
base.OnDragOver(e);
|
||||
}
|
||||
|
||||
protected override void OnDrop(DragEventArgs e)
|
||||
{
|
||||
base.OnDrop(e);
|
||||
@@ -703,8 +640,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var designerItems = serializableObject.ToObject();
|
||||
var minleft = designerItems.OfType<DesignerItemViewModelBase>().Min(p => p.Left);
|
||||
var mintop = designerItems.OfType<DesignerItemViewModelBase>().Min(p => p.Top);
|
||||
var maxright = designerItems.OfType<DesignerItemViewModelBase>().Max(p => p.Left + p.GetItemWidth());
|
||||
var maxbottom = designerItems.OfType<DesignerItemViewModelBase>().Max(p => p.Top + p.GetItemHeight());
|
||||
var maxright = designerItems.OfType<DesignerItemViewModelBase>().Max(p => p.Left + p.ItemWidth);
|
||||
var maxbottom = designerItems.OfType<DesignerItemViewModelBase>().Max(p => p.Top + p.ItemHeight);
|
||||
var itemswidth = maxright - minleft;
|
||||
var itemsheight = maxbottom - mintop;
|
||||
|
||||
@@ -725,7 +662,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
else
|
||||
{
|
||||
itemBase = Activator.CreateInstance(dragObject.ContentType) as DesignerItemViewModelBase;
|
||||
itemBase.Text = dragObject.Text;
|
||||
itemBase.Icon = dragObject.Icon;
|
||||
itemBase.ColorViewModel = CopyHelper.Mapper(dragObject.ColorViewModel);
|
||||
if (dragObject.DesiredSize != null)
|
||||
@@ -733,42 +669,28 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
itemBase.ItemWidth = dragObject.DesiredSize.Value.Width;
|
||||
itemBase.ItemHeight = dragObject.DesiredSize.Value.Height;
|
||||
}
|
||||
if (dragObject.DesiredMinSize != null)
|
||||
{
|
||||
itemBase.MinItemWidth = dragObject.DesiredMinSize.Value.Width;
|
||||
itemBase.MinItemHeight = dragObject.DesiredMinSize.Value.Height;
|
||||
}
|
||||
|
||||
}
|
||||
itemBase.Left = Math.Max(0, position.X - itemBase.GetItemWidth() / 2);
|
||||
itemBase.Top = Math.Max(0, position.Y - itemBase.GetItemHeight() / 2);
|
||||
itemBase.Left = Math.Max(0, position.X - itemBase.ItemWidth / 2);
|
||||
itemBase.Top = Math.Max(0, position.Y - itemBase.ItemHeight / 2);
|
||||
_viewModel.AddCommand.Execute(itemBase);
|
||||
|
||||
if (itemBase is BlockDesignerItemViewModel block)
|
||||
{
|
||||
_viewModel.FinishNearBlock(new System.Collections.Generic.List<BlockDesignerItemViewModel> { block });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
var dragFile = e.Data.GetData(DataFormats.FileDrop);
|
||||
if (dragFile != null && dragFile is string[] files)
|
||||
{
|
||||
var dragFile = e.Data.GetData(DataFormats.FileDrop);
|
||||
if (dragFile != null && dragFile is string[] files)
|
||||
foreach (var file in files)
|
||||
{
|
||||
foreach (var file in files)
|
||||
{
|
||||
_viewModel.ClearSelectedItems();
|
||||
Point position = e.GetPosition(this);
|
||||
ImageItemViewModel itemBase = new ImageItemViewModel();
|
||||
itemBase.Icon = file;
|
||||
itemBase.Suffix = System.IO.Path.GetExtension(itemBase.Icon).ToLower();
|
||||
itemBase.InitWidthAndHeight();
|
||||
itemBase.AutoSize();
|
||||
_viewModel.ClearSelectedItems();
|
||||
Point position = e.GetPosition(this);
|
||||
ImageItemViewModel itemBase = new ImageItemViewModel();
|
||||
itemBase.Icon = file;
|
||||
itemBase.Suffix = System.IO.Path.GetExtension(itemBase.Icon).ToLower();
|
||||
itemBase.InitWidthAndHeight();
|
||||
itemBase.AutoSize();
|
||||
|
||||
itemBase.Left = Math.Max(0, position.X - itemBase.GetItemWidth() / 2);
|
||||
itemBase.Top = Math.Max(0, position.Y - itemBase.GetItemHeight() / 2);
|
||||
_viewModel.AddCommand.Execute(itemBase);
|
||||
}
|
||||
itemBase.Left = Math.Max(0, position.X - itemBase.ItemWidth / 2);
|
||||
itemBase.Top = Math.Max(0, position.Y - itemBase.ItemHeight / 2);
|
||||
_viewModel.AddCommand.Execute(itemBase);
|
||||
}
|
||||
}
|
||||
e.Handled = true;
|
||||
|
||||
@@ -21,7 +21,10 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
|
||||
public IDiagramViewModel DiagramViewModel
|
||||
{
|
||||
get;set;
|
||||
get
|
||||
{
|
||||
return (this.DataContext as SelectableDesignerItemViewModelBase)?.Root;
|
||||
}
|
||||
}
|
||||
private List<SelectableDesignerItemViewModelBase> designerItems;
|
||||
|
||||
@@ -32,7 +35,6 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
|
||||
drag = false;
|
||||
SelectableDesignerItemViewModelBase designerItem = this.DataContext as SelectableDesignerItemViewModelBase;
|
||||
DiagramViewModel = designerItem?.Root;
|
||||
|
||||
if (designerItem != null && designerItem.IsSelected)
|
||||
{
|
||||
@@ -97,9 +99,47 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
var blocks = designerItems.OfType<BlockDesignerItemViewModel>().ToList();
|
||||
if (blocks.Any())
|
||||
{
|
||||
DiagramViewModel.FinishNearBlock(blocks);
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
{
|
||||
var portTuple = DiagramViewModel.FindNearPortToAttachTo(item, true);
|
||||
var portParent = portTuple.Item1;
|
||||
var portNext = portTuple.Item2;
|
||||
|
||||
if (portParent != null)
|
||||
{
|
||||
(portParent.DataItem as BlockDesignerItemViewModel).AddNext(item);
|
||||
portParent.BeAttachTo = false;
|
||||
portParent.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Parent != null)
|
||||
{
|
||||
(item.Parent as BlockDesignerItemViewModel).Next = null;
|
||||
item.Parent = null;
|
||||
item.ParentId = new Guid();
|
||||
}
|
||||
}
|
||||
|
||||
if (portNext != null)
|
||||
{
|
||||
item.AddNext(portNext.DataItem as BlockDesignerItemViewModel);
|
||||
portNext.BeAttachTo = false;
|
||||
portNext.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Next != null)
|
||||
{
|
||||
item.Next.Parent = null;
|
||||
item.Next.ParentId = new Guid();
|
||||
item.Next = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
//-DiagramViewModel.ClearNearPort();
|
||||
}
|
||||
|
||||
|
||||
Dictionary<DesignerItemViewModelBase, Tuple<PointBase, PointBase>> infos =
|
||||
designerItems.OfType<DesignerItemViewModelBase>().ToDictionary(p => p,
|
||||
p => new Tuple<PointBase, PointBase>(p.GetOldValue<PointBase>(nameof(p.TopLeft)), p.TopLeft));
|
||||
@@ -167,8 +207,14 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
}
|
||||
|
||||
var blocks = designerItems.OfType<BlockDesignerItemViewModel>().ToList();
|
||||
DiagramViewModel.PreviewNearBlock(blocks);
|
||||
|
||||
if (blocks.Any())
|
||||
{
|
||||
DiagramViewModel.ClearNearPort();
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
{
|
||||
DiagramViewModel.FindNearPortToAttachTo(item, false);
|
||||
}
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ItemsContainer : ContentControl
|
||||
{
|
||||
static ItemsContainer()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(ItemsContainer), new FrameworkPropertyMetadata(typeof(ItemsContainer)));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BorderProperty = DependencyProperty.Register(
|
||||
nameof(Border), typeof(object), typeof(ItemsContainer), new PropertyMetadata(default(object)));
|
||||
|
||||
public object Border
|
||||
{
|
||||
get => GetValue(BorderProperty);
|
||||
set => SetValue(BorderProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BorderTemplateProperty = DependencyProperty.Register(
|
||||
nameof(BorderTemplate), typeof(DataTemplate), typeof(ItemsContainer), new PropertyMetadata(default(DataTemplate)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public DataTemplate BorderTemplate
|
||||
{
|
||||
get => (DataTemplate)GetValue(BorderTemplateProperty);
|
||||
set => SetValue(BorderTemplateProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BorderTemplateSelectorProperty = DependencyProperty.Register(
|
||||
nameof(BorderTemplateSelector), typeof(DataTemplateSelector), typeof(ItemsContainer), new PropertyMetadata(default(DataTemplateSelector)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public DataTemplateSelector BorderTemplateSelector
|
||||
{
|
||||
get => (DataTemplateSelector)GetValue(BorderTemplateSelectorProperty);
|
||||
set => SetValue(BorderTemplateSelectorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BorderStringFormatProperty = DependencyProperty.Register(
|
||||
nameof(BorderStringFormat), typeof(string), typeof(ItemsContainer), new PropertyMetadata(default(string)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public string BorderStringFormat
|
||||
{
|
||||
get => (string)GetValue(BorderStringFormatProperty);
|
||||
set => SetValue(BorderStringFormatProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly DependencyProperty ParentPanelProperty =
|
||||
DependencyProperty.Register(nameof(ParentPanel), typeof(FrameworkElement), typeof(ItemsContainer),
|
||||
new FrameworkPropertyMetadata(null));
|
||||
|
||||
public FrameworkElement ParentPanel
|
||||
{
|
||||
get
|
||||
{
|
||||
return (FrameworkElement)GetValue(ParentPanelProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(ParentPanelProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty GetOffSetFuncProperty =
|
||||
DependencyProperty.Register(nameof(GetOffSetFunc),
|
||||
typeof(Func<Point>),
|
||||
typeof(ItemsContainer),
|
||||
new FrameworkPropertyMetadata(null));
|
||||
public Func<Point> GetOffSetFunc
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Func<Point>)this.GetValue(GetOffSetFuncProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetValue(GetOffSetFuncProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Func<Point> GetOffSet
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Func<Point>(() => this.TransformToAncestor(ParentPanel).Transform(new Point(0, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
public ItemsContainerInfo Info
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Border is ItemsContainerInfo itemsContainerInfo)
|
||||
return itemsContainerInfo;
|
||||
|
||||
return this.DataContext as ItemsContainerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel DragObject
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public Point DragOffset
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public ItemsContainer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
GetOffSetFunc = GetOffSet;
|
||||
}
|
||||
|
||||
Point? firstPoint;
|
||||
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseLeftButtonDown(e);
|
||||
firstPoint = e.GetPosition(this);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
|
||||
if (firstPoint != null)
|
||||
{
|
||||
var currentPoint = e.GetPosition(this);
|
||||
if (Math.Sqrt(Math.Pow(firstPoint.Value.X - currentPoint.X, 2) + Math.Pow(firstPoint.Value.Y - currentPoint.Y, 2)) > 5)
|
||||
{
|
||||
if (Info?.Children?.Count > 0)
|
||||
{
|
||||
var borders = VisualHelper.FindVisualChildren<BlockBorder>(this);
|
||||
foreach (var border in borders)
|
||||
{
|
||||
var point = border.TransformToAncestor(this).Transform(new Point(0, 0));
|
||||
var rect = new Rect(point.X, point.Y, border.ActualWidth, border.ActualHeight);
|
||||
if (rect.Contains(currentPoint))
|
||||
{
|
||||
DragObject = border.DataContext as BlockDesignerItemViewModel;
|
||||
DragOffset = new Point(currentPoint.X - point.X, currentPoint.Y - point.Y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (DragObject != null)
|
||||
{
|
||||
DesignerCanvas canvas = GetDesignerCanvas(this);
|
||||
if (canvas != null)
|
||||
{
|
||||
canvas.SourceItemsContainer = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
firstPoint = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnMouseUp(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
|
||||
firstPoint = null;
|
||||
DragObject = null;
|
||||
}
|
||||
|
||||
public ConnectorOrientation Orientation
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
// iterate through visual tree to get parent DesignerCanvas
|
||||
private DesignerCanvas GetDesignerCanvas(DependencyObject element)
|
||||
{
|
||||
while (element != null && !(element is DesignerCanvas))
|
||||
element = VisualTreeHelper.GetParent(element);
|
||||
|
||||
return element as DesignerCanvas;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -95,13 +95,13 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
{
|
||||
case VerticalAlignment.Bottom:
|
||||
dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical);
|
||||
scale = (item.GetItemHeight() - dragDeltaVertical) / item.GetItemHeight();
|
||||
scale = (item.ItemHeight - dragDeltaVertical) / item.ItemHeight;
|
||||
DragBottom(scale, item, DiagramViewModel.SelectionService);
|
||||
break;
|
||||
case VerticalAlignment.Top:
|
||||
double top = item.Top;
|
||||
dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical);
|
||||
scale = (item.GetItemHeight() - dragDeltaVertical) / item.GetItemHeight();
|
||||
scale = (item.ItemHeight - dragDeltaVertical) / item.ItemHeight;
|
||||
DragTop(scale, item, DiagramViewModel.SelectionService);
|
||||
break;
|
||||
default:
|
||||
@@ -113,12 +113,12 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
case HorizontalAlignment.Left:
|
||||
double left = item.Left;
|
||||
dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal);
|
||||
scale = (item.GetItemWidth() - dragDeltaHorizontal) / item.GetItemWidth();
|
||||
scale = (item.ItemWidth - dragDeltaHorizontal) / item.ItemWidth;
|
||||
DragLeft(scale, item, DiagramViewModel.SelectionService);
|
||||
break;
|
||||
case HorizontalAlignment.Right:
|
||||
dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal);
|
||||
scale = (item.GetItemWidth() - dragDeltaHorizontal) / item.GetItemWidth();
|
||||
scale = (item.ItemWidth - dragDeltaHorizontal) / item.ItemWidth;
|
||||
DragRight(scale, item, DiagramViewModel.SelectionService);
|
||||
break;
|
||||
default:
|
||||
@@ -137,26 +137,26 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
{
|
||||
IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item, false).Cast<DesignerItemViewModelBase>();
|
||||
|
||||
double groupLeft = item.Left + item.GetItemWidth();
|
||||
double groupLeft = item.Left + item.ItemWidth;
|
||||
foreach (DesignerItemViewModelBase groupItem in groupItems)
|
||||
{
|
||||
double groupItemLeft = groupItem.Left;
|
||||
double delta = (groupLeft - groupItemLeft) * (scale - 1);
|
||||
groupItem.Left = groupItemLeft - delta;
|
||||
groupItem.ItemWidth = groupItem.GetItemWidth() * scale;
|
||||
groupItem.ItemWidth = groupItem.ItemWidth * scale;
|
||||
}
|
||||
}
|
||||
|
||||
private void DragTop(double scale, DesignerItemViewModelBase item, SelectionService selectionService)
|
||||
{
|
||||
IEnumerable<DesignerItemViewModelBase> groupItems = selectionService.GetGroupMembers(item, false).Cast<DesignerItemViewModelBase>();
|
||||
double groupBottom = item.Top + item.GetItemHeight();
|
||||
double groupBottom = item.Top + item.ItemHeight;
|
||||
foreach (DesignerItemViewModelBase groupItem in groupItems)
|
||||
{
|
||||
double groupItemTop = groupItem.Top;
|
||||
double delta = (groupBottom - groupItemTop) * (scale - 1);
|
||||
groupItem.Top = groupItemTop - delta;
|
||||
groupItem.ItemHeight = groupItem.GetItemHeight() * scale;
|
||||
groupItem.ItemHeight = groupItem.ItemHeight * scale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
double delta = (groupItemLeft - groupLeft) * (scale - 1);
|
||||
|
||||
groupItem.Left = groupItemLeft + delta;
|
||||
groupItem.ItemWidth = groupItem.GetItemWidth() * scale;
|
||||
groupItem.ItemWidth = groupItem.ItemWidth * scale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
double delta = (groupItemTop - groupTop) * (scale - 1);
|
||||
|
||||
groupItem.Top = groupItemTop + delta;
|
||||
groupItem.ItemHeight = groupItem.GetItemHeight() * scale;
|
||||
groupItem.ItemHeight = groupItem.ItemHeight * scale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
if (this.designerCanvas != null)
|
||||
{
|
||||
this.centerPoint =
|
||||
new Point(this.designerItem.Left + this.designerItem.GetItemHeight() * 0.5,
|
||||
this.designerItem.Top + this.designerItem.GetItemHeight() * 0.5);
|
||||
new Point(this.designerItem.Left + this.designerItem.ItemWidth * 0.5,
|
||||
this.designerItem.Top + this.designerItem.ItemHeight * 0.5);
|
||||
|
||||
Point startPoint = Mouse.GetPosition(this.designerCanvas);
|
||||
this.startVector = Point.Subtract(startPoint, this.centerPoint);
|
||||
|
||||
Reference in New Issue
Block a user