From 7b5231af80fabad3e9a0b4bb6a324736e55ecf06 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 20 Jun 2018 09:15:11 +0200 Subject: [PATCH] GraphLib : (1) Playback removed, (2) Precision timer removed. --- GraphLib/GraphLib.csproj | 1 - GraphLib/PlotterDisplayEx.cs | 108 +----- GraphLib/PlotterDisplayEx.designer.cs | 1 - GraphLib/PrecisionTimer.cs | 490 -------------------------- 4 files changed, 1 insertion(+), 599 deletions(-) delete mode 100644 GraphLib/PrecisionTimer.cs diff --git a/GraphLib/GraphLib.csproj b/GraphLib/GraphLib.csproj index 049688a55..fd4987f4c 100644 --- a/GraphLib/GraphLib.csproj +++ b/GraphLib/GraphLib.csproj @@ -75,7 +75,6 @@ True Resources.resx - diff --git a/GraphLib/PlotterDisplayEx.cs b/GraphLib/PlotterDisplayEx.cs index 3adf8e24d..3d7a11e33 100644 --- a/GraphLib/PlotterDisplayEx.cs +++ b/GraphLib/PlotterDisplayEx.cs @@ -43,11 +43,6 @@ namespace GraphLib PlotterGraphSelectCurvesForm GraphPropertiesForm = null; PrintPreviewForm printPreviewForm = null; - private PrecisionTimer.Timer mTimer = null; - private float play_speed = 0.5f; - private float play_speed_max = 10f; - private float play_speed_min = 0.5f; - private bool paused = false; private bool isRunning = false; @@ -58,11 +53,6 @@ namespace GraphLib public PlotterDisplayEx() { InitializeComponent(); - mTimer = new PrecisionTimer.Timer(); - mTimer.Period = 50; // 20 fps - mTimer.Tick += new EventHandler(OnTimerTick); - play_speed = 0.5f; // 20x10 = 200 values per second == sample frequency - mTimer.Start(); isRunning = false; } @@ -192,85 +182,10 @@ namespace GraphLib protected override void Dispose(bool disposing) { - paused = true; - - if (mTimer.IsRunning) - { - mTimer.Stop(); - mTimer.Dispose(); - } - + paused = true; base.Dispose(disposing); } - public void Start() - { - if (isRunning == false && paused == false) - { - gPane.starting_idx = 0; - paused = false; - isRunning = true; - // mTimer.Start(); - tb1.Buttons[0].ImageIndex = 2; - } - else - { - if (paused == false) - { - //mTimer.Stop(); - paused = true; - } - else - { - // mTimer.Start(); - paused = false; - } - - if (paused) - { - - tb1.Buttons[0].ImageIndex = 0; - } - else - { - - tb1.Buttons[0].ImageIndex = 2; - } - } - } - - public void Stop() - { - if (isRunning) - { - // mTimer.Stop(); - isRunning = false; - paused = false; - hScrollBar1.Value = 0; - tb1.Buttons[0].ImageIndex = 0; - } - } - - - private void tb1_ButtonClick(object sender, ToolBarButtonClickEventArgs e) - { - bool pushed = e.Button.Pushed; - switch (e.Button.Tag.ToString().ToLower()) - { - case "play": - - Start(); - - break; - - case "stop": - - Stop(); - - break; - } - } - private void SetPlayPanelVisible() { panel1.Visible = true; @@ -317,27 +232,6 @@ namespace GraphLib { } } - - private void UpdatePlayback() - { - if (!paused && isRunning == true) - { - try - { - gPane.starting_idx += play_speed; - UpdateScrollBar(); - gPane.Invalidate(); - } - catch { } - } - } - - private void OnTimerTick(object sender, EventArgs e) - { - UpdateControl(); - - UpdatePlayback(); - } private void UpdateScrollBar() { diff --git a/GraphLib/PlotterDisplayEx.designer.cs b/GraphLib/PlotterDisplayEx.designer.cs index 1050afb80..47412927a 100644 --- a/GraphLib/PlotterDisplayEx.designer.cs +++ b/GraphLib/PlotterDisplayEx.designer.cs @@ -57,7 +57,6 @@ namespace GraphLib this.tb1.Size = new System.Drawing.Size(80, 26); this.tb1.TabIndex = 1; this.tb1.Visible = false; - this.tb1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tb1_ButtonClick); // // tbbSave // diff --git a/GraphLib/PrecisionTimer.cs b/GraphLib/PrecisionTimer.cs deleted file mode 100644 index 5480f2e1d..000000000 --- a/GraphLib/PrecisionTimer.cs +++ /dev/null @@ -1,490 +0,0 @@ -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.Runtime.InteropServices; - -#region License - -/* - * Based on the work of Leslie Sanford - */ - -#endregion - - -namespace PrecisionTimer -{ - public enum Mode - { - OneShot, - Periodic - }; - - [StructLayout(LayoutKind.Sequential)] - public struct TimerCaps - { - public int periodMin; - public int periodMax; - } - - - public sealed class Timer : IComponent - { - private delegate void TimeProc(int id, int msg, int user, int param1, int param2); - - private delegate void EventRaiser(EventArgs e); - - [DllImport("winmm.dll")] - private static extern int timeGetDevCaps(ref TimerCaps caps, - int sizeOfTimerCaps); - - [DllImport("winmm.dll")] - private static extern int timeSetEvent(int delay, - int resolution, - TimeProc proc, - int user, - int mode); - - [DllImport("winmm.dll")] - private static extern int timeKillEvent(int id); - - private const int TIMERR_NOERROR = 0; - - private int timerID; - - private volatile Mode mode; - - private volatile int period; - - private volatile int resolution; - - private TimeProc timeProcPeriodic; - - private TimeProc timeProcOneShot; - - private EventRaiser tickRaiser; - - private bool running = false; - - private volatile bool disposed = false; - - private ISynchronizeInvoke synchronizingObject = null; - - private ISite site = null; - - private static TimerCaps caps; - - public event EventHandler Started; - - public event EventHandler Stopped; - - public event EventHandler Tick; - - static Timer() - { - // Get multimedia timer capabilities. - timeGetDevCaps(ref caps, Marshal.SizeOf(caps)); - } - - - public Timer(IContainer container) - { - - container.Add(this); - - Initialize(); - } - - - public Timer() - { - Initialize(); - } - - ~Timer() - { - if(IsRunning) - { - // Stop and destroy timer. - timeKillEvent(timerID); - } - } - - private void Initialize() - { - this.mode = Mode.Periodic; - this.period = Capabilities.periodMin; - this.resolution = 1; - - running = false; - - timeProcPeriodic = new TimeProc(TimerPeriodicEventCallback); - timeProcOneShot = new TimeProc(TimerOneShotEventCallback); - tickRaiser = new EventRaiser(OnTick); - } - - - public void Start() - { - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - - if(IsRunning) - { - return; - } - - if(Mode == Mode.Periodic) - { - timerID = timeSetEvent(Period, Resolution, timeProcPeriodic, 0, (int)Mode); - } - else - { - timerID = timeSetEvent(Period, Resolution, timeProcOneShot, 0, (int)Mode); - } - - if(timerID != 0) - { - running = true; - - if(SynchronizingObject != null && SynchronizingObject.InvokeRequired) - { - SynchronizingObject.BeginInvoke( - new EventRaiser(OnStarted), - new object[] { EventArgs.Empty }); - } - else - { - OnStarted(EventArgs.Empty); - } - } - else - { - throw new TimerException("Unable to start timer."); - } - } - - - public void Stop() - { - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - - if(!running) - { - return; - } - - - int result = timeKillEvent(timerID); - - Debug.Assert(result == TIMERR_NOERROR); - - running = false; - - if(SynchronizingObject != null && SynchronizingObject.InvokeRequired) - { - SynchronizingObject.BeginInvoke( - new EventRaiser(OnStopped), - new object[] { EventArgs.Empty }); - } - else - { - OnStopped(EventArgs.Empty); - } - } - - - private void TimerPeriodicEventCallback(int id, int msg, int user, int param1, int param2) - { - if(synchronizingObject != null) - { - synchronizingObject.BeginInvoke(tickRaiser, new object[] { EventArgs.Empty }); - } - else - { - OnTick(EventArgs.Empty); - } - } - - private void TimerOneShotEventCallback(int id, int msg, int user, int param1, int param2) - { - if(synchronizingObject != null) - { - synchronizingObject.BeginInvoke(tickRaiser, new object[] { EventArgs.Empty }); - Stop(); - } - else - { - OnTick(EventArgs.Empty); - Stop(); - } - } - - - - // Raises the Disposed event. - private void OnDisposed(EventArgs e) - { - EventHandler handler = Disposed; - - if(handler != null) - { - handler(this, e); - } - } - - // Raises the Started event. - private void OnStarted(EventArgs e) - { - EventHandler handler = Started; - - if(handler != null) - { - handler(this, e); - } - } - - // Raises the Stopped event. - private void OnStopped(EventArgs e) - { - EventHandler handler = Stopped; - - if(handler != null) - { - handler(this, e); - } - } - - // Raises the Tick event. - private void OnTick(EventArgs e) - { - EventHandler handler = Tick; - - if(handler != null) - { - handler(this, e); - } - } - - - - - - /// - /// Gets or sets the object used to marshal event-handler calls. - /// - public ISynchronizeInvoke SynchronizingObject - { - get - { - #region Require - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - - #endregion - - return synchronizingObject; - } - set - { - #region Require - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - - #endregion - - synchronizingObject = value; - } - } - - - public int Period - { - get - { - #region Require - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - - #endregion - - return period; - } - set - { - #region Require - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - else if(value < Capabilities.periodMin || value > Capabilities.periodMax) - { - throw new ArgumentOutOfRangeException("Period", value, - "Multimedia Timer period out of range."); - } - - #endregion - - period = value; - - if(IsRunning) - { - Stop(); - Start(); - } - } - } - - - public int Resolution - { - get - { - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - - return resolution; - } - set - { - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - else if(value < 0) - { - throw new ArgumentOutOfRangeException("Resolution", value, - "timer resolution out of range."); - } - - resolution = value; - - if(IsRunning) - { - Stop(); - Start(); - } - } - } - - public Mode Mode - { - get - { - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - - - return mode; - } - set - { - - if(disposed) - { - throw new ObjectDisposedException("Timer"); - } - - - mode = value; - - if(IsRunning) - { - Stop(); - Start(); - } - } - } - - /// - /// Gets a value indicating whether the Timer is running. - /// - public bool IsRunning - { - get - { - return running; - } - } - - /// - /// Gets the timer capabilities. - /// - public static TimerCaps Capabilities - { - get - { - return caps; - } - } - - - - - public event System.EventHandler Disposed; - - public ISite Site - { - get - { - return site; - } - set - { - site = value; - } - } - - - public void Dispose() - { - - if(disposed) - { - return; - } - - if(IsRunning) - { - Stop(); - } - - disposed = true; - - OnDisposed(EventArgs.Empty); - } - - - } - - - public class TimerException : ApplicationException - { - public TimerException(string message) : base(message) - { - } - } -}