-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
911 lines (776 loc) · 28 KB
/
main.go
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
package main
import (
_ "embed"
"encoding/json"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/google/uuid"
"gonum.org/v1/plot/plotter"
"image"
_ "image/png"
"math"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)
//go:embed degrees_mills.png
var degreeMils []byte
//go:embed artillery.json
var artilleryJson []byte
//go:embed audio/splash_1.mp3
var splashSound1 []byte
//go:embed audio/splash_2.mp3
var splashSound2 []byte
//go:embed audio/solution_1.mp3
var solution1 []byte
//go:embed audio/solution_2.mp3
var solution2 []byte
//go:embed audio/splash_5_1.mp3
var splashInFive1 []byte
//go:embed audio/splash_5_2.mp3
var splashInFive2 []byte
const g float64 = 9.80665
const dragCoef float64 = -0.00006
const r2m float64 = 1018.591636
const addMarker = "/api/markers/add"
const deleteMarker = "/api/markers/delete"
var a fyne.App
var mute = false
var testAngle = 0.0
var muz = 0.0
var currentGunString string
var lastVectorPlotHigh plotter.XYs
var lastVectorPlotLow plotter.XYs
var habTacSync = false
type BallisticPoint struct {
X float64
Y float64
}
type Marker struct {
Lat string `json:"lat"`
Lng string `json:"lng"`
Elv string `json:"elv"`
Title string `json:"title"`
Unit string `json:"unit"`
Map string `json:"map"`
Comments string `json:"comments"`
Id string `json:"id"`
}
func GetLatestNumbers() Guns {
tempGuns := Guns{}
resp, err := http.Get("https://raw.githubusercontent.com/habitualdev/ArtyCalc/main/artillery.json")
if err != nil {
err = json.Unmarshal(artilleryJson, &tempGuns)
return tempGuns
}
defer resp.Body.Close()
buf := []byte{}
resp.Body.Read(buf)
err = json.Unmarshal(buf, &tempGuns)
if err != nil {
err = json.Unmarshal(artilleryJson, &tempGuns)
return tempGuns
}
return tempGuns
}
func GetLatestNumbersDrag() DragTable {
artyDrag := DragTable{}
resp, err := http.Get("https://raw.githubusercontent.com/habitualdev/ArtyCalc/main/drag.json")
if err != nil {
err = json.Unmarshal(dragTable, &artyDrag)
return artyDrag
}
defer resp.Body.Close()
buf := []byte{}
resp.Body.Read(buf)
err = json.Unmarshal(buf, &artyDrag)
if err != nil {
err = json.Unmarshal(dragTable, &artyDrag)
return artyDrag
}
return artyDrag
}
var sessionUuid = ""
func main() {
sessionUuid = uuid.New().String()
lastCalcMission := FireMission{}
var savedMissions FireMissions
airResistanceBool := false
guns := Guns{}
curGun := Gun{}
guns = GetLatestNumbers()
dragTableJson = GetLatestNumbersDrag()
a = app.New()
a.Settings().SetTheme(theme.DarkTheme())
w := a.NewWindow("CFF Calculator")
azimuthBoxGrid := widget.NewLabel("")
gunElevationPolar := widget.NewLabel("")
gunElevationGrid := widget.NewLabel("")
airResistance := widget.NewCheck("Air Resistance", func(checked bool) {
airResistanceBool = checked
})
muteButton := widget.NewButton("Toggle Sound", func() {
if mute {
mute = false
} else {
mute = true
}
})
habTacLogin := widget.NewCheck("HabTac Sync", func(checked bool) {
habTacSync = checked
})
timeOfFlight := widget.NewLabel("TOF: ")
azimuthBoxPolar := widget.NewEntry()
distancePolar := widget.NewEntry()
gunGrid := widget.NewEntry()
gunAltitude := widget.NewEntry()
targetGrid := widget.NewEntry()
targetAltitude := widget.NewEntry()
targetName := widget.NewEntry()
targetName.SetPlaceHolder("TRP Name")
saveMissionButtonGrid := widget.NewButton("SaveMission", func() {
lastCalcMission.Name = targetName.Text
savedMissions = append(savedMissions, lastCalcMission)
})
gunList := []string{}
for gun, _ := range guns {
gunList = append(gunList, gun)
}
curGunCharges := []string{}
for charge, _ := range curGun {
curGunCharges = append(curGunCharges, charge)
}
chargeSelection := widget.NewSelect(curGunCharges, nil)
gunSelection := widget.NewSelect(gunList, func(selectedGun string) {
curGun = guns[selectedGun]
currentGunString = selectedGun
curGunCharges = []string{}
for charge, _ := range curGun {
curGunCharges = append(curGunCharges, charge)
}
chargeSelection.Options = curGunCharges
})
gunSelectRow := container.NewHBox(gunSelection, chargeSelection, habTacLogin)
highAngleImage := canvas.NewImageFromImage(image.NewRGBA(image.Rect(0, 0, 100, 100)))
lowAngleImage := canvas.NewImageFromImage(image.NewRGBA(image.Rect(0, 0, 100, 100)))
calculateMissionGrid := widget.NewButton("Calculate Mission", func() {
dist, err := CalcDistance(gunGrid.Text, targetGrid.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
gunAlt, err := strconv.Atoi(gunAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
targetAlt, err := strconv.Atoi(targetAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
if curGun == nil {
a.SendNotification(fyne.NewNotification("Error", "No gun selected"))
return
}
if chargeSelection.Selected == "" {
a.SendNotification(fyne.NewNotification("Error", "No charge selected"))
return
}
highAngle, haTof := CalcAngleHigh(float64(gunAlt), float64(targetAlt), dist, curGun[chargeSelection.Selected], airResistanceBool)
lowAngle, laTof := CalcAngleLow(float64(gunAlt), float64(targetAlt), dist, curGun[chargeSelection.Selected], airResistanceBool)
switch airResistanceBool {
case false:
lowAngleGraph := GraphShotNoDrag(dist, lowAngle, curGun[chargeSelection.Selected], float64(gunAlt), float64(targetAlt), "Low Angle")
highAngleGraph := GraphShotNoDrag(dist, highAngle, curGun[chargeSelection.Selected], float64(gunAlt), float64(targetAlt), "High Angle")
highAngleImage.Image = highAngleGraph
lowAngleImage.Image = lowAngleGraph
highAngleImage.FillMode = canvas.ImageFillOriginal
lowAngleImage.FillMode = canvas.ImageFillOriginal
highAngleImage.Refresh()
lowAngleImage.Refresh()
case true:
lowAngleGraph := GraphShotDrag(lastVectorPlotLow, dist, "Low Angle")
highAngleGraph := GraphShotDrag(lastVectorPlotHigh, dist, "High Angle")
highAngleImage.Image = highAngleGraph
lowAngleImage.Image = lowAngleGraph
highAngleImage.FillMode = canvas.ImageFillOriginal
lowAngleImage.FillMode = canvas.ImageFillOriginal
highAngleImage.Refresh()
lowAngleImage.Refresh()
}
az, err := CalcAzimuth(gunGrid.Text, targetGrid.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
azimuthBoxGrid.Text = fmt.Sprintf("Gun Azimuth %f", az)
azimuthBoxGrid.Refresh()
gunElevationGrid.Text = fmt.Sprintf("High Angle: %d | Low Angle: %d", int(highAngle), int(lowAngle))
gunElevationGrid.Refresh()
lastCalcMission = FireMission{}
lastCalcMission.Type = 1
lastCalcMission.TargetGrid = targetGrid.Text
lastCalcMission.TargetAlt, err = strconv.Atoi(targetAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
timeOfFlight.SetText(fmt.Sprintf("HA: %f | LA: %f", haTof, laTof))
go Solution()
})
haTofButton := widget.NewButton("HA ToF Alarm", func() {
go func() {
splitTof := strings.Split(timeOfFlight.Text, "|")
ha := strings.Split(strings.ReplaceAll(splitTof[0], " ", ""), ":")[1]
haInt, err := strconv.Atoi(ha)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check if ToF is populated"))
return
}
if haInt > 5 {
haInt = haInt - 5
} else {
if !mute {
Splash()
}
return
}
time.Sleep(time.Duration(haInt) * time.Second)
if !mute {
Splash()
}
}()
})
laTofButton := widget.NewButton("LA ToF Alarm", func() {
go func() {
splitTof := strings.Split(timeOfFlight.Text, "|")
la := strings.Split(strings.ReplaceAll(splitTof[1], " ", ""), ":")[1]
laInt, err := strconv.Atoi(la)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check if ToF is populated"))
return
}
if laInt > 5 {
laInt = laInt - 5
} else {
if !mute {
Splash()
}
return
}
time.Sleep(time.Duration(laInt) * time.Second)
if !mute {
Splash()
}
}()
})
polarGridLabel := widget.NewLabel("")
calculateMissionPolar := widget.NewButton("Calculate Mission", func() {
dist, err := strconv.Atoi(distancePolar.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
gunAlt, err := strconv.Atoi(gunAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
targetAlt, err := strconv.Atoi(targetAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
if curGun == nil {
a.SendNotification(fyne.NewNotification("Error", "No gun selected"))
return
}
if chargeSelection.Selected == "" {
a.SendNotification(fyne.NewNotification("Error", "No charge selected"))
return
}
highAngle, haTof := CalcAngleHigh(float64(gunAlt), float64(targetAlt), float64(dist), curGun[chargeSelection.Selected], airResistanceBool)
lowAngle, laTof := CalcAngleLow(float64(gunAlt), float64(targetAlt), float64(dist), curGun[chargeSelection.Selected], airResistanceBool)
switch airResistanceBool {
case false:
lowAngleGraph := GraphShotNoDrag(float64(dist), lowAngle, curGun[chargeSelection.Selected], float64(gunAlt), float64(targetAlt), "Low Angle")
highAngleGraph := GraphShotNoDrag(float64(dist), highAngle, curGun[chargeSelection.Selected], float64(gunAlt), float64(targetAlt), "High Angle")
highAngleImage.Image = highAngleGraph
lowAngleImage.Image = lowAngleGraph
highAngleImage.FillMode = canvas.ImageFillOriginal
lowAngleImage.FillMode = canvas.ImageFillOriginal
highAngleImage.Refresh()
lowAngleImage.Refresh()
case true:
lowAngleGraph := GraphShotDrag(lastVectorPlotLow, float64(dist), "Low Angle")
highAngleGraph := GraphShotDrag(lastVectorPlotHigh, float64(dist), "High Angle")
highAngleImage.Image = highAngleGraph
lowAngleImage.Image = lowAngleGraph
highAngleImage.FillMode = canvas.ImageFillOriginal
lowAngleImage.FillMode = canvas.ImageFillOriginal
highAngleImage.Refresh()
lowAngleImage.Refresh()
}
gunElevationPolar.Text = fmt.Sprintf("High Angle: %f | Low Angle: %f", highAngle, lowAngle)
gunElevationPolar.Refresh()
polarGrid, _ := PolarToGrid(distancePolar.Text, azimuthBoxPolar.Text, gunGrid.Text)
polarGridLabel.SetText(polarGrid)
polarGridLabel.Refresh()
lastCalcMission = FireMission{}
lastCalcMission.Type = 0
lastCalcMission.TargetGrid = polarGrid
lastCalcMission.TargetAlt, err = strconv.Atoi(targetAltitude.Text)
timeOfFlight.SetText(fmt.Sprintf("HA: %f | LA: %f", haTof, laTof))
if !mute {
go Solution()
}
})
otlAngle := widget.NewEntry()
otlDirectionX := widget.NewSelect([]string{"Left", "Right"}, nil)
otlDirectionX.SetSelected("Left")
otlDirectionY := widget.NewSelect([]string{"Add", "Drop"}, nil)
otlDirectionY.SetSelected("Add")
otlDistanceY := widget.NewEntry()
otlDistanceX := widget.NewEntry()
otlAngle.PlaceHolder = "Observer to Target Line in MILS"
otlDistanceY.PlaceHolder = "Adjust add/drop distance"
otlDistanceX.PlaceHolder = "Adjust left/right distance"
otlCalc := widget.NewLabel("")
otlCalculate := widget.NewButton("Calculate OTL Adjust", func() {
otlDistYInt, err := strconv.Atoi(otlDistanceY.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your Add/Drop distance"))
return
}
otlDistXInt, err := strconv.Atoi(otlDistanceX.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your Left/Right distance"))
return
}
otlAngleInt, err := strconv.Atoi(otlAngle.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your Observer to target Angle"))
return
}
gunAltInt, err := strconv.Atoi(gunAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your Gun altitude"))
return
}
distance, _ := CalcDistance(gunGrid.Text, lastCalcMission.TargetGrid)
origAz, _ := CalcAzimuth(gunGrid.Text, lastCalcMission.TargetGrid)
otlCalc.SetText(OTLAdjust(float64(gunAltInt), float64(lastCalcMission.TargetAlt), distance, float64(otlDistYInt), float64(otlDistXInt),
float64(otlAngleInt), origAz, curGun[chargeSelection.Selected], otlDirectionY.Selected, otlDirectionX.Selected, airResistanceBool))
if !mute {
go Solution()
}
otlCalc.Refresh()
})
boxWidth := widget.NewEntry()
boxSpread := widget.NewEntry()
boxHeight := widget.NewEntry()
boxOrientation := widget.NewEntry()
boxWidth.PlaceHolder = "Width of Box"
boxHeight.PlaceHolder = "Height of Box"
boxSpread.PlaceHolder = "Distance between Shots"
boxOrientation.PlaceHolder = "Orientation of Box (Mils)"
boxCalculate := widget.NewButton("Calculate Box Sheaf", func() {
boxWidthInt, err := strconv.Atoi(boxWidth.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your box size"))
return
}
boxSpreadInt, err := strconv.Atoi(boxSpread.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your box spread"))
return
}
gunAltInt, err := strconv.Atoi(gunAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion distance"))
return
}
boxOrientationInt, err := strconv.Atoi(boxOrientation.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion distance"))
return
}
boxHeightInt, err := strconv.Atoi(boxHeight.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion distance"))
return
}
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion distance"))
return
}
shotsGrids := DrawARect(lastCalcMission.TargetGrid, float64(boxWidthInt), float64(boxHeightInt), float64(boxSpreadInt), float64(boxOrientationInt))
shots := []string{}
for _, shot := range shotsGrids[1:] {
boxAz, err := CalcAzimuth(gunGrid.Text, shot)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion distance"))
return
}
boxDist, err := CalcDistance(gunGrid.Text, shot)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion distance"))
return
}
highAngle, _ := CalcAngleHigh(float64(gunAltInt), float64(lastCalcMission.TargetAlt), boxDist, curGun[chargeSelection.Selected], airResistanceBool)
lowAngle, _ := CalcAngleLow(float64(gunAltInt), float64(lastCalcMission.TargetAlt), boxDist, curGun[chargeSelection.Selected], airResistanceBool)
shots = append(shots, fmt.Sprintf("%s - AZ: %d | HA: %d | LA: %d", shot, int(boxAz), int(highAngle), int(lowAngle)))
}
shotWindow := a.NewWindow("Box Sheaf")
closeButton := widget.NewButton("Close", func() {
shotWindow.Close()
})
shotWindow.SetContent(container.NewBorder(nil, closeButton, nil, nil,
widget.NewList(func() int {
return len(shots)
}, func() fyne.CanvasObject {
return widget.NewLabel("")
}, func(id widget.ListItemID, object fyne.CanvasObject) {
object.(*widget.Label).SetText(strconv.Itoa(id) + ": " + shots[id])
})))
shotWindow.Resize(fyne.Size{
Width: 500,
Height: 400,
})
go Solution()
shotWindow.Show()
})
linearCount := widget.NewEntry()
linearDispersion := widget.NewEntry()
linearDirection := widget.NewEntry()
linearCalculate := widget.NewButton("Calculate Linear Sheaf", func() {
shots := []string{}
shots = append(shots, "First shot is the original calculated point")
numShots, err := strconv.Atoi(linearCount.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your number of rounds"))
return
}
dispersion, err := strconv.Atoi(linearDispersion.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion distance"))
return
}
linearAz, err := strconv.Atoi(linearDirection.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion direction"))
return
}
gunAltInt, err := strconv.Atoi(gunAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", "Check your dispersion distance"))
return
}
distance, _ := CalcDistance(gunGrid.Text, lastCalcMission.TargetGrid)
origAz, _ := CalcAzimuth(gunGrid.Text, lastCalcMission.TargetGrid)
for i := 0; i <= numShots; i++ {
nextTarget := LinearSheaf(float64(gunAltInt), float64(lastCalcMission.TargetAlt), distance, float64(dispersion*i), float64(linearAz), origAz, curGun[chargeSelection.Selected], airResistanceBool)
shots = append(shots, nextTarget)
}
shotWindow := a.NewWindow("Linear Adjust/Sheaf")
closeButton := widget.NewButton("Close", func() {
shotWindow.Close()
})
shotWindow.SetContent(container.NewBorder(nil, closeButton, nil, nil,
widget.NewList(func() int {
return len(shots)
}, func() fyne.CanvasObject {
return widget.NewLabel("")
}, func(id widget.ListItemID, object fyne.CanvasObject) {
object.(*widget.Label).SetText(strconv.Itoa(id) + ": " + shots[id])
})))
shotWindow.Resize(fyne.Size{
Width: 500,
Height: 400,
})
go Solution()
shotWindow.Show()
})
linearCount.PlaceHolder = "Number of shots"
linearDispersion.PlaceHolder = "Dispersion of rounds"
linearDirection.PlaceHolder = "Direction of Shift"
adjustMissions := container.NewTabItem("Adjustments", container.NewVScroll(container.NewVBox(
widget.NewLabel("Observer to Target Adjusts"),
otlAngle,
otlDirectionY,
otlDistanceY,
otlDirectionX,
otlDistanceX,
otlCalc,
otlCalculate,
widget.NewSeparator(),
widget.NewLabel("Box Sheaf"),
boxWidth,
boxHeight,
boxSpread,
boxOrientation,
boxCalculate,
widget.NewSeparator(),
widget.NewLabel("Linear Sheafs"),
linearDirection,
linearDispersion,
linearCount,
linearCalculate,
)))
gridMission := container.NewTabItem("Grid Missions", container.NewVScroll(container.NewVBox(
widget.NewLabel("Gun Position"), gunGrid, widget.NewSeparator(),
widget.NewLabel("Gun Altitude"), gunAltitude, widget.NewSeparator(),
widget.NewLabel("Target Grid"), targetGrid, widget.NewSeparator(),
widget.NewLabel("Target Altitude"), targetAltitude, widget.NewSeparator(),
widget.NewLabel("Gun to Target Azimuth"), azimuthBoxGrid, widget.NewSeparator(),
widget.NewLabel("Gun Elevation"), gunElevationGrid, widget.NewSeparator(),
widget.NewLabel("Time Of Flight"), timeOfFlight, widget.NewSeparator(),
container.NewGridWithColumns(2, container.NewHBox(calculateMissionGrid, saveMissionButtonGrid, airResistance), targetName),
container.NewHScroll(container.NewHBox(highAngleImage, lowAngleImage)),
)))
polarMission := container.NewTabItem("Polar Mission", container.NewVScroll(container.NewVBox(
widget.NewLabel("Gun Position"), gunGrid, widget.NewSeparator(),
widget.NewLabel("Gun Altitude"), gunAltitude, widget.NewSeparator(),
widget.NewLabel("Gun to Target Azimuth"), azimuthBoxPolar, widget.NewSeparator(),
widget.NewLabel("Target Altitude"), targetAltitude, widget.NewSeparator(),
widget.NewLabel("Distance to Target"), distancePolar, widget.NewSeparator(),
widget.NewLabel("Gun Elevation"), gunElevationPolar, widget.NewSeparator(),
widget.NewLabel("Time Of Flight"), timeOfFlight, widget.NewSeparator(),
widget.NewLabel("Target Calculated Grid"), polarGridLabel, widget.NewSeparator(),
container.NewGridWithColumns(2, container.NewHBox(calculateMissionPolar, saveMissionButtonGrid, airResistance), targetName),
container.NewHScroll(container.NewHBox(highAngleImage, lowAngleImage)),
)))
savedMissionList := widget.NewList(
func() int {
return len(savedMissions)
}, func() fyne.CanvasObject {
return widget.NewLabel("")
}, func(id widget.ListItemID, object fyne.CanvasObject) {
object.(*widget.Label).SetText(fmt.Sprintf("%d", id) + ": " + savedMissions[id].Name)
})
deleteMission := widget.NewButton("Delete Mission", func() {
if len(savedMissions) == 0 {
return
}
popup := dialog.NewEntryDialog("Delete Mission", "Enter Mission Number", func(s string) {
missionInt, err := strconv.Atoi(s)
if err != nil {
return
}
savedMissions = savedMissions.Remove(missionInt)
savedMissionList.Refresh()
}, w)
popup.Show()
})
savedMissionsTab := container.NewTabItem("Saved Missions", container.NewBorder(nil, deleteMission, nil, nil, savedMissionList))
pressure := widget.NewEntry()
pressure.SetPlaceHolder("Air Pressure (hPA)")
temperature := widget.NewEntry()
temperature.SetPlaceHolder("Temperature (C)")
humidity := widget.NewEntry()
humidity.SetPlaceHolder("Humidity (%)")
airDensityBox := widget.NewLabel("")
airDensityCoefBox := widget.NewLabel("")
calcDensity := widget.NewButton("Calculate Air Density", func() {
pressureInt, _ := strconv.ParseFloat(pressure.Text, 64)
temperatureInt, _ := strconv.ParseFloat(temperature.Text, 64)
humidityInt, _ := strconv.ParseFloat(humidity.Text, 64)
humidityFloat := float64(humidityInt) / 100
pressureFloat := float64(pressureInt) * 100
sat := 610.78 * math.Pow(10, (7.5*temperatureInt)/(temperatureInt+237.3))
vap := humidityFloat * sat
partialPressure := pressureFloat - vap
airDensity := (partialPressure*0.028964 + vap*0.018016) / (8.314 * (temperatureInt + 273.15))
airDensityCoef := ((airDensity / 1.225) - 1) * 100
airDensityBox.SetText(fmt.Sprintf("%f kg/m³", airDensity))
airDensityBox.Refresh()
airDensityCoefBox.SetText(fmt.Sprintf("%f pct", airDensityCoef))
airDensityCoefBox.Refresh()
})
degreesToMilsCalcLabel := widget.NewLabel("")
degreesToMilsCalcEntry := widget.NewEntry()
degreesToMilsCalcEntry.SetPlaceHolder("Degrees")
degreesToMilsCalcButton := widget.NewButton("Calculate", func() {
degreesInt, err := strconv.Atoi(degreesToMilsCalcEntry.Text)
if err != nil {
return
}
mils := float64(degreesInt) * 17.777778
degreesToMilsCalcLabel.SetText(fmt.Sprintf("%f", mils))
degreesToMilsCalcLabel.Refresh()
})
degreesMilsImage := canvas.NewImageFromResource(fyne.NewStaticResource("degreesToMils", degreeMils))
degreesMilsImage.FillMode = canvas.ImageFillOriginal
observerPos := widget.NewEntry()
observerPos.SetPlaceHolder("Observer Position")
targetAz := widget.NewEntry()
targetAz.SetPlaceHolder("Target Azimuth")
targetDist := widget.NewEntry()
targetDist.SetPlaceHolder("Target Distance")
targetPos := widget.NewEntry()
targetPos.SetPlaceHolder("Target Position")
calculatePolar := widget.NewButton("Calculate Polar From Observer", func() {
targetPosCalc, err := PolarToGrid(targetDist.Text, targetAz.Text, observerPos.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
targetPos.SetText(targetPosCalc)
targetPos.Refresh()
})
habTacUrl := widget.NewEntry()
habTacUrl.SetPlaceHolder("HabTac URL")
habTacSession := widget.NewEntry()
habTacSession.SetPlaceHolder("HabTac Session")
habTacGunName := widget.NewEntry()
habTacGunName.SetPlaceHolder("HabTac Gun Name")
go func() {
for {
if habTacSync {
habTacGunName.Disable()
gunGrid.Disable()
if habTacUrl.Text == "" || habTacSession.Text == "" {
habTacLogin.SetChecked(false)
continue
}
_, err2 := url.Parse(habTacUrl.Text)
if err2 != nil {
habTacLogin.SetChecked(false)
continue
}
if gunGrid.Text != "" {
_, err := http.Get(habTacUrl.Text + deleteMarker + "?session=" + habTacSession.Text + "&title=" + habTacGunName.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
continue
}
northing := ""
easting := ""
switch len(gunGrid.Text) {
case 6:
northing = gunGrid.Text[:3] + "00"
easting = gunGrid.Text[3:] + "00"
case 8:
northing = gunGrid.Text[:4] + "0"
easting = gunGrid.Text[4:] + "0"
case 10:
northing = gunGrid.Text[:5]
easting = gunGrid.Text[5:]
}
reqForm := url.Values{
"lat": {easting},
"lng": {northing},
"elv": {gunAltitude.Text},
"title": {habTacGunName.Text},
"unit": {"savage"},
"comments": {gunSelection.Selected},
"session": {habTacSession.Text},
"id": {sessionUuid},
}
_, err = http.PostForm(habTacUrl.Text+addMarker, reqForm)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
continue
}
}
totalUrl := habTacUrl.Text + "/api/markers?session=" + habTacSession.Text
resp, err := http.Get(totalUrl)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
continue
}
markers := []Marker{}
err = json.NewDecoder(resp.Body).Decode(&markers)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
continue
}
savedMissions = []FireMission{}
for _, marker := range markers {
if marker.Unit != "fm" {
continue
}
elvConversion, err := strconv.Atoi(marker.Elv)
if err != nil {
continue
}
savedMissions = append(savedMissions, FireMission{
Name: marker.Title,
TargetGrid: marker.Lng + marker.Lat,
TargetAlt: elvConversion,
Type: 1,
})
}
} else {
habTacGunName.Enable()
gunGrid.Enable()
}
savedMissionList.Refresh()
time.Sleep(1 * time.Second)
}
}()
utilityTab := container.NewTabItem("Utilities", container.NewVScroll(container.NewVBox(widget.NewLabel("Polar from Observer Grid Calculator"),
observerPos, targetAz, targetDist, calculatePolar, targetPos, widget.NewLabel("Air Density Calculator"),
pressure, temperature, humidity, airDensityBox, airDensityCoefBox, calcDensity, widget.NewSeparator(),
degreesMilsImage, widget.NewSeparator(), widget.NewLabel("Degrees to Mils Conversions"), degreesToMilsCalcEntry,
degreesToMilsCalcLabel, degreesToMilsCalcButton, widget.NewSeparator(), widget.NewLabel("HabTac Sync"),
habTacUrl, habTacSession, habTacGunName, habTacLogin, widget.NewSeparator(), widget.NewLabel("Mute Audio"), muteButton)))
infoTab := container.NewTabItemWithIcon("Info", theme.ListIcon(), container.NewVBox(
widget.NewLabel("Thanks to the following people:"),
widget.NewLabel("Gens - For his original spreadsheet"),
widget.NewLabel("Cashton - For the audio lines"),
muteButton,
))
missionTabs := container.NewAppTabs(gridMission, polarMission, adjustMissions, savedMissionsTab, utilityTab, infoTab)
savedMissionList.OnSelected = func(id widget.ListItemID) {
missionTabs.SelectIndex(0)
targetGrid.SetText(savedMissions[id].TargetGrid)
targetAltitude.SetText(strconv.Itoa(savedMissions[id].TargetAlt))
targetAltitude.Refresh()
targetGrid.Refresh()
gunAlt, err := strconv.Atoi(gunAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
distanceRecalc, err := CalcDistance(gunGrid.Text, savedMissions[id].TargetGrid)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
highAngle, _ := CalcAngleHigh(float64(gunAlt), float64(savedMissions[id].TargetAlt), distanceRecalc, curGun[chargeSelection.Selected], airResistanceBool)
lowAngle, _ := CalcAngleLow(float64(gunAlt), float64(savedMissions[id].TargetAlt), distanceRecalc, curGun[chargeSelection.Selected], airResistanceBool)
az, err := CalcAzimuth(gunGrid.Text, targetGrid.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
azimuthBoxGrid.Text = fmt.Sprintf("Gun Azimuth %f", az)
azimuthBoxGrid.Refresh()
gunElevationGrid.Text = fmt.Sprintf("High Angle: %d | Low Angle: %d", int(highAngle), int(lowAngle))
gunElevationGrid.Refresh()
lastCalcMission = FireMission{}
lastCalcMission.Type = 1
lastCalcMission.TargetGrid = targetGrid.Text
lastCalcMission.TargetAlt, err = strconv.Atoi(targetAltitude.Text)
if err != nil {
a.SendNotification(fyne.NewNotification("Error", err.Error()))
return
}
go Solution()
savedMissionList.UnselectAll()
}
gunSelectRow.Add(haTofButton)
gunSelectRow.Add(laTofButton)
w.SetContent(container.NewBorder(gunSelectRow, nil, nil, nil, missionTabs))
w.ShowAndRun()
}