123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Log;
- using MECF.Framework.Common.OperationCenter;
- namespace MECF.Framework.UI.Client.Ctrlib.UnitControls
- {
- /// <summary>
- /// InputFileNameDialogView.xaml 的交互逻辑
- /// </summary>
- public partial class TVSettingDialogView : UserControl
- {
- public TVSettingDialogView()
- {
- InitializeComponent();
-
-
- }
- public void FocasAll()
- {
- inputBoxPosition.Text = Math.Round(SetPointPosition, 2).ToString();
- if (IsPositionMode)
- {
- inputBoxPosition.Focus();
- inputBoxPosition.SelectAll();
- }
- inputBoxPressure.Text = Math.Round(SetPointPressure, 2).ToString();
- if (IsPressureMode)
- {
- inputBoxPressure.Focus();
- inputBoxPressure.SelectAll();
- }
- }
- /// <summary>
- /// Vilidate input range
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void InputTextBoxPosition_TextChanged(object sender, TextChangedEventArgs e)
- {
- double maxValue = MaxValuePosition;
- var data = this.DataContext as TVSettingDialogViewModel;
- if (data != null)
- {
- maxValue = data.DeviceData.MaxValuePosition;
- }
- double input;
- if (!double.TryParse(inputBoxPosition.Text, out input)) buttonSet.IsEnabled = false;
- else if (input < 0 || input > maxValue) buttonSet.IsEnabled = false;
- else buttonSet.IsEnabled = true;
- inputBoxPosition.Foreground = buttonSet.IsEnabled ?
- System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
- }
- private void InputTextBoxPressure_TextChanged(object sender, TextChangedEventArgs e)
- {
- double maxValue = MaxValuePosition;
- var data = this.DataContext as TVSettingDialogViewModel;
- if (data != null)
- {
- maxValue = data.DeviceData.MaxValuePressure;
- }
- double input;
- if (!double.TryParse(inputBoxPressure.Text, out input)) buttonSet.IsEnabled = false;
- else if (input < 0 || input > maxValue) buttonSet.IsEnabled = false;
- else buttonSet.IsEnabled = true;
- inputBoxPressure.Foreground = buttonSet.IsEnabled ?
- System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
- }
- public static readonly DependencyProperty DeviceNameProperty = DependencyProperty.Register(
- "DeviceName", typeof(string), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty DeviceIdProperty = DependencyProperty.Register(
- "DeviceId", typeof(string), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty MaxValuePositionProperty = DependencyProperty.Register(
- "MaxValuePosition", typeof(double), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty MaxValuePressureProperty = DependencyProperty.Register(
- "MaxValuePressure", typeof(double), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty UnitPositionProperty = DependencyProperty.Register(
- "UnitPosition", typeof(string), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty UnitPressureProperty = DependencyProperty.Register(
- "UnitPressure", typeof(string), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty SetPointPositionProperty = DependencyProperty.Register(
- "SetPointPosition", typeof(double), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty SetPointPressureProperty = DependencyProperty.Register(
- "SetPointPressure", typeof(double), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty FeedbackPositionProperty = DependencyProperty.Register(
- "FeedbackPosition", typeof(double), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty FeedbackPressureProperty = DependencyProperty.Register(
- "FeedbackPressure", typeof(double), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty IsPositionModeProperty = DependencyProperty.Register(
- "IsPositionMode", typeof(bool), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty IsPressureModeProperty = DependencyProperty.Register(
- "IsPressureMode", typeof(bool), typeof(TVSettingDialogView),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public bool IsPercent { get; set; }
- public string DeviceName
- {
- get
- {
- return (string)this.GetValue(DeviceNameProperty);
- }
- set
- {
- if (!string.IsNullOrEmpty(value) && !value.StartsWith("_"))
- value = "_" + value;
- this.SetValue(DeviceNameProperty, value);
- }
- }
- public string DeviceId
- {
- get
- {
- return (string)this.GetValue(DeviceIdProperty);
- }
- set
- {
- this.SetValue(DeviceIdProperty, value);
- }
- }
- public double MaxValuePosition
- {
- get
- {
- return (double)this.GetValue(MaxValuePositionProperty);
- }
- set
- {
- this.SetValue(MaxValuePositionProperty, value);
- }
- }
- public double MaxValuePressure
- {
- get
- {
- return (double)this.GetValue(MaxValuePressureProperty);
- }
- set
- {
- this.SetValue(MaxValuePressureProperty, value);
- }
- }
- public string UnitPosition
- {
- get
- {
- return (string)this.GetValue(UnitPositionProperty);
- }
- set
- {
- this.SetValue(UnitPositionProperty, value);
- }
- }
- public string UnitPressure
- {
- get
- {
- return (string)this.GetValue(UnitPressureProperty);
- }
- set
- {
- this.SetValue(UnitPressureProperty, value);
- }
- }
- public double SetPointPosition
- {
- get
- {
- return (double)this.GetValue(SetPointPositionProperty);
- }
- set
- {
- this.SetValue(SetPointPositionProperty, value);
- }
- }
- public double SetPointPressure
- {
- get
- {
- return (double)this.GetValue(SetPointPressureProperty);
- }
- set
- {
- this.SetValue(SetPointPressureProperty, value);
- }
- }
- public double FeedbackPosition
- {
- get
- {
- return (double)this.GetValue(FeedbackPositionProperty);
- }
- set
- {
- this.SetValue(FeedbackPositionProperty, value);
- }
- }
- public double FeedbackPressure
- {
- get
- {
- return (double)this.GetValue(FeedbackPressureProperty);
- }
- set
- {
- this.SetValue(FeedbackPressureProperty, value);
- }
- }
- public bool IsPositionMode
- {
- get
- {
- return (bool)this.GetValue(IsPositionModeProperty);
- }
- set
- {
- this.SetValue(IsPositionModeProperty, value);
- ckPosition.IsChecked = IsPositionMode;
- }
- }
- public bool IsPressureMode
- {
- get
- {
- return (bool)this.GetValue(IsPressureModeProperty);
- }
- set
- {
- this.SetValue(IsPressureModeProperty, value);
- ckPressure.IsChecked = IsPressureMode;
- }
- }
- public Action<PressureCtrlMode> SetThrottleModeCommandDelegate;
- public Action<double> SetPositionCommandDelegate;
- public Action<double> SetPressureCommandDelegate;
- private void ButtonSet_Click(object sender, RoutedEventArgs e)
- {
- if (IsPressureMode)
- SetPressureCommandDelegate(Convert.ToDouble(inputBoxPressure.Text));
- else if (IsPositionMode)
- SetPositionCommandDelegate(Convert.ToDouble(inputBoxPosition.Text));
- //Close();
- }
- private void OnEnterKeyIsHit(object sender, KeyEventArgs e)
- {
- try
- {
- if (!buttonSet.IsEnabled) return;
- if (e.Key == Key.Return)
- {
- ButtonSet_Click(null, null);
- }
- }
- catch (Exception ex)
- {
- LOG.Error(ex.Message);
- }
- }
-
- private void CkPosition_OnChecked(object sender, RoutedEventArgs e)
- {
- if (IsPositionMode)
- return;
- ckPosition.IsChecked = false;
- try
- {
- if (SetThrottleModeCommandDelegate != null)
- {
- SetThrottleModeCommandDelegate(PressureCtrlMode.TVPositionCtrl);
- }
- var data = this.DataContext as TVSettingDialogViewModel;
- if (data != null)
- {
- InvokeClient.Instance.Service.DoOperation($"{data.DeviceData.Module}.{data.DeviceData.DeviceName}.{AITThrottleValveOperation.SetMode}", PressureCtrlMode.TVPositionCtrl.ToString());
- }
- }
- catch (Exception ex)
- {
- LOG.Error(ex.Message);
- }
- }
- private void SetThrottleModeExecute(PressureCtrlMode value)
- {
- }
- private void SetPressureExecute(double value)
- {
- //InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPressure}", (float)value);
- }
- private void SetPositionExecute(double value)
- {
- //InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITThrottleValveOperation.SetPosition}", (float)value);
- }
- private void CkPressure_OnChecked(object sender, RoutedEventArgs e)
- {
- if (IsPressureMode)
- return;
- ckPressure.IsChecked = false;
- try
- {
- if (SetThrottleModeCommandDelegate != null)
- {
- SetThrottleModeCommandDelegate(PressureCtrlMode.TVPressureCtrl);
- }
- var data = this.DataContext as TVSettingDialogViewModel;
- if (data != null)
- {
- InvokeClient.Instance.Service.DoOperation($"{data.DeviceData.Module}.{data.DeviceData.DeviceName}.{AITThrottleValveOperation.SetMode}", PressureCtrlMode.TVPressureCtrl.ToString());
- }
- }
- catch (Exception ex)
- {
- LOG.Error(ex.Message);
- }
- }
- private void CkPosition_OnClick(object sender, RoutedEventArgs e)
- {
- ckPosition.IsChecked = IsPositionMode;
- }
- private void CkPressure_OnClick(object sender, RoutedEventArgs e)
- {
- ckPressure.IsChecked = IsPressureMode;
- }
- }
- }
-
|