mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
xx
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -146,11 +147,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
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)
|
||||
{
|
||||
firstPoint = null;
|
||||
if (Info?.Children?.Count > 0)
|
||||
{
|
||||
var borders = VisualHelper.FindVisualChildren<BlockBorder>(this);
|
||||
BlockBorder innerblock = null;
|
||||
BlockDesignerItemViewModel dragObject = null;
|
||||
Point dragOffset = new Point();
|
||||
foreach (var border in borders)
|
||||
{
|
||||
var itemsContainer = VisualHelper.TryFindParent<ItemsContainer>(border);
|
||||
if (this != itemsContainer)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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))
|
||||
@@ -167,10 +178,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (canvas != null)
|
||||
{
|
||||
canvas.SourceItemsContainer = this;
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
firstPoint = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,7 +190,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
base.OnMouseUp(e);
|
||||
|
||||
firstPoint = null;
|
||||
DragObject = null;
|
||||
}
|
||||
|
||||
public ConnectorOrientation Orientation
|
||||
|
||||
@@ -227,19 +227,23 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Children.Remove(child);
|
||||
}
|
||||
|
||||
public List<ItemsContainerInfo> GetAllContain(ObservableCollection<BlockDesignerItemViewModel> children)
|
||||
public List<ItemsContainerInfo> GetAllContain(ObservableCollection<BlockDesignerItemViewModel> children, bool self)
|
||||
{
|
||||
List <ItemsContainerInfo> itemsContainers= new List <ItemsContainerInfo>();
|
||||
if (self)
|
||||
{
|
||||
itemsContainers.Add(this);
|
||||
}
|
||||
if (children != null)
|
||||
{
|
||||
foreach (var item in children)
|
||||
{
|
||||
if (item.Contains != null)
|
||||
{
|
||||
itemsContainers.AddRange(item.Contains);
|
||||
foreach (var contain in item.Contains)
|
||||
{
|
||||
itemsContainers.AddRange(contain.GetAllContain(contain.Children));
|
||||
itemsContainers.Add(contain);
|
||||
itemsContainers.AddRange(contain.GetAllContain(contain.Children, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3160,17 +3160,33 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (port.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())) //如果两个位置相交
|
||||
{
|
||||
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port.CanAttachTo(blockDesignerItemViewModel) == true)
|
||||
var innerport = port.GetAllContain(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())).OrderByDescending(p => p.ContainLevel).FirstOrDefault();
|
||||
if (innerport != null)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
if (innerport.CanAttachTo(blockDesignerItemViewModel) == true)
|
||||
{
|
||||
innerport.BeAttachTo = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
innerport.DisableAttachTo = true;
|
||||
}
|
||||
return innerport;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port.CanAttachTo(blockDesignerItemViewModel) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
}
|
||||
return port;
|
||||
}
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3190,7 +3206,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void ClearNearContain()
|
||||
{
|
||||
Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.Contains).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.GetAllContain()).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public virtual void AddChild(BlockDesignerItemViewModel child)
|
||||
{
|
||||
child.RemoveFromSelection();
|
||||
this.AddToSelection(true, false);
|
||||
this.GetRootParent.AddToSelection(true, true);
|
||||
|
||||
System.Windows.Application.Current?.Dispatcher.BeginInvoke(new Action(async () => {
|
||||
await Task.Delay(10);
|
||||
@@ -136,7 +136,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public virtual void RemoveChild(BlockDesignerItemViewModel child)
|
||||
{
|
||||
this.RemoveFromSelection();
|
||||
child.AddToSelection(true, false);
|
||||
|
||||
child.AddToSelection(true, true);
|
||||
|
||||
System.Windows.Application.Current?.Dispatcher.BeginInvoke(new Action(async () => {
|
||||
await Task.Delay(10);
|
||||
@@ -155,6 +156,26 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return Contains?.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemsContainerInfo> GetAllContain()
|
||||
{
|
||||
return Contains.SelectMany(p => p.GetAllContain(p.Children, true)).ToList();
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel GetRootParent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ParentContain == null)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ParentContain.DataItem.GetRootParent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user