67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
|
public class HeatExchanger : INode {
|
|
|
|
public const double WIDTH = 6;
|
|
public const double HEIGHT = 24;
|
|
|
|
public double CenterX { get; set; }
|
|
public double CenterY { get; set; }
|
|
public string Label { get; set; }
|
|
public ISet<IEdge> Inputs { get; init; }
|
|
public ISet<IEdge> Outputs { get; init; }
|
|
|
|
private Shape? _rect;
|
|
private TextBlock? _text;
|
|
|
|
public HeatExchanger(string label, double x, double y) {
|
|
CenterX = x;
|
|
CenterY = y;
|
|
Label = label;
|
|
Inputs = new HashSet<IEdge>();
|
|
Outputs = new HashSet<IEdge>();
|
|
}
|
|
|
|
public void Draw(Canvas canvas) {
|
|
_rect = new Rectangle() {
|
|
Stroke = Brushes.Black,
|
|
Fill = Brushes.WhiteSmoke,
|
|
};
|
|
_text = new() {
|
|
Text = Label,
|
|
TextAlignment = TextAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
RenderTransform = new RotateTransform(270),
|
|
SnapsToDevicePixels = true,
|
|
};
|
|
canvas.Children.Add(_rect);
|
|
canvas.Children.Add(_text);
|
|
}
|
|
|
|
public void Scale(double scale) {
|
|
var border = Graph.ToBorder(scale);
|
|
Graph.SetWH(_rect, WIDTH, HEIGHT, scale);
|
|
Graph.SetPos(_rect, CenterX - WIDTH / 2, CenterY - HEIGHT / 2, scale);
|
|
_rect?.StrokeThickness = border;
|
|
_text?.FontSize = 12;
|
|
_text?.Width = Math.Round(HEIGHT * scale);
|
|
Graph.SetPos(_text, CenterX, CenterY + HEIGHT / 2, scale, dxpx: -9);
|
|
}
|
|
|
|
public bool IsInside(double x, double y) {
|
|
return Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2;
|
|
}
|
|
|
|
public void Update(bool isHovering, bool isPressed) {
|
|
_rect?.Fill =
|
|
isHovering && isPressed ? Brushes.DarkGray :
|
|
isHovering ? Brushes.LightGray :
|
|
Brushes.WhiteSmoke;
|
|
}
|
|
}
|
|
}
|