Add heat exchangers
This commit is contained in:
@@ -11,6 +11,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
private readonly List<Path> Paths = [];
|
||||
|
||||
private ISource? _lastSource;
|
||||
private List<INode> _path = [];
|
||||
private ISet<INode>? _lastSelected;
|
||||
|
||||
public PlantSchemeWindow() {
|
||||
@@ -31,28 +32,38 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
|
||||
private void SchemeCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs evt) {
|
||||
var p = evt.GetPosition(SchemeCanvas);
|
||||
var curSelected = UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed);
|
||||
var pos = evt.GetPosition(SchemeCanvas);
|
||||
var curSelected = UpdateScheme(pos, evt.LeftButton == MouseButtonState.Pressed);
|
||||
var clicked = curSelected.Intersect(_lastSelected ?? new HashSet<INode>()).ToList();
|
||||
_lastSource?.IsSelected = false;
|
||||
if (clicked.Count == 0) {
|
||||
_lastSource = null;
|
||||
}
|
||||
foreach (var c in clicked) {
|
||||
if (_lastSource != null && c is ISink sink) {
|
||||
var path = Graph.GetPath(_lastSource, sink, (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
if (path != null) {
|
||||
Paths.Add(path.Value);
|
||||
if (_lastSource == null && Paths.Any(p => p.Start == c)) {
|
||||
var path = Paths.First(p => p.Start == c);
|
||||
Paths.Remove(path);
|
||||
UpdateValvesAdjacientToPath(path, false);
|
||||
foreach (var p in Paths) UpdateValvesAdjacientToPath(p, true);
|
||||
} else if (_lastSource != null && c is ISink sink) {
|
||||
var res = Graph.GetPath([_lastSource, .._path, sink], (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
if (res is Path path) {
|
||||
Paths.Add(path);
|
||||
UpdateValvesAdjacientToPath(path, true);
|
||||
_lastSource = null;
|
||||
}
|
||||
} else if (c is ISource source) {
|
||||
_lastSource = source;
|
||||
_lastSource.IsSelected = true;
|
||||
_path = [];
|
||||
} else if (_lastSource != null) {
|
||||
var path = Graph.GetPath([_lastSource, .. _path, c], (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
if (path != null) {
|
||||
_path.Add(c);
|
||||
}
|
||||
} else {
|
||||
_lastSource = null;
|
||||
}
|
||||
}
|
||||
UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed);
|
||||
UpdateScheme(pos, evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private ISet<INode> UpdateScheme(Point pos, bool down) {
|
||||
@@ -60,26 +71,30 @@ namespace PamhagenSysCtrl.Windows {
|
||||
e.Highlight = null;
|
||||
}
|
||||
foreach (var p in Paths) {
|
||||
var c = Brushes.Green;
|
||||
foreach (var (edge, node) in p.Hops) {
|
||||
edge.Highlight = Brushes.Green;
|
||||
if (node is Pump) c = Brushes.Orange;
|
||||
Graph.ColorSubgraph(node, c, (v) => v.IsLocked = true);
|
||||
}
|
||||
ColorPipesAdjacientToPath(p, Brushes.Green, Brushes.Orange);
|
||||
}
|
||||
var hover = Graph.Update(pos.X, pos.Y, down);
|
||||
if (_lastSource != null && hover.Count > 0) {
|
||||
var path = Graph.GetPath(_lastSource, hover.First(), (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
if (path != null) {
|
||||
var c = Brushes.Green;
|
||||
foreach (var (edge, node) in path.Value.Hops) {
|
||||
edge.Highlight = Brushes.Green;
|
||||
if (node is Pump) c = Brushes.Orange;
|
||||
Graph.ColorSubgraph(node, c);
|
||||
if (_lastSource != null && (hover.Count > 0 || _path.Count > 0)) {
|
||||
List<INode> points = [_lastSource, .. _path];
|
||||
if (hover.Count > 0 && !points.Contains(hover.First())) {
|
||||
points.Add(hover.First());
|
||||
}
|
||||
if (points.Count >= 2) {
|
||||
var res = Graph.GetPath(points, (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
if (res is Path path) {
|
||||
ColorPipesAdjacientToPath(path, Brushes.Green, Brushes.Orange);
|
||||
}
|
||||
}
|
||||
Graph.Update(pos.X, pos.Y, down);
|
||||
} else if (_lastSource == null && hover.Count > 0 && Paths.Any(p => p.Start == hover.First())) {
|
||||
var path = Paths.First(p => p.Start == hover.First());
|
||||
ColorPipesAdjacientToPath(path, Brushes.Red, null);
|
||||
}
|
||||
if (_lastSource != null) {
|
||||
foreach (var edge in _lastSource.Outputs) {
|
||||
edge.Highlight = Brushes.Green;
|
||||
}
|
||||
}
|
||||
Graph.Update(pos.X, pos.Y, down);
|
||||
return hover;
|
||||
}
|
||||
|
||||
@@ -88,5 +103,22 @@ namespace PamhagenSysCtrl.Windows {
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void UpdateValvesAdjacientToPath(Path path, bool locked) {
|
||||
foreach (var (edge, node) in path.Hops) {
|
||||
Graph.TraverseSubgraph(node, valveAction: (v) => v.IsLocked = locked);
|
||||
}
|
||||
}
|
||||
|
||||
private void ColorPipesAdjacientToPath(Path path, Brush? color1, Brush? color2) {
|
||||
var color = color1;
|
||||
HashSet<IEdge> visited = [];
|
||||
foreach (var (edge, node) in path.Hops) {
|
||||
edge.Highlight = color1;
|
||||
visited.Add(edge);
|
||||
if (node is Pump) color = color2;
|
||||
Graph.TraverseSubgraph(node, visited, edgeAction: (e) => e.Highlight = color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user