diff --git a/Pores/Controllers/BaseSaveController.cs b/Pores/Controllers/BaseSaveController.cs index 9bfe999..45b89a1 100644 --- a/Pores/Controllers/BaseSaveController.cs +++ b/Pores/Controllers/BaseSaveController.cs @@ -2,8 +2,7 @@ { public abstract class BaseSaveController { - public virtual TData Data { get; set; } = default(TData); - public abstract void Save(); - public abstract void Load(); + public abstract void Save(TData data); + public abstract TData Load(); } } diff --git a/Pores/Controllers/BatchGenerator.cs b/Pores/Controllers/BatchGenerator.cs new file mode 100644 index 0000000..a2a3512 --- /dev/null +++ b/Pores/Controllers/BatchGenerator.cs @@ -0,0 +1,41 @@ +using Pores.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Pores.Controllers +{ + public class BatchGenerator + { + public PoresToFileSaver batchSaver = new PoresToFileSaver("batch.log"); + + public Material Material { get; } + public IList Pores { get; } + + public BatchGenerator(Material material, IList pores) + { + Material = material; + Pores = pores; + } + + public void GenerateBatch(Point3D center, double width, double depth) + { + var p1 = new Point3D() { X = center.X - width / 2, Y = center.Y - width / 2, Z = Math.Abs(center.Z - depth) }; + var p2 = new Point3D() { X = center.X + width / 2, Y = center.Y + width / 2, Z = center.Z }; + batchSaver.FileName = "batch_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".log"; + batchSaver.Save(Pores.Where(p => IsPointInsideOfCube(p.Point, p1, p2))); + } + + public bool IsPointInsideOfCube(Point3D p, Point3D vertex1, Point3D vertex2) + { + if (vertex1.X <= p.X && p.X <= vertex2.X) + if (vertex1.Y <= p.Y && p.Y <= vertex2.Y) + if (vertex1.Z <= p.Z && p.Z <= vertex2.Z) + return true; + return false; + } + } +} diff --git a/Pores/Controllers/PoresToFileController.cs b/Pores/Controllers/PoresToFileController.cs deleted file mode 100644 index d5229be..0000000 --- a/Pores/Controllers/PoresToFileController.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Newtonsoft.Json; -using Pores.Models; -using System.Collections.Generic; -using System.IO; - -namespace Pores.Controllers -{ - public class PoresToFileController : BaseSaveController> - { - public string FileName { get; } - - public override void Load() - { - } - - public override void Save() - { - var output = JsonConvert.SerializeObject(Data); - File.WriteAllText(FileName, output); - } - - public PoresToFileController(string fileName) - { - FileName = fileName; - } - } -} diff --git a/Pores/Controllers/PoresToFileSaver.cs b/Pores/Controllers/PoresToFileSaver.cs new file mode 100644 index 0000000..b963458 --- /dev/null +++ b/Pores/Controllers/PoresToFileSaver.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; +using Pores.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows; + +namespace Pores.Controllers +{ + public class PoresToFileSaver : BaseSaveController> + { + public string FileName { get; set; } + + public override IEnumerable Load() + { + try + { + var data = File.ReadAllText(FileName); + var output = JsonConvert.DeserializeObject>(data); + return output; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + return null; + } + } + + public override void Save(IEnumerable data) + { + var output = JsonConvert.SerializeObject(data); + try + { + File.WriteAllText(FileName, output); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + public PoresToFileSaver(string fileName) + { + FileName = fileName; + } + } +} diff --git a/Pores/MainWindow.xaml b/Pores/MainWindow.xaml index 238b716..6c10687 100644 --- a/Pores/MainWindow.xaml +++ b/Pores/MainWindow.xaml @@ -9,14 +9,14 @@ Title="Pores" Height="450" Width="800"> - + + - @@ -33,14 +33,14 @@ - + - + @@ -56,8 +56,28 @@ + +