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/FmSignal.cs
  5. 2
      Signal Generator/Signal/SinusoidalSignal.cs
  6. 23
      Signal Generator/StringDoubleConverter.cs
  7. 9
      Signal Generator/TaskWindow.xaml

33
Signal Generator/DrawTask.cs

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

11
Signal Generator/ProcedureModel.cs

@ -167,5 +167,16 @@ namespace Signal_Generator
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\SinusoidalSignal.cs" />
<Compile Include="ArrayConverter.cs" />
<Compile Include="StringDoubleConverter.cs" />
<Compile Include="TaskWindow.xaml.cs">
<DependentUpon>TaskWindow.xaml</DependentUpon>
</Compile>

2
Signal Generator/Signal/FmSignal.cs

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

2
Signal Generator/Signal/SinusoidalSignal.cs

@ -27,7 +27,7 @@ namespace Signal_Generator
public double currentAmplitude(double t)
{
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>
<local:ProcedureModel x:Key="ProcedureModel"/>
<local:ArrayConverter x:Key="ArrayConverter"/>
<local:StringDoubleConverter x:Key="StringDoubleConverter"/>
</Window.Resources>
<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"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
@ -34,7 +36,10 @@
<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"
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}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource ArrayConverter}">
@ -45,7 +50,7 @@
</MultiBinding>
</Button.CommandParameter>
</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}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource ArrayConverter}">

Loading…
Cancel
Save