Browse Source

Теперь ComboBox показывает все существующие элементы из коллекции, а при выборе элемента отображается настройка элементов DataGrid. Плюс сверху накинул много рефактора для большей гибкости при добавлении новых классов сигналов.

master
Никита 6 years ago
parent
commit
23e05e864e
  1. 10
      Signal Generator/AddSignalWindow.xaml
  2. 11
      Signal Generator/AddSignalWindow.xaml.cs
  3. 20
      Signal Generator/AnalogSignalMethods.cs
  4. 31
      Signal Generator/FmSignal.cs
  5. 3
      Signal Generator/IAnalogSignal.cs
  6. 7
      Signal Generator/MainWindow.xaml.cs
  7. 10
      Signal Generator/MultiSignal.cs
  8. 20
      Signal Generator/Parameter.cs
  9. 2
      Signal Generator/Signal Generator.csproj
  10. 36
      Signal Generator/SinusoidalSignal.cs

10
Signal Generator/AddSignalWindow.xaml

@ -18,11 +18,13 @@
</Grid.ColumnDefinitions>
<TextBlock x:Name="signalType_TextBlock" Margin="0,0,10,5" Grid.Row="0" Grid.Column="0">Тип сигнала:</TextBlock>
<ComboBox x:Name="signalType_ComboBox" Margin="0,0,0,5" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1"/>
<DataGrid x:Name="signalProps_DataGrid" Margin="0,0,0,5" HorizontalAlignment="Stretch" Grid.Row="1" Grid.ColumnSpan="2">
<ComboBox x:Name="signalType_ComboBox" Margin="0,0,0,5" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1"
ItemsSource="{Binding}" DisplayMemberPath="typeToString" SelectionChanged="signalType_ComboBox_SelectionChanged"/>
<DataGrid x:Name="signalProps_DataGrid" Margin="0,0,0,5" HorizontalAlignment="Stretch" Grid.Row="1" Grid.ColumnSpan="2"
ItemsSource="{Binding}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Название" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Header="Параметр" />
<DataGridTextColumn Header="Название параметра" Width="*" IsReadOnly="True" Binding="{Binding Path=name}"/>
<DataGridTextColumn Header="Значение параметра" Binding="{Binding Path=value}"/>
</DataGrid.Columns>
</DataGrid>
<Button x:Name="createItem_Button" Height="20" Width="120" Content="Создать элемент" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"/>

11
Signal Generator/AddSignalWindow.xaml.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -19,9 +20,19 @@ namespace Signal_Generator
/// </summary>
public partial class AddSignalWindow : Window
{
ObservableCollection<Parameter> signalProps = new ObservableCollection<Parameter>();
public AddSignalWindow()
{
InitializeComponent();
signalProps_DataGrid.ItemsSource = signalProps;
}
private void signalType_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
signalProps.Clear();
var dict = ((IAnalogSignal)signalType_ComboBox.SelectedItem).paramsCollection as Collection<Parameter>;
foreach (Parameter p in dict)
signalProps.Add(p);
}
}
}

20
Signal Generator/AnalogSignalMethods.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Signal_Generator
{
class AnalogSignalMethods
{
internal string paramsToString(Collection<Parameter> paramsCollection)
{
string result = "";
foreach (Parameter p in paramsCollection)
result += " / " + p.name + " " + p.value;
return result;
}
}
}

31
Signal Generator/FmSignal.cs

@ -1,45 +1,38 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Signal_Generator
{
class FmSignal : IAnalogSignal
class FmSignal : AnalogSignalMethods, IAnalogSignal
{
public Dictionary<string, double> paramsDict { get; set; }
public Collection<Parameter> paramsCollection { get; set; }
public string typeToString
{
get
{
return "FM сигнал";
}
get { return "FM сигнал"; }
}
public string paramsToString
public new string paramsToString
{
get
{
string result = "";
foreach (KeyValuePair<string, double> pair in paramsDict)
result += " / " + pair.Key + " " + pair.Value;
return result;
}
get { return paramsToString(paramsCollection); }
}
public FmSignal(double ampl, double freq, double ampl2)
{
paramsDict = new Dictionary<string, double>();
paramsDict.Add("Амплитуда несущей", ampl);
paramsDict.Add("Частота несущей", freq);
paramsDict.Add("Амплитуда", ampl);
paramsCollection = new Collection<Parameter>();
paramsCollection.Add(new Parameter("Амплитуда несущей", ampl));
paramsCollection.Add(new Parameter("Частота несущей", freq));
paramsCollection.Add(new Parameter("Амплитуда", ampl2));
}
public double currentAmplitude(double t)
{
return paramsDict.ElementAt(0).Value * Math.Sin(2 * Math.PI * paramsDict.ElementAt(1).Value * t + paramsDict.ElementAt(1).Value * Math.Sin(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));
}
}
}

3
Signal Generator/IAnalogSignal.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,6 +12,6 @@ namespace Signal_Generator
string typeToString { get; }
string paramsToString { get; }
double currentAmplitude(double t);
Dictionary<String, Double> paramsDict { get; set; }
Collection<Parameter> paramsCollection { get; set; }
}
}

7
Signal Generator/MainWindow.xaml.cs

@ -24,10 +24,16 @@ namespace Signal_Generator
AddSignalWindow addSignalWindow_Instance = new AddSignalWindow();
TaskWindow taskWindow_Instance = new TaskWindow();
ObservableCollection<IAnalogSignal> s;
ObservableCollection<IAnalogSignal> typesOfSignal = new ObservableCollection<IAnalogSignal>();
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>();
signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = s;
@ -42,7 +48,6 @@ namespace Signal_Generator
{
SinusoidalSignal s1 = new SinusoidalSignal(1, 50);
s.Add(s1);
signals_ListBox.UpdateLayout();
}

10
Signal Generator/MultiSignal.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -16,7 +17,9 @@ namespace Signal_Generator
string IAnalogSignal.paramsToString => throw new NotImplementedException();
Dictionary<string, double> IAnalogSignal.paramsDict { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
string IAnalogSignal.typeToString => throw new NotImplementedException();
Collection<Parameter> IAnalogSignal.paramsCollection { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public MultiSignal()
{
@ -42,5 +45,10 @@ namespace Signal_Generator
}
return summaryAmplitude;
}
double IAnalogSignal.currentAmplitude(double t)
{
throw new NotImplementedException();
}
}
}

20
Signal Generator/Parameter.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Signal_Generator
{
class Parameter
{
public string name { get; set; }
public double value { get; set; }
public Parameter (string name, double value)
{
this.name = name;
this.value = value;
}
}
}

2
Signal Generator/Signal Generator.csproj

@ -58,8 +58,10 @@
<Compile Include="AddSignalWindow.xaml.cs">
<DependentUpon>AddSignalWindow.xaml</DependentUpon>
</Compile>
<Compile Include="AnalogSignalMethods.cs" />
<Compile Include="FmSignal.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Parameter.cs" />
<Compile Include="SinusoidalSignal.cs" />
<Compile Include="TaskWindow.xaml.cs">
<DependentUpon>TaskWindow.xaml</DependentUpon>

36
Signal Generator/SinusoidalSignal.cs

@ -1,50 +1,38 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Signal_Generator
{
class SinusoidalSignal : IAnalogSignal
class SinusoidalSignal : AnalogSignalMethods, IAnalogSignal
{
public string typeToString
{
get
{
return "SIN сигнал";
}
get { return "SIN сигнал"; }
}
public string paramsToString
public new string paramsToString
{
get
{
string result = "";
foreach (KeyValuePair<string, double> pair in paramsDict)
result += " / " + pair.Key + " " + pair.Value;
return result;
}
get { return paramsToString(paramsCollection); }
}
public Dictionary<String, Double> paramsDict { get; set; }
public override string ToString()
{
return "SIN signal";
}
public Collection<Parameter> paramsCollection { get; set; }
public SinusoidalSignal(double ampl, double freq, double phase = 0)
{
paramsDict = new Dictionary<string, double>();
paramsDict.Add("Амплитуда", ampl);
paramsDict.Add("Частота", freq);
paramsDict.Add("Фаза", phase);
paramsCollection = new Collection<Parameter>();
paramsCollection.Add(new Parameter("Амплитуда", ampl));
paramsCollection.Add(new Parameter("Частота", freq));
paramsCollection.Add(new Parameter("Фаза", phase));
}
public double currentAmplitude(double t)
{
return paramsDict.ElementAt(0).Value * Math.Sin(2 * Math.PI * paramsDict.ElementAt(1).Value * t + paramsDict.ElementAt(2).Value);
var c = paramsCollection.ToArray<Parameter>();
return c[0].value * Math.Sin(2 * Math.PI * c[1].value * t + c[2].value);
}
}
}

Loading…
Cancel
Save