1 parent
1e31dafce5
commit
e626ae1910
3 files changed
+90
-4
No files matched your search
@@ -88,8 +88,8 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var switcher = new Switcher("", rebX, rebY + 12, () => App.Plant?.State.MW1_IsSelected == true ? 1 : App.Plant?.State.MW2_IsSelected == true ? 2 : 0, () => App.Plant?.State.MW1_WantSelected == true ? 1 : App.Plant?.State.MW2_WantSelected == true ? 2 : 0);
|
||||
Nodes.Add(switcher);
|
||||
|
||||
MW1 = new Trough("MW1", mw1X, mpY - 14, () => App.Plant?.State.MW1_FillLevel ?? FillState.Unknown);
|
||||
MW2 = new Trough("MW2", mw2X, mpY - 14, () => App.Plant?.State.MW2_FillLevel ?? FillState.Unknown);
|
||||
MW1 = new Trough("MW1", mw1X, mpY - 14, true, () => App.Plant?.State.MW1_FillLevel ?? FillState.Unknown, () => App.Plant?.State.MW1_Stirrer_IsActive ?? false);
|
||||
MW2 = new Trough("MW2", mw2X, mpY - 14, false, () => App.Plant?.State.MW2_FillLevel ?? FillState.Unknown, () => App.Plant?.State.MW2_Stirrer_IsActive ?? false);
|
||||
MP1 = new Pump("MP1", mw1X, mpY, () => App.Plant?.State.MP1_State ?? default, () => App.Plant?.State.MP1_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
MP2 = new Pump("MP2", mw2X, mpY, () => App.Plant?.State.MP2_State ?? default, () => App.Plant?.State.MP2_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
var x1 = new PipeJoin(mw1X, mpY + 8);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
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 Stirrer {
|
||||
|
||||
public double CenterX { get; set; }
|
||||
public double CenterY { get; set; }
|
||||
public double Radius { get; set; }
|
||||
public bool IsRotatingClockwise { get; set; }
|
||||
|
||||
public bool IsAnimationActive {
|
||||
get => !(_storyboard?.GetIsPaused() ?? true);
|
||||
set {
|
||||
if (_storyboard == null) return;
|
||||
if (value && _storyboard.GetIsPaused()) {
|
||||
_storyboard.Resume();
|
||||
} else if (!value && !_storyboard.GetIsPaused()) {
|
||||
_storyboard.Pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Polyline? _polyline;
|
||||
private Storyboard? _storyboard;
|
||||
private RotateTransform? _transform;
|
||||
private DoubleAnimation? _rotate;
|
||||
|
||||
public Stirrer(double x, double y, double radius, bool clockwise = true) {
|
||||
CenterX = x;
|
||||
CenterY = y;
|
||||
Radius = radius;
|
||||
IsRotatingClockwise = clockwise;
|
||||
}
|
||||
|
||||
public void Draw(Canvas canvas) {
|
||||
_transform = new RotateTransform(0);
|
||||
_polyline = new Polyline() {
|
||||
Stroke = Brushes.Black,
|
||||
RenderTransform = _transform,
|
||||
StrokeLineJoin = PenLineJoin.Round,
|
||||
};
|
||||
|
||||
_rotate = new DoubleAnimation {
|
||||
From = 0,
|
||||
To = IsRotatingClockwise ? 360 : -360,
|
||||
Duration = new Duration(TimeSpan.FromSeconds(4.5)),
|
||||
RepeatBehavior = RepeatBehavior.Forever,
|
||||
};
|
||||
Storyboard.SetTarget(_rotate, _polyline);
|
||||
_storyboard = new Storyboard();
|
||||
_storyboard.Children.Add(_rotate);
|
||||
Storyboard.SetTargetProperty(_rotate, new PropertyPath("RenderTransform.Angle"));
|
||||
canvas.Children.Add(_polyline);
|
||||
_storyboard.Begin();
|
||||
_storyboard.Pause();
|
||||
}
|
||||
|
||||
public void Scale(double scale) {
|
||||
var border = Graph.ToBorder(scale);
|
||||
var dx = Radius * Math.Cos(double.DegreesToRadians(30));
|
||||
var dy = Radius * Math.Sin(double.DegreesToRadians(30));
|
||||
_polyline?.Points = [
|
||||
Graph.ToPx(CenterX, CenterY, scale, round: false),
|
||||
Graph.ToPx(CenterX, CenterY - Radius, scale, round: false), Graph.ToPx(CenterX, CenterY, scale, round: false),
|
||||
Graph.ToPx(CenterX + dx, CenterY + dy, scale, round: false), Graph.ToPx(CenterX, CenterY, scale, round: false),
|
||||
Graph.ToPx(CenterX - dx, CenterY + dy, scale, round: false), Graph.ToPx(CenterX, CenterY, scale, round: false)];
|
||||
_polyline?.StrokeThickness = border * 1.5;
|
||||
_transform?.CenterX = Graph.ToPx(CenterX, scale);
|
||||
_transform?.CenterY = Graph.ToPx(CenterY, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,22 +15,29 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public string Label { get; set; }
|
||||
public FillState FillState => CallbackFillState();
|
||||
public bool IsFilled => FillState != FillState.Empty;
|
||||
public bool IsStirrerActive => CallbackStirrerActive();
|
||||
public ISet<IEdge> Inputs { get; init; }
|
||||
public ISet<IEdge> Outputs { get; init; }
|
||||
|
||||
protected Func<FillState> CallbackFillState;
|
||||
protected Func<bool> CallbackStirrerActive;
|
||||
|
||||
private Shape? _inner;
|
||||
private Shape? _outer;
|
||||
private TextBlock? _text;
|
||||
private Stirrer _stirrer;
|
||||
private readonly bool _stirrerLeft;
|
||||
|
||||
public Trough(string label, double x, double y, Func<FillState> cbFillState) {
|
||||
public Trough(string label, double x, double y, bool stirrerLeft, Func<FillState> cbFillState, Func<bool> cbStirrerActive) {
|
||||
CenterX = x;
|
||||
CenterY = y;
|
||||
Label = label;
|
||||
CallbackFillState = cbFillState;
|
||||
CallbackStirrerActive = cbStirrerActive;
|
||||
Inputs = new HashSet<IEdge>();
|
||||
Outputs = new HashSet<IEdge>();
|
||||
_stirrer = new(x + (stirrerLeft ? -4 : 4), y, 4, stirrerLeft);
|
||||
_stirrerLeft = stirrerLeft;
|
||||
}
|
||||
|
||||
public void Draw(Canvas canvas) {
|
||||
@@ -48,6 +55,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
canvas.Children.Add(_outer);
|
||||
canvas.Children.Add(_inner);
|
||||
canvas.Children.Add(_text);
|
||||
_stirrer.Draw(canvas);
|
||||
}
|
||||
|
||||
public void Scale(double scale) {
|
||||
@@ -62,8 +70,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
_outer?.SetValue(Canvas.TopProperty, (CenterY - HEIGHT / 2) * scale);
|
||||
_inner?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2) * scale + border);
|
||||
_inner?.SetValue(Canvas.TopProperty, (CenterY - HEIGHT / 2) * scale);
|
||||
_text?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2) * scale);
|
||||
_text?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2 + (_stirrerLeft ? 5 : -5)) * scale);
|
||||
_text?.SetValue(Canvas.TopProperty, (CenterY * scale) - 10);
|
||||
_stirrer.Scale(scale);
|
||||
}
|
||||
|
||||
public bool IsInside(double x, double y) {
|
||||
@@ -76,6 +85,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
isHovering ? Brushes.LightGray :
|
||||
Brushes.WhiteSmoke
|
||||
);
|
||||
_stirrer.IsAnimationActive = IsStirrerActive;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user