You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
5.7 KiB
219 lines
5.7 KiB
using ReactiveUI;
|
|
using System;
|
|
|
|
namespace AuroraDesk.Core.Entities;
|
|
|
|
/// <summary>
|
|
/// 节点模板 - 定义可用的节点类型
|
|
/// </summary>
|
|
public class NodeTemplate : ReactiveObject
|
|
{
|
|
private string _name = string.Empty;
|
|
private string _displayName = string.Empty;
|
|
private string _description = string.Empty;
|
|
private string _content = string.Empty;
|
|
private int _inputCount = 3;
|
|
private int _outputCount = 3;
|
|
private double _width = 120;
|
|
private double _height = 80;
|
|
private double _leftConnectorSize = 10;
|
|
private double _rightConnectorSize = 10;
|
|
private ConnectorPlacementMode _leftConnectorPlacement = ConnectorPlacementMode.Inside;
|
|
private ConnectorPlacementMode _rightConnectorPlacement = ConnectorPlacementMode.Inside;
|
|
private string _leftConnectorColor = "#3498DB";
|
|
private string _rightConnectorColor = "#FF6B6B";
|
|
|
|
/// <summary>
|
|
/// 模板唯一标识符
|
|
/// </summary>
|
|
public string Id { get; set; } = Guid.NewGuid().ToString();
|
|
|
|
/// <summary>
|
|
/// 模板名称(用于内部标识)
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get => _name;
|
|
set => this.RaiseAndSetIfChanged(ref _name, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示名称
|
|
/// </summary>
|
|
public string DisplayName
|
|
{
|
|
get => _displayName;
|
|
set => this.RaiseAndSetIfChanged(ref _displayName, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 描述
|
|
/// </summary>
|
|
public string Description
|
|
{
|
|
get => _description;
|
|
set => this.RaiseAndSetIfChanged(ref _description, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 节点内容(显示在节点内部的文本)
|
|
/// </summary>
|
|
public string Content
|
|
{
|
|
get => _content;
|
|
set => this.RaiseAndSetIfChanged(ref _content, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输入连接点数量
|
|
/// </summary>
|
|
public int InputCount
|
|
{
|
|
get => _inputCount;
|
|
set
|
|
{
|
|
var clamped = Math.Max(3, value);
|
|
this.RaiseAndSetIfChanged(ref _inputCount, clamped);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输出连接点数量
|
|
/// </summary>
|
|
public int OutputCount
|
|
{
|
|
get => _outputCount;
|
|
set
|
|
{
|
|
var clamped = Math.Max(3, value);
|
|
this.RaiseAndSetIfChanged(ref _outputCount, clamped);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 节点宽度
|
|
/// </summary>
|
|
public double Width
|
|
{
|
|
get => _width;
|
|
set => this.RaiseAndSetIfChanged(ref _width, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 节点高度
|
|
/// </summary>
|
|
public double Height
|
|
{
|
|
get => _height;
|
|
set => this.RaiseAndSetIfChanged(ref _height, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 左侧附件圆尺寸
|
|
/// </summary>
|
|
public double LeftConnectorSize
|
|
{
|
|
get => _leftConnectorSize;
|
|
set => this.RaiseAndSetIfChanged(ref _leftConnectorSize, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 右侧附件圆尺寸
|
|
/// </summary>
|
|
public double RightConnectorSize
|
|
{
|
|
get => _rightConnectorSize;
|
|
set => this.RaiseAndSetIfChanged(ref _rightConnectorSize, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 左侧附件圆颜色(Hex)
|
|
/// </summary>
|
|
public string LeftConnectorColor
|
|
{
|
|
get => _leftConnectorColor;
|
|
set => this.RaiseAndSetIfChanged(ref _leftConnectorColor, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 右侧附件圆颜色(Hex)
|
|
/// </summary>
|
|
public string RightConnectorColor
|
|
{
|
|
get => _rightConnectorColor;
|
|
set => this.RaiseAndSetIfChanged(ref _rightConnectorColor, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 左侧附件圆定位
|
|
/// </summary>
|
|
public ConnectorPlacementMode LeftConnectorPlacement
|
|
{
|
|
get => _leftConnectorPlacement;
|
|
set => this.RaiseAndSetIfChanged(ref _leftConnectorPlacement, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 右侧附件圆定位
|
|
/// </summary>
|
|
public ConnectorPlacementMode RightConnectorPlacement
|
|
{
|
|
get => _rightConnectorPlacement;
|
|
set => this.RaiseAndSetIfChanged(ref _rightConnectorPlacement, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据模板创建节点实例
|
|
/// </summary>
|
|
public Node CreateNode(double x, double y)
|
|
{
|
|
var node = new Node
|
|
{
|
|
X = x,
|
|
Y = y,
|
|
Title = DisplayName,
|
|
Content = Content,
|
|
Width = Width,
|
|
Height = Height,
|
|
LeftConnectorSize = LeftConnectorSize,
|
|
RightConnectorSize = RightConnectorSize,
|
|
LeftConnectorColor = LeftConnectorColor,
|
|
RightConnectorColor = RightConnectorColor,
|
|
LeftConnectorPlacement = LeftConnectorPlacement,
|
|
RightConnectorPlacement = RightConnectorPlacement
|
|
};
|
|
|
|
// 创建输入连接点(左侧)
|
|
for (int i = 0; i < InputCount; i++)
|
|
{
|
|
node.ConnectionPoints.Add(new ConnectionPoint
|
|
{
|
|
Label = "",
|
|
Type = ConnectionPointType.Input,
|
|
Index = i,
|
|
Node = node,
|
|
Diameter = LeftConnectorSize,
|
|
Color = LeftConnectorColor,
|
|
Placement = LeftConnectorPlacement
|
|
});
|
|
}
|
|
|
|
// 创建输出连接点(右侧)
|
|
for (int i = 0; i < OutputCount; i++)
|
|
{
|
|
node.ConnectionPoints.Add(new ConnectionPoint
|
|
{
|
|
Label = (i + 1).ToString(),
|
|
Type = ConnectionPointType.Output,
|
|
Index = i,
|
|
Node = node,
|
|
Diameter = RightConnectorSize,
|
|
Color = RightConnectorColor,
|
|
Placement = RightConnectorPlacement
|
|
});
|
|
}
|
|
|
|
return node;
|
|
}
|
|
}
|
|
|
|
|