67 lines
2.6 KiB
C#
67 lines
2.6 KiB
C#
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() {
|
|
Stroke = Brushes.Black,
|
|
StrokeStartLineCap = PenLineCap.Round,
|
|
StrokeLineJoin = PenLineJoin.Round,
|
|
StrokeEndLineCap = PenLineCap.Flat,
|
|
};
|
|
_inner = new Polyline() {
|
|
Stroke = Brushes.DarkGray,
|
|
StrokeStartLineCap = PenLineCap.Round,
|
|
StrokeLineJoin = PenLineJoin.Round,
|
|
StrokeEndLineCap = PenLineCap.Flat,
|
|
};
|
|
canvas.Children.Add(_outer);
|
|
canvas.Children.Add(_inner);
|
|
_flowArrows = FlowArrows.Create(canvas, _inner);
|
|
}
|
|
|
|
public void Scale(double scale) {
|
|
var border = Graph.ToBorder(scale);
|
|
_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;
|
|
_flowArrows?.Update(Flow);
|
|
}
|
|
}
|
|
}
|