mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-05 09:10:52 +08:00
73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
{
|
|
public class BlockDesignerItemTempLink
|
|
{
|
|
public List<BlockDesignerItemViewModel> Items
|
|
{
|
|
get; set;
|
|
} = new List<BlockDesignerItemViewModel>();
|
|
|
|
public RectangleBase GetBounds(bool includePorts = false)
|
|
{
|
|
return Items.FirstOrDefault().GetBounds();
|
|
}
|
|
|
|
public List<FullyCreatedConnectorInfo> Connectors
|
|
{
|
|
get
|
|
{
|
|
List<FullyCreatedConnectorInfo> connectors = new List<FullyCreatedConnectorInfo>();
|
|
if (Items.FirstOrDefault().TopConnector != null)
|
|
{
|
|
connectors.Add(Items.FirstOrDefault().TopConnector);
|
|
}
|
|
if (Items.FirstOrDefault().LeftConnector != null)
|
|
{
|
|
connectors.Add(Items.FirstOrDefault().LeftConnector);
|
|
}
|
|
if (Items.LastOrDefault().BottomConnector != null)
|
|
{
|
|
connectors.Add(Items.LastOrDefault().BottomConnector);
|
|
}
|
|
if (Items.LastOrDefault().RightConnector != null)
|
|
{
|
|
connectors.Add(Items.LastOrDefault().RightConnector);
|
|
}
|
|
return connectors;
|
|
}
|
|
}
|
|
|
|
public static List<BlockDesignerItemTempLink> Build(List<BlockDesignerItemViewModel> blocks)
|
|
{
|
|
List<BlockDesignerItemTempLink> links = new List<BlockDesignerItemTempLink>();
|
|
foreach (var block in blocks.OrderBy(p => p.BlockLevel).ToList())
|
|
{
|
|
bool success = false;
|
|
foreach (var link in links)
|
|
{
|
|
if (link.Items.LastOrDefault() == block.Prev)
|
|
{
|
|
link.Items.Add(block);
|
|
success = true;
|
|
}
|
|
}
|
|
if (success == false)
|
|
{
|
|
BlockDesignerItemTempLink link = new BlockDesignerItemTempLink();
|
|
link.Items.Add(block);
|
|
links.Add(link);
|
|
}
|
|
}
|
|
return links;
|
|
}
|
|
}
|
|
}
|