You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.7 KiB
90 lines
2.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace Signal_Generator
|
|
{
|
|
public class DrawTask : Task
|
|
{
|
|
Canvas currentCanvas;
|
|
System.Timers.Timer taskTimer;
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
MultiSignal currentMultiSignal;
|
|
public DStatus dStatus;
|
|
public enum DStatus
|
|
{
|
|
Created, Running, Paused, Finished, Canceled
|
|
}
|
|
|
|
public DrawTask(Action a) : base(a) { }
|
|
|
|
public void buildTask(MultiSignal s, Canvas c)
|
|
{
|
|
currentCanvas = c;
|
|
currentMultiSignal = s;
|
|
dStatus = DStatus.Running;
|
|
drawSignalAtCanvas();
|
|
stopwatch.Start();
|
|
taskTimer = new System.Timers.Timer(2000);
|
|
taskTimer.Elapsed += updateTextForms;
|
|
taskTimer.Enabled = true;
|
|
}
|
|
|
|
private void updateTextForms(object sender, ElapsedEventArgs e)
|
|
{
|
|
var elapsed = stopwatch.ElapsedMilliseconds;
|
|
}
|
|
|
|
private void drawSignalAtCanvas()
|
|
{
|
|
double lastX = 0, lastY = 0;
|
|
double w = currentCanvas.ActualWidth;
|
|
for (int i = 0; i != (int)w; i++)
|
|
{
|
|
double y = currentMultiSignal.currentAmplitude(i / 5.0);
|
|
drawLine(lastX, lastY, i, y);
|
|
lastX = i;
|
|
lastY = y;
|
|
Thread.Sleep(10);
|
|
switch (dStatus)
|
|
{
|
|
case DStatus.Paused:
|
|
while (dStatus == DStatus.Paused)
|
|
Thread.Sleep(10);
|
|
break;
|
|
case DStatus.Canceled: return;
|
|
}
|
|
}
|
|
dStatus = DStatus.Finished;
|
|
}
|
|
|
|
private void drawLine(double x1, double y1, double x2, double y2)
|
|
{
|
|
Action a = () => {
|
|
Line l = new Line();
|
|
l.StrokeThickness = 1;
|
|
l.Stroke = Brushes.Red;
|
|
l.X1 = x1;
|
|
l.Y1 = remap(y1);
|
|
l.X2 = x2;
|
|
l.Y2 = remap(y2);
|
|
currentCanvas.Children.Add(l);
|
|
};
|
|
currentCanvas.Dispatcher.Invoke(a);
|
|
}
|
|
|
|
private double remap(double x, double oldMin = -100.0, double oldMax = 100.0, double newMin = 100.0, double newMax = 0.0)
|
|
{
|
|
newMin = currentCanvas.ActualHeight;
|
|
return newMin + (x - oldMin) * (newMax - newMin) / (oldMax - oldMin);
|
|
}
|
|
}
|
|
}
|
|
|