-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPHelper.cs
233 lines (208 loc) · 9.26 KB
/
APHelper.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EAACP
{
internal class APHelper
{
public struct SizeInfo
{
public double MajorAxis;
public double MinorAxis;
}
public struct SizeInfoString
{
public string MajorAxis;
public string MinorAxis;
}
private Dictionary<int, string> WebServerErrors = new Dictionary<int, string>()
{
{0,"No error"},{1,"Bad JSON payload"},{2,"Missing script name"},{3,"Script does not exist"},{4,"Authentication error"},
{5,"Command parameter missing"},{6,"Internal AP error"},{7,"Unknown command"},{8,"Error in script"},
{9,"Cannot open script file"},{10,"Script not of general type"},{11,"Script is empty"},{12,"Script name illegal"}
};
public string WebServerErrorString(int errorCode)
{
try
{
return WebServerErrors[errorCode];
}
catch (System.Collections.Generic.KeyNotFoundException)
{
return "Unknown error";
}
}
private Dictionary<string, string> ConstellationMappings = new Dictionary<string, string>()
{
{"and", "Andromeda"}, {"ant", "Antlia"}, {"aps", "Apus"}, {"aqr", "Aquarius"},
{"aql", "Aquila"}, {"ara", "Ara"}, {"ari","Aries"},{"aur","Auriga"},{"boo","Bootes"},
{"cae", "Caelum"},{"cam", "Camelopardalis"},{"cnc", "Cancer"},{"cvn", "Canes Venatici"},
{"cma", "Canis Major"},{"cmi", "Canis Minor"},{"cap", "Capricornus"},{"car", "Carina"},
{"cas", "Cassiopeia"}, {"cen", "Centaurus"}, {"cep", "Cepheus"}, {"cet", "Cetus"},
{"cha", "Chamaeleon"}, {"cir", "Circinus"}, {"col", "Columba"}, {"com", "Coma Berenices"},
{"cra", "Corona Australis"}, {"crb", "Corona Borealis"}, {"crv", "Corvus"}, {"crt", "Crater"},
{"cru", "Crux"}, {"cyg", "Cygnus"}, {"del", "Delphinus"}, {"dor", "Dorado"}, {"dra", "Draco"},
{"equ", "Equuleus"}, {"eri", "Eridanus"}, {"for", "Fornax"}, {"gem", "Gemini"}, {"gru", "Grus"},
{"her", "Hercules"}, {"hor", "Horologium"}, {"hya", "Hydra"}, {"hyi", "Hydrus"}, {"ind", "Indus"},
{"lac", "Lacerta"}, {"leo", "Leo"}, {"lmi", "Leo Minor"}, {"lib", "Libra"}, {"lup", "Lupus"},
{"lyn", "Lynx"}, {"lyr", "Lyra"}, {"men", "Mensa"}, {"mic", "Microscopium"}, {"mon", "Monoceros"},
{"mus", "Musca"}, {"nor", "Norma"}, {"oct", "Octans"}, {"oph", "Ophiuchus"}, {"ori", "Orion"},
{"pav", "Pavo"}, {"peg", "Pegasus"}, {"per", "Perseus"}, {"phe", "Phoenix"}, {"pic", "Pictor"},
{"psc", "Pisces"}, {"psa", "Piscis Austrinus"}, {"pup", "Puppis"}, {"pyx", "Pyxis"}, {"ret", "Reticulum"},
{"sge", "Sagitta"}, {"sgr", "Sagittarius"},{"sco", "Scorpius"}, {"scl", "Sculptor"}, {"sct", "Scutum"},
{"ser", "Serpens"}, {"sex", "Sextans"}, {"tau", "Taurus"}, {"tel", "Telescopium"}, {"tri", "Triangulum"},
{"tra", "Triangulum Australe"}, {"tuc", "Tucana"}, {"uma", "Ursa Major"}, {"umi", "Ursa Minor"},
{"vel", "Vela"}, {"vir", "Virgo"}, {"vol", "Volans"}, {"vul", "Vulpecula"}
};
public string ConstellationFullName(string ConstellationAbreviation)
{
try
{
if (ConstellationAbreviation != null || ConstellationAbreviation != "")
{
return ConstellationMappings[ConstellationAbreviation.ToLower().Trim()];
}
}
catch (System.Collections.Generic.KeyNotFoundException)
{
return ConstellationAbreviation;
}
return "";
}
private Dictionary<string, string> APTypeMappings = new Dictionary<string, string>()
{
{"P Neb","Planetary Nebula"}, {"Open","Open Cluster"}, {"Open+D Neb","Open Cluster + Dark Nebula"},
{"Neb","Nebula"}, {"SNR","Supernova Remnant"}, {"D Neb","Dark Nebula"}, {"Open+Asterism","Open Cluster + Asterism"},
{"Dbl+Asterism","Double Star + Asterism"}, {"GalClus","Galaxy Cluster"}, {"E Neb","Emission Nebula"},
{"Mult","Multiple Star"}
};
public string DisplayTypeFromAPType(string ObjectType)
{
try
{
if (ObjectType != null || ObjectType != "")
{
return APTypeMappings[ObjectType];
}
}
catch (System.Collections.Generic.KeyNotFoundException)
{
return ObjectType;
}
return "";
}
public string RADecimalHoursToHMS(double RA, string format)
{
TimeSpan time = TimeSpan.FromHours(RA * 15 * 24 / 360);
return time.ToString(format);
}
public string DecDecimalToDMS(double Dec)
{
int degrees = Math.Abs((int)Dec);
double minutes = (Math.Abs((Dec)) - degrees) * 60;
double seconds = (minutes - (int)minutes) * 60;
string dms = $"{(Dec < 0 ? "-" : "")}{degrees}d{((int)minutes).ToString("D2")}m{seconds.ToString("0.00s")}";
return dms;
}
public string DecDecimalToDMSSp(double Dec)
{
int degrees = Math.Abs((int)Dec);
double minutes = (Math.Abs((Dec)) - degrees) * 60;
double seconds = (minutes - (int)minutes) * 60;
string dms = $"{(Dec < 0 ? "-" : "+")}{degrees} {((int)minutes).ToString("D2")} {seconds.ToString("0.00")}";
return dms;
}
public string TargetDisplay(APCmdObject apObj)
{
// How many characters of the objects name to display.
const int MaxDisplayLength = 50;
string sInfo = ""; string sName = "";
if (apObj != null)
{
// Add the object ID to the information string
sInfo = apObj.ID;
// Decide which name field to use
if ((apObj.Name.Length) > 0)
{
if (apObj.Name.Contains(","))
{
// The default name field often contains multiple synonyms seperated by commas.
// Check and only display 2 names at most.
string[] sNames = apObj.Name.Split(',');
// If the length of using two names exceeds maximum specifed then use first name only
if (sNames[0].Length + sNames[1].Length + 1 > MaxDisplayLength)
{
sName = sNames[0];
}
else
{
sName = sNames[0] + ", " + sNames[1];
}
}
else
{
sName = apObj.Name;
}
// Constrain the name's length to the required characters
if (sName.Length > MaxDisplayLength)
{
sName = sName.Substring(0, MaxDisplayLength);
}
sInfo += ", " + sName;
}
sInfo += " (";
// If a distance field exists then add to information
if (apObj.Distance.Length > 0 && apObj.Distance != "???")
{
sInfo += apObj.Distance + " - ";
}
// Get the Objects constellation (abbreviation) and lookup the full name
sInfo += ConstellationFullName(apObj.Constellation);
// Add object type information
if (apObj.Type.Length > 0)
{
sInfo += " - " + DisplayTypeFromAPType(apObj.Type) + ")";
}
else
{
sInfo += ")";
}
}
return sInfo;
}
public SizeInfo ObjectSize(string apSize)
{
SizeInfo sizeInfo = new SizeInfo();
sizeInfo.MajorAxis = 0; sizeInfo.MinorAxis = 0;
var Sizes = apSize.Split('x');
if (Sizes.Length == 2)
{
sizeInfo.MajorAxis = double.Parse(Sizes[0].Trim());
sizeInfo.MinorAxis = double.Parse(Sizes[1].Trim());
}
else
{
sizeInfo.MajorAxis = double.Parse(apSize.Trim());
sizeInfo.MinorAxis = sizeInfo.MajorAxis;
}
return sizeInfo;
}
public SizeInfoString ObjectSizeString(string apSize)
{
SizeInfoString sizeInfoString = new SizeInfoString();
sizeInfoString.MajorAxis = ""; sizeInfoString.MinorAxis = "";
if (apSize.Trim().Length > 0)
{
SizeInfo sizeInfo = ObjectSize(apSize);
if (sizeInfo.MajorAxis > 0)
{
sizeInfoString.MajorAxis = sizeInfo.MajorAxis.ToString();
sizeInfoString.MinorAxis = sizeInfo.MinorAxis.ToString();
}
}
return sizeInfoString;
}
}
}