using Avalonia;
using Serein.Library;
using Serein.Workbench.Avalonia.Custom.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serein.Workbench.Avalonia.Model
{
///
/// 节点之间连接线的相关控制方法
///
public class ConnectingData
{
///
/// 是否正在创建连线
///
public bool IsCreateing { get; set; }
///
/// 起始控制点
///
public NodeJunctionView? StartJunction { get; set; }
///
/// 当前的控制点
///
public NodeJunctionView? CurrentJunction { get; set; }
///
/// 开始坐标
///
public Point StartPoint { get; set; }
///
/// 线条样式
///
public MyLine? TempLine { get; set; }
///
/// 线条类别(方法调用)
///
public ConnectionInvokeType ConnectionInvokeType { get; set; } = ConnectionInvokeType.IsSucceed;
///
/// 线条类别(参数传递)
///
public ConnectionArgSourceType ConnectionArgSourceType { get; set; } = ConnectionArgSourceType.GetOtherNodeData;
///
/// 判断当前连接类型
///
public JunctionOfConnectionType? Type => StartJunction?.JunctionType.ToConnectyionType();
///
/// 是否允许连接
///
public bool IsCanConnected
{
get
{
if (StartJunction is null
|| CurrentJunction is null
)
{
return false;
}
if(StartJunction?.MyNode is null)
{
return false;
}
if (!StartJunction.MyNode.Equals(CurrentJunction.MyNode)
&& StartJunction.JunctionType.IsCanConnection(CurrentJunction.JunctionType))
{
return true;
}
else
{
return false;
}
}
}
///
/// 更新临时的连接线
///
///
public void UpdatePoint(Point point)
{
if (StartJunction is null
|| CurrentJunction is null
)
{
return;
}
if (StartJunction.JunctionType == Library.JunctionType.Execute
|| StartJunction.JunctionType == Library.JunctionType.ArgData)
{
TempLine?.Line.UpdateStartPoints(point);
}
else
{
TempLine?.Line.UpdateEndPoints(point);
}
}
///
/// 重置
///
public void Reset()
{
IsCreateing = false;
StartJunction = null;
CurrentJunction = null;
TempLine?.Remove();
ConnectionInvokeType = ConnectionInvokeType.IsSucceed;
ConnectionArgSourceType = ConnectionArgSourceType.GetOtherNodeData;
}
}
}