123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Uestc.Auto6.Dso.Core;
- using Uestc.Auto6.Dso.Core.Decode;
- using Uestc.Auto6.Dso.ComModel;
- using Uni_Trend.MSO7000X.Common.Helper;
- using Uni_Trend.MSO7000X.Common.Structs;
- using Uni_Trend.MSO7000X.UserControls;
- using Uni_Trend.MSO7000X.Language;
- namespace Uestc.Auto6.Dso.Protocol.RS232
- {
- [System.ComponentModel.ToolboxItem(false)]
- public partial class RS232TriggerSetControl : UserControl, ITriggerSerialView
- {
- public RS232TriggerSetControl()
- {
- InitializeComponent();
- InitView();
- this.Load += (_, _) =>
- {
- Init();
- this.BtnValue.Click += (_, _) => Action?.Invoke();
- SetControl(Presenter.Conditions);
- this.SizeChanged += (_, _) => SetControl(Presenter.Conditions);
- };
- }
- private void InitView()
- {
- Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
- }
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- private Int32 _RowHeight = 76;
- private void SetControl(ProtocolRS232.Conditions conditions)
- {
- switch (conditions)
- {
- case ProtocolRS232.Conditions.SpecialData:
- DataAutoLayout();
- break;
- case ProtocolRS232.Conditions.PackageEnd:
- EOPAutoLayout();
- break;
- case ProtocolRS232.Conditions.FrameStart:
- case ProtocolRS232.Conditions.CheckError:
- StartAutoLayout();
- break;
- }
- }
- private Action Action;
- private void EditData()
- {
- Boolean lastflag = true;
- if(this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- FloatForm floatForm = new FloatForm();
- floatForm.BackColor = BackColor;
- floatForm.ForeColor = ForeColor;
- floatForm.Title = "设置数据";
- floatForm.Width = 380;
- floatForm.Height = 500 + floatForm.HeadHeight;
- HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
- Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(numberKeyboard, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
- //numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
- //numberKeyboard.Dock = DockStyle.Fill;
- numberKeyboard.Top = floatForm.HeadHeight;
- numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
- numberKeyboard.Width = floatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.MaxValue = 0xFF;
- numberKeyboard.MinValue = 0x00;
- numberKeyboard.ValueType = Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard.HexValueType.Hex;
- numberKeyboard.Value = Presenter.Data;
- numberKeyboard.OkClick += (sender, args) =>
- {
- Presenter.Data = (Char)args.Data;
- this.BtnValue.Text = "0x" + String.Format("{0:X2}", (Int32)Presenter.Data);
- floatForm.Close();
- };
- numberKeyboard.CancelClick += (_, _) => floatForm.Close();
- floatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- floatForm.Controls.Add(numberKeyboard);
- floatForm.ShowDialogByPosition();
- }
- private void EditEOP()
- {
- FloatForm floatForm = new FloatForm();
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- floatForm.BackColor = BackColor;
- floatForm.ForeColor = ForeColor;
- floatForm.Title = "设置EOP";
- floatForm.Width = 380;
- floatForm.Height = 500 + floatForm.HeadHeight;
- HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
- //numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControl(x));
- //numberKeyboard.Dock = DockStyle.Fill;
- numberKeyboard.Top = floatForm.HeadHeight;
- numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
- numberKeyboard.Width = floatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.MaxValue = 0xFF;
- numberKeyboard.MinValue = 0x00;
- numberKeyboard.ValueType = Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard.HexValueType.Hex;
- numberKeyboard.Value = Presenter.EOPChar;
- numberKeyboard.OkClick += (sender, args) =>
- {
- Presenter.EOPChar = (Char)args.Data;
- String charstring = ASCIIConverter.GetASCIIStr(Presenter.EOPChar);
- if(String.IsNullOrEmpty(charstring))
- this.BtnValue.Text = "0x" + String.Format("{0:X2}", (Int32)Presenter.EOPChar);
- else
- this.BtnValue.Text = "0x" + String.Format("{0:X2}({1})", (Int32)Presenter.EOPChar, charstring);
- floatForm.Close();
- };
- numberKeyboard.CancelClick += (_, _) => floatForm.Close();
- floatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- floatForm.Controls.Add(numberKeyboard);
- floatForm.ShowDialogByPosition();
- }
- private void Init()
- {
- SetControl(Presenter.Conditions);
- this.CbxCompare.DataSource = Enum.GetValues<PulseCondition>().Select(x => new KeyValuePair<string, PulseCondition>(x.GetDescription(), x)).ToList();
- this.CbxCompare.DisplayMember = "Key";
- this.CbxCompare.ValueMember = "Value";
- this.CbxCompare.SelectedValueChanged += (sender, args) =>
- {
- if (ParentForm == null)
- return;
- Presenter.Compare = (PulseCondition)this.CbxCompare.SelectedValue;
- };
- this.CbxCompare.SelectedValue = Presenter.Compare;
- }
- public RS232TrigSerialPrsnt Presenter
- {
- get => (RS232TrigSerialPrsnt)(ParentForm as ITriggerView).Presenter;
- set => (ParentForm as ITriggerView).Presenter = value;
- }
- ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
- {
- get => Presenter;
- set => Presenter = (RS232TrigSerialPrsnt)value;
- }
- private void EOPAutoLayout()
- {
- this.LblValue.Text = "结束标志";
- String charstring = ASCIIConverter.GetASCIIStr(Presenter.EOPChar);
- if (String.IsNullOrEmpty(charstring))
- this.BtnValue.Text = "0x" + String.Format("{0:X2}", (Int32)Presenter.EOPChar);
- else
- this.BtnValue.Text = "0x" + String.Format("{0:X2}({1})", (Int32)Presenter.EOPChar, charstring);
- this.LblValue.Visible = true;
- this.BtnValue.Visible = true;
- this.LblCompare.Visible = false;
- this.CbxCompare.Visible = false;
- SetControlPosition(BtnValue, LblValue, 0, 0);
- this.Height = BtnValue.Bottom;
- Visible = true;
- Action = () => EditEOP();
- }
- private void StartAutoLayout()
- {
- this.LblValue.Visible = false;
- this.BtnValue.Visible = false;
- this.CbxCompare.Visible = false;
- this.LblCompare.Visible = false;
- Height = 0;
- Visible = false;
- Action = null;
- }
- private void DataAutoLayout()
- {
- this.LblValue.Text = "数据(Hex)";
- this.BtnValue.Text = "0x" + String.Format("{0:X2}", (Byte)Presenter.Data);
- this.BtnValue.Visible = true;
- this.LblValue.Visible = true;
- this.CbxCompare.Visible = true;
- this.LblCompare.Visible = true;
- SetControlPosition(CbxCompare,LblCompare, 0, 0);
- SetControlPosition(BtnValue,LblValue, 0, 1);
- this.Height = BtnValue.Bottom;
- Visible = true;
- Action = () => EditData();
- }
- private void SetControlPosition<TControl>(TControl control, UestcLabel label, Int32 row = 0, Int32 col = 0) where TControl : Control
- {
- label.Height = label.Font.Height;
- Int32 tempheight = control.Height + label.Height;
- label.Left = Width / 2 * col + 10;
- label.Top = row * _RowHeight + (_RowHeight - tempheight) / 2;
- control.Left = label.Left;
- control.Top = label.Bottom + 6;
- }
- public void UpdateView(Object presenter, String propertyName)
- {
- if(String.IsNullOrEmpty(propertyName))
- {
- UpdateView();
- return;
- }
- switch(propertyName)
- {
- case nameof(RS232TrigSerialPrsnt.Compare):
- if(Presenter.Conditions == ProtocolRS232.Conditions.SpecialData)
- CbxCompare.SelectedValue = Presenter.Compare;
- break;
- case nameof(RS232TrigSerialPrsnt.Data):
- if(Presenter.Conditions == ProtocolRS232.Conditions.SpecialData)
- BtnValue.Text = "0x" + String.Format("{0:X2}", (Byte)Presenter.Data);
-
- break;
- //case nameof(RS232TrigSerialPrsnt.DataIndex):
- // if (Presenter.RS232Conditions == ProtocolRS232.Conditions.SpecialData) CbxDataIndex.SelectedValue = Presenter.DataIndex;
- // break;
- case nameof(RS232TrigSerialPrsnt.EOPChar):
- if(Presenter.Conditions == ProtocolRS232.Conditions.CheckError)
- {
- String charstring = ASCIIConverter.GetASCIIStr(Presenter.EOPChar);
- if (String.IsNullOrEmpty(charstring))
- this.BtnValue.Text = "0x" + String.Format("{0:X2}", (Int32)Presenter.EOPChar);
- else
- this.BtnValue.Text = "0x" + String.Format("{0:X2}({1})", (Int32)Presenter.EOPChar, charstring);
- }
- break;
- case nameof(RS232TrigSerialPrsnt.Conditions):
- SetControl(Presenter.Conditions);
- break;
- default:
- break;
- }
- }
- private void UpdateView()
- {
- }
- }
- }
|