-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstars.go
8080 lines (7174 loc) · 240 KB
/
stars.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
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// stars.go
// Copyright(c) 2022 Matt Pharr, licensed under the GNU Public License, Version 3.
// SPDX: GPL-3.0-only
// Main missing features:
// Altitude alerts
package main
import (
"fmt"
"runtime"
"slices"
"sort"
"strconv"
"strings"
"time"
"unicode"
"github.com/mmp/imgui-go/v4"
)
// IFR TRACON separation requirements
const LateralMinimum = 3
const VerticalMinimum = 1000
// STARS ∆ is character 0x80 in the font
const STARSTriangleCharacter = string(rune(0x80))
var (
STARSBackgroundColor = RGB{.2, .2, .2} // at 100 contrast
STARSListColor = RGB{.1, .9, .1}
STARSTextAlertColor = RGB{1, 0, 0}
STARSMapColor = RGB{.55, .55, .55}
STARSCompassColor = RGB{.55, .55, .55}
STARSRangeRingColor = RGB{.55, .55, .55}
STARSTrackBlockColor = RGB{0.12, 0.48, 1}
STARSTrackHistoryColors = [5]RGB{
RGB{.12, .31, .78},
RGB{.28, .28, .67},
RGB{.2, .2, .51},
RGB{.16, .16, .43},
RGB{.12, .12, .35},
}
STARSJRingConeColor = RGB{.5, .5, 1}
STARSTrackedAircraftColor = RGB{1, 1, 1}
STARSUntrackedAircraftColor = RGB{0, 1, 0}
STARSInboundPointOutColor = RGB{1, 1, 0}
STARSGhostColor = RGB{1, 1, 0}
STARSSelectedAircraftColor = RGB{0, 1, 1}
STARSATPAWarningColor = RGB{1, 1, 0}
STARSATPAAlertColor = RGB{1, .215, 0}
STARSDCBButtonColor = RGB{0, .4, 0}
STARSDCBActiveButtonColor = RGB{0, .8, 0}
STARSDCBTextColor = RGB{1, 1, 1}
STARSDCBTextSelectedColor = RGB{1, 1, 0}
STARSDCBDisabledButtonColor = RGB{.4, .4, .4}
STARSDCBDisabledTextColor = RGB{.8, .8, .8}
)
const NumSTARSPreferenceSets = 32
const NumSTARSMaps = 28
type STARSPane struct {
CurrentPreferenceSet STARSPreferenceSet
SelectedPreferenceSet int
PreferenceSets []STARSPreferenceSet
SystemMaps map[int]*STARSMap
weatherRadar WeatherRadar
systemFont [6]*Font
systemOutlineFont [6]*Font
dcbFont [3]*Font // 0, 1, 2 only
events *EventsSubscription
// All of the aircraft in the world, each with additional information
// carried along in an STARSAircraftState.
Aircraft map[string]*STARSAircraftState
AircraftToIndex map[string]int // for use in lists
IndexToAircraft map[int]string // map is sort of wasteful since it's dense, but...
// explicit JSON name to avoid errors during config deserialization for
// backwards compatibility, since this used to be a
// map[string]interface{}.
AutoTrackDepartures bool `json:"autotrack_departures"`
LockDisplay bool
AirspaceAwareness struct {
Interfacility bool
Intrafacility bool
}
// callsign -> controller id
InboundPointOuts map[string]string
OutboundPointOuts map[string]string
RejectedPointOuts map[string]interface{}
queryUnassociated *TransientMap[string, interface{}]
RangeBearingLines []STARSRangeBearingLine
MinSepAircraft [2]string
CAAircraft []CAAircraft
// For CRDA
ConvergingRunways []STARSConvergingRunways
// Various UI state
scopeClickHandler func(pw [2]float32, transforms ScopeTransformations) STARSCommandStatus
activeDCBMenu int
selectedPlaceButton string
dwellAircraft string
drawRouteAircraft string
commandMode CommandMode
multiFuncPrefix string
previewAreaOutput string
previewAreaInput string
HavePlayedSPCAlertSound map[string]interface{}
lastTrackUpdate time.Time
lastHistoryTrackUpdate time.Time
discardTracks bool
drawApproachAirspace bool
drawDepartureAirspace bool
// The start of a RBL--one click received, waiting for the second.
wipRBL *STARSRangeBearingLine
}
type STARSRangeBearingLine struct {
P [2]struct {
// If callsign is given, use that aircraft's position;
// otherwise we have a fixed position.
Loc Point2LL
Callsign string
}
}
func (rbl STARSRangeBearingLine) GetPoints(ctx *PaneContext, aircraft []*Aircraft, sp *STARSPane) (p0, p1 Point2LL) {
// Each line endpoint may be specified either by an aircraft's
// position or by a fixed position. We'll start with the fixed
// position and then override it if there's a valid *Aircraft.
p0, p1 = rbl.P[0].Loc, rbl.P[1].Loc
if ac := ctx.world.Aircraft[rbl.P[0].Callsign]; ac != nil {
state, ok := sp.Aircraft[ac.Callsign]
if ok && !state.LostTrack(ctx.world.CurrentTime()) && slices.Contains(aircraft, ac) {
p0 = state.TrackPosition()
}
}
if ac := ctx.world.Aircraft[rbl.P[1].Callsign]; ac != nil {
state, ok := sp.Aircraft[ac.Callsign]
if ok && !state.LostTrack(ctx.world.CurrentTime()) && slices.Contains(aircraft, ac) {
p1 = state.TrackPosition()
}
}
return
}
type CAAircraft struct {
Callsigns [2]string // sorted alphabetically
Acknowledged bool
}
type QuickLookPosition struct {
Callsign string
Id string
Plus bool
}
func (sp *STARSPane) parseQuickLookPositions(ctx *PaneContext, s string) ([]QuickLookPosition, string, error) {
var positions []QuickLookPosition
// per 6-94, this is "fun"
// - in general the string is a list of TCPs / sector ids.
// - each may have a plus at the end
// - if a single character id is entered, then we prepend the number for
// the current controller's sector id. in that case a space is required
// before the next one, if any
ids := strings.Fields(s)
for i, id := range ids {
plus := len(id) > 1 && id[len(id)-1] == '+'
id = strings.TrimRight(id, "+")
control := sp.lookupControllerForId(ctx, id, "")
if control == nil || control.FacilityIdentifier != "" || control.Callsign == ctx.world.Callsign {
return positions, strings.Join(ids[i:], " "), ErrSTARSCommandFormat
} else {
positions = append(positions, QuickLookPosition{
Callsign: control.Callsign,
Id: control.SectorId,
Plus: plus,
})
}
}
return positions, "", nil
}
type CRDAMode int
const (
CRDAModeStagger = iota
CRDAModeTie
)
// this is read-only, stored in STARSPane for convenience
type STARSConvergingRunways struct {
ConvergingRunways
ApproachRegions [2]*ApproachRegion
Airport string
Index int
}
type STARSDatablockFieldColors struct {
Start, End int
Color RGB
}
type STARSDatablockLine struct {
Text string
Colors []STARSDatablockFieldColors
}
func (s *STARSDatablockLine) RightJustify(n int) {
if n > len(s.Text) {
delta := n - len(s.Text)
s.Text = fmt.Sprintf("%*c", delta, ' ') + s.Text
// Keep the formatting aligned.
for i := range s.Colors {
s.Colors[i].Start += delta
s.Colors[i].End += delta
}
}
}
type STARSDatablock struct {
Lines [4]STARSDatablockLine
}
func (s *STARSDatablock) RightJustify(n int) {
for i := range s.Lines {
s.Lines[i].RightJustify(n)
}
}
func (s *STARSDatablock) Duplicate() STARSDatablock {
var sd STARSDatablock
for i := range s.Lines {
sd.Lines[i].Text = s.Lines[i].Text
sd.Lines[i].Colors = DuplicateSlice(s.Lines[i].Colors)
}
return sd
}
func (s *STARSDatablock) BoundText(font *Font) (int, int) {
text := ""
for i, l := range s.Lines {
text += l.Text
if i+1 < len(s.Lines) {
text += "\n"
}
}
return font.BoundText(text, 0)
}
func (s *STARSDatablock) DrawText(td *TextDrawBuilder, pt [2]float32, font *Font, baseColor RGB,
brightness STARSBrightness) {
style := TextStyle{
Font: font,
Color: brightness.ScaleRGB(baseColor),
LineSpacing: 0}
for _, line := range s.Lines {
haveFormatting := len(line.Colors) > 0
if haveFormatting {
p0 := pt // save starting point
// Gather spans of characters that have the same color
spanColor := baseColor
start, end := 0, 0
flush := func(newColor RGB) {
if end > start {
style := TextStyle{
Font: font,
Color: brightness.ScaleRGB(spanColor),
LineSpacing: 0}
pt = td.AddText(line.Text[start:end], pt, style)
start = end
}
spanColor = newColor
}
for ; end < len(line.Text); end++ {
if line.Text[end] == ' ' {
// let spaces ride regardless of style
continue
}
// Does this character have a new color?
chColor := baseColor
for _, format := range line.Colors {
if end >= format.Start && end < format.End {
chColor = format.Color
break
}
}
if !spanColor.Equals(chColor) {
flush(chColor)
}
}
flush(spanColor)
// newline from start so we maintain aligned columns.
pt = td.AddText("\n", p0, style)
} else {
pt = td.AddText(line.Text+"\n", pt, style)
}
}
}
type CRDARunwayState struct {
Enabled bool
LeaderLineDirection *CardinalOrdinalDirection // nil -> unset
DrawCourseLines bool
DrawQualificationRegion bool
}
// stores the per-preference set state for each STARSConvergingRunways
type CRDARunwayPairState struct {
Enabled bool
Mode CRDAMode
RunwayState [2]CRDARunwayState
}
func (c *STARSConvergingRunways) getRunwaysString() string {
return c.Runways[0] + "/" + c.Runways[1]
}
type CommandMode int
const (
CommandModeNone = iota
CommandModeInitiateControl
CommandModeTerminateControl
CommandModeHandOff
CommandModeVFRPlan
CommandModeMultiFunc
CommandModeFlightData
CommandModeCollisionAlert
CommandModeMin
CommandModeSavePrefAs
CommandModeMaps
CommandModeLDR
CommandModeRangeRings
CommandModeRange
CommandModeSiteMenu
)
const (
DCBMenuMain = iota
DCBMenuAux
DCBMenuMaps
DCBMenuBrite
DCBMenuCharSize
DCBMenuPref
DCBMenuSite
DCBMenuSSAFilter
DCBMenuGITextFilter
DCBMenuTPA
)
// DCBSpinner is an interface used to manage the various spinner types in
// the DCB menu. Since the various spinners generally have unique
// requirements and expectations about keyboard input, having this
// interface allows collecting all of that in the various implementations
// of the interface.
type DCBSpinner interface {
// Label returns the text that should be shown in the DCB button.
Label() string
// Equal returns true if the provided spinner controls the same value
// as this spinner.
Equals(other DCBSpinner) bool
// MouseWheel is called when the spinner is active and there is mouse
// wheel input; implementations should update the underlying value
// accordingly.
MouseWheel(delta int)
// KeyboardInput is called if the spinner is active and the user enters
// text and presses enter; implementations should update the underlying
// value accordingly.
KeyboardInput(text string) error
}
type STARSAircraftState struct {
// Independently of the track history, we store the most recent track
// from the sensor as well as the previous one. This gives us the
// freshest possible information for things like calculating headings,
// rates of altitude change, etc.
track RadarTrack
previousTrack RadarTrack
// Radar track history is maintained with a ring buffer where
// historyTracksIndex is the index of the next track to be written.
// (Thus, historyTracksIndex==0 implies that there are no tracks.)
// Changing to/from FUSED mode causes tracksIndex to be reset, thus
// discarding previous tracks.
historyTracks [10]RadarTrack
historyTracksIndex int
DatablockType DatablockType
FullLDB time.Time // If the LDB displays the groundspeed. When to stop
DisplayRequestedAltitude *bool // nil if unspecified
IsSelected bool // middle click
// Only drawn if non-zero
JRingRadius float32
ConeLength float32
DisplayTPASize *bool // unspecified->system default if nil
DisplayATPAMonitor *bool // unspecified->system default if nil
DisplayATPAWarnAlert *bool // unspecified->system default if nil
IntrailDistance float32
ATPAStatus ATPAStatus
MinimumMIT float32
ATPALeadAircraftCallsign string
POFlashingEndTime time.Time
// These are only set if a leader line direction was specified for this
// aircraft individually:
LeaderLineDirection *CardinalOrdinalDirection
GlobalLeaderLineDirection *CardinalOrdinalDirection
UseGlobalLeaderLine bool
Ghost struct {
PartialDatablock bool
State GhostState
}
displayPilotAltitude bool
pilotAltitude int
DisplayReportedBeacon bool // note: only for unassociated
DisplayPTL bool
DisableCAWarnings bool
MSAW bool // minimum safe altitude warning
DisableMSAW bool
InhibitMSAW bool // only applies if in an alert. clear when alert is over?
MSAWAcknowledged bool
FirstSeen time.Time
FirstRadarTrack time.Time
HaveEnteredAirspace bool
IdentEnd time.Time
OutboundHandoffAccepted bool
OutboundHandoffFlashEnd time.Time
// This is a little messy: we maintain maps from callsign->sector id
// for pointouts that track the global state of them. Here we track
// just inbound pointouts to the current controller so that the first
// click acks a point out but leaves it yellow and a second clears it
// entirely.
PointedOut bool
ForceQL bool
}
type ATPAStatus int
const (
ATPAStatusUnset = iota
ATPAStatusMonitor
ATPAStatusWarning
ATPAStatusAlert
)
type GhostState int
const (
GhostStateRegular = iota
GhostStateSuppressed
GhostStateForced
)
func (s *STARSAircraftState) TrackAltitude() int {
return s.track.Altitude
}
func (s *STARSAircraftState) TrackDeltaAltitude() int {
if s.previousTrack.Position.IsZero() {
// No previous track
return 0
}
return s.track.Altitude - s.previousTrack.Altitude
}
func (s *STARSAircraftState) TrackPosition() Point2LL {
return s.track.Position
}
func (s *STARSAircraftState) TrackGroundspeed() int {
return s.track.Groundspeed
}
func (s *STARSAircraftState) HaveHeading() bool {
return !s.previousTrack.Position.IsZero()
}
// Note that the vector returned by HeadingVector() is along the aircraft's
// extrapolated path. Thus, it includes the effect of wind. The returned
// vector is scaled so that it represents where it is expected to be one
// minute in the future.
func (s *STARSAircraftState) HeadingVector(nmPerLongitude, magneticVariation float32) Point2LL {
if !s.HaveHeading() {
return Point2LL{}
}
p0 := ll2nm(s.track.Position, nmPerLongitude)
p1 := ll2nm(s.previousTrack.Position, nmPerLongitude)
v := sub2ll(p0, p1)
v = normalize2f(v)
// v's length should be groundspeed / 60 nm.
v = scale2f(v, float32(s.TrackGroundspeed())/60) // hours to minutes
return nm2ll(v, nmPerLongitude)
}
func (s *STARSAircraftState) TrackHeading(nmPerLongitude float32) float32 {
if !s.HaveHeading() {
return 0
}
return headingp2ll(s.previousTrack.Position, s.track.Position, nmPerLongitude, 0)
}
func (s *STARSAircraftState) LostTrack(now time.Time) bool {
// Only return true if we have at least one valid track from the past
// but haven't heard from the aircraft recently.
return !s.track.Position.IsZero() && now.Sub(s.track.Time) > 30*time.Second
}
func (s *STARSAircraftState) Ident() bool {
return !s.IdentEnd.IsZero() && s.IdentEnd.After(time.Now())
}
type STARSMap struct {
Label string `json:"label"`
Group int `json:"group"` // 0 -> A, 1 -> B
Name string `json:"name"`
CommandBuffer CommandBuffer `json:"command_buffer"`
}
///////////////////////////////////////////////////////////////////////////
// STARSPreferenceSet
type STARSPreferenceSet struct {
Name string
DisplayDCB bool
DCBPosition int
Center Point2LL
Range float32
CurrentCenter Point2LL
OffCenter bool
RangeRingsCenter Point2LL
RangeRingRadius int
// TODO? cursor speed
CurrentATIS string
GIText [9]string
RadarTrackHistory int
// 4-94: 0.5s increments via trackball but 0.1s increments allowed if
// keyboard input.
RadarTrackHistoryRate float32
DisplayWeatherLevel [6]bool
// If empty, then then MULTI or FUSED mode, depending on
// FusedRadarMode. The custom JSON name is so we don't get errors
// parsing old configs, which stored this as an array...
RadarSiteSelected string `json:"RadarSiteSelectedName"`
FusedRadarMode bool
// For tracked by the user
LeaderLineDirection CardinalOrdinalDirection
LeaderLineLength int // 0-7
// For tracked by other controllers
ControllerLeaderLineDirections map[string]CardinalOrdinalDirection
// If not specified in ControllerLeaderLineDirections...
OtherControllerLeaderLineDirection *CardinalOrdinalDirection
// Only set if specified by the user (and not used currently...)
UnassociatedLeaderLineDirection *CardinalOrdinalDirection
AltitudeFilters struct {
Unassociated [2]int // low, high
Associated [2]int
}
QuickLookAll bool
QuickLookAllIsPlus bool
QuickLookPositions []QuickLookPosition
CRDA struct {
Disabled bool
// Has the same size and indexing as corresponding STARSPane
// STARSConvergingRunways
RunwayPairState []CRDARunwayPairState
ForceAllGhosts bool
}
DisplayLDBBeaconCodes bool // TODO: default?
SelectedBeaconCodes []string
// TODO: review--should some of the below not be in prefs but be in STARSPane?
// DisplayUncorrelatedTargets bool // NOT USED
DisableCAWarnings bool
DisableMSAW bool
OverflightFullDatablocks bool
AutomaticFDBOffset bool
DisplayTPASize bool
DisplayATPAInTrailDist bool `json:"DisplayATPAIntrailDist"`
DisplayATPAWarningAlertCones bool
DisplayATPAMonitorCones bool
VideoMapVisible map[string]interface{}
SystemMapVisible map[int]interface{}
PTLLength float32
PTLOwn, PTLAll bool
DisplayRequestedAltitude bool
DwellMode DwellMode
TopDownMode bool
GroundRangeMode bool
Bookmarks [10]struct {
Center Point2LL
Range float32
TopDownMode bool
}
Brightness struct {
DCB STARSBrightness
BackgroundContrast STARSBrightness
VideoGroupA STARSBrightness
VideoGroupB STARSBrightness
FullDatablocks STARSBrightness
Lists STARSBrightness
Positions STARSBrightness
LimitedDatablocks STARSBrightness
OtherTracks STARSBrightness
Lines STARSBrightness
RangeRings STARSBrightness
Compass STARSBrightness
BeaconSymbols STARSBrightness
PrimarySymbols STARSBrightness
History STARSBrightness
Weather STARSBrightness
WxContrast STARSBrightness
}
CharSize struct {
DCB int
Datablocks int
Lists int
Tools int
PositionSymbols int
}
PreviewAreaPosition [2]float32
SSAList struct {
Position [2]float32
Visible bool
Filter struct {
All bool
Time bool
Altimeter bool
Status bool
Radar bool
Codes bool
SpecialPurposeCodes bool
Range bool
PredictedTrackLines bool
AltitudeFilters bool
AirportWeather bool
QuickLookPositions bool
DisabledTerminal bool
ActiveCRDAPairs bool
Text struct {
Main bool
GI [9]bool
}
}
}
VFRList struct {
Position [2]float32
Visible bool
Lines int
}
TABList struct {
Position [2]float32
Visible bool
Lines int
}
AlertList struct {
Position [2]float32
Visible bool
Lines int
}
CoastList struct {
Position [2]float32
Visible bool
Lines int
}
SignOnList struct {
Position [2]float32
Visible bool
}
VideoMapsList struct {
Position [2]float32
Visible bool
Selection VideoMapsGroup
}
CRDAStatusList struct {
Position [2]float32
Visible bool
}
TowerLists [3]struct {
Position [2]float32
Visible bool
Lines int
}
}
type VideoMapsGroup int
const (
VideoMapsGroupGeo = iota
VideoMapsGroupSysProc
VideoMapsGroupCurrent
)
func (ps *STARSPreferenceSet) ResetCRDAState(rwys []STARSConvergingRunways) {
ps.CRDA.RunwayPairState = nil
state := CRDARunwayPairState{}
// The first runway is enabled by default
state.RunwayState[0].Enabled = true
for range rwys {
ps.CRDA.RunwayPairState = append(ps.CRDA.RunwayPairState, state)
}
}
type DwellMode int
const (
// Make 0 be "on" so zero-initialization gives "on"
DwellModeOn = iota
DwellModeLock
DwellModeOff
)
func (d DwellMode) String() string {
switch d {
case DwellModeOn:
return "ON"
case DwellModeLock:
return "LOCK"
case DwellModeOff:
return "OFF"
default:
return "unhandled DwellMode"
}
}
const (
DCBPositionTop = iota
DCBPositionLeft
DCBPositionRight
DCBPositionBottom
)
func (sp *STARSPane) MakePreferenceSet(name string, w *World) STARSPreferenceSet {
var ps STARSPreferenceSet
ps.Name = name
ps.DisplayDCB = true
ps.DCBPosition = DCBPositionTop
if w != nil {
ps.Center = w.Center
ps.Range = w.Range
} else {
ps.Center = Point2LL{73.475, 40.395} // JFK-ish
ps.Range = 50
}
ps.CurrentCenter = ps.Center
ps.RangeRingsCenter = ps.Center
ps.RangeRingRadius = 5
ps.RadarTrackHistory = 5
ps.RadarTrackHistoryRate = 4.5
ps.VideoMapVisible = make(map[string]interface{})
if w != nil && len(w.STARSMaps) > 0 {
ps.VideoMapVisible[w.STARSMaps[0].Name] = nil
}
ps.SystemMapVisible = make(map[int]interface{})
ps.FusedRadarMode = true
ps.LeaderLineDirection = North
ps.LeaderLineLength = 1
ps.AltitudeFilters.Unassociated = [2]int{100, 60000}
ps.AltitudeFilters.Associated = [2]int{100, 60000}
//ps.DisplayUncorrelatedTargets = true
ps.DisplayTPASize = true
ps.DisplayATPAWarningAlertCones = true
ps.PTLLength = 1
ps.Brightness.DCB = 60
ps.Brightness.BackgroundContrast = 0
ps.Brightness.VideoGroupA = 50
ps.Brightness.VideoGroupB = 40
ps.Brightness.FullDatablocks = 80
ps.Brightness.Lists = 80
ps.Brightness.Positions = 80
ps.Brightness.LimitedDatablocks = 80
ps.Brightness.OtherTracks = 80
ps.Brightness.Lines = 40
ps.Brightness.RangeRings = 20
ps.Brightness.Compass = 40
ps.Brightness.BeaconSymbols = 55
ps.Brightness.PrimarySymbols = 80
ps.Brightness.History = 60
ps.Brightness.Weather = 30
ps.Brightness.WxContrast = 30
for i := range ps.DisplayWeatherLevel {
ps.DisplayWeatherLevel[i] = true
}
ps.CharSize.DCB = 1
ps.CharSize.Datablocks = 1
ps.CharSize.Lists = 1
ps.CharSize.Tools = 1
ps.CharSize.PositionSymbols = 0
ps.PreviewAreaPosition = [2]float32{.05, .8}
ps.SSAList.Position = [2]float32{.05, .9}
ps.SSAList.Visible = true
ps.SSAList.Filter.All = true
ps.TABList.Position = [2]float32{.05, .65}
ps.TABList.Lines = 5
ps.TABList.Visible = true
ps.VFRList.Position = [2]float32{.05, .2}
ps.VFRList.Lines = 5
ps.VFRList.Visible = true
ps.AlertList.Position = [2]float32{.8, .25}
ps.AlertList.Lines = 5
ps.AlertList.Visible = true
ps.CoastList.Position = [2]float32{.8, .65}
ps.CoastList.Lines = 5
ps.CoastList.Visible = false
ps.SignOnList.Position = [2]float32{.8, .9}
ps.SignOnList.Visible = true
ps.VideoMapsList.Position = [2]float32{.85, .5}
ps.VideoMapsList.Visible = false
ps.CRDAStatusList.Position = [2]float32{.05, .7}
ps.TowerLists[0].Position = [2]float32{.05, .5}
ps.TowerLists[0].Lines = 5
ps.TowerLists[0].Visible = true
ps.TowerLists[1].Position = [2]float32{.05, .8}
ps.TowerLists[1].Lines = 5
ps.TowerLists[2].Position = [2]float32{.05, .9}
ps.TowerLists[2].Lines = 5
ps.ResetCRDAState(sp.ConvergingRunways)
return ps
}
func (ps *STARSPreferenceSet) Duplicate() STARSPreferenceSet {
dupe := *ps
dupe.SelectedBeaconCodes = DuplicateSlice(ps.SelectedBeaconCodes)
dupe.CRDA.RunwayPairState = DuplicateSlice(ps.CRDA.RunwayPairState)
dupe.VideoMapVisible = DuplicateMap(ps.VideoMapVisible)
dupe.SystemMapVisible = DuplicateMap(ps.SystemMapVisible)
return dupe
}
func (ps *STARSPreferenceSet) Activate(w *World) {
// It should only take integer values but it's a float32 and we
// previously didn't enforce this...
ps.Range = float32(int(ps.Range))
if ps.PTLAll { // both can't be set; we didn't enforce this previously...
ps.PTLOwn = false
}
if ps.RadarTrackHistoryRate == 0 {
ps.RadarTrackHistoryRate = 4.5 // upgrade from old
}
// Brightness goes in steps of 5 (similarly not enforced previously...)
remapBrightness := func(b *STARSBrightness) {
*b = (*b + 2) / 5 * 5
*b = clamp(*b, 0, 100)
}
remapBrightness(&ps.Brightness.DCB)
remapBrightness(&ps.Brightness.BackgroundContrast)
remapBrightness(&ps.Brightness.VideoGroupA)
remapBrightness(&ps.Brightness.VideoGroupB)
remapBrightness(&ps.Brightness.FullDatablocks)
remapBrightness(&ps.Brightness.Lists)
remapBrightness(&ps.Brightness.Positions)
remapBrightness(&ps.Brightness.LimitedDatablocks)
remapBrightness(&ps.Brightness.OtherTracks)
remapBrightness(&ps.Brightness.Lines)
remapBrightness(&ps.Brightness.RangeRings)
remapBrightness(&ps.Brightness.Compass)
remapBrightness(&ps.Brightness.BeaconSymbols)
remapBrightness(&ps.Brightness.PrimarySymbols)
remapBrightness(&ps.Brightness.History)
remapBrightness(&ps.Brightness.Weather)
remapBrightness(&ps.Brightness.WxContrast)
if ps.VideoMapVisible == nil {
ps.VideoMapVisible = make(map[string]interface{})
if w != nil && len(w.STARSMaps) > 0 {
ps.VideoMapVisible[w.STARSMaps[0].Name] = nil
}
}
if ps.SystemMapVisible == nil {
ps.SystemMapVisible = make(map[int]interface{})
}
}
///////////////////////////////////////////////////////////////////////////
// Utility types and methods
type DatablockType int
const (
PartialDatablock = iota
LimitedDatablock
FullDatablock
)
// In CRC, whenever a tracked aircraft is slewed, it displays the callsign, squawk, and assigned squawk
func slewAircaft(w *World, ac *Aircraft) string {
return fmt.Sprintf("%v %v %v", ac.Callsign, ac.Squawk, ac.AssignedSquawk)
}
// See STARS Operators Manual 5-184...
func (sp *STARSPane) flightPlanSTARS(w *World, ac *Aircraft) (string, error) {
fp := ac.FlightPlan
if fp == nil {
return "", ErrSTARSIllegalFlight
}