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 = 1;
private int _outputCount = 3;
private double _width = 120;
private double _height = 80;
///
/// 模板唯一标识符
///
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 => this.RaiseAndSetIfChanged(ref _inputCount, value);
}
///
/// 输出连接点数量
///
public int OutputCount
{
get => _outputCount;
set => this.RaiseAndSetIfChanged(ref _outputCount, value);
}
///
/// 节点宽度
///
public double Width
{
get => _width;
set => this.RaiseAndSetIfChanged(ref _width, value);
}
///
/// 节点高度
///
public double Height
{
get => _height;
set => this.RaiseAndSetIfChanged(ref _height, value);
}
///
/// 根据模板创建节点实例
///
public Node CreateNode(double x, double y)
{
var node = new Node
{
X = x,
Y = y,
Title = DisplayName,
Content = Content,
Width = Width,
Height = Height
};
// 创建输入连接点(左侧)
for (int i = 0; i < InputCount; i++)
{
node.ConnectionPoints.Add(new ConnectionPoint
{
Label = "",
Type = ConnectionPointType.Input,
Index = i,
Node = node
});
}
// 创建输出连接点(右侧)
for (int i = 0; i < OutputCount; i++)
{
node.ConnectionPoints.Add(new ConnectionPoint
{
Label = (i + 1).ToString(),
Type = ConnectionPointType.Output,
Index = i,
Node = node
});
}
return node;
}
}