Compare commits

...

2 Commits

  1. 2
      Signal Generator/MainWindow.xaml
  2. 7
      Signal Generator/MainWindow.xaml.cs
  3. 29
      Signal Generator/Settings.cs
  4. 1
      Signal Generator/Signal/Base/AnalogSignalMethods.cs
  5. 1
      Signal Generator/Signal/Base/Parameter.cs
  6. 13
      Signal Generator/Signal/FmSignal.cs
  7. 4
      Signal Generator/Signal/MultiSignal.cs
  8. 11
      Signal Generator/Signal/SinusoidalSignal.cs

2
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="600">
Title="Генератор сигналов" Height="450" Width="600" Closing="Window_Closing">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>

7
Signal Generator/MainWindow.xaml.cs

@ -28,6 +28,8 @@ namespace Signal_Generator
public MainWindow()
{
InitializeComponent();
var c = Properties.Settings.LoadSignals();
if (c != null) multiSignal.signals = c;
signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = multiSignal.signals;
}
@ -69,5 +71,10 @@ namespace Signal_Generator
var x = signals_ListBox.SelectedItem as IAnalogSignal;
multiSignal.Remove(x);
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Properties.Settings.SaveSignals(multiSignal.signals);
}
}
}

29
Signal Generator/Settings.cs

@ -1,4 +1,8 @@
namespace Signal_Generator.Properties {
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Signal_Generator.Properties {
// Этот класс позволяет обрабатывать определенные события в классе параметров:
@ -11,9 +15,9 @@
public Settings() {
// // Для добавления обработчиков событий для сохранения и изменения параметров раскомментируйте приведенные ниже строки:
//
// this.SettingChanging += this.SettingChangingEventHandler;
this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
this.SettingsSaving += this.SettingsSavingEventHandler;
//
}
@ -24,5 +28,24 @@
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Добавьте здесь код для обработки события SettingsSaving.
}
public static void SaveSignals(ObservableCollection<IAnalogSignal> signals)
{
BinaryFormatter formatter = new BinaryFormatter();
using (FileStream fs = new FileStream("settings.dat", FileMode.OpenOrCreate))
{
formatter.Serialize(fs, signals);
}
}
public static ObservableCollection<IAnalogSignal> LoadSignals()
{
BinaryFormatter formatter = new BinaryFormatter();
using (FileStream fs = new FileStream("settings.dat", FileMode.Open))
{
if (!fs.CanRead) return null;
return (ObservableCollection<IAnalogSignal>)formatter.Deserialize(fs);
}
}
}
}

1
Signal Generator/Signal/Base/AnalogSignalMethods.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace Signal_Generator
{
[Serializable]
class AnalogSignalMethods
{
protected string paramsToString(Collection<Parameter> paramsCollection)

1
Signal Generator/Signal/Base/Parameter.cs

@ -6,6 +6,7 @@ using System.Threading.Tasks;
namespace Signal_Generator
{
[Serializable]
class Parameter
{
public string name { get; set; }

13
Signal Generator/Signal/FmSignal.cs

@ -7,20 +7,15 @@ using System.Threading.Tasks;
namespace Signal_Generator
{
[Serializable]
class FmSignal : AnalogSignalMethods, IAnalogSignal
{
public Collection<Parameter> paramsCollection { get; set; }
public string typeToString
{
get { return "FM сигнал"; }
}
public new string paramsToString
{
get { return paramsToString(paramsCollection); }
}
public string typeToString => "FM сигнал";
public new string paramsToString => paramsToString(paramsCollection);
public FmSignal(double ampl, double freq, double ampl2)
{
paramsCollection = new Collection<Parameter>();

4
Signal Generator/Signal/MultiSignal.cs

@ -10,7 +10,7 @@ namespace Signal_Generator
public class MultiSignal : IAnalogSignal
{
private static MultiSignal instance;
internal ObservableCollection<IAnalogSignal> signals { get; private set; }
internal ObservableCollection<IAnalogSignal> signals { get; set; }
private MultiSignal()
{
@ -43,9 +43,7 @@ namespace Signal_Generator
{
double summaryAmplitude = 0;
foreach (IAnalogSignal item in signals)
{
summaryAmplitude += item.currentAmplitude(t);
}
return summaryAmplitude;
}

11
Signal Generator/Signal/SinusoidalSignal.cs

@ -7,17 +7,12 @@ using System.Threading.Tasks;
namespace Signal_Generator
{
[Serializable]
class SinusoidalSignal : AnalogSignalMethods, IAnalogSignal
{
public string typeToString
{
get { return "SIN сигнал"; }
}
public string typeToString => "SIN сигнал";
public new string paramsToString
{
get { return paramsToString(paramsCollection); }
}
public new string paramsToString => paramsToString(paramsCollection);
public Collection<Parameter> paramsCollection { get; set; }

Loading…
Cancel
Save