Browse Source

A lot of visual improvements and code refactoring.

master
Nikita Romanenko 6 years ago
parent
commit
0f76f3a60a
  1. 6
      Pores/Bootstrap.cs
  2. 2
      Pores/Controllers/ConnectedPoreReportGenerator.cs
  3. 6
      Pores/Controllers/PoreGenerator.cs
  4. 2
      Pores/Interfaces/IPoreGenerator.cs
  5. 4
      Pores/Interfaces/IPoreSpread.cs
  6. 75
      Pores/MainWindow.xaml
  7. 16
      Pores/MainWindowViewModel.cs
  8. 11
      Pores/Models/Localizations/BaseLocalization.cs
  9. 11
      Pores/Models/Spreads/BaseSpread.cs
  10. 10
      Pores/Models/Spreads/NormalSpread.cs
  11. 6
      Pores/Pores.csproj

6
Pores/Bootstrap.cs

@ -2,7 +2,7 @@
using Pores.Controllers; using Pores.Controllers;
using Pores.Interfaces; using Pores.Interfaces;
using Pores.Models; using Pores.Models;
using Pores.Models.Localizations; using Pores.Models.Spreads;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -24,8 +24,8 @@ namespace Pores
.SingleInstance(); .SingleInstance();
build build
.Register(c => new ObservableCollection<IPoreLocalization>() { new NormalLocalization(c.Resolve<Material>()) }) .Register(c => new ObservableCollection<IPoreSpread>() { new NormalSpread(c.Resolve<Material>()) })
.As<IEnumerable<IPoreLocalization>>() .As<IEnumerable<IPoreSpread>>()
.SingleInstance(); .SingleInstance();
build build

2
Pores/Controllers/ConnectedPoreReportGenerator.cs

@ -21,7 +21,7 @@ namespace Pores.Controllers
IList<Tuple<Pore,Pore>> report = new List<Tuple<Pore, Pore>>(); IList<Tuple<Pore,Pore>> report = new List<Tuple<Pore, Pore>>();
foreach(Pore p1 in pores) foreach(Pore p1 in pores)
foreach(Pore p2 in pores) foreach(Pore p2 in pores)
if (!p1.Equals(p2)) if (!p1.Id.Equals(p2.Id))
if (!report.Any(a => a.Item1.Id == p2.Id && a.Item2.Id == p1.Id)) if (!report.Any(a => a.Item1.Id == p2.Id && a.Item2.Id == p1.Id))
if (IsTwoPoresConnecting(p1, p2)) if (IsTwoPoresConnecting(p1, p2))
report.Add(Tuple.Create(p1, p2)); report.Add(Tuple.Create(p1, p2));

6
Pores/Controllers/PoreGenerator.cs

@ -7,7 +7,7 @@ namespace Pores.Controllers
{ {
public class PoreGenerator : PropertyChangedClass, IPoreGenerator public class PoreGenerator : PropertyChangedClass, IPoreGenerator
{ {
public IPoreLocalization PoresLocalization { get; set; } public IPoreSpread PoresLocalization { get; set; }
public Material CurrentMaterial { get; set; } public Material CurrentMaterial { get; set; }
public PoreGenerator(Material currentMaterial) public PoreGenerator(Material currentMaterial)
@ -15,9 +15,9 @@ namespace Pores.Controllers
CurrentMaterial = currentMaterial; CurrentMaterial = currentMaterial;
} }
public IList<Pore> Generate(IPoreLocalization localization) public IList<Pore> Generate(IPoreSpread localization)
{ {
return localization.GetLocalization(); return localization.GetSpread();
} }
} }
} }

2
Pores/Interfaces/IPoreGenerator.cs

@ -5,6 +5,6 @@ namespace Pores.Interfaces
{ {
public interface IPoreGenerator public interface IPoreGenerator
{ {
IList<Pore> Generate(IPoreLocalization localization); IList<Pore> Generate(IPoreSpread localization);
} }
} }

4
Pores/Interfaces/IPoreLocalization.cs → Pores/Interfaces/IPoreSpread.cs

@ -3,8 +3,8 @@ using System.Collections.ObjectModel;
namespace Pores.Interfaces namespace Pores.Interfaces
{ {
public interface IPoreLocalization public interface IPoreSpread
{ {
ObservableCollection<Pore> GetLocalization(); ObservableCollection<Pore> GetSpread();
} }
} }

75
Pores/MainWindow.xaml

@ -3,8 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:localizations="clr-namespace:Pores.Models.Localizations" xmlns:spreads="clr-namespace:Pores.Models.Spreads"
xmlns:local="clr-namespace:Pores"
mc:Ignorable="d" mc:Ignorable="d"
Title="Pores" Height="600" Width="1000"> Title="Pores" Height="600" Width="1000">
<Grid IsEnabled="{Binding EnableControlsFlag}"> <Grid IsEnabled="{Binding EnableControlsFlag}">
@ -26,44 +25,42 @@
</DockPanel> </DockPanel>
<StackPanel VerticalAlignment="Center" Grid.Column="1" Margin="5 0"> <DockPanel Grid.Column="1" Grid.RowSpan="3" VerticalAlignment="Stretch" Margin="5 0">
<TextBlock Text="Параметры модели"/> <StackPanel DockPanel.Dock="Top" Margin="5 0">
<TextBlock Text="Ширина: "/> <TextBlock Text="Настройки моделирования" HorizontalAlignment="Center" FontWeight="SemiBold" Margin="0 5"/>
<TextBox Text="{Binding CurrentMaterial.Width}"/> <TextBlock Text="Параметры модели материала: "/>
<TextBlock Text="Глубина: "/> <TextBlock Text="Ширина: "/>
<TextBox Text="{Binding CurrentMaterial.Depth}"/> <TextBox Text="{Binding CurrentMaterial.Width}"/>
<TextBlock Text="Высота: "/> <TextBlock Text="Глубина: "/>
<TextBox Text="{Binding CurrentMaterial.Height}"/> <TextBox Text="{Binding CurrentMaterial.Depth}"/>
<TextBlock Text="Разрешение каждого из трех измерений (общее количество точек = n^3): " TextWrapping="Wrap"/> <TextBlock Text="Высота: "/>
<TextBox Text="{Binding CurrentMaterial.NumberOfPores}"/> <TextBox Text="{Binding CurrentMaterial.Height}"/>
</StackPanel> <TextBlock Text="Разрешение каждого из трех измерений (общее количество точек = n^3): " TextWrapping="Wrap"/>
<TextBox Text="{Binding CurrentMaterial.NumberOfPores}"/>
<TextBlock Text="Параметры модели распределения:"/>
<StackPanel VerticalAlignment="Center" Grid.Column="1" Grid.Row="2" Grid.RowSpan="2" Margin="5 0"> <ComboBox ItemsSource="{Binding Spreads}" SelectedItem="{Binding SelectedSpread}" HorizontalAlignment="Left" Width="198"></ComboBox>
<TextBlock Text="Результаты работы"/> <ContentControl Content="{Binding SelectedSpread}">
<TextBlock Text="Количество пор: "/> <ContentControl.Resources>
<TextBox Text="{Binding Pores.Count, Mode=OneWay}" IsEnabled="False"/> <DataTemplate DataType="{x:Type spreads:NormalSpread}">
</StackPanel> <StackPanel>
<TextBlock Text="Сигма: "/>
<TextBox Text="{Binding sigma}"/>
<TextBlock Text="Мю: "/>
<TextBox Text="{Binding mu}"/>
</StackPanel>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Margin="5 0"> <StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Margin="5 10">
<TextBlock Text="Параметры модели распределения:"/> <TextBlock Text="Результаты работы"/>
<ComboBox ItemsSource="{Binding Localizations}" SelectedItem="{Binding SelectedLocalization}" HorizontalAlignment="Left" Width="198"></ComboBox> <TextBlock Text="Количество пор: "/>
<ContentControl Content="{Binding SelectedLocalization}"> <TextBox Text="{Binding Pores.Count, Mode=OneWay}" IsEnabled="False"/>
<ContentControl.Resources> </StackPanel>
<DataTemplate DataType="{x:Type localizations:NormalLocalization}"> </DockPanel>
<StackPanel>
<TextBlock Text="Сигма: "/>
<TextBox Text="{Binding sigma}"/>
<TextBlock Text="Мю: "/>
<TextBox Text="{Binding mu}"/>
</StackPanel>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</StackPanel>
<DockPanel Grid.Column="2" Grid.RowSpan="3" Margin="5 0"> <DockPanel Grid.Column="2" Grid.RowSpan="3" Margin="5 0">
<StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom"> <StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
<Button Content="Сгенерировать модель" Command="{Binding GeneratePoresCommand}"/> <Button Content="Сгенерировать модель" Command="{Binding GeneratePoresCommand}"/>
<Button Content="Сохранить выборку из модели в файл" Command="{Binding GenAndSaveBatchCommand}"/> <Button Content="Сохранить выборку из модели в файл" Command="{Binding GenAndSaveBatchCommand}"/>
@ -105,10 +102,6 @@
<TextBlock TextWrapping="Wrap" Text="Предоставить отчет по количеству пор, соединенных между собой"/> <TextBlock TextWrapping="Wrap" Text="Предоставить отчет по количеству пор, соединенных между собой"/>
</CheckBox> </CheckBox>
</StackPanel> </StackPanel>
</DockPanel> </DockPanel>
</Grid> </Grid>
</Window> </Window>

16
Pores/MainWindowViewModel.cs

@ -15,9 +15,9 @@ namespace Pores
{ {
public Material CurrentMaterial { get; set; } public Material CurrentMaterial { get; set; }
public ObservableCollection<Pore> Pores { get; set; } = new ObservableCollection<Pore>(); public ObservableCollection<Pore> Pores { get; set; } = new ObservableCollection<Pore>();
public IEnumerable<IPoreLocalization> Localizations { get; set; } public IEnumerable<IPoreSpread> Spreads { get; set; }
public IPoreLocalization SelectedLocalization { get; set; } public IPoreSpread SelectedSpread { get; set; }
public IPoreGenerator PoreGeneratorInstance { get; set; } public IPoreGenerator PoreGeneratorInstance { get; set; }
public BatchGenerator BatchGenerator { get; } public BatchGenerator BatchGenerator { get; }
public ConnectedPoreReportGenerator ConnectedPoreReportGenerator { get; } public ConnectedPoreReportGenerator ConnectedPoreReportGenerator { get; }
@ -43,25 +43,25 @@ namespace Pores
public MainWindowViewModel( public MainWindowViewModel(
Material material, Material material,
IEnumerable<IPoreLocalization> localizations, IEnumerable<IPoreSpread> localizations,
IPoreGenerator poreGenerator, IPoreGenerator poreGenerator,
ReportGenerator reportSaver, ReportGenerator reportSaver,
BatchGenerator batchGenerator, BatchGenerator batchGenerator,
ConnectedPoreReportGenerator connectedPoreReportGenerator) ConnectedPoreReportGenerator connectedPoreReportGenerator)
{ {
CurrentMaterial = material; CurrentMaterial = material;
Localizations = localizations; Spreads = localizations;
PoreGeneratorInstance = poreGenerator; PoreGeneratorInstance = poreGenerator;
ReportSaver = reportSaver; ReportSaver = reportSaver;
BatchGenerator = batchGenerator; BatchGenerator = batchGenerator;
ConnectedPoreReportGenerator = connectedPoreReportGenerator; ConnectedPoreReportGenerator = connectedPoreReportGenerator;
GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedLocalization != null); GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedSpread != null);
SaveToFileCommand = new RelayCommand(Save, () => Pores?.Count > 0); SaveToFileCommand = new RelayCommand(Save, () => Pores?.Count > 0);
GenAndSaveBatchCommand = new RelayCommand(SaveBatch, () => Pores?.Count > 0); GenAndSaveBatchCommand = new RelayCommand(SaveBatch, () => Pores?.Count > 0);
GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c), () => GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c), () =>
{ {
if (SelectedLocalization != null) if (SelectedSpread != null)
if (AllSavingThread?.IsAlive != true) if (AllSavingThread?.IsAlive != true)
return true; return true;
return false; return false;
@ -73,10 +73,10 @@ namespace Pores
} }
public void GeneratePoresToForm() public void GeneratePoresToForm()
=> Pores = new ObservableCollection<Pore>(PoreGeneratorInstance.Generate(SelectedLocalization)); => Pores = new ObservableCollection<Pore>(PoreGeneratorInstance.Generate(SelectedSpread));
public IList<Pore> GeneratePores() public IList<Pore> GeneratePores()
=> PoreGeneratorInstance.Generate(SelectedLocalization); => PoreGeneratorInstance.Generate(SelectedSpread);
public void Save() public void Save()
=> Save(Pores); => Save(Pores);

11
Pores/Models/Localizations/BaseLocalization.cs

@ -1,11 +0,0 @@
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();
}
}

11
Pores/Models/Spreads/BaseSpread.cs

@ -0,0 +1,11 @@
using System.Collections.ObjectModel;
using Pores.Helpers;
using Pores.Interfaces;
namespace Pores.Models.Spreads
{
public abstract class BaseSpread : PropertyChangedClass, IPoreSpread
{
public abstract ObservableCollection<Pore> GetSpread();
}
}

10
Pores/Models/Localizations/NormalLocalization.cs → Pores/Models/Spreads/NormalSpread.cs

@ -1,11 +1,9 @@
using System; using System;
using Pores.Interfaces;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace Pores.Models.Localizations namespace Pores.Models.Spreads
{ {
public class NormalLocalization : BaseLocalization public class NormalSpread : BaseSpread
{ {
public double mu { get; set; } public double mu { get; set; }
public double sigma { get; set; } public double sigma { get; set; }
@ -24,7 +22,7 @@ namespace Pores.Models.Localizations
return GaussFunction(c.Z, sigma, mu); return GaussFunction(c.Z, sigma, mu);
} }
public override ObservableCollection<Pore> GetLocalization() public override ObservableCollection<Pore> GetSpread()
{ {
var r = new Random(); var r = new Random();
var id = 0; var id = 0;
@ -58,7 +56,7 @@ namespace Pores.Models.Localizations
maxR = Math.Round(Math.Pow((3.0 / 4.0) * volume / (3.14 * Math.Pow(m.NumberOfPores, 3)), 1.0 / 3.0), 3); maxR = Math.Round(Math.Pow((3.0 / 4.0) * volume / (3.14 * Math.Pow(m.NumberOfPores, 3)), 1.0 / 3.0), 3);
} }
public NormalLocalization(Material material) public NormalSpread(Material material)
{ {
Material = material; Material = material;
sigma = 4; sigma = 4;

6
Pores/Pores.csproj

@ -88,14 +88,14 @@
<Compile Include="Helpers\PropertyChanged.cs" /> <Compile Include="Helpers\PropertyChanged.cs" />
<Compile Include="Helpers\RelayCommand.cs" /> <Compile Include="Helpers\RelayCommand.cs" />
<Compile Include="Interfaces\IPoreGenerator.cs" /> <Compile Include="Interfaces\IPoreGenerator.cs" />
<Compile Include="Interfaces\IPoreLocalization.cs" /> <Compile Include="Interfaces\IPoreSpread.cs" />
<Compile Include="MainWindowViewModel.cs" /> <Compile Include="MainWindowViewModel.cs" />
<Compile Include="Models\BatchPoint.cs" /> <Compile Include="Models\BatchPoint.cs" />
<Compile Include="Models\Point.cs" /> <Compile Include="Models\Point.cs" />
<Compile Include="Models\Point2D.cs" /> <Compile Include="Models\Point2D.cs" />
<Compile Include="Models\Point3D.cs" /> <Compile Include="Models\Point3D.cs" />
<Compile Include="Models\Localizations\BaseLocalization.cs" /> <Compile Include="Models\Spreads\BaseSpread.cs" />
<Compile Include="Models\Localizations\NormalLocalization.cs" /> <Compile Include="Models\Spreads\NormalSpread.cs" />
<Compile Include="Models\Material.cs" /> <Compile Include="Models\Material.cs" />
<Compile Include="Models\Pore.cs" /> <Compile Include="Models\Pore.cs" />
<Compile Include="MainWindow.xaml.cs"> <Compile Include="MainWindow.xaml.cs">

Loading…
Cancel
Save