|
|
@ -5,15 +5,15 @@ using Pores.Helpers; |
|
|
|
using System.Windows.Input; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Threading; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
using System.IO; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
|
|
|
|
namespace Pores |
|
|
|
{ |
|
|
|
public class MainWindowViewModel : PropertyChangedClass |
|
|
|
{ |
|
|
|
public Material CurrentMaterial { get; set; } |
|
|
|
public MaterialModel CurrentMaterial { get; set; } |
|
|
|
public ObservableCollection<Pore> Pores { get; set; } = new ObservableCollection<Pore>(); |
|
|
|
public IEnumerable<IPoreSpread> Spreads { get; set; } |
|
|
|
|
|
|
@ -24,9 +24,15 @@ namespace Pores |
|
|
|
|
|
|
|
private ReportGenerator ReportSaver; |
|
|
|
|
|
|
|
public bool GenerateBatchForEachModelFlag { get; set; } = true; |
|
|
|
public bool EnableControlsFlag { get; set; } = true; |
|
|
|
public bool GenerateConnectedPoresReportFlag { get; set; } = true; |
|
|
|
private bool _disableGenerateAllFlag; |
|
|
|
public bool DisableGenerateAllFlag |
|
|
|
{ |
|
|
|
get => !_disableGenerateAllFlag && SelectedSpread != null; |
|
|
|
set |
|
|
|
{ |
|
|
|
_disableGenerateAllFlag = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public int NumberOfPores { get; set; } |
|
|
|
public int ModelAndBatchNumber { get; set; } = 1; |
|
|
@ -34,23 +40,24 @@ namespace Pores |
|
|
|
public ICommand GeneratePoresCommand { get; set; } |
|
|
|
public ICommand SaveToFileCommand { get; set; } |
|
|
|
public ICommand GenAndSaveBatchCommand { get; set; } |
|
|
|
public ICommand GenerateAllCommand { 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( |
|
|
|
Material material, |
|
|
|
IEnumerable<IPoreSpread> localizations, |
|
|
|
MaterialModel material, |
|
|
|
IEnumerable<IPoreSpread> spreads, |
|
|
|
IPoreGenerator poreGenerator, |
|
|
|
ReportGenerator reportSaver, |
|
|
|
BatchGenerator batchGenerator, |
|
|
|
ConnectedPoreReportGenerator connectedPoreReportGenerator) |
|
|
|
{ |
|
|
|
CurrentMaterial = material; |
|
|
|
Spreads = localizations; |
|
|
|
Spreads = spreads; |
|
|
|
PoreGeneratorInstance = poreGenerator; |
|
|
|
ReportSaver = reportSaver; |
|
|
|
BatchGenerator = batchGenerator; |
|
|
@ -59,26 +66,21 @@ namespace Pores |
|
|
|
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 (SelectedSpread != null) |
|
|
|
if (AllSavingThread?.IsAlive != true) |
|
|
|
return true; |
|
|
|
return false; |
|
|
|
}); |
|
|
|
GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c)); |
|
|
|
OpenModelDirectoryCommand = new RelayCommand( |
|
|
|
() => Process.Start(@".\results\"), |
|
|
|
() => Process.Start(@".\results\"), |
|
|
|
() => Directory.Exists(@".\results\") |
|
|
|
); |
|
|
|
LoadRecommendParamsCommand = new RelayCommand(() => SelectedSpread.LoadRecommendParams(), () => SelectedSpread != null); |
|
|
|
} |
|
|
|
|
|
|
|
public void GeneratePoresToForm() |
|
|
|
public void GeneratePoresToForm() |
|
|
|
=> Pores = new ObservableCollection<Pore>(PoreGeneratorInstance.Generate(SelectedSpread)); |
|
|
|
|
|
|
|
public IList<Pore> GeneratePores() |
|
|
|
public IList<Pore> GeneratePores() |
|
|
|
=> PoreGeneratorInstance.Generate(SelectedSpread); |
|
|
|
|
|
|
|
public void Save() |
|
|
|
public void Save() |
|
|
|
=> Save(Pores); |
|
|
|
|
|
|
|
public void Save(IList<Pore> pores, int i = 0) |
|
|
@ -86,35 +88,39 @@ namespace Pores |
|
|
|
var n = string.Format( |
|
|
|
"model_{0}_w{1}_d{2}_h{3}_n{4}", |
|
|
|
i, |
|
|
|
CurrentMaterial.Width, |
|
|
|
CurrentMaterial.Depth, |
|
|
|
CurrentMaterial.Width, |
|
|
|
CurrentMaterial.Depth, |
|
|
|
CurrentMaterial.Height, |
|
|
|
pores.Count); |
|
|
|
|
|
|
|
ReportSaver.Save(pores, ReportSaver.AddOther(n)); |
|
|
|
} |
|
|
|
|
|
|
|
public void SaveBatch() |
|
|
|
public void SaveBatch() |
|
|
|
=> SaveBatch(Pores); |
|
|
|
|
|
|
|
public void SaveBatch(IList<Pore> pores, int i = 0) |
|
|
|
=> BatchGenerator.GenerateBatch(BatchPoint, pores, i); |
|
|
|
public IEnumerable<Pore> SaveBatch(IEnumerable<Pore> pores, int i = -1) |
|
|
|
{ |
|
|
|
var batch = BatchGenerator.GenerateBatch(BatchPoint, pores); |
|
|
|
if (i != -1) |
|
|
|
ReportSaver.Save(batch, ReportSaver.AddOther(string.Format("batch_{0}", i))); |
|
|
|
return batch; |
|
|
|
} |
|
|
|
|
|
|
|
public void GenAndSaveAll(int num) |
|
|
|
{ |
|
|
|
AllSavingThread = new Thread(() => |
|
|
|
{ |
|
|
|
EnableControlsFlag = false; |
|
|
|
DisableGenerateAllFlag = true; |
|
|
|
for (int i = 0; i < num; i++) |
|
|
|
{ |
|
|
|
List<Pore> list2; |
|
|
|
var list = GeneratePores(); |
|
|
|
Save(list, i); |
|
|
|
if (GenerateBatchForEachModelFlag) |
|
|
|
SaveBatch(list, i); |
|
|
|
if (GenerateConnectedPoresReportFlag) |
|
|
|
ConnectedPoreReportGenerator.CreateReport(list, i); |
|
|
|
list2 = new List<Pore>(SaveBatch(list, i)); |
|
|
|
ConnectedPoreReportGenerator.CreateReport(list2, i); |
|
|
|
} |
|
|
|
EnableControlsFlag = true; |
|
|
|
DisableGenerateAllFlag = false; |
|
|
|
}); |
|
|
|
AllSavingThread.Start(); |
|
|
|
} |
|
|
|