81 lines
3.1 KiB
C#
81 lines
3.1 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
|
public class Pipe : IEdge {
|
|
|
|
public INode Start { get; set; }
|
|
public INode End { get; set; }
|
|
public string? Label { get; set; }
|
|
public bool IsTwoWay { get; set; }
|
|
public bool Orientation { get; set; }
|
|
public Brush? Highlight { get; set; }
|
|
public (bool TowardEnd, double PathOffset)? Flow { get; set; }
|
|
public double FlowLength => _flowArrows?.Length ?? 0;
|
|
|
|
private Polyline? _outer;
|
|
private Polyline? _inner;
|
|
private TextBlock? _text;
|
|
private FlowArrows? _flowArrows;
|
|
private double? _textOffsetX;
|
|
|
|
public Pipe(INode start, INode end, string? label = null, bool orientation = false, bool twoWay = false, double? textOffsetX = null) {
|
|
Start = start;
|
|
End = end;
|
|
Label = label;
|
|
_textOffsetX = textOffsetX;
|
|
Orientation = orientation;
|
|
IsTwoWay = twoWay;
|
|
}
|
|
|
|
public void Draw(Canvas canvas) {
|
|
var x1 = Start.CenterX;
|
|
var y1 = Start.CenterY;
|
|
var x2 = Orientation ? Start.CenterX : End.CenterX;
|
|
var y2 = Orientation ? End.CenterY : Start.CenterY;
|
|
var x3 = End.CenterX;
|
|
var y3 = End.CenterY;
|
|
_outer = new Polyline() {
|
|
Points = [new(x1, y1), new(x2, y2), new(x3, y3)],
|
|
StrokeThickness = 10,
|
|
Stroke = Brushes.Black,
|
|
StrokeStartLineCap = PenLineCap.Round,
|
|
StrokeEndLineCap = PenLineCap.Round,
|
|
StrokeLineJoin = PenLineJoin.Round,
|
|
};
|
|
_inner = new Polyline() {
|
|
Points = [new(x1, y1), new(x2, y2), new(x3, y3)],
|
|
StrokeThickness = 6,
|
|
Stroke = Brushes.DarkGray,
|
|
StrokeStartLineCap = PenLineCap.Round,
|
|
StrokeEndLineCap = PenLineCap.Round,
|
|
StrokeLineJoin = PenLineJoin.Round,
|
|
};
|
|
canvas.Children.Add(_outer);
|
|
canvas.Children.Add(_inner);
|
|
if (Label != null) {
|
|
_text = new() {
|
|
Text = Label,
|
|
FontSize = 12,
|
|
Width = 50,
|
|
TextAlignment = TextAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Bottom,
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
SnapsToDevicePixels = true,
|
|
};
|
|
_text.SetValue(Canvas.LeftProperty, _textOffsetX != null ? (Orientation ? x2 : x1) + _textOffsetX : (Orientation ? (x2 + x3) / 2 : (x1 + x2) / 2) - 25);
|
|
_text.SetValue(Canvas.TopProperty, y2 - 22);
|
|
canvas.Children.Add(_text);
|
|
}
|
|
_flowArrows = FlowArrows.Create(canvas, _inner);
|
|
}
|
|
|
|
public void Update() {
|
|
_inner?.Stroke = Highlight ?? Brushes.DarkGray;
|
|
_flowArrows?.Update(Flow);
|
|
}
|
|
}
|
|
}
|