Files
pamhagen-sysctrl/PamhagenSysCtrl/Helpers/Pipeline/Outlet.cs
T
2026-07-13 17:11:21 +02:00

97 lines
3.1 KiB
C#

using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class Outlet : IEdge {
public const double POINT = 16;
public INode Start => Source;
public INode End { get; set; }
public ISource Source { get; set; }
public bool IsTwoWay => false;
public bool Orientation { get; set; }
public Brush? Highlight { get; set; }
private Polygon? _hopper;
private Line? _outer1;
private Line? _outer2;
private Line? _inner1;
private Line? _inner2;
public Outlet(ISource start, INode end) {
Source = start;
End = end;
Orientation = true;
}
public void Draw(Canvas canvas) {
var x1 = Start.CenterX ;
var y1 = Source.BottomY;
var x2 = Orientation ? Start.CenterX : End.CenterX;
var y2 = Orientation ? End.CenterY : Start.CenterY;
var x3 = End.CenterX;
var y3 = End.CenterY;
_hopper = new Polygon() {
Points = [new(x1 - POINT, y1 - 2), new(x1 + POINT, y1 - 2), new(x1, y1 + POINT)],
Fill = Brushes.DarkGray,
Stroke = Brushes.Black,
StrokeThickness = 2,
};
_outer1 = new Line() {
X1 = x1,
Y1 = y1,
X2 = x2,
Y2 = y2,
StrokeThickness = 10,
Stroke = Brushes.Black,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
};
_inner1 = new Line() {
X1 = x1,
Y1 = y1,
X2 = x2,
Y2 = y2,
StrokeThickness = 6,
Stroke = Brushes.DarkGray,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
};
_outer2 = new Line() {
X1 = x2,
Y1 = y2,
X2 = x3,
Y2 = y3,
StrokeThickness = 10,
Stroke = Brushes.Black,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
};
_inner2 = new Line() {
X1 = x2,
Y1 = y2,
X2 = x3,
Y2 = y3,
StrokeThickness = 6,
Stroke = Brushes.DarkGray,
StrokeStartLineCap = PenLineCap.Square,
StrokeEndLineCap = PenLineCap.Square,
};
canvas.Children.Add(_outer1);
canvas.Children.Add(_outer2);
canvas.Children.Add(_hopper);
canvas.Children.Add(_inner1);
canvas.Children.Add(_inner2);
}
public bool Update(double x, double y) {
_inner1?.Stroke = Highlight ?? Brushes.DarkGray;
_inner2?.Stroke = Highlight ?? Brushes.DarkGray;
_hopper?.Fill = Highlight ?? Brushes.DarkGray;
return false;
}
}
}