| | 1 | | using Morpho25.Geometry; |
| | 2 | | using Morpho25.Management; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | |
|
| | 7 | | namespace Morpho25.Settings |
| | 8 | | { |
| | 9 | | public class Model |
| | 10 | | { |
| 0 | 11 | | public Dictionary<string, Matrix2d> EnvimetMatrix { get; private set; } |
| | 12 | |
|
| 0 | 13 | | public Workspace Workspace { get; } |
| 0 | 14 | | public Grid Grid { get; } |
| 0 | 15 | | public Location Location { get; } |
| 0 | 16 | | public List<Building> BuildingObjects { get; set; } |
| 0 | 17 | | public List<Plant2d> Plant2dObjects { get; set; } |
| 0 | 18 | | public List<Plant3d> Plant3dObjects { get; set; } |
| 0 | 19 | | public List<Soil> SoilObjects { get; set; } |
| 0 | 20 | | public List<Terrain> TerrainObjects { get; set; } |
| 0 | 21 | | public List<Source> SourceObjects { get; set; } |
| 0 | 22 | | public List<Receptor> ReceptorObjects { get; set; } |
| | 23 | |
|
| 0 | 24 | | public bool IsDetailed { get; set; } |
| 0 | 25 | | public bool ShiftEachVoxel { get; set; } |
| | 26 | |
|
| 0 | 27 | | public Model(Grid grid, Location location) |
| 0 | 28 | | { |
| 0 | 29 | | EnvimetMatrix = new Dictionary<string, Matrix2d>(); |
| 0 | 30 | | Grid = grid; |
| 0 | 31 | | Location = location; |
| 0 | 32 | | BuildingObjects = new List<Building>(); |
| 0 | 33 | | Plant2dObjects = new List<Plant2d>(); |
| 0 | 34 | | Plant3dObjects = new List<Plant3d>(); |
| 0 | 35 | | SoilObjects = new List<Soil>(); |
| 0 | 36 | | TerrainObjects = new List<Terrain>(); |
| 0 | 37 | | SourceObjects = new List<Source>(); |
| 0 | 38 | | ReceptorObjects = new List<Receptor>(); |
| 0 | 39 | | } |
| | 40 | |
|
| | 41 | | public Model(Grid grid, Location location, Workspace workspace) |
| 0 | 42 | | : this(grid, location) |
| 0 | 43 | | { |
| 0 | 44 | | Workspace = workspace; |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | public void Calculation() |
| 0 | 48 | | { |
| 0 | 49 | | SetDefaultMatrix(Grid); |
| | 50 | |
|
| 0 | 51 | | if (TerrainObjects.Count > 0) |
| 0 | 52 | | SetTerrain(); |
| | 53 | |
|
| 0 | 54 | | if (Plant2dObjects.Count > 0) |
| 0 | 55 | | SetPlant2d(); |
| | 56 | |
|
| 0 | 57 | | if (BuildingObjects.Count > 0) |
| 0 | 58 | | SetBuilding(); |
| | 59 | |
|
| 0 | 60 | | if (Plant3dObjects.Count > 0) |
| 0 | 61 | | SetPlant3d(); |
| | 62 | |
|
| 0 | 63 | | if (ReceptorObjects.Count > 0) |
| 0 | 64 | | SetReceptor(); |
| | 65 | |
|
| 0 | 66 | | if (SoilObjects.Count > 0) |
| 0 | 67 | | SetSoil(); |
| | 68 | |
|
| 0 | 69 | | if (SourceObjects.Count > 0) |
| 0 | 70 | | SetSource(); |
| | 71 | |
|
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | public override string ToString() |
| 0 | 75 | | { |
| 0 | 76 | | var label = IsDetailed ? "3D" : "2.5D"; |
| 0 | 77 | | return String.Format("EnvimetINX::{0}", label); |
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | |
|
| | 81 | | private void SetBuilding() |
| 0 | 82 | | { |
| 0 | 83 | | BuildingObjects.ForEach(_ => _.SetMatrix(Grid)); |
| | 84 | |
|
| 0 | 85 | | List<Building> buildings = BuildingObjects.OrderBy(b => b.ID).ToList(); |
| 0 | 86 | | List<Matrix2d> topMatrixList = buildings.Select(b => b.TopMatrix).ToList(); |
| 0 | 87 | | List<Matrix2d> bottomMatrixList = buildings.Select(b => b.BottomMatrix).ToList(); |
| 0 | 88 | | List<Matrix2d> idMatrixList = buildings.Select(b => b.IDmatrix).ToList(); |
| | 89 | |
|
| 0 | 90 | | Matrix2d topMatrix = Matrix2d.MergeMatrix(topMatrixList, "0"); |
| 0 | 91 | | Matrix2d bottomMatrix = Matrix2d.MergeMatrix(bottomMatrixList, "0"); |
| 0 | 92 | | Matrix2d idMatrix = Matrix2d.MergeMatrix(idMatrixList, "0"); |
| | 93 | |
|
| 0 | 94 | | EnvimetMatrix["topMatrix"] = topMatrix; |
| 0 | 95 | | EnvimetMatrix["bottomMatrix"] = bottomMatrix; |
| 0 | 96 | | EnvimetMatrix["idMatrix"] = idMatrix; |
| 0 | 97 | | } |
| | 98 | |
|
| | 99 | | private void SetSoil() |
| 0 | 100 | | { |
| 0 | 101 | | SoilObjects.ForEach(_ => _.SetMatrix(Grid)); |
| | 102 | |
|
| 0 | 103 | | List<Soil> soils = SoilObjects.OrderBy(e => e.ID).ToList(); |
| 0 | 104 | | List<Matrix2d> matrixList = soils.Select(e => e.IDmatrix).ToList(); |
| 0 | 105 | | Matrix2d soilMatrix = Matrix2d.MergeMatrix(matrixList, Material.DEFAULT_SOIL); |
| 0 | 106 | | EnvimetMatrix["soilMatrix"] = soilMatrix; |
| 0 | 107 | | } |
| | 108 | |
|
| | 109 | | private void SetPlant2d() |
| 0 | 110 | | { |
| 0 | 111 | | Plant2dObjects.ForEach(_ => _.SetMatrix(Grid)); |
| | 112 | |
|
| 0 | 113 | | List<Plant2d> plants = Plant2dObjects.OrderBy(e => e.ID).ToList(); |
| 0 | 114 | | List<Matrix2d> matrixList = plants.Select(e => e.IDmatrix).ToList(); |
| 0 | 115 | | Matrix2d plantMatrix = Matrix2d.MergeMatrix(matrixList, ""); |
| 0 | 116 | | EnvimetMatrix.Add("plantMatrix", plantMatrix); |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | | private void SetPlant3d() |
| 0 | 120 | | { |
| 0 | 121 | | Plant3dObjects.ForEach(_ => _.SetPixel(Grid)); |
| 0 | 122 | | } |
| | 123 | |
|
| | 124 | | private void SetReceptor() |
| 0 | 125 | | { |
| 0 | 126 | | ReceptorObjects.ForEach(_ => _.SetPixel(Grid)); |
| 0 | 127 | | } |
| | 128 | |
|
| | 129 | | private void SetTerrain() |
| 0 | 130 | | { |
| 0 | 131 | | TerrainObjects.ForEach(_ => _.SetMatrix(Grid)); |
| | 132 | |
|
| 0 | 133 | | List<Terrain> terrain = TerrainObjects.OrderBy(e => e.ID).ToList(); |
| 0 | 134 | | List<Matrix2d> matrixList = terrain.Select(e => e.IDmatrix).ToList(); |
| 0 | 135 | | Matrix2d terrainMatrix = Matrix2d.MergeMatrix(matrixList, "0"); |
| 0 | 136 | | EnvimetMatrix["terrainMatrix"] = terrainMatrix; |
| 0 | 137 | | } |
| | 138 | |
|
| | 139 | | private void SetSource() |
| 0 | 140 | | { |
| 0 | 141 | | SourceObjects.ForEach(_ => _.SetMatrix(Grid)); |
| | 142 | |
|
| 0 | 143 | | List<Source> sources = SourceObjects.OrderBy(e => e.ID).ToList(); |
| 0 | 144 | | List<Matrix2d> matrixList = sources.Select(e => e.IDmatrix).ToList(); |
| 0 | 145 | | Matrix2d sourceMatrix = Matrix2d.MergeMatrix(matrixList, ""); |
| 0 | 146 | | EnvimetMatrix.Add("sourceMatrix", sourceMatrix); |
| 0 | 147 | | } |
| | 148 | |
|
| | 149 | | private void SetDefaultMatrix(Grid grid) |
| 0 | 150 | | { |
| 0 | 151 | | Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, "0"); |
| 0 | 152 | | Matrix2d matrixSoil = new Matrix2d(grid.Size.NumX, grid.Size.NumY, Material.DEFAULT_SOIL); |
| 0 | 153 | | EnvimetMatrix.Add("topMatrix", matrix); |
| 0 | 154 | | EnvimetMatrix.Add("bottomMatrix", matrix); |
| 0 | 155 | | EnvimetMatrix.Add("idMatrix", matrix); |
| 0 | 156 | | EnvimetMatrix.Add("terrainMatrix", matrix); |
| 0 | 157 | | EnvimetMatrix.Add("soilMatrix", matrixSoil); |
| 0 | 158 | | } |
| | 159 | | } |
| | 160 | | } |