StarSim

StarSim.git
git clone git://git.lenczewski.org/StarSim.git
Log | Files | Refs | README | LICENSE

BodyDummy.cs (4779B)


      1 using JetBrains.Annotations;
      2 
      3 using StarSimLib.Configuration;
      4 using StarSimLib.Data_Structures;
      5 
      6 using System.ComponentModel;
      7 using System.Runtime.CompilerServices;
      8 
      9 namespace StarSimGui.Source
     10 {
     11     /// <summary>
     12     /// Represents the editable fields in a <see cref="Body"/> instance.
     13     /// </summary>
     14     public class BodyDummy : INotifyPropertyChanged
     15     {
     16         /// <summary>
     17         /// The underlying mass.
     18         /// </summary>
     19         private double mass;
     20 
     21         /// <summary>
     22         /// The underlying position vector.
     23         /// </summary>
     24         private Vector4 positionVector;
     25 
     26         /// <summary>
     27         /// The underlying velocity vector.
     28         /// </summary>
     29         private Vector4 velocityVector;
     30 
     31         /// <summary>
     32         /// Initialises a new instance of the <see cref="BodyDummy"/> class.
     33         /// </summary>
     34         public BodyDummy()
     35         {
     36         }
     37 
     38         /// <summary>
     39         /// Initialises a new instance of the <see cref="BodyDummy"/> class.
     40         /// </summary>
     41         /// <param name="body">The <see cref="Body"/> instance around which to construct a dummy.</param>
     42         /// <param name="configuration">The current configuration of the application.</param>
     43         public BodyDummy(Body body, Config configuration)
     44         {
     45             Configuration = configuration;
     46 
     47             Generation = body.Generation;
     48             Id = body.Id;
     49             mass = body.Mass / Configuration.SolarMass;
     50             positionVector = body.Position / Configuration.AstronomicalUnit;
     51             velocityVector = body.Velocity / 1000;
     52         }
     53 
     54         /// <summary>
     55         /// Signals that a property on this instance has changed.
     56         /// </summary>
     57         public event PropertyChangedEventHandler PropertyChanged;
     58 
     59         /// <summary>
     60         /// The current configuration of the application.
     61         /// </summary>
     62         public Config Configuration { get; internal set; }
     63 
     64         /// <summary>
     65         /// The generation of this instance.
     66         /// </summary>
     67         public uint Generation { get; set; }
     68 
     69         /// <summary>
     70         /// The id of this instance.
     71         /// </summary>
     72         public uint Id { get; set; }
     73 
     74         /// <summary>
     75         /// The starting mass of this instance.
     76         /// </summary>
     77         public double Mass
     78         {
     79             get { return mass; }
     80             set { mass = value; }
     81         }
     82 
     83         /// <summary>
     84         /// The starting position X component of this instance.
     85         /// </summary>
     86         public double PosX
     87         {
     88             get { return positionVector.X; }
     89             set { positionVector.X = value; }
     90         }
     91 
     92         /// <summary>
     93         /// The starting position Y component of this instance.
     94         /// </summary>
     95         public double PosY
     96         {
     97             get { return positionVector.Y; }
     98             set { positionVector.Y = value; }
     99         }
    100 
    101         /// <summary>
    102         /// The starting position Z component of this instance.
    103         /// </summary>
    104         public double PosZ
    105         {
    106             get { return positionVector.Z; }
    107             set { positionVector.Z = value; }
    108         }
    109 
    110         /// <summary>
    111         /// The starting velocity X component of this instance.
    112         /// </summary>
    113         public double VelX
    114         {
    115             get { return velocityVector.X; }
    116             set { velocityVector.X = value; }
    117         }
    118 
    119         /// <summary>
    120         /// The starting velocity Y component of this instance.
    121         /// </summary>
    122         public double VelY
    123         {
    124             get { return velocityVector.Y; }
    125             set { velocityVector.Y = value; }
    126         }
    127 
    128         /// <summary>
    129         /// The starting velocity Z component of this instance.
    130         /// </summary>
    131         public double VelZ
    132         {
    133             get { return velocityVector.Z; }
    134             set { velocityVector.Z = value; }
    135         }
    136 
    137 #pragma warning disable IDE0051
    138 
    139         /// <summary>
    140         /// Invokes the <see cref="PropertyChanged"/> event with the name of the caller property that changed.
    141         /// </summary>
    142         /// <param name="propertyName"></param>
    143         [NotifyPropertyChangedInvocator]
    144         private void OnPropertyChanged([CallerMemberName] string propertyName = null)
    145         {
    146             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    147         }
    148 
    149 #pragma warning restore IDE0051
    150 
    151         /// <summary>
    152         /// Implements a conversion between a <see cref="BodyDummy"/> instance to a <see cref="Body"/> instance.
    153         /// </summary>
    154         public Body AsBody()
    155         {
    156             return new Body(positionVector * Configuration.AstronomicalUnit, velocityVector * 1000,
    157                 Mass * Configuration.SolarMass, Generation, Id);
    158         }
    159     }
    160 }