Compare commits

...

2 Commits

  1. 4
      Signal Generator/AddSignalWindow.xaml.cs
  2. 5
      Signal Generator/MainWindow.xaml
  3. 50
      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. 6
      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
{
ObservableCollection<Parameter> signalProps = new ObservableCollection<Parameter>();
ObservableCollection<IAnalogSignal> typesOfSignal = new ObservableCollection<IAnalogSignal>();
public AddSignalWindow()
{
InitializeComponent();
typesOfSignal.Add(new SinusoidalSignal(0, 0));
typesOfSignal.Add(new FmSignal(0, 0, 0));
signalType_ComboBox.ItemsSource = typesOfSignal;
signalProps_DataGrid.ItemsSource = signalProps;
}

5
Signal Generator/MainWindow.xaml

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Signal_Generator"
mc:Ignorable="d"
Title="Генератор сигналов" Height="450" Width="489">
Title="Генератор сигналов" Height="450" Width="600">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
@ -39,6 +39,7 @@
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"
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>
</Window>

50
Signal Generator/MainWindow.xaml.cs

@ -21,44 +21,50 @@ namespace Signal_Generator
/// </summary>
public partial class MainWindow : Window
{
AddSignalWindow addSignalWindow_Instance = new AddSignalWindow();
TaskWindow taskWindow_Instance = new TaskWindow();
ObservableCollection<IAnalogSignal> s;
ObservableCollection<IAnalogSignal> typesOfSignal = new ObservableCollection<IAnalogSignal>();
AddSignalWindow addSignalWindow_Instance;
TaskWindow taskWindow_Instance;
ObservableCollection<IAnalogSignal> signalCollection;
public MainWindow()
{
InitializeComponent();
typesOfSignal.Add(new SinusoidalSignal(0, 0));
typesOfSignal.Add(new FmSignal(0, 0, 0));
addSignalWindow_Instance.signalType_ComboBox.ItemsSource = typesOfSignal;
s = new ObservableCollection<IAnalogSignal>();
signalCollection = new ObservableCollection<IAnalogSignal>();
signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = s;
addSignalWindow_Instance.Closed += addSignalWindow_Instance_Closed;
signals_ListBox.ItemsSource = signalCollection;
}
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);
s.Add(s1);
}
var signal = null as IAnalogSignal;
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)
{
addSignalWindow_Instance.Show();
}
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();
}
private void removeSignal_Button_Click(object sender, RoutedEventArgs e)
{
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)
{
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
{
class MultiSignal : IAnalogSignal
public class MultiSignal : IAnalogSignal
{
private string paramsToString { get; }
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()
{
signals = new List<IAnalogSignal>();
}
public void add(IAnalogSignal signal)
internal void add(IAnalogSignal signal)
{
signals.Add(signal);
}
public void remove(IAnalogSignal signal)
internal void remove(IAnalogSignal signal)
{
signals.Remove(signal);
}
@ -46,6 +36,16 @@ namespace Signal_Generator
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)
{
throw new NotImplementedException();

2
Signal Generator/Signal/SinusoidalSignal.cs

@ -32,7 +32,7 @@ namespace Signal_Generator
public double currentAmplitude(double t)
{
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="*"/>
</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>
<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>
<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"/>
</Grid>
</Window>

40
Signal Generator/TaskWindow.xaml.cs

@ -19,9 +19,47 @@ namespace Signal_Generator
/// </summary>
public partial class TaskWindow : Window
{
public TaskWindow()
MultiSignal currentMultiSignal;
public TaskWindow(MultiSignal s)
{
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