Browse Source

Реализован черновой вариант рендера сигнала

master
Никита 6 years ago
parent
commit
67dab7288c
  1. 9
      Signal Generator/MainWindow.xaml.cs
  2. 2
      Signal Generator/Signal/FmSignal.cs
  3. 6
      Signal Generator/Signal/MultiSignal.cs
  4. 2
      Signal Generator/Signal/SinusoidalSignal.cs
  5. 6
      Signal Generator/TaskWindow.xaml
  6. 40
      Signal Generator/TaskWindow.xaml.cs

9
Signal Generator/MainWindow.xaml.cs

@ -22,7 +22,7 @@ namespace Signal_Generator
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
AddSignalWindow addSignalWindow_Instance; AddSignalWindow addSignalWindow_Instance;
TaskWindow taskWindow_Instance = new TaskWindow(); TaskWindow taskWindow_Instance;
ObservableCollection<IAnalogSignal> signalCollection; ObservableCollection<IAnalogSignal> signalCollection;
public MainWindow() public MainWindow()
@ -52,11 +52,18 @@ namespace Signal_Generator
private void startProcedure_Button_Click(object sender, RoutedEventArgs e) private void startProcedure_Button_Click(object sender, RoutedEventArgs e)
{ {
MultiSignal ms = new MultiSignal();
foreach (IAnalogSignal item in signalCollection)
{
ms.add(item);
}
taskWindow_Instance = new TaskWindow(ms);
taskWindow_Instance.Show(); taskWindow_Instance.Show();
} }
private void removeSignal_Button_Click(object sender, RoutedEventArgs e) private void removeSignal_Button_Click(object sender, RoutedEventArgs e)
{ {
if (signals_ListBox.SelectedIndex == -1) return;
signalCollection.RemoveAt(signals_ListBox.SelectedIndex); signalCollection.RemoveAt(signals_ListBox.SelectedIndex);
} }
} }

2
Signal Generator/Signal/FmSignal.cs

@ -32,7 +32,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 * Math.PI * 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));
} }
} }
} }

6
Signal Generator/Signal/MultiSignal.cs

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Signal_Generator namespace Signal_Generator
{ {
class MultiSignal : IAnalogSignal public class MultiSignal : IAnalogSignal
{ {
private List<IAnalogSignal> signals { get; set; } private List<IAnalogSignal> signals { get; set; }
@ -16,12 +16,12 @@ namespace Signal_Generator
signals = new List<IAnalogSignal>(); signals = new List<IAnalogSignal>();
} }
public void add(IAnalogSignal signal) internal void add(IAnalogSignal signal)
{ {
signals.Add(signal); signals.Add(signal);
} }
public void remove(IAnalogSignal signal) internal void remove(IAnalogSignal signal)
{ {
signals.Remove(signal); signals.Remove(signal);
} }

2
Signal Generator/Signal/SinusoidalSignal.cs

@ -32,7 +32,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 * Math.PI * c[1].value * t + c[2].value); return c[0].value * Math.Sin(2.0 * 3.14 * c[1].value * t + c[2].value);
} }
} }
} }

6
Signal Generator/TaskWindow.xaml

@ -20,13 +20,13 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Canvas x:Name="signalGraph_Canvas" Grid.ColumnSpan="4" Margin="0,0,0,5"></Canvas> <Canvas x:Name="signalGraph_Canvas" Background="AliceBlue" Grid.ColumnSpan="4" Margin="0,0,0,5"/>
<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">Время выполения:</TextBlock>
<TextBox x:Name="currentTime_TextBox" Margin="0,0,0,5" Grid.Row="1" Grid.Column="2"/> <TextBox x:Name="currentTime_TextBox" Margin="0,0,0,5" Grid.Row="1" Grid.Column="2"/>
<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"/> <TextBox x:Name="currentAmplitude_TextBox" Margin="0,0,0,5" Grid.Row="2" Grid.Column="2"/>
<Button x:Name="start_Button" Width="60" Content="Старт" Margin="5,0" Grid.Row="3" Grid.Column="1"/> <Button x:Name="start_Button" Width="60" Content="Старт" Margin="5,0" Grid.Row="3" Grid.Column="1" Click="start_Button_Click"/>
<Button x:Name="pause_Button" Width="60" Content="Пауза" Margin="5,0" Grid.Row="3" Grid.Column="2"/> <Button x:Name="pause_Button" Width="60" Content="Пауза" Margin="5,0" Grid.Row="3" Grid.Column="2"/>
</Grid> </Grid>
</Window> </Window>

40
Signal Generator/TaskWindow.xaml.cs

@ -19,9 +19,47 @@ namespace Signal_Generator
/// </summary> /// </summary>
public partial class TaskWindow : Window public partial class TaskWindow : Window
{ {
public TaskWindow() MultiSignal currentMultiSignal;
public TaskWindow(MultiSignal s)
{ {
InitializeComponent(); InitializeComponent();
currentMultiSignal = s;
}
public void drawSignal(MultiSignal s)
{
double lastX = 0, lastY = 0;
double w = signalGraph_Canvas.ActualWidth;
for (int i = 0; i != (int)w; i++)
{
double y = s.currentAmplitude(i / 5.0);
drawLine(lastX, lastY, i, y);
lastX = i;
lastY = y;
}
}
public void drawLine (double x1, double y1, double x2, double y2)
{
Line l = new Line();
l.StrokeThickness = 1;
l.Stroke = Brushes.Red;
l.X1 = x1;
l.Y1 = remap(y1);
l.X2 = x2;
l.Y2 = remap(y2);
signalGraph_Canvas.Children.Add(l);
}
public double remap (double x, double oldMin = -100.0, double oldMax = 100.0, double newMin = 100.0, double newMax = 0.0)
{
newMin = signalGraph_Canvas.ActualHeight;
return newMin + (x - oldMin) * (newMax - newMin) / (oldMax - oldMin);
}
private void start_Button_Click(object sender, RoutedEventArgs e)
{
drawSignal(currentMultiSignal);
} }
} }
} }

Loading…
Cancel
Save