Browse Source

done = new way of module architicture; first implementation of pore inspection module

master
Nikita Romanenko 6 years ago
parent
commit
c1754eb2c1
  1. 15
      Pores/App.xaml
  2. 27
      Pores/Bootstrap.cs
  3. 2
      Pores/Converters/CubicPowerOfInt.cs
  4. 4
      Pores/Interfaces/IPoreSpread.cs
  5. 25
      Pores/MODELING-DEF-DES-MI-VI.csproj
  6. 133
      Pores/MainWindow.xaml
  7. 133
      Pores/MainWindowViewModel.cs
  8. 26
      Pores/Models/Camera.cs
  9. 3
      Pores/Models/Material.cs
  10. 6
      Pores/Models/Point.cs
  11. 11
      Pores/Models/Point2D.cs
  12. 16
      Pores/Models/Point3D.cs
  13. 4
      Pores/Models/Spreads/BaseSpread.cs
  14. 6
      Pores/Models/Spreads/NormalSpread.cs
  15. 146
      Pores/Modules/ModelCreationUnit/ModelCreationView.xaml
  16. 13
      Pores/Modules/ModelCreationUnit/ModelCreationView.xaml.cs
  17. 142
      Pores/Modules/ModelCreationUnit/ModelCreationViewModel.cs
  18. 57
      Pores/Modules/PoreInspectionUnit/PoreInspectionView.xaml
  19. 13
      Pores/Modules/PoreInspectionUnit/PoreInspectionView.xaml.cs
  20. 170
      Pores/Modules/PoreInspectionUnit/PoreInspectionViewModel.cs

15
Pores/App.xaml

@ -1,9 +1,8 @@
<Application x:Class="MODELING_DEF_DES_MI_VI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MODELING_DEF_DES_MI_VI"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
<Application
x:Class="MODELING_DEF_DES_MI_VI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MODELING_DEF_DES_MI_VI"
StartupUri="MainWindow.xaml">
<Application.Resources />
</Application>

27
Pores/Bootstrap.cs

@ -3,12 +3,10 @@ using MODELING_DEF_DES_MI_VI.Controllers;
using MODELING_DEF_DES_MI_VI.Interfaces;
using MODELING_DEF_DES_MI_VI.Models;
using MODELING_DEF_DES_MI_VI.Models.Spreads;
using System;
using MODELING_DEF_DES_MI_VI.Modules.ModelCreationUnit;
using MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MODELING_DEF_DES_MI_VI
{
@ -47,10 +45,29 @@ namespace MODELING_DEF_DES_MI_VI
.SingleInstance();
build
.RegisterType<MainWindowViewModel>()
.RegisterType<ModelCreationViewModel>()
.AsSelf()
.SingleInstance();
build
.RegisterType<ModelCreationView>()
.AsSelf()
.SingleInstance();
build
.RegisterType<PoreInspectionViewModel>()
.AsSelf()
.SingleInstance();
build
.RegisterType<PoreInspectionView>()
.AsSelf()
.SingleInstance();
build
.RegisterType<MainWindowViewModel>()
.AsSelf()
.SingleInstance();
return build.Build();
}

2
Pores/Converters/CubicPowerOfInt.cs

@ -2,7 +2,7 @@
using System.Globalization;
using System.Windows.Data;
namespace Pores.Converters
namespace MODELING_DEF_DES_MI_VI.Converters
{
public class CubicPowerOfInt : IValueConverter
{

4
Pores/Interfaces/IPoreSpread.cs

@ -1,11 +1,11 @@
using MODELING_DEF_DES_MI_VI.Models;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace MODELING_DEF_DES_MI_VI.Interfaces
{
public interface IPoreSpread
{
ObservableCollection<Pore> GetSpread();
IList<Pore> GetSpread();
void LoadRecommendParams();
}
}

25
Pores/MODELING-DEF-DES-MI-VI.csproj

@ -53,6 +53,9 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
@ -92,6 +95,7 @@
<Compile Include="Interfaces\IPoreSpread.cs" />
<Compile Include="MainWindowViewModel.cs" />
<Compile Include="Models\BatchPoint.cs" />
<Compile Include="Models\Camera.cs" />
<Compile Include="Models\Point.cs" />
<Compile Include="Models\Point2D.cs" />
<Compile Include="Models\Point3D.cs" />
@ -103,8 +107,24 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Modules\ModelCreationUnit\ModelCreationView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\PoreInspectionUnit\PoreInspectionView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Modules\ModelCreationUnit\ModelCreationView.xaml.cs">
<DependentUpon>ModelCreationView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\ModelCreationUnit\ModelCreationViewModel.cs" />
<Compile Include="Modules\PoreInspectionUnit\PoreInspectionView.xaml.cs">
<DependentUpon>PoreInspectionView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\PoreInspectionUnit\PoreInspectionViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
@ -131,10 +151,7 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="ViewModels\" />
<Folder Include="Views\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.3.3.3\build\Fody.targets" Condition="Exists('..\packages\Fody.3.3.3\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

133
Pores/MainWindow.xaml

@ -1,120 +1,23 @@
<Window x:Class="MODELING_DEF_DES_MI_VI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:spreads="clr-namespace:MODELING_DEF_DES_MI_VI.Models.Spreads"
xmlns:converters="clr-namespace:Pores.Converters"
mc:Ignorable="d"
Title="MODELING-DEF-DES-MI-VI" Height="600" Width="1000">
<Window.Resources>
<converters:CubicPowerOfInt x:Key="CubicPowerOfInt"/>
</Window.Resources>
<Window
x:Class="MODELING_DEF_DES_MI_VI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="MODELING_DEF_DES_MI_VI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:modelcreation="clr-namespace:MODELING_DEF_DES_MI_VI.Modules.ModelCreationUnit"
xmlns:poreinspection="clr-namespace:MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit"
Title="MODELING-DEF-DES-MI-VI"
Width="1000"
Height="600"
d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<DockPanel Grid.RowSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="DimGray">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="Просмотр модели"/>
</StackPanel>
</DockPanel>
<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}"/>
<ContentControl>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Разрешение модели (n="/>
<TextBlock Text="{Binding CurrentMaterial.NumberOfPores,
Converter={StaticResource CubicPowerOfInt}, Mode=OneWay}"/>
<TextBlock Text="):"/>
</StackPanel>
</ContentControl>
<TextBox Text="{Binding CurrentMaterial.NumberOfPores, UpdateSourceTrigger=PropertyChanged}"/>
<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>
<TextBlock Text="Параметры распределения радиуса пор: "/>
<TextBlock Text="Минимальный: "/>
<TextBox Text="{Binding CurrentMaterial.MinRadius}"/>
<TextBlock Text="Максимальный: "/>
<TextBox Text="{Binding CurrentMaterial.MaxRadius}"/>
</StackPanel>
<StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Margin="5 10">
<Button Content="[Рекомендуемые параметры]" Command="{Binding LoadRecommendParamsCommand}"/>
<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}"/>-->
<Button Content="Сохранить модель в файл" Command="{Binding SaveToFileCommand}"/>
<Button Command="{Binding GenerateAllCommand}" IsEnabled="{Binding DisableGenerateAllFlag, UpdateSourceTrigger=PropertyChanged}" CommandParameter="{Binding ModelAndBatchNumber}">
<Button.Content>
<TextBlock>
<Run Text="Сгенерировать все данные ["/>
<Run><Binding Path="ModelAndBatchNumber" UpdateSourceTrigger="PropertyChanged"/></Run>
<Run Text="]"/>
</TextBlock>
</Button.Content>
</Button>
<Button Content="Открыть папку с моделями" Command="{Binding OpenModelDirectoryCommand}"/>
</StackPanel>
<StackPanel DockPanel.Dock="Top">
<TextBlock Text="Настройки выборки и экспорта" FontWeight="SemiBold" HorizontalAlignment="Center" Margin="0 5"/>
<TextBlock Text="Параметры единичного выборки:"/>
<TextBlock Text="Координаты центра (Х): "/>
<TextBox Text="{Binding BatchPoint.Center.X}"/>
<TextBlock Text="Координаты центра (Y): "/>
<TextBox Text="{Binding BatchPoint.Center.Y}"/>
<TextBlock Text="Координаты центра (Z-высота): "/>
<TextBox Text="{Binding BatchPoint.Center.Z}"/>
<TextBlock Text="Длина и ширина основания: "/>
<TextBox Text="{Binding BatchPoint.Width}"/>
<TextBlock Text="Глубина:"/>
<TextBox Text="{Binding BatchPoint.Depth}"/>
<!--<CheckBox Margin="0 5" IsChecked="{Binding RandomBatchPointFlag}" IsEnabled="False">
<TextBlock TextWrapping="Wrap" Text="Случайное координаты для выборки"/>
</CheckBox>-->
<TextBlock Text="Количество моделей/моделей и выборок генерируемое за один раз:" TextWrapping="Wrap"/>
<TextBox Text="{Binding ModelAndBatchNumber, UpdateSourceTrigger=PropertyChanged}"/>
<!--<CheckBox Margin="0 5" IsChecked="{Binding GenerateConPoresReportFlag}">
<TextBlock TextWrapping="Wrap" Text="Создавать отчет [выборки : соединенные поры в выборке]"/>
</CheckBox>-->
</StackPanel>
</DockPanel>
<ContentControl Grid.Column="0" Content="{Binding PoreInspectionUnit}" />
<ContentControl Grid.Column="1" Content="{Binding ModelCreationUnit}" />
</Grid>
</Window>

133
Pores/MainWindowViewModel.cs

@ -1,135 +1,18 @@
using MODELING_DEF_DES_MI_VI.Controllers;
using MODELING_DEF_DES_MI_VI.Interfaces;
using MODELING_DEF_DES_MI_VI.Models;
using MODELING_DEF_DES_MI_VI.Helpers;
using System.Windows.Input;
using System.Collections.Generic;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Collections.ObjectModel;
using MODELING_DEF_DES_MI_VI.Helpers;
using MODELING_DEF_DES_MI_VI.Modules.ModelCreationUnit;
using MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit;
using System.Windows;
using System.Linq;
namespace MODELING_DEF_DES_MI_VI
{
public class MainWindowViewModel : PropertyChangedClass
{
public MaterialModel CurrentMaterial { get; set; }
public ObservableCollection<Pore> Pores { get; set; } = new ObservableCollection<Pore>();
public IEnumerable<IPoreSpread> Spreads { get; set; }
public IPoreSpread SelectedSpread { get; set; }
public IPoreGenerator PoreGeneratorInstance { get; set; }
public BatchGenerator BatchGenerator { get; }
public ConnectedPoreReportGenerator ConnectedPoreReportGenerator { get; }
private ReportGenerator ReportSaver;
private bool _disableGenerateAllFlag;
public bool DisableGenerateAllFlag
{
get => !_disableGenerateAllFlag && SelectedSpread != null;
set
{
_disableGenerateAllFlag = value;
}
}
public int NumberOfPores { get; set; }
public int ModelAndBatchNumber { get; set; } = 1;
public ICommand GeneratePoresCommand { get; set; }
public ICommand SaveToFileCommand { get; set; }
public ICommand GenAndSaveBatchCommand { get; set; }
public ICommand GenerateAllCommand { get; set; }
public ICommand OpenModelDirectoryCommand { get; set; }
public ICommand LoadRecommendParamsCommand { get; set; }
public BatchPoint BatchPoint { get; set; } = new BatchPoint();
public Thread AllSavingThread { get; set; }
public MainWindowViewModel(
MaterialModel material,
IEnumerable<IPoreSpread> spreads,
IPoreGenerator poreGenerator,
ReportGenerator reportSaver,
BatchGenerator batchGenerator,
ConnectedPoreReportGenerator connectedPoreReportGenerator)
{
CurrentMaterial = material;
Spreads = spreads;
PoreGeneratorInstance = poreGenerator;
ReportSaver = reportSaver;
BatchGenerator = batchGenerator;
ConnectedPoreReportGenerator = connectedPoreReportGenerator;
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));
OpenModelDirectoryCommand = new RelayCommand(
() => Process.Start(@".\results\"),
() => Directory.Exists(@".\results\")
);
LoadRecommendParamsCommand = new RelayCommand(() => SelectedSpread.LoadRecommendParams(), () => SelectedSpread != null);
}
public void GeneratePoresToForm()
=> Pores = new ObservableCollection<Pore>(PoreGeneratorInstance.Generate(SelectedSpread));
public IList<Pore> GeneratePores()
=> PoreGeneratorInstance.Generate(SelectedSpread);
public void Save()
=> Save(Pores);
public void Save(IList<Pore> pores, int i = -1)
public UIElement PoreInspectionUnit { get; set; }
public UIElement ModelCreationUnit { get; set; }
public MainWindowViewModel(ModelCreationView modelCreationView, PoreInspectionView poreInspectionView)
{
var n = string.Format(
"model_{0}_w{1}_d{2}_h{3}_n{4}",
i,
CurrentMaterial.Width,
CurrentMaterial.Depth,
CurrentMaterial.Height,
pores.Count);
ReportSaver.Save(pores, ReportSaver.AddTime(n));
if (i == -1) OperationCompletedMessage();
PoreInspectionUnit = poreInspectionView;
ModelCreationUnit = modelCreationView;
}
public void SaveBatch()
=> SaveBatch(Pores);
public IEnumerable<Pore> SaveBatch(IEnumerable<Pore> pores, int i = -1)
{
var batch = BatchGenerator.GenerateBatch(BatchPoint, pores);
var s = string.Format("batch_{0}_n{1}", i, batch.ToList().Count);
ReportSaver.Save(batch, ReportSaver.AddTime(s));
return batch;
}
public void GenAndSaveAll(int num)
{
AllSavingThread = new Thread(() =>
{
DisableGenerateAllFlag = true;
for (int i = 0; i < num; i++)
{
List<Pore> list2;
var list = GeneratePores();
Save(list, i);
list2 = new List<Pore>(SaveBatch(list, i));
ConnectedPoreReportGenerator.CreateReport(list2, i);
}
DisableGenerateAllFlag = false;
OperationCompletedMessage();
});
AllSavingThread.Start();
}
private void OperationCompletedMessage()
=> MessageBox.Show("Операция завершена!", "Сообщение");
}
}

26
Pores/Models/Camera.cs

@ -0,0 +1,26 @@
using MODELING_DEF_DES_MI_VI.Helpers;
namespace MODELING_DEF_DES_MI_VI.Models
{
public class Camera2D : PropertyChangedClass
{
private double scale = 1;
public double Scale
{
get => scale;
set
{
CutDepth = CutDepth / scale * value;
Speed = Speed / scale * value;
DepthVisibility = DepthVisibility / scale * value;
scale = value;
}
}
public double CutDepth { get; set; }
public double DepthVisibility { get; set; }
public double Speed { get; set; }
public Point2D StartPosition { get; set; }
public int Height { get; set; }
public int Width { get; set; }
}
}

3
Pores/Models/Material.cs

@ -1,4 +1,5 @@
using MODELING_DEF_DES_MI_VI.Helpers;
using System.Collections.ObjectModel;
namespace MODELING_DEF_DES_MI_VI.Models
{
@ -11,5 +12,7 @@ namespace MODELING_DEF_DES_MI_VI.Models
public double MinRadius { get; set; }
public double MaxRadius { get; set; }
public ObservableCollection<Pore> Pores { get; set; } = new ObservableCollection<Pore>();
}
}

6
Pores/Models/Point.cs

@ -4,6 +4,12 @@ namespace MODELING_DEF_DES_MI_VI.Models
{
public class Point : PropertyChangedClass
{
public Point() { }
public Point(double x)
{
X = x;
}
public virtual double X { get; set; }
}
}

11
Pores/Models/Point2D.cs

@ -2,9 +2,16 @@
namespace MODELING_DEF_DES_MI_VI.Models
{
public class Point2D : Point
public class Point2D : PropertyChangedClass
{
public override double X { get; set; }
public virtual double X { get; set; }
public virtual double Y { get; set; }
public Point2D() { }
public Point2D(double x, double y)
{
X = x;
Y = y;
}
}
}

16
Pores/Models/Point3D.cs

@ -5,13 +5,21 @@ using System.Collections.Generic;
namespace MODELING_DEF_DES_MI_VI.Models
{
[Serializable]
public class Point3D : Point2D
public class Point3D : PropertyChangedClass
{
public override double X { get; set; }
public override double Y { get; set; }
public Point3D() { }
public Point3D(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public virtual double X { get; set; }
public virtual double Y { get; set; }
public virtual double Z { get; set; }
public List<double> ToList()
public virtual List<double> ToList()
{
return new List<double>() { X, Y, Z };
}

4
Pores/Models/Spreads/BaseSpread.cs

@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using MODELING_DEF_DES_MI_VI.Helpers;
using MODELING_DEF_DES_MI_VI.Interfaces;
@ -6,7 +6,7 @@ namespace MODELING_DEF_DES_MI_VI.Models.Spreads
{
public abstract class BaseSpread : PropertyChangedClass, IPoreSpread
{
public abstract ObservableCollection<Pore> GetSpread();
public abstract IList<Pore> GetSpread();
public virtual void LoadRecommendParams() { }
}
}

6
Pores/Models/Spreads/NormalSpread.cs

@ -1,5 +1,5 @@
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace MODELING_DEF_DES_MI_VI.Models.Spreads
{
@ -19,12 +19,12 @@ namespace MODELING_DEF_DES_MI_VI.Models.Spreads
public double GaussFunctionByHeight(Point3D c)
=> GaussFunction(c.Z, Sigma, Mu);
public override ObservableCollection<Pore> GetSpread()
public override IList<Pore> GetSpread()
{
var r = new Random();
var id = 0;
GetOptimalRadius();
var result = new ObservableCollection<Pore>();
var result = new List<Pore>();
for (int i = 0; i <= Material.NumberOfPores; i++)
for (int j = 0; j <= Material.NumberOfPores; j++)
for (int k = 0; k <= Material.NumberOfPores; k++)

146
Pores/Modules/ModelCreationUnit/ModelCreationView.xaml

@ -0,0 +1,146 @@
<UserControl
x:Class="MODELING_DEF_DES_MI_VI.Modules.ModelCreationUnit.ModelCreationView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:MODELING_DEF_DES_MI_VI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MODELING_DEF_DES_MI_VI.Modules.ModelCreationUnit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:spreads="clr-namespace:MODELING_DEF_DES_MI_VI.Models.Spreads"
d:DesignHeight="450"
d:DesignWidth="500"
mc:Ignorable="d">
<UserControl.Resources>
<converters:CubicPowerOfInt x:Key="CubicPowerOfInt" />
</UserControl.Resources>
<Grid Background="WhiteSmoke">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition Height="2*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<DockPanel
Grid.RowSpan="3"
Grid.Column="1"
Margin="5,0"
VerticalAlignment="Stretch">
<StackPanel Margin="5,0" DockPanel.Dock="Top">
<TextBlock
Margin="0,5"
HorizontalAlignment="Center"
FontWeight="SemiBold"
Text="Настройки моделирования" />
<TextBlock Text="Параметры модели материала: " />
<TextBlock Text="Ширина: " />
<TextBox Text="{Binding CurrentMaterial.Width}" />
<TextBlock Text="Глубина: " />
<TextBox Text="{Binding CurrentMaterial.Depth}" />
<TextBlock Text="Высота: " />
<TextBox Text="{Binding CurrentMaterial.Height}" />
<ContentControl>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Разрешение модели (n=" />
<TextBlock Text="{Binding CurrentMaterial.NumberOfPores, Converter={StaticResource CubicPowerOfInt}, Mode=OneWay}" />
<TextBlock Text="):" />
</StackPanel>
</ContentControl>
<TextBox Text="{Binding CurrentMaterial.NumberOfPores, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Text="Параметры модели распределения:" />
<ComboBox
Width="198"
HorizontalAlignment="Left"
ItemsSource="{Binding Spreads}"
SelectedItem="{Binding SelectedSpread}" />
<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>
<TextBlock Text="Параметры распределения радиуса пор: " />
<TextBlock Text="Минимальный: " />
<TextBox Text="{Binding CurrentMaterial.MinRadius}" />
<TextBlock Text="Максимальный: " />
<TextBox Text="{Binding CurrentMaterial.MaxRadius}" />
</StackPanel>
<StackPanel
Margin="5,10"
VerticalAlignment="Bottom"
DockPanel.Dock="Bottom">
<Button Command="{Binding LoadRecommendParamsCommand}" Content="[Рекомендуемые параметры]" />
<TextBlock Text="Результаты работы" />
<TextBlock Text="Количество пор: " />
<TextBox IsEnabled="False" Text="{Binding CurrentMaterial.Pores.Count, Mode=OneWay}" />
</StackPanel>
</DockPanel>
<DockPanel
Grid.RowSpan="3"
Grid.Column="2"
Margin="5,0">
<StackPanel VerticalAlignment="Bottom" DockPanel.Dock="Bottom">
<Button Command="{Binding GeneratePoresCommand}" Content="Сгенерировать модель" />
<!--<Button Content="Сохранить выборку из модели в файл" Command="{Binding GenAndSaveBatchCommand}"/>-->
<Button Command="{Binding SaveToFileCommand}" Content="Сохранить модель в файл" />
<Button
Command="{Binding GenerateAllCommand}"
CommandParameter="{Binding ModelAndBatchNumber}"
IsEnabled="{Binding DisableGenerateAllFlag, UpdateSourceTrigger=PropertyChanged}">
<Button.Content>
<TextBlock>
<Run Text="Сгенерировать все данные [" />
<Run>
<Binding Path="ModelAndBatchNumber" UpdateSourceTrigger="PropertyChanged" />
</Run>
<Run Text="]" />
</TextBlock>
</Button.Content>
</Button>
<Button Command="{Binding OpenModelDirectoryCommand}" Content="Открыть папку с моделями" />
</StackPanel>
<StackPanel DockPanel.Dock="Top">
<TextBlock
Margin="0,5"
HorizontalAlignment="Center"
FontWeight="SemiBold"
Text="Настройки выборки и экспорта" />
<TextBlock Text="Параметры единичного выборки:" />
<TextBlock Text="Координаты центра (Х): " />
<TextBox Text="{Binding BatchPoint.Center.X}" />
<TextBlock Text="Координаты центра (Y): " />
<TextBox Text="{Binding BatchPoint.Center.Y}" />
<TextBlock Text="Координаты центра (Z-высота): " />
<TextBox Text="{Binding BatchPoint.Center.Z}" />
<TextBlock Text="Длина и ширина основания: " />
<TextBox Text="{Binding BatchPoint.Width}" />
<TextBlock Text="Глубина:" />
<TextBox Text="{Binding BatchPoint.Depth}" />
<!--<CheckBox Margin="0 5" IsChecked="{Binding RandomBatchPointFlag}" IsEnabled="False">
<TextBlock TextWrapping="Wrap" Text="Случайное координаты для выборки"/>
</CheckBox>-->
<TextBlock Text="Количество моделей/моделей и выборок генерируемое за один раз:" TextWrapping="Wrap" />
<TextBox Text="{Binding ModelAndBatchNumber, UpdateSourceTrigger=PropertyChanged}" />
<!--<CheckBox Margin="0 5" IsChecked="{Binding GenerateConPoresReportFlag}">
<TextBlock TextWrapping="Wrap" Text="Создавать отчет [выборки : соединенные поры в выборке]"/>
</CheckBox>-->
</StackPanel>
</DockPanel>
</Grid>
</UserControl>

13
Pores/Modules/ModelCreationUnit/ModelCreationView.xaml.cs

@ -0,0 +1,13 @@
using System.Windows.Controls;
namespace MODELING_DEF_DES_MI_VI.Modules.ModelCreationUnit
{
public partial class ModelCreationView : UserControl
{
public ModelCreationView(ModelCreationViewModel viewModel)
{
DataContext = viewModel;
InitializeComponent();
}
}
}

142
Pores/Modules/ModelCreationUnit/ModelCreationViewModel.cs

@ -0,0 +1,142 @@
using MODELING_DEF_DES_MI_VI.Controllers;
using MODELING_DEF_DES_MI_VI.Helpers;
using MODELING_DEF_DES_MI_VI.Interfaces;
using MODELING_DEF_DES_MI_VI.Models;
using MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Input;
namespace MODELING_DEF_DES_MI_VI.Modules.ModelCreationUnit
{
public class ModelCreationViewModel : PropertyChangedClass
{
public MaterialModel CurrentMaterial { get; set; }
public IEnumerable<IPoreSpread> Spreads { get; set; }
public IPoreSpread SelectedSpread { get; set; }
public IPoreGenerator PoreGeneratorInstance { get; set; }
public BatchGenerator BatchGenerator { get; }
public ConnectedPoreReportGenerator ConnectedPoreReportGenerator { get; }
public PoreInspectionViewModel PoreInspectionUnit { get; }
private ReportGenerator ReportSaver;
private bool _disableGenerateAllFlag;
public bool DisableGenerateAllFlag
{
get => !_disableGenerateAllFlag && SelectedSpread != null;
set
{
_disableGenerateAllFlag = value;
}
}
public int NumberOfPores { get; set; }
public int ModelAndBatchNumber { get; set; } = 1;
public ICommand GeneratePoresCommand { get; set; }
public ICommand SaveToFileCommand { get; set; }
public ICommand GenAndSaveBatchCommand { get; set; }
public ICommand GenerateAllCommand { get; set; }
public ICommand OpenModelDirectoryCommand { get; set; }
public ICommand LoadRecommendParamsCommand { get; set; }
public BatchPoint BatchPoint { get; set; } = new BatchPoint();
public Thread AllSavingThread { get; set; }
public ModelCreationViewModel(
MaterialModel material,
IEnumerable<IPoreSpread> spreads,
IPoreGenerator poreGenerator,
ReportGenerator reportSaver,
BatchGenerator batchGenerator,
ConnectedPoreReportGenerator connectedPoreReportGenerator,
PoreInspectionViewModel poreInspectionUnit)
{
CurrentMaterial = material;
Spreads = spreads;
PoreGeneratorInstance = poreGenerator;
ReportSaver = reportSaver;
BatchGenerator = batchGenerator;
ConnectedPoreReportGenerator = connectedPoreReportGenerator;
PoreInspectionUnit = poreInspectionUnit;
GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedSpread != null);
SaveToFileCommand = new RelayCommand(Save, () => CurrentMaterial.Pores?.Count > 0);
GenAndSaveBatchCommand = new RelayCommand(SaveBatch, () => CurrentMaterial.Pores?.Count > 0);
GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c));
OpenModelDirectoryCommand = new RelayCommand(
() => Process.Start(@".\results\"),
() => Directory.Exists(@".\results\")
);
LoadRecommendParamsCommand = new RelayCommand(() => SelectedSpread.LoadRecommendParams(), () => SelectedSpread != null);
}
public void GeneratePoresToForm()
{
CurrentMaterial.Pores.Clear();
PoreGeneratorInstance.Generate(SelectedSpread).ToList().ForEach(p => CurrentMaterial.Pores.Add(p));
PoreInspectionUnit.UpdateModel();
}
public IList<Pore> GeneratePores()
=> PoreGeneratorInstance.Generate(SelectedSpread);
public void Save()
=> Save(CurrentMaterial.Pores);
public void Save(IList<Pore> pores, int i = -1)
{
var n = string.Format(
"model_{0}_w{1}_d{2}_h{3}_n{4}",
i,
CurrentMaterial.Width,
CurrentMaterial.Depth,
CurrentMaterial.Height,
pores.Count);
ReportSaver.Save(pores, ReportSaver.AddTime(n));
if (i == -1) OperationCompletedMessage();
}
public void SaveBatch()
=> SaveBatch(CurrentMaterial.Pores);
public IEnumerable<Pore> SaveBatch(IEnumerable<Pore> pores, int i = -1)
{
var batch = BatchGenerator.GenerateBatch(BatchPoint, pores);
var s = string.Format("batch_{0}_n{1}", i, batch.ToList().Count);
ReportSaver.Save(batch, ReportSaver.AddTime(s));
return batch;
}
public void GenAndSaveAll(int num)
{
AllSavingThread = new Thread(() =>
{
DisableGenerateAllFlag = true;
for (int i = 0; i < num; i++)
{
List<Pore> list2;
var list = GeneratePores();
Save(list, i);
list2 = new List<Pore>(SaveBatch(list, i));
ConnectedPoreReportGenerator.CreateReport(list2, i);
}
DisableGenerateAllFlag = false;
OperationCompletedMessage();
});
AllSavingThread.Start();
}
private void OperationCompletedMessage()
=> MessageBox.Show("Операция завершена!", "Сообщение");
}
}

57
Pores/Modules/PoreInspectionUnit/PoreInspectionView.xaml

@ -0,0 +1,57 @@
<UserControl
x:Class="MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit.PoreInspectionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:MODELING_DEF_DES_MI_VI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:local="clr-namespace:MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DataContext="{d:DesignInstance local:PoreInspectionViewModel}"
d:DesignHeight="450"
d:DesignWidth="400"
mc:Ignorable="d">
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Black">
<TextBlock Text="Просмотр модели недоступен">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding GlobalMaterial.Pores.Count}" Value="0">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<ItemsControl Focusable="True" ItemsSource="{Binding Ellipses}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas
Width="{Binding Camera.Width, Mode=OneWayToSource}"
Height="{Binding Camera.Height, Mode=OneWayToSource}"
IsItemsHost="True">
<Canvas.Style>
<Style TargetType="Canvas">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding Ellipses.Count}" Value="0">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Canvas.Style>
</Canvas>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">
<TextBlock Foreground="White" Text="{Binding Camera.Scale, StringFormat={}Масштаб отрисовки: 1 к {0}}" />
<TextBlock Foreground="White" Text="{Binding Camera.Speed, StringFormat={}Скорость камеры: {0}}" />
<TextBlock Foreground="White" Text="{Binding Camera.CutDepth, StringFormat={}Глубина среза: {0}}" />
</StackPanel>
</Grid>
</UserControl>

13
Pores/Modules/PoreInspectionUnit/PoreInspectionView.xaml.cs

@ -0,0 +1,13 @@
using System.Windows.Controls;
namespace MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit
{
public partial class PoreInspectionView : UserControl
{
public PoreInspectionView(PoreInspectionViewModel viewModel)
{
DataContext = viewModel;
InitializeComponent();
}
}
}

170
Pores/Modules/PoreInspectionUnit/PoreInspectionViewModel.cs

@ -0,0 +1,170 @@
using MODELING_DEF_DES_MI_VI.Helpers;
using MODELING_DEF_DES_MI_VI.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit
{
public class PoreInspectionViewModel : PropertyChangedClass
{
public MaterialModel GlobalMaterial { get; set; }
public ObservableCollection<Shape> Ellipses { get; set; } = new ObservableCollection<Shape>();
public Camera2D Camera { get; set; }
private CancellationTokenSource ctSource { get; set; }
public PoreInspectionViewModel(MaterialModel material)
{
GlobalMaterial = material;
Camera = new Camera2D()
{
Speed = 1.0,
CutDepth = 1.0,
DepthVisibility = 2.0,
Scale = 40,
StartPosition = new Point2D(0 * 40, 0 * 40),
};
Application.Current.MainWindow.KeyDown += OnKeyDown;
}
public async Task UpdateModel()
{
await Task.Run(() =>
{
try
{
ctSource = new CancellationTokenSource();
Application.Current.Dispatcher.Invoke(() =>
{
List<Shape> bufferedShapes = new List<Shape>();
bufferedShapes.Add(CreateMaterial());
var visibilityRange = Tuple.Create(Camera.CutDepth / Camera.Scale, (Camera.DepthVisibility + Camera.CutDepth) / Camera.Scale);
foreach (Pore pore in GlobalMaterial.Pores)
{
if (ctSource.IsCancellationRequested)
return;
if (visibilityRange.Item1 < pore.Point.Z && pore.Point.Z < visibilityRange.Item2)
bufferedShapes.Add(CreateEllipse(pore));
}
Ellipses.Clear();
bufferedShapes.ForEach(s => Ellipses.Add(s));
});
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace, "Не удалось отобразить модель");
}
});
}
private Ellipse CreateEllipse(Pore pore)
{
var e = new Ellipse();
var cuttingHeight = Math.Abs(pore.Point.Z * Camera.Scale - Camera.CutDepth);
if (cuttingHeight < pore.Radius * Camera.Scale)
{
e.Fill = Brushes.Violet;
var cuttedDiameter = Math.Sqrt(Math.Pow(pore.Radius * Camera.Scale, 2) - Math.Pow(cuttingHeight, 2)) * 2;
e.Width = cuttedDiameter;
e.Height = cuttedDiameter;
}
else
{
e.Opacity = 0.5;
byte colorDegree = Convert.ToByte(pore.Point.Z * Camera.Scale / (Camera.DepthVisibility + Camera.CutDepth) * 255);
e.Fill = new SolidColorBrush(Color.FromRgb(colorDegree, colorDegree, colorDegree));
e.Width = pore.Radius * 2 * Camera.Scale;
e.Height = pore.Radius * 2 * Camera.Scale;
}
var x = Camera.Scale * pore.Point.X + Camera.StartPosition.X - e.Width / 2;
var y = Camera.Scale * pore.Point.Y + Camera.StartPosition.Y - e.Height / 2;
e.SetValue(Canvas.LeftProperty, x);
e.SetValue(Canvas.TopProperty, y);
return e;
}
private Rectangle CreateMaterial()
{
var material = new Rectangle()
{
Width = Camera.Scale * GlobalMaterial.Width,
Height = Camera.Scale * GlobalMaterial.Height,
Fill = Brushes.DarkBlue,
};
material.SetValue(Canvas.LeftProperty, Camera.StartPosition.X);
material.SetValue(Canvas.TopProperty, Camera.StartPosition.Y);
return material;
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.A:
ctSource.Cancel();
Camera.StartPosition.X -= Camera.Speed;
UpdateModel();
break;
case Key.D:
ctSource.Cancel();
Camera.StartPosition.X += Camera.Speed;
UpdateModel();
break;
case Key.W:
ctSource.Cancel();
Camera.StartPosition.Y -= Camera.Speed;
UpdateModel();
break;
case Key.S:
ctSource.Cancel();
Camera.StartPosition.Y += Camera.Speed;
UpdateModel();
break;
case Key.OemMinus:
ctSource.Cancel();
Camera.Scale /= 2;
UpdateModel();
break;
case Key.OemPlus:
ctSource.Cancel();
Camera.Scale *= 2;
UpdateModel();
break;
case Key.R:
ctSource.Cancel();
Camera.CutDepth += Camera.Speed;
UpdateModel();
break;
case Key.F:
ctSource.Cancel();
Camera.CutDepth -= Camera.Speed;
UpdateModel();
break;
case Key.D9:
if (Camera.Speed > 1)
{
ctSource.Cancel();
Camera.Speed--;
UpdateModel();
}
break;
case Key.D0:
ctSource.Cancel();
Camera.Speed++;
UpdateModel();
break;
}
}
}
}
Loading…
Cancel
Save