From 42d419a24ffe05dfcb8d1cb01a932df54b07e6d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Fri, 9 Nov 2018 01:50:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B8=D1=87=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=B0=D1=83=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D0=B4=D1=83=D1=80?= =?UTF-8?q?=D1=8B=20=D0=BF=D1=80=D0=B8=20=D0=BF=D0=BE=D0=BC=D0=BE=D1=89?= =?UTF-8?q?=D0=B8=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20DrawTask?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Signal Generator/DrawTask.cs | 90 ++++++++++++++++++++++++ Signal Generator/Signal Generator.csproj | 1 + Signal Generator/TaskWindow.xaml | 6 +- Signal Generator/TaskWindow.xaml.cs | 62 ++++++++-------- 4 files changed, 128 insertions(+), 31 deletions(-) create mode 100644 Signal Generator/DrawTask.cs diff --git a/Signal Generator/DrawTask.cs b/Signal Generator/DrawTask.cs new file mode 100644 index 0000000..d0e5ffd --- /dev/null +++ b/Signal Generator/DrawTask.cs @@ -0,0 +1,90 @@ +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); + } + } +} diff --git a/Signal Generator/Signal Generator.csproj b/Signal Generator/Signal Generator.csproj index 6c67525..f43c494 100644 --- a/Signal Generator/Signal Generator.csproj +++ b/Signal Generator/Signal Generator.csproj @@ -58,6 +58,7 @@ AddSignalWindow.xaml + diff --git a/Signal Generator/TaskWindow.xaml b/Signal Generator/TaskWindow.xaml index dc0a050..20cbddd 100644 --- a/Signal Generator/TaskWindow.xaml +++ b/Signal Generator/TaskWindow.xaml @@ -26,7 +26,9 @@ Текущий сигнал: -