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