Add PlantSchemeWindow

This commit is contained in:
2026-07-10 16:15:15 +02:00
parent ac2eafc8c6
commit a3a0504c11
16 changed files with 350 additions and 4 deletions
+16 -3
View File
@@ -9,7 +9,7 @@ namespace PamhagenSysCtrl.Helpers {
protected bool IsRunning = true;
protected Thread? BackgroundThread;
public event EventHandler<EventArgs>? Update;
public event EventHandler<PlantEventArgs>? Update;
protected bool ActuatorsChanged = false;
protected PamhagenPlc.ActuatorStates Actuators;
@@ -48,13 +48,14 @@ namespace PamhagenSysCtrl.Helpers {
public bool IsBeltActive => Actuators.Belt;
public bool IsAuger1Active => Actuators.Auger1;
public bool IsAuger2Active => Actuators.Auger2;
public bool IsWasteDisposalActive => IsBeltActive || IsAuger1Active || IsAuger2Active;
public bool IsGradationPumpActive => Actuators.GradationPump;
public PamhagenPlant(string portName) {
Plc = new(portName);
}
protected virtual void RaiseUpdateEvent(EventArgs evt) {
protected virtual void RaiseUpdateEvent(PlantEventArgs evt) {
App.MainDispatcher.BeginInvoke(() => Update?.Invoke(this, evt));
}
@@ -81,7 +82,7 @@ namespace PamhagenSysCtrl.Helpers {
ActuatorsChanged = false;
}
Sensors = await Plc.ReadInputs();
RaiseUpdateEvent(EventArgs.Empty);
RaiseUpdateEvent(new());
} catch (Exception exc) {
var str = "Bei der SPS ist ein Fehler aufgetreten:\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
@@ -220,6 +221,18 @@ namespace PamhagenSysCtrl.Helpers {
Actuators.Auger2 = false;
}
public void StartWasteDisposal() {
StartBelt();
StartAuger1();
StartAuger2();
}
public void StopWasteDisposal() {
StopBelt();
StopAuger1();
StopAuger2();
}
public void StartGradationPump() {
Actuators.GradationPump = true;
}
+31
View File
@@ -0,0 +1,31 @@
using System.Windows.Controls;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class Graph {
protected HashSet<INode> Nodes = [];
protected HashSet<IEdge> Edges = [];
public Graph() {
}
public Pipe CreatePipe(INode start, INode end) {
Nodes.Add(start);
Nodes.Add(end);
var p = new Pipe(start, end);
Edges.Add(p);
return p;
}
public void Draw(Canvas canvas) {
foreach (var e in Edges) {
e.Draw(canvas);
}
foreach (var n in Nodes) {
n.Draw(canvas);
}
}
}
}
+13
View File
@@ -0,0 +1,13 @@
using System.Windows.Controls;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public interface IEdge {
public INode Start { get; }
public INode End { get; }
public bool Orientation { get; }
public void Draw(Canvas canvas);
}
}
+13
View File
@@ -0,0 +1,13 @@
using System.Windows.Controls;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public interface INode {
public double CenterX { get; }
public double CenterY { get; }
public string Label { get; }
public void Draw(Canvas canvas);
}
}
@@ -0,0 +1,5 @@
namespace PamhagenSysCtrl.Helpers.Pipeline {
public interface ISink : INode {
public bool IsFull { get; }
}
}
@@ -0,0 +1,5 @@
namespace PamhagenSysCtrl.Helpers.Pipeline {
public interface ISource : INode {
public bool IsFilled { get; }
}
}
+60
View File
@@ -0,0 +1,60 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class Pipe : IEdge {
public INode Start { get; set; }
public INode End { get; set; }
public bool Orientation { get; set; }
public Pipe(INode start, INode end, bool orientation = false) {
Start = start;
End = end;
Orientation = orientation;
}
public void Draw(Canvas canvas) {
var x1 = Start.CenterX;
var y1 = Start.CenterY;
var x2 = Orientation ? Start.CenterX : End.CenterX;
var y2 = Orientation ? End.CenterY : Start.CenterY;
var x3 = End.CenterX;
var y3 = End.CenterY;
var a1 = new Line() {
X1 = x1, Y1 = y1, X2 = x2, Y2 = y2,
StrokeThickness = 10,
Stroke = Brushes.Black,
StrokeStartLineCap = PenLineCap.Square,
StrokeEndLineCap = PenLineCap.Square,
};
var a2 = new Line() {
X1 = x1, Y1 = y1, X2 = x2, Y2 = y2,
StrokeThickness = 6,
Stroke = Brushes.Gray,
StrokeStartLineCap = PenLineCap.Square,
StrokeEndLineCap = PenLineCap.Square,
};
var b1 = new Line() {
X1 = x2, Y1 = y2, X2 = x3, Y2 = y3,
StrokeThickness = 10,
Stroke = Brushes.Black,
StrokeStartLineCap = PenLineCap.Square,
StrokeEndLineCap = PenLineCap.Square,
};
var b2 = new Line() {
X1 = x2, Y1 = y2, X2 = x3, Y2 = y3,
StrokeThickness = 6,
Stroke = Brushes.Gray,
StrokeStartLineCap = PenLineCap.Square,
StrokeEndLineCap = PenLineCap.Square,
};
canvas.Children.Add(a1);
canvas.Children.Add(b1);
canvas.Children.Add(a2);
canvas.Children.Add(b2);
}
}
}
@@ -0,0 +1,28 @@
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class PipeJoin : INode {
public double CenterX { get; set; }
public double CenterY { get; set; }
public string Label { get; } = "";
public PipeJoin(double x, double y) {
CenterX = x;
CenterY = y;
}
public void Draw(Canvas canvas) {
var e = new Rectangle() {
Height = 18,
Width = 18,
Fill = Brushes.Black,
};
e.SetValue(Canvas.LeftProperty, CenterX - 9);
e.SetValue(Canvas.TopProperty, CenterY - 9);
canvas.Children.Add(e);
}
}
}
+20
View File
@@ -0,0 +1,20 @@
using System.Windows.Controls;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class Pump : INode {
public double CenterX { get; set; }
public double CenterY { get; set; }
public string Label { get; set; }
public Pump(string label, double x, double y) {
CenterX = x;
CenterY = y;
Label = label;
}
public void Draw(Canvas canvas) {
}
}
}
+27
View File
@@ -0,0 +1,27 @@
using System.Windows.Controls;
namespace PamhagenSysCtrl.Helpers.Pipeline {
class Tank : INode, ISink, ISource {
public double CenterX { get; set; }
public double CenterY { get; set; }
public string Label { get; set; }
public bool IsFull => CallbackIsFull();
public bool IsFilled => CallbackIsFilled();
protected Func<bool> CallbackIsFilled;
protected Func<bool> CallbackIsFull;
public Tank(string label, double x, double y, Func<bool> cbFilled, Func<bool> cbFull) {
CenterX = x;
CenterY = y;
Label = label;
CallbackIsFilled = cbFilled;
CallbackIsFull = cbFull;
}
public void Draw(Canvas canvas) {
}
}
}
@@ -0,0 +1,24 @@
using System.Windows.Controls;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class Trough : INode, ISource {
public double CenterX { get; set; }
public double CenterY { get; set; }
public string Label { get; set; }
public bool IsFilled => CallbackIsFilled();
protected Func<bool> CallbackIsFilled;
public Trough(string label, double x, double y, Func<bool> cbFilled) {
CenterX = x;
CenterY = y;
Label = label;
CallbackIsFilled = cbFilled;
}
public void Draw(Canvas canvas) {
}
}
}
+39
View File
@@ -0,0 +1,39 @@
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class Valve : INode {
public double CenterX { get; set; }
public double CenterY { get; set; }
public string Label { get; set; }
public bool IsOpen => CallbackIsOpen();
public bool WantOpen => CallbackWantOpen();
protected Func<bool> CallbackIsOpen;
protected Func<bool> CallbackWantOpen;
public Valve(string label, double x, double y, Func<bool> cbOpen, Func<bool> cbWant) {
CenterX = x;
CenterY = y;
Label = label;
CallbackIsOpen = cbOpen;
CallbackWantOpen = cbWant;
}
public void Draw(Canvas canvas) {
var e = 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);
}
}
}
@@ -0,0 +1,3 @@
namespace PamhagenSysCtrl.Helpers {
public class PlantEventArgs : EventArgs { }
}