Revert "block 可以拖拽到内部,还有少量问题待解决"

This reverts commit 538898d238.
This commit is contained in:
艾竹
2023-06-11 23:57:59 +08:00
parent 538898d238
commit fcd7beb193
73 changed files with 242 additions and 7132 deletions

View File

@@ -77,9 +77,7 @@ namespace AIStudio.Wpf.DiagramDesigner
DragObject dataObject = new DragObject();
dataObject.ContentType = toolBoxData.Type;
dataObject.DesiredSize = toolBoxData.DesiredSize;
dataObject.DesiredMinSize = toolBoxData.DesiredMinSize;
dataObject.Icon = toolBoxData.Icon;
dataObject.Text = toolBoxData.Text;
dataObject.ColorViewModel = toolBoxData.ColorViewModel;
dataObject.DesignerItem = toolBoxData.Addition;

View File

@@ -1,100 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AIStudio.Wpf.DiagramDesigner
{
public static class WidthAndHeightProps
{
public static readonly DependencyProperty ActiveProperty = DependencyProperty.RegisterAttached(
"Active",
typeof(bool),
typeof(WidthAndHeightProps),
new FrameworkPropertyMetadata(OnActiveChanged));
public static bool GetActive(FrameworkElement frameworkElement)
{
return (bool)frameworkElement.GetValue(ActiveProperty);
}
public static void SetActive(FrameworkElement frameworkElement, bool active)
{
frameworkElement.SetValue(ActiveProperty, active);
}
public static readonly DependencyProperty BoundActualWidthProperty = DependencyProperty.RegisterAttached(
"BoundActualWidth",
typeof(double),
typeof(WidthAndHeightProps));
public static double GetBoundActualWidth(FrameworkElement frameworkElement)
{
return (double)frameworkElement.GetValue(BoundActualWidthProperty);
}
public static void SetBoundActualWidth(FrameworkElement frameworkElement, double width)
{
frameworkElement.SetValue(BoundActualWidthProperty, width);
}
public static readonly DependencyProperty BoundActualHeightProperty = DependencyProperty.RegisterAttached(
"BoundActualHeight",
typeof(double),
typeof(WidthAndHeightProps));
public static double GetBoundActualHeight(FrameworkElement frameworkElement)
{
return (double)frameworkElement.GetValue(BoundActualHeightProperty);
}
public static void SetBoundActualHeight(FrameworkElement frameworkElement, double height)
{
frameworkElement.SetValue(BoundActualHeightProperty, height);
}
private static void OnActiveChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (!(dependencyObject is FrameworkElement frameworkElement))
{
return;
}
if ((bool)e.NewValue)
{
frameworkElement.SizeChanged -= OnFrameworkElementSizeChanged;
frameworkElement.SizeChanged += OnFrameworkElementSizeChanged;
frameworkElement.Loaded -= FrameworkElement_Loaded;
frameworkElement.Loaded += FrameworkElement_Loaded;
}
else
{
frameworkElement.SizeChanged -= OnFrameworkElementSizeChanged;
frameworkElement.Loaded -= FrameworkElement_Loaded;
}
}
private static void FrameworkElement_Loaded(object sender, RoutedEventArgs e)
{
UpdateObservedSizesForFrameworkElement(sender as FrameworkElement);
}
private static void OnFrameworkElementSizeChanged(object sender, SizeChangedEventArgs e)
{
if (sender is FrameworkElement frameworkElement)
{
UpdateObservedSizesForFrameworkElement(frameworkElement);
}
}
private static void UpdateObservedSizesForFrameworkElement(FrameworkElement frameworkElement)
{
frameworkElement.SetCurrentValue(BoundActualWidthProperty, frameworkElement.ActualWidth);
frameworkElement.SetCurrentValue(BoundActualHeightProperty, frameworkElement.ActualHeight);
}
}
}

View File

@@ -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
{
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -12,7 +12,6 @@ namespace AIStudio.Wpf.DiagramDesigner
SFC,
Mind,
Script,
Drawing,
Block
Drawing
}
}

View File

@@ -16,12 +16,6 @@ namespace AIStudio.Wpf.DiagramDesigner.Geometrys
_y = y;
}
public PointBase(Point point)
{
_x = point.X;
_y = point.Y;
}
/// <summary>
/// 中间X
/// </summary>

View File

@@ -17,8 +17,8 @@ namespace AIStudio.Wpf.DiagramDesigner
var connectorHeight = double.IsNaN(connector.ConnectorHeight) ? 0 : connector.ConnectorHeight;
var left = connector.DataItem.Left;
var top = connector.DataItem.Top;
var itemWidth = connector.DataItem.GetItemWidth();
var itemHeight = connector.DataItem.GetItemHeight();
var itemWidth = connector.DataItem.ItemWidth;
var itemHeight = connector.DataItem.ItemHeight;
if (connector.IsInnerPoint)
{

View File

@@ -9,33 +9,10 @@ namespace AIStudio.Wpf.DiagramDesigner
// Wraps info of the dragged object into a class
public class DragObject
{
public Size? DesiredSize
{
get; set;
}
public Size? DesiredMinSize
{
get; set;
}
public Type ContentType
{
get; set;
}
public string Icon
{
get; set;
}
public string Text
{
get; set;
}
public IColorViewModel ColorViewModel
{
get; set;
}
public object DesignerItem
{
get; set;
}
public Size? DesiredSize { get; set; }
public Type ContentType { get; set; }
public string Icon { get; set; }
public IColorViewModel ColorViewModel { get; set; }
public object DesignerItem { get; set; }
}
}

View File

@@ -36,10 +36,6 @@ namespace AIStudio.Wpf.DiagramDesigner
{
get; set;
}
public Size? DesiredMinSize
{
get; set;
}
public string Description
{
get; set;
@@ -50,7 +46,7 @@ namespace AIStudio.Wpf.DiagramDesigner
get; set;
}
public ToolBoxData(string text, string icon, Type type, double width, double height, Size? desiredSize = null, Size? desiredMinSize = null, string description = null)
public ToolBoxData(string text, string icon, Type type, double width, double height, Size? desiredSize = null, string description = null)
{
this.Text = text;
this.Icon = icon;
@@ -58,7 +54,6 @@ namespace AIStudio.Wpf.DiagramDesigner
this.Width = width;
this.Height = height;
this.DesiredSize = desiredSize;
this.DesiredMinSize = desiredMinSize;
this.ColorViewModel = new ColorViewModel();
this.Description = description;
}

View File

@@ -5,7 +5,7 @@
<dd:ColorBrushConverter x:Key="ColorBrushConverter" />
<dd:ConectorOrientationConverter x:Key="ConectorOrientationConverter" />
<dd:ConectorValueConverter x:Key="ConectorValueConverter"/>
<DataTemplate DataType="{x:Type dd:FullyCreatedConnectorInfo}">
<Grid Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}" Cursor="Cross">
<Grid.ContextMenu>
@@ -70,7 +70,7 @@
<!-- transparent extra space makes connector easier to hit -->
<Ellipse x:Name="outer" Fill="Transparent" Opacity="0.3" Margin="-3" />
<Ellipse x:Name="innter" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
</Grid>
</Grid>
<Control x:Name="label">
<Control.Template>
@@ -115,7 +115,7 @@
<ControlTemplate>
<TextBlock x:Name="txtRight" FontSize="10" RenderTransformOrigin="0.5,0.5" TextTrimming="CharacterEllipsis">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ConectorValueConverter}">
<MultiBinding Converter="{StaticResource ConectorValueConverter}">
<Binding Path="." />
<Binding Path="ConnectorChanged" />
</MultiBinding>
@@ -158,58 +158,6 @@
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate DataType="{x:Type dd:ItemsContainerInfo}">
<Grid dd:WidthAndHeightProps.Active="True"
dd:WidthAndHeightProps.BoundActualWidth="{Binding ActualItemWidth,Mode=OneWayToSource}"
dd:WidthAndHeightProps.BoundActualHeight="{Binding ActualItemHeight,Mode=OneWayToSource}">
<Rectangle x:Name="innter"
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
StrokeThickness="{Binding ColorViewModel.LineWidth}"
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding BeAttachTo}" Value="True">
<Setter TargetName="innter" Property="Margin" Value="-1" />
<Setter TargetName="innter" Property="Stroke" Value="#f73438" />
</DataTrigger>
<DataTrigger Binding="{Binding DisableAttachTo}" Value="True">
<Setter TargetName="innter" Property="Margin" Value="-1" />
<Setter TargetName="innter" Property="Stroke" Value="Gray" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<!-- DragThumb Default Template -->
<Style TargetType="{x:Type dd:ItemsContainer}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dd:ItemsContainer}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<Grid>
<ContentPresenter
ContentSource="Border"
ContentTemplate="{TemplateBinding BorderTemplate}"
ContentTemplateSelector="{TemplateBinding BorderTemplateSelector}"
ContentStringFormat="{TemplateBinding BorderStringFormat}"/>
<ContentPresenter
x:Name="ContentPresenter"
Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentControl.ContentTemplateSelector}"
ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}">
</ContentPresenter>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- DragThumb Default Template -->
<Style TargetType="{x:Type c:DragThumb}">
<Setter Property="Template">
@@ -222,5 +170,4 @@
</Style>
</ResourceDictionary>

View File

@@ -12,7 +12,6 @@
<dd:NegativeConverter x:Key="NegativeConverter"/>
<dd:LineDashConverter x:Key="LineDashConverter"/>
<dd:DoubleToThickness x:Key="DoubleToThickness"/>
<dd:InvertBoolConverter x:Key="InvertBoolConverter"/>
<DataTemplate DataType="{x:Type dd:DefaultDesignerItemViewModel}">
<Grid IsHitTestVisible="False">
@@ -99,72 +98,14 @@
</DataTemplate>
<DataTemplate DataType="{x:Type dd:BlockDesignerItemViewModel}">
<dd:BlockBorder>
<Grid x:Name="grid" MinWidth="{Binding MinItemWidth}" MinHeight="{Binding MinItemHeight}">
<Grid IsHitTestVisible="False">
<Rectangle StrokeThickness="1" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
<Border x:Name="left" HorizontalAlignment="Left" Width="5" Background="Transparent"/>
<Control x:Name="PART_Text" IsHitTestVisible="{Binding IsReadOnlyText,Converter={StaticResource InvertBoolConverter}}">
<Control.Style>
<Style TargetType="Control">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ShowText}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<dd:TextControl x:Name="PART_Text" />
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Text,Converter={StaticResource NotNullOrEmptyToBoolConverter}}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<dd:TextControl x:Name="PART_Text" />
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding CustomText}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid/>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Control.Style>
</Control>
</Grid>
<dd:ItemsContainer x:Name="contain"
Margin="20"
ParentPanel="{Binding ElementName=grid}"
GetOffSetFunc="{Binding FirstContain.GetOffSetFunc,Mode=OneWayToSource}"
Border="{Binding FirstContain}">
<ItemsControl x:Name="items" ItemsSource="{Binding FirstContain.Children}">
</ItemsControl>
</dd:ItemsContainer>
</Grid>
</dd:BlockBorder>
<Grid IsHitTestVisible="False">
<Rectangle StrokeThickness="1" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
<Border x:Name="left" HorizontalAlignment="Left" Width="5" Background="Transparent"/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="true">
<Setter TargetName="left" Property="Background" Value="#3399FF"/>
</DataTrigger>
<DataTrigger Binding="{Binding FirstContain}" Value="{x:Null}">
<Setter TargetName="contain" Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>

View File

@@ -38,8 +38,8 @@ namespace AIStudio.Wpf.DiagramDesigner
var connector = ItemContainerGenerator.ContainerFromItem(item) as ContentPresenter;
if (connector != null)
{
Canvas.SetLeft(connector, vm.DataItem.GetItemWidth() * vm.XRatio - vm.ConnectorWidth / 2);
Canvas.SetTop(connector, vm.DataItem.GetItemHeight() * vm.YRatio - vm.ConnectorHeight / 2);
Canvas.SetLeft(connector, vm.DataItem.ItemWidth * vm.XRatio - vm.ConnectorWidth / 2);
Canvas.SetTop(connector, vm.DataItem.ItemHeight * vm.YRatio - vm.ConnectorHeight / 2);
}
}

View File

@@ -344,25 +344,25 @@
<ControlTemplate x:Key="BlockConnectorDecoratorTemplate"
TargetType="{x:Type Control}">
<Grid Margin="{Binding ConnectorMargin}">
<dd:BlockConnector
<dd:Connector
Content="{Binding LeftConnector}"
SnapsToDevicePixels="True"
Orientation="Left"
VerticalAlignment="Stretch"
HorizontalAlignment="Left"/>
<dd:BlockConnector
<dd:Connector
Content="{Binding TopConnector}"
SnapsToDevicePixels="True"
Orientation="Top"
VerticalAlignment="Top"
HorizontalAlignment="Stretch"/>
<dd:BlockConnector
<dd:Connector
Content="{Binding RightConnector}"
SnapsToDevicePixels="True"
Orientation="Right"
VerticalAlignment="Stretch"
HorizontalAlignment="Right"/>
<dd:BlockConnector
<dd:Connector
Content="{Binding BottomConnector}"
SnapsToDevicePixels="True"
Orientation="Bottom"
@@ -827,12 +827,6 @@
Value="{Binding MinItemHeight}" />
<Setter Property="SnapsToDevicePixels"
Value="True" />
<Setter Property="dd:WidthAndHeightProps.Active"
Value="true" />
<Setter Property="dd:WidthAndHeightProps.BoundActualWidth"
Value="{Binding ActualItemWidth,Mode=OneWayToSource}" />
<Setter Property="dd:WidthAndHeightProps.BoundActualHeight"
Value="{Binding ActualItemHeight,Mode=OneWayToSource}" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
@@ -861,13 +855,16 @@
</c:DragThumb.InputBindings>
</c:DragThumb>
<Grid RenderTransformOrigin="0.5,0.5" >
<Grid RenderTransformOrigin="0.5,0.5" >
<!-- PART_ContentPresenter -->
<ContentPresenter x:Name="PART_ContentPresenter"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Content="{TemplateBinding Content}" />
<TextBlock x:Name="PART_Text" Text="{Binding Text}" IsHitTestVisible="False"/>
<!-- PART_ConnectorDecorator -->
<Control x:Name="PART_ConnectorDecorator" Template="{StaticResource BlockConnectorDecoratorTemplate}"/>

View File

@@ -1,213 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner.Geometrys;
using AIStudio.Wpf.DiagramDesigner.Models;
namespace AIStudio.Wpf.DiagramDesigner
{
public class ItemsContainerInfo : SelectableViewModelBase
{
public ItemsContainerInfo(BlockDesignerItemViewModel dataItem) : this(null, dataItem)
{
}
public ItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem) : base(root)
{
this.Parent = dataItem;
}
public ItemsContainerInfo(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
{
}
public ItemsContainerInfo(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
{
}
//public override SelectableItemBase GetSerializableObject()
//{
// return new ConnectorInfoItemBase(this);
//}
protected override void Init(IDiagramViewModel root, bool initNew)
{
base.Init(root, initNew);
}
protected override void InitNew()
{
ColorViewModel = new ColorViewModel()
{
LineWidth = 1,
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
FillColor = new ColorObject() { Color = Colors.Transparent },
};
}
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
{
base.LoadDesignerItemViewModel(designerbase);
//if (designerbase is ConnectorInfoItemBase designer)
//{
// PhysicalConnectorWidth = designer.PhysicalConnectorWidth;
// PhysicalConnectorHeight = designer.PhysicalConnectorHeight;
// Orientation = designer.Orientation;
//}
}
#region
private double _itemWidth = double.NaN;
public double ItemWidth
{
get
{
return _itemWidth;
}
set
{
if (value <= 0) return;
SetProperty(ref _itemWidth, value);
}
}
private double _itemHeight = double.NaN;
public double ItemHeight
{
get
{
return _itemHeight;
}
set
{
if (value <= 0) return;
SetProperty(ref _itemHeight, value);
}
}
private double _actualItemWidth;
public double ActualItemWidth
{
get
{
return _actualItemWidth;
}
set
{
SetProperty(ref _actualItemWidth, value);
}
}
private double _actualItemHeight;
public double ActualItemHeight
{
get
{
return _actualItemHeight;
}
set
{
SetProperty(ref _actualItemHeight, value);
}
}
//public PointBase Position
//{
// get
// {
// var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
// return new PointBase(DataItem.Left + offset.X, DataItem.Top + offset.Y);
// }
//}
//public PointBase MiddlePosition
//{
// get
// {
// return new PointBase(Position.X + GetItemWidth() / 2, Position.Y + GetItemHeight() / 2);
// }
//}
public RectangleBase GetBounds()
{
var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
return new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, GetItemWidth(), GetItemHeight());
}
public BlockDesignerItemViewModel DataItem
{
get
{
return Parent as BlockDesignerItemViewModel;
}
}
public ObservableCollection<BlockDesignerItemViewModel> Children
{
get; set;
} = new ObservableCollection<BlockDesignerItemViewModel>();
private Func<Point> _getOffSetFunc;
public Func<Point> GetOffSetFunc
{
get
{
return _getOffSetFunc;
}
set
{
SetProperty(ref _getOffSetFunc, value);
}
}
private bool _beAttachTo;
public bool BeAttachTo
{
get
{
return _beAttachTo;
}
set
{
SetProperty(ref _beAttachTo, value);
}
}
private bool _disableAttachTo;
public bool DisableAttachTo
{
get
{
return _disableAttachTo;
}
set
{
SetProperty(ref _disableAttachTo, value);
}
}
public virtual bool CanAttachTo(DesignerItemViewModelBase item)
=> item != null && item != this.DataItem && !item.IsReadOnly && item is BlockDesignerItemViewModel;
#endregion
public double GetItemWidth()
{
return double.IsNaN(ItemWidth) ? ActualItemWidth : ItemWidth;
}
public double GetItemHeight()
{
return double.IsNaN(ItemHeight) ? ActualItemHeight : ItemHeight;
}
}
}

View File

@@ -261,7 +261,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
get
{
return new SizeBase(GetItemWidth(), GetItemHeight());
return new SizeBase(ItemWidth, ItemHeight);
}
set
{
@@ -445,7 +445,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
get
{
return new Point(Left + GetItemWidth(), Top + GetItemHeight());
return new Point(Left + ItemWidth, Top + ItemHeight);
}
}
@@ -557,32 +557,6 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private double _actualItemWidth;
public double ActualItemWidth
{
get
{
return _actualItemWidth;
}
set
{
SetProperty(ref _actualItemWidth, value);
}
}
private double _actualItemHeight;
public double ActualItemHeight
{
get
{
return _actualItemHeight;
}
set
{
SetProperty(ref _actualItemHeight, value);
}
}
/// <summary>
/// 连接点是否可以按偏移自定义
/// </summary>
@@ -663,9 +637,9 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (Root.DiagramOption.LayoutOption.CellHorizontalAlignment == CellHorizontalAlignment.Center)
{
if (Root.DiagramOption.LayoutOption.GridCellSize.Width > this.GetItemWidth())
if (Root.DiagramOption.LayoutOption.GridCellSize.Width > this.ItemWidth)
{
this.Left = (int)(this.Left / Root.DiagramOption.LayoutOption.GridCellSize.Width) * Root.DiagramOption.LayoutOption.GridCellSize.Width + Root.DiagramOption.LayoutOption.GridMarginSize.Width + (Root.DiagramOption.LayoutOption.GridCellSize.Width - this.GetItemWidth()) / 2;
this.Left = (int)(this.Left / Root.DiagramOption.LayoutOption.GridCellSize.Width) * Root.DiagramOption.LayoutOption.GridCellSize.Width + Root.DiagramOption.LayoutOption.GridMarginSize.Width + (Root.DiagramOption.LayoutOption.GridCellSize.Width - this.ItemWidth) / 2;
}
}
else if (Root.DiagramOption.LayoutOption.CellHorizontalAlignment == CellHorizontalAlignment.Left)
@@ -674,17 +648,17 @@ namespace AIStudio.Wpf.DiagramDesigner
}
else if (Root.DiagramOption.LayoutOption.CellHorizontalAlignment == CellHorizontalAlignment.Right)
{
if (Root.DiagramOption.LayoutOption.GridCellSize.Width > this.GetItemWidth())
if (Root.DiagramOption.LayoutOption.GridCellSize.Width > this.ItemWidth)
{
this.Left = (int)(this.Left / Root.DiagramOption.LayoutOption.GridCellSize.Width) * Root.DiagramOption.LayoutOption.GridCellSize.Width + Root.DiagramOption.LayoutOption.GridMarginSize.Width + (Root.DiagramOption.LayoutOption.GridCellSize.Width - this.GetItemWidth());
this.Left = (int)(this.Left / Root.DiagramOption.LayoutOption.GridCellSize.Width) * Root.DiagramOption.LayoutOption.GridCellSize.Width + Root.DiagramOption.LayoutOption.GridMarginSize.Width + (Root.DiagramOption.LayoutOption.GridCellSize.Width - this.ItemWidth);
}
}
if (Root.DiagramOption.LayoutOption.CellVerticalAlignment == CellVerticalAlignment.Center)
{
if (Root.DiagramOption.LayoutOption.GridCellSize.Height > this.GetItemHeight())
if (Root.DiagramOption.LayoutOption.GridCellSize.Height > this.ItemHeight)
{
this.Top = (int)(this.Top / Root.DiagramOption.LayoutOption.GridCellSize.Height) * Root.DiagramOption.LayoutOption.GridCellSize.Height + Root.DiagramOption.LayoutOption.GridMarginSize.Height + (Root.DiagramOption.LayoutOption.GridCellSize.Height - this.GetItemHeight()) / 2;
this.Top = (int)(this.Top / Root.DiagramOption.LayoutOption.GridCellSize.Height) * Root.DiagramOption.LayoutOption.GridCellSize.Height + Root.DiagramOption.LayoutOption.GridMarginSize.Height + (Root.DiagramOption.LayoutOption.GridCellSize.Height - this.ItemHeight) / 2;
}
}
else if (Root.DiagramOption.LayoutOption.CellVerticalAlignment == CellVerticalAlignment.Top)
@@ -693,9 +667,9 @@ namespace AIStudio.Wpf.DiagramDesigner
}
else if (Root.DiagramOption.LayoutOption.CellVerticalAlignment == CellVerticalAlignment.Bottom)
{
if (Root.DiagramOption.LayoutOption.GridCellSize.Height > this.GetItemHeight())
if (Root.DiagramOption.LayoutOption.GridCellSize.Height > this.ItemHeight)
{
this.Top = (int)(this.Top / Root.DiagramOption.LayoutOption.GridCellSize.Height) * Root.DiagramOption.LayoutOption.GridCellSize.Height + Root.DiagramOption.LayoutOption.GridMarginSize.Height + (Root.DiagramOption.LayoutOption.GridCellSize.Height - this.GetItemHeight());
this.Top = (int)(this.Top / Root.DiagramOption.LayoutOption.GridCellSize.Height) * Root.DiagramOption.LayoutOption.GridCellSize.Height + Root.DiagramOption.LayoutOption.GridMarginSize.Height + (Root.DiagramOption.LayoutOption.GridCellSize.Height - this.ItemHeight);
}
}
}
@@ -766,24 +740,14 @@ namespace AIStudio.Wpf.DiagramDesigner
var left = leftPort == null ? Position.X : Math.Min(Position.X, leftPort.Position.X);
var top = topPort == null ? Position.Y : Math.Min(Position.Y, topPort.Position.Y);
var right = rightPort == null ? Position.X + GetItemWidth() :
Math.Max(rightPort.Position.X + rightPort.ConnectorWidth, Position.X + GetItemWidth());
var right = rightPort == null ? Position.X + ItemWidth :
Math.Max(rightPort.Position.X + rightPort.ConnectorWidth, Position.X + ItemWidth);
var bottom = bottomPort == null ? Position.Y + ItemHeight :
Math.Max(bottomPort.Position.Y + bottomPort.ConnectorHeight, Position.Y + GetItemHeight());
Math.Max(bottomPort.Position.Y + bottomPort.ConnectorHeight, Position.Y + ItemHeight);
return new RectangleBase(left, top, right, bottom, true);
}
public double GetItemWidth()
{
return double.IsNaN(ItemWidth) ? ActualItemWidth : ItemWidth;
}
public double GetItemHeight()
{
return double.IsNaN(ItemHeight) ? ActualItemHeight : ItemHeight;
}
public IShape GetShape() => ShapeDefiner(this);
public override string ToString()

View File

@@ -1449,7 +1449,7 @@ namespace AIStudio.Wpf.DiagramDesigner
return items;
}
protected virtual void ExecuteDeleteCommand(object parameter)
protected void ExecuteDeleteCommand(object parameter)
{
var items = Delete(parameter, false);
if (items.Any())
@@ -1580,11 +1580,11 @@ namespace AIStudio.Wpf.DiagramDesigner
DoCommandManager.DoNewCommand(this.ToString(),
() => {
double mid = selectedItems.Select(p => p.Top + p.GetItemHeight() / 2).Average();
double mid = selectedItems.Select(p => p.Top + p.ItemHeight / 2).Average();
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Top = mid - item.GetItemHeight() / 2;
item.Top = mid - item.ItemHeight / 2;
}
},
() => {
@@ -1618,11 +1618,11 @@ namespace AIStudio.Wpf.DiagramDesigner
DoCommandManager.DoNewCommand(this.ToString(),
() => {
double top = selectedItems.OrderBy(p => p.Top + p.GetItemHeight()).Select(p => p.Top + p.GetItemHeight()).LastOrDefault();
double top = selectedItems.OrderBy(p => p.Top + p.ItemHeight).Select(p => p.Top + p.ItemHeight).LastOrDefault();
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Top = top - item.GetItemHeight();
item.Top = top - item.ItemHeight;
}
},
() => {
@@ -1694,11 +1694,11 @@ namespace AIStudio.Wpf.DiagramDesigner
DoCommandManager.DoNewCommand(this.ToString(),
() => {
double mid = selectedItems.Select(p => p.Left + p.GetItemWidth() / 2).Average();
double mid = selectedItems.Select(p => p.Left + p.ItemWidth / 2).Average();
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Left = mid - item.GetItemWidth() / 2;
item.Left = mid - item.ItemWidth / 2;
}
},
() => {
@@ -1732,11 +1732,11 @@ namespace AIStudio.Wpf.DiagramDesigner
DoCommandManager.DoNewCommand(this.ToString(),
() => {
double right = selectedItems.OrderBy(p => p.Left + p.GetItemWidth()).Select(p => p.Left + p.GetItemWidth()).LastOrDefault();
double right = selectedItems.OrderBy(p => p.Left + p.ItemWidth).Select(p => p.Left + p.ItemWidth).LastOrDefault();
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Left = right - item.GetItemWidth();
item.Left = right - item.ItemWidth;
}
},
() => {
@@ -1975,8 +1975,8 @@ namespace AIStudio.Wpf.DiagramDesigner
foreach (DesignerItemViewModelBase item in selectedItems)
{
left = Math.Min(left, item.Left);
right = Math.Max(right, item.Left + item.GetItemWidth());
sumWidth += item.GetItemWidth();
right = Math.Max(right, item.Left + item.ItemWidth);
sumWidth += item.ItemWidth;
}
double distance = Math.Max(0, (right - left - sumWidth) / (selectedItems.Count() - 1));
@@ -1989,7 +1989,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
di.Left += delta;
}
offset = offset + item.GetItemWidth() + distance;
offset = offset + item.ItemWidth + distance;
}
},
@@ -2030,8 +2030,8 @@ namespace AIStudio.Wpf.DiagramDesigner
foreach (DesignerItemViewModelBase item in selectedItems)
{
top = Math.Min(top, item.Top);
bottom = Math.Max(bottom, item.Top + item.GetItemHeight());
sumHeight += item.GetItemHeight();
bottom = Math.Max(bottom, item.Top + item.ItemHeight);
sumHeight += item.ItemHeight;
}
double distance = Math.Max(0, (bottom - top - sumHeight) / (selectedItems.Count() - 1));
@@ -2044,7 +2044,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
di.Top += +delta;
}
offset = offset + item.GetItemHeight() + distance;
offset = offset + item.ItemHeight + distance;
}
},
() => {
@@ -2264,8 +2264,8 @@ namespace AIStudio.Wpf.DiagramDesigner
() => {
foreach (var item in selectedItems)
{
item.ItemWidth = selectedItems.FirstOrDefault().GetItemWidth();
item.ItemHeight = selectedItems.FirstOrDefault().GetItemHeight();
item.ItemWidth = selectedItems.FirstOrDefault().ItemWidth;
item.ItemHeight = selectedItems.FirstOrDefault().ItemHeight;
}
},
() => {
@@ -2295,13 +2295,13 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count > 1)
{
Dictionary<DesignerItemViewModelBase, double> infos = selectedItems.ToDictionary(p => p, p => p.GetItemWidth());
Dictionary<DesignerItemViewModelBase, double> infos = selectedItems.ToDictionary(p => p, p => p.ItemWidth);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in selectedItems)
{
item.ItemWidth = selectedItems.FirstOrDefault().GetItemWidth();
item.ItemWidth = selectedItems.FirstOrDefault().ItemWidth;
}
},
() => {
@@ -2331,13 +2331,13 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count > 1)
{
Dictionary<DesignerItemViewModelBase, double> infos = selectedItems.ToDictionary(p => p, p => p.GetItemHeight());
Dictionary<DesignerItemViewModelBase, double> infos = selectedItems.ToDictionary(p => p, p => p.ItemHeight);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in selectedItems)
{
item.ItemHeight = selectedItems.FirstOrDefault().GetItemHeight();
item.ItemHeight = selectedItems.FirstOrDefault().ItemHeight;
}
},
() => {
@@ -3145,37 +3145,6 @@ namespace AIStudio.Wpf.DiagramDesigner
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(parent, next);
}
public ItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel)
{
if (blockDesignerItemViewModel == null)
return null;
List<BlockDesignerItemViewModel> items;
items = Items.OfType<BlockDesignerItemViewModel>().
Where(p => p != blockDesignerItemViewModel)
.ToList();
foreach (var port in items.SelectMany(n => n.Contains))
{
if (port.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())) //如果两个位置相交
{
port.DataItem.ShowConnectors = true;
if (port.CanAttachTo(blockDesignerItemViewModel) == true)
{
port.BeAttachTo = true;
}
else
{
port.DisableAttachTo = true;
}
return port;
}
}
return null;
}
public void ClearNearPort()
{
Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
@@ -3183,91 +3152,6 @@ namespace AIStudio.Wpf.DiagramDesigner
p.DisableAttachTo = false;
p.BeAttachTo = false;
});
}
public void ClearNearContain()
{
Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.Contains).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
.ForEach(p => {
p.DisableAttachTo = false;
p.BeAttachTo = false;
});
}
#endregion
#region Block拖拽预览-
public void PreviewNearBlock(List<BlockDesignerItemViewModel> blocks)
{
if (blocks.Any())
{
ClearNearPort();
ClearNearContain();
foreach (BlockDesignerItemViewModel item in blocks)
{
var contain = FindNearContainerToAttachTo(item);
if (contain != null)
{
continue;
}
FindNearPortToAttachTo(item, false);
}
}
}
public void FinishNearBlock(List<BlockDesignerItemViewModel> blocks)
{
if (blocks.Any())
{
ClearNearPort();
ClearNearContain();
foreach (BlockDesignerItemViewModel item in blocks)
{
var contain = FindNearContainerToAttachTo(item);
if (contain != null)
{
(contain.DataItem as BlockDesignerItemViewModel).AddChild(item);
contain.BeAttachTo = false;
contain.DisableAttachTo = false;
continue;
}
var portTuple = 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).RemoveNext();
}
}
if (portNext != null)
{
item.AddNext(portNext.DataItem as BlockDesignerItemViewModel);
portNext.BeAttachTo = false;
portNext.DisableAttachTo = false;
}
else
{
if (item.Next != null)
{
item.RemoveNext();
}
}
}
}
}
#endregion

View File

@@ -26,8 +26,8 @@ namespace AIStudio.Wpf.DiagramDesigner
x1 = Math.Min(item.Left, x1);
y1 = Math.Min(item.Top, y1);
x2 = Math.Max(item.Left + item.GetItemWidth(), x2);
y2 = Math.Max(item.Top + item.GetItemHeight(), y2);
x2 = Math.Max(item.Left + item.ItemWidth, x2);
y2 = Math.Max(item.Top + item.ItemHeight, y2);
}
return new RectangleBase(new PointBase(x1, y1), new PointBase(x2, y2));

View File

@@ -1,60 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AIStudio.Wpf.DiagramDesigner.Models;
namespace AIStudio.Wpf.DiagramDesigner
{
public class BlockContainDesignerItemViewModel : BlockDesignerItemViewModel
{
public BlockContainDesignerItemViewModel()
{
}
public BlockContainDesignerItemViewModel(IDiagramViewModel root) : base(root)
{
}
public BlockContainDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
{
}
public BlockContainDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
{
}
protected override void InitNew()
{
base.InitNew();
Contains.Add(new ItemsContainerInfo(this.Root, this));
}
public override void AddChild(BlockDesignerItemViewModel child)
{
var oldchildren = FirstContain.Children.FirstOrDefault();
if (oldchildren != null)
{
this.RemoveChild(oldchildren);
}
Root.Items.Remove(child);
FirstContain.Children.Add(child);
base.AddChild(child);
}
public override void RemoveChild(BlockDesignerItemViewModel child)
{
Root.Items.Add(child);
FirstContain.Children.Remove(child);
this.RemoveFromSelection();
child.AddToSelection(true, false);
base.RemoveChild(child);
}
}
}

View File

@@ -1,51 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AIStudio.Wpf.DiagramDesigner.Models;
namespace AIStudio.Wpf.DiagramDesigner
{
public class BlockContainListDesignerItemViewModel : BlockDesignerItemViewModel
{
public BlockContainListDesignerItemViewModel()
{
}
public BlockContainListDesignerItemViewModel(IDiagramViewModel root) : base(root)
{
}
public BlockContainListDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
{
}
public BlockContainListDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
{
}
protected override void InitNew()
{
base.InitNew();
Contains.Add(new ItemsContainerInfo(this.Root, this));
}
public override void AddChild(BlockDesignerItemViewModel child)
{
Root.Items.Remove(child);
FirstContain.Children.Add(child);
base.AddChild(child);
}
public override void RemoveChild(BlockDesignerItemViewModel child)
{
Root.Items.Add(child);
FirstContain.Children.Remove(child);
base.RemoveChild(child);
}
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -28,57 +27,28 @@ namespace AIStudio.Wpf.DiagramDesigner
protected override void InitNew()
{
ItemWidth = double.NaN;
ItemHeight = double.NaN;
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Top));
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Bottom));
IsReadOnlyText = true;
}
public BlockDesignerItemViewModel Next
{
get; set;
get;set;
}
public void AddNext(BlockDesignerItemViewModel next)
{
this.ParentId = new Guid();
this.Parent = null;
next.Left = this.Left;
next.Top = this.Top + this.GetItemHeight();
next.Top = this.Top + this.ItemHeight;
next.ParentId = this.Id;
next.Parent = this;
this.Next = next;
//if (oldnext != null)
//{
// next.AddNext(oldnext);
//}
}
public void RemoveNext()
{
var next = this.Next;
if (next != null)
if (next.Next != null)
{
next.ParentId = new Guid();
next.Parent = null;
this.Next = null;
next.AddNext(next.Next);
}
}
public BlockDesignerItemViewModel GetLastNext()
{
var next = this.Next;
if (next != null)
{
while (next.Next != null)
{
next = next.Next;
}
}
return next;
}
public override void AddToSelection(bool selected, bool clearother)
{
if (clearother)
@@ -94,31 +64,5 @@ namespace AIStudio.Wpf.DiagramDesigner
IsSelected = selected;
}
public virtual void AddChild(BlockDesignerItemViewModel child)
{
child.RemoveFromSelection();
this.AddToSelection(true, false);
}
public virtual void RemoveChild(BlockDesignerItemViewModel child)
{
this.RemoveFromSelection();
child.AddToSelection(true, false);
}
public ObservableCollection<ItemsContainerInfo> Contains
{
get; set;
} = new ObservableCollection<ItemsContainerInfo>();
public ItemsContainerInfo FirstContain
{
get
{
return Contains?.FirstOrDefault();
}
}
}
}

View File

@@ -115,8 +115,8 @@ namespace AIStudio.Wpf.DiagramDesigner
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.None, true);
MouseButtonEventArgs mosueArg = ((EventToCommandArgs)parameter).EventArgs as MouseButtonEventArgs;
var position = mosueArg.GetPosition(((EventToCommandArgs)parameter).Sender as IInputElement);
connector.XRatio = (position.X - connector.ConnectorWidth / 2) / connector.DataItem.GetItemWidth();
connector.YRatio = (position.Y - connector.ConnectorHeight / 2) / connector.DataItem.GetItemHeight();
connector.XRatio = (position.X - connector.ConnectorWidth / 2) / connector.DataItem.ItemWidth;
connector.YRatio = (position.Y - connector.ConnectorHeight / 2) / connector.DataItem.ItemHeight;
AddConnector(connector);
}

View File

@@ -366,11 +366,7 @@ namespace AIStudio.Wpf.DiagramDesigner
FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection, ConnectorVertexType connectorVertexType);
FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection);
Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel, bool isExist);
ItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel);
void ClearNearPort();
void ClearNearContain();
void PreviewNearBlock(List<BlockDesignerItemViewModel> blocks);
void FinishNearBlock(List<BlockDesignerItemViewModel> blocks);
#endregion
event PropertyChangedEventHandler PropertyChanged;