Browse Source

Правки за последние 7 дней. Много рефактора

master
Никита 6 years ago
parent
commit
10f3840880
  1. 31
      Signal Generator/FmSignal.cs
  2. 4
      Signal Generator/IAnalogSignal.cs
  3. 15
      Signal Generator/MainWindow.xaml
  4. 18
      Signal Generator/MainWindow.xaml.cs
  5. 9
      Signal Generator/MultiSignal.cs
  6. 2
      Signal Generator/Signal Generator.csproj
  7. 31
      Signal Generator/SinusoidalSignal.cs

31
Signal Generator/FmSignal.cs

@ -8,35 +8,38 @@ namespace Signal_Generator
{
class FmSignal : IAnalogSignal
{
private double ampl = 0;
private double freq = 0;
private IAnalogSignal modSignal;
public Dictionary<string, double> paramsDict { get; set; }
public string ParamsToString
public string typeToString
{
get
{
return this.ToString() +
" | А = " + ampl +
" | f = " + freq;
return "FM сигнал";
}
}
public override string ToString()
public string paramsToString
{
return "FM signal";
get
{
string result = "";
foreach (KeyValuePair<string, double> pair in paramsDict)
result += " / " + pair.Key + " " + pair.Value;
return result;
}
}
public FmSignal(double ampl, double freq, IAnalogSignal modSignal)
public FmSignal(double ampl, double freq, double ampl2)
{
this.ampl = ampl;
this.freq = freq;
this.modSignal = modSignal;
paramsDict = new Dictionary<string, double>();
paramsDict.Add("Амплитуда несущей", ampl);
paramsDict.Add("Частота несущей", freq);
paramsDict.Add("Амплитуда", ampl);
}
public double currentAmplitude(double t)
{
return ampl * Math.Sin(2 * Math.PI * freq * t + modSignal.currentAmplitude(t));
return paramsDict.ElementAt(0).Value * Math.Sin(2 * Math.PI * paramsDict.ElementAt(1).Value * t + paramsDict.ElementAt(1).Value * Math.Sin(t));
}
}
}

4
Signal Generator/IAnalogSignalModel.cs → Signal Generator/IAnalogSignal.cs

@ -8,7 +8,9 @@ namespace Signal_Generator
{
interface IAnalogSignal
{
string ParamsToString { get; }
string typeToString { get; }
string paramsToString { get; }
double currentAmplitude(double t);
Dictionary<String, Double> paramsDict { get; set; }
}
}

15
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="MainWindow" Height="450" Width="489">
Title="Signal Generator" Height="450" Width="489">
<Grid>
<DockPanel LastChildFill="True" Margin="10,10,10,10">
<ListBox x:Name="signals_ListBox" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
@ -13,18 +13,25 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=ParamsToString}"/>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat=" {0} {1}">
<Binding Path="typeToString"/>
<Binding Path="paramsToString"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
<DockPanel x:Name="buttons_DockPanel" IsEnabled="False" Margin="10,0,10,10" VerticalAlignment="Bottom">
<DockPanel x:Name="buttons_DockPanel" IsEnabled="True" Margin="10,0,10,10" VerticalAlignment="Bottom">
<DockPanel DockPanel.Dock="Left">
<Button x:Name="startProcedure_Button" Width="120" Content="Запустить процедуру" />
</DockPanel>
<DockPanel HorizontalAlignment="Right">
<Button x:Name="addSignal_Button" Width="20" Content="+"/>
<Button x:Name="addSignal_Button" Width="20" Content="+" Click="addSignal_Button_Click"/>
<Button x:Name="removeSignal_Button" Width="20" Content="-"/>
</DockPanel>
</DockPanel>

18
Signal Generator/MainWindow.xaml.cs

@ -21,22 +21,26 @@ namespace Signal_Generator
/// </summary>
public partial class MainWindow : Window
{
ObservableCollection<IAnalogSignal> s;
public MainWindow()
{
InitializeComponent();
addSomeExtra();
s = new ObservableCollection<IAnalogSignal>();
signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = s;
}
private void addSomeExtra()
{
// test of signals_ListBox
// repo test line
SinusoidalSignal s1 = new SinusoidalSignal(1, 50);
SinusoidalSignal s2 = new SinusoidalSignal(3, 120);
ObservableCollection<IAnalogSignal> s = new ObservableCollection<IAnalogSignal>();
s.Add(s1);
signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = s;
signals_ListBox.UpdateLayout();
}
private void addSignal_Button_Click(object sender, RoutedEventArgs e)
{
addSomeExtra();
}
}
}

9
Signal Generator/MultiSignal.cs

@ -8,8 +8,15 @@ namespace Signal_Generator
{
class MultiSignal : IAnalogSignal
{
private string paramsToString { get; }
private List<IAnalogSignal> signals { get; set; }
public string ParamsToString { get; set; }
private Dictionary<string, double> paramsDict { get; set; }
public string typeToString => throw new NotImplementedException();
string IAnalogSignal.paramsToString => throw new NotImplementedException();
Dictionary<string, double> IAnalogSignal.paramsDict { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public MultiSignal()
{

2
Signal Generator/Signal Generator.csproj

@ -76,7 +76,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="IAnalogSignalModel.cs" />
<Compile Include="IAnalogSignal.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>

31
Signal Generator/SinusoidalSignal.cs

@ -8,21 +8,27 @@ namespace Signal_Generator
{
class SinusoidalSignal : IAnalogSignal
{
private double ampl = 0;
private double freq = 0;
private double phase = 0;
public string typeToString
{
get
{
return "SIN сигнал";
}
}
public string ParamsToString
public string paramsToString
{
get
{
return this.ToString() +
" | A = " + ampl +
" | f = " + freq +
" | phi = " + phase;
string result = "";
foreach (KeyValuePair<string, double> pair in paramsDict)
result += " / " + pair.Key + " " + pair.Value;
return result;
}
}
public Dictionary<String, Double> paramsDict { get; set; }
public override string ToString()
{
return "SIN signal";
@ -30,14 +36,15 @@ namespace Signal_Generator
public SinusoidalSignal(double ampl, double freq, double phase = 0)
{
this.ampl = ampl;
this.freq = freq;
this.phase = phase;
paramsDict = new Dictionary<string, double>();
paramsDict.Add("Амплитуда", ampl);
paramsDict.Add("Частота", freq);
paramsDict.Add("Фаза", phase);
}
public double currentAmplitude(double t)
{
return ampl * Math.Sin(2 * Math.PI * freq * t + phase);
return paramsDict.ElementAt(0).Value * Math.Sin(2 * Math.PI * paramsDict.ElementAt(1).Value * t + paramsDict.ElementAt(2).Value);
}
}
}

Loading…
Cancel
Save