mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-17 15:06:36 +08:00
block
This commit is contained in:
@@ -44,6 +44,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
ColorViewModel.FillColor.Color = Colors.Transparent;
|
||||
}
|
||||
|
||||
public new BlockDesignerItemViewModel DataItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent as BlockDesignerItemViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanAttachTo(ConnectorInfoBase port)
|
||||
{
|
||||
|
||||
@@ -134,16 +134,24 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ObservableCollection<BlockDesignerItemViewModel> _children = new ObservableCollection<BlockDesignerItemViewModel>();
|
||||
public ObservableCollection<BlockDesignerItemViewModel> Children
|
||||
{
|
||||
get; set;
|
||||
} = new ObservableCollection<BlockDesignerItemViewModel>();
|
||||
get
|
||||
{
|
||||
return _children;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _children, value);
|
||||
}
|
||||
}
|
||||
|
||||
public List<BlockItemsContainerInfo> ChildrenContain
|
||||
{
|
||||
get
|
||||
{
|
||||
return Children?.SelectMany(p => p.Contains)?.ToList();
|
||||
return Children?.SelectMany(p => p.Containers)?.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,13 +159,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataItem.ParentContain == null)
|
||||
if (DataItem.ParentContainer == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DataItem.ParentContain.ContainLevel + 1;
|
||||
return DataItem.ParentContainer.ContainLevel + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,8 +209,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool CanAttachTo(DesignerItemViewModelBase item)
|
||||
=> item != null && item != this.DataItem && !item.IsReadOnly && item is BlockDesignerItemViewModel;
|
||||
public virtual bool CanAttachTo(BlockDesignerItemViewModel item)
|
||||
=> item != null && item != this.DataItem && !item.IsReadOnly && item.CanContainTo;
|
||||
#endregion
|
||||
|
||||
public double GetItemWidth()
|
||||
@@ -217,13 +225,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void AddChild(BlockDesignerItemViewModel child)
|
||||
{
|
||||
child.ParentContain = this;
|
||||
child.ParentContainer = this;
|
||||
Children.Add(child);
|
||||
}
|
||||
|
||||
public void RemoveChild(BlockDesignerItemViewModel child)
|
||||
{
|
||||
child.ParentContain = null;
|
||||
child.ParentContainer = null;
|
||||
Children.Remove(child);
|
||||
}
|
||||
|
||||
@@ -238,12 +246,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
foreach (var item in children)
|
||||
{
|
||||
if (item.Contains != null)
|
||||
if (item.Containers != null)
|
||||
{
|
||||
foreach (var contain in item.Contains)
|
||||
foreach (var container in item.Containers)
|
||||
{
|
||||
itemsContainers.Add(contain);
|
||||
itemsContainers.AddRange(contain.GetAllContain(contain.Children, false));
|
||||
itemsContainers.Add(container);
|
||||
itemsContainers.AddRange(container.GetAllContain(container.Children, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Reactive.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Xml.Serialization;
|
||||
@@ -1567,7 +1568,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void ExecutedRemoveNextCommand(object parameter)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void ExecutedAddChildCommand(object parameter)
|
||||
@@ -3216,7 +3217,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Where(p => p != blockDesignerItemViewModel)
|
||||
.ToList();
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Contains))
|
||||
foreach (var port in items.SelectMany(n => n.Containers))
|
||||
{
|
||||
if (port.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())) //如果两个位置相交
|
||||
{
|
||||
@@ -3253,6 +3254,144 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// type=0最近且没有依附;=1
|
||||
/// </summary>
|
||||
/// <param name="blockDesignerItemViewModel"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(BlockDesignerItemTempLink blockDesignerItemTempLink, bool isExist)
|
||||
{
|
||||
if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(null, null);
|
||||
|
||||
List<BlockDesignerItemViewModel> items;
|
||||
if (isExist == false)
|
||||
{
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
}
|
||||
|
||||
FullyCreatedConnectorInfo parent = null;
|
||||
FullyCreatedConnectorInfo next = null;
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Connectors).OfType<BlockConnectorInfo>())
|
||||
{
|
||||
//已经被连接的不允许在顶部吸附了
|
||||
if ((port.Orientation == ConnectorOrientation.Top || port.Orientation == ConnectorOrientation.Left) && port.DataItem.Prev != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var port2 in blockDesignerItemTempLink.Connectors)
|
||||
{
|
||||
//parent
|
||||
if (parent == null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Right && port2.Orientation == ConnectorOrientation.Left)
|
||||
|| (port.Orientation == ConnectorOrientation.Bottom && port2.Orientation == ConnectorOrientation.Top))
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
parent = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//next
|
||||
if (next == null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Left && port2.Orientation == ConnectorOrientation.Right)
|
||||
|| (port.Orientation == ConnectorOrientation.Top && port2.Orientation == ConnectorOrientation.Bottom))
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
next = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(parent, next);
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemTempLink blockDesignerItemTempLink)
|
||||
{
|
||||
if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
|
||||
return null;
|
||||
|
||||
List<BlockDesignerItemViewModel> items;
|
||||
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Containers))
|
||||
{
|
||||
if (port.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())) //如果两个位置相交
|
||||
{
|
||||
var innerport = port.GetAllContain(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())).OrderByDescending(p => p.ContainLevel).FirstOrDefault();
|
||||
if (innerport != null)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
if (innerport.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
innerport.BeAttachTo = true;
|
||||
return innerport;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// innerport.DisableAttachTo = true;
|
||||
// return null;
|
||||
//}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// port.DisableAttachTo = true;
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ClearNearPort()
|
||||
{
|
||||
Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
@@ -3260,8 +3399,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ClearNearContain()
|
||||
@@ -3281,10 +3418,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
ClearNearPort();
|
||||
ClearNearContain();
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
{
|
||||
var contain = FindNearContainerToAttachTo(item);
|
||||
if (contain != null)
|
||||
var container = FindNearContainerToAttachTo(item);
|
||||
if (container != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -3301,14 +3439,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
ClearNearPort();
|
||||
ClearNearContain();
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
{
|
||||
var contain = FindNearContainerToAttachTo(item);
|
||||
if (contain != null)
|
||||
var container = FindNearContainerToAttachTo(item);
|
||||
if (container != null)
|
||||
{
|
||||
(contain.DataItem as BlockDesignerItemViewModel).AddChild(item);
|
||||
contain.BeAttachTo = false;
|
||||
contain.DisableAttachTo = false;
|
||||
(container.DataItem as BlockDesignerItemViewModel).AddChild(item.Items.FirstOrDefault(), container);//待完善
|
||||
container.BeAttachTo = false;
|
||||
container.DisableAttachTo = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -3318,35 +3458,35 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (portParent != null)
|
||||
{
|
||||
(portParent.DataItem as BlockDesignerItemViewModel).AddNext(item);
|
||||
(portParent.DataItem as BlockDesignerItemViewModel).AddNext(item.Items.FirstOrDefault());
|
||||
portParent.BeAttachTo = false;
|
||||
portParent.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Parent != null)
|
||||
if (item.Items.FirstOrDefault().Parent != null)
|
||||
{
|
||||
(item.Parent as BlockDesignerItemViewModel).RemoveNext();
|
||||
(item.Items.FirstOrDefault().Parent as BlockDesignerItemViewModel).RemoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
if (portNext != null)
|
||||
{
|
||||
item.AddNext(portNext.DataItem as BlockDesignerItemViewModel);
|
||||
item.Items.LastOrDefault().AddNext(portNext.DataItem as BlockDesignerItemViewModel);
|
||||
portNext.BeAttachTo = false;
|
||||
portNext.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Next != null)
|
||||
if (item.Items.LastOrDefault().Next != null)
|
||||
{
|
||||
item.RemoveNext();
|
||||
item.Items.LastOrDefault().RemoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user