diff --git a/project/Morpho/Morpho25/Geometry/Building.cs b/project/Morpho/Morpho25/Geometry/Building.cs index d980150..66306f6 100644 --- a/project/Morpho/Morpho25/Geometry/Building.cs +++ b/project/Morpho/Morpho25/Geometry/Building.cs @@ -3,23 +3,30 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; namespace Morpho25.Geometry { + [DisplayName("Building")] /// /// Building class. /// public class Building : Entity, IEquatable { - [JsonProperty("observeBPS")] + [DisplayName("Name")] + [Description("Name of the building group")] + [JsonProperty("name")] /// - /// Enable Building BPS output + /// Name of the building. /// - public bool ObserveBPS { get; } + public override string Name { get; } - [JsonProperty("geometry")] + [DisplayName("Geometry")] + [Description("Solid geometry")] + [JsonProperty("geometry", Required = Required.Always)] /// /// Geometry of the building. /// @@ -56,6 +63,8 @@ public class Building : Entity, IEquatable /// public List BuildingGreenWallRows { get; private set; } + [DisplayName("Material")] + [Description("Facade and roof materials")] [JsonProperty("material")] /// /// Material of the building. @@ -74,11 +83,13 @@ protected set } - [JsonProperty("name")] + [DisplayName("Observe BPS")] + [Description("Export BPS output")] + [JsonProperty("observeBPS")] /// - /// Name of the building. + /// Enable Building BPS output /// - public override string Name { get; } + public bool ObserveBPS { get; } [JsonConstructor] /// diff --git a/project/Morpho/Morpho25/Geometry/Entity.cs b/project/Morpho/Morpho25/Geometry/Entity.cs index 9579465..3c04639 100644 --- a/project/Morpho/Morpho25/Geometry/Entity.cs +++ b/project/Morpho/Morpho25/Geometry/Entity.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.ComponentModel; namespace Morpho25.Geometry { @@ -25,6 +26,8 @@ public abstract class Entity /// public abstract string Name { get; } + [DisplayName("ID")] + [Description("Numeric ID of the entity")] [JsonProperty("id")] /// /// ID of the entity. diff --git a/project/Morpho/Morpho25/Geometry/Grid.cs b/project/Morpho/Morpho25/Geometry/Grid.cs index d51bed5..8949acc 100644 --- a/project/Morpho/Morpho25/Geometry/Grid.cs +++ b/project/Morpho/Morpho25/Geometry/Grid.cs @@ -8,6 +8,7 @@ namespace Morpho25.Geometry { + [DisplayName("Grid")] /// /// Grid class. /// diff --git a/project/Morpho/Morpho25/Geometry/Material.cs b/project/Morpho/Morpho25/Geometry/Material.cs index f2ee9ad..25274a9 100644 --- a/project/Morpho/Morpho25/Geometry/Material.cs +++ b/project/Morpho/Morpho25/Geometry/Material.cs @@ -1,5 +1,8 @@ -using Newtonsoft.Json; +using Morpho25.Utility; +using Newtonsoft.Json; using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.Linq; namespace Morpho25.Geometry @@ -50,6 +53,8 @@ public class Material : IEquatable /// public const string DEFAULT_PLANT_3D = "0000C2"; + [MinLength(1)] + [MaxLength(4)] [JsonProperty("ids", Required = Required.Always)] /// /// Material array of ID. diff --git a/project/Morpho/Morpho25/Geometry/Plant2d.cs b/project/Morpho/Morpho25/Geometry/Plant2d.cs index 92a0b7f..b629d25 100644 --- a/project/Morpho/Morpho25/Geometry/Plant2d.cs +++ b/project/Morpho/Morpho25/Geometry/Plant2d.cs @@ -1,27 +1,43 @@ using Morpho25.Utility; using MorphoGeometry; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.ComponentModel; namespace Morpho25.Geometry { + [DisplayName("Simple Plant")] /// /// Plant 2D class. /// - public class Plant2d : Entity + public class Plant2d : Entity, IEquatable { - /// - /// Geometry of the plant 2D. - /// - public FaceGroup Geometry { get; } + [DisplayName("Name")] + [Description("Name of the simple plant group")] + [JsonProperty("name")] /// /// Name of the plant 2D. /// public override string Name { get; } + + [DisplayName("Geometry")] + [Description("Flat or solid geometry")] + [JsonProperty("geometry", Required = Required.Always)] + /// + /// Geometry of the plant 2D. + /// + public FaceGroup Geometry { get; } + + [JsonIgnore] /// /// Matrix 2D of the plant 2D. /// public Matrix2d IDmatrix { get; private set; } + + [DisplayName("Material")] + [Description("Simple plant type")] + [JsonProperty("material")] /// /// Material of the plant 2D. /// @@ -38,15 +54,16 @@ protected set } } + + [JsonConstructor] /// /// Create a new plant 2D. /// - /// Grid object. /// Geometry of the plant 2D. /// Numerical ID. /// Code of the material. /// Name of the plant 2D. - public Plant2d(Grid grid, FaceGroup geometry, + public Plant2d(FaceGroup geometry, int id, string code = null, string name = null) { ID = id; @@ -55,11 +72,9 @@ public Plant2d(Grid grid, FaceGroup geometry, ? CreateMaterial(Material.DEFAULT_PLANT_2D, code) : CreateMaterial(Material.DEFAULT_PLANT_2D); Name = name ?? "PlantGroup"; - - SetMatrix(grid); } - private void SetMatrix(Grid grid) + public void SetMatrix(Grid grid) { Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, ""); @@ -81,5 +96,74 @@ public override string ToString() Name, ID, Material.IDs[0]); } + public string Serialize() + { + return JsonConvert.SerializeObject(this); + } + + public static Plant2d Deserialize(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + public bool Equals(Plant2d other) + { + if (other == null) + return false; + + if (other != null + && other.ID == this.ID + && other.Name == this.Name + && other.Material == this.Material + && other.Geometry == this.Geometry) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + var plantObj = obj as Plant2d; + if (plantObj == null) + return false; + else + return Equals(plantObj); + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 23 + ID.GetHashCode(); + hash = hash * 23 + Name.GetHashCode(); + hash = hash * 23 + Material.GetHashCode(); + hash = hash * 23 + Geometry.GetHashCode(); + return hash; + } + } + + public static bool operator ==(Plant2d plant1, Plant2d plant2) + { + if (((object)plant1) == null || ((object)plant2) == null) + return Object.Equals(plant1, plant2); + + return plant1.Equals(plant2); + } + + public static bool operator !=(Plant2d plant1, Plant2d plant2) + { + return !(plant1 == plant2); + } } } diff --git a/project/Morpho/Morpho25/Geometry/Plant3d.cs b/project/Morpho/Morpho25/Geometry/Plant3d.cs index c8914e0..3986743 100644 --- a/project/Morpho/Morpho25/Geometry/Plant3d.cs +++ b/project/Morpho/Morpho25/Geometry/Plant3d.cs @@ -1,21 +1,38 @@ using Morpho25.Utility; using MorphoGeometry; +using Newtonsoft.Json; using System; +using System.ComponentModel; namespace Morpho25.Geometry { + [DisplayName("Plant3D")] /// /// Plant 3D class. /// - public class Plant3d : Entity + public class Plant3d : Entity, IEquatable { private const int SHIFT = 1; + [DisplayName("Name")] + [Description("Name of the plant3D group")] + [JsonProperty("name")] + /// + /// Name of the plant 3D. + /// + public override string Name { get; } + + [DisplayName("Geometry")] + [Description("Point geometry")] + [JsonProperty("geometry", Required = Required.Always)] /// /// Geometry of the plant 3D. /// public Vector Geometry { get; } + [DisplayName("Material")] + [Description("Plant3D type")] + [JsonProperty("material")] /// /// Material of the plant 3D. /// @@ -32,10 +49,8 @@ protected set } } - /// - /// Name of the plant 3D. - /// - public override string Name { get; } + + [JsonIgnore] /// /// Location of the plant 3D in the grid. /// @@ -43,11 +58,10 @@ protected set /// /// Create a new plant 3D. /// - /// Grid object. /// Geometry of the plant 3D. /// Code of the material. /// Name of the plant 3D. - public Plant3d(Grid grid, Vector geometry, + public Plant3d(Vector geometry, string code = null, string name = null) { Geometry = geometry; @@ -55,11 +69,9 @@ public Plant3d(Grid grid, Vector geometry, ? CreateMaterial(Material.DEFAULT_PLANT_3D, code) : CreateMaterial(Material.DEFAULT_PLANT_3D); Name = name ?? "PlantGroup"; - - SetPixel(grid); } - private void SetPixel(Grid grid) + public void SetPixel(Grid grid) { Pixel = new Pixel { @@ -79,5 +91,72 @@ public override string ToString() Pixel.I, Pixel.J, Pixel.K)); } + public string Serialize() + { + return JsonConvert.SerializeObject(this); + } + + public static Plant3d Deserialize(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + public bool Equals(Plant3d other) + { + if (other == null) + return false; + + if (other != null + && other.Name == this.Name + && other.Material == this.Material + && other.Geometry == this.Geometry) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + var plantObj = obj as Plant3d; + if (plantObj == null) + return false; + else + return Equals(plantObj); + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 23 + Name.GetHashCode(); + hash = hash * 23 + Material.GetHashCode(); + hash = hash * 23 + Geometry.GetHashCode(); + return hash; + } + } + + public static bool operator ==(Plant3d plant1, Plant3d plant2) + { + if (((object)plant1) == null || ((object)plant2) == null) + return Object.Equals(plant1, plant2); + + return plant1.Equals(plant2); + } + + public static bool operator !=(Plant3d plant1, Plant3d plant2) + { + return !(plant1 == plant2); + } } } diff --git a/project/Morpho/Morpho25/Geometry/Receptor.cs b/project/Morpho/Morpho25/Geometry/Receptor.cs index c03be04..4ad14ad 100644 --- a/project/Morpho/Morpho25/Geometry/Receptor.cs +++ b/project/Morpho/Morpho25/Geometry/Receptor.cs @@ -1,27 +1,40 @@ using Morpho25.Utility; using MorphoGeometry; +using Newtonsoft.Json; using System; - +using System.ComponentModel; namespace Morpho25.Geometry { + [DisplayName("Receptor")] /// /// Receptor class. /// - public class Receptor : Entity + public class Receptor : Entity, IEquatable { - /// - /// Geometry of the receptor. - /// - public Vector Geometry { get; } + [DisplayName("Name")] + [Description("Name of the receptor")] + [JsonProperty("name", Required = Required.Always)] /// /// Name of the receptor. /// public override string Name { get; } + + [DisplayName("Geometry")] + [Description("Point geometry")] + [JsonProperty("geometry", Required = Required.Always)] + /// + /// Geometry of the receptor. + /// + public Vector Geometry { get; } + + [JsonIgnore] /// /// Location of the receptor in the grid. /// public Pixel Pixel { get; private set; } + + [JsonIgnore] /// /// Material of the receptor. /// @@ -33,21 +46,15 @@ public override Material Material /// /// Create a new receptor. /// - /// Grid object. /// Geometry of the receptor. /// Name of the receptor. - public Receptor(Grid grid, - Vector geometry, string name = null) + public Receptor(Vector geometry, string name) { Geometry = geometry; - SetPixel(grid); - string text = name ?? "R_"; - - Name = text + String.Join("_", Pixel.I, - Pixel.J, Pixel.K); + Name = name; } - private void SetPixel(Grid grid) + public void SetPixel(Grid grid) { Pixel = new Pixel { @@ -64,5 +71,71 @@ public override string ToString() { return String.Format("Receptor::{0}", Name); } + + public string Serialize() + { + return JsonConvert.SerializeObject(this); + } + + public static Receptor Deserialize(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + public bool Equals(Receptor other) + { + if (other == null) + return false; + + if (other != null + && other.Name == this.Name + && other.Geometry == this.Geometry) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + var receptorObj = obj as Receptor; + if (receptorObj == null) + return false; + else + return Equals(receptorObj); + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 23 + Name.GetHashCode(); + hash = hash * 23 + Geometry.GetHashCode(); + return hash; + } + } + + public static bool operator ==(Receptor receptor1, Receptor receptor2) + { + if (((object)receptor1) == null || ((object)receptor2) == null) + return Object.Equals(receptor1, receptor2); + + return receptor1.Equals(receptor2); + } + + public static bool operator !=(Receptor receptor1, Receptor receptor2) + { + return !(receptor1 == receptor2); + } } } diff --git a/project/Morpho/Morpho25/Geometry/Soil.cs b/project/Morpho/Morpho25/Geometry/Soil.cs index 822c6c2..660db2c 100644 --- a/project/Morpho/Morpho25/Geometry/Soil.cs +++ b/project/Morpho/Morpho25/Geometry/Soil.cs @@ -1,27 +1,43 @@ using Morpho25.Utility; using MorphoGeometry; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.ComponentModel; namespace Morpho25.Geometry { + [DisplayName("Soil")] /// /// Soil class. /// - public class Soil : Entity + public class Soil : Entity, IEquatable { - /// - /// Geometry of the soil. - /// - public FaceGroup Geometry { get; } + [DisplayName("Name")] + [Description("Name of the soil group")] + [JsonProperty("name")] /// /// Name of the soil. /// public override string Name { get; } + + [DisplayName("Geometry")] + [Description("Flat or solid geometry")] + [JsonProperty("geometry", Required = Required.Always)] + /// + /// Geometry of the soil. + /// + public FaceGroup Geometry { get; } + + [JsonIgnore] /// /// Matrix 2D of the soil. /// public Matrix2d IDmatrix { get; private set; } + + [DisplayName("Material")] + [Description("Profile of the soil")] + [JsonProperty("material")] /// /// Material of the soil. /// @@ -36,17 +52,17 @@ protected set _material = value; } - } + + [JsonConstructor] /// /// Create a new soil. /// - /// Grid object. /// Geometry of the soil. /// Numerical ID. /// Code of the material. /// Name of the soil. - public Soil(Grid grid, FaceGroup geometry, + public Soil(FaceGroup geometry, int id, string code = null, string name = null) { @@ -56,11 +72,9 @@ public Soil(Grid grid, FaceGroup geometry, ? CreateMaterial(Material.DEFAULT_SOIL, code) : CreateMaterial(Material.DEFAULT_SOIL); Name = name ?? "SoilGroup"; - - SetMatrix(grid); } - private void SetMatrix(Grid grid) + public void SetMatrix(Grid grid) { Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, Material.DEFAULT_SOIL); @@ -80,5 +94,73 @@ public override string ToString() return String.Format("Soil::{0}::{1}::{2}", Name, ID, Material.IDs[0]); } + + public string Serialize() + { + return JsonConvert.SerializeObject(this); + } + + public static Soil Deserialize(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + public bool Equals(Soil other) + { + if (other == null) + return false; + + if (other != null + && other.ID == this.ID + && other.Material == this.Material + && other.Geometry == this.Geometry) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + var soilObj = obj as Soil; + if (soilObj == null) + return false; + else + return Equals(soilObj); + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 23 + ID.GetHashCode(); + hash = hash * 23 + Material.GetHashCode(); + hash = hash * 23 + Geometry.GetHashCode(); + return hash; + } + } + + public static bool operator ==(Soil soil1, Soil soil2) + { + if (((object)soil1) == null || ((object)soil2) == null) + return Object.Equals(soil1, soil2); + + return soil1.Equals(soil2); + } + + public static bool operator !=(Soil soil1, Soil soil2) + { + return !(soil1 == soil2); + } } } diff --git a/project/Morpho/Morpho25/Geometry/Source.cs b/project/Morpho/Morpho25/Geometry/Source.cs index 41fa894..271adfa 100644 --- a/project/Morpho/Morpho25/Geometry/Source.cs +++ b/project/Morpho/Morpho25/Geometry/Source.cs @@ -1,27 +1,43 @@ using Morpho25.Utility; using MorphoGeometry; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.ComponentModel; namespace Morpho25.Geometry { + [DisplayName("Source")] /// /// Source class. /// - public class Source : Entity + public class Source : Entity, IEquatable { - /// - /// Geometry of the source. - /// - public FaceGroup Geometry { get; } + [DisplayName("Name")] + [Description("Name of the source group")] + [JsonProperty("name")] /// /// Name of the source. /// public override string Name { get; } + + [DisplayName("Geometry")] + [Description("Flat or solid geometry")] + [JsonProperty("geometry", Required = Required.Always)] + /// + /// Geometry of the source. + /// + public FaceGroup Geometry { get; } + + [JsonIgnore] /// /// Matrix of the source. /// public Matrix2d IDmatrix { get; private set; } + + [DisplayName("Material")] + [Description("Source type")] + [JsonProperty("material")] /// /// Material of the source. /// @@ -38,15 +54,16 @@ protected set } } + + [JsonConstructor] /// /// Create a new source. /// - /// Grid object. /// Geometry of the source. /// Numerical ID. /// Code of the material. /// Name of the source. - public Source(Grid grid, FaceGroup geometry, + public Source(FaceGroup geometry, int id, string code = null, string name = null) { @@ -56,11 +73,9 @@ public Source(Grid grid, FaceGroup geometry, ? CreateMaterial(Material.DEFAULT_SOURCE, code) : CreateMaterial(Material.DEFAULT_SOURCE); Name = name ?? "SourceGroup"; - - SetMatrix(grid); } - private void SetMatrix(Grid grid) + public void SetMatrix(Grid grid) { Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, ""); @@ -80,5 +95,76 @@ public override string ToString() return String.Format("Source::{0}::{1}::{2}", Name, ID, Material.IDs[0]); } + + public string Serialize() + { + return JsonConvert.SerializeObject(this); + } + + public static Source Deserialize(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + public bool Equals(Source other) + { + if (other == null) + return false; + + if (other != null + && other.ID == this.ID + && other.Name == this.Name + && other.Material == this.Material + && other.Geometry == this.Geometry) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + var sourceObj = obj as Source; + if (sourceObj == null) + return false; + else + return Equals(sourceObj); + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 23 + ID.GetHashCode(); + hash = hash * 23 + Name.GetHashCode(); + hash = hash * 23 + Material.GetHashCode(); + hash = hash * 23 + Geometry.GetHashCode(); + return hash; + } + } + + public static bool operator ==(Source source1, Source source2) + { + if (((object)source1) == null || ((object)source2) == null) + return Object.Equals(source1, source2); + + return source1.Equals(source2); + } + + public static bool operator !=(Source source1, Source source2) + { + return !(source1 == source2); + } + } } diff --git a/project/Morpho/Morpho25/Geometry/Terrain.cs b/project/Morpho/Morpho25/Geometry/Terrain.cs index c7c0ca1..d2b976a 100644 --- a/project/Morpho/Morpho25/Geometry/Terrain.cs +++ b/project/Morpho/Morpho25/Geometry/Terrain.cs @@ -1,36 +1,54 @@ using Morpho25.Utility; using MorphoGeometry; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; namespace Morpho25.Geometry { + [DisplayName("Terrain")] /// /// Terrain class. /// - public class Terrain : Entity + public class Terrain : Entity, IEquatable { - /// - /// Geometry of the terrain. - /// - public FaceGroup Geometry { get; } + [DisplayName("Name")] + [Description("Name of the terrain group")] + [JsonProperty("name")] /// /// Name of the terrain. /// public override string Name { get; } + + [DisplayName("Geometry")] + [Description("Flat or solid geometry")] + [JsonProperty("geometry", Required = Required.Always)] + /// + /// Geometry of the terrain. + /// + public FaceGroup Geometry { get; } + + [JsonIgnore] /// /// Matrix 2D of the terrain. /// public Matrix2d IDmatrix { get; private set; } + + [JsonIgnore] /// /// Collection of string based on Pixel and ID. /// public List TerrainIDrows { get; private set; } + + [JsonIgnore] /// /// Location of the terrain in the grid. /// public List Pixels { get; private set; } + + [JsonIgnore] /// /// Material of the terrain. /// @@ -42,11 +60,10 @@ public override Material Material /// /// Create a new terrain. /// - /// Grid object. /// Geometry of the terrain. /// Numerical ID. /// Name of the terrain. - public Terrain(Grid grid, FaceGroup geometry, + public Terrain(FaceGroup geometry, int id, string name = null) { ID = id; @@ -54,11 +71,9 @@ public Terrain(Grid grid, FaceGroup geometry, Name = name ?? "TerrainGroup"; TerrainIDrows = new List(); Pixels = new List(); - - SetMatrix(grid); } - private void SetMatrix(Grid grid) + public void SetMatrix(Grid grid) { Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, "0"); @@ -110,5 +125,73 @@ public override string ToString() { return String.Format("Terrain::{0}::{1}", Name, ID); } + + public string Serialize() + { + return JsonConvert.SerializeObject(this); + } + + public static Terrain Deserialize(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + public bool Equals(Terrain other) + { + if (other == null) + return false; + + if (other != null + && other.ID == this.ID + && other.Name == this.Name + && other.Geometry == this.Geometry) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + var terrainObj = obj as Terrain; + if (terrainObj == null) + return false; + else + return Equals(terrainObj); + } + + public override int GetHashCode() + { + unchecked + { + int hash = 17; + hash = hash * 23 + ID.GetHashCode(); + hash = hash * 23 + Name.GetHashCode(); + hash = hash * 23 + Geometry.GetHashCode(); + return hash; + } + } + + public static bool operator ==(Terrain terrain1, Terrain terrain2) + { + if (((object)terrain1) == null || ((object)terrain2) == null) + return Object.Equals(terrain1, terrain2); + + return terrain1.Equals(terrain2); + } + + public static bool operator !=(Terrain terrain1, Terrain terrain2) + { + return !(terrain1 == terrain2); + } } } diff --git a/project/Morpho/Morpho25/Settings/Model.cs b/project/Morpho/Morpho25/Settings/Model.cs index 1248b99..619d8a8 100644 --- a/project/Morpho/Morpho25/Settings/Model.cs +++ b/project/Morpho/Morpho25/Settings/Model.cs @@ -39,7 +39,7 @@ public Model(Grid grid, Location location, Workspace workspace) ReceptorObjects = new List(); } - public Model(Grid grid, Location location, Workspace workspace, + public Model(Grid grid, Location location, Workspace workspace, List buildingObjects) { Workspace = workspace; @@ -79,18 +79,24 @@ public void Calculation() { SetDefaultMatrix(Grid); - if (BuildingObjects.Count > 0) - SetBuilding(); + if (TerrainObjects.Count > 0) + SetTerrain(); if (Plant2dObjects.Count > 0) SetPlant2d(); + if (BuildingObjects.Count > 0) + SetBuilding(); + + if (Plant3dObjects.Count > 0) + SetPlant3d(); + + if (ReceptorObjects.Count > 0) + SetReceptor(); + if (SoilObjects.Count > 0) SetSoil(); - if (TerrainObjects.Count > 0) - SetTerrain(); - if (SourceObjects.Count > 0) SetSource(); @@ -122,6 +128,8 @@ private void SetBuilding() private void SetSoil() { + SoilObjects.ForEach(_ => _.SetMatrix(Grid)); + List soils = SoilObjects.OrderBy(e => e.ID).ToList(); List matrixList = soils.Select(e => e.IDmatrix).ToList(); Matrix2d soilMatrix = Matrix2d.MergeMatrix(matrixList, Material.DEFAULT_SOIL); @@ -130,14 +138,28 @@ private void SetSoil() private void SetPlant2d() { + Plant2dObjects.ForEach(_ => _.SetMatrix(Grid)); + List plants = Plant2dObjects.OrderBy(e => e.ID).ToList(); List matrixList = plants.Select(e => e.IDmatrix).ToList(); Matrix2d plantMatrix = Matrix2d.MergeMatrix(matrixList, ""); EnvimetMatrix.Add("plantMatrix", plantMatrix); } + private void SetPlant3d() + { + Plant3dObjects.ForEach(_ => _.SetPixel(Grid)); + } + + private void SetReceptor() + { + ReceptorObjects.ForEach(_ => _.SetPixel(Grid)); + } + private void SetTerrain() { + TerrainObjects.ForEach(_ => _.SetMatrix(Grid)); + List terrain = TerrainObjects.OrderBy(e => e.ID).ToList(); List matrixList = terrain.Select(e => e.IDmatrix).ToList(); Matrix2d terrainMatrix = Matrix2d.MergeMatrix(matrixList, "0"); @@ -146,6 +168,8 @@ private void SetTerrain() private void SetSource() { + SourceObjects.ForEach(_ => _.SetMatrix(Grid)); + List sources = SourceObjects.OrderBy(e => e.ID).ToList(); List matrixList = sources.Select(e => e.IDmatrix).ToList(); Matrix2d sourceMatrix = Matrix2d.MergeMatrix(matrixList, ""); diff --git a/project/Morpho/MorphoTests/Geometry/BuildingTest.cs b/project/Morpho/MorphoTests/Geometry/BuildingTest.cs index 8b37ba0..62d7767 100644 --- a/project/Morpho/MorphoTests/Geometry/BuildingTest.cs +++ b/project/Morpho/MorphoTests/Geometry/BuildingTest.cs @@ -43,15 +43,18 @@ public void Setup() public void SerializeTest() { var jsonOuput = _building.Serialize(); - var jsonInput = "{\"observeBPS\":false,\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"000000\",\"000000\",\" \",\" \"]},\"name\":\"Building\",\"id\":1}"; + var jsonInput = "{\"name\":\"Building\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"000000\",\"000000\",\" \",\" \"]},\"observeBPS\":false,\"id\":1}"; Assert.That(jsonOuput, Is.EqualTo(jsonInput)); + + JSchemaGenerator generator = new JSchemaGenerator(); + JSchema schema = generator.Generate(typeof(Building)); } [Test] public void DeserializeTest() { - var jsonInput = "{\"observeBPS\":false,\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"000000\",\"000000\",\" \",\" \"]},\"name\":\"Building\",\"id\":1}"; + var jsonInput = "{\"name\":\"Building\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"000000\",\"000000\",\" \",\" \"]},\"observeBPS\":false,\"id\":1}"; var matOutput = Building.Deserialize(jsonInput); Assert.That(matOutput, Is.EqualTo(_building)); diff --git a/project/Morpho/MorphoTests/Geometry/Plant2dTest.cs b/project/Morpho/MorphoTests/Geometry/Plant2dTest.cs new file mode 100644 index 0000000..eec82dc --- /dev/null +++ b/project/Morpho/MorphoTests/Geometry/Plant2dTest.cs @@ -0,0 +1,65 @@ +using Morpho25.Geometry; +using Morpho25.Utility; +using Newtonsoft.Json.Schema.Generation; +using Newtonsoft.Json.Schema; +using NUnit.Framework; +using System; +using System.Linq; +using MorphoGeometry; +using System.Collections.Generic; + +namespace MorphoTests.Geometry +{ + public class Plant2dTest + { + private Plant2d _plant2D; + + [SetUp] + public void Setup() + { + var pts1 = new[] +{ + new Vector(0, 0, 0), + new Vector(5, 0, 0), + new Vector(0, 5, 0) + + }; + var face1 = new Face(pts1); + + var pts2 = new[] +{ + new Vector(5, 0, 0), + new Vector(5, 5, 0), + new Vector(0, 5, 0) + + }; + var face2 = new Face(pts2); + var facegroup = new FaceGroup(new List { face1, face2 }); + + _plant2D = new Plant2d(facegroup, 1); + } + + [Test] + public void SerializeTest() + { + var jsonOuput = _plant2D.Serialize(); + var jsonInput = "{\"name\":\"PlantGroup\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"0000XX\"]},\"id\":1}"; + + Assert.That(jsonOuput, Is.EqualTo(jsonInput)); + + JSchemaGenerator generator = new JSchemaGenerator(); + JSchema schema = generator.Generate(typeof(Plant2d)); + } + + [Test] + public void DeserializeTest() + { + var jsonInput = "{\"name\":\"PlantGroup\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"0000XX\"]},\"id\":1}"; + var matOutput = Plant2d.Deserialize(jsonInput); + Assert.That(matOutput, Is.EqualTo(_plant2D)); + + jsonInput = "{\"ids\":\"0000AA\"}"; + Assert.Throws(() => Material.Deserialize(jsonInput)); + } + } +} diff --git a/project/Morpho/MorphoTests/Geometry/Plant3dTest.cs b/project/Morpho/MorphoTests/Geometry/Plant3dTest.cs new file mode 100644 index 0000000..85522f4 --- /dev/null +++ b/project/Morpho/MorphoTests/Geometry/Plant3dTest.cs @@ -0,0 +1,48 @@ +using Morpho25.Geometry; +using Morpho25.Utility; +using Newtonsoft.Json.Schema.Generation; +using Newtonsoft.Json.Schema; +using NUnit.Framework; +using System; +using System.Linq; +using MorphoGeometry; +using System.Collections.Generic; + + +namespace MorphoTests.Geometry +{ + public class Plant3dTest + { + private Plant3d _plant3D; + + [SetUp] + public void Setup() + { + var pt = new Vector(10, 10, 0); + _plant3D = new Plant3d(pt); + } + + [Test] + public void SerializeTest() + { + var jsonOuput = _plant3D.Serialize(); + var jsonInput = "{\"name\":\"PlantGroup\",\"geometry\":{\"x\":10.0,\"y\":10.0,\"z\":0.0},\"material\":{\"ids\":[\"0000C2\"]},\"id\":0}"; + + Assert.That(jsonOuput, Is.EqualTo(jsonInput)); + + JSchemaGenerator generator = new JSchemaGenerator(); + JSchema schema = generator.Generate(typeof(Plant3d)); + } + + [Test] + public void DeserializeTest() + { + var jsonInput = "{\"name\":\"PlantGroup\",\"geometry\":{\"x\":10.0,\"y\":10.0,\"z\":0.0},\"material\":{\"ids\":[\"0000C2\"]},\"id\":0}"; + var matOutput = Plant3d.Deserialize(jsonInput); + Assert.That(matOutput, Is.EqualTo(_plant3D)); + + jsonInput = "{\"ids\":\"0000AA\"}"; + Assert.Throws(() => Material.Deserialize(jsonInput)); + } + } +} diff --git a/project/Morpho/MorphoTests/Geometry/ReceptorTest.cs b/project/Morpho/MorphoTests/Geometry/ReceptorTest.cs new file mode 100644 index 0000000..f2d782f --- /dev/null +++ b/project/Morpho/MorphoTests/Geometry/ReceptorTest.cs @@ -0,0 +1,48 @@ +using Morpho25.Geometry; +using Morpho25.Utility; +using Newtonsoft.Json.Schema.Generation; +using Newtonsoft.Json.Schema; +using NUnit.Framework; +using System; +using System.Linq; +using MorphoGeometry; +using System.Collections.Generic; + + +namespace MorphoTests.Geometry +{ + public class ReceptorTest + { + private Receptor _receptor; + + [SetUp] + public void Setup() + { + var pt = new Vector(10, 10, 0); + _receptor = new Receptor(pt, "MyReceptor"); + } + + [Test] + public void SerializeTest() + { + var jsonOuput = _receptor.Serialize(); + var jsonInput = "{\"name\":\"MyReceptor\",\"geometry\":{\"x\":10.0,\"y\":10.0,\"z\":0.0},\"id\":0}"; + + Assert.That(jsonOuput, Is.EqualTo(jsonInput)); + + JSchemaGenerator generator = new JSchemaGenerator(); + JSchema schema = generator.Generate(typeof(Receptor)); + } + + [Test] + public void DeserializeTest() + { + var jsonInput = "{\"name\":\"MyReceptor\",\"geometry\":{\"x\":10.0,\"y\":10.0,\"z\":0.0},\"id\":0}"; + var matOutput = Receptor.Deserialize(jsonInput); + Assert.That(matOutput, Is.EqualTo(_receptor)); + + jsonInput = "{\"ids\":\"0000AA\"}"; + Assert.Throws(() => Material.Deserialize(jsonInput)); + } + } +} diff --git a/project/Morpho/MorphoTests/Geometry/SoilTest.cs b/project/Morpho/MorphoTests/Geometry/SoilTest.cs new file mode 100644 index 0000000..72a9976 --- /dev/null +++ b/project/Morpho/MorphoTests/Geometry/SoilTest.cs @@ -0,0 +1,65 @@ +using Morpho25.Geometry; +using Morpho25.Utility; +using Newtonsoft.Json.Schema.Generation; +using Newtonsoft.Json.Schema; +using NUnit.Framework; +using System; +using System.Linq; +using MorphoGeometry; +using System.Collections.Generic; + +namespace MorphoTests.Geometry +{ + public class SoilTest + { + private Soil _soil; + + [SetUp] + public void Setup() + { + var pts1 = new[] +{ + new Vector(0, 0, 0), + new Vector(5, 0, 0), + new Vector(0, 5, 0) + + }; + var face1 = new Face(pts1); + + var pts2 = new[] +{ + new Vector(5, 0, 0), + new Vector(5, 5, 0), + new Vector(0, 5, 0) + + }; + var face2 = new Face(pts2); + var facegroup = new FaceGroup(new List { face1, face2 }); + + _soil = new Soil(facegroup, 1); + } + + [Test] + public void SerializeTest() + { + var jsonOuput = _soil.Serialize(); + var jsonInput = "{\"name\":\"SoilGroup\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"000000\"]},\"id\":1}"; + + Assert.That(jsonOuput, Is.EqualTo(jsonInput)); + + JSchemaGenerator generator = new JSchemaGenerator(); + JSchema schema = generator.Generate(typeof(Soil)); + } + + [Test] + public void DeserializeTest() + { + var jsonInput = "{\"name\":\"SoilGroup\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"000000\"]},\"id\":1}"; + var matOutput = Soil.Deserialize(jsonInput); + Assert.That(matOutput, Is.EqualTo(_soil)); + + jsonInput = "{\"ids\":\"0000AA\"}"; + Assert.Throws(() => Material.Deserialize(jsonInput)); + } + } +} diff --git a/project/Morpho/MorphoTests/Geometry/SourceTest.cs b/project/Morpho/MorphoTests/Geometry/SourceTest.cs new file mode 100644 index 0000000..dac9344 --- /dev/null +++ b/project/Morpho/MorphoTests/Geometry/SourceTest.cs @@ -0,0 +1,65 @@ +using Morpho25.Geometry; +using Morpho25.Utility; +using Newtonsoft.Json.Schema.Generation; +using Newtonsoft.Json.Schema; +using NUnit.Framework; +using System; +using System.Linq; +using MorphoGeometry; +using System.Collections.Generic; + +namespace MorphoTests.Geometry +{ + public class SourceTest + { + private Source _source; + + [SetUp] + public void Setup() + { + var pts1 = new[] +{ + new Vector(0, 0, 0), + new Vector(5, 0, 0), + new Vector(0, 5, 0) + + }; + var face1 = new Face(pts1); + + var pts2 = new[] +{ + new Vector(5, 0, 0), + new Vector(5, 5, 0), + new Vector(0, 5, 0) + + }; + var face2 = new Face(pts2); + var facegroup = new FaceGroup(new List { face1, face2 }); + + _source = new Source(facegroup, 1); + } + + [Test] + public void SerializeTest() + { + var jsonOuput = _source.Serialize(); + var jsonInput = "{\"name\":\"SourceGroup\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"0000FT\"]},\"id\":1}"; + + Assert.That(jsonOuput, Is.EqualTo(jsonInput)); + + JSchemaGenerator generator = new JSchemaGenerator(); + JSchema schema = generator.Generate(typeof(Source)); + } + + [Test] + public void DeserializeTest() + { + var jsonInput = "{\"name\":\"SourceGroup\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"material\":{\"ids\":[\"0000FT\"]},\"id\":1}"; + var matOutput = Source.Deserialize(jsonInput); + Assert.That(matOutput, Is.EqualTo(_source)); + + jsonInput = "{\"ids\":\"0000AA\"}"; + Assert.Throws(() => Material.Deserialize(jsonInput)); + } + } +} diff --git a/project/Morpho/MorphoTests/Geometry/TerrainTest.cs b/project/Morpho/MorphoTests/Geometry/TerrainTest.cs new file mode 100644 index 0000000..4240148 --- /dev/null +++ b/project/Morpho/MorphoTests/Geometry/TerrainTest.cs @@ -0,0 +1,65 @@ +using Morpho25.Geometry; +using Morpho25.Utility; +using Newtonsoft.Json.Schema.Generation; +using Newtonsoft.Json.Schema; +using NUnit.Framework; +using System; +using System.Linq; +using MorphoGeometry; +using System.Collections.Generic; + +namespace MorphoTests.Geometry +{ + public class TerrainTest + { + private Terrain _terrain; + + [SetUp] + public void Setup() + { + var pts1 = new[] +{ + new Vector(0, 0, 0), + new Vector(5, 0, 0), + new Vector(0, 5, 0) + + }; + var face1 = new Face(pts1); + + var pts2 = new[] +{ + new Vector(5, 0, 0), + new Vector(5, 5, 0), + new Vector(0, 5, 0) + + }; + var face2 = new Face(pts2); + var facegroup = new FaceGroup(new List { face1, face2 }); + + _terrain = new Terrain(facegroup, 1); + } + + [Test] + public void SerializeTest() + { + var jsonOuput = _terrain.Serialize(); + var jsonInput = "{\"name\":\"TerrainGroup\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"id\":1}"; + + Assert.That(jsonOuput, Is.EqualTo(jsonInput)); + + JSchemaGenerator generator = new JSchemaGenerator(); + JSchema schema = generator.Generate(typeof(Terrain)); + } + + [Test] + public void DeserializeTest() + { + var jsonInput = "{\"name\":\"TerrainGroup\",\"geometry\":{\"faces\":[{\"vertices\":[{\"x\":0.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]},{\"vertices\":[{\"x\":5.0,\"y\":0.0,\"z\":0.0},{\"x\":5.0,\"y\":5.0,\"z\":0.0},{\"x\":0.0,\"y\":5.0,\"z\":0.0}]}]},\"id\":1}"; + var matOutput = Terrain.Deserialize(jsonInput); + Assert.That(matOutput, Is.EqualTo(_terrain)); + + jsonInput = "{\"ids\":\"0000AA\"}"; + Assert.Throws(() => Material.Deserialize(jsonInput)); + } + } +}