using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace PamhagenSysCtrl.Helpers.Pipeline { public class Inlet : IEdge { public INode Start { get; set; } public INode End => Sink; public ISink Sink { get; set; } public string? Label => null; public bool IsTwoWay => false; public bool Orientation { get; set; } public Brush? Highlight { get; set; } public (bool TowardEnd, double PathOffset)? Flow { get; set; } public double FlowLength => _flowArrows?.Length ?? 0; public double X1 => Start.CenterX; public double Y1 => Start.CenterY; public double X2 => Start.CenterX; public double Y2 => Orientation ? Sink.CenterY - 2 : Sink.TopY - 2; public double X3 => Orientation ? Sink.CenterX : Start.CenterX + (Start.CenterX == End.CenterX ? 0 : Start.CenterX > End.CenterX ? -4 : 4); public double Y3 => Orientation ? Sink.CenterY - 2 : Sink.TopY + 4; private Polyline? _outer; private Polyline? _inner; private FlowArrows? _flowArrows; public Inlet(INode start, ISink end, bool orientation = false) { Start = start; Sink = end; Orientation = orientation; } public void Draw(Canvas canvas) { _outer = new Polyline() { Points = [new(X1, Y1), new(X2, Y2), new (X3, Y3)], Stroke = Brushes.Black, StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Flat, }; _inner = new Polyline() { Points = [new(X1, Y1), new(X2, Y2), new(X3, Y3)], Stroke = Brushes.DarkGray, StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Flat, }; canvas.Children.Add(_outer); canvas.Children.Add(_inner); _flowArrows = FlowArrows.Create(canvas, _inner); } public void Scale(double scale) { _outer?.RenderTransform = new ScaleTransform(scale, scale); _outer?.StrokeThickness = 10 / scale; _inner?.RenderTransform = new ScaleTransform(scale, scale); _inner?.StrokeThickness = 6 / scale; } public void Update() { _inner?.Stroke = Highlight ?? Brushes.DarkGray; _flowArrows?.Update(Flow); } } }