defend
6 years ago
13 changed files with 158 additions and 51 deletions
@ -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<Pore> Pores { get; } |
|||
|
|||
public BatchGenerator(Material material, IList<Pore> 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; |
|||
} |
|||
} |
|||
} |
@ -1,27 +0,0 @@ |
|||
using Newtonsoft.Json; |
|||
using Pores.Models; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
|
|||
namespace Pores.Controllers |
|||
{ |
|||
public class PoresToFileController : BaseSaveController<IList<Pore>> |
|||
{ |
|||
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; |
|||
} |
|||
} |
|||
} |
@ -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<IEnumerable<Pore>> |
|||
{ |
|||
public string FileName { get; set; } |
|||
|
|||
public override IEnumerable<Pore> Load() |
|||
{ |
|||
try |
|||
{ |
|||
var data = File.ReadAllText(FileName); |
|||
var output = JsonConvert.DeserializeObject<IList<Pore>>(data); |
|||
return output; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
MessageBox.Show(ex.Message); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
public override void Save(IEnumerable<Pore> data) |
|||
{ |
|||
var output = JsonConvert.SerializeObject(data); |
|||
try |
|||
{ |
|||
File.WriteAllText(FileName, output); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
MessageBox.Show(ex.Message); |
|||
} |
|||
} |
|||
|
|||
public PoresToFileSaver(string fileName) |
|||
{ |
|||
FileName = fileName; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
using Pores.Helpers; |
|||
|
|||
namespace Pores.Models |
|||
{ |
|||
public class Point : PropertyChangedClass |
|||
{ |
|||
public double X { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
namespace Pores.Models |
|||
{ |
|||
public class Point2D : Point |
|||
{ |
|||
public double Y { get; set; } |
|||
} |
|||
} |
Loading…
Reference in new issue