GraphLib : (1) Playback removed, (2) Precision timer removed.
This commit is contained in:
parent
63b7b83363
commit
7b5231af80
@ -75,7 +75,6 @@
|
|||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="PrecisionTimer.cs" />
|
|
||||||
<Compile Include="Utils.cs" />
|
<Compile Include="Utils.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -43,11 +43,6 @@ namespace GraphLib
|
|||||||
PlotterGraphSelectCurvesForm GraphPropertiesForm = null;
|
PlotterGraphSelectCurvesForm GraphPropertiesForm = null;
|
||||||
PrintPreviewForm printPreviewForm = 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 paused = false;
|
||||||
private bool isRunning = false;
|
private bool isRunning = false;
|
||||||
|
|
||||||
@ -58,11 +53,6 @@ namespace GraphLib
|
|||||||
public PlotterDisplayEx()
|
public PlotterDisplayEx()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,85 +182,10 @@ namespace GraphLib
|
|||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
paused = true;
|
paused = true;
|
||||||
|
|
||||||
if (mTimer.IsRunning)
|
|
||||||
{
|
|
||||||
mTimer.Stop();
|
|
||||||
mTimer.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
base.Dispose(disposing);
|
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()
|
private void SetPlayPanelVisible()
|
||||||
{
|
{
|
||||||
panel1.Visible = true;
|
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()
|
private void UpdateScrollBar()
|
||||||
{
|
{
|
||||||
|
|||||||
1
GraphLib/PlotterDisplayEx.designer.cs
generated
1
GraphLib/PlotterDisplayEx.designer.cs
generated
@ -57,7 +57,6 @@ namespace GraphLib
|
|||||||
this.tb1.Size = new System.Drawing.Size(80, 26);
|
this.tb1.Size = new System.Drawing.Size(80, 26);
|
||||||
this.tb1.TabIndex = 1;
|
this.tb1.TabIndex = 1;
|
||||||
this.tb1.Visible = false;
|
this.tb1.Visible = false;
|
||||||
this.tb1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tb1_ButtonClick);
|
|
||||||
//
|
//
|
||||||
// tbbSave
|
// tbbSave
|
||||||
//
|
//
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the object used to marshal event-handler calls.
|
|
||||||
/// </summary>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a value indicating whether the Timer is running.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsRunning
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return running;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the timer capabilities.
|
|
||||||
/// </summary>
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user