Nikita Romanenko
6 years ago
20 changed files with 681 additions and 271 deletions
@ -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> |
|||
|
@ -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(); |
|||
} |
|||
} |
|||
|
@ -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> |
|||
|
@ -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("Операция завершена!", "Сообщение"); |
|||
} |
|||
} |
|||
|
@ -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; } |
|||
} |
|||
} |
@ -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> |
@ -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(); |
|||
} |
|||
} |
|||
} |
@ -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("Операция завершена!", "Сообщение"); |
|||
} |
|||
} |
@ -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> |
@ -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(); |
|||
} |
|||
} |
|||
} |
@ -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…
Reference in new issue