170 lines
5.3 KiB
C#
170 lines
5.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace StellaOps.ElkSharp;
|
|
|
|
public enum ElkLayoutDirection
|
|
{
|
|
TopToBottom = 0,
|
|
LeftToRight = 1,
|
|
}
|
|
|
|
public enum ElkLayoutEffort
|
|
{
|
|
Draft = 0,
|
|
Balanced = 1,
|
|
Best = 2,
|
|
}
|
|
|
|
public sealed record ElkPort
|
|
{
|
|
public required string Id { get; init; }
|
|
public string? Side { get; init; }
|
|
public double Width { get; init; } = 8;
|
|
public double Height { get; init; } = 8;
|
|
}
|
|
|
|
public sealed record ElkNode
|
|
{
|
|
public required string Id { get; init; }
|
|
public required string Label { get; init; }
|
|
public required string Kind { get; init; }
|
|
public string? IconKey { get; init; }
|
|
public string? SemanticType { get; init; }
|
|
public string? SemanticKey { get; init; }
|
|
public string? Route { get; init; }
|
|
public string? TaskType { get; init; }
|
|
public string? ParentNodeId { get; init; }
|
|
public double Width { get; init; } = 160;
|
|
public double Height { get; init; } = 72;
|
|
public IReadOnlyCollection<ElkPort> Ports { get; init; } = [];
|
|
}
|
|
|
|
public sealed record ElkEdge
|
|
{
|
|
public required string Id { get; init; }
|
|
public required string SourceNodeId { get; init; }
|
|
public required string TargetNodeId { get; init; }
|
|
public string? SourcePortId { get; init; }
|
|
public string? TargetPortId { get; init; }
|
|
public string? Kind { get; init; }
|
|
public string? Label { get; init; }
|
|
}
|
|
|
|
public sealed record ElkGraph
|
|
{
|
|
public required string Id { get; init; }
|
|
public required IReadOnlyCollection<ElkNode> Nodes { get; init; }
|
|
public required IReadOnlyCollection<ElkEdge> Edges { get; init; }
|
|
}
|
|
|
|
public sealed record ElkLayoutOptions
|
|
{
|
|
public ElkLayoutDirection Direction { get; init; } = ElkLayoutDirection.LeftToRight;
|
|
public double NodeSpacing { get; init; } = 40;
|
|
public double LayerSpacing { get; init; } = 60;
|
|
public double CompoundPadding { get; init; } = 30;
|
|
public double CompoundHeaderHeight { get; init; } = 28;
|
|
public ElkLayoutEffort Effort { get; init; } = ElkLayoutEffort.Best;
|
|
public int? OrderingIterations { get; init; }
|
|
public int? PlacementIterations { get; init; }
|
|
public EdgeRefinementOptions? EdgeRefinement { get; init; }
|
|
public IterativeRoutingOptions? IterativeRouting { get; init; }
|
|
}
|
|
|
|
public sealed record EdgeRefinementOptions
|
|
{
|
|
public bool? Enabled { get; init; }
|
|
public int MaxGlobalPasses { get; init; } = 2;
|
|
public int MaxTrialsPerProblemEdge { get; init; } = 4;
|
|
public int MaxProblemEdgesPerPass { get; init; } = 12;
|
|
public double BaseObstacleMargin { get; init; } = 18;
|
|
public double SoftObstacleWeight { get; init; } = 0.4d;
|
|
public double SoftObstacleClearance { get; init; } = 14d;
|
|
}
|
|
|
|
public sealed record IterativeRoutingOptions
|
|
{
|
|
public bool? Enabled { get; init; }
|
|
public IterativeRoutingMode Mode { get; init; } = IterativeRoutingMode.LegacyMultiStrategy;
|
|
public int MaxAdaptationsPerStrategy { get; init; } = 100;
|
|
public int RequiredValidSolutions { get; init; } = 10;
|
|
public int MaxRepairWaves { get; init; } = 4;
|
|
public int MaxParallelRepairBuilds { get; init; } = 4;
|
|
}
|
|
|
|
public enum IterativeRoutingMode
|
|
{
|
|
LegacyMultiStrategy = 0,
|
|
HybridDeterministic = 1,
|
|
}
|
|
|
|
public sealed record ElkPoint
|
|
{
|
|
public required double X { get; init; }
|
|
public required double Y { get; init; }
|
|
}
|
|
|
|
public sealed record ElkPositionedPort
|
|
{
|
|
public required string Id { get; init; }
|
|
public string? Side { get; init; }
|
|
public double X { get; init; }
|
|
public double Y { get; init; }
|
|
public double Width { get; init; }
|
|
public double Height { get; init; }
|
|
}
|
|
|
|
public sealed record ElkPositionedNode
|
|
{
|
|
public required string Id { get; init; }
|
|
public required string Label { get; init; }
|
|
public required string Kind { get; init; }
|
|
public string? IconKey { get; init; }
|
|
public string? SemanticType { get; init; }
|
|
public string? SemanticKey { get; init; }
|
|
public string? Route { get; init; }
|
|
public string? TaskType { get; init; }
|
|
public string? ParentNodeId { get; init; }
|
|
public double X { get; init; }
|
|
public double Y { get; init; }
|
|
public double Width { get; init; }
|
|
public double Height { get; init; }
|
|
public IReadOnlyCollection<ElkPositionedPort> Ports { get; init; } = [];
|
|
}
|
|
|
|
public sealed record ElkEdgeSection
|
|
{
|
|
public required ElkPoint StartPoint { get; init; }
|
|
public required ElkPoint EndPoint { get; init; }
|
|
public IReadOnlyCollection<ElkPoint> BendPoints { get; init; } = [];
|
|
}
|
|
|
|
public sealed record ElkRoutedEdge
|
|
{
|
|
public required string Id { get; init; }
|
|
public required string SourceNodeId { get; init; }
|
|
public required string TargetNodeId { get; init; }
|
|
public string? SourcePortId { get; init; }
|
|
public string? TargetPortId { get; init; }
|
|
public string? Kind { get; init; }
|
|
public string? Label { get; init; }
|
|
public IReadOnlyCollection<ElkEdgeSection> Sections { get; init; } = [];
|
|
}
|
|
|
|
public sealed record ElkLayoutResult
|
|
{
|
|
public required string GraphId { get; init; }
|
|
public required IReadOnlyCollection<ElkPositionedNode> Nodes { get; init; }
|
|
public required IReadOnlyCollection<ElkRoutedEdge> Edges { get; init; }
|
|
}
|
|
|
|
public interface IElkLayoutEngine
|
|
{
|
|
Task<ElkLayoutResult> LayoutAsync(
|
|
ElkGraph graph,
|
|
ElkLayoutOptions? options = null,
|
|
CancellationToken cancellationToken = default);
|
|
}
|