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

2
Pores/Controllers/ConnectedPoreReportGenerator.cs

@ -21,7 +21,7 @@ namespace Pores.Controllers
IList<Tuple<Pore,Pore>> report = new List<Tuple<Pore, Pore>>();
foreach(Pore p1 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 (IsTwoPoresConnecting(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 IPoreLocalization PoresLocalization { get; set; }
public IPoreSpread PoresLocalization { get; set; }
public Material CurrentMaterial { get; set; }
public PoreGenerator(Material currentMaterial)
@ -15,9 +15,9 @@ namespace Pores.Controllers
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
{
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
{
public interface IPoreLocalization
public interface IPoreSpread
{
ObservableCollection<Pore> GetLocalization();
ObservableCollection<Pore> GetSpread();
}
}

79
Pores/MainWindow.xaml

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

16
Pores/MainWindowViewModel.cs

@ -15,9 +15,9 @@ namespace Pores
{
public Material CurrentMaterial { get; set; }
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 BatchGenerator BatchGenerator { get; }
public ConnectedPoreReportGenerator ConnectedPoreReportGenerator { get; }
@ -43,25 +43,25 @@ namespace Pores
public MainWindowViewModel(
Material material,
IEnumerable<IPoreLocalization> localizations,
IEnumerable<IPoreSpread> localizations,
IPoreGenerator poreGenerator,
ReportGenerator reportSaver,
BatchGenerator batchGenerator,
ConnectedPoreReportGenerator connectedPoreReportGenerator)
{
CurrentMaterial = material;
Localizations = localizations;
Spreads = localizations;
PoreGeneratorInstance = poreGenerator;
ReportSaver = reportSaver;
BatchGenerator = batchGenerator;
ConnectedPoreReportGenerator = connectedPoreReportGenerator;
GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedLocalization != null);
GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedSpread != null);
SaveToFileCommand = new RelayCommand(Save, () => Pores?.Count > 0);
GenAndSaveBatchCommand = new RelayCommand(SaveBatch, () => Pores?.Count > 0);
GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c), () =>
{
if (SelectedLocalization != null)
if (SelectedSpread != null)
if (AllSavingThread?.IsAlive != true)
return true;
return false;
@ -73,10 +73,10 @@ namespace Pores
}
public void GeneratePoresToForm()
=> Pores = new ObservableCollection<Pore>(PoreGeneratorInstance.Generate(SelectedLocalization));
=> Pores = new ObservableCollection<Pore>(PoreGeneratorInstance.Generate(SelectedSpread));
public IList<Pore> GeneratePores()
=> PoreGeneratorInstance.Generate(SelectedLocalization);
=> PoreGeneratorInstance.Generate(SelectedSpread);
public void Save()
=> 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 Pores.Interfaces;
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 sigma { get; set; }
@ -24,7 +22,7 @@ namespace Pores.Models.Localizations
return GaussFunction(c.Z, sigma, mu);
}
public override ObservableCollection<Pore> GetLocalization()
public override ObservableCollection<Pore> GetSpread()
{
var r = new Random();
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);
}
public NormalLocalization(Material material)
public NormalSpread(Material material)
{
Material = material;
sigma = 4;

6
Pores/Pores.csproj

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

Loading…
Cancel
Save