123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- using System.Reflection;
- using System.Windows.Forms;
- using Uestc.Auto6.Dso.Core;
- using Uestc.Auto6.Dso.Core.Decode;
- using Uestc.Auto6.Dso.ComModel;
- using Uni_Trend.MSO7000X.Language;
- using Uni_Trend.MSO7000X.Common.Helper;
- using Uni_Trend.MSO7000X.UserControls;
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using Uni_Trend.MSO7000X.UserControls.Style;
- namespace Uestc.Auto6.Dso.Protocol.MIL
- {
- [System.ComponentModel.ToolboxItem(false)]
- public partial class MILSetControl : UserControl, IProtocolView
- {
- #region 属性定义
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- public MILDecodePrsnt DestinDecodePrsnt
- {
- get => _DestinDecodePrsnt;
- set
- {
- if (_DestinDecodePrsnt != value)
- {
- _DestinDecodePrsnt = value;
- ///当有新的同步目标时,应先将目标中参数同步到本地<see cref="MILDecodePrsnt"/>属性中
- if (DecodePrsnt != null && value != null)
- {
- typeof(MILDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
- {
- x.SetValue(DecodePrsnt, x.GetValue(value));
- });
- }
- }
- }
- }
- private MILDecodePrsnt _DestinDecodePrsnt;
- private MILDecodePrsnt DecodePrsnt => Presenter as MILDecodePrsnt;
- public IProtocolPrsnt Presenter { get; set; }
- #endregion 属性定义
- public MILSetControl()
- {
- InitializeComponent();
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
- Init();
- }
- private void Init()
- {
- GetDestinPrsnt();
- InitPolarity();
- InitRealBiteRate();
- InitSignalRate();
- InitSource();
- InitThreshold();
- UpdateView();
- }
- private void InitSource()
- {
- this.CbxSource.DataSource = ComModel.ChannelIdExt.GetAnalogs().Select(x => new ComboBoxData<ChannelId>(x.ToString(), x)).ToList();
- this.CbxSource.ValueMember = "Value";
- this.CbxSource.DisplayMember = "Key";
- this.CbxSource.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.Source = (ChannelId)this.CbxSource.SelectedValue;
- };
- }
- private void InitThreshold()
- {
- this.BtnThreshold.Click += (sender, args) => SetThreshold();
- }
- private void SetThreshold()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- FloatForm floatForm = new FloatForm();
- floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
- floatForm.BackColor = BackColor;
- floatForm.ForeColor = ForeColor;
- floatForm.Width = 380;
- floatForm.Height = 460 + floatForm.HeadHeight;
- floatForm.Title = "设置门限";
- Uni_Trend.MSO7000X.UserControls.NumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.NumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
- numberKeyboard.Top = floatForm.HeadHeight;
- numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
- numberKeyboard.Width = floatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.DefaultValue = DecodePrsnt.Threshold;
- numberKeyboard.Unit = "V";
- numberKeyboard.MinValue = DecodePrsnt.MinThreshold;
- numberKeyboard.MaxValue = DecodePrsnt.MaxThreshold;
- numberKeyboard.DecimalNumber = 2;
- numberKeyboard.OkClickEvent += (sender, args) =>
- {
- this.DecodePrsnt.Threshold = args.Data;
- floatForm?.Close();
- };
- numberKeyboard.CancelEvent += (sender, args) => floatForm?.Close();
- floatForm.Controls.Add(numberKeyboard);
- DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
- floatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- floatForm.ShowDialogByPosition();
- }
- private void InitPolarity()
- {
- this.RbgPolarity.ButtonItems = Enum.GetValues<ProtocolMIL.Polarity>().Select(x =>
- {
- String key = String.Empty;
- key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
- if (String.IsNullOrEmpty(key))
- {
- key = x.ToString();
- }
- return new RadioButtonItem()
- {
- Tag = x,
- Text = key
- };
- }).ToArray();
- this.RbgPolarity.IndexChanged += (_, _) =>
- {
- DecodePrsnt.Polarity = (ProtocolMIL.Polarity)this.RbgPolarity.ButtonItems[this.RbgPolarity.ChoosedButtonIndex].Tag;
- };
- }
- private void InitSignalRate()
- {
- this.CbxBitRate.DataSource = Enum.GetValues<ProtocolMIL.SignalRate>().Select(x => new KeyValuePair<String, ProtocolMIL.SignalRate>(x switch
- {
- ProtocolMIL.SignalRate.SignalRate_1M => "1Mbps",
- ProtocolMIL.SignalRate.SignalRate_10M => "10Mbps",
- ProtocolMIL.SignalRate.Custom => "Custom",
- _ => "1Mbps",
- }, x)).ToList();
- this.CbxBitRate.ValueMember = "Value";
- this.CbxBitRate.DisplayMember = "Key";
- this.CbxBitRate.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.SignalRate = (ProtocolMIL.SignalRate)this.CbxBitRate.SelectedValue;
- };
- }
- private void InitRealBiteRate()
- {
- this.BtnRealBitRate.Click += (sender, args) => SetBitRate();
- }
- private void SetBitRate()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- FloatForm floatForm = new FloatForm();
- floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
- floatForm.BackColor = BackColor;
- floatForm.ForeColor = ForeColor;
- floatForm.Width = 380;
- floatForm.Height = 460 + floatForm.HeadHeight;
- floatForm.Title = "设置波特率";
- Uni_Trend.MSO7000X.UserControls.NumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.NumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
- numberKeyboard.Top = floatForm.HeadHeight;
- numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
- numberKeyboard.Width = floatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.DefaultValue = DecodePrsnt.RealSignalRate;
- numberKeyboard.Unit = "bps";
- numberKeyboard.MinValue = DecodePrsnt.MinSignalRate;
- numberKeyboard.MaxValue = DecodePrsnt.MaxSignalRate;
- numberKeyboard.DecimalNumber = 2;
- numberKeyboard.OkClickEvent += (sender, args) =>
- {
- this.DecodePrsnt.RealSignalRate = (Int32)args.Data;
- floatForm?.Close();
- };
- numberKeyboard.CancelEvent += (sender, args) => floatForm?.Close();
- floatForm.Controls.Add(numberKeyboard);
- DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
- floatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- floatForm.ShowDialogByPosition();
- }
- /// <summary>
- /// 获取需要同步的Prsnt
- /// 当<see cref="DecodePrsnt"/>为<see cref="null"/>时表示不需要与其他Prsnt进行同步
- /// </summary>
- private void GetDestinPrsnt()
- {
- if (DecodePrsnt == null)
- return;
- if (DecodePrsnt.IsTrigger)
- DestinDecodePrsnt = Presenter.GetChannlesDecodePrsnt().Where(x => x is MILDecodePrsnt).Cast<MILDecodePrsnt>().Where(x => x.Source == DecodePrsnt.Source).OrderBy(x => x.Source).FirstOrDefault();
- else
- {
- if (Presenter.GetTriggerDecodePrsnt() is MILDecodePrsnt rs232decodePrsnt && rs232decodePrsnt.Source == DecodePrsnt.Source)
- DestinDecodePrsnt = rs232decodePrsnt;
- else
- DestinDecodePrsnt = null;
- }
- }
- /// <summary>
- /// 同步两个Prsnt
- /// </summary>
- /// <param name="propertyName">属性名称</param>
- private void DecodeSynchronization(String propertyName)
- {
- if (DestinDecodePrsnt == null)
- return;
- ///由于使用了<see cref="IMILDecodePrsnt.SDA"/>进行判断具体同步的目标
- ///因此<see cref="IMILDecodePrsnt.SDA"/>参数不进行同步
- if (propertyName == nameof(MILDecodePrsnt.Source))
- return;
- if (String.IsNullOrEmpty(propertyName))
- {
- typeof(MILDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
- {
- x.SetValue(DestinDecodePrsnt, x.GetValue(DecodePrsnt));
- });
- }
- else
- {
- PropertyInfo propertyInfo = typeof(MILDecodePrsnt).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
- if (propertyInfo != null && propertyInfo.CanWrite&& propertyInfo.CanRead)
- propertyInfo.SetValue(DestinDecodePrsnt, propertyInfo.GetValue(DecodePrsnt));
- }
- }
-
- public void UpdateView(Object presenter, String propertyName)
- {
- DecodeSynchronization(propertyName);
- if (String.IsNullOrEmpty(propertyName))
- {
- UpdateView();
- return;
- }
- this.GetType()
- .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
- .Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null && x.GetCustomAttribute<UpdatePropertyAttribute>().PropertyName == propertyName)
- .ToList()
- .ForEach(x => x?.Invoke(this, null));
- }
- private void UpdateView()
- {
- this.GetType().GetMethods( BindingFlags.Public| BindingFlags.Instance| BindingFlags.NonPublic).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
- this.Refresh();
- }
- [UpdateProperty(nameof(MILDecodePrsnt.SignalRate))]
- private void UpdateRate()
- {
- this.CbxBitRate.SelectedValue = DecodePrsnt.SignalRate;
- this.LblRealBitRate.Visible = DecodePrsnt.SignalRate == ProtocolMIL.SignalRate.Custom;
- this.BtnRealBitRate.Visible = this.LblRealBitRate.Visible;
- }
- [UpdateProperty(nameof(MILDecodePrsnt.RealSignalRate))]
- private void UpdateRealRate()
- {
- this.BtnRealBitRate.Text = SIHelper.ValueChangeToSI(DecodePrsnt.RealSignalRate, 2, "bps");
- }
- [UpdateProperty(nameof(MILDecodePrsnt.Threshold))]
- private void UpdateThreshold()
- {
- this.BtnThreshold.Text = SIHelper.ValueChangeToSI(DecodePrsnt.Threshold, 2, "V");
- }
- [UpdateProperty(nameof(MILDecodePrsnt.Polarity))]
- private void UpdatePolarity()
- {
- this.RbgPolarity.ChoosedButtonIndex = Enum.GetValues<ProtocolMIL.Polarity>().ToList().FindIndex(x => x == DecodePrsnt.Polarity);
- }
- [UpdateProperty(nameof(MILDecodePrsnt.Source))]
- private void UpdateSource()
- {
- this.CbxSource.SelectedValue = DecodePrsnt.Source;
- GetDestinPrsnt();
- }
- }
- }
|