WaveformFigure.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using ScottPlot;
  11. using ScottPlot.Plottable;
  12. using Uestc.Auto6.Dso.Core;
  13. using System.Threading;
  14. using System.Diagnostics;
  15. using Uestc.Auto6.Dso.MathExt;
  16. using Uestc.Auto6.Dso.ComModel;
  17. using ScottPlot.Renderable;
  18. using Uestc.Auto6.Dso.Core.Tools;
  19. using Uni_Trend.MSO7000X.Common.Structs;
  20. using EventBus;
  21. using System.Collections.ObjectModel;
  22. namespace Uestc.Auto6.Dso.U2
  23. {
  24. public partial class WaveformFigure : BaseDisplayForm, ITimebaseView, ITriggerView, IDisplayView
  25. {
  26. public WaveformFigure()
  27. {
  28. InitializeComponent();
  29. }
  30. private static readonly Object _ObjectLock = new();
  31. private System.Windows.Forms.Timer _TimerRefresh = new System.Windows.Forms.Timer();
  32. private Boolean _IsRefreshing = false;
  33. private Boolean _IsDraging = false;
  34. private TimeDomainViewSettingForm _TimeDomainViewSettingForm = null;
  35. #region WavePlot
  36. private WavePlot wavePlot;
  37. private VRIndicationArea _VRIndicationAreaA;
  38. private VRIndicationArea _VRIndicationAreaB;
  39. private HTIndicationArea _HTIndicationArea;
  40. private ZoomRectangleArea zoomRectangleArea;
  41. public Dictionary<(ChannelId, ChannelId), ZoomRectangleArea> ZoomRectangleAreaDictionary = new Dictionary<(ChannelId, ChannelId), ZoomRectangleArea>();
  42. //private List<ChannelId> _AnalogWaveIdList = new List<ChannelId>()
  43. //{
  44. // ChannelId.C1,
  45. // ChannelId.C2,
  46. // ChannelId.C3,
  47. // ChannelId.C4
  48. //};
  49. //private List<ChannelId> _DigitalWaveIdList = new List<ChannelId>()
  50. //{
  51. // ChannelId.D1,
  52. // ChannelId.D2,
  53. // ChannelId.D3,
  54. // ChannelId.D4
  55. //};
  56. private Dictionary<ChannelId, WavePlot> _WavePlotDictionary = new Dictionary<ChannelId, WavePlot>();
  57. private Dictionary<ChannelId, VLIndicationArea> _VLIndicationAreaDictionary = new Dictionary<ChannelId, VLIndicationArea>();
  58. private Dictionary<ChannelId, DigitalWavePlot> _DigitalWavePlotDictionary = new Dictionary<ChannelId, DigitalWavePlot>();
  59. private Dictionary<ChannelId, VLArrowIndicationArea> _VLArrowIndicationAreaDictionary = new Dictionary<ChannelId, VLArrowIndicationArea>();
  60. private Dictionary<ChannelId, IPlotBase> _PlotBaseDictionary = new Dictionary<ChannelId, IPlotBase>();
  61. /// <summary>
  62. /// 光标层级计算使用
  63. /// </summary>
  64. private Dictionary<ChannelId, IndicationArea> _IndicationAreaDictionary = new Dictionary<ChannelId, IndicationArea>();
  65. /// <summary>
  66. /// 更新波形
  67. /// </summary>
  68. private void DrawWave()
  69. {
  70. _IsRefreshing = true;
  71. AnalogWaveUpdate();
  72. DigitalWaveUpdate();
  73. TriggerIndicationAreaUpdate();
  74. if (_HTIndicationArea != null && _IsDraging == false)
  75. {
  76. double position6 = ScottPlotFormControl.Plot.XAxis.Dims.GetPixel(TmbPresenter.PosIndexBymDiv);
  77. _HTIndicationArea.SetPosition(position6);
  78. }
  79. if (_WavePlotDictionary.Count == 0)
  80. {
  81. AddWavePlot();
  82. }
  83. SetPlotRenderZIndex();
  84. ////更新通道刻度信息
  85. //if (Program.Oscilloscope.TryGetChannel(Program.Oscilloscope.FocusId, out IChnlPrsnt focusChannel))
  86. // 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*/);
  87. ScottPlotFormControl.Plot.ResetTimebaseParameter((Int32)TmbPresenter.PosIndexBymDiv - 5000, TmbPresenter.ScaleByus, TmbPresenter.Prefix.ToString(), TmbPresenter.Unit, Color.FromArgb((Int32)(GridIntensity / 100d * 255), Color.White));
  88. ScottPlotFormControl.Render(skipIfCurrentlyRendering: true);//未知栈溢出错误,标记栈的可能性较大
  89. _IsRefreshing = false;
  90. }
  91. private void TriggerIndicationAreaUpdate()
  92. {
  93. if (_VRIndicationAreaA != null && _VRIndicationAreaB != null /*&& _IsDraging == false*/)
  94. {
  95. switch (TriggerPrsnt.Type)
  96. {
  97. case TriggerType.Edge:
  98. case TriggerType.PulseWidth:
  99. case TriggerType.TimeOut:
  100. case TriggerType.Glitch:
  101. {
  102. _VRIndicationAreaB.IsVisible = false;
  103. if (TrgPresenter is TrigSingleSrcPrsnt trgp)
  104. {
  105. if (trgp.Source.IsAnalog() == true)
  106. {
  107. _VRIndicationAreaA.IsVisible = true;
  108. double position1 = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-trgp.RelPosIndex);
  109. _VRIndicationAreaA.SetPosition(position1);
  110. }
  111. else
  112. {
  113. _VRIndicationAreaA.IsVisible = false;
  114. }
  115. }
  116. }
  117. break;
  118. case TriggerType.Video:
  119. case TriggerType.Pattern:
  120. case TriggerType.State:
  121. case TriggerType.MultiQulified:
  122. case TriggerType.Serial:
  123. case TriggerType.SetupHold:
  124. {
  125. _VRIndicationAreaA.IsVisible = false;
  126. _VRIndicationAreaB.IsVisible = false;
  127. }
  128. break;
  129. case TriggerType.Runt:
  130. case TriggerType.Transition:
  131. case TriggerType.Window:
  132. {
  133. //两个
  134. if (TrgPresenter is TrigMultiLevelPrsnt trgp)
  135. {
  136. if (trgp.Source.IsAnalog() == true)
  137. {
  138. _VRIndicationAreaA.IsVisible = true;
  139. _VRIndicationAreaB.IsVisible = true;
  140. double positiona = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-trgp.RelPosUpperIndex);
  141. _VRIndicationAreaA.SetPosition(positiona);
  142. double positionb = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-trgp.RelPosLowerIndex);
  143. _VRIndicationAreaB.SetPosition(positionb);
  144. }
  145. else
  146. {
  147. _VRIndicationAreaA.IsVisible = false;
  148. _VRIndicationAreaB.IsVisible = false;
  149. }
  150. }
  151. }
  152. break;
  153. default:
  154. break;
  155. }
  156. }
  157. }
  158. private void DigitalWaveUpdate()
  159. {
  160. foreach (var id in ChannelIdExt.GetDigitals())
  161. {
  162. if (Program.Oscilloscope.TryGetChannel(id, out IChnlPrsnt ch) && ch.Pack!=null)
  163. {
  164. var dch = (DigitalPrsnt)ch;
  165. if (!_DigitalWavePlotDictionary.ContainsKey(id))
  166. {
  167. DigitalWavePlot digitalWavePlot = ScottPlotFormControl.Plot.AddDigitalWave(dch.Pack.Buffer, sampleRate: dch.Pack.Properties.Factor, color: dch.DrawColor/*, label: channel.Label*/);
  168. digitalWavePlot.IsAfterglowOn = false;
  169. _DigitalWavePlotDictionary.Add(id, digitalWavePlot);
  170. _PlotBaseDictionary.Add(id, digitalWavePlot);
  171. }
  172. _DigitalWavePlotDictionary[id].IsVisible = dch.Active;
  173. if (dch.Active == true)
  174. {
  175. for (int i = 0; i < dch.BitLength; i++)
  176. {
  177. Boolean isactive = dch.GetActiveAt(i);
  178. _DigitalWavePlotDictionary[id].SetBitActive(i, isactive);
  179. _DigitalWavePlotDictionary[id].SetBitColor(i, dch.GetColorAt(i));
  180. VLArrowIndicationArea vlarrowindicationarea = _VLArrowIndicationAreaDictionary[ChannelId.D1 + i];
  181. vlarrowindicationarea.Color = dch.GetColorAt(i);
  182. vlarrowindicationarea.Label = dch.GetLabelAt(i);
  183. vlarrowindicationarea.IsVisible = isactive;
  184. if (vlarrowindicationarea.PosIndexEnabled == false && isactive == true)
  185. {
  186. float offsety = (float)vlarrowindicationarea.GetIndicationValue() - ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-dch.GetPosIndexAt(i)) + vlarrowindicationarea.IndicationImage.Height / 2;
  187. _DigitalWavePlotDictionary[id].SetBitOffsetY(i, offsety);
  188. }
  189. else
  190. {
  191. _DigitalWavePlotDictionary[id].SetBitOffsetY(i, 0);
  192. if (isactive == true)
  193. {
  194. vlarrowindicationarea.SetPosition(ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-dch.GetPosIndexAt(i) /** dch.BitHeight*/) - vlarrowindicationarea.IndicationImage.Height / 2);
  195. }
  196. }
  197. }
  198. //更新数据
  199. if (dch.Pack != null)
  200. _DigitalWavePlotDictionary[id].YTs = dch.VuDatabase.Current.Buffer;
  201. _DigitalWavePlotDictionary[id].SampleRate = dch.Pack.Properties.Factor;
  202. //更新通道刻度信息
  203. if (DsoPrsnt.FocusId.IsDigital() == true)
  204. ScottPlotFormControl.Plot.YAxis.IsVisible = false;
  205. else if (AxisTickVisible == true)
  206. {
  207. ScottPlotFormControl.Plot.YAxis.IsVisible = true;
  208. }
  209. }
  210. else
  211. {
  212. for (int i = 0; i < dch.BitLength; i++)
  213. {
  214. _VLArrowIndicationAreaDictionary[ChannelId.D1 + i].IsVisible = false;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. private void AnalogWaveUpdate()
  221. {
  222. if (_WavePlotDictionary.Count > 3)
  223. {
  224. foreach (var id in ChannelIdExt.GetAnalogs())
  225. {
  226. if (Program.Oscilloscope.TryGetChannel(id, out IChnlPrsnt channel))
  227. {
  228. _WavePlotDictionary[id].IsVisible = channel.Active;
  229. if (channel.Active == true)
  230. {
  231. //更新数据
  232. //if (channel.Pack != null)
  233. // _WavePlotDictionary[id].YTs = channel.Pack.Buffer;
  234. if (channel.VuDatabase.Current != null)
  235. {
  236. _WavePlotDictionary[id].YTs = (double[,])channel.VuDatabase.Current.Buffer;
  237. _WavePlotDictionary[id].SampleRate = channel.VuDatabase.Current.ZoomRatio;
  238. _WavePlotDictionary[id].OffsetX = channel.VuDatabase.Current.Start;
  239. }
  240. //更新通道刻度信息
  241. if (channel.Id == DsoPrsnt.FocusId)
  242. {
  243. 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*/);
  244. if (AxisTickVisible == true)
  245. {
  246. ScottPlotFormControl.Plot.YAxis.IsVisible = true;
  247. }
  248. }
  249. if (_VLIndicationAreaDictionary.ContainsKey(id))
  250. {
  251. if (_IsDraging == false)
  252. {
  253. _VLIndicationAreaDictionary[id].IsVisible = true;
  254. _VLIndicationAreaDictionary[id].Color = channel.DrawColor;
  255. _VLIndicationAreaDictionary[id].Label = channel.Label;
  256. _VLIndicationAreaDictionary[id].SetPosition(ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(-(int)(channel as AnalogPrsnt).PosIndexBymDiv));
  257. }
  258. if (channel.Id == DsoPrsnt.FocusId)
  259. {
  260. if (_VLIndicationAreaDictionary[id].IsMoved)
  261. {
  262. _VRIndicationAreaA.IsRenderDottedLine = false;
  263. _VRIndicationAreaB.IsRenderDottedLine = false;
  264. }
  265. else
  266. {
  267. _VRIndicationAreaA.IsRenderDottedLine = true;
  268. _VRIndicationAreaB.IsRenderDottedLine = true;
  269. }
  270. }
  271. }
  272. List<(ChannelId, ChannelId)> keylist = ZoomRectangleAreaDictionary.Keys.Where((x) => { return x.Item2 == channel.Id; }).ToList();
  273. foreach (var item in keylist)
  274. {
  275. if (ZoomRectangleAreaDictionary.TryGetValue(item, out ZoomRectangleArea zoomRectangleArea) == true)
  276. {
  277. zoomRectangleArea.YPosIndexBymDiv = (channel as AnalogPrsnt).PosIndexBymDiv;
  278. if (item.Item1 == DsoPrsnt.FocusId)
  279. zoomRectangleArea.IsFocused = true;
  280. else
  281. zoomRectangleArea.IsFocused = false;
  282. if (Program.Oscilloscope.TryGetChannel(item.Item1, out IChnlPrsnt mathchannel))
  283. {
  284. double width =(mathchannel as MathPrsnt).Sampling.Scale / TmbPresenter.ScaleByus * Constants.MAX_XPOS_IDX;
  285. //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;
  286. 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;
  287. zoomRectangleArea.SetAreaBoundaryOnly(start,start+width,1,1);
  288. }
  289. }
  290. }
  291. }
  292. else
  293. {
  294. _VLIndicationAreaDictionary[id].IsVisible = false;
  295. }
  296. }
  297. }
  298. }
  299. if (DisplayPresenter.Persist == WfmPersist.Auto)
  300. ScottPlotFormControl.WfmPersist = WaveFormPersist.Auto;
  301. else if (DisplayPresenter.Persist == WfmPersist.Infinity)
  302. ScottPlotFormControl.WfmPersist = WaveFormPersist.Infinity;
  303. else
  304. ScottPlotFormControl.WfmPersist = WaveFormPersist.Close;
  305. }
  306. /// <summary>
  307. /// 设置渲染层级
  308. /// </summary>
  309. private void SetPlotRenderZIndex()
  310. {
  311. if (_PlotBaseDictionary.ContainsKey(DsoPrsnt.FocusId))
  312. {
  313. List<KeyValuePair<ChannelId, IPlotBase>> waveplotlist = _PlotBaseDictionary.ToList();
  314. waveplotlist.Sort((a, b) => { return a.Key > b.Key ? 1 : -1; });
  315. Int32 index = waveplotlist.Count;
  316. Int32 currentfocusindex = waveplotlist.FindIndex((a) => { return a.Key == DsoPrsnt.FocusId; });
  317. for (int i = currentfocusindex; i < waveplotlist.Count; i++)
  318. {
  319. waveplotlist[i].Value.ZIndex = index;
  320. index--;
  321. }
  322. for (int j = 0; j < currentfocusindex; j++)
  323. {
  324. waveplotlist[j].Value.ZIndex = index;
  325. index--;
  326. }
  327. }
  328. if (_IndicationAreaDictionary.ContainsKey(DsoPrsnt.FocusId))
  329. {
  330. List<KeyValuePair<ChannelId, IndicationArea>> vlindicationarealist = _IndicationAreaDictionary.ToList();
  331. vlindicationarealist.Sort((a, b) => { return a.Key > b.Key ? 1 : -1; });
  332. ChannelId currentchannelid = DsoPrsnt.FocusId;
  333. if (DsoPrsnt.FocusId.IsDigital() == true)
  334. {
  335. if (Program.Oscilloscope.TryGetChannel(DsoPrsnt.FocusId, out IChnlPrsnt ch))
  336. {
  337. var dch = (DigitalPrsnt)ch;
  338. currentchannelid = ChannelId.D1 + dch.FocusBitId;
  339. }
  340. }
  341. Int32 index = vlindicationarealist.Count;
  342. Int32 currentfocusindex = vlindicationarealist.FindIndex((a) => { return a.Key == currentchannelid; });
  343. for (int i = currentfocusindex; i < vlindicationarealist.Count; i++)
  344. {
  345. if (index == vlindicationarealist.Count)
  346. {
  347. vlindicationarealist[i].Value.IsFocused = true;
  348. }
  349. else
  350. {
  351. vlindicationarealist[i].Value.IsFocused = false;
  352. }
  353. vlindicationarealist[i].Value.ZIndex = index;
  354. index--;
  355. }
  356. for (int j = 0; j < currentfocusindex; j++)
  357. {
  358. vlindicationarealist[j].Value.IsFocused = false;
  359. vlindicationarealist[j].Value.ZIndex = index;
  360. index--;
  361. }
  362. }
  363. else
  364. {
  365. foreach (var item in _IndicationAreaDictionary)
  366. {
  367. item.Value.IsFocused = false;
  368. }
  369. }
  370. foreach (var item in ZoomRectangleAreaDictionary)
  371. {
  372. if (item.Key.Item1 == DsoPrsnt.FocusId)
  373. {
  374. item.Value.ZIndex = 1;
  375. }
  376. else
  377. {
  378. item.Value.ZIndex = 0;
  379. }
  380. }
  381. }
  382. /// <summary>
  383. /// 配置显示信息
  384. /// </summary>
  385. private void ConfigureWavePlot()
  386. {
  387. //控件属性配置
  388. ScottPlotFormControl.Configuration.MiddleClickAutoAxisMarginX = 0;
  389. ScottPlotFormControl.Configuration.Quality = 0;
  390. //波形线路名称
  391. ScottPlot.Renderable.Legend legend = ScottPlotFormControl.Plot.Legend();
  392. legend.FontColor = Color.Gray;
  393. legend.OutlineColor = Color.White;
  394. legend.FillColor = Color.Black;
  395. ScottPlotFormControl.Plot.AxisAutoX(margin: 0);
  396. ScottPlotFormControl.Plot.SetAxisLimits(xMin: 0, xMax: 10000, yMin: -5000, yMax: 5000);//初始视阈
  397. ScottPlotFormControl.Plot.SetViewLimits(xMin: -32768, xMax: 32768, yMin: -10000, yMax: 10000);//视阈限制
  398. ScottPlotFormControl.Dock = DockStyle.Fill;
  399. //图形颜色设置
  400. ScottPlotFormControl.Plot.Style(figureBackground: Color.Transparent, dataBackground: Color.Transparent, grid: Color.Gray, tick: Color.Gray, axisLabel: Color.Gray, titleLabel: Color.Gray);
  401. //网格属性配置
  402. ScottPlotFormControl.Plot.Grid(enable: true, color: Color.Gray, lineStyle: LineStyle.Dot);
  403. ScottPlotFormControl.BackColor = Color.Black;
  404. ScottPlotFormControl.Plot.ResetChannelParameter(50, 6.6, "", "", Color.White);
  405. ScottPlotFormControl.Plot.ResetTimebaseParameter(50, 7.7, "", "", Color.White);
  406. AddWavePlot();
  407. AddDragArea();
  408. //AddZoomArea();
  409. ScottPlotFormControl.PlottableDropped += ScottPlotFormControl_PlottableDropped;
  410. ScottPlotFormControl.PlottableDragged += ScottPlotFormControl_PlottableDragged;
  411. ScottPlotFormControl.Plot.RenderEventHandler += ScottPlotFormControlPlot_RenderEventHandler;
  412. (Program.Oscilloscope.View as DsoForm).RemoveZoomRectangleAreaEventArgs += DsoForm_ZoomRectangleAreaRemoveEventArgs;
  413. (Program.Oscilloscope.View as DsoForm).AddZoomRectangleAreaEventArgs += DsoForm_AddZoomRectangleAreaEventArgs;
  414. }
  415. private void DsoForm_ZoomRectangleAreaRemoveEventArgs(object sender, ChannelId e)
  416. {
  417. List<(ChannelId, ChannelId)> removekeylist = ZoomRectangleAreaDictionary.Keys.Where((x) => { return x.Item1 == e; }).ToList();
  418. foreach (var item in removekeylist)
  419. {
  420. ZoomRectangleAreaDictionary.Remove(item, out ZoomRectangleArea zoomrectanglearea);
  421. if (zoomrectanglearea != null)
  422. {
  423. ScottPlotFormControl.Plot.Remove(zoomrectanglearea);
  424. }
  425. }
  426. }
  427. private void ScottPlotFormControlPlot_RenderEventHandler(object sender, (Bitmap bmp, PlotDimensions plotDimensions, bool lowQuality) e)
  428. {
  429. CursorApp.Default?.DrawCursor(sender, e);
  430. MeasureApp.Default?.DrawIndicator(sender, e);
  431. return;
  432. //String message = Guid.NewGuid().ToString();
  433. //using (var gfx = ScottPlot.Drawing.GDI.Graphics(e.bmp, e.plotDimensions, e.lowQuality, false))
  434. //using (var font = ScottPlot.Drawing.GDI.Font("微软雅黑", 10))
  435. //using (var fontBrush = new SolidBrush(Color.Black))
  436. //using (var fillBrush = new SolidBrush(Color.White))
  437. //using (var borderPen = new Pen(Color.White, 2))
  438. //{
  439. // SizeF textSize = ScottPlot.Drawing.GDI.MeasureString(gfx, message, font);
  440. // float textHeight = textSize.Height;
  441. // float textWidth = textSize.Width;
  442. // float textY = 0;
  443. // textY = e.plotDimensions.DataOffsetY + e.plotDimensions.DataHeight / 2 - textHeight / 2;
  444. // float textX = 0;
  445. // textX = e.plotDimensions.DataOffsetX + e.plotDimensions.DataWidth / 2 - textWidth / 2;
  446. // RectangleF textRect = new RectangleF(textX, textY, textWidth, textHeight);
  447. // gfx.FillRectangle(fillBrush, textRect);
  448. // gfx.DrawRectangle(borderPen, Rectangle.Round(textRect));
  449. // gfx.DrawString(message, font, fontBrush, textX, textY);
  450. //}
  451. }
  452. private void ScottPlotFormControl_PlottableDragged(object sender, EventArgs e)
  453. {
  454. if (sender != null && sender is VLArrowIndicationArea vlarrowindicationarea)
  455. {
  456. //数字位光标在拖动时,P层PosIndex无效
  457. vlarrowindicationarea.PosIndexEnabled = false;
  458. }
  459. }
  460. private void ScottPlotFormControl_PlottableDropped(object sender, EventArgs e)
  461. {
  462. if (sender != null && sender is VLArrowIndicationArea vlarrowindicationarea)
  463. {
  464. //数字位光标拖动结束时,计算位置替换
  465. if (Program.Oscilloscope.TryGetChannel(ChannelId.D1, out IChnlPrsnt ch))
  466. {
  467. var dch = (DigitalPrsnt)ch;
  468. Int32 curchannelidindex = 0;
  469. foreach (var item in _VLArrowIndicationAreaDictionary)
  470. {
  471. if (item.Value.Equals(vlarrowindicationarea))
  472. {
  473. curchannelidindex = item.Key - ChannelId.D1;
  474. break;
  475. }
  476. }
  477. dch.SetPosIndexAt(curchannelidindex, ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)vlarrowindicationarea.GetIndicationValue()));
  478. vlarrowindicationarea.PosIndexEnabled = true;
  479. }
  480. }
  481. }
  482. /// <summary>
  483. /// 增加模拟波形
  484. /// </summary>
  485. private void AddWavePlot()
  486. {
  487. foreach (var id in ChannelIdExt.GetAnalogs())
  488. if (Program.Oscilloscope.TryGetChannel(id, out IChnlPrsnt channel))
  489. if (channel.Pack != null)
  490. {
  491. wavePlot = ScottPlotFormControl.Plot.AddWave(channel.Pack.Buffer, sampleRate: channel.Pack.Properties.Factor, isAfterglowOn: true, channel.DrawColor/*, label: channel.Label*/);
  492. _WavePlotDictionary.Add(id, wavePlot);
  493. _PlotBaseDictionary.Add(id, wavePlot);
  494. }
  495. }
  496. /// <summary>
  497. /// 增加拖拽指示区域
  498. /// </summary>
  499. private void AddDragArea()
  500. {
  501. PlotDimensions plotDimensions = ScottPlotFormControl.Plot.GetSettings().GetPlotDimensions(0, 0, 1);
  502. foreach (var item in ChannelIdExt.GetAnalogs())//模拟通道
  503. {
  504. VLIndicationArea vLIndicationAreaCH1 = ScottPlotFormControl.Plot.AddVLIndicationArea(plotDimensions, color: Color.Red, label: item.ToString(), name: item.ToString());
  505. vLIndicationAreaCH1.Margin = (0, 3, 0, 3);
  506. _VLIndicationAreaDictionary.Add(item, vLIndicationAreaCH1);
  507. _IndicationAreaDictionary.Add(item, vLIndicationAreaCH1);
  508. double position0 = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(0);
  509. vLIndicationAreaCH1.SetPosition(position0);
  510. vLIndicationAreaCH1.Dragged += (sender, e) =>
  511. {
  512. if (Program.Oscilloscope.TryGetChannel(item, out IChnlPrsnt channel))
  513. {
  514. (channel as AnalogPrsnt).PosIndexBymDiv = ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)vLIndicationAreaCH1.GetIndicationValue());
  515. }
  516. ScottPlotFormControl.ClearWfmCache();//清理无限余晖缓存测试,不影响其他业务
  517. };
  518. vLIndicationAreaCH1.MouseDown += (sender, e) =>
  519. {
  520. DsoPrsnt.FocusId = item;
  521. };
  522. }
  523. for (int i = 0; i < 16; i++)//数字通道
  524. {
  525. VLArrowIndicationArea vlarrowindicationarea = ScottPlotFormControl.Plot.AddVLArrowIndicationArea(plotDimensions, color: Color.Yellow, label: "D" + (i + 1).ToString(), name: "D" + (i + 1).ToString());
  526. vlarrowindicationarea.IsVisible = false;
  527. _VLArrowIndicationAreaDictionary.Add(ChannelId.D1 + i, vlarrowindicationarea);
  528. _IndicationAreaDictionary.Add(ChannelId.D1 + i, vlarrowindicationarea);
  529. int bitindex = i;
  530. vlarrowindicationarea.MouseDown += (sender, e) =>
  531. {
  532. DsoPrsnt.FocusId = ChannelId.D1;
  533. if (Program.Oscilloscope.TryGetChannel(DsoPrsnt.FocusId, out IChnlPrsnt ch))
  534. {
  535. var dch = (DigitalPrsnt)ch;
  536. dch.FocusBitId = bitindex;
  537. }
  538. };
  539. }
  540. _VRIndicationAreaB = ScottPlotFormControl.Plot.AddVRIndicationArea(plotDimensions, color: Color.OrangeRed/*, name: "B"*/); //触发
  541. _VRIndicationAreaB.Margin = (6, 3, 0, 3);
  542. _VRIndicationAreaA = ScottPlotFormControl.Plot.AddVRIndicationArea(plotDimensions, color: Color.OrangeRed/*, name: "A"*/); //触发
  543. _VRIndicationAreaA.Margin = (0, 3, 5, 3);
  544. _VRIndicationAreaA.ZIndex = 1;
  545. _HTIndicationArea = ScottPlotFormControl.Plot.AddHTIndicationArea(plotDimensions, color: Color.OrangeRed, name: "T");//时基
  546. _HTIndicationArea.Margin = (3, 0, 3, 0);
  547. double position1 = ScottPlotFormControl.Plot.YAxis.Dims.GetPixel(0);
  548. double position2 = ScottPlotFormControl.Plot.XAxis.Dims.GetPixel(5000);
  549. _VRIndicationAreaA.SetPosition(position1);
  550. _VRIndicationAreaB.SetPosition(position1);
  551. _HTIndicationArea.SetPosition(position2);
  552. _VRIndicationAreaA.Dragged += VRIndicationArea_Dragged;
  553. _VRIndicationAreaB.Dragged += VRIndicationArea_Dragged;
  554. _HTIndicationArea.Dragged += (sender, e) =>
  555. {
  556. TmbPresenter.PosIndexBymDiv = ScottPlotFormControl.Plot.XAxis.Dims.GetUnit((float)_HTIndicationArea.GetIndicationValue());
  557. };
  558. ////设置拖拽指示图片
  559. //vLIndicationArea.IndicationImage = new Bitmap(19,19);
  560. //vRIndicationArea.IndicationImage = new Bitmap(19,19);
  561. //hTIndicationArea.IndicationImage = new Bitmap(19,19);
  562. }
  563. private void VRIndicationArea_Dragged(object sender, EventArgs e)
  564. {
  565. if (sender is VRIndicationArea vrindicationarea)
  566. {
  567. Boolean isdraggedupperarea = true;
  568. if (vrindicationarea.Equals(_VRIndicationAreaB))
  569. {
  570. isdraggedupperarea = false;
  571. }
  572. switch (TriggerPrsnt.Type)
  573. {
  574. case TriggerType.Edge:
  575. case TriggerType.PulseWidth:
  576. case TriggerType.TimeOut:
  577. case TriggerType.Glitch:
  578. {
  579. if (TrgPresenter is TrigSingleSrcPrsnt trgp && isdraggedupperarea == true)
  580. {
  581. trgp.RelPosIndex = ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)_VRIndicationAreaA.GetIndicationValue());
  582. }
  583. }
  584. break;
  585. case TriggerType.Video:
  586. case TriggerType.Pattern:
  587. case TriggerType.State:
  588. case TriggerType.MultiQulified:
  589. case TriggerType.Serial:
  590. case TriggerType.SetupHold:
  591. break;
  592. case TriggerType.Runt:
  593. case TriggerType.Transition:
  594. case TriggerType.Window:
  595. {
  596. //两个
  597. if (TrgPresenter is TrigMultiLevelPrsnt trgp)
  598. {
  599. if (isdraggedupperarea == true)
  600. {
  601. double posa = ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)_VRIndicationAreaA.GetIndicationValue());
  602. trgp.RelPosUpperIndex = posa;
  603. }
  604. else
  605. {
  606. double posb = ScottPlotFormControl.Plot.YAxis.Dims.GetUnit((float)_VRIndicationAreaB.GetIndicationValue());
  607. trgp.RelPosLowerIndex = posb;
  608. }
  609. }
  610. }
  611. break;
  612. default:
  613. break;
  614. }
  615. }
  616. }
  617. private void AddZoomArea()
  618. {
  619. PlotDimensions plotDimensions = ScottPlotFormControl.Plot.GetSettings().GetPlotDimensions(0, 0, 1);
  620. AxisDimensions axisDimensionsX = ScottPlotFormControl.Plot.XAxis.Dims;
  621. AxisDimensions axisDimensionsY = ScottPlotFormControl.Plot.YAxis.Dims;
  622. zoomRectangleArea = ScottPlotFormControl.Plot.AddDraggableZoomRectangleArea(plotDimensions, axisDimensionsX, axisDimensionsY, label: "Math1");
  623. }
  624. /// <summary>
  625. /// 增加拓展区域
  626. /// </summary>
  627. /// <param name="id"></param>
  628. /// <param name="channeCcolor"></param>
  629. /// <param name="idKey"></param>
  630. /// <param name="zoomunitarea"></param>
  631. private void AddZoomArea((ChannelId, ChannelId) id, Color channeCcolor, Int64 idKey, (double xLeft, double xRight, double yTop, double yBottom) zoomunitarea, Color labelColor)
  632. {
  633. PlotDimensions plotDimensions = ScottPlotFormControl.Plot.GetSettings().GetPlotDimensions(0, 0, 1);
  634. AxisDimensions axisDimensionsX = ScottPlotFormControl.Plot.XAxis.Dims;
  635. AxisDimensions axisDimensionsY = ScottPlotFormControl.Plot.YAxis.Dims;
  636. ZoomRectangleArea zoomRectangle = ScottPlotFormControl.Plot.AddDraggableZoomRectangleArea(plotDimensions, axisDimensionsX, axisDimensionsY, color: channeCcolor, label: id.Item1.ToString(), labelColor: labelColor);
  637. ZoomRectangleAreaDictionary.Add(id, zoomRectangle);
  638. }
  639. #endregion
  640. #region 创建Zoom
  641. private void ScottPlotFormControl_ZoomCreated(object sender, EventArgs e)
  642. {
  643. isZooming = false;
  644. ScottPlotFormControl.SetZoomingState(isZooming);
  645. (double xLeft, double xRight, double yTop, double yBottom) zoomunitarea = ScottPlotFormControl.Plot.GetZoomUnitArea();
  646. //此操作获取焦点通道的水平、垂直档位,以此为依据创建新的数学通道,通道的数学运算属性为zoom
  647. //1.垂直档位 = Math.Abs(yTop - yBottom)/10000*focusedchannel.YScale
  648. //2.水平档位 = Math.Abs(xLeft - xRight)/10000*focusedchannel.XScale
  649. //3.垂直位移
  650. //4.水平位移
  651. ChannelId channelId = ChannelId.C1;
  652. if (DsoPrsnt.FocusId.IsAnalog() == true)
  653. {
  654. channelId = DsoPrsnt.FocusId;
  655. }
  656. //5.创建ZoomArea
  657. (Program.Oscilloscope.View as DsoForm).Presenter.TryGetChannel(channelId, out var prsnt);
  658. if ((Program.Oscilloscope.View as DsoForm).TryAddMathInfo( MathType.Zoom) && prsnt != null)
  659. {
  660. ////此处需要Core公开部分属性的写权限
  661. (Program.Oscilloscope.View as DsoForm).Presenter.TryGetChannel(DsoPrsnt.FocusId, out var mprsnt);
  662. AddZoomArea((DsoPrsnt.FocusId, channelId), mprsnt.DrawColor, IdFactory.NextId, zoomunitarea, mprsnt.DrawColor);
  663. //channel.timebase = Math.Abs(zoomunitarea.xLeft - zoomunitarea.xRight) / 10000 * timebase.Scale;
  664. //channel.Scale = Math.Abs(zoomunitarea.yTop - zoomunitarea.yBottom) / 10000 * prsnt.YScale;
  665. }
  666. //6.属性绑定(AreaUnit,unit边界)
  667. //7.资源释放 数学通道关闭后,将对应zoom区域清除
  668. }
  669. private void DsoForm_AddZoomRectangleAreaEventArgs(object sender, (ChannelId, ChannelId) e)
  670. {
  671. if (ZoomRectangleAreaDictionary.ContainsKey(e) == false)
  672. {
  673. PlotDimensions plotDimensions = ScottPlotFormControl.Plot.GetSettings().GetPlotDimensions(0, 0, 1);
  674. AxisDimensions axisDimensionsX = ScottPlotFormControl.Plot.XAxis.Dims;
  675. AxisDimensions axisDimensionsY = ScottPlotFormControl.Plot.YAxis.Dims;
  676. if (Program.Oscilloscope.TryGetChannel(e.Item1, out IChnlPrsnt mathchannel))
  677. {
  678. ZoomRectangleArea zoomRectangle = ScottPlotFormControl.Plot.AddDraggableZoomRectangleArea(plotDimensions, axisDimensionsX, axisDimensionsY, color: mathchannel.DrawColor);
  679. ZoomRectangleAreaDictionary.Add(e, zoomRectangle);
  680. }
  681. }
  682. }
  683. #endregion
  684. #region 标记
  685. private VLine _VLine;
  686. private HLine _HLine;
  687. private Boolean _IsCursorTracking = false;
  688. public Boolean IsCursorTracking
  689. {
  690. get => _IsCursorTracking;
  691. set => _IsCursorTracking = value;
  692. }
  693. private void ConfigureMouseTracker()
  694. {
  695. _VLine = ScottPlotFormControl.Plot.AddVerticalLine(0, Color.Yellow, 1, LineStyle.Dash);
  696. _HLine = ScottPlotFormControl.Plot.AddHorizontalLine(0, Color.Yellow, 1, LineStyle.Dash);
  697. }
  698. private void ScottPlotFormControl_MouseMove(object sender, MouseEventArgs e)
  699. {
  700. //#region 鼠标移动,显示最近点的坐标值
  701. ////// determine point nearest the cursor
  702. ////(double mouseCoordX, double mouseCoordY) = ScottPlotFormControl.GetMouseCoordinates();
  703. ////double xyRatio = ScottPlotFormControl.Plot.XAxis.Dims.PxPerUnit / ScottPlotFormControl.Plot.YAxis.Dims.PxPerUnit;
  704. ////(double pointX, double pointY, int pointIndex) = _MyScatterPlot.GetPointNearest(mouseCoordX, mouseCoordY, xyRatio);
  705. ////// place the highlight over the point of interest
  706. ////_HighlightedPoint.Xs[0] = pointX;
  707. ////_HighlightedPoint.Ys[0] = pointY;
  708. ////_HighlightedPoint.IsVisible = true;
  709. ////// render if the highlighted point chnaged
  710. ////if (_LastHighlightedIndex != pointIndex)
  711. ////{
  712. //// _LastHighlightedIndex = pointIndex;
  713. //// ScottPlotFormControl.Render();
  714. ////}
  715. ////// update the GUI to describe the highlighted point
  716. ////LblShowResult.Text = $"Closest point to ({e.X:N0}, {e.Y:N0}) " +
  717. //// $"is index {pointIndex} ({pointX:N2}, {pointY:N2})";
  718. //#endregion
  719. //#region 线标
  720. //if (_IsCursorTracking)
  721. //{
  722. // _VLine.IsVisible = true;
  723. // _HLine.IsVisible = true;
  724. // (double coordinateX, double coordinateY) = ScottPlotFormControl.GetMouseCoordinates();
  725. // LblShowResult.Text = $"Mouse Pixel ({e.X:0.000}, {e.Y:0.000}) " +
  726. // $"Coordinate ({coordinateX:0.00000000}, {coordinateY:0.00000000})";
  727. // _VLine.X = coordinateX;
  728. // _HLine.Y = coordinateY;
  729. //}
  730. //else
  731. //{
  732. // _VLine.IsVisible = false;
  733. // _HLine.IsVisible = false;
  734. //}
  735. //#endregion
  736. }
  737. #endregion
  738. #region 窗口显示属性及配置
  739. /// <summary>
  740. /// 波形显示风格
  741. /// </summary>
  742. public WfmDrawMode DrawMode
  743. {
  744. get => DisplayPresenter.DrawMode;
  745. set => DisplayPresenter.DrawMode = value;
  746. }
  747. /// <summary>
  748. /// 波形亮度
  749. /// </summary>
  750. public Int32 WfmIntensity
  751. {
  752. get => DisplayPresenter.WfmIntensity;
  753. set => DisplayPresenter.WfmIntensity = value;
  754. }
  755. /// <summary>
  756. /// 网格风格
  757. /// </summary>
  758. public GridType GridStyle
  759. {
  760. get => DisplayPresenter.GridStyle;
  761. set => DisplayPresenter.GridStyle = value;
  762. }
  763. /// <summary>
  764. /// 网格亮度
  765. /// </summary>
  766. public Int32 GridIntensity
  767. {
  768. get => DisplayPresenter.GridIntensity;
  769. set => DisplayPresenter.GridIntensity = value;
  770. }
  771. /// <summary>
  772. /// 标记是否可见
  773. /// </summary>
  774. public Boolean AxisTickVisible
  775. {
  776. get => DisplayPresenter.AxisTickVisible;
  777. set => DisplayPresenter.AxisTickVisible = value;
  778. }
  779. /// <summary>
  780. /// 水平标记是否显示在下方
  781. /// </summary>
  782. public Boolean XAxisTickBottom
  783. {
  784. get => DisplayPresenter.XAxisTickBottom;
  785. set => DisplayPresenter.XAxisTickBottom = value;
  786. }
  787. /// <summary>
  788. /// 垂直标记是否显示在右方
  789. /// </summary>
  790. public Boolean YAxisTickRight
  791. {
  792. get => DisplayPresenter.YAxisTickRight;
  793. set => DisplayPresenter.YAxisTickRight = value;
  794. }
  795. /// <summary>
  796. /// 配置波形显示风格
  797. /// </summary>
  798. /// <param name="wfmDrawMode"></param>
  799. private void ConfigDrawMode(WfmDrawMode wfmDrawMode)
  800. {
  801. switch (wfmDrawMode)
  802. {
  803. case WfmDrawMode.Vector:
  804. ScottPlotFormControl.Plot.WavePlotStyle(WavePlotLineStyle.Vector);
  805. break;
  806. case WfmDrawMode.Dot:
  807. ScottPlotFormControl.Plot.WavePlotStyle(WavePlotLineStyle.Dot);
  808. break;
  809. default:
  810. break;
  811. }
  812. }
  813. /// <summary>
  814. /// 配置波形亮度
  815. /// </summary>
  816. /// <param name="wfmIntensity"></param>
  817. private void ConfigWfmIntensity(Int32 wfmIntensity)
  818. {
  819. ScottPlotFormControl.Plot.WavePlotStyle(wfmIntensity);
  820. }
  821. /// <summary>
  822. /// 配置网格样式
  823. /// </summary>
  824. /// <param name="gridType"></param>
  825. private void ConfigGridStyle(GridType gridType)
  826. {
  827. switch (gridType)
  828. {
  829. case GridType.Full:
  830. ScottPlotFormControl.Plot.Grid(enable: true, lineStyle: LineStyle.Dot);
  831. ScottPlotFormControl.Plot.MinorTickVisible(true);
  832. break;
  833. case GridType.Brief:
  834. ScottPlotFormControl.Plot.Grid(enable: true, lineStyle: LineStyle.Dot);
  835. ScottPlotFormControl.Plot.MinorTickVisible(false);
  836. break;
  837. case GridType.None:
  838. ScottPlotFormControl.Plot.Grid(enable: false);
  839. ScottPlotFormControl.Plot.MinorTickVisible(false);
  840. break;
  841. default:
  842. break;
  843. }
  844. }
  845. /// <summary>
  846. /// 配置网格亮度
  847. /// </summary>
  848. /// <param name="GridIntensity"></param>
  849. private void ConfigGridIntensity(Int32 GridIntensity)
  850. {
  851. ScottPlotFormControl.Plot.Grid(color: Color.FromArgb((Int32)(GridIntensity / 100d * 255), Color.Gray));
  852. }
  853. /// <summary>
  854. /// 配置水平标记的显示位置
  855. /// </summary>
  856. /// <param name="horizontalBottom"></param>
  857. private void ConfigHorizontalTickLabelDirection(Boolean horizontalBottom = true)
  858. {
  859. ScottPlotFormControl.Plot.XAxis.Edge = horizontalBottom == true ? ScottPlot.Renderable.Edge.Bottom : ScottPlot.Renderable.Edge.Top;
  860. }
  861. /// <summary>
  862. /// 配置垂直标记的显示位置
  863. /// </summary>
  864. /// <param name="virticalRight"></param>
  865. private void ConfigVirticalTickLabelDirection(Boolean virticalRight = true)
  866. {
  867. ScottPlotFormControl.Plot.YAxis.Edge = virticalRight == true ? ScottPlot.Renderable.Edge.Right : ScottPlot.Renderable.Edge.Left;
  868. }
  869. /// <summary>
  870. /// 配置标记label的显示
  871. /// </summary>
  872. /// <param name="visible"></param>
  873. private void ConfigTickLabelVisible(Boolean visible = true)
  874. {
  875. ScottPlotFormControl.Plot.XAxis.IsVisible = visible;
  876. ScottPlotFormControl.Plot.YAxis.IsVisible = visible;
  877. }
  878. private void ToolStripMenuItemTimeWave_Click(object sender, EventArgs e)
  879. {
  880. if (_TimeDomainViewSettingForm != null)
  881. {
  882. _TimeDomainViewSettingForm.Close();
  883. }
  884. _TimeDomainViewSettingForm = new TimeDomainViewSettingForm();
  885. _TimeDomainViewSettingForm.SetGridComboBoxSelectType(Enum.GetValues<GridType>());
  886. XAxisTickType xaxisticktype = XAxisTickBottom ? XAxisTickType.Bottom : XAxisTickType.Top;
  887. YAxisTickType yaxisticktype = YAxisTickRight ? YAxisTickType.Right : YAxisTickType.Left;
  888. _TimeDomainViewSettingForm.SetMutexButtonModeType(xaxisticktype, yaxisticktype, DrawMode);
  889. _TimeDomainViewSettingForm.SetParameterValue(TimeEventParameterType.TickIntensity, GridIntensity);
  890. _TimeDomainViewSettingForm.SetParameterValue(TimeEventParameterType.WFMIntensity, WfmIntensity);
  891. _TimeDomainViewSettingForm.SetParameterValue(TimeEventParameterType.AxisTick, ScottPlotFormControl.Plot.XAxis.IsVisible);
  892. _TimeDomainViewSettingForm.ParameterChangedEventHandler += TimeDomainViewSettingForm_ParameterChangedEventHandler;
  893. if (Program.Oscilloscope.View != null && Program.Oscilloscope.View is DsoForm dsoForm)
  894. {
  895. Int32 locationx = (dsoForm.Width - _TimeDomainViewSettingForm.Width) / 2;
  896. locationx = locationx > 0 ? locationx : 0;
  897. Int32 locationy = (dsoForm.Height - _TimeDomainViewSettingForm.Height) / 2;
  898. locationy = locationy > 0 ? locationy : 0;
  899. //locationx = locationx + dsoForm.Left;
  900. //locationy = locationy + dsoForm.Top;
  901. _TimeDomainViewSettingForm.Location = new Point(locationx, locationy);
  902. }
  903. _TimeDomainViewSettingForm.Presenter = DisplayPresenter;
  904. _TimeDomainViewSettingForm.Presenter.TryAddView(_TimeDomainViewSettingForm);
  905. _TimeDomainViewSettingForm.FormClosed += (sender, e) =>
  906. {
  907. _TimeDomainViewSettingForm.ParameterChangedEventHandler -= TimeDomainViewSettingForm_ParameterChangedEventHandler;
  908. _TimeDomainViewSettingForm = null;
  909. };
  910. FormEventArgs formeventargs = new FormEventArgs() { Current = _TimeDomainViewSettingForm, Type = FormType.SettingForm };
  911. EventBroker.Instance.GetEvent<FormEventArgs>().Publish(this, formeventargs);
  912. }
  913. private void TimeDomainViewSettingForm_ParameterChangedEventHandler(TimeEventParameterType type, object obj)
  914. {
  915. switch (type)
  916. {
  917. case TimeEventParameterType.AxisTick:
  918. {
  919. if (obj is Boolean visible)
  920. {
  921. AxisTickVisible = visible;
  922. ConfigTickLabelVisible(visible);
  923. }
  924. }
  925. break;
  926. case TimeEventParameterType.XAxisTick:
  927. {
  928. if (obj is XAxisTickType timeBaseMarkerType)
  929. {
  930. XAxisTickBottom = timeBaseMarkerType == XAxisTickType.Bottom;
  931. ConfigHorizontalTickLabelDirection(timeBaseMarkerType == XAxisTickType.Bottom);
  932. }
  933. }
  934. break;
  935. case TimeEventParameterType.YAxisTick:
  936. {
  937. if (obj is YAxisTickType verticalGearMarkerType)
  938. {
  939. YAxisTickRight = verticalGearMarkerType == YAxisTickType.Right;
  940. ConfigVirticalTickLabelDirection(verticalGearMarkerType == YAxisTickType.Right);
  941. }
  942. }
  943. break;
  944. case TimeEventParameterType.WFMType:
  945. if (obj is WfmDrawMode mode)
  946. {
  947. DrawMode = mode;
  948. ConfigDrawMode(DrawMode);
  949. }
  950. break;
  951. case TimeEventParameterType.WFMIntensity:
  952. if (obj is Int32 int32)
  953. {
  954. WfmIntensity = int32;
  955. ConfigWfmIntensity(WfmIntensity);
  956. }
  957. break;
  958. case TimeEventParameterType.TickType:
  959. if (obj is GridType value)
  960. {
  961. GridStyle = value;
  962. ConfigGridStyle(GridStyle);
  963. }
  964. break;
  965. case TimeEventParameterType.TickIntensity:
  966. if (obj is Int32 intensity)
  967. {
  968. GridIntensity = intensity;
  969. ConfigGridIntensity(GridIntensity);
  970. }
  971. break;
  972. default:
  973. break;
  974. }
  975. }
  976. private void ToolStripMenuItemXY_Click(object sender, EventArgs e)
  977. {
  978. XYViewSettingForm xysettingform = new XYViewSettingForm();
  979. if (Program.Oscilloscope.View != null && Program.Oscilloscope.View is DsoForm dsoForm)
  980. {
  981. Int32 locationx = (dsoForm.Width - xysettingform.Width) / 2;
  982. locationx = locationx > 0 ? locationx : 0;
  983. Int32 locationy = (dsoForm.Height - xysettingform.Height) / 2;
  984. locationy = locationy > 0 ? locationy : 0;
  985. //locationx = locationx + dsoForm.Left;
  986. //locationy = locationy + dsoForm.Top;
  987. xysettingform.Location = new Point(locationx, locationy);
  988. }
  989. FormEventArgs formeventargs = new FormEventArgs() { Current = xysettingform, Type = FormType.SettingForm };
  990. EventBroker.Instance.GetEvent<FormEventArgs>().Publish(this, formeventargs);
  991. }
  992. private void OnLostFocusClick_FloatForm(object obj, EventArgs e)
  993. {
  994. var form = obj as Uni_Trend.MSO7000X.UserControls.FloatForm;
  995. if (form != null)
  996. {
  997. form.Close();
  998. }
  999. }
  1000. #endregion
  1001. #region 事件
  1002. private void TimerRefresh_Tick(object sender, EventArgs e)
  1003. {
  1004. if (_IsRefreshing == false)
  1005. {
  1006. DrawWave();
  1007. }
  1008. }
  1009. private void WaveformViewForm_Load(object sender, EventArgs e)
  1010. {
  1011. ConfigureWavePlot();
  1012. ConfigGridIntensity(GridIntensity);
  1013. ConfigGridStyle(GridStyle);
  1014. ConfigWfmIntensity(WfmIntensity);
  1015. ConfigDrawMode(DrawMode);
  1016. ConfigTickLabelVisible(AxisTickVisible);
  1017. ConfigVirticalTickLabelDirection(XAxisTickBottom);
  1018. ConfigHorizontalTickLabelDirection(YAxisTickRight);
  1019. ConfigScottPlotFormControlTouch();
  1020. _TimerRefresh.Interval = 10;
  1021. _TimerRefresh.Tick += TimerRefresh_Tick;
  1022. _TimerRefresh.Enabled = true;
  1023. }
  1024. private void ScottPlotFormControl_MouseDown(object sender, MouseEventArgs e)
  1025. {
  1026. _IsDraging = true;
  1027. }
  1028. private void ScottPlotFormControl_MouseLeave(object sender, EventArgs e)
  1029. {
  1030. _IsDraging = false;
  1031. }
  1032. private void ScottPlotFormControl_MouseUp(object sender, MouseEventArgs e)
  1033. {
  1034. _IsDraging = false;
  1035. }
  1036. private void ScottPlotFormControl_AxesChanged(object sender, EventArgs e)
  1037. {
  1038. //ConfigAxis();
  1039. }
  1040. protected override void OnFormClosed(FormClosedEventArgs e)
  1041. {
  1042. _TimerRefresh.Dispose();
  1043. TmbPresenter.TryRemoveView(this);
  1044. TrgPresenter.TryRemoveView(this);
  1045. base.OnFormClosed(e);
  1046. }
  1047. ~WaveformFigure()
  1048. {
  1049. if (_TimerRefresh != null)
  1050. _TimerRefresh.Dispose();
  1051. }
  1052. #endregion
  1053. #region IDsoView
  1054. public MeasPrsnt MeasurePresenter
  1055. {
  1056. get;
  1057. set;
  1058. }
  1059. public DisplayPrsnt DisplayPresenter
  1060. {
  1061. get;
  1062. set;
  1063. }
  1064. IDisplayPrsnt IView<IDisplayPrsnt>.Presenter
  1065. {
  1066. get => DisplayPresenter;
  1067. set => DisplayPresenter = (DisplayPrsnt)value;
  1068. }
  1069. public TimebasePrsnt TmbPresenter
  1070. {
  1071. get;
  1072. set;
  1073. }
  1074. ITimebasePrsnt IView<ITimebasePrsnt>.Presenter
  1075. {
  1076. get => TmbPresenter;
  1077. set => TmbPresenter = (TimebasePrsnt)value;
  1078. }
  1079. public TriggerPrsnt TrgPresenter
  1080. {
  1081. get;
  1082. set;
  1083. }
  1084. ITriggerPrsnt IView<ITriggerPrsnt>.Presenter
  1085. {
  1086. get => TrgPresenter;
  1087. set => TrgPresenter = (TriggerPrsnt)value;
  1088. }
  1089. public void UpdateView(String propertyName)
  1090. {
  1091. if (String.IsNullOrEmpty(propertyName))
  1092. {
  1093. UpdateView();
  1094. return;
  1095. }
  1096. switch (propertyName)
  1097. {
  1098. //case nameof(TrgPresenter.):
  1099. // break;
  1100. //case nameof(TmbPresenter.Length):
  1101. // break;
  1102. case nameof(TmbPresenter.ScaleByus):
  1103. ScottPlotFormControl.Plot.ResetTimebaseParameter((Int32)TmbPresenter.PositionByus, TmbPresenter.ScaleByus, TmbPresenter.Prefix.ToString(), TmbPresenter.Unit, Color.White);
  1104. break;
  1105. case nameof(TmbPresenter.PositionByus):
  1106. ScottPlotFormControl.Plot.ResetTimebaseParameter((Int32)TmbPresenter.PositionByus, TmbPresenter.ScaleByus, TmbPresenter.Prefix.ToString(), TmbPresenter.Unit, Color.White);
  1107. break;
  1108. }
  1109. }
  1110. protected void UpdateView()
  1111. {
  1112. }
  1113. #endregion
  1114. private Boolean isZooming = false;
  1115. private void uestcIconButton1_MouseDown(object sender, MouseEventArgs e)
  1116. {
  1117. isZooming = !isZooming;
  1118. ScottPlotFormControl.SetZoomingState(isZooming);
  1119. }
  1120. //缩放的累计量集合元组,包含了:水平放大,水平缩小,垂直放大,垂直缩小;
  1121. private (float ZoomInH, float ZoomOutH, float ZoomInV, float ZoomOutV) _ScaleCumulative = (1F, 1F, 1F, 1F);
  1122. /// <summary>
  1123. /// 对波形显示控件的触摸事件进行配置处理;
  1124. /// </summary>
  1125. private void ConfigScottPlotFormControlTouch()
  1126. {
  1127. //处理TouchDown事件
  1128. ScottPlotFormControl.TouchDown += (x, y) =>
  1129. {
  1130. _ScaleCumulative = (1F, 1F, 1F, 1F);
  1131. _IsDraging = true;
  1132. };
  1133. //处理TouchUp事件
  1134. ScottPlotFormControl.TouchUp += (x, y) =>
  1135. {
  1136. _ScaleCumulative = (1F, 1F, 1F, 1F);
  1137. _IsDraging = false;
  1138. };
  1139. //处理TouchScale事件;分水平和垂直方向
  1140. ScottPlotFormControl.TouchScale += (x, y) =>
  1141. {
  1142. switch(y)
  1143. {
  1144. case Uni_Trend.MSO7000X.Touch.ScaleDirection.Horizontal:
  1145. OnScaleHorizontal(x);
  1146. break;
  1147. case Uni_Trend.MSO7000X.Touch.ScaleDirection.Veritcal:
  1148. OnScaleVertical(x);
  1149. break;
  1150. default:// Uni_Trend.MSO7000X.Touch.ScaleDirection.Both
  1151. OnScaleHorizontal(x);
  1152. OnScaleVertical(x);
  1153. break;
  1154. }
  1155. };
  1156. }
  1157. /// <summary>
  1158. /// 处理水平缩放
  1159. /// </summary>
  1160. /// <param name="scale">水平缩放的比例</param>
  1161. private void OnScaleHorizontal(float scale)
  1162. {
  1163. if (scale > 1F)//放大
  1164. {
  1165. _ScaleCumulative.ZoomInH *= scale;
  1166. if (_ScaleCumulative.ZoomInH > 1.25F)
  1167. {
  1168. TmbPresenter.ScaleIndex--;
  1169. _ScaleCumulative.ZoomInH = 1F;
  1170. }
  1171. }
  1172. else//缩小
  1173. {
  1174. _ScaleCumulative.ZoomOutH *= scale;
  1175. if (_ScaleCumulative.ZoomOutH < 0.8F)
  1176. {
  1177. TmbPresenter.ScaleIndex++;
  1178. _ScaleCumulative.ZoomOutH = 1F;
  1179. }
  1180. }
  1181. }
  1182. /// <summary>
  1183. /// 处理垂直缩放
  1184. /// </summary>
  1185. /// <param name="scale">垂直缩放的比例</param>
  1186. private void OnScaleVertical(float scale)
  1187. {
  1188. //找到当前选中通道的P层数据
  1189. AnalogPrsnt channelPrsnt = null;
  1190. if(DsoPrsnt.FocusId.IsAnalog())
  1191. {
  1192. Program.Oscilloscope.TryGetChannel(DsoPrsnt.FocusId, out IChnlPrsnt channel);
  1193. if(channel != null && channel.Active == true)
  1194. {
  1195. channelPrsnt = channel as AnalogPrsnt;
  1196. }
  1197. }
  1198. //波形进行缩放
  1199. if(channelPrsnt != null)
  1200. {
  1201. if (scale > 1F)//放大
  1202. {
  1203. _ScaleCumulative.ZoomInV *= scale;
  1204. if (_ScaleCumulative.ZoomInV > 1.25F)
  1205. {
  1206. channelPrsnt.AnaScaleIndex--;
  1207. _ScaleCumulative.ZoomInV = 1F;
  1208. }
  1209. }
  1210. else//缩小
  1211. {
  1212. _ScaleCumulative.ZoomOutV *= scale;
  1213. if (_ScaleCumulative.ZoomOutV < 0.8F)
  1214. {
  1215. channelPrsnt.AnaScaleIndex++;
  1216. _ScaleCumulative.ZoomOutV = 1F;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }