Compare commits

..

8 Commits

Author SHA1 Message Date
lorenz.stechauner 79e8640ac0 Add conveyor belt and augers 2026-07-16 12:54:16 +02:00
lorenz.stechauner 62f227ca03 Add frame to press 2026-07-16 01:11:31 +02:00
lorenz.stechauner 3f6fba36e0 Add Übernahme-Trog 2026-07-16 00:09:26 +02:00
lorenz.stechauner b8ac414673 Display filling level 2026-07-15 13:59:22 +02:00
lorenz.stechauner 4c9da5c9d5 Add Rebler 2026-07-15 00:06:26 +02:00
lorenz.stechauner 9baae02240 PlantSchemeWindow: Add MinWidth/MinHeight 2026-07-14 17:14:21 +02:00
lorenz.stechauner 77bcfcc3b8 Add valve open/close logic 2026-07-14 16:55:03 +02:00
lorenz.stechauner 44a605598e Add heat exchangers 2026-07-14 16:29:12 +02:00
21 changed files with 927 additions and 187 deletions
@@ -0,0 +1,43 @@
using System.Windows.Media;
namespace PamhagenSysCtrl.Helpers {
public class PamhagenBrushes {
public const double TRANSITION = 1.0 / 4096;
public static readonly SolidColorBrush Green = new SolidColorBrush(Color.FromRgb(0x20, 0xE0, 0x20));
public static readonly SolidColorBrush DimOrange = new SolidColorBrush(Color.FromRgb(0xFF, 0xC0, 0x80));
public static readonly SolidColorBrush Yellow = new SolidColorBrush(Color.FromRgb(0xFF, 0xE0, 0x10));
public static readonly SolidColorBrush Red = new SolidColorBrush(Color.FromRgb(0xFF, 0x20, 0x20));
public static Brush ForFillState(FillState state, Color background) {
return state switch {
FillState.Empty => GetEmpty(background),
FillState.Filled => GetFilled(background),
FillState.Half => GetHalf(background),
FillState.Full => GetFull(background),
_ => GetEmpty(background),
};
}
public static Brush ForFillState(FillState state, SolidColorBrush background) {
return ForFillState(state, background.Color);
}
public static Brush GetEmpty(Color background) {
return new SolidColorBrush(background);
}
public static Brush GetFilled(Color background) {
return new LinearGradientBrush(background, Green.Color, new(0.5, 0.875 - TRANSITION), new(0.5, 0.875 + TRANSITION));
}
public static Brush GetHalf(Color background) {
return new LinearGradientBrush(background, Green.Color, new(0.5, 0.5 - TRANSITION), new(0.5, 0.5 + TRANSITION));
}
public static Brush GetFull(Color background) {
return new LinearGradientBrush(background, Red.Color, new(0.5, 0.0625 - TRANSITION), new(0.5, 0.0625 + TRANSITION));
}
}
}
+138 -56
View File
@@ -4,21 +4,27 @@ using System.Windows.Media;
namespace PamhagenSysCtrl.Helpers { namespace PamhagenSysCtrl.Helpers {
public class PamhagenGraph : Graph { public class PamhagenGraph : Graph {
private readonly List<Path> _selectedPaths = [];
public IEnumerable<Path> SelectedPaths => _selectedPaths;
public readonly Trough MW1; public readonly Trough MW1;
public readonly Trough MW2; public readonly Trough MW2;
public PamhagenGraph() { public PamhagenGraph() {
double mw2X = 100; double mw2X = 180;
double mw1X = 250; double mw1X = 300;
double mpY = 280; double mpY = 380;
double ltg1Y = 410; double ltg1Y = 510;
double ltg2Y = ltg1Y + 30; double ltg2Y = ltg1Y + 30;
double ltg1X = 600; double ltg1X = 600;
double ltg2X = ltg1X + 30; double ltg2X = ltg1X + 30;
double ltg6Y = 60; double ltg6Y = 160;
double ltg7Y = ltg6Y - 30; double ltg7Y = ltg6Y - 30;
double tanksY = 180; double tanksY = 280;
double tValveY = ((tanksY - 50) + ltg6Y) / 2 + 5; double tValveY = ((tanksY - 50) + ltg6Y) / 2 + 5;
double wtX = ltg1X - 180;
double wt2Y = 225;
double wt1Y = wt2Y + 135;
double t1X = 735; double t1X = 735;
double t2X = t1X + 80; double t2X = t1X + 80;
double t3X = t2X + 80; double t3X = t2X + 80;
@@ -28,9 +34,26 @@ namespace PamhagenSysCtrl.Helpers {
double t7X = t6X + 80; double t7X = t6X + 80;
double t8X = t7X + 80; double t8X = t7X + 80;
double t9X = t8X + 80; double t9X = t8X + 80;
var prY = 780;
var pr1X = 750;
var pr2X = 900;
MW1 = new Trough("MW1", mw1X, mpY - 70, () => App.Plant?.FillLevelA1 != FillState.Empty); var trough = new EntryTrough("Auffangwanne", mw1X + 70, 100);
MW2 = new Trough("MW2", mw2X, mpY - 70, () => App.Plant?.FillLevelA1 != FillState.Empty); Nodes.Add(trough);
var auger1 = new EncasedAuger("", (mw1X + mw2X) / 2 - 100, 200);
var auger2 = new EncasedAuger("Pressen-\nQuerschnecke", 40, 200, 180);
var auger3 = new EncasedAuger("", 120, 80, 135);
var belt = new ConveyorBelt("", 90, 160);
Nodes.Add(belt);
Nodes.Add(auger1);
Nodes.Add(auger2);
Nodes.Add(auger3);
var rebler = new Rebler("Rebler", (mw1X + mw2X) / 2, 200);
Nodes.Add(rebler);
MW1 = new Trough("MW1", mw1X, mpY - 70, () => App.Plant?.FillLevelA1 ?? FillState.Unknown);
MW2 = new Trough("MW2", mw2X, mpY - 70, () => App.Plant?.FillLevelA1 ?? FillState.Unknown);
var mp1 = new Pump("MP1", mw1X, mpY); var mp1 = new Pump("MP1", mw1X, mpY);
var mp2 = new Pump("MP2", mw2X, mpY); var mp2 = new Pump("MP2", mw2X, mpY);
var x1 = new PipeJoin(mw1X, mpY + 40); var x1 = new PipeJoin(mw1X, mpY + 40);
@@ -67,7 +90,7 @@ namespace PamhagenSysCtrl.Helpers {
var v6 = CreateValve(6, mw1X, ltg2Y + 40); var v6 = CreateValve(6, mw1X, ltg2Y + 40);
var v7 = CreateValve(7, (mw2X + mw1X) / 2, ltg2Y); var v7 = CreateValve(7, (mw2X + mw1X) / 2, ltg2Y);
var v8 = CreateValve(8, mw2X, ltg2Y + 40); var v8 = CreateValve(8, mw2X, ltg2Y + 40);
var v9 = CreateValve(9, ltg2X, 400); var v9 = CreateValve(9, ltg2X, 500);
CreatePipe(x4, v5); CreatePipe(x4, v5);
CreatePipe(x4, v6); CreatePipe(x4, v6);
@@ -75,56 +98,71 @@ namespace PamhagenSysCtrl.Helpers {
CreatePipe(x6, v8); CreatePipe(x6, v8);
CreatePipe(v7, v9); CreatePipe(v7, v9);
var xv15 = new PipeJoin(ltg1X, 300); var xv15 = new PipeJoin(ltg1X, wt1Y + 40);
var xv11 = new PipeJoin(ltg2X, 330); var xv11 = new PipeJoin(ltg2X, wt1Y + 70);
var x7 = new PipeJoin(ltg2X, 360); var x7 = new PipeJoin(ltg2X, 460);
CreatePipe(v5, xv15); CreatePipe(v5, xv15);
CreatePipe(v9, x7); CreatePipe(v9, x7);
CreatePipe(x7, xv11); CreatePipe(x7, xv11);
var v10 = CreateValve(10, ltg2X + 40, 360); var v10 = CreateValve(10, ltg2X + 40, 460);
var v11 = CreateValve(11, ltg1X - 40, 330); var v11 = CreateValve(11, ltg1X - 30, wt1Y + 70);
var v12 = CreateValve(12, ltg1X, 260); var v12 = CreateValve(12, ltg1X, wt1Y);
var v13 = CreateValve(13, ltg2X, 260); var v13 = CreateValve(13, ltg2X, wt1Y);
var v14 = CreateValve(14, ltg1X - 40, 220); var v14 = CreateValve(14, ltg1X - 30, wt1Y - 40);
var v15 = CreateValve(15, ltg1X - 40, 300); var v15 = CreateValve(15, ltg1X - 30, wt1Y + 40);
var v16 = CreateValve(16, ltg1X - 40, 190); var v16 = CreateValve(16, ltg1X - 30, wt1Y - 70);
CreatePipe(v10, x7); CreatePipe(v10, x7);
CreatePipe(xv11, v11); CreatePipe(xv11, v11);
CreatePipe(xv15, v15); CreatePipe(xv15, v15);
CreatePipe(xv15, v12); CreatePipe(xv15, v12);
CreatePipe(xv11, v13); CreatePipe(xv11, v13);
var xv16 = new PipeJoin(ltg1X, 190); var xv16 = new PipeJoin(ltg1X, wt1Y - 70);
var xv14 = new PipeJoin(ltg2X, 220); var xv14 = new PipeJoin(ltg2X, wt1Y - 40);
CreatePipe(v12, xv16); CreatePipe(v12, xv16);
CreatePipe(v13, xv14); CreatePipe(v13, xv14);
CreatePipe(v16, xv16); CreatePipe(v16, xv16);
CreatePipe(v14, xv14); CreatePipe(v14, xv14);
var v20 = CreateValve(20, ltg1X - 40, 60); var v20 = CreateValve(20, ltg1X - 30, wt2Y - 70);
var v21 = CreateValve(21, ltg1X - 40, 90); var v21 = CreateValve(21, ltg1X - 30, wt2Y - 40);
var xv20 = new PipeJoin(ltg1X, 60); var xv20 = new PipeJoin(ltg1X, wt2Y - 70);
var xv21 = new PipeJoin(ltg2X, 90); var xv21 = new PipeJoin(ltg2X, wt2Y - 40);
CreatePipe(xv16, xv20); CreatePipe(xv16, xv20);
CreatePipe(xv14, xv21); CreatePipe(xv14, xv21);
CreatePipe(v20, xv20); CreatePipe(v20, xv20);
CreatePipe(v21, xv21); CreatePipe(v21, xv21);
var x8 = new PipeJoin(ltg1X - 80, 300); var wt1 = new HeatExchanger("WT Most", wtX, wt1Y);
var x9 = new PipeJoin(ltg1X - 80, 220); var wt2 = new HeatExchanger("WT Warmwasser", wtX, wt2Y);
var x10 = new PipeJoin(ltg1X - 80, 90); var v17 = CreateValve(17, wtX + 70, wt1Y);
var v18 = CreateValve(18, wtX + 40, wt1Y + 40);
CreatePipe(v11, x8); var v19 = CreateValve(19, wtX + 40, (wt1Y + wt2Y) / 2);
CreatePipe(v15, x8); var xwt1 = new PipeJoin(wtX + 120, wt1Y + 40);
CreatePipe(x9, v14, true); var xwt2 = new PipeJoin(wtX + 70, wt1Y + 40);
CreatePipe(x9, v16, true); var xwt3 = new PipeJoin(wtX + 40, wt1Y - 40);
CreatePipe(x10, v20, true); var xwt4 = new PipeJoin(wtX + 120, wt1Y - 40);
CreatePipe(x10, v21, true); var xwt5 = new PipeJoin(wtX + 40, wt2Y + 40);
var xwt6 = new PipeJoin(wtX + 120, wt2Y - 40);
CreatePipe(v11, xwt1);
CreatePipe(v15, xwt1);
CreatePipe(xwt1, xwt2);
CreatePipe(xwt4, v14, true);
CreatePipe(xwt4, v16, true);
CreatePipe(xwt6, v20, true);
CreatePipe(xwt6, v21, true);
CreatePipe(wt2, xwt6, true);
CreatePipe(wt1, xwt3, true);
CreatePipe(xwt3, xwt4);
CreatePipe(xwt2, v18);
CreatePipe(v18, wt1);
CreatePipe(xwt2, v17);
CreatePipe(xwt3, v19);
CreatePipe(v17, xwt5, true);
CreatePipe(v19, xwt5);
CreatePipe(xwt5, wt2);
var xv22 = new PipeJoin(t1X - 15, ltg7Y); var xv22 = new PipeJoin(t1X - 15, ltg7Y);
var xv23 = new PipeJoin(t1X + 15, ltg6Y); var xv23 = new PipeJoin(t1X + 15, ltg6Y);
@@ -290,11 +328,8 @@ namespace PamhagenSysCtrl.Helpers {
var v49 = CreateValve(49, t4X, tanksY + 220); var v49 = CreateValve(49, t4X, tanksY + 220);
CreatePipe(xv47, v49); CreatePipe(xv47, v49);
var prY = 680; var press1 = new Press("Presse 1", pr1X, prY, 200000, () => App.Plant?.FillLevelPress1 ?? FillState.Unknown);
var pr1X = 750; var press2 = new Press("Presse 2", pr2X, prY, 150000, () => App.Plant?.FillLevelPress1 ?? FillState.Unknown);
var pr2X = 900;
var press1 = new Press("Presse 1", pr1X, prY, 200000, () => App.Plant?.FillLevelPress1 == FillState.Full);
var press2 = new Press("Presse 2", pr2X, prY, 150000, () => App.Plant?.FillLevelPress1 == FillState.Full);
var v50 = CreateValve(50, pr1X - 45, prY - 100); var v50 = CreateValve(50, pr1X - 45, prY - 100);
var v51 = CreateValve(51, pr1X - 15, prY - 100); var v51 = CreateValve(51, pr1X - 15, prY - 100);
var v52 = CreateValve(52, pr1X + 15, prY - 100); var v52 = CreateValve(52, pr1X + 15, prY - 100);
@@ -303,10 +338,10 @@ namespace PamhagenSysCtrl.Helpers {
var v55 = CreateValve(55, pr2X - 15, prY - 100); var v55 = CreateValve(55, pr2X - 15, prY - 100);
var v56 = CreateValve(56, pr2X + 15, prY - 100); var v56 = CreateValve(56, pr2X + 15, prY - 100);
var v57 = CreateValve(57, pr2X + 45, prY - 100); var v57 = CreateValve(57, pr2X + 45, prY - 100);
var xp1 = new PipeJoin(pr1X - 15, 510); var xp1 = new PipeJoin(pr1X - 15, 610);
var xp2 = new PipeJoin(pr1X + 15, 540); var xp2 = new PipeJoin(pr1X + 15, 640);
var xp3 = new PipeJoin(pr2X - 45, 450); var xp3 = new PipeJoin(pr2X - 45, 550);
var xp4 = new PipeJoin(pr2X + 45, 480); var xp4 = new PipeJoin(pr2X + 45, 580);
CreatePipe(v6, xp1, true); CreatePipe(v6, xp1, true);
CreatePipe(v8, xp2, true); CreatePipe(v8, xp2, true);
@@ -332,14 +367,15 @@ namespace PamhagenSysCtrl.Helpers {
} }
protected static Valve CreateValve(int n, double x, double y) { protected static Valve CreateValve(int n, double x, double y) {
return new($"V{n}", x, y, () => App.Plant?.IsValveOpen(4) ?? false, () => App.Plant?.WantValveOpen(4) ?? false); return new(n, x, y, () => App.Plant?.IsValveOpen(4) ?? false, () => App.Plant?.WantValveOpen(4) ?? false);
} }
protected static Tank CreateTank(int n, double x, double y, int capacity) { protected static Tank CreateTank(int n, double x, double y, int capacity) {
return new($"Tank {n}", x, y, capacity, () => App.Plant?.TankFillLevels[n - 1] != FillState.Empty, () => App.Plant?.TankFillLevels[n - 1] != FillState.Full); return new($"Tank {n}", x, y, capacity, () => App.Plant?.TankFillLevels[n - 1] ?? FillState.Unknown);
} }
public void ColorSubgraph(INode start, Brush color, Action<Valve>? valveAction = null) { public void TraverseSubgraph(INode start, HashSet<IEdge>? visited = null, Action<IEdge>? edgeAction = null, Action<Valve>? valveAction = null) {
visited ??= [];
if (start is Valve v) { if (start is Valve v) {
valveAction?.Invoke(v); valveAction?.Invoke(v);
return; return;
@@ -347,16 +383,62 @@ namespace PamhagenSysCtrl.Helpers {
return; return;
} }
foreach (var edge in start.Inputs) { foreach (var edge in start.Inputs) {
if (edge.Highlight != null) continue; if (visited.Contains(edge)) continue;
var o = edge.IsTwoWay && edge.Start == start ? edge.End : edge.Start; var o = edge.IsTwoWay && edge.Start == start ? edge.End : edge.Start;
edge.Highlight = color; edgeAction?.Invoke(edge);
ColorSubgraph(o, color, valveAction); visited.Add(edge);
TraverseSubgraph(o, visited, edgeAction, valveAction);
} }
foreach (var edge in start.Outputs) { foreach (var edge in start.Outputs) {
if (edge.Highlight != null) continue; if (visited.Contains(edge)) continue;
var o = edge.IsTwoWay && edge.End == start ? edge.Start : edge.End; var o = edge.IsTwoWay && edge.End == start ? edge.Start : edge.End;
edge.Highlight = color; edgeAction?.Invoke(edge);
ColorSubgraph(o, color, valveAction); visited.Add(edge);
TraverseSubgraph(o, visited, edgeAction, valveAction);
}
}
public void AddPath(Path path) {
_selectedPaths.Add(path);
UpdateValvesAdjacientToPath(path, true);
if (App.Plant is PamhagenPlant plant) {
foreach (var (edge, _) in path.Hops) {
if (edge is Valve v) {
plant.OpenV(v.Nr);
}
}
plant.CommitChanges();
}
}
public void RemovePath(Path path) {
_selectedPaths.Remove(path);
UpdateValvesAdjacientToPath(path, false);
foreach (var p in _selectedPaths) UpdateValvesAdjacientToPath(p, true);
if (App.Plant is PamhagenPlant plant) {
foreach (var (edge, _) in path.Hops) {
if (edge is Valve v) {
plant.CloseV(v.Nr);
}
}
plant.CommitChanges();
}
}
private void UpdateValvesAdjacientToPath(Path path, bool locked) {
foreach (var (edge, node) in path.Hops) {
TraverseSubgraph(node, valveAction: (v) => v.IsLocked = locked);
}
}
public 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;
TraverseSubgraph(node, visited, edgeAction: (e) => e.Highlight = color);
} }
} }
} }
+75
View File
@@ -0,0 +1,75 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class Auger {
public double CenterX { get; set; }
public double CenterY { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public double Angle { get; set; }
public bool IsActive {
set {
if (value) {
_storyboard?.Resume();
} else {
_storyboard?.Pause();
}
}
}
private Polyline? _polyline;
private Storyboard? _storyboard;
public Auger(double x, double y, double width, double height, double angle = 0) {
CenterX = x;
CenterY = y;
Width = width;
Height = height;
Angle = angle;
}
public void Draw(Canvas canvas) {
var d = Height / 4;
int n = (int)(Width / d / 4) + 2;
_polyline = new Polyline() {
Points = [.. Enumerable.Range(0, n).SelectMany(i => new List<Point>() {
new(i * 4 * d, Height / 2), new((i * 4 + 1) * d, 0),
new((i * 4 + 2) * d, Height / 2), new((i * 4 + 3) * d, Height)
}), new(n * 4 * d, Height / 2), new(0, Height / 2)],
Fill = Brushes.Transparent,
Stroke = Brushes.Black,
StrokeThickness = 2,
};
_polyline.SetValue(Canvas.LeftProperty, 0.0);
var slideLeft = new DoubleAnimation {
From = 0,
To = -d * 4,
Duration = new Duration(TimeSpan.FromSeconds(1)),
RepeatBehavior = RepeatBehavior.Forever,
};
_storyboard = new Storyboard();
_storyboard.Children.Add(slideLeft);
Storyboard.SetTarget(slideLeft, _polyline);
Storyboard.SetTargetProperty(slideLeft, new PropertyPath(Canvas.LeftProperty));
var clipCanvas = new Canvas() {
Width = Width,
Height = Height,
ClipToBounds = true,
RenderTransform = new RotateTransform(Angle, Width / 2, Height / 2),
};
clipCanvas.SetValue(Canvas.TopProperty, CenterY - Height / 2);
clipCanvas.SetValue(Canvas.LeftProperty, CenterX - Width / 2);
clipCanvas.Children.Add(_polyline);
canvas.Children.Add(clipCanvas);
_storyboard.Begin();
_storyboard.Pause();
}
}
}
@@ -0,0 +1,109 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class ConveyorBelt : INode {
public const double WIDTH = 35;
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; }
public bool IsActive {
get => _active;
set {
_active = value;
if (value) {
_storyboard?.Resume();
} else {
_storyboard?.Pause();
}
}
}
private bool _active;
private Shape? _rect;
private Polyline? _polyline;
private Storyboard? _storyboard;
public ConveyorBelt(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,
StrokeLineJoin = PenLineJoin.Round,
};
_rect.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
_rect.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
var d = 20;
int n = (int)(HEIGHT / d) + 2;
_polyline = new Polyline() {
Points = [.. Enumerable.Range(0, n).SelectMany(i => new List<Point>() {
new(-WIDTH, i * d), new(WIDTH, i * d), new(-WIDTH, i * d)
})],
Fill = Brushes.Transparent,
Stroke = Brushes.Black,
StrokeThickness = 2,
};
_polyline.SetValue(Canvas.TopProperty, 0.0);
var slideUp = new DoubleAnimation {
From = 0,
To = -d,
Duration = new Duration(TimeSpan.FromSeconds(1)),
RepeatBehavior = RepeatBehavior.Forever,
};
_storyboard = new Storyboard();
_storyboard.Children.Add(slideUp);
Storyboard.SetTarget(slideUp, _polyline);
Storyboard.SetTargetProperty(slideUp, new PropertyPath(Canvas.TopProperty));
var clipCanvas = new Canvas() {
Width = WIDTH - 20,
Height = HEIGHT - 2,
ClipToBounds = true,
};
clipCanvas.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2 + 2);
clipCanvas.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2 + 10);
clipCanvas.Children.Add(_polyline);
canvas.Children.Add(_rect);
canvas.Children.Add(clipCanvas);
_storyboard.Begin();
_storyboard.Pause();
}
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 =
IsActive && isHovering && isPressed ? PamhagenBrushes.Red :
IsActive && isHovering ? PamhagenBrushes.Red :
!IsActive && isHovering && isPressed ? PamhagenBrushes.Green :
!IsActive && isHovering ? PamhagenBrushes.Green :
IsActive ? PamhagenBrushes.Green :
Brushes.WhiteSmoke;
}
}
}
@@ -0,0 +1,92 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class EncasedAuger : INode {
public const double WIDTH = 80;
public const double HEIGHT = 20;
public double CenterX { get; set; }
public double CenterY { get; set; }
public double Angle { get; set; }
public string Label { get; set; }
public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; }
public bool IsActive {
get => _active;
set {
_active = value;
_auger?.IsActive = value;
}
}
private bool _active;
private Shape? _inner;
private Shape? _outer;
private Auger? _auger;
private TextBlock? _text;
public EncasedAuger(string label, double x, double y, double angle = 0) {
CenterX = x;
CenterY = y;
Label = label;
Angle = angle;
Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>();
}
public void Draw(Canvas canvas) {
var c = new Canvas() {
RenderTransform = new RotateTransform(Angle, WIDTH / 2, HEIGHT / 2),
};
_outer = new Rectangle() {
Width = WIDTH,
Height = HEIGHT,
Fill = Brushes.Black,
};
_inner = new Rectangle() {
Width = WIDTH,
Height = HEIGHT - 4,
Fill = Brushes.WhiteSmoke,
};
c.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
c.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
_inner.SetValue(Canvas.TopProperty, 2.0);
c.Children.Add(_outer);
c.Children.Add(_inner);
canvas.Children.Add(c);
_text = new() {
Text = Label,
Width = WIDTH,
FontSize = 12,
TextAlignment = TextAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
_text.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
_text.SetValue(Canvas.TopProperty, CenterY + HEIGHT / 2);
canvas.Children.Add(_text);
_auger = new Auger(CenterX, CenterY, WIDTH, 12, Angle);
_auger.Draw(canvas);
}
public bool IsInside(double x, double y) {
return Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= WIDTH / 2;
}
public void Update(bool isHovering, bool isPressed) {
_inner?.Fill =
IsActive && isHovering && isPressed ? PamhagenBrushes.Red :
IsActive && isHovering ? PamhagenBrushes.Red :
!IsActive && isHovering && isPressed ? PamhagenBrushes.Green :
!IsActive && isHovering ? PamhagenBrushes.Green :
IsActive ? PamhagenBrushes.Green :
Brushes.WhiteSmoke;
}
}
}
@@ -0,0 +1,111 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
class EntryTrough : INode {
public const double WIDTH = 150;
public const double HEIGHT = 60;
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; }
public bool IsActive {
get => _active;
set {
_active = value;
_auger?.IsActive = value;
if (value) {
_doorTransform?.BeginAnimation(
RotateTransform.AngleProperty,
new DoubleAnimation {
From = _doorTransform.Angle,
To = 60,
Duration = TimeSpan.FromSeconds(Math.Abs(_doorTransform.Angle - 60) / 60.0)
});
} else {
_doorTransform?.BeginAnimation(
RotateTransform.AngleProperty,
new DoubleAnimation {
From = _doorTransform.Angle,
To = 0,
Duration = TimeSpan.FromSeconds(Math.Abs(_doorTransform.Angle - 0) / 60.0)
});
}
}
}
private bool _active;
private Shape? _inner;
private Shape? _outer;
private TextBlock? _text;
private Auger? _auger;
private Shape? _door;
private RotateTransform? _doorTransform;
public EntryTrough(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) {
var top = CenterY - HEIGHT / 2;
var right = CenterX + WIDTH / 2;
var bottom = CenterY + HEIGHT / 2;
var left = CenterX - WIDTH / 2;
_outer = new Polygon() {
Points = [new(left, top), new(right, top), new(right - 20, bottom), new(left, bottom), new(left, bottom - 20), new(left + 12.5, bottom - 20)],
Fill = Brushes.Black,
};
_inner = new Polygon() {
Points = [new(left + 2, top), new(right - 2, top), new(right - 20 - 2, bottom - 2), new(left, bottom - 2), new(left, bottom - 18), new(left + 15.5, bottom - 18)],
Fill = Brushes.WhiteSmoke,
};
_doorTransform = new RotateTransform(0, left, bottom - 24);
_door = new Line() {
X1 = left, Y1 = bottom - 24, X2 = left, Y2 = bottom + 4,
Stroke = Brushes.Black,
StrokeThickness = 4,
RenderTransform = _doorTransform,
};
_text = new() {
Text = Label,
FontSize = 12,
Width = WIDTH,
TextAlignment = TextAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
_text.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
_text.SetValue(Canvas.TopProperty, CenterY - 7.5 - 8);
canvas.Children.Add(_outer);
canvas.Children.Add(_inner);
canvas.Children.Add(_text);
canvas.Children.Add(_door);
_auger = new(CenterX - 11, CenterY + HEIGHT / 2 - 9, WIDTH - 25, 12);
_auger.Draw(canvas);
}
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) {
_inner?.Fill =
IsActive && isHovering && isPressed ? PamhagenBrushes.Red :
IsActive && isHovering ? PamhagenBrushes.Red :
!IsActive && isHovering && isPressed ? PamhagenBrushes.Green :
!IsActive && isHovering ? PamhagenBrushes.Green :
IsActive ? PamhagenBrushes.Green :
Brushes.WhiteSmoke;
}
}
}
+20 -8
View File
@@ -54,11 +54,23 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
return p; 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) { 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"); if (!Nodes.Contains(start) || !Nodes.Contains(end)) throw new ArgumentException("Start/end node not contained in graph");
valid ??= a => true; valid ??= a => true;
visited ??= []; visited = [.. visited ?? [], start];
visited.Add(start);
List<(IEdge, INode)> hops = []; List<(IEdge, INode)> hops = [];
Path? path = null; Path? path = null;
foreach (var o in start.Outputs) { foreach (var o in start.Outputs) {
@@ -94,17 +106,17 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
} }
} }
public ISet<INode> Update(double x, double y, bool down) { public ISet<INode> GetHover(double x, double y) {
HashSet<INode> hover = new(); return Nodes.Where(n => n.IsInside(x, y)).ToHashSet();
}
public void Update(ISet<INode> hovering, bool isPressed) {
foreach (var e in Edges) { foreach (var e in Edges) {
e.Update(); e.Update();
} }
foreach (var n in Nodes) { foreach (var n in Nodes) {
if (n.Update(x, y, down)) { n.Update(hovering.Contains(n), isPressed);
hover.Add(n);
} }
} }
return hover;
}
} }
} }
@@ -0,0 +1,64 @@
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 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;
}
}
}
+2 -1
View File
@@ -10,7 +10,8 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public ISet<IEdge> Outputs { get; } public ISet<IEdge> Outputs { get; }
public void Draw(Canvas canvas); public void Draw(Canvas canvas);
public bool Update(double x, double y, bool down); public void Update(bool isHovering, bool isPressed);
public bool IsInside(double x, double y);
} }
} }
@@ -2,6 +2,5 @@
public interface ISource : INode { public interface ISource : INode {
public double BottomY { get; } public double BottomY { get; }
public bool IsFilled { get; } public bool IsFilled { get; }
public bool IsSelected { get; set; }
} }
} }
+1 -1
View File
@@ -3,7 +3,7 @@
INode Start, INode Start,
IEnumerable<(IEdge Edge, INode Node)> Hops) 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)); 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));
} }
} }
+12 -30
View File
@@ -1,5 +1,4 @@
using System.Windows; using System.Windows.Controls;
using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
@@ -12,10 +11,8 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public bool Orientation { get; set; } public bool Orientation { get; set; }
public Brush? Highlight { get; set; } public Brush? Highlight { get; set; }
private Line? _outer1; private Polyline? _outer;
private Line? _outer2; private Polyline? _inner;
private Line? _inner1;
private Line? _inner2;
public Pipe(INode start, INode end, bool orientation = false, bool twoWay = false) { public Pipe(INode start, INode end, bool orientation = false, bool twoWay = false) {
Start = start; Start = start;
@@ -31,43 +28,28 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
var y2 = Orientation ? End.CenterY : Start.CenterY; var y2 = Orientation ? End.CenterY : Start.CenterY;
var x3 = End.CenterX; var x3 = End.CenterX;
var y3 = End.CenterY; var y3 = End.CenterY;
_outer1 = new Line() { _outer = new Polyline() {
X1 = x1, Y1 = y1, X2 = x2, Y2 = y2, Points = [new(x1, y1), new(x2, y2), new(x3, y3)],
StrokeThickness = 10, StrokeThickness = 10,
Stroke = Brushes.Black, Stroke = Brushes.Black,
StrokeStartLineCap = PenLineCap.Round, StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round,
StrokeLineJoin = PenLineJoin.Round,
}; };
_inner1 = new Line() { _inner = new Polyline() {
X1 = x1, Y1 = y1, X2 = x2, Y2 = y2, Points = [new(x1, y1), new(x2, y2), new(x3, y3)],
StrokeThickness = 6, StrokeThickness = 6,
Stroke = Brushes.DarkGray, Stroke = Brushes.DarkGray,
StrokeStartLineCap = PenLineCap.Round, StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round,
StrokeLineJoin = PenLineJoin.Round,
}; };
_outer2 = new Line() { canvas.Children.Add(_outer);
X1 = x2, Y1 = y2, X2 = x3, Y2 = y3, canvas.Children.Add(_inner);
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.Round,
StrokeEndLineCap = PenLineCap.Round,
};
canvas.Children.Add(_outer1);
canvas.Children.Add(_outer2);
canvas.Children.Add(_inner1);
canvas.Children.Add(_inner2);
} }
public void Update() { public void Update() {
_inner1?.Stroke = Highlight ?? Brushes.DarkGray; _inner?.Stroke = Highlight ?? Brushes.DarkGray;
_inner2?.Stroke = Highlight ?? Brushes.DarkGray;
} }
} }
} }
+7 -5
View File
@@ -11,7 +11,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public double CenterX { get; set; } public double CenterX { get; set; }
public double CenterY { get; set; } public double CenterY { get; set; }
public string Label { get; } = ""; public string Label => "";
public ISet<IEdge> Inputs { get; init; } public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; } public ISet<IEdge> Outputs { get; init; }
@@ -81,10 +81,12 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
canvas.Children.Add(_rect); canvas.Children.Add(_rect);
} }
public bool Update(double x, double y, bool down) { public bool IsInside(double x, double y) {
var hover = Math.Abs(x - CenterX) <= SIZE / 2 && Math.Abs(y - CenterY) <= SIZE / 2; return Math.Abs(x - CenterX) <= SIZE / 2 && Math.Abs(y - CenterY) <= SIZE / 2;
_rect?.Stroke = hover ? Brushes.Black : Brushes.Black; }
return hover;
public void Update(bool isHovering, bool isPressed) {
_rect?.Stroke = isHovering ? Brushes.Black : Brushes.Black;
} }
} }
} }
+31 -10
View File
@@ -1,6 +1,7 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Shapes; using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline { namespace PamhagenSysCtrl.Helpers.Pipeline {
@@ -15,23 +16,24 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public ISet<IEdge> Inputs { get; set; } public ISet<IEdge> Inputs { get; set; }
public ISet<IEdge> Outputs { get; set; } public ISet<IEdge> Outputs { get; set; }
protected Func<bool> CallbackIsFull;
public double TopY => CenterY - DIAMETER / 2; public double TopY => CenterY - DIAMETER / 2;
public bool IsFull => CallbackIsFull(); public FillState FillState => CallbackFillState();
public bool IsFull => FillState == FillState.Full;
public int? CapacityLiters { get; set; } public int? CapacityLiters { get; set; }
protected Func<FillState> CallbackFillState;
private Shape? _frame;
private Shape? _circle; private Shape? _circle;
private TextBlock? _text; private TextBlock? _text;
public Press(string label, double x, double y, int capacityLiters, Func<FillState> cbFillState) {
public Press(string label, double x, double y, int capacityLiters, Func<bool> cbFull) {
CenterX = x; CenterX = x;
CenterY = y; CenterY = y;
Label = label; Label = label;
CapacityLiters = capacityLiters; CapacityLiters = capacityLiters;
CallbackIsFull = cbFull; CallbackFillState = cbFillState;
Inputs = new HashSet<IEdge>(); Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>(); Outputs = new HashSet<IEdge>();
} }
@@ -44,6 +46,17 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
StrokeThickness = 2, StrokeThickness = 2,
Fill = Brushes.WhiteSmoke, Fill = Brushes.WhiteSmoke,
}; };
_frame = new Polygon() {
Points = [
new(CenterX - DIAMETER / 2 - 10, CenterY), new(CenterX + DIAMETER / 2 + 10, CenterY),
new(CenterX + DIAMETER / 2 + 10, CenterY + DIAMETER / 2 + 30), new(CenterX + DIAMETER / 2 - 20, CenterY + DIAMETER / 2 + 30),
new(CenterX + DIAMETER / 2 - 20, CenterY + DIAMETER / 2 + 10), new(CenterX - DIAMETER / 2 + 20, CenterY + DIAMETER / 2 + 10),
new(CenterX - DIAMETER / 2 + 20, CenterY + DIAMETER / 2 + 30), new(CenterX - DIAMETER / 2 - 10, CenterY + DIAMETER / 2 + 30)
],
Stroke = Brushes.Black,
StrokeThickness = 2,
Fill = Brushes.WhiteSmoke,
};
_text = new() { _text = new() {
Text = CapacityLiters.HasValue ? $"{Label}\n{CapacityLiters:N0}" : Label, Text = CapacityLiters.HasValue ? $"{Label}\n{CapacityLiters:N0}" : Label,
FontSize = 14, FontSize = 14,
@@ -55,14 +68,22 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
_circle.SetValue(Canvas.TopProperty, CenterY - DIAMETER / 2); _circle.SetValue(Canvas.TopProperty, CenterY - DIAMETER / 2);
_text.SetValue(Canvas.LeftProperty, CenterX - DIAMETER / 2); _text.SetValue(Canvas.LeftProperty, CenterX - DIAMETER / 2);
_text.SetValue(Canvas.TopProperty, CenterY - (CapacityLiters.HasValue ? 20 : 10)); _text.SetValue(Canvas.TopProperty, CenterY - (CapacityLiters.HasValue ? 20 : 10));
canvas.Children.Add(_frame);
canvas.Children.Add(_circle); canvas.Children.Add(_circle);
canvas.Children.Add(_text); canvas.Children.Add(_text);
} }
public bool Update(double x, double y, bool down) { public bool IsInside(double x, double y) {
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2; return Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2 || (Math.Abs(x - CenterX) <= DIAMETER / 2 + 10 && y >= CenterY && y <= CenterY + DIAMETER / 2 + 30);
_circle?.Fill = hover ? Brushes.LightGray : Brushes.WhiteSmoke; }
return hover;
public void Update(bool isHovering, bool isPressed) {
var color =
isHovering && isPressed ? Brushes.DarkGray :
isHovering ? Brushes.LightGray :
Brushes.WhiteSmoke;
_circle?.Fill = PamhagenBrushes.ForFillState(FillState, color);
_frame?.Fill = color;
} }
} }
} }
+6 -4
View File
@@ -58,10 +58,12 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
canvas.Children.Add(_text); canvas.Children.Add(_text);
} }
public bool Update(double x, double y, bool down) { public bool IsInside(double x, double y) {
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2; return Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2;
_circle?.Fill = hover ? Brushes.LightGray : Brushes.WhiteSmoke; }
return hover;
public void Update(bool isHovering, bool isPresed) {
_circle?.Fill = isHovering ? Brushes.LightGray : Brushes.WhiteSmoke;
} }
} }
} }
+102
View File
@@ -0,0 +1,102 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class Rebler : INode {
public const double WIDTH = 120;
public const double HEIGHT = 60;
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; }
public bool IsActive { get; set; }
private TextBlock? _text;
private Shape? _rect;
private Shape? _hopperOuter;
private Shape? _hopperInner;
private Shape? _bottomInner;
private Shape? _bottomOuter;
public Rebler(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,
Fill = Brushes.WhiteSmoke,
Stroke = Brushes.Black,
StrokeThickness = 2,
};
var left = CenterX - WIDTH / 2;
var right = CenterX + WIDTH / 2;
var top = CenterY - HEIGHT / 2;
var bottom = CenterY + HEIGHT / 2;
var hx = right - 20;
var h = 15;
var w = 25;
_hopperOuter = new Polygon() {
Points = [new(hx - w, top - h), new(hx - w + 5, top + 2), new(hx + w - 5, top + 2), new(hx + w, top - h)],
Fill = Brushes.Black,
};
_hopperInner = new Polygon() {
Points = [new(hx - w + 2, top - h), new(hx - w + 5 + 2, top + 2), new(hx + w - 5 - 2, top + 2), new(hx + w - 2, top - h)],
Fill = Brushes.WhiteSmoke,
};
_bottomOuter = new Polygon() {
Points = [new(left + 20, bottom), new(right - 20, bottom), new(right - 15, bottom + 10), new(left + 15, bottom + 10)],
Fill = Brushes.Black,
};
_bottomInner = new Polygon() {
Points = [new(left + 20 + 2, bottom), new(right - 20 - 2, bottom), new(right - 15 - 2, bottom + 10), new(left + 15 + 2, bottom + 10)],
Fill = Brushes.WhiteSmoke,
};
_text = new() {
Text = Label,
FontSize = 12,
Width = WIDTH,
TextAlignment = TextAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
_rect.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
_rect.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
_text.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
_text.SetValue(Canvas.TopProperty, CenterY - 8);
canvas.Children.Add(_hopperOuter);
canvas.Children.Add(_bottomOuter);
canvas.Children.Add(_rect);
canvas.Children.Add(_hopperInner);
canvas.Children.Add(_bottomInner);
canvas.Children.Add(_text);
}
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) {
var color =
IsActive && isHovering && isPressed ? PamhagenBrushes.Red :
IsActive && isHovering ? PamhagenBrushes.Red :
!IsActive && isHovering && isPressed ? PamhagenBrushes.Green :
!IsActive && isHovering ? PamhagenBrushes.Green :
IsActive ? PamhagenBrushes.Green :
Brushes.WhiteSmoke;
_rect?.Fill = color;
_hopperInner?.Fill = color;
_bottomInner?.Fill = color;
}
}
}
+16 -12
View File
@@ -14,28 +14,26 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public double TopY => CenterY - HEIGHT / 2; public double TopY => CenterY - HEIGHT / 2;
public double BottomY => CenterY + HEIGHT / 2; public double BottomY => CenterY + HEIGHT / 2;
public string Label { get; set; } public string Label { get; set; }
public bool IsFull => CallbackIsFull(); public FillState FillState => CallbackFillState();
public bool IsFilled => CallbackIsFilled(); public bool IsFull => FillState == FillState.Full;
public bool IsSelected { get; set; } public bool IsFilled => FillState != FillState.Empty;
public ISet<IEdge> Inputs { get; init; } public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; } public ISet<IEdge> Outputs { get; init; }
public int? CapacityLiters { get; set; } public int? CapacityLiters { get; set; }
protected Func<bool> CallbackIsFilled; protected Func<FillState> CallbackFillState;
protected Func<bool> CallbackIsFull;
private Shape? _rect; private Shape? _rect;
private TextBlock? _text; private TextBlock? _text;
public Tank(string label, double x, double y, int capacityLiters, Func<bool> cbFilled, Func<bool> cbFull) { public Tank(string label, double x, double y, int capacityLiters, Func<FillState> cbFillState) {
CenterX = x; CenterX = x;
CenterY = y; CenterY = y;
Label = label; Label = label;
CapacityLiters = capacityLiters; CapacityLiters = capacityLiters;
CallbackIsFilled = cbFilled; CallbackFillState = cbFillState;
CallbackIsFull = cbFull;
Inputs = new HashSet<IEdge>(); Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>(); Outputs = new HashSet<IEdge>();
} }
@@ -63,10 +61,16 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
canvas.Children.Add(_text); canvas.Children.Add(_text);
} }
public bool Update(double x, double y, bool down) { public bool IsInside(double x, double y) {
var hover = Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2; return Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2;
_rect?.Fill = IsSelected ? Brushes.LightGray : hover ? Brushes.LightGray : Brushes.WhiteSmoke; }
return hover;
public void Update(bool isHovering, bool isPressed) {
_rect?.Fill = PamhagenBrushes.ForFillState(FillState,
isHovering && isPressed ? Brushes.DarkGray :
isHovering ? Brushes.LightGray :
Brushes.WhiteSmoke
);
} }
} }
} }
+31 -18
View File
@@ -13,52 +13,65 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public double CenterY { get; set; } public double CenterY { get; set; }
public double BottomY => CenterY + HEIGHT / 2; public double BottomY => CenterY + HEIGHT / 2;
public string Label { get; set; } public string Label { get; set; }
public bool IsFilled => CallbackIsFilled(); public FillState FillState => CallbackFillState();
public bool IsSelected { get; set; } public bool IsFilled => FillState != FillState.Empty;
public ISet<IEdge> Inputs { get; init; } public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; } public ISet<IEdge> Outputs { get; init; }
protected Func<bool> CallbackIsFilled; protected Func<FillState> CallbackFillState;
private Shape? _rect; private Shape? _inner;
private Shape? _outer;
private TextBlock? _text; private TextBlock? _text;
public Trough(string label, double x, double y, Func<bool> cbFilled) { public Trough(string label, double x, double y, Func<FillState> cbFillState) {
CenterX = x; CenterX = x;
CenterY = y; CenterY = y;
Label = label; Label = label;
CallbackIsFilled = cbFilled; CallbackFillState = cbFillState;
Inputs = new HashSet<IEdge>(); Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>(); Outputs = new HashSet<IEdge>();
} }
public void Draw(Canvas canvas) { public void Draw(Canvas canvas) {
_rect = new Rectangle() { _outer = new Rectangle() {
Width = WIDTH, Width = WIDTH,
Height = HEIGHT, Height = HEIGHT,
Stroke = Brushes.Black, Fill = Brushes.Black,
StrokeThickness = 2, };
_inner = new Rectangle() {
Width = WIDTH - 4,
Height = HEIGHT - 2,
Fill = Brushes.WhiteSmoke, Fill = Brushes.WhiteSmoke,
}; };
_text = new() { _text = new() {
Text = Label, Text = Label,
FontSize = 12, FontSize = 14,
Width = WIDTH, Width = WIDTH,
TextAlignment = TextAlignment.Center, TextAlignment = TextAlignment.Center,
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
}; };
_rect.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2); _outer.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
_rect.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2); _outer.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
_inner.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2 + 2);
_inner.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
_text.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2); _text.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
_text.SetValue(Canvas.TopProperty, CenterY - 8); _text.SetValue(Canvas.TopProperty, CenterY - 10);
canvas.Children.Add(_rect); canvas.Children.Add(_outer);
canvas.Children.Add(_inner);
canvas.Children.Add(_text); canvas.Children.Add(_text);
} }
public bool Update(double x, double y, bool down) { public bool IsInside(double x, double y) {
var hover = Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2; return Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2;
_rect?.Fill = IsSelected ? Brushes.LightGray : hover ? Brushes.LightGray : Brushes.WhiteSmoke; }
return hover;
public void Update(bool isHovering, bool isPressed) {
_inner?.Fill = PamhagenBrushes.ForFillState(FillState,
isHovering && isPressed ? Brushes.DarkGray :
isHovering ? Brushes.LightGray :
Brushes.WhiteSmoke
);
} }
} }
} }
+16 -8
View File
@@ -10,7 +10,8 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public double CenterX { get; set; } public double CenterX { get; set; }
public double CenterY { get; set; } public double CenterY { get; set; }
public string Label { get; set; } public int Nr { get; set; }
public string Label => $"V{Nr}";
public Brush? Highlight { get; set; } public Brush? Highlight { get; set; }
public bool IsLocked { get; set; } public bool IsLocked { get; set; }
@@ -25,10 +26,10 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
private Shape? _circle; private Shape? _circle;
private TextBlock? _text; private TextBlock? _text;
public Valve(string label, double x, double y, Func<bool> cbOpen, Func<bool> cbWant) { public Valve(int nr, double x, double y, Func<bool> cbOpen, Func<bool> cbWant) {
CenterX = x; CenterX = x;
CenterY = y; CenterY = y;
Label = label; Nr = nr;
CallbackIsOpen = cbOpen; CallbackIsOpen = cbOpen;
CallbackWantOpen = cbWant; CallbackWantOpen = cbWant;
Inputs = new HashSet<IEdge>(); Inputs = new HashSet<IEdge>();
@@ -54,15 +55,22 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
}; };
_text.SetValue(Canvas.LeftProperty, CenterX - DIAMETER / 2); _text.SetValue(Canvas.LeftProperty, CenterX - DIAMETER / 2);
_text.SetValue(Canvas.TopProperty, CenterY - DIAMETER / 2 + 5); _text.SetValue(Canvas.TopProperty, CenterY - DIAMETER / 2 + 5.5);
canvas.Children.Add(_circle); canvas.Children.Add(_circle);
canvas.Children.Add(_text); canvas.Children.Add(_text);
} }
public bool Update(double x, double y, bool down) { public bool IsInside(double x, double y) {
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2; return 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); }
return hover;
public void Update(bool isHovering, bool isPressed) {
_circle?.Fill =
IsLocked && !WantOpen && !IsOpen ? PamhagenBrushes.DimOrange :
IsLocked && !WantOpen && IsOpen ? PamhagenBrushes.Red :
IsLocked && WantOpen && !IsOpen ? PamhagenBrushes.Yellow :
IsLocked && WantOpen && IsOpen ? PamhagenBrushes.Green :
Highlight ?? (isHovering ? Brushes.LightGray : Brushes.DarkGray);
} }
} }
} }
@@ -4,9 +4,10 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PamhagenSysCtrl.Windows" xmlns:local="clr-namespace:PamhagenSysCtrl.Windows"
Title="Schema - Anlagensteuerung Pamhagen" Height="800" Width="1600"> Title="Schema - Anlagensteuerung Pamhagen" Height="900" Width="1600" MinWidth="1500" MinHeight="900">
<Grid MouseMove="SchemeCanvas_MouseMove" MouseLeftButtonDown="SchemeCanvas_MouseLeftButtonDown" MouseLeftButtonUp="SchemeCanvas_MouseLeftButtonUp"> <Grid>
<Canvas x:Name="SchemeCanvas"> <Canvas x:Name="SchemeCanvas" Width="1550" Height="900" VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True"
MouseMove="SchemeCanvas_MouseMove" MouseLeftButtonDown="SchemeCanvas_MouseLeftButtonDown" MouseLeftButtonUp="SchemeCanvas_MouseLeftButtonUp">
</Canvas> </Canvas>
</Grid> </Grid>
</Window> </Window>
@@ -2,15 +2,14 @@
using PamhagenSysCtrl.Helpers.Pipeline; using PamhagenSysCtrl.Helpers.Pipeline;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
namespace PamhagenSysCtrl.Windows { namespace PamhagenSysCtrl.Windows {
public partial class PlantSchemeWindow : Window { public partial class PlantSchemeWindow : Window {
private readonly PamhagenGraph Graph; private readonly PamhagenGraph Graph;
private readonly List<Path> Paths = [];
private ISource? _lastSource; private ISource? _lastSource;
private List<INode> _path = [];
private ISet<INode>? _lastSelected; private ISet<INode>? _lastSelected;
public PlantSchemeWindow() { public PlantSchemeWindow() {
@@ -31,62 +30,80 @@ namespace PamhagenSysCtrl.Windows {
} }
private void SchemeCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs evt) { private void SchemeCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs evt) {
var p = evt.GetPosition(SchemeCanvas); var pos = evt.GetPosition(SchemeCanvas);
var curSelected = UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed); var curSelected = UpdateScheme(pos, evt.LeftButton == MouseButtonState.Pressed);
var clicked = curSelected.Intersect(_lastSelected ?? new HashSet<INode>()).ToList(); var clicked = curSelected.Intersect(_lastSelected ?? new HashSet<INode>()).ToList();
_lastSource?.IsSelected = false;
if (clicked.Count == 0) { if (clicked.Count == 0) {
_lastSource = null; _lastSource = null;
} }
foreach (var c in clicked) { foreach (var c in clicked) {
if (_lastSource != null && c is ISink sink) { if (_lastSource == null && Graph.SelectedPaths.Any(p => p.Start == c)) {
var path = Graph.GetPath(_lastSource, sink, (n) => n is not ISink && (n is not Valve v || !v.IsLocked)); var path = Graph.SelectedPaths.First(p => p.Start == c);
if (path != null) { Graph.RemovePath(path);
Paths.Add(path.Value); } 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) {
Graph.AddPath(path);
_lastSource = null; _lastSource = null;
} }
} 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 if (c is ISource source) { } else if (c is ISource source) {
_lastSource = source; _lastSource = source;
_lastSource.IsSelected = true; _path = [];
} else { } else {
_lastSource = null; _lastSource = null;
} }
if (c is EntryTrough trough) {
trough.IsActive = !trough.IsActive;
} else if (c is Rebler rebler) {
rebler.IsActive = !rebler.IsActive;
} else if (c is EncasedAuger auger) {
auger.IsActive = !auger.IsActive;
} else if (c is ConveyorBelt belt) {
belt.IsActive = !belt.IsActive;
} }
UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed); }
UpdateScheme(pos, evt.LeftButton == MouseButtonState.Pressed);
} }
private ISet<INode> UpdateScheme(Point pos, bool down) { private ISet<INode> UpdateScheme(Point pos, bool down) {
foreach (var e in Graph.Edges) { foreach (var e in Graph.Edges) {
e.Highlight = null; e.Highlight = null;
} }
foreach (var p in Paths) { foreach (var p in Graph.SelectedPaths) {
var c = Brushes.Green; Graph.ColorPipesAdjacientToPath(p, PamhagenBrushes.Green, PamhagenBrushes.DimOrange);
foreach (var (edge, node) in p.Hops) { }
edge.Highlight = Brushes.Green; var hover = Graph.GetHover(pos.X, pos.Y);
if (node is Pump) c = Brushes.Orange; if (_lastSource != null && (hover.Count > 0 || _path.Count > 0)) {
Graph.ColorSubgraph(node, c, (v) => v.IsLocked = true); 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) {
Graph.ColorPipesAdjacientToPath(path, PamhagenBrushes.Green, PamhagenBrushes.DimOrange);
} }
} }
var hover = Graph.Update(pos.X, pos.Y, down); } else if (_lastSource == null && hover.Count > 0 && Graph.SelectedPaths.Any(p => p.Start == hover.First())) {
if (_lastSource != null && hover.Count > 0) { var path = Graph.SelectedPaths.First(p => p.Start == hover.First());
var path = Graph.GetPath(_lastSource, hover.First(), (n) => n is not ISink && (n is not Valve v || !v.IsLocked)); Graph.ColorPipesAdjacientToPath(path, PamhagenBrushes.Red, null);
if (path != null) { }
var c = Brushes.Green; if (_lastSource != null) {
foreach (var (edge, node) in path.Value.Hops) { foreach (var edge in _lastSource.Outputs) {
edge.Highlight = Brushes.Green; edge.Highlight = PamhagenBrushes.Green;
if (node is Pump) c = Brushes.Orange;
Graph.ColorSubgraph(node, c);
} }
} }
Graph.Update(pos.X, pos.Y, down); Graph.Update(hover, down);
}
return hover; return hover;
} }
public void OnUpdate(object? sender, PlantEventArgs evt) { public void OnUpdate(object? sender, PlantEventArgs evt) {
if (sender is not PamhagenPlant plant) return; if (sender is not PamhagenPlant plant) return;
} }
} }
} }