2025-01-04 22:25:42 +08:00
|
|
|
|
using Avalonia;
|
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
using Avalonia.Controls.Shapes;
|
|
|
|
|
|
using Avalonia.Media;
|
|
|
|
|
|
using Avalonia.VisualTree;
|
|
|
|
|
|
using Serein.Library;
|
|
|
|
|
|
using Serein.Script.Node;
|
2025-01-22 21:09:52 +08:00
|
|
|
|
using Serein.Workbench.Avalonia.Custom.Views;
|
2025-01-04 22:25:42 +08:00
|
|
|
|
using Serein.Workbench.Avalonia.Extension;
|
|
|
|
|
|
using Serein.Workbench.Avalonia.Services;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Color = Avalonia.Media.Color;
|
|
|
|
|
|
using Point = Avalonia.Point;
|
|
|
|
|
|
|
2025-01-22 21:09:52 +08:00
|
|
|
|
namespace Serein.Workbench.Avalonia.Model
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-22 21:09:52 +08:00
|
|
|
|
|
|
|
|
|
|
public class NodeConnectionLineControl
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 线条类别(方法调用)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ConnectionInvokeType ConnectionInvokeType { get; set; } = ConnectionInvokeType.IsSucceed;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 线条类别(参数传递)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ConnectionArgSourceType ConnectionArgSourceType { get; set; } = ConnectionArgSourceType.GetOtherNodeData;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 画布
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private Canvas Canvas;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 连接线的起点
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private NodeJunctionView? LeftNodeJunctionView;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 连接线的终点
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private NodeJunctionView? RightNodeJunctionView;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 连接时显示的线
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ConnectionLineShape? ConnectionLineShape { get; private set; }
|
|
|
|
|
|
|
2025-01-22 21:09:52 +08:00
|
|
|
|
private NodeJunctionView StartNodeJunctionView;
|
|
|
|
|
|
|
|
|
|
|
|
public NodeConnectionLineControl(Canvas canvas,
|
2025-01-04 22:25:42 +08:00
|
|
|
|
NodeJunctionView? leftNodeJunctionView,
|
|
|
|
|
|
NodeJunctionView? rightNodeJunctionView)
|
|
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
if (leftNodeJunctionView is null && rightNodeJunctionView is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("不能都为空");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Canvas = canvas;
|
|
|
|
|
|
LeftNodeJunctionView = leftNodeJunctionView;
|
|
|
|
|
|
RightNodeJunctionView = rightNodeJunctionView;
|
|
|
|
|
|
|
|
|
|
|
|
if (leftNodeJunctionView is null && rightNodeJunctionView is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
StartNodeJunctionView = rightNodeJunctionView;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(leftNodeJunctionView is not null && rightNodeJunctionView is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
StartNodeJunctionView = leftNodeJunctionView;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (leftNodeJunctionView is not null && rightNodeJunctionView is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
LeftNodeJunctionView = leftNodeJunctionView;
|
|
|
|
|
|
RightNodeJunctionView = rightNodeJunctionView;
|
|
|
|
|
|
RefreshLineDsiplay();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-04 22:25:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 连接到终点
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="endNodeJunctionView"></param>
|
|
|
|
|
|
public void ToEnd(NodeJunctionView endNodeJunctionView)
|
|
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
var @bool = endNodeJunctionView.JunctionType == JunctionType.Execute || endNodeJunctionView.JunctionType == JunctionType.ArgData;
|
|
|
|
|
|
(LeftNodeJunctionView, RightNodeJunctionView) = @bool? (StartNodeJunctionView, endNodeJunctionView) : (endNodeJunctionView, StartNodeJunctionView);
|
|
|
|
|
|
RefreshLineDsiplay();
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
/*if(StartNodeJunctionView.JunctionType == JunctionType.NextStep
|
|
|
|
|
|
&& endNodeJunctionView.JunctionType == JunctionType.Execute
|
|
|
|
|
|
&& StartNodeJunctionView.MyNode?.Equals(endNodeJunctionView.MyNode) == false)
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
LeftNodeJunctionView = StartNodeJunctionView;
|
|
|
|
|
|
RightNodeJunctionView = endNodeJunctionView;
|
2025-01-04 22:25:42 +08:00
|
|
|
|
RefreshLineDsiplay();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-01-22 21:09:52 +08:00
|
|
|
|
|
|
|
|
|
|
if (StartNodeJunctionView.JunctionType == JunctionType.ReturnData
|
|
|
|
|
|
&& endNodeJunctionView.JunctionType == JunctionType.ArgData
|
|
|
|
|
|
&& StartNodeJunctionView.MyNode?.Equals(endNodeJunctionView.MyNode) == false)
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
LeftNodeJunctionView = StartNodeJunctionView;
|
2025-01-04 22:25:42 +08:00
|
|
|
|
RightNodeJunctionView = endNodeJunctionView;
|
|
|
|
|
|
RefreshLineDsiplay();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-22 21:09:52 +08:00
|
|
|
|
if (StartNodeJunctionView.JunctionType == JunctionType.Execute
|
|
|
|
|
|
&& endNodeJunctionView.JunctionType == JunctionType.NextStep
|
|
|
|
|
|
&& StartNodeJunctionView.MyNode?.Equals(endNodeJunctionView.MyNode) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
LeftNodeJunctionView = endNodeJunctionView;
|
|
|
|
|
|
RightNodeJunctionView = StartNodeJunctionView;
|
|
|
|
|
|
RefreshLineDsiplay();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (StartNodeJunctionView.JunctionType == JunctionType.ArgData
|
|
|
|
|
|
&& endNodeJunctionView.JunctionType == JunctionType.ReturnData
|
|
|
|
|
|
&& StartNodeJunctionView.MyNode?.Equals(endNodeJunctionView.MyNode) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
LeftNodeJunctionView = endNodeJunctionView;
|
|
|
|
|
|
RightNodeJunctionView = StartNodeJunctionView;
|
|
|
|
|
|
RefreshLineDsiplay();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}*/
|
2025-01-04 22:25:42 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 刷新线的显示
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void RefreshLineDsiplay()
|
|
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
if (LeftNodeJunctionView is null || RightNodeJunctionView is null)
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
var leftPoint = GetPoint(LeftNodeJunctionView);
|
|
|
|
|
|
var rightPoint = GetPoint(RightNodeJunctionView);
|
|
|
|
|
|
if (ConnectionLineShape is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
CreateLineShape(leftPoint, rightPoint, GetBackgrounp());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var brush = GetBackgrounp();
|
2025-01-22 21:09:52 +08:00
|
|
|
|
ConnectionLineShape.UpdatePoint(leftPoint, rightPoint, brush);
|
2025-01-04 22:25:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-22 21:09:52 +08:00
|
|
|
|
//public void UpdateColor()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var brush = GetBackgrounp();
|
|
|
|
|
|
// ConnectionLineShape?.UpdateColor(brush);
|
|
|
|
|
|
//}
|
2025-01-04 22:25:42 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 刷新临时线的显示
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void RefreshRightPointOfTempLineDsiplay(Point rightPoint)
|
|
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
if (ConnectionLineShape is not null)
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
|
|
|
|
|
|
RightNodeJunctionView = null;
|
2025-01-04 22:25:42 +08:00
|
|
|
|
var brush = GetBackgrounp();
|
|
|
|
|
|
ConnectionLineShape.UpdateRightPoint(rightPoint, brush);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-01-22 21:09:52 +08:00
|
|
|
|
|
2025-01-04 22:25:42 +08:00
|
|
|
|
if (LeftNodeJunctionView is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var leftPoint = GetPoint(LeftNodeJunctionView);
|
|
|
|
|
|
var brush = GetBackgrounp();
|
|
|
|
|
|
CreateLineShape(leftPoint, rightPoint, brush);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-22 21:09:52 +08:00
|
|
|
|
|
2025-01-04 22:25:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 刷新临时线的显示
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void RefreshLeftPointOfTempLineDsiplay(Point leftPoint)
|
|
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
if (ConnectionLineShape is not null)
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
var brush = GetBackgrounp();
|
2025-01-22 21:09:52 +08:00
|
|
|
|
LeftNodeJunctionView = null;
|
2025-01-04 22:25:42 +08:00
|
|
|
|
ConnectionLineShape.UpdateLeftPoints(leftPoint, brush);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-01-22 21:09:52 +08:00
|
|
|
|
|
2025-01-04 22:25:42 +08:00
|
|
|
|
if (RightNodeJunctionView is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rightPoint = GetPoint(RightNodeJunctionView);
|
|
|
|
|
|
var brush = GetBackgrounp();
|
|
|
|
|
|
CreateLineShape(leftPoint, rightPoint, brush);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取背景颜色
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public Brush GetBackgrounp()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2025-01-22 21:09:52 +08:00
|
|
|
|
if (LeftNodeJunctionView is null || RightNodeJunctionView is null)
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
return new SolidColorBrush(Color.Parse("#FF0000")); // 没有终点
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断连接控制点是否匹配
|
|
|
|
|
|
if (!IsCanConnected())
|
|
|
|
|
|
{
|
|
|
|
|
|
return new SolidColorBrush(Color.Parse("#FF0000"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-22 21:09:52 +08:00
|
|
|
|
|
2025-01-04 22:25:42 +08:00
|
|
|
|
if (GetConnectionType() == JunctionOfConnectionType.Invoke)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ConnectionInvokeType.ToLineColor(); // 调用
|
2025-01-22 21:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (GetConnectionType() == JunctionOfConnectionType.Arg)
|
|
|
|
|
|
{
|
2025-01-04 22:25:42 +08:00
|
|
|
|
return ConnectionArgSourceType.ToLineColor(); // 参数
|
|
|
|
|
|
}
|
2025-01-22 21:09:52 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return new SolidColorBrush(Color.Parse("#FF0000"));
|
|
|
|
|
|
}
|
2025-01-04 22:25:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsCanConnected()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (LeftNodeJunctionView is null
|
|
|
|
|
|
|| RightNodeJunctionView is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (LeftNodeJunctionView?.MyNode is null
|
|
|
|
|
|
|| LeftNodeJunctionView.MyNode.Equals(RightNodeJunctionView.MyNode))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (LeftNodeJunctionView.JunctionType.IsCanConnection(RightNodeJunctionView.JunctionType))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 移除线
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Remove()
|
|
|
|
|
|
{
|
2025-01-22 21:09:52 +08:00
|
|
|
|
if (ConnectionLineShape is null)
|
2025-01-04 22:25:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Canvas.Children.Remove(ConnectionLineShape);
|
|
|
|
|
|
}
|
2025-01-22 21:09:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Point defaultPoint = new Point(0, 0);
|
|
|
|
|
|
int count;
|
|
|
|
|
|
private Point GetPoint(NodeJunctionView nodeJunctionView)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var junctionSize = nodeJunctionView.GetTransformedBounds()!.Value.Bounds.Size;
|
|
|
|
|
|
Point junctionPoint;
|
|
|
|
|
|
if (nodeJunctionView.JunctionType == JunctionType.ArgData || nodeJunctionView.JunctionType == JunctionType.Execute)
|
|
|
|
|
|
{
|
|
|
|
|
|
junctionPoint = new Point(junctionSize.Width / 2 - 11, junctionSize.Height / 2); // 选择左侧
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
junctionPoint = new Point(junctionSize.Width / 2 + 11, junctionSize.Height / 2); // 选择右侧
|
|
|
|
|
|
}
|
|
|
|
|
|
if (nodeJunctionView.TranslatePoint(junctionPoint, Canvas) is Point point)
|
|
|
|
|
|
{
|
|
|
|
|
|
//myData.StartPoint = point;
|
|
|
|
|
|
return point;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return defaultPoint;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CreateLineShape(Point leftPoint, Point rightPoint, Brush brush)
|
|
|
|
|
|
{
|
|
|
|
|
|
ConnectionLineShape = new ConnectionLineShape(leftPoint, rightPoint, brush);
|
|
|
|
|
|
Canvas.Children.Add(ConnectionLineShape);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private JunctionOfConnectionType GetConnectionType()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(LeftNodeJunctionView is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(RightNodeJunctionView is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return JunctionOfConnectionType.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return RightNodeJunctionView.JunctionType.ToConnectyionType();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return LeftNodeJunctionView.JunctionType.ToConnectyionType();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-04 22:25:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|