| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 | 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{    /// <summary>    /// TexGasValve.xaml 的交互逻辑    /// </summary>    public partial class AITGasValve : UserControl    {        // define dependency properties        public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(                      "Command", typeof(ICommand), typeof(AITGasValve),                      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 bool IsSwitchOpen { get; set; }        public BrushConverter _brushconvert = new BrushConverter();        public bool IsVirtualSwitchOpen { get; set; }        private SwitchDialog dialog;        private string _valveDisplayName = "";        public string ValveDisplayName        {            get => _valveDisplayName;            set            {                _valveDisplayName = 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(AITGasValve),                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(AITGasValve),                new FrameworkPropertyMetadata(Visibility.Visible));        public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(                        "DeviceData", typeof(AITValveData), typeof(AITGasValve),                        new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));        public AITValveData DeviceData        {            get            {                var data = (AITValveData)this.GetValue(DeviceDataProperty);                switch (GasStateType)                {                    case GasPanelStateType.Manual:                    case GasPanelStateType.Monitor:                        rdTrig.CLK = (data == null || data.IsOpen);                        if (rdTrig.R)                        {                            if (data.ILKDiValue)                            {                                ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");                                Application.Current.Dispatcher.BeginInvoke(new Action(() =>                                {                                    Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;                                    sb.Begin();                                }));                            }                            else                            {                                ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");                                Application.Current.Dispatcher.BeginInvoke(new Action(() =>                                {                                    Storyboard sb = this.FindResource("FlickerValveStoryBoard") as Storyboard;                                    sb.Begin();                                }));                            }                        }                        if (rdTrig.T)                        {                            ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");                            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)                        {                            ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>                            {                                Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;                                sb.Begin();                            }));                            IsVirtualSwitchOpen = true;                        }                        if (rdTrig.T)                        {                            ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");                            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(AITGasValve),           new FrameworkPropertyMetadata(GasPanelStateType.Manual, FrameworkPropertyMetadataOptions.AffectsRender));        public GasPanelStateType GasStateType        {            get            {                return (GasPanelStateType)this.GetValue(GasPanelStateTypeProperty);            }            set            {                this.SetValue(GasPanelStateTypeProperty, value);            }        }        public bool IsShowSwitchDialog        {            get { return (bool)GetValue(IsShowSwitchDialogProperty); }            set { SetValue(IsShowSwitchDialogProperty, value); }        }        // Using a DependencyProperty as the backing store for IsShowSwitchDialog.  This enables animation, styling, binding, etc...        public static readonly DependencyProperty IsShowSwitchDialogProperty =            DependencyProperty.Register("IsShowSwitchDialog", typeof(bool), typeof(AITGasValve), new PropertyMetadata(false));        public static readonly DependencyProperty DeviceData2Property = DependencyProperty.Register(                "DeviceData2", typeof(AITValveData), typeof(AITGasValve),                new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));        public AITValveData DeviceData2        {            get            {                return (AITValveData)this.GetValue(DeviceData2Property);            }            set            {                this.SetValue(DeviceData2Property, value);            }        }        public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(    "ValveOpenOrientation", typeof(LineOrientation), typeof(AITGasValve),    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(AITGasValve),    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();        RD_TRIG flickerTrig = new RD_TRIG();        public AITGasValve()        {            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)        {            var data = (AITValveData)this.GetValue(DeviceDataProperty);            if (data != null)            {                ValveName.Text = DeviceData.DisplayName.Replace("ValveAV", "");                if ((DeviceData.SetPoint && GasStateType == GasPanelStateType.Manual) || (DeviceData.Feedback && GasStateType == GasPanelStateType.Monitor)               || (DeviceData.VirtualFeedback && GasStateType == GasPanelStateType.Recipe))                {                    if (!DeviceData.ILKDiValue && !(GasStateType == GasPanelStateType.Recipe))                    {                        ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>                        {                            Storyboard sb = this.FindResource("FlickerValveStoryBoard") as Storyboard;                            sb.Begin();                        }));                    }                    else if (DeviceData.ILKDiValue && !DeviceData.Feedback && !(GasStateType == GasPanelStateType.Recipe))                    {                        ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>                        {                            Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;                            sb.Begin();                        }));                    }                    else                    {                        ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>                        {                            Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;                            sb.Begin();                        }));                    }                }                else                {                    ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>                    {                        Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;                        sb.Begin();                    }));                }                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}";            }            else            {                ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");                Application.Current.Dispatcher.BeginInvoke(new Action(() =>                            {                                Storyboard sb = this.FindResource("CloseValveStoryBoard") as Storyboard;                                sb.Begin();                            }));            }            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:                //InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);                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:                //InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);                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 AITGasValve_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)        {            ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("White");            Application.Current.Dispatcher.BeginInvoke(new Action(() =>            {                Storyboard sb = this.FindResource("OpenValveStoryBoard") as Storyboard;                sb.Begin();            }));        }        else        {            ValveName.Foreground = (Brush)_brushconvert.ConvertFromString("Black");            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 (IsShowSwitchDialog)        {            dialog = new SwitchDialog { };            dialog.IsOpen = GasStateType == GasPanelStateType.Recipe ? IsVirtualSwitchOpen : IsSwitchOpen;            dialog.Owner = AITGasOwner;            dialog.Topmost = true;            dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;            dialog.DeviceName = "Valve Name: " + DeviceData.DeviceName.Replace("Valve", "");            dialog.ShowDialog();            if ((bool)dialog.IsSave)            {                switch (GasStateType)                {                    case GasPanelStateType.Manual:                        IsSwitchOpen = dialog.IsOpen;                        InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", dialog.IsOpen);                        break;                    case GasPanelStateType.Monitor:                        break;                    case GasPanelStateType.Recipe:                        IsVirtualSwitchOpen = dialog.IsOpen;                        InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVVirtualTurnValve}", dialog.IsOpen);                        break;                    default:                        break;                }            }            if (Command == null)                return;            Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVVirtualTurnValve, IsVirtualSwitchOpen });        }        else        {            if (IsDisableMode) return;            switch (GasStateType)            {                case GasPanelStateType.Manual:                    IsSwitchOpen = !IsSwitchOpen;                    InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", IsSwitchOpen);                    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 });        }    }}}
 |