Browse Source

Немного рефакторинга + изменения на форме выполнения процедуры

master
Никита 6 years ago
parent
commit
6fa2a7fe27
  1. 20
      Signal Generator/DrawTask.cs
  2. 14
      Signal Generator/ProcedureModel.cs
  3. 4
      Signal Generator/TaskWindow.xaml

20
Signal Generator/DrawTask.cs

@ -55,14 +55,21 @@ 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;
if (taskSemaphore() == false) return;
}
state = State.Finished;
}
private bool taskSemaphore()
{
Thread.Sleep(10);
switch (state)
{
@ -70,14 +77,15 @@ namespace Signal_Generator
while (state == State.Paused)
Thread.Sleep(50);
break;
case State.Canceled: return;
}
case State.Canceled: return false;
}
state = State.Finished;
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();
}

14
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<bool, string>(false, "Пауза");
switch (currentTask.state)
{
case DrawTask.State.Created:
return new Tuple<bool, string>(false, "Пауза");
case DrawTask.State.Running:
return new Tuple<bool, string>(true, "Пауза");
case DrawTask.State.Paused:
return new Tuple<bool, string>(true, "Возобновить");
default:
goto case DrawTask.State.Created;
return new Tuple<bool, string>(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 = () =>

4
Signal Generator/TaskWindow.xaml

@ -30,10 +30,10 @@
</Grid.ColumnDefinitions>
<Canvas x:Name="signalGraph_Canvas" Background="AliceBlue" Grid.ColumnSpan="4" Margin="0,0,0,5" ClipToBounds="True"/>
<TextBlock x:Name="currentTime_TextBlock" Margin="0,0,5,5" Grid.Row="1" Grid.Column="1">Время выполения:</TextBlock>
<TextBlock x:Name="currentTime_TextBlock" Margin="0,0,5,5" Grid.Row="1" Grid.Column="1">Текущее время (t, мс):</TextBlock>
<TextBox x:Name="currentTime_TextBox" Margin="0,0,0,5" Grid.Row="1" Grid.Column="2" IsEnabled="False"
Text="{Binding Path=CurrentTime}"/>
<TextBlock x:Name="currentAmplitude_TextBlock" Margin="0,0,5,5" Grid.Row="2" Grid.Column="1">Текущий сигнал:</TextBlock>
<TextBlock x:Name="currentAmplitude_TextBlock" Margin="0,0,5,5" Grid.Row="2" Grid.Column="1">Текущая амплитуда (y(t), В):</TextBlock>
<TextBox x:Name="currentAmplitude_TextBox" Margin="0,0,0,5" Grid.Row="2" Grid.Column="2" IsEnabled="False"
Text="{Binding Path=CurrentAmplitude}"/>
<TextBlock x:Name="duration_TextBlock" Margin="0,0,5,5" Grid.Row="3" Grid.Column="1">Длительность (мс):</TextBlock>

Loading…
Cancel
Save