First-pass implemention of configurable precision for some values.
[VOID.git] / VOID_Orbital.cs
blob:a/VOID_Orbital.cs -> blob:b/VOID_Orbital.cs
// //
// VOID_Orbital.cs // VOID_Orbital.cs
// //
// Author: // Author:
// toadicus <> // toadicus <>
// //
// Copyright (c) 2013 toadicus // Copyright (c) 2013 toadicus
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using KSP; using KSP;
using System; using System;
using UnityEngine; using UnityEngine;
   
namespace VOID namespace VOID
{ {
public class VOID_Orbital : VOID_WindowModule public class VOID_Orbital : VOID_WindowModule
{ {
[AVOID_SaveValue("toggleExtended")] [AVOID_SaveValue("toggleExtended")]
protected VOID_SaveValue<bool> toggleExtended = false; protected VOID_SaveValue<bool> toggleExtended = false;
   
[AVOID_SaveValue("precisionValues")] [AVOID_SaveValue("precisionValues")]
protected IntCollection precisionValues = new IntCollection(4, 230584300921369395); protected IntCollection precisionValues = new IntCollection(4, 230584300921369395);
   
  protected double orbitAltitude;
  protected double orbitVelocity;
  protected double orbitApoAlt;
  protected double oribtPeriAlt;
  protected string timeToApo;
  protected string timeToPeri;
  protected double orbitInclination;
  protected double gravityAccel;
  protected string orbitPeriod;
  protected double semiMajorAxis;
  protected double eccentricity;
  protected double meanAnomaly;
  protected double trueAnomaly;
  protected double eccAnomaly;
  protected double longitudeAscNode;
  protected double argumentPeriapsis;
  protected double localSiderealLongitude;
   
public VOID_Orbital() public VOID_Orbital()
{ {
this._Name = "Orbital Information"; this._Name = "Orbital Information";
   
this.WindowPos.x = Screen.width - 520f; this.WindowPos.x = Screen.width - 520f;
this.WindowPos.y = 250f; this.WindowPos.y = 250f;
} }
   
public override void ModuleWindow(int _) public override void ModuleWindow(int _)
{ {
// Toadicus edit: added local sidereal longitude. if (VOID_Core.Instance.updateTimer >= this.lastUpdate + VOID_Core.Instance.updatePeriod)
double LSL = vessel.longitude + vessel.orbit.referenceBody.rotationAngle; {
LSL = Tools.FixDegreeDomain (LSL); this.lastUpdate = VOID_Core.Instance.updateTimer;
   
  this.orbitAltitude = vessel.orbit.altitude;
  this.orbitVelocity = vessel.orbit.vel.magnitude;
  this.orbitApoAlt = vessel.orbit.ApA;
  this.oribtPeriAlt = vessel.orbit.PeA;
  this.timeToApo = Tools.ConvertInterval(vessel.orbit.timeToAp);
  this.timeToPeri = Tools.ConvertInterval(vessel.orbit.timeToPe);
  this.orbitInclination = vessel.orbit.inclination;
   
  double orbitRadius = vessel.mainBody.Radius + vessel.mainBody.GetAltitude(vessel.findWorldCenterOfMass());
  this.gravityAccel = (VOID_Core.Constant_G * vessel.mainBody.Mass) / Math.Pow(orbitRadius, 2);
   
  this.orbitPeriod = Tools.ConvertInterval(vessel.orbit.period);
  this.semiMajorAxis = vessel.orbit.semiMajorAxis;
  this.eccentricity = vessel.orbit.eccentricity;
  this.meanAnomaly = vessel.orbit.meanAnomaly * 180d / Math.PI;
  this.trueAnomaly = vessel.orbit.trueAnomaly;
  this.eccAnomaly = vessel.orbit.eccentricAnomaly * 180d / Math.PI;
  this.longitudeAscNode = vessel.orbit.LAN;
  this.argumentPeriapsis = vessel.orbit.argumentOfPeriapsis;
  this.localSiderealLongitude =
  Tools.FixDegreeDomain(vessel.longitude + vessel.orbit.referenceBody.rotationAngle);
  }
   
int idx = 0; int idx = 0;
   
GUILayout.BeginVertical(); GUILayout.BeginVertical();
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(VOIDLabels.void_primary + ":"); GUILayout.Label(VOIDLabels.void_primary + ":");
  GUILayout.FlexibleSpace();
GUILayout.Label(vessel.mainBody.bodyName, GUILayout.ExpandWidth(false)); GUILayout.Label(vessel.mainBody.bodyName, GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(VOIDLabels.void_altitude_asl + ":"); GUILayout.Label(VOIDLabels.void_altitude_asl + ":", GUILayout.ExpandWidth(true));
GUILayout.Label(Tools.MuMech_ToSI(vessel.orbit.altitude, this.precisionValues [idx]) + "m", GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace();
GUILayout.FlexibleSpace (); GUILayout.Label(
  Tools.MuMech_ToSI(this.orbitAltitude, this.precisionValues[idx]) + "m",
  GUILayout.ExpandWidth(false)
  );
if (GUILayout.Button ("P")) { if (GUILayout.Button ("P")) {
this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15); this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15);
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
idx++; idx++;
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(VOIDLabels.void_velocity + ":"); GUILayout.Label(VOIDLabels.void_velocity + ":");
GUILayout.Label(Tools.MuMech_ToSI(vessel.orbit.vel.magnitude, this.precisionValues [idx]) + "m/s", GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace();
GUILayout.FlexibleSpace (); GUILayout.Label(Tools.MuMech_ToSI(this.orbitVelocity, this.precisionValues [idx]) + "m/s", GUILayout.ExpandWidth(false));
   
if (GUILayout.Button ("P")) { if (GUILayout.Button ("P")) {
this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15); this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15);
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
idx++; idx++;
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(VOIDLabels.void_apoapsis + ":"); GUILayout.Label(VOIDLabels.void_apoapsis + ":");
GUILayout.Label(Tools.MuMech_ToSI(vessel.orbit.ApA, this.precisionValues [idx]) + "m", GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace();
GUILayout.FlexibleSpace (); GUILayout.Label(Tools.MuMech_ToSI(this.orbitApoAlt, this.precisionValues [idx]) + "m", GUILayout.ExpandWidth(false));
if (GUILayout.Button ("P")) {  
this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15); if (GUILayout.Button ("P")) {
} this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15);
GUILayout.EndHorizontal(); }
idx++; GUILayout.EndHorizontal();
  idx++;
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("Time to Ap:"); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(Tools.ConvertInterval(vessel.orbit.timeToAp), GUILayout.ExpandWidth(false)); GUILayout.Label("Time to Ap:");
  GUILayout.FlexibleSpace();
  GUILayout.Label(this.timeToApo, GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(VOIDLabels.void_periapsis + ":"); GUILayout.Label(VOIDLabels.void_periapsis + ":");
GUILayout.Label(Tools.MuMech_ToSI(vessel.orbit.PeA, this.precisionValues [idx]) + "m", GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace();
GUILayout.FlexibleSpace (); GUILayout.Label(
if (GUILayout.Button ("P")) { Tools.MuMech_ToSI(this.oribtPeriAlt, this.precisionValues [idx]) + "m",
this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15); GUILayout.ExpandWidth(false)
} );
GUILayout.EndHorizontal();  
idx++; if (GUILayout.Button ("P")) {
  this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15);
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); }
GUILayout.Label("Time to Pe:"); GUILayout.EndHorizontal();
GUILayout.Label(Tools.ConvertInterval(vessel.orbit.timeToPe), GUILayout.ExpandWidth(false)); idx++;
GUILayout.EndHorizontal();  
  GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("Time to Pe:");
GUILayout.Label("Inclination:"); GUILayout.FlexibleSpace();
GUILayout.Label(vessel.orbit.inclination.ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.Label(this.timeToPeri, GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
double r_vessel = vessel.mainBody.Radius + vessel.mainBody.GetAltitude(vessel.findWorldCenterOfMass()); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
double g_vessel = (VOID_Core.Constant_G * vessel.mainBody.Mass) / Math.Pow(r_vessel, 2); GUILayout.Label("Inclination:");
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace();
GUILayout.Label("Gravity:"); GUILayout.Label(this.orbitInclination.ToString("F3") + "°", GUILayout.ExpandWidth(false));
GUILayout.Label(Tools.MuMech_ToSI(g_vessel, this.precisionValues[idx]) + "m/s²", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal();
GUILayout.FlexibleSpace ();  
  GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
  GUILayout.Label("Gravity:");
  GUILayout.FlexibleSpace();
  GUILayout.Label(
  Tools.MuMech_ToSI(gravityAccel, this.precisionValues[idx]) + "m/s²",
  GUILayout.ExpandWidth(false)
  );
   
if (GUILayout.Button ("P")) { if (GUILayout.Button ("P")) {
this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15); this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15);
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
idx++; idx++;
   
this.toggleExtended = GUILayout.Toggle(this.toggleExtended, "Extended info"); this.toggleExtended = GUILayout.Toggle(this.toggleExtended, "Extended info");
   
if (this.toggleExtended) if (this.toggleExtended)
{ {
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label("Period:"); GUILayout.Label("Period:");
GUILayout.Label(Tools.ConvertInterval(vessel.orbit.period), GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace();
GUILayout.EndHorizontal(); GUILayout.Label(this.orbitPeriod, GUILayout.ExpandWidth(false));
  GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("Semi-major axis:"); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(Tools.MuMech_ToSI(vessel.orbit.semiMajorAxis, this.precisionValues [idx]) + "m", GUILayout.ExpandWidth(false)); GUILayout.Label("Semi-major axis:");
GUILayout.FlexibleSpace (); GUILayout.FlexibleSpace();
  GUILayout.Label(
  Tools.MuMech_ToSI(this.semiMajorAxis, this.precisionValues [idx]) + "m",
  GUILayout.ExpandWidth(false)
  );
   
if (GUILayout.Button ("P")) { if (GUILayout.Button ("P")) {
this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15); this.precisionValues [idx] = (ushort)((this.precisionValues[idx] + 3) % 15);
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
idx++; idx++;
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label("Eccentricity:"); GUILayout.Label("Eccentricity:");
GUILayout.Label(vessel.orbit.eccentricity.ToString("F4"), GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace();
  GUILayout.Label(this.eccentricity.ToString("F4"), GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
// Toadicus edit: convert mean anomaly into degrees. // Toadicus edit: convert mean anomaly into degrees.
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label("Mean anomaly:"); GUILayout.Label("Mean anomaly:");
GUILayout.Label((vessel.orbit.meanAnomaly * 180d / Math.PI).ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace();
GUILayout.EndHorizontal(); GUILayout.Label(this.meanAnomaly.ToString("F3") + "°", GUILayout.ExpandWidth(false));
  GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("True anomaly:"); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(vessel.orbit.trueAnomaly.ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.Label("True anomaly:");
  GUILayout.FlexibleSpace();
  GUILayout.Label(this.trueAnomaly.ToString("F3") + "°", GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
// Toadicus edit: convert eccentric anomaly into degrees. // Toadicus edit: convert eccentric anomaly into degrees.
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label("Eccentric anomaly:"); GUILayout.Label("Eccentric anomaly:");
GUILayout.Label((vessel.orbit.eccentricAnomaly * 180d / Math.PI).ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.FlexibleSpace();
GUILayout.EndHorizontal(); GUILayout.Label(this.eccAnomaly.ToString("F3") + "°", GUILayout.ExpandWidth(false));
  GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("Long. ascending node:"); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(vessel.orbit.LAN.ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.Label("Long. ascending node:");
GUILayout.EndHorizontal(); GUILayout.FlexibleSpace();
  GUILayout.Label(this.longitudeAscNode.ToString("F3") + "°", GUILayout.ExpandWidth(false));
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal();
GUILayout.Label("Arg. of periapsis:");  
GUILayout.Label(vessel.orbit.argumentOfPeriapsis.ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
  GUILayout.Label("Arg. of periapsis:");
  GUILayout.FlexibleSpace();
  GUILayout.Label(this.argumentPeriapsis.ToString("F3") + "°", GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
// Toadicus edit: added local sidereal longitude. // Toadicus edit: added local sidereal longitude.
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label("Local Sidereal Longitude:"); GUILayout.Label("Local Sidereal Longitude:");
GUILayout.Label(LSL.ToString("F3") + "°", VOID_Core.Instance.LabelStyles["txt_right"]); GUILayout.FlexibleSpace();
  GUILayout.Label(this.localSiderealLongitude.ToString("F3") + "°", VOID_Core.Instance.LabelStyles["right"]);
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
   
GUILayout.EndVertical(); GUILayout.EndVertical();
GUI.DragWindow(); GUI.DragWindow();
} }
} }
} }