Add heat exchangers
This commit is contained in:
@@ -54,11 +54,23 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
return p;
|
||||
}
|
||||
|
||||
public Path? GetPath(IEnumerable<INode> points, Func<INode, bool>? valid = null) {
|
||||
if (points.Count() < 2) throw new ArgumentException("Path is too short");
|
||||
var start = points.First();
|
||||
var path = new Path(start, []);
|
||||
foreach (var end in points.Skip(1)) {
|
||||
if (GetPath(start, end, valid, visited: [..path.Hops.Select(h => h.Node)]) is not Path p)
|
||||
return null;
|
||||
path.Hops = [..path.Hops, ..p.Hops];
|
||||
start = end;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public Path? GetPath(INode start, INode end, Func<INode, bool>? valid = null, HashSet<INode>? visited = null) {
|
||||
if (!Nodes.Contains(start) || !Nodes.Contains(end)) throw new ArgumentException("Start/end node not contained in graph");
|
||||
valid ??= a => true;
|
||||
visited ??= [];
|
||||
visited.Add(start);
|
||||
visited = [.. visited ?? [], start];
|
||||
List<(IEdge, INode)> hops = [];
|
||||
Path? path = null;
|
||||
foreach (var o in start.Outputs) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
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 = 30;
|
||||
public const double HEIGHT = 120;
|
||||
|
||||
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() {
|
||||
Width = WIDTH,
|
||||
Height = HEIGHT,
|
||||
Stroke = Brushes.Black,
|
||||
StrokeThickness = 2,
|
||||
Fill = Brushes.WhiteSmoke,
|
||||
};
|
||||
_text = new() {
|
||||
Text = Label,
|
||||
FontSize = 12,
|
||||
Width = HEIGHT,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
RenderTransform = new RotateTransform(270),
|
||||
};
|
||||
_rect.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
|
||||
_rect.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
|
||||
_text.SetValue(Canvas.LeftProperty, CenterX - 9);
|
||||
_text.SetValue(Canvas.TopProperty, CenterY + HEIGHT / 2);
|
||||
canvas.Children.Add(_rect);
|
||||
canvas.Children.Add(_text);
|
||||
}
|
||||
|
||||
public bool Update(double x, double y, bool down) {
|
||||
var hover = Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2;
|
||||
_rect?.Fill = hover ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
return hover;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,5 @@
|
||||
public interface ISource : INode {
|
||||
public double BottomY { get; }
|
||||
public bool IsFilled { get; }
|
||||
public bool IsSelected { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
INode Start,
|
||||
IEnumerable<(IEdge Edge, INode Node)> Hops)
|
||||
{
|
||||
public readonly double Bends => Hops.Sum(h => h.Edge.Start.CenterX != h.Edge.End.CenterX && h.Edge.Start.CenterY != h.Edge.End.CenterY ? 1 : 0);
|
||||
public readonly double Bends => Hops.Sum(h => (h.Node is not Valve && h.Node is not PipeJoin ? 1 : 0) + (h.Edge.Start.CenterX != h.Edge.End.CenterX && h.Edge.Start.CenterY != h.Edge.End.CenterY ? 1 : 0));
|
||||
public readonly double Length => Hops.Sum(h => Math.Abs(h.Edge.Start.CenterX - h.Edge.End.CenterX) + Math.Abs(h.Edge.Start.CenterY - h.Edge.End.CenterY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public string Label { get; set; }
|
||||
public bool IsFull => CallbackIsFull();
|
||||
public bool IsFilled => CallbackIsFilled();
|
||||
public bool IsSelected { get; set; }
|
||||
|
||||
public ISet<IEdge> Inputs { get; init; }
|
||||
public ISet<IEdge> Outputs { get; init; }
|
||||
@@ -65,7 +64,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
public bool Update(double x, double y, bool down) {
|
||||
var hover = Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2;
|
||||
_rect?.Fill = IsSelected ? Brushes.LightGray : hover ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
_rect?.Fill = hover ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
return hover;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public double BottomY => CenterY + HEIGHT / 2;
|
||||
public string Label { get; set; }
|
||||
public bool IsFilled => CallbackIsFilled();
|
||||
public bool IsSelected { get; set; }
|
||||
public ISet<IEdge> Inputs { get; init; }
|
||||
public ISet<IEdge> Outputs { get; init; }
|
||||
|
||||
@@ -57,7 +56,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
public bool Update(double x, double y, bool down) {
|
||||
var hover = Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2;
|
||||
_rect?.Fill = IsSelected ? Brushes.LightGray : hover ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
_rect?.Fill = hover ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
return hover;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
public bool Update(double x, double y, bool down) {
|
||||
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2;
|
||||
_circle?.Fill = IsLocked ? Brushes.Red : Highlight ?? (hover ? Brushes.LightGray : Brushes.DarkGray);
|
||||
_circle?.Fill = IsLocked ? Brushes.Orange : Highlight ?? (hover ? Brushes.LightGray : Brushes.DarkGray);
|
||||
return hover;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user