-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchResults1.cs
397 lines (330 loc) · 14.6 KB
/
SearchResults1.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
namespace EAACP
{
public partial class SearchResults : Form
{
private Stellarium Stellarium = new Stellarium();
private List<string[]> ResultsList = null;
private DataTable ResultsTable = null;
DataTable dt = new DataTable();
DataTable dtUniqueCatalogues = new DataTable();
int totalResults = 0;
string stellariumDSOFilter;
string displayMode = "All";
public frmCP EAACP;
public SearchResults()
{
InitializeComponent();
}
public List<string[]> Results
{
set
{
ResultsList = value;
}
}
public DataTable ResultsDataTable
{
set
{
ResultsTable = value;
}
}
public double CentreRA;
public double CentreDec;
public string CentreID;
private void SearchResults_Load(object sender, EventArgs e)
{
Stellarium.ScriptFolder = Properties.Settings.Default.StScriptFolder;
stellariumDSOFilter = Stellarium.GetStelProperty("NebulaMgr.catalogFilters");
cbStellariumShowDSOImage.Checked = bool.Parse(Stellarium.GetStelProperty("actionShow_DSO_Textures", true));
cbStellariumMinorBodyMarkers.Checked = bool.Parse(Stellarium.GetStelProperty("actionShow_Planets_ShowMinorBodyMarkers", true));
if (ResultsList != null || ResultsTable != null)
{
dt.Columns.Add("ID");
dt.Columns.Add("Names");
dt.Columns.Add("Type");
dt.Columns.Add("Magnitude", typeof(double));
dt.Columns.Add("Distance Mpc", typeof(double));
dt.Columns.Add("Galaxy Type");
dt.Columns.Add("Catalogue");
dt.Columns.Add("RA");
dt.Columns.Add("Dec");
dt.Columns.Add("dRA");
dt.Columns.Add("dDec");
dt.Columns.Add("Size");
dt.Columns.Add("PosAngle");
dt.Columns.Add("Constellation");
if (ResultsTable != null)
{
dt = ResultsTable;
}
else
{
foreach (string[] APObject in ResultsList)
{
DataRow row = dt.NewRow();
row["ID"] = APObject[0];
row["Names"] = APObject[1];
row["Type"] = APObject[2];
if (double.TryParse(APObject[3], out double Mag))
{
row["Magnitude"] = Mag;
}
else row["Magnitude"] = DBNull.Value;
if (double.TryParse(APObject[5], out double Dist))
{
row["Distance Mpc"] = Math.Round(Dist, 2);
}
else row["Distance Mpc"] = DBNull.Value;
row["Galaxy Type"] = APObject[4];
row["Catalogue"] = APObject[6];
row["RA"] = APObject[7];
row["Dec"] = APObject[8];
row["dRA"] = APObject[9];
row["dDec"] = APObject[10];
row["Size"] = APObject[11];
row["PosAngle"] = APObject[12];
row["Constellation"] = APObject[13];
dt.Rows.Add(row);
}
}
// Fetch and display list of unique catalogues
cbCataloguesFilter.SelectedIndexChanged -= cbCataloguesFilter_SelectedIndexChanged;
dtUniqueCatalogues = Stellarium.UniqueCataloguesInSearchResults(dt);
cbCataloguesFilter.DataSource = dtUniqueCatalogues;
cbCataloguesFilter.DisplayMember = "Catalogue";
cbCataloguesFilter.SelectedIndexChanged += cbCataloguesFilter_SelectedIndexChanged;
dgvSearchResults.DataSource = dt;
dgvSearchResults.Columns["dRA"].Visible = false;
dgvSearchResults.Columns["dDec"].Visible = false;
dgvSearchResults.Columns["Size"].Visible = false;
dgvSearchResults.Columns["PosAngle"].Visible = false;
dgvSearchResults.Columns["Constellation"].Visible = false;
dgvSearchResults.Sort(dgvSearchResults.Columns["Magnitude"], System.ComponentModel.ListSortDirection.Ascending);
totalResults = dt.Rows.Count;
UpdateSearchInfo(totalResults);
}
}
private void UpdateSearchInfo(int viewCount)
{
this.Text = $"Search Results: {totalResults} objects, Current View: {viewCount} objects";
}
private void DrawSelectedObjects()
{
displayMode = "Selected";
DataTable Selected = new DataTable();
Selected.Columns.Add("ID");
Selected.Columns.Add("Names");
Selected.Columns.Add("Type");
Selected.Columns.Add("Magnitude", typeof(double));
Selected.Columns.Add("Distance Mpc", typeof(double));
Selected.Columns.Add("Galaxy Type");
Selected.Columns.Add("Catalogue");
Selected.Columns.Add("RA");
Selected.Columns.Add("Dec");
Selected.Columns.Add("dRA");
Selected.Columns.Add("dDec");
Selected.Columns.Add("Size");
Selected.Columns.Add("PosAngle");
Selected.Columns.Add("Constellation");
foreach (DataGridViewRow row in dgvSearchResults.SelectedRows)
{
DataRow SelectedRow = Selected.NewRow();
SelectedRow["ID"] = row.Cells["ID"].Value;
SelectedRow["Names"] = row.Cells["Names"].Value;
SelectedRow["Type"] = row.Cells["Type"].Value;
if (double.TryParse(row.Cells["Magnitude"].Value.ToString(), out double Mag))
{
SelectedRow["Magnitude"] = Mag;
}
else SelectedRow["Magnitude"] = DBNull.Value;
if (double.TryParse(row.Cells["Distance Mpc"].Value.ToString(), out double Dist))
{
SelectedRow["Distance Mpc"] = Math.Round(Dist, 2);
}
else SelectedRow["Distance Mpc"] = DBNull.Value;
SelectedRow["Galaxy Type"] = row.Cells["Galaxy Type"].Value;
SelectedRow["Catalogue"] = row.Cells["Catalogue"].Value;
SelectedRow["RA"] = row.Cells["RA"].Value;
SelectedRow["Dec"] = row.Cells["Dec"].Value;
SelectedRow["dRA"] = row.Cells["dRA"].Value;
SelectedRow["dDec"] = row.Cells["dDec"].Value;
SelectedRow["Size"] = row.Cells["Size"].Value;
SelectedRow["PosAngle"] = row.Cells["PosAngle"].Value;
SelectedRow["Constellation"] = row.Cells["Constellation"].Value;
Selected.Rows.Add(SelectedRow);
}
Stellarium.DrawObjects(Selected);
UpdateSearchInfo(dgvSearchResults.SelectedRows.Count);
}
private void btnDrawSelection_Click(object sender, EventArgs e)
{
DrawSelectedObjects();
}
private void ResetCatalogueFilter()
{
cbCataloguesFilter.SelectedIndexChanged -= cbCataloguesFilter_SelectedIndexChanged;
cbCataloguesFilter.SelectedIndex = 0;
cbCataloguesFilter.SelectedIndexChanged += cbCataloguesFilter_SelectedIndexChanged;
}
private void btnPlotAll_Click(object sender, EventArgs e)
{
displayMode = "All";
// Stop the catalogues filter from firing
ResetCatalogueFilter();
// Remove any filtering
dt.DefaultView.RowFilter = "";
Stellarium.DrawObjects(dt);
UpdateSearchInfo(totalResults);
}
private void btnAddToAP_Click(object sender, EventArgs e)
{
List<APCmdObject> apObjects = new List<APCmdObject>();
DialogResult result = MessageBox.Show("Adding many objects to AstroPlanner, can take sometime and cannot be cancelled. Do you wish to continue?", "Add Objects to AstroPlanner", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.No)
{
return;
}
if (dgvSearchResults.SelectedRows.Count == 0)
{
EAACP.Speak("No objects selected");
return;
}
foreach (DataGridViewRow row in dgvSearchResults.SelectedRows)
{
APCmdObject obj = new APCmdObject();
obj.ID = row.Cells["ID"].Value.ToString();
obj.Name = row.Cells["Names"].Value.ToString();
obj.Type = row.Cells["Type"].Value.ToString();
obj.RA2000 = double.Parse(row.Cells["dRA"].Value.ToString());
obj.Dec2000 = double.Parse(row.Cells["dDec"].Value.ToString());
obj.Catalogue = row.Cells["Catalogue"].Value.ToString();
obj.Distance = row.Cells["Distance Mpc"].Value.ToString();
obj.GalaxyType = row.Cells["Galaxy Type"].Value.ToString();
obj.Size = row.Cells["Size"].Value.ToString();
obj.PosAngle = int.Parse(row.Cells["PosAngle"].Value.ToString());
obj.Constellation = row.Cells["Constellation"].Value.ToString();
if (double.TryParse(row.Cells["Magnitude"].Value.ToString(), out double Magnitude))
{
obj.Magnitude = Magnitude;
}
apObjects.Add(obj);
}
APPutCmd aPPutCmd = new APPutCmd();
aPPutCmd.script = "EAAControl2";
aPPutCmd.parameters = new APPutCmdParams();
aPPutCmd.parameters.Cmd = 2;
aPPutCmd.parameters.Option = 1;
aPPutCmd.parameters.Objects = apObjects;
string sOut = EAACP.APExecuteScript(Uri.EscapeDataString(JsonSerializer.Serialize<APPutCmd>(aPPutCmd)));
EAACP.Speak(dgvSearchResults.SelectedRows.Count.ToString() + " Objects added");
}
private void btnOptions_Click(object sender, EventArgs e)
{
using (StelFOVOptions frmOpt = new StelFOVOptions())
{
frmOpt.Mode = 1;
frmOpt.TopMost = true;
if (frmOpt.ShowDialog() == DialogResult.OK)
{
// If the user hs changed the display attributes then update the current plot selection on ext.
switch (displayMode)
{
case "All":
Stellarium.DrawObjects(dt);
break;
case "Filtered":
DrawCatalogueFiltered();
break;
case "Selected":
DrawSelectedObjects();
break;
}
}
}
}
private void btnRecentre_Click(object sender, EventArgs e)
{
Stellarium.SyncStellariumToAPObject(CentreID, CentreRA.ToString(), CentreDec.ToString(), "");
}
private void btnCentreSelected_Click(object sender, EventArgs e)
{
if (dgvSearchResults.SelectedRows.Count>0)
{
double RA = double.Parse(dgvSearchResults.SelectedRows[0].Cells["dRA"].Value.ToString());
double Dec = double.Parse(dgvSearchResults.SelectedRows[0].Cells["dDec"].Value.ToString());
Stellarium.SyncStellariumToPosition(RA, Dec);
}
}
private void DrawCatalogueFiltered()
{
displayMode = "Filtered";
string apCatalogue = cbCataloguesFilter.Text;
if (apCatalogue == "All Catalogues")
{
dt.DefaultView.RowFilter = "";
Stellarium.DrawObjects(dt);
UpdateSearchInfo(totalResults);
}
else
{
DataView dv = dt.DefaultView;
dv.RowFilter = "Catalogue = '" + apCatalogue + "'";
Stellarium.DrawObjects(dv.ToTable());
UpdateSearchInfo(dv.ToTable().Rows.Count);
}
}
private void cbCataloguesFilter_SelectedIndexChanged(object sender, EventArgs e)
{
DrawCatalogueFiltered();
}
private void btnAllCats_Click(object sender, EventArgs e)
{
Stellarium.SetStelProperty("NebulaMgr.catalogFilters", "0");
}
private void btnDSOStandard_Click(object sender, EventArgs e)
{
Stellarium.SetStelProperty("NebulaMgr.catalogFilters", "7");
}
private void btnDSOAll_Click(object sender, EventArgs e)
{
Stellarium.SetStelProperty("NebulaMgr.catalogFilters", "255852279");
}
private void btnClearPlot_Click(object sender, EventArgs e)
{
displayMode = "All";
Stellarium.ClearObjects();
// Stop the catalogues filter from firing
ResetCatalogueFilter();
UpdateSearchInfo(0);
}
private void SearchResults_FormClosing(object sender, FormClosingEventArgs e)
{
Stellarium.SetStelProperty("NebulaMgr.catalogFilters", stellariumDSOFilter);
}
private void cbStellariumShowDSOImage_CheckedChanged(object sender, EventArgs e)
{
Stellarium.SetStelProperty("actionShow_DSO_Textures", cbStellariumShowDSOImage.Checked.ToString());
}
private void cbStellariumMinorBodyMarkers_CheckedChanged(object sender, EventArgs e)
{
Stellarium.SetStelProperty("actionShow_Planets_ShowMinorBodyMarkers", cbStellariumMinorBodyMarkers.Checked.ToString());
}
private void cbStellariumSatellites_CheckStateChanged(object sender, EventArgs e)
{
Stellarium.SetStelProperty("actionShow_Satellite_Hints", cbStellariumSatellites.Checked.ToString());
}
}
}