Compare commits

...

2 Commits

  1. 33
      Signal Generator/DrawTask.cs
  2. 11
      Signal Generator/ProcedureModel.cs
  3. 1
      Signal Generator/Signal Generator.csproj
  4. 2
      Signal Generator/Signal/SinusoidalSignal.cs
  5. 23
      Signal Generator/StringDoubleConverter.cs
  6. 9
      Signal Generator/TaskWindow.xaml

33
Signal Generator/DrawTask.cs

@ -54,21 +54,21 @@ namespace Signal_Generator
private void drawSignalAtCanvas() private void drawSignalAtCanvas()
{ {
double lastX = 0, lastY = 0; double lastX = 0, lastY = 0;
double w = canvas.ActualWidth; double W = canvas.ActualWidth;
for (int i = 0; i != (int)w; i++) double mod = (procedureModel.Duration / 1000) / W;
for (int X = 0; X != (int)W; X++)
{ {
procedureModel.CurrentAmplitude = multiSignal.currentAmplitude(i / 5.0).ToString(); double Y = multiSignal.currentAmplitude(X * mod);
procedureModel.CurrentTime = (i / 5.0).ToString(); updateTextBoxProps(Y, X * mod);
double y = multiSignal.currentAmplitude(i / 5.0); drawLine(lastX, lastY, X, Y);
drawLine(lastX, lastY, i, y); lastX = X;
lastX = i; lastY = Y;
lastY = y;
Thread.Sleep(10); Thread.Sleep(10);
switch (state) switch (state)
{ {
case State.Paused: case State.Paused:
while (state == State.Paused) while (state == State.Paused)
Thread.Sleep(10); Thread.Sleep(50);
break; break;
case State.Canceled: return; case State.Canceled: return;
} }
@ -76,6 +76,12 @@ namespace Signal_Generator
state = State.Finished; state = State.Finished;
} }
private void updateTextBoxProps(double amp, double time)
{
procedureModel.CurrentAmplitude = amp.ToString();
procedureModel.CurrentTime = time.ToString();
}
private void drawLine(double x1, double y1, double x2, double y2) private void drawLine(double x1, double y1, double x2, double y2)
{ {
Action a = () => { Action a = () => {
@ -83,18 +89,17 @@ namespace Signal_Generator
l.StrokeThickness = 1; l.StrokeThickness = 1;
l.Stroke = Brushes.Red; l.Stroke = Brushes.Red;
l.X1 = x1; l.X1 = x1;
l.Y1 = remap(y1); l.Y1 = remapOY(y1, 100, canvas.ActualHeight);
l.X2 = x2; l.X2 = x2;
l.Y2 = remap(y2); l.Y2 = remapOY(y2, 100, canvas.ActualHeight);
canvas.Children.Add(l); canvas.Children.Add(l);
}; };
canvas.Dispatcher.Invoke(a); canvas.Dispatcher.Invoke(a);
} }
private double remap(double x, double oldMin = -100.0, double oldMax = 100.0, double newMin = 100.0, double newMax = 0.0) private double remapOY(double x, double amp = 100.0, double height = 100.0)
{ {
newMin = canvas.ActualHeight; return height + (x + amp) * (-height) / (2 * amp);
return newMin + (x - oldMin) * (newMax - newMin) / (oldMax - oldMin);
} }
} }
} }

11
Signal Generator/ProcedureModel.cs

@ -167,5 +167,16 @@ namespace Signal_Generator
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentTime")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentTime"));
} }
} }
private double duration = 1000;
public double Duration
{
get { return duration; }
set
{
duration = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentTime"));
}
}
} }
} }

1
Signal Generator/Signal Generator.csproj

@ -66,6 +66,7 @@
<Compile Include="Signal\Base\Parameter.cs" /> <Compile Include="Signal\Base\Parameter.cs" />
<Compile Include="Signal\SinusoidalSignal.cs" /> <Compile Include="Signal\SinusoidalSignal.cs" />
<Compile Include="ArrayConverter.cs" /> <Compile Include="ArrayConverter.cs" />
<Compile Include="StringDoubleConverter.cs" />
<Compile Include="TaskWindow.xaml.cs"> <Compile Include="TaskWindow.xaml.cs">
<DependentUpon>TaskWindow.xaml</DependentUpon> <DependentUpon>TaskWindow.xaml</DependentUpon>
</Compile> </Compile>

2
Signal Generator/Signal/SinusoidalSignal.cs

@ -27,7 +27,7 @@ namespace Signal_Generator
public double currentAmplitude(double t) public double currentAmplitude(double t)
{ {
var c = paramsCollection.ToArray<Parameter>(); var c = paramsCollection.ToArray<Parameter>();
return c[0].value * Math.Sin(2.0 * 3.14 * c[1].value * t + c[2].value); return c[0].value * Math.Sin(2.0 * 3.14 * c[1].value * t + c[2].value * 180 / 3.14);
} }
} }
} }

23
Signal Generator/StringDoubleConverter.cs

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Signal_Generator
{
class StringDoubleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((double)value).ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return double.Parse((string)value);
}
}
}

9
Signal Generator/TaskWindow.xaml

@ -11,6 +11,7 @@
<Window.Resources> <Window.Resources>
<local:ProcedureModel x:Key="ProcedureModel"/> <local:ProcedureModel x:Key="ProcedureModel"/>
<local:ArrayConverter x:Key="ArrayConverter"/> <local:ArrayConverter x:Key="ArrayConverter"/>
<local:StringDoubleConverter x:Key="StringDoubleConverter"/>
</Window.Resources> </Window.Resources>
<Grid Margin="10" Loaded="Grid_Loaded" DataContext="{Binding Source={StaticResource ProcedureModel}}"> <Grid Margin="10" Loaded="Grid_Loaded" DataContext="{Binding Source={StaticResource ProcedureModel}}">
@ -19,6 +20,7 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@ -34,7 +36,10 @@
<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">Текущий сигнал:</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}"/>
<Button x:Name="start_Button" Width="120" Content="Запустить" Margin="5,0" Grid.Row="3" Grid.Column="0" <TextBlock x:Name="duration_TextBlock" Margin="0,0,5,5" Grid.Row="3" Grid.Column="1">Длительность (мс):</TextBlock>
<TextBox x:Name="duration_TextBox" Margin="0,0,0,5" Grid.Row="3" Grid.Column="2"
Text="{Binding Duration, Converter={StaticResource StringDoubleConverter}, Mode=TwoWay}"/>
<Button x:Name="start_Button" Width="120" Content="Запустить" Margin="5,0" Grid.Row="4" Grid.Column="0"
Grid.ColumnSpan="2" Command="{StaticResource ProcedureModel}"> Grid.ColumnSpan="2" Command="{StaticResource ProcedureModel}">
<Button.CommandParameter> <Button.CommandParameter>
<MultiBinding Converter="{StaticResource ArrayConverter}"> <MultiBinding Converter="{StaticResource ArrayConverter}">
@ -45,7 +50,7 @@
</MultiBinding> </MultiBinding>
</Button.CommandParameter> </Button.CommandParameter>
</Button> </Button>
<Button x:Name="pause_Button" Width="120" Content="Приостановить" Margin="5,0" Grid.Row="3" Grid.Column="2" <Button x:Name="pause_Button" Width="120" Content="Приостановить" Margin="5,0" Grid.Row="4" Grid.Column="2"
Grid.ColumnSpan="2" Command="{StaticResource ProcedureModel}"> Grid.ColumnSpan="2" Command="{StaticResource ProcedureModel}">
<Button.CommandParameter> <Button.CommandParameter>
<MultiBinding Converter="{StaticResource ArrayConverter}"> <MultiBinding Converter="{StaticResource ArrayConverter}">

Loading…
Cancel
Save