Browse Source

Добавлен интерфейс выбора типа локализации пор для генератора

master
defend 6 years ago
parent
commit
071ca8cc3c
  1. 7
      Pores/Controllers/ModelGenerationController.cs
  2. 4
      Pores/Interfaces/IPoresLocalization.cs
  3. 33
      Pores/MainWindow.xaml
  4. 16
      Pores/MainWindowViewModel.cs
  5. 11
      Pores/Models/Localizations/BaseLocalization.cs
  6. 13
      Pores/Models/Localizations/NormalLocalization.cs
  7. 1
      Pores/Pores.csproj

7
Pores/Controllers/ModelGenerationController.cs

@ -1,12 +1,11 @@
using Pores.Interfaces;
using Pores.Helpers;
using Pores.Interfaces;
using Pores.Models;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace Pores.Controllers
{
public class ModelGenerationController
public class ModelGenerationController : PropertyChangedClass
{
public IPoreLocalization PoresLocalization { get; set; }
public Material MaterialInstance { get; set; }

4
Pores/Interfaces/IPoresLocalization.cs

@ -1,10 +1,10 @@
using Pores.Models;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Pores.Interfaces
{
public interface IPoreLocalization
{
IList<Pore> GetLocalization();
ObservableCollection<Pore> GetLocalization();
}
}

33
Pores/MainWindow.xaml

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:localizations="clr-namespace:Pores.Models.Localizations"
xmlns:local="clr-namespace:Pores"
mc:Ignorable="d"
Title="Pores" Height="450" Width="800">
@ -14,7 +15,8 @@
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="40"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
@ -30,7 +32,32 @@
<TextBox Text="{Binding Material.NumberOfPores}"/>
</StackPanel>
<Button Content="Сгенерировать поры" Command="{Binding GeneratePoresCommand}" Grid.Row="1"/>
<Button Content="Сохранить в файл" Command="{Binding SaveToFileCommand}" Grid.Row="1" Grid.Column="1"/>
<StackPanel VerticalAlignment="Center" Grid.Column="2" Grid.Row="2" Margin="20 0">
<TextBlock Text="Результаты работы"/>
<TextBlock Text="Количество пор: "/>
<TextBox Text="{Binding GenController.PoreCoordinates.Count, Mode=OneWay}"/>
</StackPanel>
<StackPanel Grid.Column="2" Grid.Row="1" VerticalAlignment="Center">
<ComboBox ItemsSource="{Binding Localizations}" SelectedItem="{Binding SelectedLocalization}"></ComboBox>
<ContentControl Content="{Binding SelectedLocalization}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type localizations:NormalLocalization}">
<StackPanel>
<TextBlock Text="Параметры модели"/>
<TextBlock Text="Сигма: "/>
<TextBox Text="{Binding sigma}"/>
<TextBlock Text="Мю: "/>
<TextBox Text="{Binding mu}"/>
</StackPanel>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</StackPanel>
<Button Content="Сгенерировать поры" Command="{Binding GeneratePoresCommand}" Grid.Row="2"/>
<Button Content="Сохранить в файл" Command="{Binding SaveToFileCommand}" Grid.Row="2" Grid.Column="1"/>
</Grid>
</Window>

16
Pores/MainWindowViewModel.cs

@ -4,32 +4,32 @@ using Pores.Models;
using Pores.Models.Localizations;
using Pores.Helpers;
using System.Windows.Input;
using System.Collections.ObjectModel;
namespace Pores
{
public class MainWindowViewModel : PropertyChangedClass
{
public Material Material { get; set; } = new Material();
public IPoreLocalization Localization { get; set; }
public IPoreLocalization SelectedLocalization { get; set; }
public ModelGenerationController GenController { get; set; }
public ObservableCollection<IPoreLocalization> Localizations { get; set; }
public int NumberOfPores { get; set; }
public ICommand GeneratePoresCommand { get; set; }
public MainWindowViewModel()
{
Init();
GeneratePoresCommand = new RelayCommand(StartGeneration, () => true);
}
public void Init()
Localizations = new ObservableCollection<IPoreLocalization>
{
Localization = new NormalLocalization(Material);
GenController = new ModelGenerationController(Localization);
new NormalLocalization(Material),
};
GeneratePoresCommand = new RelayCommand(StartGeneration, () => true);
}
public void StartGeneration()
{
GenController = new ModelGenerationController(SelectedLocalization);
GenController.GeneratePores();
}
}

11
Pores/Models/Localizations/BaseLocalization.cs

@ -0,0 +1,11 @@
using System.Collections.ObjectModel;
using Pores.Helpers;
using Pores.Interfaces;
namespace Pores.Models.Localizations
{
public abstract class BaseLocalization : PropertyChangedClass, IPoreLocalization
{
public abstract ObservableCollection<Pore> GetLocalization();
}
}

13
Pores/Models/Localizations/NormalLocalization.cs

@ -5,9 +5,10 @@ using System.Collections.Generic;
namespace Pores.Models.Localizations
{
public class NormalLocalization : IPoreLocalization
public class NormalLocalization : BaseLocalization
{
private double mu, sigma;
public double mu { get; set; }
public double sigma { get; set; }
private double maxR;
private Material Material { get; }
@ -23,11 +24,8 @@ namespace Pores.Models.Localizations
return GaussFunction(c.Z, sigma, mu);
}
public IList<Pore> GetLocalization()
public override ObservableCollection<Pore> GetLocalization()
{
sigma = 4;
mu = Material.Height - Material.Height / 4;
maxR = Math.Sqrt(Material.NumberOfPores / (Material.Height * Material.Width * Material.Depth) / 3.14);
var r = new Random();
var result = new ObservableCollection<Pore>();
@ -52,6 +50,9 @@ namespace Pores.Models.Localizations
public NormalLocalization(Material material)
{
Material = material;
sigma = 4;
mu = Material.Height - Material.Height / 4;
maxR = Math.Sqrt(Material.NumberOfPores / (Material.Height * Material.Width * Material.Depth) / 3.14);
}
}
}

1
Pores/Pores.csproj

@ -79,6 +79,7 @@
<Compile Include="Interfaces\IPoresLocalization.cs" />
<Compile Include="MainWindowViewModel.cs" />
<Compile Include="Models\Coordinate.cs" />
<Compile Include="Models\Localizations\BaseLocalization.cs" />
<Compile Include="Models\Localizations\NormalLocalization.cs" />
<Compile Include="Models\Material.cs" />
<Compile Include="Models\Pore.cs" />

Loading…
Cancel
Save