diff --git a/Signal Generator/DrawTask.cs b/Signal Generator/DrawTask.cs index 1cffceb..dbc0e59 100644 --- a/Signal Generator/DrawTask.cs +++ b/Signal Generator/DrawTask.cs @@ -55,29 +55,37 @@ namespace Signal_Generator { double lastX = 0, lastY = 0; double W = canvas.ActualWidth; - double mod = (procedureModel.Duration / 1000) / W; + double dX = (procedureModel.Duration / 1000) / W; for (int X = 0; X != (int)W; X++) { - double Y = multiSignal.currentAmplitude(X * mod); - updateTextBoxProps(Y, X * mod); + double Y = multiSignal.currentAmplitude(X * dX); + updateTextBoxProps(Y, X * dX * 1000); drawLine(lastX, lastY, X, Y); lastX = X; lastY = Y; - Thread.Sleep(10); - switch (state) - { - case State.Paused: - while (state == State.Paused) - Thread.Sleep(50); - break; - case State.Canceled: return; - } + if (taskSemaphore() == false) return; } state = State.Finished; } + private bool taskSemaphore() + { + Thread.Sleep(10); + switch (state) + { + case State.Paused: + while (state == State.Paused) + Thread.Sleep(50); + break; + case State.Canceled: return false; + } + return true; + } + private void updateTextBoxProps(double amp, double time) { + amp = Math.Round(amp, 2); + time = Math.Round(time, 2); procedureModel.CurrentAmplitude = amp.ToString(); procedureModel.CurrentTime = time.ToString(); } diff --git a/Signal Generator/ProcedureModel.cs b/Signal Generator/ProcedureModel.cs index 776ec25..daceade 100644 --- a/Signal Generator/ProcedureModel.cs +++ b/Signal Generator/ProcedureModel.cs @@ -65,14 +65,11 @@ namespace Signal_Generator if (currentTask == null) return "Запустить"; switch (currentTask.state) { - case DrawTask.State.Created: - return "Запустить"; case DrawTask.State.Running: - return "Завершить"; case DrawTask.State.Paused: - goto case DrawTask.State.Running; + return "Завершить"; default: - goto case DrawTask.State.Created; + return "Запустить"; } } @@ -81,14 +78,12 @@ namespace Signal_Generator if (currentTask == null) return new Tuple(false, "Пауза"); switch (currentTask.state) { - case DrawTask.State.Created: - return new Tuple(false, "Пауза"); case DrawTask.State.Running: return new Tuple(true, "Пауза"); case DrawTask.State.Paused: return new Tuple(true, "Возобновить"); default: - goto case DrawTask.State.Created; + return new Tuple(false, "Пауза"); } } @@ -113,14 +108,13 @@ namespace Signal_Generator private void startOrCancelTask () { - targetCanvas.Children.Clear(); if (currentTask != null) switch (currentTask.state) { case DrawTask.State.Paused: - goto case DrawTask.State.Running; case DrawTask.State.Running: currentTask.state = DrawTask.State.Canceled; + targetCanvas.Children.Clear(); return; } Action newAction = () => diff --git a/Signal Generator/TaskWindow.xaml b/Signal Generator/TaskWindow.xaml index fa1aef6..8b6a7a7 100644 --- a/Signal Generator/TaskWindow.xaml +++ b/Signal Generator/TaskWindow.xaml @@ -30,10 +30,10 @@ - Время выполения: + Текущее время (t, мс): - Текущий сигнал: + Текущая амплитуда (y(t), В): Длительность (мс):