mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-12 12:16:37 +08:00
block
This commit is contained in:
@@ -61,6 +61,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,7 +607,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SetSinkPort(nearPort);
|
||||
}
|
||||
}
|
||||
Root?.ClearNearPort();
|
||||
Root?.ClearAttachTo();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public abstract class ConnectorInfoBase : SelectableViewModelBase
|
||||
public abstract class ConnectorInfoBase : SelectableViewModelBase, IAttachTo
|
||||
{
|
||||
public ConnectorInfoBase(ConnectorOrientation orientation) : this(null, orientation)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BlockItemsContainerInfo : SelectableViewModelBase
|
||||
public class BlockItemsContainerInfo : SelectableViewModelBase, IAttachTo
|
||||
{
|
||||
public BlockItemsContainerInfo(BlockDesignerItemViewModel dataItem, bool onlyOneChild, List<string> childFlag) : this(null, dataItem, onlyOneChild, childFlag)
|
||||
{
|
||||
|
||||
@@ -2979,7 +2979,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
});
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -6,8 +6,13 @@ using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public static class DiagramViewModelHelper
|
||||
public static partial class DiagramViewModelHelper
|
||||
{
|
||||
static List<IAttachTo> AttachTos
|
||||
{
|
||||
get; set;
|
||||
} = new List<IAttachTo>();
|
||||
|
||||
public static DesignerItemViewModelBase GetConnectorDataItem(IEnumerable<SelectableDesignerItemViewModelBase> items, Guid conectorDataItemId, Type connectorDataItemType)
|
||||
{
|
||||
DesignerItemViewModelBase dataItem = items.OfType<DesignerItemViewModelBase>().Single(x => x.Id == conectorDataItemId);
|
||||
@@ -44,7 +49,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection == null)
|
||||
return null;
|
||||
|
||||
diagramViewModel.ClearNearPort();
|
||||
diagramViewModel.ClearAttachTo();
|
||||
foreach (var port in diagramViewModel.Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors))
|
||||
{
|
||||
if (connectorVertexType == ConnectorVertexType.Start)
|
||||
@@ -54,13 +59,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection.SinkConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -72,13 +77,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection.SourceConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +98,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection == null)
|
||||
return null;
|
||||
|
||||
diagramViewModel.ClearNearPort();
|
||||
diagramViewModel.ClearAttachTo();
|
||||
foreach (var port in diagramViewModel.Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors))
|
||||
{
|
||||
if (partialConnection.OnGoingPosition.DistanceTo(port.Position) < diagramViewModel.DiagramOption.SnappingOption.SnappingRadius)
|
||||
@@ -101,31 +106,44 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (partialConnection.SourceConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void ClearNearPort(this IDiagramViewModel diagramViewModel)
|
||||
public static void AddAttachTo(this IDiagramViewModel diagramViewModel, IAttachTo item, bool beAttachTo)
|
||||
{
|
||||
diagramViewModel.Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
if (beAttachTo)
|
||||
{
|
||||
item.BeAttachTo = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.DisableAttachTo = true;
|
||||
}
|
||||
AttachTos.Add(item);
|
||||
}
|
||||
|
||||
public static void ClearAttachTo(this IDiagramViewModel diagramViewModel)
|
||||
{
|
||||
AttachTos.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
AttachTos.Clear();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public static class BlockDesignerItemViewModelHelper
|
||||
public static partial class BlockDesignerItemViewModelHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// type=0最近且没有依附;=1
|
||||
@@ -55,13 +55,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
parent = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,13 +80,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
next = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,20 +98,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(parent, next);
|
||||
}
|
||||
|
||||
|
||||
public static void ClearNearContain(this IDiagramViewModel diagramViewModel)
|
||||
{
|
||||
diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.GetAllContainers()).ToList()
|
||||
.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
p.Children.SelectMany(n => n.Connectors).Where(q => q.BeAttachTo == true || q.DisableAttachTo == true).ToList().ForEach(q => {
|
||||
q.DisableAttachTo = false;
|
||||
q.BeAttachTo = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static BlockItemsContainerInfo FindNearContainerToAttachTo(this IDiagramViewModel diagramViewModel, BlockDesignerItemTempLink blockDesignerItemTempLink)
|
||||
{
|
||||
if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
|
||||
@@ -127,20 +113,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
var innerport = container.GetAllContainers(container.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())).OrderByDescending(p => p.ContainerLevel).FirstOrDefault();
|
||||
if (innerport != null)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
{
|
||||
if (innerport.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
if (innerport.OnlyOneChild || innerport.Children.Count == 0)
|
||||
{
|
||||
innerport.BeAttachTo = true;
|
||||
return innerport;
|
||||
diagramViewModel.AddAttachTo(innerport, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.FindNearPortToAttachTo(innerport.Children.ToList(), blockDesignerItemTempLink);
|
||||
return innerport;
|
||||
diagramViewModel.FindNearPortToAttachTo(innerport.Children.ToList(), blockDesignerItemTempLink);
|
||||
}
|
||||
return innerport;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
@@ -151,19 +136,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
container.DataItem.ShowConnectors = true;
|
||||
|
||||
if (container.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
container.DataItem.ShowConnectors = true;
|
||||
if (container.OnlyOneChild || container.Children.Count == 0)
|
||||
{
|
||||
container.BeAttachTo = true;
|
||||
return container;
|
||||
diagramViewModel.AddAttachTo(container, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.FindNearPortToAttachTo(container.Children.ToList(), blockDesignerItemTempLink);
|
||||
return container;
|
||||
}
|
||||
diagramViewModel.FindNearPortToAttachTo(container.Children.ToList(), blockDesignerItemTempLink);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
@@ -185,8 +170,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (blocks.Any())
|
||||
{
|
||||
diagramViewModel.ClearNearPort();
|
||||
diagramViewModel.ClearNearContain();
|
||||
diagramViewModel.ClearAttachTo();
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
{
|
||||
@@ -208,9 +192,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return;
|
||||
|
||||
if (blocks.Any())
|
||||
{
|
||||
diagramViewModel.ClearNearPort();
|
||||
diagramViewModel.ClearNearContain();
|
||||
{
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
@@ -228,14 +210,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
index ++;
|
||||
}
|
||||
}
|
||||
diagramViewModel.InsertChildCommand.Execute(new BlockContainerPara() { Item = container.DataItem, Child = item.Items.FirstOrDefault(), Container = container, Index = index });
|
||||
|
||||
container.BeAttachTo = false;
|
||||
container.DisableAttachTo = false;
|
||||
container.Children.SelectMany(n => n.Connectors).Where(q => q.BeAttachTo == true || q.DisableAttachTo == true).ToList().ForEach(q => {
|
||||
q.DisableAttachTo = false;
|
||||
q.BeAttachTo = false;
|
||||
});
|
||||
diagramViewModel.InsertChildCommand.Execute(new BlockContainerPara() { Item = container.DataItem, Child = item.Items.FirstOrDefault(), Container = container, Index = index });
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -271,6 +246,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
diagramViewModel.ClearAttachTo();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
22
AIStudio.Wpf.DiagramDesigner/ViewModels/IAttachTo.cs
Normal file
22
AIStudio.Wpf.DiagramDesigner/ViewModels/IAttachTo.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IAttachTo
|
||||
{
|
||||
bool BeAttachTo
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
|
||||
bool DisableAttachTo
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user