using ReactiveUI;
using System;
namespace AuroraDesk.Core.Entities;
///
/// 节点模板 - 定义可用的节点类型
///
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.Outside;
private ConnectorPlacementMode _rightConnectorPlacement = ConnectorPlacementMode.Outside;
private string _leftConnectorColor = "#3498DB";
private string _rightConnectorColor = "#FF6B6B";
///
/// 模板唯一标识符
///
public string Id { get; set; } = Guid.NewGuid().ToString();
///
/// 模板名称(用于内部标识)
///
public string Name
{
get => _name;
set => this.RaiseAndSetIfChanged(ref _name, value);
}
///
/// 显示名称
///
public string DisplayName
{
get => _displayName;
set => this.RaiseAndSetIfChanged(ref _displayName, value);
}
///
/// 描述
///
public string Description
{
get => _description;
set => this.RaiseAndSetIfChanged(ref _description, value);
}
///
/// 节点内容(显示在节点内部的文本)
///
public string Content
{
get => _content;
set => this.RaiseAndSetIfChanged(ref _content, value);
}
///
/// 输入连接点数量
///
public int InputCount
{
get => _inputCount;
set
{
var clamped = Math.Max(3, value);
this.RaiseAndSetIfChanged(ref _inputCount, clamped);
}
}
///
/// 输出连接点数量
///
public int OutputCount
{
get => _outputCount;
set
{
var clamped = Math.Max(3, value);
this.RaiseAndSetIfChanged(ref _outputCount, clamped);
}
}
///
/// 节点宽度
///
public double Width
{
get => _width;
set => this.RaiseAndSetIfChanged(ref _width, value);
}
///
/// 节点高度
///
public double Height
{
get => _height;
set => this.RaiseAndSetIfChanged(ref _height, value);
}
///
/// 左侧附件圆尺寸
///
public double LeftConnectorSize
{
get => _leftConnectorSize;
set => this.RaiseAndSetIfChanged(ref _leftConnectorSize, value);
}
///
/// 右侧附件圆尺寸
///
public double RightConnectorSize
{
get => _rightConnectorSize;
set => this.RaiseAndSetIfChanged(ref _rightConnectorSize, value);
}
///
/// 左侧附件圆颜色(Hex)
///
public string LeftConnectorColor
{
get => _leftConnectorColor;
set => this.RaiseAndSetIfChanged(ref _leftConnectorColor, value);
}
///
/// 右侧附件圆颜色(Hex)
///
public string RightConnectorColor
{
get => _rightConnectorColor;
set => this.RaiseAndSetIfChanged(ref _rightConnectorColor, value);
}
///
/// 左侧附件圆定位
///
public ConnectorPlacementMode LeftConnectorPlacement
{
get => _leftConnectorPlacement;
set => this.RaiseAndSetIfChanged(ref _leftConnectorPlacement, value);
}
///
/// 右侧附件圆定位
///
public ConnectorPlacementMode RightConnectorPlacement
{
get => _rightConnectorPlacement;
set => this.RaiseAndSetIfChanged(ref _rightConnectorPlacement, value);
}
///
/// 根据模板创建节点实例
///
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;
}
}