Compare commits

...

2 Commits

  1. 4
      Signal Generator/AddSignalWindow.xaml.cs
  2. 5
      Signal Generator/MainWindow.xaml
  3. 46
      Signal Generator/MainWindow.xaml.cs
  4. 2
      Signal Generator/Signal/FmSignal.cs
  5. 26
      Signal Generator/Signal/MultiSignal.cs
  6. 2
      Signal Generator/Signal/SinusoidalSignal.cs
  7. 4
      Signal Generator/TaskWindow.xaml
  8. 40
      Signal Generator/TaskWindow.xaml.cs

4
Signal Generator/AddSignalWindow.xaml.cs

@ -21,9 +21,13 @@ namespace Signal_Generator
public partial class AddSignalWindow : Window public partial class AddSignalWindow : Window
{ {
ObservableCollection<Parameter> signalProps = new ObservableCollection<Parameter>(); ObservableCollection<Parameter> signalProps = new ObservableCollection<Parameter>();
ObservableCollection<IAnalogSignal> typesOfSignal = new ObservableCollection<IAnalogSignal>();
public AddSignalWindow() public AddSignalWindow()
{ {
InitializeComponent(); InitializeComponent();
typesOfSignal.Add(new SinusoidalSignal(0, 0));
typesOfSignal.Add(new FmSignal(0, 0, 0));
signalType_ComboBox.ItemsSource = typesOfSignal;
signalProps_DataGrid.ItemsSource = signalProps; signalProps_DataGrid.ItemsSource = signalProps;
} }

5
Signal Generator/MainWindow.xaml

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Signal_Generator" xmlns:local="clr-namespace:Signal_Generator"
mc:Ignorable="d" mc:Ignorable="d"
Title="Генератор сигналов" Height="450" Width="489"> Title="Генератор сигналов" Height="450" Width="600">
<Grid Margin="10"> <Grid Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
@ -39,6 +39,7 @@
Grid.Row="2" Margin="5,0,0,0"/> Grid.Row="2" Margin="5,0,0,0"/>
<Button x:Name="addSignal_Button" Width="20" Content="+" Margin="0,0,5,0" Click="addSignal_Button_Click" Grid.Row="2" <Button x:Name="addSignal_Button" Width="20" Content="+" Margin="0,0,5,0" Click="addSignal_Button_Click" Grid.Row="2"
Grid.Column="2"/> Grid.Column="2"/>
<Button x:Name="removeSignal_Button" Width="20" Margin="0,0,5,0" Content="-" Grid.Row="2" Grid.Column="3"/> <Button x:Name="removeSignal_Button" Width="20" Margin="0,0,5,0" Content="-" Grid.Row="2" Grid.Column="3"
Click="removeSignal_Button_Click"/>
</Grid> </Grid>
</Window> </Window>

46
Signal Generator/MainWindow.xaml.cs

@ -21,44 +21,50 @@ namespace Signal_Generator
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
AddSignalWindow addSignalWindow_Instance = new AddSignalWindow(); AddSignalWindow addSignalWindow_Instance;
TaskWindow taskWindow_Instance = new TaskWindow(); TaskWindow taskWindow_Instance;
ObservableCollection<IAnalogSignal> s; ObservableCollection<IAnalogSignal> signalCollection;
ObservableCollection<IAnalogSignal> typesOfSignal = new ObservableCollection<IAnalogSignal>();
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
signalCollection = new ObservableCollection<IAnalogSignal>();
typesOfSignal.Add(new SinusoidalSignal(0, 0));
typesOfSignal.Add(new FmSignal(0, 0, 0));
addSignalWindow_Instance.signalType_ComboBox.ItemsSource = typesOfSignal;
s = new ObservableCollection<IAnalogSignal>();
signals_ListBox.Items.Clear(); signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = s; signals_ListBox.ItemsSource = signalCollection;
addSignalWindow_Instance.Closed += addSignalWindow_Instance_Closed;
} }
private void addSignalWindow_Instance_Closed(object sender, EventArgs e) private void addSignal_Button_Click(object sender, RoutedEventArgs e)
{ {
addSignalWindow_Instance = new AddSignalWindow();
addSignalWindow_Instance.createItem_Button.Click += addSignalWindow_Instance_Closing;
addSignalWindow_Instance.Show();
} }
private void addSomeExtra() private void addSignalWindow_Instance_Closing(object sender, EventArgs e)
{ {
SinusoidalSignal s1 = new SinusoidalSignal(1, 50); var signal = null as IAnalogSignal;
s.Add(s1); signal = (IAnalogSignal) addSignalWindow_Instance.signalType_ComboBox.SelectedItem;
if (addSignalWindow_Instance.signalType_ComboBox.SelectedItem == null) return;
signalCollection.Add(signal);
addSignalWindow_Instance.Close();
} }
private void addSignal_Button_Click(object sender, RoutedEventArgs e) private void startProcedure_Button_Click(object sender, RoutedEventArgs e)
{ {
addSignalWindow_Instance.Show(); MultiSignal ms = new MultiSignal();
foreach (IAnalogSignal item in signalCollection)
{
ms.add(item);
}
taskWindow_Instance = new TaskWindow(ms);
taskWindow_Instance.Show();
} }
private void startProcedure_Button_Click(object sender, RoutedEventArgs e) private void removeSignal_Button_Click(object sender, RoutedEventArgs e)
{ {
taskWindow_Instance.Show(); if (signals_ListBox.SelectedIndex == -1) return;
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));
} }
} }
} }

26
Signal Generator/Signal/MultiSignal.cs

@ -7,31 +7,21 @@ using System.Threading.Tasks;
namespace Signal_Generator namespace Signal_Generator
{ {
class MultiSignal : IAnalogSignal public class MultiSignal : IAnalogSignal
{ {
private string paramsToString { get; }
private List<IAnalogSignal> signals { get; set; } private List<IAnalogSignal> signals { get; set; }
private Dictionary<string, double> paramsDict { get; set; }
public string typeToString => throw new NotImplementedException();
string IAnalogSignal.paramsToString => throw new NotImplementedException();
string IAnalogSignal.typeToString => throw new NotImplementedException();
Collection<Parameter> IAnalogSignal.paramsCollection { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public MultiSignal() public MultiSignal()
{ {
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);
} }
@ -46,6 +36,16 @@ namespace Signal_Generator
return summaryAmplitude; return summaryAmplitude;
} }
// Неиспользуемые поля и методы
public string typeToString => throw new NotImplementedException();
string IAnalogSignal.paramsToString => throw new NotImplementedException();
string IAnalogSignal.typeToString => throw new NotImplementedException();
Collection<Parameter> IAnalogSignal.paramsCollection { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
double IAnalogSignal.currentAmplitude(double t) double IAnalogSignal.currentAmplitude(double t)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

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);
} }
} }
} }

4
Signal Generator/TaskWindow.xaml

@ -21,12 +21,12 @@
<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