Browse Source

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

master
Никита 6 years ago
parent
commit
10f3840880
  1. 31
      Signal Generator/FmSignal.cs
  2. 4
      Signal Generator/IAnalogSignal.cs
  3. 17
      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 class FmSignal : IAnalogSignal
{ {
private double ampl = 0; public Dictionary<string, double> paramsDict { get; set; }
private double freq = 0;
private IAnalogSignal modSignal;
public string ParamsToString public string typeToString
{ {
get get
{ {
return this.ToString() + return "FM сигнал";
" | А = " + ampl +
" | f = " + freq;
} }
} }
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; paramsDict = new Dictionary<string, double>();
this.freq = freq; paramsDict.Add("Амплитуда несущей", ampl);
this.modSignal = modSignal; paramsDict.Add("Частота несущей", freq);
paramsDict.Add("Амплитуда", ampl);
} }
public double currentAmplitude(double t) 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 interface IAnalogSignal
{ {
string ParamsToString { get; } string typeToString { get; }
string paramsToString { get; }
double currentAmplitude(double t); double currentAmplitude(double t);
Dictionary<String, Double> paramsDict { get; set; }
} }
} }

17
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="MainWindow" Height="450" Width="489"> Title="Signal Generator" Height="450" Width="489">
<Grid> <Grid>
<DockPanel LastChildFill="True" Margin="10,10,10,10"> <DockPanel LastChildFill="True" Margin="10,10,10,10">
<ListBox x:Name="signals_ListBox" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" <ListBox x:Name="signals_ListBox" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
@ -13,19 +13,26 @@
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <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> </StackPanel>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
</DockPanel> </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"> <DockPanel DockPanel.Dock="Left">
<Button x:Name="startProcedure_Button" Width="120" Content="Запустить процедуру" /> <Button x:Name="startProcedure_Button" Width="120" Content="Запустить процедуру" />
</DockPanel> </DockPanel>
<DockPanel HorizontalAlignment="Right"> <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="-" /> <Button x:Name="removeSignal_Button" Width="20" Content="-"/>
</DockPanel> </DockPanel>
</DockPanel> </DockPanel>
</Grid> </Grid>

18
Signal Generator/MainWindow.xaml.cs

@ -21,22 +21,26 @@ namespace Signal_Generator
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
ObservableCollection<IAnalogSignal> s;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
addSomeExtra(); s = new ObservableCollection<IAnalogSignal>();
signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = s;
} }
private void addSomeExtra() private void addSomeExtra()
{ {
// test of signals_ListBox
// repo test line
SinusoidalSignal s1 = new SinusoidalSignal(1, 50); SinusoidalSignal s1 = new SinusoidalSignal(1, 50);
SinusoidalSignal s2 = new SinusoidalSignal(3, 120);
ObservableCollection<IAnalogSignal> s = new ObservableCollection<IAnalogSignal>();
s.Add(s1); s.Add(s1);
signals_ListBox.Items.Clear(); signals_ListBox.UpdateLayout();
signals_ListBox.ItemsSource = s; }
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 class MultiSignal : IAnalogSignal
{ {
private string paramsToString { get; }
private List<IAnalogSignal> signals { get; set; } 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() public MultiSignal()
{ {

2
Signal Generator/Signal Generator.csproj

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

31
Signal Generator/SinusoidalSignal.cs

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