45 lines
2.0 KiB
C#
45 lines
2.0 KiB
C#
using System.Windows;
|
|
using System.Windows.Media;
|
|
|
|
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
|
public class ControlledValve : Valve {
|
|
|
|
public int Nr { get; set; }
|
|
public override string Label => $"V{Nr}";
|
|
|
|
public readonly ISet<Path> LockedForPaths = new HashSet<Path>();
|
|
public bool IsLocked => LockedForPaths.Any();
|
|
public bool WantOpen => CallbackWantOpen(this);
|
|
|
|
protected Func<Valve, bool> CallbackWantOpen;
|
|
|
|
public ControlledValve(int nr, double x, double y, int orientation, Func<bool> cbOpen, Func<Valve, bool> cbWant) :
|
|
base(x, y, orientation, cbOpen) {
|
|
Nr = nr;
|
|
CallbackWantOpen = cbWant;
|
|
}
|
|
|
|
public override void Update(bool isHovering, bool isPressed) {
|
|
if (App.Plant?.ManualControlMode ?? false) {
|
|
_text?.Visibility = Visibility.Visible;
|
|
_triangles?.Fill =
|
|
!WantOpen && !IsOpen && !isHovering ? PamhagenBrushes.Red :
|
|
!WantOpen && !IsOpen ? PamhagenBrushes.Green :
|
|
!WantOpen && IsOpen ? PamhagenBrushes.DimRed :
|
|
WantOpen && !IsOpen ? PamhagenBrushes.DimGreen :
|
|
WantOpen && IsOpen && !isHovering ? PamhagenBrushes.Green :
|
|
WantOpen && IsOpen ? PamhagenBrushes.Red :
|
|
Highlight ?? (isHovering ? Brushes.LightGray : Brushes.DarkGray);
|
|
} else {
|
|
_text?.Visibility = isHovering ? Visibility.Visible : Visibility.Hidden;
|
|
_triangles?.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);
|
|
}
|
|
}
|
|
}
|
|
}
|