Skip to content

Commit 74ab1f5

Browse files
committed
A little more cleaning still more to do
1 parent b556338 commit 74ab1f5

File tree

1 file changed

+83
-91
lines changed

1 file changed

+83
-91
lines changed

myFlightInfo/CrossWind.cs

+83-91
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ private void btn_calc_wind_Click(object sender, EventArgs e)
4141
double windSpeed1 = Math.Ceiling(double.Parse(results.Item3));
4242
double windSpeed2 = Math.Ceiling(double.Parse(results.Item6));
4343
double MaxCrossWindAllowed = Settings.Default.MaxCrossWind;
44+
float HeadwindMultiplier;
45+
float CrosswindMultiplier;
4446

4547

4648
//Runway 1 data - runway Chosen by user
@@ -185,131 +187,117 @@ private void btn_calc_wind_Click(object sender, EventArgs e)
185187
//The scale we are using is to divide the values by 3. This allows the values to be shown on the
186188
//graphics screen.
187189

188-
using (Pen myPen = new Pen(Brushes.Yellow, 4f))
190+
if (RunwayToUse == txtbx_runway_heading.Text) //used when you choose tailwind runway, app always wants headwind for takeoff.
189191
{
190-
if (RunwayToUse ==
191-
txtbx_runway_heading
192-
.Text) //used when you choose tailwind runway, app always wants headwind for takeoff.
192+
if (StarboardFlag)
193193
{
194-
if (StarboardFlag)
195-
{
196-
StarboardFlag = false;
197-
}
198-
else
199-
{
200-
StarboardFlag = true;
201-
}
194+
StarboardFlag = false;
202195
}
196+
else
197+
{
198+
StarboardFlag = true;
199+
}
200+
}
203201

204-
//Specify the EndCap and StartCap for line we start with circle and end with arrowhead
205-
//myPen.EndCap = LineCap.ArrowAnchor;
206-
//myPen.StartCap = LineCap.RoundAnchor;
202+
if (crosswind3 == headwind)
203+
{
204+
CrosswindMultiplier = 1;
205+
HeadwindMultiplier = 1;
206+
}
207+
else if (crosswind3 > headwind)
208+
{
209+
CrosswindMultiplier = 2;
210+
HeadwindMultiplier = 1;
211+
}
212+
else
213+
{
214+
CrosswindMultiplier = 1;
215+
HeadwindMultiplier = 2;
216+
}
207217

208-
//Draw the arrows
209-
if (StarboardFlag)
210-
{
211-
//RunwayGraphic.DrawLine(myPen, 180, 20, 130, 20);
212-
RunwayGraphic.DrawLine(myPen, 180, 20, 180, 60);
218+
//Draw the crosswind and headwind arrows
219+
if (StarboardFlag) //starboard side
220+
{
221+
PaintWindComponent_kts(CrosswindMultiplier, 180, 20, 130, 20,
222+
RunwayGraphic, Math.Round(crosswind3, 0) + "kts", new Font("Arial", 12),
223+
Color.Yellow, 80, 10);
224+
225+
PaintWindComponent_kts(HeadwindMultiplier, 180, 20, 180, 60,
226+
RunwayGraphic, Math.Round(headwind, 0) + "kts", new Font("Arial", 12),
227+
Color.Yellow, 130, 65);
228+
229+
}
230+
else //port side
231+
{
232+
PaintWindComponent_kts(CrosswindMultiplier, 15, 20, 65, 20,
233+
RunwayGraphic, Math.Round(crosswind3, 0) + "kts", new Font("Arial", 12),
234+
Color.Yellow, 68, 10);
235+
236+
PaintWindComponent_kts(HeadwindMultiplier, 15, 20, 15, 60,
237+
RunwayGraphic, Math.Round(headwind, 0) + "kts", new Font("Arial", 12),
238+
Color.Yellow, 5, 65);
239+
}
213240

214-
using (Font myFont = new Font("Arial", 12))
215-
{
216-
PaintWindComponent_kts(180, 20, 130, 20,
217-
RunwayGraphic, Math.Round(crosswind3, 0) + "kts", myFont,
218-
Color.Yellow, 80, 10);
219241

220242

221-
//RunwayGraphic.DrawString(Math.Round(crosswind3, 0) + "kts", myFont,
222-
// new SolidBrush((Color)new ColorConverter().ConvertFrom("Yellow")), new Point(80, 10));
223-
//RunwayGraphic.DrawString(Math.Round(headwind, 0) + "kts", myFont,
224-
// new SolidBrush((Color)new ColorConverter().ConvertFrom("Yellow")), new Point(130, 65));
225-
}
243+
// Draw runway number
244+
if (crossWind1 == 0)
245+
{
246+
if (headwind == 0)
247+
{
248+
RunwayGraphic.DrawString(RunwayHeading1 + "/" + RunwayHeading2, new Font("Arial", 50), new SolidBrush(Color.White),
249+
new Point(0, 120));
226250
}
227251
else
228252
{
229-
RunwayGraphic.DrawLine(myPen, 15, 20, 65, 20);
230-
RunwayGraphic.DrawLine(myPen, 15, 20, 15, 60);
231-
232-
using (Font myFont = new Font("Arial", 12))
233-
{
234-
RunwayGraphic.DrawString(Math.Round(crosswind3, 0) + "kts", myFont,
235-
new SolidBrush((Color)new ColorConverter().ConvertFrom("Yellow")), new Point(68, 10));
236-
RunwayGraphic.DrawString(Math.Round(headwind, 0) + "kts", myFont,
237-
new SolidBrush((Color)new ColorConverter().ConvertFrom("Yellow")), new Point(5, 65));
238-
}
253+
RunwayGraphic.DrawString(RunwayToUse, new Font("Arial", 50), new SolidBrush(Color.White), new Point(40, 120));
239254
}
240255

241-
}
256+
PaintWindComponent_kts(HeadwindMultiplier, 180, 20, 130, 20,
257+
RunwayGraphic, Math.Round(headwind, 0) + "kts", new Font("Arial", 12),
258+
Color.Yellow, 160, 65);
242259

243-
// Draw runway number
244-
using (Font myFont = new Font("Arial", 60))
260+
PaintWindComponent_kts(HeadwindMultiplier, 180, 20, 180, 60,
261+
RunwayGraphic, Math.Round(headwind, 0) + "kts", new Font("Arial", 12),
262+
Color.Yellow, 160, 65);
263+
}
264+
else
245265
{
246-
if (crossWind1 == 0)
266+
if (RunwayFlag)
247267
{
248-
Font myFont2 = new Font("Arial", 50);
249-
250-
if (headwind == 0)
251-
{
252-
RunwayGraphic.DrawString(RunwayHeading1 + "/" + RunwayHeading2, myFont2, new SolidBrush(Color.White),
253-
new Point(0, 120));
254-
}
255-
else
256-
{
257-
RunwayGraphic.DrawString(RunwayToUse, myFont, new SolidBrush(Color.White), new Point(40, 120));
258-
}
259-
260-
using (Pen p = new Pen(Brushes.Yellow, 4f))
261-
{
262-
p.EndCap = LineCap.ArrowAnchor;
263-
p.StartCap = LineCap.RoundAnchor;
264-
265-
RunwayGraphic.DrawLine(p, 180, 20, 130, 20);
266-
RunwayGraphic.DrawLine(p, 180, 20, 180, 60);
267-
268-
using (Font myFont3 = new Font("Arial", 12))
269-
{
270-
RunwayGraphic.DrawString(Math.Ceiling(headwind) + "kts", myFont3,
271-
new SolidBrush((Color)new ColorConverter().ConvertFrom("Yellow")), new Point(160, 65));
272-
}
273-
}
268+
RunwayGraphic.DrawString(RunwayToUse, new Font("Arial", 50), new SolidBrush(Color.White), new Point(40, 120));
274269
}
275-
else
270+
else //wind exceeds aircraft max limits
276271
{
277-
if (RunwayFlag)
278-
{
279-
RunwayGraphic.DrawString(RunwayToUse, myFont, new SolidBrush(Color.White), new Point(40, 120));
280-
}
281-
else
282-
{
283-
RunwayGraphic.DrawString("X", myFont, new SolidBrush(Color.White), new Point(60, 120));
284-
}
272+
RunwayGraphic.DrawString("X", new Font("Arial", 50), new SolidBrush(Color.White), new Point(60, 120));
285273
}
286274
}
287275
}
288276

289277

290-
private bool PaintWindComponent_kts(int myCrossWindLineStartX,int myCrossWind, int myCrossWindLineEndX, int myCrossWindLineEndY,
278+
private bool PaintWindComponent_kts(double myLineWidthMultiplier, int myCrossWindLineStartX, int myCrossWindLineStartY, int myCrossWindLineEndX, int myCrossWindLineEndY,
291279
Graphics myRunwayGraphic, string myRunwayNumber, Font myFont,
292280
Color myColor, int myCrossWindDataStringXCoOrd, int myCrossWindDataStringYCoOrd)
293281
{
294282
try
295283
{
296-
float myLineWidth = 4f; //To Do convert into ratio for different wind speeds
297-
298-
Pen myPen = new Pen(new SolidBrush(myColor), myLineWidth);
284+
Pen myPen = new Pen(new SolidBrush(myColor), 4f * (float)(myLineWidthMultiplier));
299285

300286
//Specify the EndCap and StartCap for line we start with circle and end with arrowhead
301287
myPen.EndCap = LineCap.ArrowAnchor;
302288
myPen.StartCap = LineCap.RoundAnchor;
303289

304290
// Draw line and write in wind strength in knots
305-
myRunwayGraphic.DrawLine(myPen, 180, 20, 130, 20);
291+
myRunwayGraphic.DrawLine(myPen, myCrossWindLineStartX, myCrossWindLineStartY, myCrossWindLineEndX, myCrossWindLineEndY); //to do change to read in numbers
292+
293+
//Draw in runway number
306294
myRunwayGraphic.DrawString(myRunwayNumber, myFont, new SolidBrush(myColor),
307295
new Point(myCrossWindDataStringXCoOrd, myCrossWindDataStringYCoOrd));
308296
return true;
309297
}
310298
catch
311299
{
312-
//It did not work instead of crashing just put up hint and return
300+
//It did not work instead of crashing just put up hint and return gracefully
313301
MsgBox.Show("Something has gone wrong.\rPlease check data and try again", "Something is Wrong",
314302
MessageBoxButtons.OK, MessageBoxIcon.Error);
315303
return false;
@@ -343,7 +331,11 @@ private void ResetCrosswindGraphics()
343331

344332
private bool DataCheck(string myWindStrength, string myDirection, string myRunwayHeading)
345333
{
346-
if (myWindStrength == "0") myDirection = "0";
334+
if (myWindStrength == "0")
335+
{
336+
txtbx_direction.Text = "360";
337+
myDirection = "360";
338+
}
347339

348340
//catch for incomplete data
349341
if ((myWindStrength == "") || (myDirection == "") || (myRunwayHeading == ""))
@@ -353,7 +345,7 @@ private bool DataCheck(string myWindStrength, string myDirection, string myRunwa
353345
return false;
354346
}
355347

356-
//Check data is infact a doubles.
348+
//Check data is in fact doubles.
357349
if (!CheckData.IsItADouble(myWindStrength))
358350
{
359351

@@ -379,21 +371,21 @@ private bool DataCheck(string myWindStrength, string myDirection, string myRunwa
379371
MessageBoxIcon.Error);
380372
return false;
381373
}
382-
else if ((double.Parse(myDirection) < 10) || (double.Parse(myDirection) > 360))
374+
else if ((double.Parse(myDirection) < 01) || (double.Parse(myDirection) > 360))
383375
{
384376
MsgBox.Show("Check Direction Data is a valid number (0 - 360)", "Data out of scope",
385377
MessageBoxButtons.OK, MessageBoxIcon.Error);
386378
return false;
387379
}
388380
else if (!CheckData.IsItADouble(myRunwayHeading))
389381
{
390-
MsgBox.Show("Check Runway Heading is valid (0 - 36)", "Incorrect Data", MessageBoxButtons.OK,
382+
MsgBox.Show("Check Runway Heading is valid (01 - 36)", "Incorrect Data", MessageBoxButtons.OK,
391383
MessageBoxIcon.Error);
392384
return false;
393385
}
394-
else if ((double.Parse(myRunwayHeading) < 0) || (double.Parse(myRunwayHeading) > 36))
386+
else if ((double.Parse(myRunwayHeading) < 01) || (double.Parse(myRunwayHeading) > 36))
395387
{
396-
MsgBox.Show("Check Runway Heading is valid (0 - 36)", "Data out of scope", MessageBoxButtons.OK,
388+
MsgBox.Show("Check Runway Heading is valid (01 - 36)", "Data out of scope", MessageBoxButtons.OK,
397389
MessageBoxIcon.Error);
398390
return false;
399391
}

0 commit comments

Comments
 (0)