@@ -41,6 +41,8 @@ private void btn_calc_wind_Click(object sender, EventArgs e)
41
41
double windSpeed1 = Math . Ceiling ( double . Parse ( results . Item3 ) ) ;
42
42
double windSpeed2 = Math . Ceiling ( double . Parse ( results . Item6 ) ) ;
43
43
double MaxCrossWindAllowed = Settings . Default . MaxCrossWind ;
44
+ float HeadwindMultiplier ;
45
+ float CrosswindMultiplier ;
44
46
45
47
46
48
//Runway 1 data - runway Chosen by user
@@ -185,131 +187,117 @@ private void btn_calc_wind_Click(object sender, EventArgs e)
185
187
//The scale we are using is to divide the values by 3. This allows the values to be shown on the
186
188
//graphics screen.
187
189
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.
189
191
{
190
- if ( RunwayToUse ==
191
- txtbx_runway_heading
192
- . Text ) //used when you choose tailwind runway, app always wants headwind for takeoff.
192
+ if ( StarboardFlag )
193
193
{
194
- if ( StarboardFlag )
195
- {
196
- StarboardFlag = false ;
197
- }
198
- else
199
- {
200
- StarboardFlag = true ;
201
- }
194
+ StarboardFlag = false ;
202
195
}
196
+ else
197
+ {
198
+ StarboardFlag = true ;
199
+ }
200
+ }
203
201
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
+ }
207
217
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
+ }
213
240
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 ) ;
219
241
220
242
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 ) ) ;
226
250
}
227
251
else
228
252
{
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 ) ) ;
239
254
}
240
255
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 ) ;
242
259
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
245
265
{
246
- if ( crossWind1 == 0 )
266
+ if ( RunwayFlag )
247
267
{
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 ) ) ;
274
269
}
275
- else
270
+ else //wind exceeds aircraft max limits
276
271
{
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 ) ) ;
285
273
}
286
274
}
287
275
}
288
276
289
277
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 ,
291
279
Graphics myRunwayGraphic , string myRunwayNumber , Font myFont ,
292
280
Color myColor , int myCrossWindDataStringXCoOrd , int myCrossWindDataStringYCoOrd )
293
281
{
294
282
try
295
283
{
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 ) ) ;
299
285
300
286
//Specify the EndCap and StartCap for line we start with circle and end with arrowhead
301
287
myPen . EndCap = LineCap . ArrowAnchor ;
302
288
myPen . StartCap = LineCap . RoundAnchor ;
303
289
304
290
// 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
306
294
myRunwayGraphic . DrawString ( myRunwayNumber , myFont , new SolidBrush ( myColor ) ,
307
295
new Point ( myCrossWindDataStringXCoOrd , myCrossWindDataStringYCoOrd ) ) ;
308
296
return true ;
309
297
}
310
298
catch
311
299
{
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
313
301
MsgBox . Show ( "Something has gone wrong.\r Please check data and try again" , "Something is Wrong" ,
314
302
MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
315
303
return false ;
@@ -343,7 +331,11 @@ private void ResetCrosswindGraphics()
343
331
344
332
private bool DataCheck ( string myWindStrength , string myDirection , string myRunwayHeading )
345
333
{
346
- if ( myWindStrength == "0" ) myDirection = "0" ;
334
+ if ( myWindStrength == "0" )
335
+ {
336
+ txtbx_direction . Text = "360" ;
337
+ myDirection = "360" ;
338
+ }
347
339
348
340
//catch for incomplete data
349
341
if ( ( myWindStrength == "" ) || ( myDirection == "" ) || ( myRunwayHeading == "" ) )
@@ -353,7 +345,7 @@ private bool DataCheck(string myWindStrength, string myDirection, string myRunwa
353
345
return false ;
354
346
}
355
347
356
- //Check data is infact a doubles.
348
+ //Check data is in fact doubles.
357
349
if ( ! CheckData . IsItADouble ( myWindStrength ) )
358
350
{
359
351
@@ -379,21 +371,21 @@ private bool DataCheck(string myWindStrength, string myDirection, string myRunwa
379
371
MessageBoxIcon . Error ) ;
380
372
return false ;
381
373
}
382
- else if ( ( double . Parse ( myDirection ) < 10 ) || ( double . Parse ( myDirection ) > 360 ) )
374
+ else if ( ( double . Parse ( myDirection ) < 01 ) || ( double . Parse ( myDirection ) > 360 ) )
383
375
{
384
376
MsgBox . Show ( "Check Direction Data is a valid number (0 - 360)" , "Data out of scope" ,
385
377
MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
386
378
return false ;
387
379
}
388
380
else if ( ! CheckData . IsItADouble ( myRunwayHeading ) )
389
381
{
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 ,
391
383
MessageBoxIcon . Error ) ;
392
384
return false ;
393
385
}
394
- else if ( ( double . Parse ( myRunwayHeading ) < 0 ) || ( double . Parse ( myRunwayHeading ) > 36 ) )
386
+ else if ( ( double . Parse ( myRunwayHeading ) < 01 ) || ( double . Parse ( myRunwayHeading ) > 36 ) )
395
387
{
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 ,
397
389
MessageBoxIcon . Error ) ;
398
390
return false ;
399
391
}
0 commit comments