| | 1 | | using Morpho25.Utility; |
| | 2 | | using MorphoGeometry; |
| | 3 | | using Newtonsoft.Json; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.ComponentModel; |
| | 7 | |
|
| | 8 | | namespace Morpho25.Geometry |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Entity class. |
| | 12 | | /// </summary> |
| | 13 | | public abstract class Entity |
| | 14 | | { |
| | 15 | | protected string _name; |
| | 16 | | protected Material _material; |
| | 17 | | protected int _ID; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Material of the entity. |
| | 21 | | /// </summary> |
| | 22 | | public abstract Material Material { get; protected set; } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Name of the entity. |
| | 26 | | /// </summary> |
| | 27 | | public abstract string Name { get; } |
| | 28 | |
|
| | 29 | | [DisplayName("ID")] |
| | 30 | | [Description("Numeric ID of the entity")] |
| | 31 | | [JsonProperty("id")] |
| | 32 | | /// <summary> |
| | 33 | | /// ID of the entity. |
| | 34 | | /// </summary> |
| | 35 | | public int ID { |
| 51 | 36 | | get { return _ID; } |
| | 37 | | protected set |
| 17 | 38 | | { |
| 17 | 39 | | if (value < 0) |
| 0 | 40 | | throw new ArgumentOutOfRangeException( |
| 0 | 41 | | $"{nameof(value)} must be positive."); |
| | 42 | |
|
| 17 | 43 | | _ID = value; |
| 17 | 44 | | } |
| | 45 | | } |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Set 2D Matrix. |
| | 49 | | /// </summary> |
| | 50 | | /// <param name="intersection">Intersection points.</param> |
| | 51 | | /// <param name="grid">Grid object.</param> |
| | 52 | | /// <param name="matrix">2D Matrix to map.</param> |
| | 53 | | /// <param name="text">Optional text to use.</param> |
| | 54 | | protected void SetMatrix(IEnumerable<Vector> intersection, |
| | 55 | | Grid grid, Matrix2d matrix, String text = "") |
| 0 | 56 | | { |
| 0 | 57 | | foreach (Vector vec in intersection) |
| 0 | 58 | | { |
| 0 | 59 | | var pixel = vec.ToPixel(grid); |
| | 60 | |
|
| 0 | 61 | | matrix[pixel.I, pixel.J] = (text == String.Empty) |
| 0 | 62 | | ? Math.Round(vec.z, 0).ToString() |
| 0 | 63 | | : text; |
| 0 | 64 | | } |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// Create a new material. |
| | 69 | | /// </summary> |
| | 70 | | /// <param name="defaultCode">Default material ID.</param> |
| | 71 | | /// <param name="code">Custom material ID.</param> |
| | 72 | | /// <returns>New material object.</returns> |
| | 73 | | protected Material CreateMaterial(string defaultCode, string code = null) |
| 12 | 74 | | { |
| 12 | 75 | | string material = code ?? defaultCode; |
| | 76 | |
|
| 12 | 77 | | return new Material(new string[] { material }); |
| 12 | 78 | | } |
| | 79 | | } |
| | 80 | | } |