DebugPlot.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using Logging.Base;
  5. namespace Plotting
  6. {
  7. public class DebugPlot
  8. {
  9. private Process plottingProc;
  10. private readonly List<AsyncLogFileWriter> plotWriters = new List<AsyncLogFileWriter>();
  11. private DebugPlot()
  12. {
  13. }
  14. public AsyncLogFileWriter StartPlotting(string path)
  15. {
  16. var writer = new AsyncLogFileWriter(path);
  17. plotWriters.Add(writer);
  18. return writer;
  19. }
  20. public void ShowPlots()
  21. {
  22. plottingProc = Process.Start("CMD.exe", "/C cd Assets/Plotting & python plot.py");
  23. }
  24. private void Dispose()
  25. {
  26. plottingProc?.Kill();
  27. foreach (var p in plotWriters) p.Dispose();
  28. }
  29. #region signleton
  30. private static Lazy<DebugPlot>
  31. instance =
  32. new Lazy<DebugPlot>
  33. (() => new DebugPlot());
  34. public static DebugPlot Instance => instance.Value;
  35. public static void DestroyInstance()
  36. {
  37. if (instance.IsValueCreated)
  38. {
  39. instance.Value.Dispose();
  40. instance =
  41. new Lazy<DebugPlot>
  42. (() => new DebugPlot());
  43. }
  44. }
  45. #endregion
  46. }
  47. }