private void Parse(string[] lines) { int i; for (i = 0; i <= lines.Count() - 1; i++) { switch (lines[i].ToUpperInvariant()) { case "BEGIN_DESC": { i++; Description = lines[i]; i++; while (!(lines[i] == "END_DESC")) { Description += '\n' + lines[i]; i++; } break; } case "BEGIN_ENVIRONMENT": { i++; while (!(lines[i] == "END_ENVIRONMENT")) { string[] content = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (content[0].ToUpperInvariant()) { case "SYSTEM": System = content[1]; break; case "DATE": switch (content[1]) { case "MJD": MJD = double.Parse(content[2]); break; case "JD": MJD = double.Parse(content[2]) + 2400000.5; break; default: //MJD = Misc.GetMJD(DateTime.Now); // Wrong: we should only indicate there's no MJD data MJD = -1d; // Will trigger 'HasMJD = false' break; } break; case "HELP": Help = content[1]; break; case "SCRIPT": Script = content[1]; break; } i++; } break; } case "BEGIN_CAMERA": { OrbCamera cam = new OrbCamera(); while (lines[i] != "END_CAMERA") { string[] line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (line[0].ToUpperInvariant()) { case "MODE": if (line[1] == "Extern") { cam.Mode = OrbCamera.CameraMode.Extern; } else { cam.Mode = OrbCamera.CameraMode.GlassCockpit; } break; case "TARGET": cam.Target = line[1]; break; case "POS": try { cam.Pos = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); } catch { } break; case "TRACKMODE": OrbCamera.CameraTrackMode tmode; if (Enum.TryParse <OrbCamera.CameraTrackMode>(line[1], out tmode)) { cam.TrackMode = tmode; } try { cam.RefBody = line[2]; } catch { } break; case "GROUNDLOCATION": if (line.Length < 4) { break; } cam.GroundLocation = new double[] { double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]) }; break; case "GROUNDDIRECTION": if (line.Length < 3) { break; } cam.GroundDirection = new double[] { double.Parse(line[1]), double.Parse(line[2]) }; break; case "FOV": cam.FieldOfView = double.Parse(line[1]); break; } i++; } Camera = cam; break; } case "BEGIN_PANEL": Camera.Mode = OrbCamera.CameraMode.PanelCockpit; while (lines[i] != "END_PANEL") { i++; } break; case "BEGIN_VC": Camera.Mode = OrbCamera.CameraMode.VirtualCockpit; while (lines[i] != "END_VC") { i++; } break; case "BEGIN_HUD": i++; while (lines[i] != "END_HUD") { string[] line2 = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (line2[0].ToUpperInvariant()) { case "TYPE": OrbHUD hud = OrbHUD.None; Enum.TryParse <OrbHUD>(line2[1], out hud); HUDmode = hud; break; } i++; } break; case "BEGIN_SHIPS": { OrbVessel ship = new OrbVessel(); i++; string[] content = lines[i].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (content.Count() == 2) { ship.Name = content[0]; ship.VesselClass = content[1]; i++; while (!(lines[i] == "END")) { string[] line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (line[0].ToUpperInvariant()) { case "STATUS": ship.Status = line[1]; ship.RefBody = line[2]; break; case "POS": ship.SetPOS(Double.Parse(line[2]), double.Parse(line[1])); break; case "HEADING": ship.Heading = double.Parse(line[1]); break; case "RPOS": ship.RPos = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); break; case "RVEL": ship.RVel = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); break; case "AROT": ship.ARot = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); break; case "VROT": ship.VRot = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); break; case "FUEL": { ship.Fuel = float.Parse(line[1]); break; } case "PRPLEVEL": { List <OrbLevels> level = new List <OrbLevels>(); for (int j = 1; j < line.Count() - 1; j++) { string[] split = line[j].Split(':'); level.Add(new OrbLevels(int.Parse(split[0]), float.Parse(split[1]))); } ship.PrpLevel = level; break; } case "THLEVEL": { List <OrbLevels> throttles = new List <OrbLevels>(); for (int j = 1; j < line.Count() - 1; j++) { string[] split = line[j].Split(':'); throttles.Add(new OrbLevels(int.Parse(split[0]), float.Parse(split[1]))); } ship.ThLevel = throttles; break; } case "DOCKINFO": { List <OrbDockInfo> dockinfo = new List <OrbDockInfo>(); for (int j = 1; j < line.Count() - 1; j++) { string[] split = line[j].Split(':'); dockinfo.Add(new OrbDockInfo { DockID = int.Parse(split[0]), TargetDockID = int.Parse(split[1]), TargetVessel = split[2] }); } ship.DockInfo = dockinfo; break; } default: { string key = line[0]; string value = ""; for (int j = 1; j < line.Count(); j++) { value += line[j] + " "; } ship.Extra.Add(key, value.Trim()); break; } } i++; } } } break; } } if (MJD == 0) { MJD = Misc.GetMJD(DateTime.Now); } }
private void Parse(string[] lines) { int i; for (i = 0; i <= lines.Count()-1; i++) { switch (lines[i].ToUpperInvariant()) { case "BEGIN_DESC": { i++; Description = lines[i]; i++; while (!(lines[i] == "END_DESC")) { Description += '\n' + lines[i]; i++; } break; } case "BEGIN_ENVIRONMENT": { i++; while (!(lines[i] == "END_ENVIRONMENT")) { string[] content = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (content[0].ToUpperInvariant()) { case "SYSTEM": System = content[1]; break; case "DATE": switch (content[1]) { case "MJD": MJD = double.Parse(content[2]); break; case "JD": MJD = double.Parse(content[2]) + 2400000.5; break; default: //MJD = Misc.GetMJD(DateTime.Now); // Wrong: we should only indicate there's no MJD data MJD = -1d; // Will trigger 'HasMJD = false' break; } break; case "HELP": Help = content[1]; break; case "SCRIPT": Script = content[1]; break; } i++; } break; } case "BEGIN_CAMERA": { OrbCamera cam = new OrbCamera(); while (lines[i] != "END_CAMERA") { string[] line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (line[0].ToUpperInvariant()) { case "MODE": if (line[1] == "Extern") cam.Mode = OrbCamera.CameraMode.Extern; else cam.Mode = OrbCamera.CameraMode.GlassCockpit; break; case "TARGET": cam.Target = line[1]; break; case "POS": try { cam.Pos = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); } catch { } break; case "TRACKMODE": OrbCamera.CameraTrackMode tmode; if(Enum.TryParse<OrbCamera.CameraTrackMode>(line[1], out tmode)) cam.TrackMode = tmode; try { cam.RefBody = line[2]; } catch { } break; case "GROUNDLOCATION": if (line.Length < 4) break; cam.GroundLocation = new double[] { double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]) }; break; case "GROUNDDIRECTION": if (line.Length < 3) break; cam.GroundDirection = new double[] { double.Parse(line[1]), double.Parse(line[2]) }; break; case "FOV": cam.FieldOfView = double.Parse(line[1]); break; } i++; } Camera = cam; break; } case "BEGIN_PANEL": Camera.Mode = OrbCamera.CameraMode.PanelCockpit; while (lines[i] != "END_PANEL") { i++; } break; case "BEGIN_VC": Camera.Mode = OrbCamera.CameraMode.VirtualCockpit; while (lines[i]!="END_VC") { i++; } break; case "BEGIN_HUD": i++; while (lines[i]!="END_HUD") { string[] line2 = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (line2[0].ToUpperInvariant()) { case "TYPE": OrbHUD hud = OrbHUD.None; Enum.TryParse<OrbHUD>(line2[1], out hud); HUDmode = hud; break; } i++; } break; case "BEGIN_SHIPS": { OrbVessel ship = new OrbVessel(); i++; string[] content = lines[i].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (content.Count() == 2) { ship.Name = content[0]; ship.VesselClass = content[1]; i++; while (!(lines[i] == "END")) { string[] line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (line[0].ToUpperInvariant()) { case "STATUS": ship.Status = line[1]; ship.RefBody = line[2]; break; case "POS": ship.SetPOS(Double.Parse(line[2]), double.Parse(line[1])); break; case "HEADING": ship.Heading = double.Parse(line[1]); break; case "RPOS": ship.RPos = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); break; case "RVEL": ship.RVel = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); break; case "AROT": ship.ARot = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); break; case "VROT": ship.VRot = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); break; case "FUEL": { ship.Fuel = float.Parse(line[1]); break; } case "PRPLEVEL": { List<OrbLevels> level = new List<OrbLevels>(); for (int j = 1; j < line.Count()-1; j++) { string[] split = line[j].Split(':'); level.Add(new OrbLevels(int.Parse(split[0]), float.Parse(split[1]))); } ship.PrpLevel = level; break; } case "THLEVEL": { List<OrbLevels> throttles = new List<OrbLevels>(); for (int j = 1; j < line.Count()-1; j++) { string[] split = line[j].Split(':'); throttles.Add(new OrbLevels(int.Parse(split[0]), float.Parse(split[1]))); } ship.ThLevel = throttles; break; } case "DOCKINFO": { List<OrbDockInfo> dockinfo = new List<OrbDockInfo>(); for (int j = 1; j<line.Count() - 1; j++) { string[] split = line[j].Split(':'); dockinfo.Add(new OrbDockInfo { DockID = int.Parse(split[0]), TargetDockID = int.Parse(split[1]), TargetVessel = split[2] }); } ship.DockInfo = dockinfo; break; } default: { string key = line[0]; string value = ""; for (int j = 1; j < line.Count(); j++) { value += line[j] + " "; } ship.Extra.Add(key, value.Trim()); break; } } i++; } } } break; } } if (MJD == 0) MJD = Misc.GetMJD(DateTime.Now); }
private void BT_ImportTLE_Click(object sender, EventArgs e) { ImportTLE IT = new ImportTLE(); List<string> errorVessels = new List<string>(); if (IT.ShowDialog() != DialogResult.OK) return; string[] content = IT.TLEData.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < content.Length; i += 3) { string tname = content[i + 0].Trim(); string strTle = tname + '\n'; strTle += content[i + 1] + '\n'; strTle += content[i + 2]; ListViewItem lvi = LV_Ships.Items.Add(tname); try { OrbVessel OV = new OrbVessel("ShuttlePB", strTle.Split('\n')); lvi.SubItems.Add(OV.Name); lvi.SubItems.Add(OV.VesselClass); lvi.SubItems.Add(strTle); lvi.Tag = OV; lvi.Checked = true; } catch (Exception ex ) { Log.Write(string.Format("[ERROR] Could not add '{0}':", tname)); Log.WriteError(ex); errorVessels.Add(tname); lvi.Remove(); } } MessageBox.Show("These entries could not be added:\n" + string.Join("\n", errorVessels.ToArray()) + "\n\nPlease check the logs.", "Error importing TLE", MessageBoxButtons.OK, MessageBoxIcon.Error); }
/// <summary> /// Orbiter Camera block in string format /// </summary> /// <param name="firstship">First ship in the list to track to when no target is avaliable.</param> /// <returns>Orbiter formatted string containing the Camera block of the scenario.</returns> public string ToString(OrbVessel firstship) { StringBuilder sb = new StringBuilder(); sb.AppendLine("BEGIN_CAMERA"); switch (Mode) { case CameraMode.Extern: sb.AppendLine(" MODE Extern"); break; case CameraMode.GlassCockpit: case CameraMode.PanelCockpit: case CameraMode.VirtualCockpit: sb.AppendLine(" MODE Cockpit"); break; } if (!string.IsNullOrWhiteSpace(Target)) sb.AppendLine(" TARGET " + Target); else sb.AppendLine(" TARGET " + firstship.Name); sb.AppendLine(string.Format(" POS {0:0.00} {1:0.00} {2:0.00}", Pos.x, Pos.y, Pos.z)); switch (TrackMode) { case CameraTrackMode.TargetRelative: sb.AppendLine(" TRACKMODE TargetRelative"); break; case CameraTrackMode.AbsoluteDirection: sb.AppendLine(" TRACKMODE AbsoluteDirection"); break; case CameraTrackMode.GlobalFrame: sb.AppendLine(" TRACKMODE GlobalFrame"); break; case CameraTrackMode.TargetTo: sb.AppendLine(" TRACKMODE TargetTo " + RefBody); break; case CameraTrackMode.TargetFrom: sb.AppendLine(" TRACKMODE TargetFrom " + RefBody); break; case CameraTrackMode.Ground: sb.AppendLine(" TRACKMODE Ground " + RefBody); sb.AppendLine(string.Format(" GROUNDLOCATION {0:0.00} {1:0.00} {2:0.00}", GroundLocation)); sb.AppendLine(string.Format(" GROUNDDIRECTION {0:0.000} {1:0.000}", GroundDirection)); break; } sb.AppendLine(string.Format(" FOV {0:0.0}", FieldOfView)); sb.Append("END_CAMERA"); switch (Mode) { case CameraMode.PanelCockpit: sb.AppendLine("BEGIN_PANEL"); sb.Append("END_PANEL"); break; case CameraMode.VirtualCockpit: sb.AppendLine("BEGIN_VC"); sb.Append("END_VC"); break; } return sb.ToString(); }
public OrbVesselContext(Dictionary<string, object> data, string[] tle, OrbVessel Vessel) { _vesselData = data; _tle = tle; _vessel = Vessel; }
/// <summary> /// Orbiter Camera block in string format /// </summary> /// <param name="firstship">First ship in the list to track to when no target is avaliable.</param> /// <returns>Orbiter formatted string containing the Camera block of the scenario.</returns> public string ToString(OrbVessel firstship) { StringBuilder sb = new StringBuilder(); sb.AppendLine("BEGIN_CAMERA"); switch (Mode) { case CameraMode.Extern: sb.AppendLine(" MODE Extern"); break; case CameraMode.GlassCockpit: case CameraMode.PanelCockpit: case CameraMode.VirtualCockpit: sb.AppendLine(" MODE Cockpit"); break; } if (!string.IsNullOrWhiteSpace(Target)) { sb.AppendLine(" TARGET " + Target); } else { sb.AppendLine(" TARGET " + firstship.Name); } sb.AppendLine(string.Format(" POS {0:0.00} {1:0.00} {2:0.00}", Pos.x, Pos.y, Pos.z)); switch (TrackMode) { case CameraTrackMode.TargetRelative: sb.AppendLine(" TRACKMODE TargetRelative"); break; case CameraTrackMode.AbsoluteDirection: sb.AppendLine(" TRACKMODE AbsoluteDirection"); break; case CameraTrackMode.GlobalFrame: sb.AppendLine(" TRACKMODE GlobalFrame"); break; case CameraTrackMode.TargetTo: sb.AppendLine(" TRACKMODE TargetTo " + RefBody); break; case CameraTrackMode.TargetFrom: sb.AppendLine(" TRACKMODE TargetFrom " + RefBody); break; case CameraTrackMode.Ground: sb.AppendLine(" TRACKMODE Ground " + RefBody); sb.AppendLine(string.Format(" GROUNDLOCATION {0:0.00} {1:0.00} {2:0.00}", GroundLocation)); sb.AppendLine(string.Format(" GROUNDDIRECTION {0:0.000} {1:0.000}", GroundDirection)); break; } sb.AppendLine(string.Format(" FOV {0:0.0}", FieldOfView)); sb.Append("END_CAMERA"); switch (Mode) { case CameraMode.PanelCockpit: sb.AppendLine("BEGIN_PANEL"); sb.Append("END_PANEL"); break; case CameraMode.VirtualCockpit: sb.AppendLine("BEGIN_VC"); sb.Append("END_VC"); break; } return(sb.ToString()); }