using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace PamhagenSysCtrl.Helpers.Pipeline { public class Outlet : IEdge { public const double POINT = 3.2; public INode Start => Source; public INode End { get; set; } public ISource Source { 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 => Source.BottomY; public double X2 => Orientation ? Start.CenterX : End.CenterX; public double Y2 => Orientation ? End.CenterY : Start.CenterY; public double X3 => End.CenterX; public double Y3 => End.CenterY; private Polygon? _hopper; private FlowArrows? _flowArrows; private Polyline? _outer; private Polyline? _inner; public Outlet(ISource start, INode end) { Source = start; End = end; Orientation = true; } public void Draw(Canvas canvas) { _hopper = new Polygon() { Fill = Brushes.DarkGray, Stroke = Brushes.Black, }; _outer = new Polyline() { Stroke = Brushes.Black, StrokeStartLineCap = PenLineCap.Round, StrokeLineJoin = PenLineJoin.Round, StrokeEndLineCap = PenLineCap.Round, }; _inner = new Polyline() { Stroke = Brushes.DarkGray, StrokeStartLineCap = PenLineCap.Round, StrokeLineJoin = PenLineJoin.Round, StrokeEndLineCap = PenLineCap.Round, }; canvas.Children.Add(_outer); canvas.Children.Add(_hopper); canvas.Children.Add(_inner); _flowArrows = FlowArrows.Create(canvas, _inner); } public void Scale(double scale) { var border = Graph.ToBorder(scale); _hopper?.Points = [Graph.ToPx(X1 - POINT, Y1, scale, dypx: -border * 2), Graph.ToPx(X1 + POINT, Y1, scale, dypx: -border * 2), Graph.ToPx(X1, Y1 + POINT, scale)]; _hopper?.StrokeThickness = border; _outer?.Points = [Graph.ToPx(X1, Y1, scale), Graph.ToPx(X2, Y2, scale), Graph.ToPx(X3, Y3, scale)]; _inner?.Points = [Graph.ToPx(X1, Y1, scale), Graph.ToPx(X2, Y2, scale), Graph.ToPx(X3, Y3, scale)]; _inner?.StrokeThickness = Math.Round(1.2 * scale / 2) * 2; _outer?.StrokeThickness = Math.Round(1.2 * scale / 2) * 2 + border * 2; } public void Update() { _inner?.Stroke = Highlight ?? Brushes.DarkGray; _hopper?.Fill = Highlight ?? Brushes.DarkGray; _flowArrows?.Update(Flow); } } }