2023-04-13 11:51:03 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Effects;
|
|
|
|
|
using Aitex.Core.Common.DeviceData;
|
|
|
|
|
|
|
|
|
|
namespace Aitex.Core.UI.DeviceControl
|
|
|
|
|
{
|
|
|
|
|
public partial class AITSignalTower : UserControl
|
|
|
|
|
{
|
|
|
|
|
public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
|
2023-12-27 15:12:26 +08:00
|
|
|
|
nameof(DeviceData), typeof(AITSignalTowerData), typeof(AITSignalTower),
|
|
|
|
|
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty BuzzingWarningConfigCommandProperty = DependencyProperty.Register(
|
2023-12-27 15:12:26 +08:00
|
|
|
|
nameof(BuzzingWarningConfigCallback), typeof(Action), typeof(AITSignalTower),
|
2023-04-13 11:51:03 +08:00
|
|
|
|
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.None));
|
|
|
|
|
|
|
|
|
|
public Action BuzzingWarningConfigCallback
|
|
|
|
|
{
|
2023-12-27 15:12:26 +08:00
|
|
|
|
get => (Action)GetValue(BuzzingWarningConfigCommandProperty);
|
|
|
|
|
set => SetValue(BuzzingWarningConfigCommandProperty, value);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AITSignalTowerData DeviceData
|
|
|
|
|
{
|
2023-12-27 15:12:26 +08:00
|
|
|
|
get => (AITSignalTowerData)GetValue(DeviceDataProperty);
|
|
|
|
|
set => SetValue(DeviceDataProperty, value);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-27 15:12:26 +08:00
|
|
|
|
private readonly DropShadowEffect _redLightEffect = new();
|
|
|
|
|
private readonly DropShadowEffect _yellowLightEffect = new();
|
|
|
|
|
private readonly DropShadowEffect _greenLightEffect = new();
|
|
|
|
|
private readonly DropShadowEffect _blueLightEffect = new();
|
|
|
|
|
private readonly DropShadowEffect _buzzerLightEffect = new();
|
2023-04-13 11:51:03 +08:00
|
|
|
|
public double OutLights = 0.2;
|
|
|
|
|
|
|
|
|
|
public AITSignalTower()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-12-27 15:12:26 +08:00
|
|
|
|
_redLightEffect.BlurRadius = 20;
|
|
|
|
|
_redLightEffect.Opacity = 1;
|
|
|
|
|
_redLightEffect.Color = Colors.Red;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
2023-12-27 15:12:26 +08:00
|
|
|
|
_yellowLightEffect.BlurRadius = 20;
|
|
|
|
|
_yellowLightEffect.Opacity = 1;
|
|
|
|
|
_yellowLightEffect.Color = Colors.Yellow;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
2023-12-27 15:12:26 +08:00
|
|
|
|
_greenLightEffect.BlurRadius = 20;
|
|
|
|
|
_greenLightEffect.Opacity = 1;
|
|
|
|
|
_greenLightEffect.Color = Colors.Green;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
2023-12-27 15:12:26 +08:00
|
|
|
|
_blueLightEffect.BlurRadius = 20;
|
|
|
|
|
_blueLightEffect.Opacity = 1;
|
|
|
|
|
_blueLightEffect.Color = Colors.Blue;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
2023-12-27 15:12:26 +08:00
|
|
|
|
_buzzerLightEffect.BlurRadius = 20;
|
|
|
|
|
_buzzerLightEffect.Opacity = 1;
|
|
|
|
|
_buzzerLightEffect.Color = Colors.White;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnRender(DrawingContext drawingContext)
|
|
|
|
|
{
|
|
|
|
|
base.OnRender(drawingContext);
|
|
|
|
|
|
|
|
|
|
if (DeviceData == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (DeviceData.IsRedLightOn)
|
|
|
|
|
{
|
|
|
|
|
if (rectangle1.Opacity != 1)
|
|
|
|
|
{
|
|
|
|
|
rectangle1.Opacity = 1;
|
2023-12-27 15:12:26 +08:00
|
|
|
|
rectangle1.Effect = _redLightEffect;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (rectangle1.Opacity != OutLights)
|
|
|
|
|
{
|
|
|
|
|
rectangle1.Opacity = OutLights;
|
|
|
|
|
rectangle1.Effect = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DeviceData.IsYellowLightOn)
|
|
|
|
|
{
|
|
|
|
|
if (rectangle2.Opacity != 1)
|
|
|
|
|
{
|
|
|
|
|
rectangle2.Opacity = 1;
|
2023-12-27 15:12:26 +08:00
|
|
|
|
rectangle2.Effect = _yellowLightEffect;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (rectangle2.Opacity != OutLights)
|
|
|
|
|
{
|
|
|
|
|
rectangle2.Opacity = OutLights;
|
|
|
|
|
rectangle2.Effect = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DeviceData.IsGreenLightOn)
|
|
|
|
|
{
|
|
|
|
|
if (rectangle3.Opacity != 1)
|
|
|
|
|
{
|
|
|
|
|
rectangle3.Opacity = 1;
|
2023-12-27 15:12:26 +08:00
|
|
|
|
rectangle3.Effect = _greenLightEffect;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (rectangle3.Opacity != OutLights)
|
|
|
|
|
{
|
|
|
|
|
rectangle3.Opacity = OutLights;
|
|
|
|
|
rectangle3.Effect = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DeviceData.IsBlueLightOn)
|
|
|
|
|
{
|
|
|
|
|
if (rectangle4.Opacity != 1)
|
|
|
|
|
{
|
|
|
|
|
rectangle4.Opacity = 1;
|
2023-12-27 15:12:26 +08:00
|
|
|
|
rectangle4.Effect = _blueLightEffect;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (rectangle4.Opacity != OutLights)
|
|
|
|
|
{
|
|
|
|
|
rectangle4.Opacity = OutLights;
|
|
|
|
|
rectangle4.Effect = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-27 15:12:26 +08:00
|
|
|
|
if (DeviceData.IsBuzzerOn || DeviceData.IsBuzzer1On || DeviceData.IsBuzzer2On || DeviceData.IsBuzzer3On ||
|
|
|
|
|
DeviceData.IsBuzzer4On)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
if (rectangle5.Opacity != 1)
|
|
|
|
|
{
|
|
|
|
|
rectangle5.Opacity = 1;
|
2023-12-27 15:12:26 +08:00
|
|
|
|
rectangle5.Effect = _buzzerLightEffect;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (rectangle5.Opacity != OutLights)
|
|
|
|
|
{
|
|
|
|
|
rectangle5.Opacity = OutLights;
|
|
|
|
|
rectangle5.Effect = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void rectangle2_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (BuzzingWarningConfigCallback != null)
|
|
|
|
|
{
|
|
|
|
|
BuzzingWarningConfigCallback.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-27 15:12:26 +08:00
|
|
|
|
|
|
|
|
|
private void TopGrid_OnMouseEnter(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TopGrid.ToolTip = $"Red: {DeviceData.RedLightEvent}\r\n" +
|
|
|
|
|
$"Yellow: {DeviceData.YellowLightEvent}\r\n" +
|
|
|
|
|
$"Green: {DeviceData.GreenLightEvent}\r\n" +
|
|
|
|
|
$"Buzzer: {DeviceData.BuzzerEvent}";
|
|
|
|
|
}
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|