using Avalonia; using Avalonia.Threading; using Serein.Library; using Serein.Workbench.Avalonia.Api; using Serein.Workbench.Avalonia.Custom.Views; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Serein.Workbench.Avalonia.Model { /// /// 节点之间连接线的相关控制方法 /// internal class ConnectingManage { /// /// 是否正在创建连线 /// public bool IsCreateing { get; set; } /// /// 起始控制点 /// public NodeJunctionView? StartJunction { get; set; } /// /// 当前的控制点 /// public NodeJunctionView? CurrentJunction { get; set; } /// /// 线条样式 /// public NodeConnectionLineControl? TempLine { get; set; } /// /// 线条类别(方法调用) /// public ConnectionInvokeType ConnectionInvokeType { get; set; } = ConnectionInvokeType.IsSucceed; /// /// 线条类别(参数传递) /// public ConnectionArgSourceType ConnectionArgSourceType { get; set; } = ConnectionArgSourceType.GetOtherNodeData; /// /// 判断当前连接类型 /// public JunctionOfConnectionType? Type => StartJunction?.JunctionType.ToConnectyionType(); private readonly INodeOperationService nodeOperationService1; /// /// 是否允许连接 /// public bool IsCanConnected() { if (StartJunction is null || CurrentJunction is null ) { return false; } if (StartJunction?.MyNode is null || StartJunction.MyNode.Equals(CurrentJunction.MyNode)) return false; if (StartJunction.JunctionType.IsCanConnection(CurrentJunction.JunctionType)) { return true; } else { return false; } } /// /// 更新临时的连接线 /// /// public void UpdatePoint(Point point) { if (StartJunction is null || CurrentJunction is null ) { return; } if (IsCanConnected()) { return; } if (StartJunction.JunctionType == Library.JunctionType.Execute || StartJunction.JunctionType == Library.JunctionType.ArgData) { TempLine?.RefreshLeftPointOfTempLineDsiplay(point); } else { TempLine?.RefreshRightPointOfTempLineDsiplay(point); } } /// /// 重置 /// public void Reset() { if(CurrentJunction is not null) { CurrentJunction.IsPreviewing = false; Dispatcher.UIThread.InvokeAsync(CurrentJunction.InvalidateVisual, DispatcherPriority.Background); } if(StartJunction is not null) { StartJunction.IsPreviewing = false; Dispatcher.UIThread.InvokeAsync(StartJunction.InvalidateVisual, DispatcherPriority.Background); } IsCreateing = false; TempLine?.Remove(); ConnectionInvokeType = ConnectionInvokeType.IsSucceed; ConnectionArgSourceType = ConnectionArgSourceType.GetOtherNodeData; } } }