From e05d3f1f3b29e13b65db75c1a729051b841c1200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Sun, 11 Nov 2018 03:03:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B8=D0=B2=D1=8F=D0=B7=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D1=85=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9.=20=D0=A2?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B2=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F=D1=85=20=D0=B2=20=D1=80=D0=B5=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=20=D1=81=D0=B8=D0=B3=D0=BD=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...TaskViewConverter.cs => ArrayConverter.cs} | 0 Signal Generator/DrawTask.cs | 21 ++++-------- Signal Generator/ProcedureModel.cs | 34 ++++++++++++++++--- Signal Generator/Signal Generator.csproj | 2 +- Signal Generator/TaskWindow.xaml | 16 ++++++--- 5 files changed, 49 insertions(+), 24 deletions(-) rename Signal Generator/{TaskViewConverter.cs => ArrayConverter.cs} (100%) diff --git a/Signal Generator/TaskViewConverter.cs b/Signal Generator/ArrayConverter.cs similarity index 100% rename from Signal Generator/TaskViewConverter.cs rename to Signal Generator/ArrayConverter.cs diff --git a/Signal Generator/DrawTask.cs b/Signal Generator/DrawTask.cs index 58da12f..efebd93 100644 --- a/Signal Generator/DrawTask.cs +++ b/Signal Generator/DrawTask.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; @@ -7,6 +8,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Timers; +using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; @@ -16,9 +18,8 @@ namespace Signal_Generator public class DrawTask : Task, INotifyPropertyChanged { Canvas canvas; - System.Timers.Timer taskTimer; - Stopwatch stopwatch = new Stopwatch(); MultiSignal multiSignal; + ProcedureModel procedureModel; private State _state; public State state @@ -40,25 +41,15 @@ namespace Signal_Generator public DrawTask(Action a) : base(a) { } - public void buildTask(Canvas c) + public void buildTask(ProcedureModel pm, Canvas c) { canvas = c; + procedureModel = pm; multiSignal = MultiSignal.getInstance(); state = State.Running; - stopwatch.Start(); - taskTimer = new System.Timers.Timer(2000); - taskTimer.Elapsed += updateTextForms; - taskTimer.Enabled = true; - drawSignalAtCanvas(); } - - - private void updateTextForms(object sender, ElapsedEventArgs e) - { - var elapsed = stopwatch.ElapsedMilliseconds; - } private void drawSignalAtCanvas() { @@ -66,6 +57,8 @@ namespace Signal_Generator double w = canvas.ActualWidth; for (int i = 0; i != (int)w; i++) { + procedureModel.CurrentAmplitude = multiSignal.currentAmplitude(i / 5.0).ToString(); + procedureModel.CurrentTime = (i / 5.0).ToString(); double y = multiSignal.currentAmplitude(i / 5.0); drawLine(lastX, lastY, i, y); lastX = i; diff --git a/Signal Generator/ProcedureModel.cs b/Signal Generator/ProcedureModel.cs index 99a6e49..3a1a45d 100644 --- a/Signal Generator/ProcedureModel.cs +++ b/Signal Generator/ProcedureModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; @@ -8,10 +9,11 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Shapes; namespace Signal_Generator { - public class ProcedureModel : ICommand + public class ProcedureModel : ICommand, INotifyPropertyChanged { public DrawTask currentTask; Canvas targetCanvas; @@ -43,7 +45,7 @@ namespace Signal_Generator var btn = parameters[0] as Button; var ms = MultiSignal.getInstance(); - if ((ms == null) && (ms.count() == 0)) + if ((ms == null) || (ms.count() == 0)) return false; switch (btn.Name) { @@ -95,7 +97,8 @@ namespace Signal_Generator var parameters = parameter as object[]; var btn = parameters[0] as Button; targetCanvas = parameters[1] as Canvas; - + + switch (btn.Name) { case "start_Button": @@ -123,7 +126,7 @@ namespace Signal_Generator Action newAction = () => { currentTask.PropertyChanged += RaiseCanExecuteChanged; - currentTask.buildTask(targetCanvas); + currentTask.buildTask(this, targetCanvas); }; currentTask = new DrawTask(newAction); currentTask.Start(); @@ -141,5 +144,28 @@ namespace Signal_Generator break; } } + + public event PropertyChangedEventHandler PropertyChanged; + private string currentAmplitude; + public string CurrentAmplitude + { + get { return currentAmplitude; } + set + { + currentAmplitude = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentAmplitude")); + } + } + + private string currentTime; + public string CurrentTime + { + get { return currentTime; } + set + { + currentTime = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentTime")); + } + } } } diff --git a/Signal Generator/Signal Generator.csproj b/Signal Generator/Signal Generator.csproj index c9bac2e..af53227 100644 --- a/Signal Generator/Signal Generator.csproj +++ b/Signal Generator/Signal Generator.csproj @@ -65,7 +65,7 @@ - + TaskWindow.xaml diff --git a/Signal Generator/TaskWindow.xaml b/Signal Generator/TaskWindow.xaml index 4db8b83..aad6f82 100644 --- a/Signal Generator/TaskWindow.xaml +++ b/Signal Generator/TaskWindow.xaml @@ -13,7 +13,7 @@ - + @@ -26,18 +26,22 @@ - - + + Время выполения: - + Текущий сигнал: - + @@ -47,6 +51,8 @@ + +