using ReactiveUI;
using System;
namespace AuroraDesk.Core.Entities;
///
/// 连接实体 - 表示两个连接点之间的连线
///
public class Connection : ReactiveObject
{
private ConnectionPoint? _sourcePoint;
private ConnectionPoint? _targetPoint;
///
/// 连接唯一标识符
///
public string Id { get; set; } = Guid.NewGuid().ToString();
///
/// 源连接点(输出点)
///
public ConnectionPoint? SourcePoint
{
get => _sourcePoint;
set => this.RaiseAndSetIfChanged(ref _sourcePoint, value);
}
///
/// 目标连接点(输入点)
///
public ConnectionPoint? TargetPoint
{
get => _targetPoint;
set => this.RaiseAndSetIfChanged(ref _targetPoint, value);
}
///
/// 验证连接是否有效(输出点必须连接到输入点)
///
public bool IsValid()
{
if (SourcePoint == null || TargetPoint == null)
return false;
return SourcePoint.Type == ConnectionPointType.Output &&
TargetPoint.Type == ConnectionPointType.Input &&
SourcePoint.Node != TargetPoint.Node; // 不能连接到同一个节点
}
}