PlantSchemeWindow: Expand graph

This commit is contained in:
2026-07-12 22:26:08 +02:00
parent a3a0504c11
commit 791ee7b804
12 changed files with 129 additions and 25 deletions
+12 -2
View File
@@ -10,10 +10,12 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
}
public Pipe CreatePipe(INode start, INode end) {
public Pipe CreatePipe(INode start, INode end, bool verticalFirst = false) {
Nodes.Add(start);
Nodes.Add(end);
var p = new Pipe(start, end);
var p = new Pipe(start, end, verticalFirst);
start.Outputs.Add(p);
end.Inputs.Add(p);
Edges.Add(p);
return p;
}
@@ -27,5 +29,13 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
}
}
public void Update(double x, double y) {
foreach (var e in Edges) {
e.Update(x, y);
}
foreach (var n in Nodes) {
n.Update(x, y);
}
}
}
}
@@ -8,6 +8,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public bool Orientation { get; }
public void Draw(Canvas canvas);
public bool Update(double x, double y);
}
}
@@ -6,8 +6,11 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public double CenterX { get; }
public double CenterY { get; }
public string Label { get; }
public ISet<IEdge> Inputs { get; }
public ISet<IEdge> Outputs { get; }
public void Draw(Canvas canvas);
public bool Update(double x, double y);
}
}
+4
View File
@@ -56,5 +56,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
canvas.Children.Add(a2);
canvas.Children.Add(b2);
}
public bool Update(double x, double y) {
return false;
}
}
}
@@ -9,9 +9,15 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public double CenterY { get; set; }
public string Label { get; } = "";
public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; }
public PipeJoin(double x, double y) {
CenterX = x;
CenterY = y;
Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>();
}
public void Draw(Canvas canvas) {
@@ -24,5 +30,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
e.SetValue(Canvas.TopProperty, CenterY - 9);
canvas.Children.Add(e);
}
public bool Update(double x, double y) {
return false;
}
}
}
+10
View File
@@ -7,14 +7,24 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public double CenterY { get; set; }
public string Label { get; set; }
public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; }
public Pump(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) {
}
public bool Update(double x, double y) {
return false;
}
}
}
+9
View File
@@ -9,6 +9,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public bool IsFull => CallbackIsFull();
public bool IsFilled => CallbackIsFilled();
public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; }
protected Func<bool> CallbackIsFilled;
protected Func<bool> CallbackIsFull;
@@ -18,10 +21,16 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
Label = label;
CallbackIsFilled = cbFilled;
CallbackIsFull = cbFull;
Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>();
}
public void Draw(Canvas canvas) {
}
public bool Update(double x, double y) {
return false;
}
}
}
@@ -7,6 +7,8 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public double CenterY { get; set; }
public string Label { get; set; }
public bool IsFilled => CallbackIsFilled();
public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; }
protected Func<bool> CallbackIsFilled;
@@ -15,10 +17,16 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
CenterY = y;
Label = label;
CallbackIsFilled = cbFilled;
Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>();
}
public void Draw(Canvas canvas) {
}
public bool Update(double x, double y) {
return false;
}
}
}
+16 -4
View File
@@ -11,29 +11,41 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public bool IsOpen => CallbackIsOpen();
public bool WantOpen => CallbackWantOpen();
public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; }
protected Func<bool> CallbackIsOpen;
protected Func<bool> CallbackWantOpen;
private Ellipse Me;
public Valve(string label, double x, double y, Func<bool> cbOpen, Func<bool> cbWant) {
CenterX = x;
CenterY = y;
Label = label;
CallbackIsOpen = cbOpen;
CallbackWantOpen = cbWant;
Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>();
}
public void Draw(Canvas canvas) {
var e = new Ellipse() {
Me = new Ellipse() {
Height = 20,
Width = 20,
Fill = Brushes.Gray,
Stroke = Brushes.Black,
StrokeThickness = 2,
};
e.SetValue(Canvas.LeftProperty, CenterX - 10);
e.SetValue(Canvas.TopProperty, CenterY - 10);
canvas.Children.Add(e);
Me.SetValue(Canvas.LeftProperty, CenterX - 10);
Me.SetValue(Canvas.TopProperty, CenterY - 10);
canvas.Children.Add(Me);
}
public bool Update(double x, double y) {
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= 10;
Me.Fill = hover ? Brushes.LightGray : Brushes.Gray;
return hover;
}
}
}
+3 -2
View File
@@ -39,6 +39,9 @@ namespace PamhagenSysCtrl {
};
ValvePanel.Children.Add(b);
}
var w = new PlantSchemeWindow();
w.Show();
}
public async void ConnectButton_Click(object? sender, RoutedEventArgs evt) {
@@ -54,8 +57,6 @@ namespace PamhagenSysCtrl {
MessageBox.Show(str, "SPS-Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
var w = new PlantSchemeWindow();
w.Show();
}
public void OnUpdate(object? sender, PlantEventArgs evt) {
@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PamhagenSysCtrl.Windows"
Title="Schema - Anlagensteuerung Pamhagen" Height="450" Width="800">
<Grid>
<Grid MouseMove="SchemeCanvas_MouseMove">
<Canvas x:Name="SchemeCanvas">
</Canvas>
</Grid>
@@ -3,41 +3,77 @@ using PamhagenSysCtrl.Helpers.Pipeline;
using System.Drawing;
using System.Security.Cryptography.X509Certificates;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Windows {
public partial class PlantSchemeWindow : Window {
private readonly Graph Graph;
public PlantSchemeWindow() {
InitializeComponent();
App.Plant?.Update += OnUpdate;
var graph = new Graph();
Graph = new Graph();
var mw1 = new Trough("MW1", 200, 50, () => App.Plant?.FillLevelA1 != FillState.Empty);
var mw2 = new Trough("MW2", 50, 50, () => App.Plant?.FillLevelA1 != FillState.Empty);
var mp1 = new Pump("MP1", 200, 80);
var mp2 = new Pump("MP2", 50, 80);
var x1 = new PipeJoin(200, 100);
var x2 = new PipeJoin(50, 100);
var v1 = new Valve("V1", 200, 150, () => App.Plant?.IsValveOpen(1) ?? false, () => App.Plant?.WantValveOpen(1) ?? false);
var v2 = new Valve("V2", 50, 150, () => App.Plant?.IsValveOpen(2) ?? false, () => App.Plant?.WantValveOpen(2) ?? false);
var v3 = new Valve("V3", 80, 150, () => App.Plant?.IsValveOpen(3) ?? false, () => App.Plant?.WantValveOpen(3) ?? false);
var v4 = new Valve("V4", 170, 150, () => App.Plant?.IsValveOpen(4) ?? false, () => App.Plant?.WantValveOpen(4) ?? false);
Graph.CreatePipe(mw1, mp1);
Graph.CreatePipe(mw2, mp2);
Graph.CreatePipe(mp1, x1);
Graph.CreatePipe(mp2, x2);
graph.CreatePipe(mw1, mp1);
graph.CreatePipe(mw2, mp2);
graph.CreatePipe(mp1, x1);
graph.CreatePipe(mp2, x2);
graph.CreatePipe(x1, v1);
graph.CreatePipe(x1, v4);
graph.CreatePipe(x2, v2);
graph.CreatePipe(x2, v3);
var v1 = CreateValve(1, 200, 150);
var v2 = CreateValve(2, 50, 150);
var v3 = CreateValve(3, 80, 150);
var v4 = CreateValve(4, 170, 150);
graph.Draw(SchemeCanvas);
Graph.CreatePipe(x1, v1);
Graph.CreatePipe(x1, v4);
Graph.CreatePipe(x2, v2);
Graph.CreatePipe(x2, v3);
var x3 = new PipeJoin(200, 180);
var x4 = new PipeJoin(200, 210);
var x5 = new PipeJoin(50, 210);
var x6 = new PipeJoin(50, 240);
Graph.CreatePipe(v1, x3, true);
Graph.CreatePipe(v3, x3, true);
Graph.CreatePipe(x3, x4, true);
Graph.CreatePipe(v2, x5, true);
Graph.CreatePipe(v4, x5, true);
Graph.CreatePipe(x5, x6, true);
var v5 = CreateValve(5, 250, 210);
var v6 = CreateValve(6, 200, 280);
var v7 = CreateValve(7, 125, 240);
var v8 = CreateValve(8, 50, 280);
var v9 = CreateValve(9, 300, 240);
Graph.CreatePipe(x4, v5);
Graph.CreatePipe(x4, v6);
Graph.CreatePipe(x6, v7);
Graph.CreatePipe(x6, v8);
Graph.CreatePipe(v7, v9);
Graph.Draw(SchemeCanvas);
}
private 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);
}
private void SchemeCanvas_MouseMove(object sender, MouseEventArgs evt) {
var p = evt.GetPosition(SchemeCanvas);
Graph.Update(p.X, p.Y);
}
public void OnUpdate(object? sender, PlantEventArgs evt) {