using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; using Aitex.Core.Common.DeviceData; using Aitex.Core.UI.Control; using Aitex.Core.Util; using MECF.Framework.Common.OperationCenter; using MECF.Framework.UI.Core.Control; using MECF.Framework.UI.Core.ExtendedControls; namespace Aitex.Core.UI.DeviceControl { /// /// TexGasValve.xaml 的交互逻辑 /// public partial class AITGasIIValve : UserControl { // define dependency properties public static readonly DependencyProperty CommandProperty = DependencyProperty.Register( "Command", typeof(ICommand), typeof(AITGasIIValve), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); public ICommand Command { get { return (ICommand)this.GetValue(CommandProperty); } set { this.SetValue(CommandProperty, value); } } public Window AITGasOwner { get; set; } public static readonly DependencyProperty IsSwitchOpenProperty = DependencyProperty.Register( "IsSwitchOpen", typeof(bool), typeof(AITGasIIValve), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); public bool IsSwitchOpen { get { return (bool)this.GetValue(IsSwitchOpenProperty); } set { this.SetValue(IsSwitchOpenProperty, value); } } public BrushConverter _brushconvert = new BrushConverter(); public bool IsVirtualSwitchOpen { get; set; } private SwitchDialog dialog; public static readonly DependencyProperty ValveDisplayNameProperty = DependencyProperty.Register( "ValveDisplayName", typeof(string), typeof(AITGasIIValve), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender)); public string ValveDisplayName { get { return (string)this.GetValue(ValveDisplayNameProperty); } set { this.SetValue(ValveDisplayNameProperty, value); } } public bool IsSim { get { return (bool)this.GetValue(IsSimProperty); } set { this.SetValue(IsSimProperty, value); } } // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc... public static readonly DependencyProperty IsSimProperty = DependencyProperty.Register("IsSim", typeof(bool), typeof(AITGasIIValve), new FrameworkPropertyMetadata(false)); public Visibility MenuVisibility { get { return (Visibility)this.GetValue(MenuVisibilityProperty); } set { this.SetValue(MenuVisibilityProperty, value); } } // Using a DependencyProperty as the backing store for MenuVisibility. This enables animation, styling, binding, etc... public static readonly DependencyProperty MenuVisibilityProperty = DependencyProperty.Register("MenuVisibility", typeof(Visibility), typeof(AITGasIIValve), new FrameworkPropertyMetadata(Visibility.Visible)); public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register( "DeviceData", typeof(AITValveData), typeof(AITGasIIValve), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); public AITValveData DeviceData { get { var data = (AITValveData)this.GetValue(DeviceDataProperty); if (data!=null&&!string.IsNullOrEmpty(data.DisplayName)) { ValveDisplayName = data.DisplayName.Replace("ValveAV",""); } switch (GasStateType) { case GasPanelStateType.Manual: case GasPanelStateType.Monitor: if (data == null) { rdTrig.CLK = data == null; } else { if (data.IsOpen) { rdTrig.CLK = true; } else { rdTrig.CLK = false; } } if (rdTrig.R) { IsSwitchOpen = true; Application.Current.Dispatcher.BeginInvoke(new Action(() => { Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard; sb.Begin(); })); } if (rdTrig.T) { IsSwitchOpen = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard; sb.Begin(); })); } break; case GasPanelStateType.Recipe: rdTrig.CLK = (data == null || data.VirtualFeedback); if (rdTrig.R) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard; sb.Begin(); })); IsVirtualSwitchOpen = true; } if (rdTrig.T) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard; sb.Begin(); })); IsVirtualSwitchOpen = false; } break; default: break; } return data; } set { this.SetValue(DeviceDataProperty, value); } } public static readonly DependencyProperty GasPanelStateTypeProperty = DependencyProperty.Register( "GasStateType", typeof(GasPanelStateType), typeof(AITGasIIValve), new FrameworkPropertyMetadata(GasPanelStateType.Manual, FrameworkPropertyMetadataOptions.AffectsRender)); public GasPanelStateType GasStateType { get { return (GasPanelStateType)this.GetValue(GasPanelStateTypeProperty); } set { this.SetValue(GasPanelStateTypeProperty, value); } } public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register( "ValveOpenOrientation", typeof(LineOrientation), typeof(AITGasIIValve), new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender)); public LineOrientation ValveOpenOrientation { get { return (LineOrientation)GetValue(ValveOpenOrientationProperty); } set { SetValue(ValveOpenOrientationProperty, value); } } public static readonly DependencyProperty IsDisableModeProperty = DependencyProperty.Register( "IsDisableMode", typeof(bool), typeof(AITGasIIValve), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); public bool IsDisableMode { get { return (bool)GetValue(IsDisableModeProperty); } set { SetValue(IsDisableModeProperty, value); } } public bool IsOpen => DeviceData == null || DeviceData.IsOpen; private DispatcherTimer valveTimer = new DispatcherTimer(); RD_TRIG rdTrig = new RD_TRIG(); public AITGasIIValve() { InitializeComponent(); } private BitmapSource GetImage(string name) { return new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/Valve/{0}", name))); } protected override void OnRender(DrawingContext drawingContext) { if (DeviceData != null) { if ((DeviceData.Feedback && (GasStateType == GasPanelStateType.Manual || GasStateType == GasPanelStateType.Monitor)) || (DeviceData.VirtualFeedback && GasStateType == GasPanelStateType.Recipe)) { IsSwitchOpen = true; Application.Current.Dispatcher.BeginInvoke(new Action(() => { Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard; sb.Begin(); })); } else { IsSwitchOpen = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard; sb.Begin(); })); } } if (DeviceData != null) { this.ToolTip = $"Valve Name:{DeviceData.DisplayName} \r\n Device ID:{DeviceData.DeviceSchematicId} \r\n SetPoint:{DeviceData.SetPoint} \r\n SetVirtual:{DeviceData.VirtualFeedback} \r\n Status:{DeviceData.Feedback}"; } base.OnRender(drawingContext); } private void OpenValve(object sender, RoutedEventArgs e) { if (IsDisableMode) return; switch (GasStateType) { case GasPanelStateType.Manual: // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true); break; case GasPanelStateType.Monitor: break; case GasPanelStateType.Recipe: // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", true); break; default: break; } if (Command == null) return; Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, true }); } private void CloseValve(object sender, RoutedEventArgs e) { if (IsDisableMode) return; switch (GasStateType) { case GasPanelStateType.Manual: // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false); break; case GasPanelStateType.Monitor: break; case GasPanelStateType.Recipe: // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", false); break; default: break; } if (Command == null) return; Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, false }); } private void AITGasIIValve_OnLoaded(object sender, RoutedEventArgs e) { imgValveOpen.Source = GetImage(ValveOpenOrientation == LineOrientation.Horizontal ? "ValveOpenVerticalJet.png" : "ValveOpenHorizontalJet.png"); imgValveClose.Source = GetImage(ValveOpenOrientation == LineOrientation.Vertical ? "ValveCloseVerticalJet.png" : "ValveCloseHorizontalJet.png"); if (DeviceData == null || DeviceData.IsOpen) { IsSwitchOpen = true; Application.Current.Dispatcher.BeginInvoke(new Action(() => { Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard; sb.Begin(); })); } else { IsSwitchOpen = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard; sb.Begin(); })); } //valveTimer.Start(); } private void imgValveClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (e.StylusDevice != null) e.Handled = true;//认为误触 else imgValve_TouchUp(sender, null); } private void imgValve_TouchUp(object sender, TouchEventArgs e) { if (IsDisableMode) return; switch (GasStateType) { case GasPanelStateType.Manual: DeviceData.Feedback = !DeviceData.IsOpen; rdTrig.CLK = (DeviceData == null || DeviceData.IsOpen); IsSwitchOpen = DeviceData.Feedback; break; case GasPanelStateType.Monitor: break; case GasPanelStateType.Recipe: IsVirtualSwitchOpen = !IsVirtualSwitchOpen; // InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", IsVirtualSwitchOpen); break; default: break; } if (Command == null) return; // Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, IsVirtualSwitchOpen }); } } }