Browse Source

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

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

32
Signal Generator/DrawTask.cs

@ -55,29 +55,37 @@ namespace Signal_Generator
{ {
double lastX = 0, lastY = 0; double lastX = 0, lastY = 0;
double W = canvas.ActualWidth; double W = canvas.ActualWidth;
double mod = (procedureModel.Duration / 1000) / W; double dX = (procedureModel.Duration / 1000) / W;
for (int X = 0; X != (int)W; X++) for (int X = 0; X != (int)W; X++)
{ {
double Y = multiSignal.currentAmplitude(X * mod); double Y = multiSignal.currentAmplitude(X * dX);
updateTextBoxProps(Y, X * mod); updateTextBoxProps(Y, X * dX * 1000);
drawLine(lastX, lastY, X, Y); drawLine(lastX, lastY, X, Y);
lastX = X; lastX = X;
lastY = Y; lastY = Y;
Thread.Sleep(10); if (taskSemaphore() == false) return;
switch (state)
{
case State.Paused:
while (state == State.Paused)
Thread.Sleep(50);
break;
case State.Canceled: return;
}
} }
state = State.Finished; 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) private void updateTextBoxProps(double amp, double time)
{ {
amp = Math.Round(amp, 2);
time = Math.Round(time, 2);
procedureModel.CurrentAmplitude = amp.ToString(); procedureModel.CurrentAmplitude = amp.ToString();
procedureModel.CurrentTime = time.ToString(); procedureModel.CurrentTime = time.ToString();
} }

14
Signal Generator/ProcedureModel.cs

@ -65,14 +65,11 @@ namespace Signal_Generator
if (currentTask == null) return "Запустить"; if (currentTask == null) return "Запустить";
switch (currentTask.state) switch (currentTask.state)
{ {
case DrawTask.State.Created:
return "Запустить";
case DrawTask.State.Running: case DrawTask.State.Running:
return "Завершить";
case DrawTask.State.Paused: case DrawTask.State.Paused:
goto case DrawTask.State.Running; return "Завершить";
default: default:
goto case DrawTask.State.Created; return "Запустить";
} }
} }
@ -81,14 +78,12 @@ namespace Signal_Generator
if (currentTask == null) return new Tuple<bool, string>(false, "Пауза"); if (currentTask == null) return new Tuple<bool, string>(false, "Пауза");
switch (currentTask.state) switch (currentTask.state)
{ {
case DrawTask.State.Created:
return new Tuple<bool, string>(false, "Пауза");
case DrawTask.State.Running: case DrawTask.State.Running:
return new Tuple<bool, string>(true, "Пауза"); return new Tuple<bool, string>(true, "Пауза");
case DrawTask.State.Paused: case DrawTask.State.Paused:
return new Tuple<bool, string>(true, "Возобновить"); return new Tuple<bool, string>(true, "Возобновить");
default: default:
goto case DrawTask.State.Created; return new Tuple<bool, string>(false, "Пауза");
} }
} }
@ -113,14 +108,13 @@ namespace Signal_Generator
private void startOrCancelTask () private void startOrCancelTask ()
{ {
targetCanvas.Children.Clear();
if (currentTask != null) if (currentTask != null)
switch (currentTask.state) switch (currentTask.state)
{ {
case DrawTask.State.Paused: case DrawTask.State.Paused:
goto case DrawTask.State.Running;
case DrawTask.State.Running: case DrawTask.State.Running:
currentTask.state = DrawTask.State.Canceled; currentTask.state = DrawTask.State.Canceled;
targetCanvas.Children.Clear();
return; return;
} }
Action newAction = () => Action newAction = () =>

4
Signal Generator/TaskWindow.xaml

@ -30,10 +30,10 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Canvas x:Name="signalGraph_Canvas" Background="AliceBlue" Grid.ColumnSpan="4" Margin="0,0,0,5" ClipToBounds="True"/> <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" <TextBox x:Name="currentTime_TextBox" Margin="0,0,0,5" Grid.Row="1" Grid.Column="2" IsEnabled="False"
Text="{Binding Path=CurrentTime}"/> 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" <TextBox x:Name="currentAmplitude_TextBox" Margin="0,0,0,5" Grid.Row="2" Grid.Column="2" IsEnabled="False"
Text="{Binding Path=CurrentAmplitude}"/> Text="{Binding Path=CurrentAmplitude}"/>
<TextBlock x:Name="duration_TextBlock" Margin="0,0,5,5" Grid.Row="3" Grid.Column="1">Длительность (мс):</TextBlock> <TextBlock x:Name="duration_TextBlock" Margin="0,0,5,5" Grid.Row="3" Grid.Column="1">Длительность (мс):</TextBlock>

Loading…
Cancel
Save