From 56c3aac8e87c0a80eff5c26f6e7aece17103effd Mon Sep 17 00:00:00 2001 From: kwai Date: Fri, 16 Jun 2023 19:03:15 +0800 Subject: [PATCH] xx --- ...emsContainer.cs => BlockItemsContainer.cs} | 60 ++++++---- .../Controls/BlockItemsControl.xaml | 23 ++++ .../Controls/BlockItemsControl.xaml.cs | 33 ++++++ .../Controls/DesignerCanvas.cs | 6 +- .../Themes/ConnectorItem.xaml | 6 +- .../Themes/DesignerItem.xaml | 107 +++++++++--------- ...inerInfo.cs => BlockItemsContainerInfo.cs} | 16 +-- .../BaseViewModel/DiagramViewModel.cs | 2 +- .../BlockContainDesignerItemViewModel.cs | 2 +- .../BlockContainListDesignerItemViewModel.cs | 2 +- .../BlockDesignerItemViewModel.cs | 10 +- .../ViewModels/IDiagramViewModel.cs | 2 +- 12 files changed, 167 insertions(+), 102 deletions(-) rename AIStudio.Wpf.DiagramDesigner/Controls/{ItemsContainer.cs => BlockItemsContainer.cs} (75%) create mode 100644 AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml create mode 100644 AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml.cs rename AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/{ItemsContainerInfo.cs => BlockItemsContainerInfo.cs} (87%) diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/ItemsContainer.cs b/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsContainer.cs similarity index 75% rename from AIStudio.Wpf.DiagramDesigner/Controls/ItemsContainer.cs rename to AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsContainer.cs index 5f2a6de..b20d225 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/ItemsContainer.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsContainer.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Reflection; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; @@ -10,15 +12,15 @@ using AIStudio.Wpf.DiagramDesigner.Helpers; namespace AIStudio.Wpf.DiagramDesigner { - public class ItemsContainer : ContentControl + public class BlockItemsContainer : ContentControl { - static ItemsContainer() + static BlockItemsContainer() { - DefaultStyleKeyProperty.OverrideMetadata(typeof(ItemsContainer), new FrameworkPropertyMetadata(typeof(ItemsContainer))); + DefaultStyleKeyProperty.OverrideMetadata(typeof(BlockItemsContainer), new FrameworkPropertyMetadata(typeof(BlockItemsContainer))); } public static readonly DependencyProperty BorderProperty = DependencyProperty.Register( - nameof(Border), typeof(object), typeof(ItemsContainer), new PropertyMetadata(default(object))); + nameof(Border), typeof(object), typeof(BlockItemsContainer), new PropertyMetadata(default(object))); public object Border { @@ -27,7 +29,7 @@ namespace AIStudio.Wpf.DiagramDesigner } public static readonly DependencyProperty BorderTemplateProperty = DependencyProperty.Register( - nameof(BorderTemplate), typeof(DataTemplate), typeof(ItemsContainer), new PropertyMetadata(default(DataTemplate))); + nameof(BorderTemplate), typeof(DataTemplate), typeof(BlockItemsContainer), new PropertyMetadata(default(DataTemplate))); [Bindable(true), Category("Content")] public DataTemplate BorderTemplate @@ -37,7 +39,7 @@ namespace AIStudio.Wpf.DiagramDesigner } public static readonly DependencyProperty BorderTemplateSelectorProperty = DependencyProperty.Register( - nameof(BorderTemplateSelector), typeof(DataTemplateSelector), typeof(ItemsContainer), new PropertyMetadata(default(DataTemplateSelector))); + nameof(BorderTemplateSelector), typeof(DataTemplateSelector), typeof(BlockItemsContainer), new PropertyMetadata(default(DataTemplateSelector))); [Bindable(true), Category("Content")] public DataTemplateSelector BorderTemplateSelector @@ -47,7 +49,7 @@ namespace AIStudio.Wpf.DiagramDesigner } public static readonly DependencyProperty BorderStringFormatProperty = DependencyProperty.Register( - nameof(BorderStringFormat), typeof(string), typeof(ItemsContainer), new PropertyMetadata(default(string))); + nameof(BorderStringFormat), typeof(string), typeof(BlockItemsContainer), new PropertyMetadata(default(string))); [Bindable(true), Category("Content")] public string BorderStringFormat @@ -58,7 +60,7 @@ namespace AIStudio.Wpf.DiagramDesigner public static readonly DependencyProperty ParentPanelProperty = - DependencyProperty.Register(nameof(ParentPanel), typeof(FrameworkElement), typeof(ItemsContainer), + DependencyProperty.Register(nameof(ParentPanel), typeof(FrameworkElement), typeof(BlockItemsContainer), new FrameworkPropertyMetadata(null)); public FrameworkElement ParentPanel @@ -76,7 +78,7 @@ namespace AIStudio.Wpf.DiagramDesigner public static readonly DependencyProperty GetOffSetFuncProperty = DependencyProperty.Register(nameof(GetOffSetFunc), typeof(Func), - typeof(ItemsContainer), + typeof(BlockItemsContainer), new FrameworkPropertyMetadata(null)); public Func GetOffSetFunc { @@ -98,14 +100,14 @@ namespace AIStudio.Wpf.DiagramDesigner } } - public ItemsContainerInfo Info + public BlockItemsContainerInfo Info { get { - if (Border is ItemsContainerInfo itemsContainerInfo) + if (Border is BlockItemsContainerInfo itemsContainerInfo) return itemsContainerInfo; - return this.DataContext as ItemsContainerInfo; + return this.DataContext as BlockItemsContainerInfo; } } @@ -119,11 +121,18 @@ namespace AIStudio.Wpf.DiagramDesigner get; private set; } - public ItemsContainer() + public Point? FirstPoint + { + get; private set; + } + + public BlockItemsContainer() { } + public static List Containers = new List(); + public override void OnApplyTemplate() { base.OnApplyTemplate(); @@ -131,33 +140,31 @@ namespace AIStudio.Wpf.DiagramDesigner GetOffSetFunc = GetOffSet; } - Point? firstPoint; + protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); - firstPoint = e.GetPosition(this); + FirstPoint = e.GetPosition(this); + Containers.Add(this); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); - if (firstPoint != null) + 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 (Math.Sqrt(Math.Pow(FirstPoint.Value.X - currentPoint.X, 2) + Math.Pow(FirstPoint.Value.Y - currentPoint.Y, 2)) > 5) { - firstPoint = null; + FirstPoint = null; if (Info?.Children?.Count > 0) { var borders = VisualHelper.FindVisualChildren(this); - BlockBorder innerblock = null; - BlockDesignerItemViewModel dragObject = null; - Point dragOffset = new Point(); foreach (var border in borders) { - var itemsContainer = VisualHelper.TryFindParent(border); - if (this != itemsContainer) + var itemsContainers = VisualHelper.TryFindParent(border); + if (this != itemsContainers) { continue; } @@ -174,9 +181,10 @@ namespace AIStudio.Wpf.DiagramDesigner if (DragObject != null) { + Containers.ForEach(p => p.FirstPoint = null); DesignerCanvas canvas = GetDesignerCanvas(this); if (canvas != null) - { + { canvas.SourceItemsContainer = this; e.Handled = true; } @@ -189,7 +197,9 @@ namespace AIStudio.Wpf.DiagramDesigner { base.OnMouseUp(e); - firstPoint = null; + FirstPoint = null; + + Containers.Clear(); } public ConnectorOrientation Orientation diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml b/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml new file mode 100644 index 0000000..72e6083 --- /dev/null +++ b/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml @@ -0,0 +1,23 @@ + + + + + diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml.cs b/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml.cs new file mode 100644 index 0000000..eaadb10 --- /dev/null +++ b/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AIStudio.Wpf.DiagramDesigner +{ + /// + /// BlockItemsControl.xaml 的交互逻辑 + /// + public partial class BlockItemsControl : ItemsControl + { + public BlockItemsControl() + { + InitializeComponent(); + } + + protected override System.Windows.DependencyObject GetContainerForItemOverride() + { + return new ListBoxItem(); + } + } +} diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs index 40560cb..a64a4c4 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs @@ -84,8 +84,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private ItemsContainer _sourceItemsContainer; - public ItemsContainer SourceItemsContainer + private BlockItemsContainer _sourceItemsContainer; + public BlockItemsContainer SourceItemsContainer { get { @@ -98,7 +98,7 @@ namespace AIStudio.Wpf.DiagramDesigner _sourceItemsContainer = value; if (_sourceItemsContainer != null) { - ItemsContainerInfo sourceDataItem = _sourceItemsContainer.Info; + BlockItemsContainerInfo sourceDataItem = _sourceItemsContainer.Info; sourceDataItem.DataItem.RemoveChild(_sourceItemsContainer.DragObject); diff --git a/AIStudio.Wpf.DiagramDesigner/Themes/ConnectorItem.xaml b/AIStudio.Wpf.DiagramDesigner/Themes/ConnectorItem.xaml index aa0855b..db036e5 100644 --- a/AIStudio.Wpf.DiagramDesigner/Themes/ConnectorItem.xaml +++ b/AIStudio.Wpf.DiagramDesigner/Themes/ConnectorItem.xaml @@ -158,7 +158,7 @@ - + @@ -181,10 +181,10 @@ - - - - - + + + + + + + + + + - + + + + + - - - - diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/ItemsContainerInfo.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs similarity index 87% rename from AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/ItemsContainerInfo.cs rename to AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs index ab294bc..2853835 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/ItemsContainerInfo.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs @@ -10,24 +10,24 @@ using AIStudio.Wpf.DiagramDesigner.Models; namespace AIStudio.Wpf.DiagramDesigner { - public class ItemsContainerInfo : SelectableViewModelBase + public class BlockItemsContainerInfo : SelectableViewModelBase { - public ItemsContainerInfo(BlockDesignerItemViewModel dataItem) : this(null, dataItem) + public BlockItemsContainerInfo(BlockDesignerItemViewModel dataItem) : this(null, dataItem) { } - public ItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem) : base(root) + public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem) : base(root) { this.Parent = dataItem; } - public ItemsContainerInfo(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer) + public BlockItemsContainerInfo(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer) { } - public ItemsContainerInfo(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType) + public BlockItemsContainerInfo(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType) { } @@ -139,7 +139,7 @@ namespace AIStudio.Wpf.DiagramDesigner get; set; } = new ObservableCollection(); - public List ChildrenContain + public List ChildrenContain { get { @@ -227,9 +227,9 @@ namespace AIStudio.Wpf.DiagramDesigner Children.Remove(child); } - public List GetAllContain(ObservableCollection children, bool self) + public List GetAllContain(ObservableCollection children, bool self) { - List itemsContainers= new List (); + List itemsContainers= new List (); if (self) { itemsContainers.Add(this); diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs index 4851f91..915f25c 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs @@ -3145,7 +3145,7 @@ namespace AIStudio.Wpf.DiagramDesigner return new Tuple(parent, next); } - public ItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel) + public BlockItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel) { if (blockDesignerItemViewModel == null) return null; diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockContainDesignerItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockContainDesignerItemViewModel.cs index af72b8b..39f74f2 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockContainDesignerItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockContainDesignerItemViewModel.cs @@ -29,7 +29,7 @@ namespace AIStudio.Wpf.DiagramDesigner { base.InitNew(); - Contains.Add(new ItemsContainerInfo(this.Root, this)); + Contains.Add(new BlockItemsContainerInfo(this.Root, this)); } public override void AddChild(BlockDesignerItemViewModel child) diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockContainListDesignerItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockContainListDesignerItemViewModel.cs index e0b9a7b..bcc91d3 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockContainListDesignerItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockContainListDesignerItemViewModel.cs @@ -29,7 +29,7 @@ namespace AIStudio.Wpf.DiagramDesigner { base.InitNew(); - Contains.Add(new ItemsContainerInfo(this.Root, this)); + Contains.Add(new BlockItemsContainerInfo(this.Root, this)); } public override void AddChild(BlockDesignerItemViewModel child) diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockDesignerItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockDesignerItemViewModel.cs index 6dbf62f..de3db7a 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockDesignerItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockDesignerItemViewModel.cs @@ -41,7 +41,7 @@ namespace AIStudio.Wpf.DiagramDesigner get; set; } - public ItemsContainerInfo ParentContain + public BlockItemsContainerInfo ParentContain { get; set; } @@ -145,12 +145,12 @@ namespace AIStudio.Wpf.DiagramDesigner })); } - public ObservableCollection Contains + public ObservableCollection Contains { get; set; - } = new ObservableCollection(); + } = new ObservableCollection(); - public ItemsContainerInfo FirstContain + public BlockItemsContainerInfo FirstContain { get { @@ -158,7 +158,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } - public List GetAllContain() + public List GetAllContain() { return Contains.SelectMany(p => p.GetAllContain(p.Children, true)).ToList(); } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs index 68114cc..6696ca2 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs @@ -366,7 +366,7 @@ namespace AIStudio.Wpf.DiagramDesigner FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection, ConnectorVertexType connectorVertexType); FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection); Tuple FindNearPortToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel, bool isExist); - ItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel); + BlockItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel); void ClearNearPort(); void ClearNearContain(); void PreviewNearBlock(List blocks);