12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397 |
- 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 ScottPlot;
- using ScottPlot.Plottable;
- using Uestc.Auto6.Dso.Core;
- using System.Threading;
- using System.Diagnostics;
- using Uestc.Auto6.Dso.MathExt;
- using Uestc.Auto6.Dso.ComModel;
- using ScottPlot.Renderable;
- using Uestc.Auto6.Dso.Core.Tools;
- using Uni_Trend.MSO7000X.Common.Structs;
- using EventBus;
- using System.Collections.ObjectModel;
- namespace Uestc.Auto6.Dso.U2
- {
- public partial class WaveformFigure : BaseDisplayForm, ITimebaseView, ITriggerView, IDisplayView
- {
- public WaveformFigure()
- {
- InitializeComponent();
- }
- private static readonly Object _ObjectLock = new();
- private System.Windows.Forms.Timer _TimerRefresh = new System.Windows.Forms.Timer();
- private Boolean _IsRefreshing = false;
- private Boolean _IsDraging = false;
- private TimeDomainViewSettingForm _TimeDomainViewSettingForm = null;
- #region WavePlot
- private WavePlot wavePlot;
- private VRIndicationArea _VRIndicationAreaA;
- private VRIndicationArea _VRIndicationAreaB;
- private HTIndicationArea _HTIndicationArea;
- private ZoomRectangleArea zoomRectangleArea;
- public Dictionary<(ChannelId, ChannelId), ZoomRectangleArea> ZoomRectangleAreaDictionary = new Dictionary<(ChannelId, ChannelId), ZoomRectangleArea>();
- //private List<ChannelId> _AnalogWaveIdList = new List<ChannelId>()
- //{
- // ChannelId.C1,
- // ChannelId.C2,
- // ChannelId.C3,
- // ChannelId.C4
- //};
- //private List<ChannelId> _DigitalWaveIdList = new List<ChannelId>()
- //{
- // ChannelId.D1,
- // ChannelId.D2,
- // ChannelId.D3,
- // ChannelId.D4
- //};
- private Dictionary<ChannelId, WavePlot> _WavePlotDictionary = new Dictionary<ChannelId, WavePlot>();
- private Dictionary<ChannelId, VLIndicationArea> _VLIndicationAreaDictionary = new Dictionary<ChannelId, VLIndicationArea>();
- private Dictionary<ChannelId, DigitalWavePlot> _DigitalWavePlotDictionary = new Dictionary<ChannelId, DigitalWavePlot>();
- private Dictionary<ChannelId, VLArrowIndicationArea> _VLArrowIndicationAreaDictionary = new Dictionary<ChannelId, VLArrowIndicationArea>();
- private Dictionary<ChannelId, IPlotBase> _PlotBaseDictionary = new Dictionary<ChannelId, IPlotBase>();
- /// <summary>
- /// 光标层级计算使用
- /// </summary>
- private Dictionary<ChannelId, IndicationArea> _IndicationAreaDictionary = new Dictionary<ChannelId, IndicationArea>();
- /// <summary>
- /// 更新波形
- /// </summary>
- private void DrawWave()
- {
- _IsRefreshing = true;
- AnalogWaveUpdate();
- DigitalWaveUpdate();
- TriggerIndicationAreaUpdate();
- if (_HTIndicationArea != null && _IsDraging == false)
- {
- double position6 = ScottPlotFormControl.Plot.XAxis.Dims.GetPixel(TmbPresenter.PosIndexBymDiv);
- _HTIndicationArea.SetPosition(position6);
- }
- if (_WavePlotDictionary.Count == 0)
- {
- AddWavePlot();
- }
- SetPlotRenderZIndex();
- ////更新通道刻度信息
- //if (Program.Oscilloscope.TryGetChannel(Program.Oscilloscope.FocusId, out IChnlPrsnt focusChannel))
- // ScottPlotFormControl.Plot.ResetChannelParameter((int)(focusChannel as AnalogPrsnt).PosIndex, (focusChannel as AnalogPrsnt).Scale, (focusChannel as AnalogPrsnt).UnitPrefix.ToString(), focusChannel.Unit, Color.FromArgb((Int32)(GridIntensity / 100d * 255), Color.White)/*channel.DrawColor*/);
- ScottPlotFormControl.Plot.ResetTimebaseParameter((Int32)TmbPresenter.PosIndexBymDiv - 5000, TmbPresenter.ScaleByus, TmbPresenter.Prefix.ToString(), TmbPresenter.Unit, Color.FromArgb((Int32)(GridIntensity / 100d * 255), Color.White));
- ScottPlotFormControl.Render(skipIfCurrentlyRendering: true);//未知栈溢出错误,标记栈的可能性较大
-
- _IsRefreshing = false;
- }
- private void TriggerIndicationAreaUpdate()
- {
- if (_VRIndicationAreaA != null && _VRIndicationAreaB != null /*&& _IsDraging == false*/)
- {
- switch (TriggerPrsnt.Type)
- {
- case TriggerType.Edge:
- case TriggerType.PulseWidth:
- case TriggerType.TimeOut:
- case TriggerType.Glitch:
- {
- _VRIndicationAreaB.IsVisible = false;
- if (TrgPresenter is TrigSingleSrcPrsnt trgp)
- {
- if (trgp.Source.IsAnalog() == true)
- {
- _VRIndicationAreaA.IsVisible = true;
- double position1 = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-trgp.RelPosIndex);
- _VRIndicationAreaA.SetPosition(position1);
- }
- else
- {
- _VRIndicationAreaA.IsVisible = false;
- }
- }
- }
- break;
- case TriggerType.Video:
- case TriggerType.Pattern:
- case TriggerType.State:
- case TriggerType.MultiQulified:
- case TriggerType.Serial:
- case TriggerType.SetupHold:
- {
- _VRIndicationAreaA.IsVisible = false;
- _VRIndicationAreaB.IsVisible = false;
- }
- break;
- case TriggerType.Runt:
- case TriggerType.Transition:
- case TriggerType.Window:
- {
- //两个
- if (TrgPresenter is TrigMultiLevelPrsnt trgp)
- {
- if (trgp.Source.IsAnalog() == true)
- {
- _VRIndicationAreaA.IsVisible = true;
- _VRIndicationAreaB.IsVisible = true;
- double positiona = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-trgp.RelPosUpperIndex);
- _VRIndicationAreaA.SetPosition(positiona);
- double positionb = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-trgp.RelPosLowerIndex);
- _VRIndicationAreaB.SetPosition(positionb);
- }
- else
- {
- _VRIndicationAreaA.IsVisible = false;
- _VRIndicationAreaB.IsVisible = false;
- }
- }
- }
- break;
- default:
- break;
- }
- }
- }
- private void DigitalWaveUpdate()
- {
- foreach (var id in ChannelIdExt.GetDigitals())
- {
- if (Program.Oscilloscope.TryGetChannel(id, out IChnlPrsnt ch) && ch.Pack!=null)
- {
- var dch = (DigitalPrsnt)ch;
- if (!_DigitalWavePlotDictionary.ContainsKey(id))
- {
- DigitalWavePlot digitalWavePlot = ScottPlotFormControl.Plot.AddDigitalWave(dch.Pack.Buffer, sampleRate: dch.Pack.Properties.Factor, color: dch.DrawColor/*, label: channel.Label*/);
- digitalWavePlot.IsAfterglowOn = false;
- _DigitalWavePlotDictionary.Add(id, digitalWavePlot);
- _PlotBaseDictionary.Add(id, digitalWavePlot);
- }
- _DigitalWavePlotDictionary[id].IsVisible = dch.Active;
- if (dch.Active == true)
- {
- for (int i = 0; i < dch.BitLength; i++)
- {
- Boolean isactive = dch.GetActiveAt(i);
- _DigitalWavePlotDictionary[id].SetBitActive(i, isactive);
- _DigitalWavePlotDictionary[id].SetBitColor(i, dch.GetColorAt(i));
- VLArrowIndicationArea vlarrowindicationarea = _VLArrowIndicationAreaDictionary[ChannelId.D1 + i];
- vlarrowindicationarea.Color = dch.GetColorAt(i);
- vlarrowindicationarea.Label = dch.GetLabelAt(i);
- vlarrowindicationarea.IsVisible = isactive;
- if (vlarrowindicationarea.PosIndexEnabled == false && isactive == true)
- {
- float offsety = (float)vlarrowindicationarea.GetIndicationValue() - ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-dch.GetPosIndexAt(i)) + vlarrowindicationarea.IndicationImage.Height / 2;
- _DigitalWavePlotDictionary[id].SetBitOffsetY(i, offsety);
- }
- else
- {
- _DigitalWavePlotDictionary[id].SetBitOffsetY(i, 0);
- if (isactive == true)
- {
- vlarrowindicationarea.SetPosition(ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-dch.GetPosIndexAt(i) /** dch.BitHeight*/) - vlarrowindicationarea.IndicationImage.Height / 2);
- }
- }
- }
- //更新数据
- if (dch.Pack != null)
- _DigitalWavePlotDictionary[id].YTs = dch.VuDatabase.Current.Buffer;
- _DigitalWavePlotDictionary[id].SampleRate = dch.Pack.Properties.Factor;
- //更新通道刻度信息
- if (DsoPrsnt.FocusId.IsDigital() == true)
- ScottPlotFormControl.Plot.YAxis.IsVisible = false;
- else if (AxisTickVisible == true)
- {
- ScottPlotFormControl.Plot.YAxis.IsVisible = true;
- }
- }
- else
- {
- for (int i = 0; i < dch.BitLength; i++)
- {
- _VLArrowIndicationAreaDictionary[ChannelId.D1 + i].IsVisible = false;
- }
- }
- }
- }
- }
- private void AnalogWaveUpdate()
- {
- if (_WavePlotDictionary.Count > 3)
- {
- foreach (var id in ChannelIdExt.GetAnalogs())
- {
- if (Program.Oscilloscope.TryGetChannel(id, out IChnlPrsnt channel))
- {
- _WavePlotDictionary[id].IsVisible = channel.Active;
- if (channel.Active == true)
- {
- //更新数据
- //if (channel.Pack != null)
- // _WavePlotDictionary[id].YTs = channel.Pack.Buffer;
- if (channel.VuDatabase.Current != null)
- {
- _WavePlotDictionary[id].YTs = (double[,])channel.VuDatabase.Current.Buffer;
- _WavePlotDictionary[id].SampleRate = channel.VuDatabase.Current.ZoomRatio;
- _WavePlotDictionary[id].OffsetX = channel.VuDatabase.Current.Start;
- }
- //更新通道刻度信息
- if (channel.Id == DsoPrsnt.FocusId)
- {
- ScottPlotFormControl.Plot.ResetChannelParameter((int)(channel as AnalogPrsnt).PosIndexBymDiv, (channel as AnalogPrsnt).ScaleBymV, (channel as AnalogPrsnt).Prefix.ToString(), channel.Unit, Color.FromArgb((Int32)(GridIntensity / 100d * 255), Color.White)/*channel.DrawColor*/);
- if (AxisTickVisible == true)
- {
- ScottPlotFormControl.Plot.YAxis.IsVisible = true;
- }
- }
- if (_VLIndicationAreaDictionary.ContainsKey(id))
- {
- if (_IsDraging == false)
- {
- _VLIndicationAreaDictionary[id].IsVisible = true;
- _VLIndicationAreaDictionary[id].Color = channel.DrawColor;
- _VLIndicationAreaDictionary[id].Label = channel.Label;
- _VLIndicationAreaDictionary[id].SetPosition(ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-(int)(channel as AnalogPrsnt).PosIndexBymDiv));
- }
- if (channel.Id == DsoPrsnt.FocusId)
- {
- if (_VLIndicationAreaDictionary[id].IsMoved)
- {
- _VRIndicationAreaA.IsRenderDottedLine = false;
- _VRIndicationAreaB.IsRenderDottedLine = false;
- }
- else
- {
- _VRIndicationAreaA.IsRenderDottedLine = true;
- _VRIndicationAreaB.IsRenderDottedLine = true;
- }
- }
- }
- List<(ChannelId, ChannelId)> keylist = ZoomRectangleAreaDictionary.Keys.Where((x) => { return x.Item2 == channel.Id; }).ToList();
- foreach (var item in keylist)
- {
- if (ZoomRectangleAreaDictionary.TryGetValue(item, out ZoomRectangleArea zoomRectangleArea) == true)
- {
- zoomRectangleArea.YPosIndexBymDiv = (channel as AnalogPrsnt).PosIndexBymDiv;
- if (item.Item1 == DsoPrsnt.FocusId)
- zoomRectangleArea.IsFocused = true;
- else
- zoomRectangleArea.IsFocused = false;
- if (Program.Oscilloscope.TryGetChannel(item.Item1, out IChnlPrsnt mathchannel))
- {
- double width =(mathchannel as MathPrsnt).Sampling.Scale / TmbPresenter.ScaleByus * Constants.MAX_XPOS_IDX;
- //double start = TmbPresenter.PosIndexBymDiv +(channel.Pack!.Properties.TmbPosition.Index + channel.Pack!.Properties.TmbPosition.Value - (mathchannel as MathPrsnt).Sampling.PosIndexBymDiv) * (mathchannel as MathPrsnt).Sampling.Scale / TmbPresenter.ScaleByus - width / 2;
- double start = channel.Pack!.Properties.TmbPosition.Index + channel.Pack!.Properties.TmbPosition.Value + (channel.Pack!.Properties.TmbPosition.Index + channel.Pack!.Properties.TmbPosition.Value - (mathchannel as MathPrsnt).Sampling.PosIndexBymDiv) * (mathchannel as MathPrsnt).Sampling.Scale / TmbPresenter.ScaleByus - width / 2;
- zoomRectangleArea.SetAreaBoundaryOnly(start,start+width,1,1);
- }
- }
- }
- }
- else
- {
- _VLIndicationAreaDictionary[id].IsVisible = false;
- }
- }
- }
- }
- if (DisplayPresenter.Persist == WfmPersist.Auto)
- ScottPlotFormControl.WfmPersist = WaveFormPersist.Auto;
- else if (DisplayPresenter.Persist == WfmPersist.Infinity)
- ScottPlotFormControl.WfmPersist = WaveFormPersist.Infinity;
- else
- ScottPlotFormControl.WfmPersist = WaveFormPersist.Close;
- }
- /// <summary>
- /// 设置渲染层级
- /// </summary>
- private void SetPlotRenderZIndex()
- {
- if (_PlotBaseDictionary.ContainsKey(DsoPrsnt.FocusId))
- {
- List<KeyValuePair<ChannelId, IPlotBase>> waveplotlist = _PlotBaseDictionary.ToList();
- waveplotlist.Sort((a, b) => { return a.Key > b.Key ? 1 : -1; });
- Int32 index = waveplotlist.Count;
- Int32 currentfocusindex = waveplotlist.FindIndex((a) => { return a.Key == DsoPrsnt.FocusId; });
- for (int i = currentfocusindex; i < waveplotlist.Count; i++)
- {
- waveplotlist[i].Value.ZIndex = index;
- index--;
- }
- for (int j = 0; j < currentfocusindex; j++)
- {
- waveplotlist[j].Value.ZIndex = index;
- index--;
- }
- }
- if (_IndicationAreaDictionary.ContainsKey(DsoPrsnt.FocusId))
- {
- List<KeyValuePair<ChannelId, IndicationArea>> vlindicationarealist = _IndicationAreaDictionary.ToList();
- vlindicationarealist.Sort((a, b) => { return a.Key > b.Key ? 1 : -1; });
- ChannelId currentchannelid = DsoPrsnt.FocusId;
- if (DsoPrsnt.FocusId.IsDigital() == true)
- {
- if (Program.Oscilloscope.TryGetChannel(DsoPrsnt.FocusId, out IChnlPrsnt ch))
- {
- var dch = (DigitalPrsnt)ch;
- currentchannelid = ChannelId.D1 + dch.FocusBitId;
- }
- }
- Int32 index = vlindicationarealist.Count;
- Int32 currentfocusindex = vlindicationarealist.FindIndex((a) => { return a.Key == currentchannelid; });
- for (int i = currentfocusindex; i < vlindicationarealist.Count; i++)
- {
- if (index == vlindicationarealist.Count)
- {
- vlindicationarealist[i].Value.IsFocused = true;
- }
- else
- {
- vlindicationarealist[i].Value.IsFocused = false;
- }
- vlindicationarealist[i].Value.ZIndex = index;
- index--;
- }
- for (int j = 0; j < currentfocusindex; j++)
- {
- vlindicationarealist[j].Value.IsFocused = false;
- vlindicationarealist[j].Value.ZIndex = index;
- index--;
- }
- }
- else
- {
- foreach (var item in _IndicationAreaDictionary)
- {
- item.Value.IsFocused = false;
- }
- }
- foreach (var item in ZoomRectangleAreaDictionary)
- {
- if (item.Key.Item1 == DsoPrsnt.FocusId)
- {
- item.Value.ZIndex = 1;
- }
- else
- {
- item.Value.ZIndex = 0;
- }
- }
- }
- /// <summary>
- /// 配置显示信息
- /// </summary>
- private void ConfigureWavePlot()
- {
- //控件属性配置
- ScottPlotFormControl.Configuration.MiddleClickAutoAxisMarginX = 0;
- ScottPlotFormControl.Configuration.Quality = 0;
- //波形线路名称
- ScottPlot.Renderable.Legend legend = ScottPlotFormControl.Plot.Legend();
- legend.FontColor = Color.Gray;
- legend.OutlineColor = Color.White;
- legend.FillColor = Color.Black;
- ScottPlotFormControl.Plot.AxisAutoX(margin: 0);
- ScottPlotFormControl.Plot.SetAxisLimits(xMin: 0, xMax: 10000, yMin: -5000, yMax: 5000);//初始视阈
- ScottPlotFormControl.Plot.SetViewLimits(xMin: -32768, xMax: 32768, yMin: -10000, yMax: 10000);//视阈限制
- ScottPlotFormControl.Dock = DockStyle.Fill;
- //图形颜色设置
- ScottPlotFormControl.Plot.Style(figureBackground: Color.Transparent, dataBackground: Color.Transparent, grid: Color.Gray, tick: Color.Gray, axisLabel: Color.Gray, titleLabel: Color.Gray);
- //网格属性配置
- ScottPlotFormControl.Plot.Grid(enable: true, color: Color.Gray, lineStyle: LineStyle.Dot);
- ScottPlotFormControl.BackColor = Color.Black;
- ScottPlotFormControl.Plot.ResetChannelParameter(50, 6.6, "", "", Color.White);
- ScottPlotFormControl.Plot.ResetTimebaseParameter(50, 7.7, "", "", Color.White);
- AddWavePlot();
- AddDragArea();
- //AddZoomArea();
- ScottPlotFormControl.PlottableDropped += ScottPlotFormControl_PlottableDropped;
- ScottPlotFormControl.PlottableDragged += ScottPlotFormControl_PlottableDragged;
- ScottPlotFormControl.Plot.RenderEventHandler += ScottPlotFormControlPlot_RenderEventHandler;
- (Program.Oscilloscope.View as DsoForm).RemoveZoomRectangleAreaEventArgs += DsoForm_ZoomRectangleAreaRemoveEventArgs;
- (Program.Oscilloscope.View as DsoForm).AddZoomRectangleAreaEventArgs += DsoForm_AddZoomRectangleAreaEventArgs;
- }
-
- private void DsoForm_ZoomRectangleAreaRemoveEventArgs(object sender, ChannelId e)
- {
- List<(ChannelId, ChannelId)> removekeylist = ZoomRectangleAreaDictionary.Keys.Where((x) => { return x.Item1 == e; }).ToList();
- foreach (var item in removekeylist)
- {
- ZoomRectangleAreaDictionary.Remove(item, out ZoomRectangleArea zoomrectanglearea);
- if (zoomrectanglearea != null)
- {
- ScottPlotFormControl.Plot.Remove(zoomrectanglearea);
- }
- }
- }
- private void ScottPlotFormControlPlot_RenderEventHandler(object sender, (Bitmap bmp, PlotDimensions plotDimensions, bool lowQuality) e)
- {
- CursorApp.Default?.DrawCursor(sender, e);
- MeasureApp.Default?.DrawIndicator(sender, e);
- return;
- //String message = Guid.NewGuid().ToString();
- //using (var gfx = ScottPlot.Drawing.GDI.Graphics(e.bmp, e.plotDimensions, e.lowQuality, false))
- //using (var font = ScottPlot.Drawing.GDI.Font("微软雅黑", 10))
- //using (var fontBrush = new SolidBrush(Color.Black))
- //using (var fillBrush = new SolidBrush(Color.White))
- //using (var borderPen = new Pen(Color.White, 2))
- //{
- // SizeF textSize = ScottPlot.Drawing.GDI.MeasureString(gfx, message, font);
- // float textHeight = textSize.Height;
- // float textWidth = textSize.Width;
- // float textY = 0;
- // textY = e.plotDimensions.DataOffsetY + e.plotDimensions.DataHeight / 2 - textHeight / 2;
- // float textX = 0;
- // textX = e.plotDimensions.DataOffsetX + e.plotDimensions.DataWidth / 2 - textWidth / 2;
- // RectangleF textRect = new RectangleF(textX, textY, textWidth, textHeight);
- // gfx.FillRectangle(fillBrush, textRect);
- // gfx.DrawRectangle(borderPen, Rectangle.Round(textRect));
- // gfx.DrawString(message, font, fontBrush, textX, textY);
- //}
- }
- private void ScottPlotFormControl_PlottableDragged(object sender, EventArgs e)
- {
- if (sender != null && sender is VLArrowIndicationArea vlarrowindicationarea)
- {
- //数字位光标在拖动时,P层PosIndex无效
- vlarrowindicationarea.PosIndexEnabled = false;
- }
- }
- private void ScottPlotFormControl_PlottableDropped(object sender, EventArgs e)
- {
- if (sender != null && sender is VLArrowIndicationArea vlarrowindicationarea)
- {
- //数字位光标拖动结束时,计算位置替换
- if (Program.Oscilloscope.TryGetChannel(ChannelId.D1, out IChnlPrsnt ch))
- {
- var dch = (DigitalPrsnt)ch;
- Int32 curchannelidindex = 0;
- foreach (var item in _VLArrowIndicationAreaDictionary)
- {
- if (item.Value.Equals(vlarrowindicationarea))
- {
- curchannelidindex = item.Key - ChannelId.D1;
- break;
- }
- }
- dch.SetPosIndexAt(curchannelidindex, ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)vlarrowindicationarea.GetIndicationValue()));
- vlarrowindicationarea.PosIndexEnabled = true;
- }
- }
- }
- /// <summary>
- /// 增加模拟波形
- /// </summary>
- private void AddWavePlot()
- {
- foreach (var id in ChannelIdExt.GetAnalogs())
- if (Program.Oscilloscope.TryGetChannel(id, out IChnlPrsnt channel))
- if (channel.Pack != null)
- {
- wavePlot = ScottPlotFormControl.Plot.AddWave(channel.Pack.Buffer, sampleRate: channel.Pack.Properties.Factor, isAfterglowOn: true, channel.DrawColor/*, label: channel.Label*/);
- _WavePlotDictionary.Add(id, wavePlot);
- _PlotBaseDictionary.Add(id, wavePlot);
- }
- }
- /// <summary>
- /// 增加拖拽指示区域
- /// </summary>
- private void AddDragArea()
- {
- PlotDimensions plotDimensions = ScottPlotFormControl.Plot.GetSettings().GetPlotDimensions(0, 0, 1);
- foreach (var item in ChannelIdExt.GetAnalogs())//模拟通道
- {
- VLIndicationArea vLIndicationAreaCH1 = ScottPlotFormControl.Plot.AddVLIndicationArea(plotDimensions, color: Color.Red, label: item.ToString(), name: item.ToString());
- vLIndicationAreaCH1.Margin = (0, 3, 0, 3);
- _VLIndicationAreaDictionary.Add(item, vLIndicationAreaCH1);
- _IndicationAreaDictionary.Add(item, vLIndicationAreaCH1);
- double position0 = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(0);
- vLIndicationAreaCH1.SetPosition(position0);
- vLIndicationAreaCH1.Dragged += (sender, e) =>
- {
- if (Program.Oscilloscope.TryGetChannel(item, out IChnlPrsnt channel))
- {
- (channel as AnalogPrsnt).PosIndexBymDiv = ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)vLIndicationAreaCH1.GetIndicationValue());
- }
- ScottPlotFormControl.ClearWfmCache();//清理无限余晖缓存测试,不影响其他业务
- };
- vLIndicationAreaCH1.MouseDown += (sender, e) =>
- {
- DsoPrsnt.FocusId = item;
- };
- }
- for (int i = 0; i < 16; i++)//数字通道
- {
- VLArrowIndicationArea vlarrowindicationarea = ScottPlotFormControl.Plot.AddVLArrowIndicationArea(plotDimensions, color: Color.Yellow, label: "D" + (i + 1).ToString(), name: "D" + (i + 1).ToString());
- vlarrowindicationarea.IsVisible = false;
- _VLArrowIndicationAreaDictionary.Add(ChannelId.D1 + i, vlarrowindicationarea);
- _IndicationAreaDictionary.Add(ChannelId.D1 + i, vlarrowindicationarea);
- int bitindex = i;
- vlarrowindicationarea.MouseDown += (sender, e) =>
- {
- DsoPrsnt.FocusId = ChannelId.D1;
- if (Program.Oscilloscope.TryGetChannel(DsoPrsnt.FocusId, out IChnlPrsnt ch))
- {
- var dch = (DigitalPrsnt)ch;
- dch.FocusBitId = bitindex;
- }
- };
- }
- _VRIndicationAreaB = ScottPlotFormControl.Plot.AddVRIndicationArea(plotDimensions, color: Color.OrangeRed/*, name: "B"*/); //触发
- _VRIndicationAreaB.Margin = (6, 3, 0, 3);
- _VRIndicationAreaA = ScottPlotFormControl.Plot.AddVRIndicationArea(plotDimensions, color: Color.OrangeRed/*, name: "A"*/); //触发
- _VRIndicationAreaA.Margin = (0, 3, 5, 3);
- _VRIndicationAreaA.ZIndex = 1;
- _HTIndicationArea = ScottPlotFormControl.Plot.AddHTIndicationArea(plotDimensions, color: Color.OrangeRed, name: "T");//时基
- _HTIndicationArea.Margin = (3, 0, 3, 0);
- double position1 = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(0);
- double position2 = ScottPlotFormControl.Plot.XAxis.Dims.GetPixel(5000);
- _VRIndicationAreaA.SetPosition(position1);
- _VRIndicationAreaB.SetPosition(position1);
- _HTIndicationArea.SetPosition(position2);
- _VRIndicationAreaA.Dragged += VRIndicationArea_Dragged;
- _VRIndicationAreaB.Dragged += VRIndicationArea_Dragged;
- _HTIndicationArea.Dragged += (sender, e) =>
- {
- TmbPresenter.PosIndexBymDiv = ScottPlotFormControl.Plot.XAxis.Dims.GetUnit((float)_HTIndicationArea.GetIndicationValue());
- };
- ////设置拖拽指示图片
- //vLIndicationArea.IndicationImage = new Bitmap(19,19);
- //vRIndicationArea.IndicationImage = new Bitmap(19,19);
- //hTIndicationArea.IndicationImage = new Bitmap(19,19);
- }
- private void VRIndicationArea_Dragged(object sender, EventArgs e)
- {
- if (sender is VRIndicationArea vrindicationarea)
- {
- Boolean isdraggedupperarea = true;
- if (vrindicationarea.Equals(_VRIndicationAreaB))
- {
- isdraggedupperarea = false;
- }
- switch (TriggerPrsnt.Type)
- {
- case TriggerType.Edge:
- case TriggerType.PulseWidth:
- case TriggerType.TimeOut:
- case TriggerType.Glitch:
- {
- if (TrgPresenter is TrigSingleSrcPrsnt trgp && isdraggedupperarea == true)
- {
- trgp.RelPosIndex = ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)_VRIndicationAreaA.GetIndicationValue());
- }
- }
- break;
- case TriggerType.Video:
- case TriggerType.Pattern:
- case TriggerType.State:
- case TriggerType.MultiQulified:
- case TriggerType.Serial:
- case TriggerType.SetupHold:
- break;
- case TriggerType.Runt:
- case TriggerType.Transition:
- case TriggerType.Window:
- {
- //两个
- if (TrgPresenter is TrigMultiLevelPrsnt trgp)
- {
- if (isdraggedupperarea == true)
- {
- double posa = ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)_VRIndicationAreaA.GetIndicationValue());
- trgp.RelPosUpperIndex = posa;
- }
- else
- {
- double posb = ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)_VRIndicationAreaB.GetIndicationValue());
- trgp.RelPosLowerIndex = posb;
- }
- }
- }
- break;
- default:
- break;
- }
- }
- }
- private void AddZoomArea()
- {
- PlotDimensions plotDimensions = ScottPlotFormControl.Plot.GetSettings().GetPlotDimensions(0, 0, 1);
- AxisDimensions axisDimensionsX = ScottPlotFormControl.Plot.XAxis.Dims;
- AxisDimensions axisDimensionsY = ScottPlotFormControl.Plot.YAxis.Dims;
- zoomRectangleArea = ScottPlotFormControl.Plot.AddDraggableZoomRectangleArea(plotDimensions, axisDimensionsX, axisDimensionsY, label: "Math1");
- }
- /// <summary>
- /// 增加拓展区域
- /// </summary>
- /// <param name="id"></param>
- /// <param name="channeCcolor"></param>
- /// <param name="idKey"></param>
- /// <param name="zoomunitarea"></param>
- private void AddZoomArea((ChannelId, ChannelId) id, Color channeCcolor, Int64 idKey, (double xLeft, double xRight, double yTop, double yBottom) zoomunitarea, Color labelColor)
- {
- PlotDimensions plotDimensions = ScottPlotFormControl.Plot.GetSettings().GetPlotDimensions(0, 0, 1);
- AxisDimensions axisDimensionsX = ScottPlotFormControl.Plot.XAxis.Dims;
- AxisDimensions axisDimensionsY = ScottPlotFormControl.Plot.YAxis.Dims;
- ZoomRectangleArea zoomRectangle = ScottPlotFormControl.Plot.AddDraggableZoomRectangleArea(plotDimensions, axisDimensionsX, axisDimensionsY, color: channeCcolor, label: id.Item1.ToString(), labelColor: labelColor);
- ZoomRectangleAreaDictionary.Add(id, zoomRectangle);
- }
- #endregion
- #region 创建Zoom
- private void ScottPlotFormControl_ZoomCreated(object sender, EventArgs e)
- {
- isZooming = false;
- ScottPlotFormControl.SetZoomingState(isZooming);
- (double xLeft, double xRight, double yTop, double yBottom) zoomunitarea = ScottPlotFormControl.Plot.GetZoomUnitArea();
- //此操作获取焦点通道的水平、垂直档位,以此为依据创建新的数学通道,通道的数学运算属性为zoom
- //1.垂直档位 = Math.Abs(yTop - yBottom)/10000*focusedchannel.YScale
- //2.水平档位 = Math.Abs(xLeft - xRight)/10000*focusedchannel.XScale
- //3.垂直位移
- //4.水平位移
- ChannelId channelId = ChannelId.C1;
- if (DsoPrsnt.FocusId.IsAnalog() == true)
- {
- channelId = DsoPrsnt.FocusId;
- }
- //5.创建ZoomArea
- (Program.Oscilloscope.View as DsoForm).Presenter.TryGetChannel(channelId, out var prsnt);
- if ((Program.Oscilloscope.View as DsoForm).TryAddMathInfo( MathType.Zoom) && prsnt != null)
- {
- ////此处需要Core公开部分属性的写权限
- (Program.Oscilloscope.View as DsoForm).Presenter.TryGetChannel(DsoPrsnt.FocusId, out var mprsnt);
- AddZoomArea((DsoPrsnt.FocusId, channelId), mprsnt.DrawColor, IdFactory.NextId, zoomunitarea, mprsnt.DrawColor);
- //channel.timebase = Math.Abs(zoomunitarea.xLeft - zoomunitarea.xRight) / 10000 * timebase.Scale;
- //channel.Scale = Math.Abs(zoomunitarea.yTop - zoomunitarea.yBottom) / 10000 * prsnt.YScale;
- }
- //6.属性绑定(AreaUnit,unit边界)
- //7.资源释放 数学通道关闭后,将对应zoom区域清除
- }
- private void DsoForm_AddZoomRectangleAreaEventArgs(object sender, (ChannelId, ChannelId) e)
- {
- if (ZoomRectangleAreaDictionary.ContainsKey(e) == false)
- {
- PlotDimensions plotDimensions = ScottPlotFormControl.Plot.GetSettings().GetPlotDimensions(0, 0, 1);
- AxisDimensions axisDimensionsX = ScottPlotFormControl.Plot.XAxis.Dims;
- AxisDimensions axisDimensionsY = ScottPlotFormControl.Plot.YAxis.Dims;
- if (Program.Oscilloscope.TryGetChannel(e.Item1, out IChnlPrsnt mathchannel))
- {
- ZoomRectangleArea zoomRectangle = ScottPlotFormControl.Plot.AddDraggableZoomRectangleArea(plotDimensions, axisDimensionsX, axisDimensionsY, color: mathchannel.DrawColor);
- ZoomRectangleAreaDictionary.Add(e, zoomRectangle);
- }
- }
- }
- #endregion
- #region 标记
- private VLine _VLine;
- private HLine _HLine;
- private Boolean _IsCursorTracking = false;
- public Boolean IsCursorTracking
- {
- get => _IsCursorTracking;
- set => _IsCursorTracking = value;
- }
- private void ConfigureMouseTracker()
- {
- _VLine = ScottPlotFormControl.Plot.AddVerticalLine(0, Color.Yellow, 1, LineStyle.Dash);
- _HLine = ScottPlotFormControl.Plot.AddHorizontalLine(0, Color.Yellow, 1, LineStyle.Dash);
- }
- private void ScottPlotFormControl_MouseMove(object sender, MouseEventArgs e)
- {
- //#region 鼠标移动,显示最近点的坐标值
- ////// determine point nearest the cursor
- ////(double mouseCoordX, double mouseCoordY) = ScottPlotFormControl.GetMouseCoordinates();
- ////double xyRatio = ScottPlotFormControl.Plot.XAxis.Dims.PxPerUnit / ScottPlotFormControl.Plot.YAxis.Dims.PxPerUnit;
- ////(double pointX, double pointY, int pointIndex) = _MyScatterPlot.GetPointNearest(mouseCoordX, mouseCoordY, xyRatio);
- ////// place the highlight over the point of interest
- ////_HighlightedPoint.Xs[0] = pointX;
- ////_HighlightedPoint.Ys[0] = pointY;
- ////_HighlightedPoint.IsVisible = true;
- ////// render if the highlighted point chnaged
- ////if (_LastHighlightedIndex != pointIndex)
- ////{
- //// _LastHighlightedIndex = pointIndex;
- //// ScottPlotFormControl.Render();
- ////}
- ////// update the GUI to describe the highlighted point
- ////LblShowResult.Text = $"Closest point to ({e.X:N0}, {e.Y:N0}) " +
- //// $"is index {pointIndex} ({pointX:N2}, {pointY:N2})";
- //#endregion
- //#region 线标
- //if (_IsCursorTracking)
- //{
- // _VLine.IsVisible = true;
- // _HLine.IsVisible = true;
- // (double coordinateX, double coordinateY) = ScottPlotFormControl.GetMouseCoordinates();
- // LblShowResult.Text = $"Mouse Pixel ({e.X:0.000}, {e.Y:0.000}) " +
- // $"Coordinate ({coordinateX:0.00000000}, {coordinateY:0.00000000})";
- // _VLine.X = coordinateX;
- // _HLine.Y = coordinateY;
- //}
- //else
- //{
- // _VLine.IsVisible = false;
- // _HLine.IsVisible = false;
- //}
- //#endregion
- }
- #endregion
- #region 窗口显示属性及配置
- /// <summary>
- /// 波形显示风格
- /// </summary>
- public WfmDrawMode DrawMode
- {
- get => DisplayPresenter.DrawMode;
- set => DisplayPresenter.DrawMode = value;
- }
- /// <summary>
- /// 波形亮度
- /// </summary>
- public Int32 WfmIntensity
- {
- get => DisplayPresenter.WfmIntensity;
- set => DisplayPresenter.WfmIntensity = value;
- }
- /// <summary>
- /// 网格风格
- /// </summary>
- public GridType GridStyle
- {
- get => DisplayPresenter.GridStyle;
- set => DisplayPresenter.GridStyle = value;
- }
- /// <summary>
- /// 网格亮度
- /// </summary>
- public Int32 GridIntensity
- {
- get => DisplayPresenter.GridIntensity;
- set => DisplayPresenter.GridIntensity = value;
- }
- /// <summary>
- /// 标记是否可见
- /// </summary>
- public Boolean AxisTickVisible
- {
- get => DisplayPresenter.AxisTickVisible;
- set => DisplayPresenter.AxisTickVisible = value;
- }
- /// <summary>
- /// 水平标记是否显示在下方
- /// </summary>
- public Boolean XAxisTickBottom
- {
- get => DisplayPresenter.XAxisTickBottom;
- set => DisplayPresenter.XAxisTickBottom = value;
- }
- /// <summary>
- /// 垂直标记是否显示在右方
- /// </summary>
- public Boolean YAxisTickRight
- {
- get => DisplayPresenter.YAxisTickRight;
- set => DisplayPresenter.YAxisTickRight = value;
- }
- /// <summary>
- /// 配置波形显示风格
- /// </summary>
- /// <param name="wfmDrawMode"></param>
- private void ConfigDrawMode(WfmDrawMode wfmDrawMode)
- {
- switch (wfmDrawMode)
- {
- case WfmDrawMode.Vector:
- ScottPlotFormControl.Plot.WavePlotStyle(WavePlotLineStyle.Vector);
- break;
- case WfmDrawMode.Dot:
- ScottPlotFormControl.Plot.WavePlotStyle(WavePlotLineStyle.Dot);
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 配置波形亮度
- /// </summary>
- /// <param name="wfmIntensity"></param>
- private void ConfigWfmIntensity(Int32 wfmIntensity)
- {
- ScottPlotFormControl.Plot.WavePlotStyle(wfmIntensity);
- }
- /// <summary>
- /// 配置网格样式
- /// </summary>
- /// <param name="gridType"></param>
- private void ConfigGridStyle(GridType gridType)
- {
- switch (gridType)
- {
- case GridType.Full:
- ScottPlotFormControl.Plot.Grid(enable: true, lineStyle: LineStyle.Dot);
- ScottPlotFormControl.Plot.MinorTickVisible(true);
- break;
- case GridType.Brief:
- ScottPlotFormControl.Plot.Grid(enable: true, lineStyle: LineStyle.Dot);
- ScottPlotFormControl.Plot.MinorTickVisible(false);
- break;
- case GridType.None:
- ScottPlotFormControl.Plot.Grid(enable: false);
- ScottPlotFormControl.Plot.MinorTickVisible(false);
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 配置网格亮度
- /// </summary>
- /// <param name="GridIntensity"></param>
- private void ConfigGridIntensity(Int32 GridIntensity)
- {
- ScottPlotFormControl.Plot.Grid(color: Color.FromArgb((Int32)(GridIntensity / 100d * 255), Color.Gray));
- }
- /// <summary>
- /// 配置水平标记的显示位置
- /// </summary>
- /// <param name="horizontalBottom"></param>
- private void ConfigHorizontalTickLabelDirection(Boolean horizontalBottom = true)
- {
- ScottPlotFormControl.Plot.XAxis.Edge = horizontalBottom == true ? ScottPlot.Renderable.Edge.Bottom : ScottPlot.Renderable.Edge.Top;
- }
- /// <summary>
- /// 配置垂直标记的显示位置
- /// </summary>
- /// <param name="virticalRight"></param>
- private void ConfigVirticalTickLabelDirection(Boolean virticalRight = true)
- {
- ScottPlotFormControl.Plot.YAxis.Edge = virticalRight == true ? ScottPlot.Renderable.Edge.Right : ScottPlot.Renderable.Edge.Left;
- }
- /// <summary>
- /// 配置标记label的显示
- /// </summary>
- /// <param name="visible"></param>
- private void ConfigTickLabelVisible(Boolean visible = true)
- {
- ScottPlotFormControl.Plot.XAxis.IsVisible = visible;
- ScottPlotFormControl.Plot.YAxis.IsVisible = visible;
- }
- private void ToolStripMenuItemTimeWave_Click(object sender, EventArgs e)
- {
- if (_TimeDomainViewSettingForm != null)
- {
- _TimeDomainViewSettingForm.Close();
- }
- _TimeDomainViewSettingForm = new TimeDomainViewSettingForm();
- _TimeDomainViewSettingForm.SetGridComboBoxSelectType(Enum.GetValues<GridType>());
- XAxisTickType xaxisticktype = XAxisTickBottom ? XAxisTickType.Bottom : XAxisTickType.Top;
- YAxisTickType yaxisticktype = YAxisTickRight ? YAxisTickType.Right : YAxisTickType.Left;
- _TimeDomainViewSettingForm.SetMutexButtonModeType(xaxisticktype, yaxisticktype, DrawMode);
- _TimeDomainViewSettingForm.SetParameterValue(TimeEventParameterType.TickIntensity, GridIntensity);
- _TimeDomainViewSettingForm.SetParameterValue(TimeEventParameterType.WFMIntensity, WfmIntensity);
- _TimeDomainViewSettingForm.SetParameterValue(TimeEventParameterType.AxisTick, ScottPlotFormControl.Plot.XAxis.IsVisible);
- _TimeDomainViewSettingForm.ParameterChangedEventHandler += TimeDomainViewSettingForm_ParameterChangedEventHandler;
- if (Program.Oscilloscope.View != null && Program.Oscilloscope.View is DsoForm dsoForm)
- {
- Int32 locationx = (dsoForm.Width - _TimeDomainViewSettingForm.Width) / 2;
- locationx = locationx > 0 ? locationx : 0;
- Int32 locationy = (dsoForm.Height - _TimeDomainViewSettingForm.Height) / 2;
- locationy = locationy > 0 ? locationy : 0;
- //locationx = locationx + dsoForm.Left;
- //locationy = locationy + dsoForm.Top;
- _TimeDomainViewSettingForm.Location = new Point(locationx, locationy);
- }
- _TimeDomainViewSettingForm.Presenter = DisplayPresenter;
- _TimeDomainViewSettingForm.Presenter.TryAddView(_TimeDomainViewSettingForm);
- _TimeDomainViewSettingForm.FormClosed += (sender, e) =>
- {
- _TimeDomainViewSettingForm.ParameterChangedEventHandler -= TimeDomainViewSettingForm_ParameterChangedEventHandler;
- _TimeDomainViewSettingForm = null;
- };
- FormEventArgs formeventargs = new FormEventArgs() { Current = _TimeDomainViewSettingForm, Type = FormType.SettingForm };
- EventBroker.Instance.GetEvent<FormEventArgs>().Publish(this, formeventargs);
- }
- private void TimeDomainViewSettingForm_ParameterChangedEventHandler(TimeEventParameterType type, object obj)
- {
- switch (type)
- {
- case TimeEventParameterType.AxisTick:
- {
- if (obj is Boolean visible)
- {
- AxisTickVisible = visible;
- ConfigTickLabelVisible(visible);
- }
- }
- break;
- case TimeEventParameterType.XAxisTick:
- {
- if (obj is XAxisTickType timeBaseMarkerType)
- {
- XAxisTickBottom = timeBaseMarkerType == XAxisTickType.Bottom;
- ConfigHorizontalTickLabelDirection(timeBaseMarkerType == XAxisTickType.Bottom);
- }
- }
- break;
- case TimeEventParameterType.YAxisTick:
- {
- if (obj is YAxisTickType verticalGearMarkerType)
- {
- YAxisTickRight = verticalGearMarkerType == YAxisTickType.Right;
- ConfigVirticalTickLabelDirection(verticalGearMarkerType == YAxisTickType.Right);
- }
- }
- break;
- case TimeEventParameterType.WFMType:
- if (obj is WfmDrawMode mode)
- {
- DrawMode = mode;
- ConfigDrawMode(DrawMode);
- }
- break;
- case TimeEventParameterType.WFMIntensity:
- if (obj is Int32 int32)
- {
- WfmIntensity = int32;
- ConfigWfmIntensity(WfmIntensity);
- }
- break;
- case TimeEventParameterType.TickType:
- if (obj is GridType value)
- {
- GridStyle = value;
- ConfigGridStyle(GridStyle);
- }
- break;
- case TimeEventParameterType.TickIntensity:
- if (obj is Int32 intensity)
- {
- GridIntensity = intensity;
- ConfigGridIntensity(GridIntensity);
- }
- break;
- default:
- break;
- }
- }
- private void ToolStripMenuItemXY_Click(object sender, EventArgs e)
- {
- XYViewSettingForm xysettingform = new XYViewSettingForm();
- if (Program.Oscilloscope.View != null && Program.Oscilloscope.View is DsoForm dsoForm)
- {
- Int32 locationx = (dsoForm.Width - xysettingform.Width) / 2;
- locationx = locationx > 0 ? locationx : 0;
- Int32 locationy = (dsoForm.Height - xysettingform.Height) / 2;
- locationy = locationy > 0 ? locationy : 0;
- //locationx = locationx + dsoForm.Left;
- //locationy = locationy + dsoForm.Top;
- xysettingform.Location = new Point(locationx, locationy);
- }
- FormEventArgs formeventargs = new FormEventArgs() { Current = xysettingform, Type = FormType.SettingForm };
- EventBroker.Instance.GetEvent<FormEventArgs>().Publish(this, formeventargs);
- }
- private void OnLostFocusClick_FloatForm(object obj, EventArgs e)
- {
- var form = obj as Uni_Trend.MSO7000X.UserControls.FloatForm;
- if (form != null)
- {
- form.Close();
- }
- }
- #endregion
- #region 事件
- private void TimerRefresh_Tick(object sender, EventArgs e)
- {
- if (_IsRefreshing == false)
- {
- DrawWave();
- }
- }
- private void WaveformViewForm_Load(object sender, EventArgs e)
- {
- ConfigureWavePlot();
- ConfigGridIntensity(GridIntensity);
- ConfigGridStyle(GridStyle);
- ConfigWfmIntensity(WfmIntensity);
- ConfigDrawMode(DrawMode);
- ConfigTickLabelVisible(AxisTickVisible);
- ConfigVirticalTickLabelDirection(XAxisTickBottom);
- ConfigHorizontalTickLabelDirection(YAxisTickRight);
- ConfigScottPlotFormControlTouch();
- _TimerRefresh.Interval = 10;
- _TimerRefresh.Tick += TimerRefresh_Tick;
- _TimerRefresh.Enabled = true;
- }
- private void ScottPlotFormControl_MouseDown(object sender, MouseEventArgs e)
- {
- _IsDraging = true;
- }
- private void ScottPlotFormControl_MouseLeave(object sender, EventArgs e)
- {
- _IsDraging = false;
- }
- private void ScottPlotFormControl_MouseUp(object sender, MouseEventArgs e)
- {
- _IsDraging = false;
- }
- private void ScottPlotFormControl_AxesChanged(object sender, EventArgs e)
- {
- //ConfigAxis();
- }
- protected override void OnFormClosed(FormClosedEventArgs e)
- {
- _TimerRefresh.Dispose();
- TmbPresenter.TryRemoveView(this);
- TrgPresenter.TryRemoveView(this);
- base.OnFormClosed(e);
- }
- ~WaveformFigure()
- {
- if (_TimerRefresh != null)
- _TimerRefresh.Dispose();
- }
- #endregion
- #region IDsoView
- public MeasPrsnt MeasurePresenter
- {
- get;
- set;
- }
- public DisplayPrsnt DisplayPresenter
- {
- get;
- set;
- }
- IDisplayPrsnt IView<IDisplayPrsnt>.Presenter
- {
- get => DisplayPresenter;
- set => DisplayPresenter = (DisplayPrsnt)value;
- }
- public TimebasePrsnt TmbPresenter
- {
- get;
- set;
- }
- ITimebasePrsnt IView<ITimebasePrsnt>.Presenter
- {
- get => TmbPresenter;
- set => TmbPresenter = (TimebasePrsnt)value;
- }
- public TriggerPrsnt TrgPresenter
- {
- get;
- set;
- }
- ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
- {
- get => TrgPresenter;
- set => TrgPresenter = (TriggerPrsnt)value;
- }
- public void UpdateView(String propertyName)
- {
- if (String.IsNullOrEmpty(propertyName))
- {
- UpdateView();
- return;
- }
- switch (propertyName)
- {
- //case nameof(TrgPresenter.):
- // break;
- //case nameof(TmbPresenter.Length):
- // break;
- case nameof(TmbPresenter.ScaleByus):
- ScottPlotFormControl.Plot.ResetTimebaseParameter((Int32)TmbPresenter.PositionByus, TmbPresenter.ScaleByus, TmbPresenter.Prefix.ToString(), TmbPresenter.Unit, Color.White);
- break;
- case nameof(TmbPresenter.PositionByus):
- ScottPlotFormControl.Plot.ResetTimebaseParameter((Int32)TmbPresenter.PositionByus, TmbPresenter.ScaleByus, TmbPresenter.Prefix.ToString(), TmbPresenter.Unit, Color.White);
- break;
- }
- }
- protected void UpdateView()
- {
- }
- #endregion
- private Boolean isZooming = false;
- private void uestcIconButton1_MouseDown(object sender, MouseEventArgs e)
- {
- isZooming = !isZooming;
- ScottPlotFormControl.SetZoomingState(isZooming);
- }
- //缩放的累计量集合元组,包含了:水平放大,水平缩小,垂直放大,垂直缩小;
- private (float ZoomInH, float ZoomOutH, float ZoomInV, float ZoomOutV) _ScaleCumulative = (1F, 1F, 1F, 1F);
- /// <summary>
- /// 对波形显示控件的触摸事件进行配置处理;
- /// </summary>
- private void ConfigScottPlotFormControlTouch()
- {
- //处理TouchDown事件
- ScottPlotFormControl.TouchDown += (x, y) =>
- {
- _ScaleCumulative = (1F, 1F, 1F, 1F);
- _IsDraging = true;
- };
- //处理TouchUp事件
- ScottPlotFormControl.TouchUp += (x, y) =>
- {
- _ScaleCumulative = (1F, 1F, 1F, 1F);
- _IsDraging = false;
- };
- //处理TouchScale事件;分水平和垂直方向
- ScottPlotFormControl.TouchScale += (x, y) =>
- {
- switch(y)
- {
- case Uni_Trend.MSO7000X.Touch.ScaleDirection.Horizontal:
- OnScaleHorizontal(x);
- break;
- case Uni_Trend.MSO7000X.Touch.ScaleDirection.Veritcal:
- OnScaleVertical(x);
- break;
- default:// Uni_Trend.MSO7000X.Touch.ScaleDirection.Both
- OnScaleHorizontal(x);
- OnScaleVertical(x);
- break;
- }
- };
- }
- /// <summary>
- /// 处理水平缩放
- /// </summary>
- /// <param name="scale">水平缩放的比例</param>
- private void OnScaleHorizontal(float scale)
- {
- if (scale > 1F)//放大
- {
- _ScaleCumulative.ZoomInH *= scale;
- if (_ScaleCumulative.ZoomInH > 1.25F)
- {
- TmbPresenter.ScaleIndex--;
- _ScaleCumulative.ZoomInH = 1F;
- }
- }
- else//缩小
- {
- _ScaleCumulative.ZoomOutH *= scale;
- if (_ScaleCumulative.ZoomOutH < 0.8F)
- {
- TmbPresenter.ScaleIndex++;
- _ScaleCumulative.ZoomOutH = 1F;
- }
- }
- }
- /// <summary>
- /// 处理垂直缩放
- /// </summary>
- /// <param name="scale">垂直缩放的比例</param>
- private void OnScaleVertical(float scale)
- {
- //找到当前选中通道的P层数据
- AnalogPrsnt channelPrsnt = null;
- if(DsoPrsnt.FocusId.IsAnalog())
- {
- Program.Oscilloscope.TryGetChannel(DsoPrsnt.FocusId, out IChnlPrsnt channel);
- if(channel != null && channel.Active == true)
- {
- channelPrsnt = channel as AnalogPrsnt;
- }
- }
- //波形进行缩放
- if(channelPrsnt != null)
- {
- if (scale > 1F)//放大
- {
- _ScaleCumulative.ZoomInV *= scale;
- if (_ScaleCumulative.ZoomInV > 1.25F)
- {
- channelPrsnt.AnaScaleIndex--;
- _ScaleCumulative.ZoomInV = 1F;
- }
- }
- else//缩小
- {
- _ScaleCumulative.ZoomOutV *= scale;
- if (_ScaleCumulative.ZoomOutV < 0.8F)
- {
- channelPrsnt.AnaScaleIndex++;
- _ScaleCumulative.ZoomOutV = 1F;
- }
- }
- }
- }
-
- }
- }
|