From b83bc18121bd383ee7689ec1ce1899b7e625395b Mon Sep 17 00:00:00 2001 From: defend Date: Sun, 9 Dec 2018 19:51:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81,=20=D0=B7=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BC=D0=B0=D1=8E=D1=89=D0=B8=D0=B9=D1=81=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=BE=D0=BA,=20=D0=B0=20=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D0=B6=D0=B5=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D1=8F?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=BE=D0=BA=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pores/Controllers/BaseSaveController.cs | 5 +- Pores/Controllers/BatchGenerator.cs | 41 ++++++++++++++++ Pores/Controllers/PoresToFileController.cs | 27 ----------- Pores/Controllers/PoresToFileSaver.cs | 47 +++++++++++++++++++ Pores/MainWindow.xaml | 32 ++++++++++--- Pores/MainWindowViewModel.cs | 22 ++++++--- .../Localizations/NormalLocalization.cs | 4 +- Pores/Models/Material.cs | 2 +- Pores/Models/Point.cs | 9 ++++ Pores/Models/Point2D.cs | 7 +++ Pores/Models/{Coordinate.cs => Point3D.cs} | 4 +- Pores/Models/Pore.cs | 2 +- Pores/Pores.csproj | 7 ++- 13 files changed, 158 insertions(+), 51 deletions(-) create mode 100644 Pores/Controllers/BatchGenerator.cs delete mode 100644 Pores/Controllers/PoresToFileController.cs create mode 100644 Pores/Controllers/PoresToFileSaver.cs create mode 100644 Pores/Models/Point.cs create mode 100644 Pores/Models/Point2D.cs rename Pores/Models/{Coordinate.cs => Point3D.cs} (71%) 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 @@ + +