-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainForm.cs
146 lines (128 loc) · 4.99 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (c) 2016 SolarLiner - Part of the TLE Orbiter Sceneraio Generator (TLEOSG)
using AOSP;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace TLEOrbiter
{
public partial class MainForm : Form
{
public OrbScenario SCN { get; set; }
public string ScnName { get; set; }
public MainForm()
{
Log.Write("new MainForm()");
InitializeComponent();
SCN = new OrbScenario();
SCN.Camera = new OrbCamera(OrbCamera.CameraMode.GlassCockpit);
SCN.MJD = -1d;
SCN.Description = "Imported TLE with TLE Scenario Generator";
ScnName = "Imported TLE";
}
private void BT_EditScenario_Click(object sender, EventArgs e)
{
ScenarioProperties SP = new ScenarioProperties();
SP.MJD = SCN.MJD;
SP.ScenarioName = ScnName;
SP.Description = SCN.Description;
if (SP.ShowDialog() != DialogResult.OK) return;
//SP.ShowDialog();
SCN.MJD = SP.MJD;
SCN.Description = SP.Description;
ScnName = SP.ScenarioName;
}
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);
}
private void PopulateSCN()
{
// Populate ships
Log.Write("MainForm.PopulateSCN()");
SCN.Ships.Clear();
SCN.MJD = SCN.HasMJD ? SCN.MJD : Misc.GetMJD(DateTime.UtcNow);
foreach( ListViewItem lvi in LV_Ships.Items )
{
if( !lvi.Checked ) continue;
Log.Write("Ship: " + (lvi.Tag as OrbVessel).Name);
SCN.Ships.Add((OrbVessel)lvi.Tag);
}
}
private void BT_SelectNone_Click(object sender, EventArgs e)
{
foreach (ListViewItem lvi in LV_Ships.Items)
{
lvi.Checked = false;
}
}
private void BT_SelectAll_Click(object sender, EventArgs e)
{
foreach (ListViewItem lvi in LV_Ships.Items)
{
lvi.Checked = true;
}
}
private void BT_InvertSelection_Click(object sender, EventArgs e)
{
foreach (ListViewItem lvi in LV_Ships.Items)
{
lvi.Checked = !lvi.Checked;
}
}
private void BT_GenScn_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Orbiter Scenario|*.scn";
sfd.FileName = ScnName.Trim().Replace(' ', '_') + ".scn";
if (sfd.ShowDialog() != DialogResult.OK) return;
PopulateSCN();
System.IO.File.WriteAllText(sfd.FileName, SCN.RenderScenario());
}
private void LV_Ships_DoubleClick(object sender, EventArgs e)
{
ListViewItem lvi = LV_Ships.SelectedItems[0];
lvi.Checked = !lvi.Checked;
VesselEdit VE = new VesselEdit();
VE.Vessel = (OrbVessel)lvi.Tag;
VE.TLE = lvi.SubItems[3].Text.Split('\n');
if (VE.ShowDialog() != DialogResult.OK) return;
lvi.SubItems[1].Text = VE.OrbiterName;
lvi.SubItems[2].Text = VE.VesselClass;
lvi.SubItems[3].Text = string.Join("\n", VE.TLE);
lvi.Text = VE.TLE[0];
lvi.Tag = VE.Vessel;
}
private void LL_Settings_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
(new SettingsForm()).ShowDialog();
}
}
}