Compare commits

...

3 Commits

  1. 33
      Signal Generator/AddSignalWindow.xaml
  2. 11
      Signal Generator/AddSignalWindow.xaml.cs
  3. 45
      Signal Generator/FmSignal.cs
  4. 65
      Signal Generator/MainWindow.xaml
  5. 22
      Signal Generator/MainWindow.xaml.cs
  6. 10
      Signal Generator/Signal Generator.csproj
  7. 20
      Signal Generator/Signal/Base/AnalogSignalMethods.cs
  8. 3
      Signal Generator/Signal/Base/IAnalogSignal.cs
  9. 20
      Signal Generator/Signal/Base/Parameter.cs
  10. 38
      Signal Generator/Signal/FmSignal.cs
  11. 10
      Signal Generator/Signal/MultiSignal.cs
  12. 38
      Signal Generator/Signal/SinusoidalSignal.cs
  13. 50
      Signal Generator/SinusoidalSignal.cs
  14. 40
      Signal Generator/TaskWindow.xaml

33
Signal Generator/AddSignalWindow.xaml

@ -5,15 +5,28 @@
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="AddSignalWindow" Height="200" Width="400"> Title="Добавить новый сигнал" Height="200" Width="400">
<Grid> <Grid Margin="10">
<DockPanel Margin="10"> <Grid.RowDefinitions>
<DockPanel DockPanel.Dock="Top"> <RowDefinition Height="Auto"/>
<TextBlock x:Name="signalType_TextBlock" Margin="0,0,10,0">Тип сигнала:</TextBlock> <RowDefinition Height="*"/>
<ComboBox x:Name="signalType_ComboBox" HorizontalAlignment="Stretch"/> <RowDefinition Height="Auto"/>
</DockPanel> </Grid.RowDefinitions>
<DockPanel DockPanel.Dock="Top"> <Grid.ColumnDefinitions>
</DockPanel> <ColumnDefinition Width="Auto"/>
</DockPanel> <ColumnDefinition Width="*"/>
</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"
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" 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"/>
</Grid> </Grid>
</Window> </Window>

11
Signal Generator/AddSignalWindow.xaml.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -19,9 +20,19 @@ namespace Signal_Generator
/// </summary> /// </summary>
public partial class AddSignalWindow : Window public partial class AddSignalWindow : Window
{ {
ObservableCollection<Parameter> signalProps = new ObservableCollection<Parameter>();
public AddSignalWindow() public AddSignalWindow()
{ {
InitializeComponent(); 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);
} }
} }
} }

45
Signal Generator/FmSignal.cs

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

65
Signal Generator/MainWindow.xaml

@ -5,35 +5,40 @@
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="Signal Generator" Height="450" Width="489"> Title="Генератор сигналов" Height="450" Width="489">
<Grid> <Grid Margin="10">
<DockPanel LastChildFill="True" Margin="10,10,10,10"> <Grid.RowDefinitions>
<ListBox x:Name="signals_ListBox" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" <RowDefinition Height="*"/>
DockPanel.Dock="Top" ItemsSource="{Binding}" Margin="0,0,0,20"> <RowDefinition Height="Auto"/>
<ListBox.ItemTemplate> </Grid.RowDefinitions>
<DataTemplate> <Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal"> <ColumnDefinition Width="Auto"/>
<TextBlock> <ColumnDefinition Width="*"/>
<TextBlock.Text> <ColumnDefinition Width="Auto"/>
<MultiBinding StringFormat=" {0} {1}"> <ColumnDefinition Width="Auto"/>
<Binding Path="typeToString"/> </Grid.ColumnDefinitions>
<Binding Path="paramsToString"/>
</MultiBinding> <ListBox x:Name="signals_ListBox" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
</TextBlock.Text> DockPanel.Dock="Top" ItemsSource="{Binding}" Margin="0,0,0,5" Grid.ColumnSpan="4">
</TextBlock> <ListBox.ItemTemplate>
</StackPanel> <DataTemplate>
</DataTemplate> <StackPanel Orientation="Horizontal">
</ListBox.ItemTemplate> <TextBlock>
</ListBox> <TextBlock.Text>
</DockPanel> <MultiBinding StringFormat=" {0} {1}">
<DockPanel x:Name="buttons_DockPanel" IsEnabled="True" Margin="10,0,10,10" VerticalAlignment="Bottom"> <Binding Path="typeToString"/>
<DockPanel DockPanel.Dock="Left"> <Binding Path="paramsToString"/>
<Button x:Name="startProcedure_Button" Width="120" Content="Запустить процедуру" /> </MultiBinding>
</DockPanel> </TextBlock.Text>
<DockPanel HorizontalAlignment="Right"> </TextBlock>
<Button x:Name="addSignal_Button" Width="20" Content="+" Click="addSignal_Button_Click"/> </StackPanel>
<Button x:Name="removeSignal_Button" Width="20" Content="-"/> </DataTemplate>
</DockPanel> </ListBox.ItemTemplate>
</DockPanel> </ListBox>
<Button x:Name="startProcedure_Button" Content="Запустить процедуру" Click="startProcedure_Button_Click"
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"/>
</Grid> </Grid>
</Window> </Window>

22
Signal Generator/MainWindow.xaml.cs

@ -21,26 +21,44 @@ namespace Signal_Generator
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
AddSignalWindow addSignalWindow_Instance = new AddSignalWindow();
TaskWindow taskWindow_Instance = new TaskWindow();
ObservableCollection<IAnalogSignal> s; ObservableCollection<IAnalogSignal> s;
ObservableCollection<IAnalogSignal> typesOfSignal = new ObservableCollection<IAnalogSignal>();
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
typesOfSignal.Add(new SinusoidalSignal(0, 0));
typesOfSignal.Add(new FmSignal(0, 0, 0));
addSignalWindow_Instance.signalType_ComboBox.ItemsSource = typesOfSignal;
s = new ObservableCollection<IAnalogSignal>(); s = new ObservableCollection<IAnalogSignal>();
signals_ListBox.Items.Clear(); signals_ListBox.Items.Clear();
signals_ListBox.ItemsSource = s; signals_ListBox.ItemsSource = s;
addSignalWindow_Instance.Closed += addSignalWindow_Instance_Closed;
}
private void addSignalWindow_Instance_Closed(object sender, EventArgs e)
{
} }
private void addSomeExtra() private void addSomeExtra()
{ {
SinusoidalSignal s1 = new SinusoidalSignal(1, 50); SinusoidalSignal s1 = new SinusoidalSignal(1, 50);
s.Add(s1); s.Add(s1);
signals_ListBox.UpdateLayout();
} }
private void addSignal_Button_Click(object sender, RoutedEventArgs e) private void addSignal_Button_Click(object sender, RoutedEventArgs e)
{ {
addSomeExtra(); addSignalWindow_Instance.Show();
}
private void startProcedure_Button_Click(object sender, RoutedEventArgs e)
{
taskWindow_Instance.Show();
} }
} }
} }

10
Signal Generator/Signal Generator.csproj

@ -58,9 +58,11 @@
<Compile Include="AddSignalWindow.xaml.cs"> <Compile Include="AddSignalWindow.xaml.cs">
<DependentUpon>AddSignalWindow.xaml</DependentUpon> <DependentUpon>AddSignalWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="FmSignal.cs" /> <Compile Include="Signal\Base\AnalogSignalMethods.cs" />
<Compile Include="Signal\FmSignal.cs" />
<Compile Include="Settings.cs" /> <Compile Include="Settings.cs" />
<Compile Include="SinusoidalSignal.cs" /> <Compile Include="Signal\Base\Parameter.cs" />
<Compile Include="Signal\SinusoidalSignal.cs" />
<Compile Include="TaskWindow.xaml.cs"> <Compile Include="TaskWindow.xaml.cs">
<DependentUpon>TaskWindow.xaml</DependentUpon> <DependentUpon>TaskWindow.xaml</DependentUpon>
</Compile> </Compile>
@ -76,7 +78,7 @@
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="IAnalogSignal.cs" /> <Compile Include="Signal\Base\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>
@ -87,7 +89,7 @@
</Page> </Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="MultiSignal.cs" /> <Compile Include="Signal\MultiSignal.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

20
Signal Generator/Signal/Base/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
{
protected string paramsToString(Collection<Parameter> paramsCollection)
{
string result = "";
foreach (Parameter p in paramsCollection)
result += " / " + p.name + " " + p.value;
return result;
}
}
}

3
Signal Generator/IAnalogSignal.cs → Signal Generator/Signal/Base/IAnalogSignal.cs

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

20
Signal Generator/Signal/Base/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;
}
}
}

38
Signal Generator/Signal/FmSignal.cs

@ -0,0 +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 : AnalogSignalMethods, IAnalogSignal
{
public Collection<Parameter> paramsCollection { get; set; }
public string typeToString
{
get { return "FM сигнал"; }
}
public new string paramsToString
{
get { return paramsToString(paramsCollection); }
}
public FmSignal(double ampl, double freq, double ampl2)
{
paramsCollection = new Collection<Parameter>();
paramsCollection.Add(new Parameter("Амплитуда несущей", ampl));
paramsCollection.Add(new Parameter("Частота несущей", freq));
paramsCollection.Add(new Parameter("Амплитуда", ampl2));
}
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));
}
}
}

10
Signal Generator/MultiSignal.cs → Signal Generator/Signal/MultiSignal.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,7 +17,9 @@ namespace Signal_Generator
string IAnalogSignal.paramsToString => throw new NotImplementedException(); 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() public MultiSignal()
{ {
@ -42,5 +45,10 @@ namespace Signal_Generator
} }
return summaryAmplitude; return summaryAmplitude;
} }
double IAnalogSignal.currentAmplitude(double t)
{
throw new NotImplementedException();
}
} }
} }

38
Signal Generator/Signal/SinusoidalSignal.cs

@ -0,0 +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 : AnalogSignalMethods, IAnalogSignal
{
public string typeToString
{
get { return "SIN сигнал"; }
}
public new string paramsToString
{
get { return paramsToString(paramsCollection); }
}
public Collection<Parameter> paramsCollection { get; set; }
public SinusoidalSignal(double ampl, double freq, double phase = 0)
{
paramsCollection = new Collection<Parameter>();
paramsCollection.Add(new Parameter("Амплитуда", ampl));
paramsCollection.Add(new Parameter("Частота", freq));
paramsCollection.Add(new Parameter("Фаза", phase));
}
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);
}
}
}

50
Signal Generator/SinusoidalSignal.cs

@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Signal_Generator
{
class SinusoidalSignal : IAnalogSignal
{
public string typeToString
{
get
{
return "SIN сигнал";
}
}
public string paramsToString
{
get
{
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";
}
public SinusoidalSignal(double ampl, double freq, double phase = 0)
{
paramsDict = new Dictionary<string, double>();
paramsDict.Add("Амплитуда", ampl);
paramsDict.Add("Частота", freq);
paramsDict.Add("Фаза", 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);
}
}
}

40
Signal Generator/TaskWindow.xaml

@ -5,24 +5,28 @@
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="TaskWindow" Height="127" Width="284" Title="Моделирование работы группы сигналов" Height="250" Width="500"
ResizeMode="NoResize"> ResizeMode="NoResize">
<Grid> <Grid Margin="10">
<DockPanel VerticalAlignment="Top" Margin="10,10,10,0"> <Grid.RowDefinitions>
<DockPanel> <RowDefinition Height="*"/>
<TextBlock x:Name="currentTime_TextBlock" TextWrapping="Wrap" DockPanel.Dock="Top" Height="18"> <RowDefinition Height="Auto"/>
Время выполения: <RowDefinition Height="Auto"/>
</TextBlock> <RowDefinition Height="Auto"/>
<TextBlock x:Name="currentAmplitude_TextBlock" TextWrapping="Wrap"> </Grid.RowDefinitions>
Текущий сигнал: <Grid.ColumnDefinitions>
</TextBlock> <ColumnDefinition Width="*"/>
</DockPanel> <ColumnDefinition Width="Auto"/>
<TextBox x:Name="currentTime_TextBox" TextWrapping="Wrap" DockPanel.Dock="Top"/> <ColumnDefinition Width="*"/>
<TextBox x:Name="currentAmplitude_TextBox" TextWrapping="Wrap" DockPanel.Dock="Top"/> <ColumnDefinition Width="*"/>
<DockPanel HorizontalAlignment="Center"> </Grid.ColumnDefinitions>
<Button x:Name="start_Button" Width="60" Content="Старт" Margin="5,0"/>
<Button x:Name="pause_Button" Width="60" Content="Пауза" Margin="5,0"/> <Canvas x:Name="signalGraph_Canvas" Grid.ColumnSpan="4" Margin="0,0,0,5"></Canvas>
</DockPanel> <TextBlock x:Name="currentTime_TextBlock" Margin="0,0,5,5" Grid.Row="1" Grid.Column="1">Время выполения:</TextBlock>
</DockPanel> <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="pause_Button" Width="60" Content="Пауза" Margin="5,0" Grid.Row="3" Grid.Column="2"/>
</Grid> </Grid>
</Window> </Window>

Loading…
Cancel
Save