-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintscDrawArea.java
More file actions
executable file
·6265 lines (5851 loc) · 331 KB
/
intscDrawArea.java
File metadata and controls
executable file
·6265 lines (5851 loc) · 331 KB
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
/*
* intscDrawArea.java
* Intersection geometry design design class.
*
* Created on May 21, 2006, 4:12 PM
*/
/**
* @author Chen-Fu Liao
* Sr. Systems Engineer
* ITS Institute, ITS Laboratory
* Center For Transportation Studies
* University of Minnesota
* 200 Transportation and Safety Building
* 511 Washington Ave. SE
* Minneapolis, MN 55455
*/
import java.awt.*;
import java.applet.* ;
import java.awt.event.* ;
import java.awt.image.* ;
import java.awt.print.* ;
import java.net.URL ;
import java.io.* ;
import java.io.FilenameFilter ;
import javax.swing.* ;
import java.util.* ;
import javax.imageio.* ;
import java.text.DecimalFormat ;
import javax.swing.table.* ;
public class intscDrawArea extends DoubleBufferedPanel
implements MouseListener, MouseMotionListener
{
final int stepSignalTimeState_BUF_SIZE = 300 ; // 5 minutes
private stepSignalTimeState[] SavedSignalTime = new stepSignalTimeState[stepSignalTimeState_BUF_SIZE] ;
private int savedSignalTime_steps = 0 ;
private int savedSignalTime_ptr = 0 ;
private boolean restoreLastSignalTiming_flag = false ;
//private String statusBarMessage = "" ;
private static Font monoFont = new Font("Monospaced", Font.BOLD, 14) ;
private static Font sanSerifFont = new Font("SanSerif", Font.BOLD | Font.PLAIN, 14) ;
private static Font serifFont = new Font("Serif", Font.BOLD, 14) ;
private static Font dialogFontB14 = new Font("Dialog", Font.BOLD | Font.PLAIN, 14) ;
private static Font dialogFontB12 = new Font("Dialog", Font.BOLD | Font.PLAIN, 12) ;
private static Font dialogFont = new Font("Dialog", Font.PLAIN, 12) ;
toolbar tb; // toolbar
statusbar sb; // status bar
final int grid = 8; // drawarea grid size
final int link_length = 300 ; // pixel
final int MAX_VEH_SIZE = 40 ; // max vehicles at a link
final int STOPBAR_WIDTH = 20 ; // stop bar width in pixel
final int DET_PERIOD = 100 ; // 50 ms
private final int KEY_CLEAR = 77 ; // Controller clear key
private DecimalFormat twoPlaces = new DecimalFormat("00"); // changed from "00.00" 8/20/07
// approach vs pahse assignment, assume N-S main street, 8 phases
// ***** DO NOT CHANGE THE PHASE ASSIGNMENT TO INTERSECTION GEOMETRY *****
// N-S MAIN
final int[] NS_LEFT_ASSIGN_PH = {7,3,5,1} ; // E, W, N, S, left turn
final int[] NS_THRU_ASSIGN_PH = {4,8,2,6} ; // E, W, N, S, thru
// E-W MAIN
final int[] EW_LEFT_ASSIGN_PH = {5,1,3,7} ; // E, W, N, S, left turn
final int[] EW_THRU_ASSIGN_PH = {2,6,8,4} ; // E, W, N, S, thru
// ***** DO NOT CHANGE THE PHASE ASSIGNMENT TO INTERSECTION GEOMETRY *****
private int[] LEFT_ASSIGN_PH = new int[4]; // E, W, N, S, left turn
private int[] THRU_ASSIGN_PH = new int[4]; // E, W, N, S, thru
//vDrawArea vDesign = new vDrawArea();
Applet myApplet ; // applet pointer from parent, Geometry_Design
// variables here
public SHARED myDB = new SHARED();
// public Actuated_Control actuatedScreen = new Actuated_Control();
int toolbarIndex = 0 ;
mPoint e0, e1 ; //= DBNull
boolean line_started = false ;
boolean curve_started = false ;
boolean modification_started = false ;
public Image image ;
public int imageW = 0, imageH=0 ;
//Graphics g ;
mPoint translate = new mPoint(0, 0);
mPoint scaledxlate = new mPoint(0, 0);
mPoint translate_delta = new mPoint(0, 0);
mPoint scaledxlate_delta = new mPoint(0, 0);
boolean mouseHoldDown = false ;
float draw_scale = 1.0f ;
int dataSelIndex = -1 ;
public boolean controller_configured = false ;
// Horizontal geometry DB
static final int NUM_LINK = 4 ; // num of links
static final int INTSC_SIZE = 1 ;
// other variables
int myAlpha = 255 ; // declare a Alpha variable
// intersectin deometry info
int intsc_left, intsc_right, intsc_top, intsc_bottom ;
int intsc_width, intsc_height ;
Point center ;
private float [][][] traffic_demand ; // [intsc id][approach id][demand + turning %]
routeDB[] route_NB ; // NB route DB
routeDB[] route_SB ; // SB route DB
routeDB[] route_EB ; // EB route DB
routeDB[] route_WB ; // WB route DB
float[] vHeadway = new float[4] ; // E, W, N, S, duration (sec) per vehicle
float[] timeElapsed = new float[4] ;
long tLast = 0 ; // last system time, thread2, vehicle generation
long tLast1 = 0 ; // system time for thread3, vehicle collision avoidance
int[] veh_index = new int[4] ; // generated vehicle index
int veh_ref_index = 0 ;
Random random = new Random(CInt(Math.IEEEremainder(System.currentTimeMillis(), 1967))) ;
int[] _lane_size = new int[4] ;
float[] _speed_limit = new float[4] ;
public float myGlobalTime = 0f ;
// vehciles
//Vehicle2D myCar ;
Vehicle2D[][] myVehicles = new Vehicle2D[4][MAX_VEH_SIZE] ; // 4 links, 40 vehicles max in each approach
VehPointer[] myVehRef = new VehPointer[4*MAX_VEH_SIZE] ;
// signal timing control algorithm
SignalTiming mySignalControl = new SignalTiming() ;
// N-S MAIN
//TimingPanel timeEB = new TimingPanel("EB Timing", "7", "4") ;
//TimingPanel timeWB = new TimingPanel("WB Timing", "3", "8") ;
//TimingPanel timeNB = new TimingPanel("NB Timing", "5", "2") ;
//TimingPanel timeSB = new TimingPanel("SB Timing", "1", "6") ;
// E-W MAIN
//TimingPanel timeEB = new TimingPanel("EB Timing", "5", "2") ;
//TimingPanel timeWB = new TimingPanel("WB Timing", "1", "6") ;
//TimingPanel timeNB = new TimingPanel("NB Timing", "3", "8") ;
//TimingPanel timeSB = new TimingPanel("SB Timing", "7", "4") ;
TimingPanel timeEB ;
TimingPanel timeWB ;
TimingPanel timeNB ;
TimingPanel timeSB ;
LTPanel leftturn_EB = new LTPanel("EB Left Turn") ;
LTPanel leftturn_WB = new LTPanel("WB Left Turn") ;
LTPanel leftturn_NB = new LTPanel("NB Left Turn") ;
LTPanel leftturn_SB = new LTPanel("SB Left Turn") ;
// window frame =================
//public myWindow frameParent = new myWindow();
myWindow frmAbout ;
myWindow frame_msgbox, frame_msgboxYesNo ;
myWindow frame_demand = new myWindow("Intersection Traffic Demand") ; // volume & turning setting screen
myWindow frame_controlType = new myWindow("Control Type") ; // select control type
myWindow frame_globalTime = new myWindow("Global Time") ; // set global time
myWindow frame_jumpTime = new myWindow("Jump Back to Time") ; // set global time
myWindow frame_timing = new myWindow("Intersection Signal Timing") ; // signal timing plan window
myWindow frame_controller = new myWindow("Intersection Signal Controller") ; // signal controller
JFrame frmSignalTimingTable = new JFrame("View Signal Timing Data") ;
private JTable stationTable = new JTable();
Image myControllerImage = null ;
Image myPhaseAssgn = null ;
imageCanvas controlPanel = null ;
private Color LCD_BG_COLOR = new Color(207, 216, 35) ; // LCD screen background color
private int NUM_LCD_PAGES ;
private int NUM_LCD_FORMATS ;
private LCD_PAGE[] myLCD_PAGES = new LCD_PAGE[164] ; // 162 pages
private LCD_DATA_ENTRY[] myLCD_Formats = new LCD_DATA_ENTRY[100] ;
private int lcd_page_index = 0 ;
private int lcd_row_index = 0 ;
private int lcd_col_index = 0 ;
private int lcd_page_ID = 389 ; // LCD page ID, starting page
private int lcd_page_ID_last = 0 ; // LCD last page ID
private int lcd_menu_layer = 0 ;
private int lcd_num_key = -99 ; // LCD numerical key
private boolean data_entry_mode = false ; // LCD data entry mode or option select mode
private boolean next_screen_sel = false ; // next screen key is pressed
private boolean next_page_sel = false ; // next page key is pressed
private int old_page_index = -1 ;
private int blink_flag = -1 ; // blinking toggle flag
private boolean LCD_READY = false ;
//private int paint_refresh = 0 ; // paint refresh
// ============================
PrintUtilities hd_pu, vd_pu ;
// Java GUI
Stroke myDashStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float [] {9}, 0) ;
Stroke myLineStroke = new BasicStroke(1) ;
TextField [] txt_demand = new TextField[NUM_LINK] ;
TextField [] txt_turnL = new TextField[NUM_LINK] ;
TextField [] txt_turnT = new TextField[NUM_LINK] ;
TextField [] txt_turnR = new TextField[NUM_LINK] ;
Label [] lbl_turnTotal = new Label[NUM_LINK] ;
Runnable cursorThread = null ; // cursor blinking thread, 1/9/07 added
Runnable runThreadToolbar = null ; // runs toolbar newstatus(0,xx)
Runnable runThreadRepaint = null ; // draw area repaint
Runnable runThreadVehGen = null ; // vehicle generation
Runnable runThreadVehSim = null ; // collisin avoidance & simulation
Runnable runThreadSignalControl = null ; // run signal controller
Runnable runThreadNBdet = null ; // NB detection
Runnable runThreadSBdet = null ; // SB detection
Runnable runThreadEBdet = null ; // EB detection
Runnable runThreadWBdet = null ; // WB detection
//Runnable runThreadSTP_NB = null ; // stop on red light
//Runnable runThreadSTP_SB = null ; // stop on red light
//Runnable runThreadSTP_EB = null ; // stop on red light
//Runnable runThreadSTP_WB = null ; // stop on red light
private Runnable runThread_gTimer ;
private Thread t_gTimer ;
private Runnable runThread_simStep ;
private Thread t_simStep ;
public Thread tCursor ; // cursor thread, 1/9/07
public Thread tSetVol ;
public Thread tSetTiming ;
public Thread tRepaint ; // draw area refresh
public Thread tGenVeh ; // vehicle generation thread
public Thread tVehicleSim ; // vehicle simulation & collision avoidance thread
public Thread tDetectionNB ; // detector thread
public Thread tDetectionSB ; // detector thread
public Thread tDetectionEB ; // detector thread
public Thread tDetectionWB ; // detector thread
//public Thread tStopOnRedNB ; // stop on red light
//public Thread tStopOnRedSB ; // stop on red light
//public Thread tStopOnRedEB ; // stop on red light
//public Thread tStopOnRedWB ; // stop on red light
public boolean SetVol_flag = false ;
public boolean SetActuationType_flag = false ;
public boolean SetTiming_flag = false ;
public boolean msgBox_flag = false ;
private String msgBox_title = "" ;
private String msgBox_body = "" ;
boolean sim_flag = false ; // simulation flag, true when running simulation
boolean sim_step_toolbar = false ; // step simulation used in new_status toolbar
public boolean sim_step_once = false ; // flag use to run simStep Thread once, 3/16/07
boolean sim_alreadyStarted = false ;
Random rdm = new Random(1) ; // a random class
Checkbox fixed, actuated, actuated_m ; // actuationi type checkbox
TextField txt_gTime ;
//PageFormat printPageFormat = new PageFormat() ;
//private String msg_title = "" ;
//private String msg_body = "" ;
//private boolean msg_flag = false ;
//==================================================================
// class initialization
intscDrawArea()
{ // initialization code here...
// included in init sub routine
}
intscDrawArea(toolbar t, statusbar s)
{
tb = t;
sb = s;
setBackground(Color.lightGray);
t.parent = this;
s.parent = this;
}
// object initialization
public void init() {
addMouseListener(this);
addMouseMotionListener(this);
mySignalControl.sb = sb ;
if (myDB.mainStreetNS) {
// NS main street
LEFT_ASSIGN_PH = NS_LEFT_ASSIGN_PH ;
THRU_ASSIGN_PH = NS_THRU_ASSIGN_PH ;
timeEB = new TimingPanel("EB Timing", "7", "4") ;
timeWB = new TimingPanel("WB Timing", "3", "8") ;
timeNB = new TimingPanel("NB Timing", "5", "2") ;
timeSB = new TimingPanel("SB Timing", "1", "6") ;
} else {
// EW maiin street
LEFT_ASSIGN_PH = EW_LEFT_ASSIGN_PH ;
THRU_ASSIGN_PH = EW_THRU_ASSIGN_PH ;
timeEB = new TimingPanel("EB Timing", "5", "2") ;
timeWB = new TimingPanel("WB Timing", "1", "6") ;
timeNB = new TimingPanel("NB Timing", "3", "8") ;
timeSB = new TimingPanel("SB Timing", "7", "4") ;
}
frmAbout = new myWindow();
//mySignalControl.setRing1Seq(1,2,3,4) ; // ring 1 phase sequence
//mySignalControl.setRing2Seq(5,6,7,8) ; // ring 2 phase sequence
// =======================================================================
// process intersection geometry layout
// =======================================================================
Rectangle r = new Rectangle(800, 530) ; // frmGeometryDesign.setSize(800, 600) ;
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
intsc_width = (myDB.NB_data.getLaneSize()+1)*myDB.LANE_WIDTH ;
} else {
intsc_width = myDB.NB_data.getLaneSize()*myDB.LANE_WIDTH ;
}
if (myDB.EB_data.leftTurnLaneExists() | myDB.WB_data.leftTurnLaneExists()) {
intsc_height = (myDB.EB_data.getLaneSize()+1)*myDB.LANE_WIDTH ;
} else {
intsc_height = myDB.EB_data.getLaneSize()*myDB.LANE_WIDTH ;
}
intsc_left = (r.width-intsc_width)/2 ;
intsc_right = intsc_left+intsc_width ;
intsc_top = (r.height-intsc_height)/2 ;
intsc_bottom = intsc_top+intsc_height ;
int intsc_centerX = (intsc_left+intsc_right)/2 ;
int intsc_centerY = (intsc_top+intsc_bottom)/2 ;
center = new Point((intsc_left+intsc_right)/2,(intsc_top+intsc_bottom)/2) ;
// =======================================================================
// intersection stopbar locations
// =======================================================================
myDB.EB_data.stopbar_UL = new Point(intsc_left-STOPBAR_WIDTH, intsc_centerY) ;
myDB.EB_data.stopbar_LR = new Point(intsc_left, intsc_bottom) ;
myDB.WB_data.stopbar_UL = new Point(intsc_right, intsc_top) ;
myDB.WB_data.stopbar_LR = new Point(intsc_right+STOPBAR_WIDTH, intsc_centerY) ;
myDB.NB_data.stopbar_UL = new Point(intsc_centerX, intsc_bottom) ;
myDB.NB_data.stopbar_LR = new Point(intsc_right, intsc_bottom+STOPBAR_WIDTH) ;
myDB.SB_data.stopbar_UL = new Point(intsc_left, intsc_top-STOPBAR_WIDTH) ;
myDB.SB_data.stopbar_LR = new Point(intsc_centerX, intsc_top) ;
// System.out.println("left="+intsc_left) ;
// System.out.println("right="+intsc_right) ;
// System.out.println("top="+intsc_top) ;
// System.out.println("bottom="+intsc_bottom) ;
//sb.setStatusBarText(3, new Float(draw_scale).toString()) ;
//processImage();
traffic_demand = new float [INTSC_SIZE][NUM_LINK][4] ;
// =======================================================================
// default demand & turning proportions
// =======================================================================
// default demand, East
//traffic_demand[0][0][0] = 280 ; // veh/h
traffic_demand[0][0][1] = 10 ; // 10% left turn
traffic_demand[0][0][2] = 75 ; // 75% thru
traffic_demand[0][0][3] = 15 ; // 15% right turn
// default demand, West
//traffic_demand[0][1][0] = 250 ; // veh/h
traffic_demand[0][1][1] = 10 ; // 10% left turn
traffic_demand[0][1][2] = 75 ; // 75% thru
traffic_demand[0][1][3] = 15 ; // 15% right turn
// default demand, North
//traffic_demand[0][2][0] = 450 ; // veh/h
traffic_demand[0][2][1] = 19 ; // 10% left turn
traffic_demand[0][2][2] = 70 ; // 75% thru
traffic_demand[0][2][3] = 11 ; // 15% right turn
// default demand, South
//traffic_demand[0][3][0] = 400 ; // veh/h
traffic_demand[0][3][1] = 18 ; // 10% left turn
traffic_demand[0][3][2] = 70 ; // 75% thru
traffic_demand[0][3][3] = 12 ; // 15% right turn
traffic_demand[0][0][0] = myDB.EB_data.getVolume() ;
traffic_demand[0][1][0] = myDB.WB_data.getVolume() ;
traffic_demand[0][2][0] = myDB.NB_data.getVolume() ;
traffic_demand[0][3][0] = myDB.SB_data.getVolume() ;
// init routeDB
int nb_routeSize = myDB.NB_data.getLaneSize()/2+2 ;
int sb_routeSize = myDB.SB_data.getLaneSize()/2+2 ;
int eb_routeSize = myDB.EB_data.getLaneSize()/2+2 ;
int wb_routeSize = myDB.WB_data.getLaneSize()/2+2 ;
route_NB = new routeDB[nb_routeSize] ;
route_SB = new routeDB[sb_routeSize] ;
route_EB = new routeDB[eb_routeSize] ;
route_WB = new routeDB[wb_routeSize] ;
int i ;
for (i=0; i<4; i++) {
switch (i) {
case 0:
_lane_size[0] = myDB.EB_data.getLaneSize()/2 ;
_speed_limit[0] = myDB.EB_data.getSpeedLimit() ;
break ;
case 1:
_lane_size[1] = myDB.WB_data.getLaneSize()/2 ;
_speed_limit[1] = myDB.WB_data.getSpeedLimit() ;
break ;
case 2:
_lane_size[2] = myDB.NB_data.getLaneSize()/2 ;
_speed_limit[2] = myDB.NB_data.getSpeedLimit() ;
break ;
case 3:
_lane_size[3] = myDB.SB_data.getLaneSize()/2 ;
_speed_limit[3] = myDB.SB_data.getSpeedLimit() ;
break ;
}// switch i
veh_index[i]=0 ;
}
// =======================================================================
// NB routes
// =======================================================================
for (i=0; i<nb_routeSize; i++) {
// initialize NB route DB
switch (i) {
case 0: // left
// check exclusive left turn?
if (myDB.NB_data.leftTurnLaneExists()) {
// left turn lane exists
route_NB[0] = new routeDB(8) ;
route_NB[0].setRouteDBi(0, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, intsc_bottom+link_length), 2) ;
route_NB[0].setRouteDBi(1, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, intsc_bottom+link_length/2-5), 2) ;
route_NB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2, intsc_bottom+link_length/2-15), 2) ;
route_NB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2, intsc_bottom), 99) ; // 22.5 deg
route_NB[0].setRouteDBi(4, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2), 99 ) ; // 45 deg
route_NB[0].setRouteDBi(5, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2), 99) ; // 67.5 deg
if (myDB.EB_data.leftTurnLaneExists() || myDB.WB_data.leftTurnLaneExists()) {
route_NB[0].setRouteDBi(6, new Point(intsc_left, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH), 105) ; //
route_NB[0].setRouteDBi(7, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH),105) ;
} else {
route_NB[0].setRouteDBi(6, new Point(intsc_left, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),105) ; //
route_NB[0].setRouteDBi(7, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),105) ;
}
// signal strips, NB LF
mySignalControl.myPhases[LEFT_ASSIGN_PH[2]-1].sigbar_UL =
new Point(center.x-myDB.LANE_WIDTH/2, intsc_bottom+STOPBAR_WIDTH-5) ;
mySignalControl.myPhases[LEFT_ASSIGN_PH[2]-1].sigbar_LR =
new Point(center.x+myDB.LANE_WIDTH/2, intsc_bottom+STOPBAR_WIDTH-2) ;
mySignalControl.protected_left[2] = true ;
//route_NB[0].print() ;
} else {
route_NB[0] = new routeDB(6) ;
if (myDB.SB_data.leftTurnLaneExists()) {
route_NB[0].setRouteDBi(0, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, intsc_bottom+link_length),2) ;
route_NB[0].setRouteDBi(1, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, intsc_bottom),99) ; //
route_NB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2),99) ; //
route_NB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),99) ; //
} else {
route_NB[0].setRouteDBi(0, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, intsc_bottom+link_length),2) ;
route_NB[0].setRouteDBi(1, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, intsc_bottom),99 ) ; //
route_NB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2),99 ) ; //
route_NB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),99 ) ; //
}
if (myDB.EB_data.leftTurnLaneExists() | myDB.WB_data.leftTurnLaneExists()) {
route_NB[0].setRouteDBi(4, new Point(intsc_left, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH),105) ; // 90 deg
route_NB[0].setRouteDBi(5, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH),105) ;
} else {
route_NB[0].setRouteDBi(4, new Point(intsc_left, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),105) ; // 90 deg
route_NB[0].setRouteDBi(5, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),105) ;
}
//route_NB[0].print() ;
// signal strips, NB LF
mySignalControl.myPhases[LEFT_ASSIGN_PH[2]-1].sigbar_UL =
new Point(-99, -99) ;
mySignalControl.myPhases[LEFT_ASSIGN_PH[2]-1].sigbar_LR =
new Point(-99, -99) ;
//if (mySignalControl.inRing2(LEFT_ASSIGN_PH[2])) {
// ring 2
mySignalControl.setRing2Seq_i(0, 6) ;
//} else {
// ring 1
// mySignalControl.setRing1Seq_iThru(LEFT_ASSIGN_PH[2]-1) ;
//}
mySignalControl.protected_left[2] = false ; ;
}
break ;
case 1: // right
route_NB[1] = new routeDB(5) ;
route_NB[1].setRouteDBi(0, new Point(intsc_right-myDB.LANE_WIDTH/2, intsc_bottom+link_length),2) ;
route_NB[1].setRouteDBi(1, new Point(intsc_right-myDB.LANE_WIDTH/2, intsc_bottom),99) ; //
route_NB[1].setRouteDBi(2, new Point(intsc_right-myDB.LANE_WIDTH/4, intsc_bottom-myDB.LANE_WIDTH/2),99) ; //
route_NB[1].setRouteDBi(3, new Point(intsc_right, intsc_bottom-myDB.LANE_WIDTH/2),104) ; //
route_NB[1].setRouteDBi(4, new Point(intsc_right+link_length, intsc_bottom-myDB.LANE_WIDTH/2),104) ;
//route_NB[1].print() ;
break ;
default: // straight thru
route_NB[i] = new routeDB(4) ; // linear path
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
route_NB[i].setRouteDBi(0, new Point((intsc_left+intsc_right)/2+(i-1)*myDB.LANE_WIDTH, intsc_bottom+link_length),2) ;
route_NB[i].setRouteDBi(1, new Point((intsc_left+intsc_right)/2+(i-1)*myDB.LANE_WIDTH, intsc_bottom),99) ;
route_NB[i].setRouteDBi(2, new Point((intsc_left+intsc_right)/2+(i-1)*myDB.LANE_WIDTH, intsc_top),106) ;
route_NB[i].setRouteDBi(3, new Point((intsc_left+intsc_right)/2+(i-1)*myDB.LANE_WIDTH, intsc_top-link_length),106) ;
// signal strips, NB THRU
mySignalControl.myPhases[THRU_ASSIGN_PH[2]-1].sigbar_UL =
new Point(center.x+myDB.LANE_WIDTH/2, intsc_bottom+STOPBAR_WIDTH-5) ;
mySignalControl.myPhases[THRU_ASSIGN_PH[2]-1].sigbar_LR =
new Point(intsc_right, intsc_bottom+STOPBAR_WIDTH-2) ;
} else {
route_NB[i].setRouteDBi(0, new Point((intsc_left+intsc_right)/2+(i-2)*myDB.LANE_WIDTH+myDB.LANE_WIDTH/2, intsc_bottom+link_length),2) ;
route_NB[i].setRouteDBi(1, new Point((intsc_left+intsc_right)/2+(i-2)*myDB.LANE_WIDTH+myDB.LANE_WIDTH/2, intsc_bottom),99) ;
route_NB[i].setRouteDBi(2, new Point((intsc_left+intsc_right)/2+(i-2)*myDB.LANE_WIDTH+myDB.LANE_WIDTH/2, intsc_top),106) ;
route_NB[i].setRouteDBi(3, new Point((intsc_left+intsc_right)/2+(i-2)*myDB.LANE_WIDTH+myDB.LANE_WIDTH/2, intsc_top-link_length),106) ;
// signal strips, NB THRU
mySignalControl.myPhases[THRU_ASSIGN_PH[2]-1].sigbar_UL =
new Point(center.x, intsc_bottom+STOPBAR_WIDTH-5) ;
mySignalControl.myPhases[THRU_ASSIGN_PH[2]-1].sigbar_LR =
new Point(intsc_right, intsc_bottom+STOPBAR_WIDTH-2) ;
}
break ;
}
} // end of NB routes
// =======================================================================
// South bound routes
// =======================================================================
for (i=0; i<sb_routeSize; i++) {
// initialize SB route DB
switch (i) {
case 0: // left
// check excl left turn?
if (myDB.SB_data.leftTurnLaneExists()) {
// left turn lane exists
route_SB[0] = new routeDB(8) ;
route_SB[0].setRouteDBi(0, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, intsc_top-link_length),3) ;
route_SB[0].setRouteDBi(1, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, intsc_top-link_length/2+5),3) ;
route_SB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2, intsc_top-link_length/2+15),3) ;
route_SB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2, intsc_top),99) ; // 22.5 deg
route_SB[0].setRouteDBi(4, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2),99) ; // 45 deg
route_SB[0].setRouteDBi(5, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),99) ; // 67.5 deg
if (myDB.EB_data.leftTurnLaneExists() | myDB.WB_data.leftTurnLaneExists()) {
route_SB[0].setRouteDBi(6, new Point(intsc_right, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),104) ; //
route_SB[0].setRouteDBi(7, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),104) ;
} else {
route_SB[0].setRouteDBi(6, new Point(intsc_right, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),104) ; //
route_SB[0].setRouteDBi(7, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),104) ;
}
// signal strips, SB LF
mySignalControl.myPhases[LEFT_ASSIGN_PH[3]-1].sigbar_UL =
new Point(center.x-myDB.LANE_WIDTH/2, intsc_top-STOPBAR_WIDTH+2) ;
mySignalControl.myPhases[LEFT_ASSIGN_PH[3]-1].sigbar_LR =
new Point(center.x+myDB.LANE_WIDTH/2, intsc_top-STOPBAR_WIDTH+5) ;
mySignalControl.protected_left[3] = true ;
//route_SB[0].print() ;
} else {
route_SB[0] = new routeDB(6) ;
if (myDB.NB_data.leftTurnLaneExists()) {
route_SB[0].setRouteDBi(0, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, intsc_top-link_length),3) ;
route_SB[0].setRouteDBi(1, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, intsc_top),99) ; //
route_SB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2),99) ; //
route_SB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),99) ; //
} else {
route_SB[0].setRouteDBi(0, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, intsc_top-link_length),3) ;
route_SB[0].setRouteDBi(1, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, intsc_top),99) ; //
route_SB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2),99) ; //
route_SB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),99) ; //
}
if (myDB.EB_data.leftTurnLaneExists() | myDB.WB_data.leftTurnLaneExists()) {
route_SB[0].setRouteDBi(4, new Point(intsc_right, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),104) ; // 90 deg
route_SB[0].setRouteDBi(5, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),104) ;
} else {
route_SB[0].setRouteDBi(4, new Point(intsc_right, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),104) ; // 90 deg
route_SB[0].setRouteDBi(5, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),104) ;
}
//route_SB[0].print() ;
// signal strips, SB LF
mySignalControl.myPhases[LEFT_ASSIGN_PH[3]-1].sigbar_UL =
new Point(-99, -99) ;
mySignalControl.myPhases[LEFT_ASSIGN_PH[3]-1].sigbar_LR =
new Point(-99, -99) ;
//if (mySignalControl.inRing2(LEFT_ASSIGN_PH[3])) {
// ring 2
// mySignalControl.setRing2Seq_iThru(LEFT_ASSIGN_PH[3]-5) ;
//} else {
// ring 1
mySignalControl.setRing1Seq_i(0, 2) ;
//}
mySignalControl.protected_left[3] = false ;
}
break ;
case 1: // right
route_SB[1] = new routeDB(5) ;
route_SB[1].setRouteDBi(0, new Point(intsc_left+myDB.LANE_WIDTH/2, intsc_top-link_length),3) ;
route_SB[1].setRouteDBi(1, new Point(intsc_left+myDB.LANE_WIDTH/2, intsc_top),99) ; //
route_SB[1].setRouteDBi(2, new Point(intsc_left+myDB.LANE_WIDTH/4, intsc_top+myDB.LANE_WIDTH/2),99) ; //
route_SB[1].setRouteDBi(3, new Point(intsc_left, intsc_top+myDB.LANE_WIDTH/2),105) ; //
route_SB[1].setRouteDBi(4, new Point(intsc_left-link_length, intsc_top+myDB.LANE_WIDTH/2),105) ;
//route_SB[1].print() ;
break ;
default: // straight thru
route_SB[i] = new routeDB(4) ; // linear path
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
route_SB[i].setRouteDBi(0, new Point((intsc_left+intsc_right)/2-(i-1)*myDB.LANE_WIDTH, intsc_top-link_length),3) ;
route_SB[i].setRouteDBi(1, new Point((intsc_left+intsc_right)/2-(i-1)*myDB.LANE_WIDTH, intsc_top),99) ;
route_SB[i].setRouteDBi(2, new Point((intsc_left+intsc_right)/2-(i-1)*myDB.LANE_WIDTH, intsc_bottom),107) ;
route_SB[i].setRouteDBi(3, new Point((intsc_left+intsc_right)/2-(i-1)*myDB.LANE_WIDTH, intsc_bottom+link_length),107) ;
// signal strips, SB THRU
mySignalControl.myPhases[THRU_ASSIGN_PH[3]-1].sigbar_UL =
new Point(intsc_left, intsc_top-STOPBAR_WIDTH+2) ;
mySignalControl.myPhases[THRU_ASSIGN_PH[3]-1].sigbar_LR =
new Point(center.x-myDB.LANE_WIDTH/2, intsc_top-STOPBAR_WIDTH+5) ;
} else {
route_SB[i].setRouteDBi(0, new Point((intsc_left+intsc_right)/2-(i-2)*myDB.LANE_WIDTH-myDB.LANE_WIDTH/2, intsc_top-link_length),3) ;
route_SB[i].setRouteDBi(1, new Point((intsc_left+intsc_right)/2-(i-2)*myDB.LANE_WIDTH-myDB.LANE_WIDTH/2, intsc_top),99) ;
route_SB[i].setRouteDBi(2, new Point((intsc_left+intsc_right)/2-(i-2)*myDB.LANE_WIDTH-myDB.LANE_WIDTH/2, intsc_bottom),107) ;
route_SB[i].setRouteDBi(3, new Point((intsc_left+intsc_right)/2-(i-2)*myDB.LANE_WIDTH-myDB.LANE_WIDTH/2, intsc_bottom+link_length),107) ;
// signal strips, SB THRU, no medium
mySignalControl.myPhases[THRU_ASSIGN_PH[3]-1].sigbar_UL =
new Point(intsc_left, intsc_top-STOPBAR_WIDTH+2) ;
mySignalControl.myPhases[THRU_ASSIGN_PH[3]-1].sigbar_LR =
new Point(center.x, intsc_top-STOPBAR_WIDTH+5) ;
}
break ;
}
} // end of SB routes
// =======================================================================
// EB routes
// =======================================================================
for (i=0; i<eb_routeSize; i++) {
// initialize EB route DB
switch (i) {
case 0: // left
// check excl left turn?
if (myDB.EB_data.leftTurnLaneExists()) {
// left turn lane exists
route_EB[0] = new routeDB(8) ;
route_EB[0].setRouteDBi(0, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),0) ;
route_EB[0].setRouteDBi(1, new Point(intsc_left-link_length/2+5, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),0) ;
route_EB[0].setRouteDBi(2, new Point(intsc_left-link_length/2+15, (intsc_top+intsc_bottom)/2),0) ;
route_EB[0].setRouteDBi(3, new Point(intsc_left, (intsc_top+intsc_bottom)/2 ),99) ; //
route_EB[0].setRouteDBi(4, new Point((intsc_left+intsc_right)/2, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),99) ; //
route_EB[0].setRouteDBi(5, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH),99) ; //
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
route_EB[0].setRouteDBi(6, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, intsc_top),106) ; //
route_EB[0].setRouteDBi(7, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, intsc_top-link_length),106) ;
} else {
route_EB[0].setRouteDBi(6, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, intsc_top),106) ; //
route_EB[0].setRouteDBi(7, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, intsc_top-link_length),106) ;
}
// signal strips, EB LF
mySignalControl.myPhases[LEFT_ASSIGN_PH[0]-1].sigbar_UL =
new Point(intsc_left-STOPBAR_WIDTH+2, center.y-myDB.LANE_WIDTH/2) ;
mySignalControl.myPhases[LEFT_ASSIGN_PH[0]-1].sigbar_LR =
new Point(intsc_left-STOPBAR_WIDTH+5, center.y+myDB.LANE_WIDTH/2) ;
mySignalControl.protected_left[0] = true ;
//route_EB[0].print() ;
} else {
route_EB[0] = new routeDB(6) ;
if (myDB.WB_data.leftTurnLaneExists()) {
route_EB[0].setRouteDBi(0, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),0) ;
route_EB[0].setRouteDBi(1, new Point(intsc_left, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),99) ; //
route_EB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),99) ; //
route_EB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),99) ; //
} else {
route_EB[0].setRouteDBi(0, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2 ),0) ;
route_EB[0].setRouteDBi(1, new Point(intsc_left, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),99) ; //
route_EB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),99) ; //
route_EB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2),99) ; //
}
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
route_EB[0].setRouteDBi(4, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, intsc_top),106) ; // 90 deg
route_EB[0].setRouteDBi(5, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH, intsc_top-link_length ),106) ;
} else {
route_EB[0].setRouteDBi(4, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, intsc_top),106) ; // 90 deg
route_EB[0].setRouteDBi(5, new Point((intsc_left+intsc_right)/2+myDB.LANE_WIDTH/2, intsc_top-link_length ),106) ;
}
//route_EB[0].print() ;
// signal strips, EB LF
mySignalControl.myPhases[LEFT_ASSIGN_PH[0]-1].sigbar_UL =
new Point(-99, -99) ;
mySignalControl.myPhases[LEFT_ASSIGN_PH[0]-1].sigbar_LR =
new Point(-99, -99) ;
//if (mySignalControl.inRing2(LEFT_ASSIGN_PH[0])) {
// ring 2
mySignalControl.setRing2Seq_i(2, 8) ;
//} else {
// ring 1
// mySignalControl.setRing1Seq_iThru(LEFT_ASSIGN_PH[0]-1) ;
//}
mySignalControl.protected_left[0] = false ;
}
break ;
case 1: // right
route_EB[1] = new routeDB(5) ;
route_EB[1].setRouteDBi(0, new Point(intsc_left-link_length, intsc_bottom-myDB.LANE_WIDTH/2),0) ;
route_EB[1].setRouteDBi(1, new Point(intsc_left, intsc_bottom-myDB.LANE_WIDTH/2),99) ; //
route_EB[1].setRouteDBi(2, new Point(intsc_left+myDB.LANE_WIDTH/2, intsc_bottom-myDB.LANE_WIDTH/4),99) ; //
route_EB[1].setRouteDBi(3, new Point(intsc_left+myDB.LANE_WIDTH/2, intsc_bottom),107) ; //
route_EB[1].setRouteDBi(4, new Point(intsc_left+myDB.LANE_WIDTH/2, intsc_bottom+link_length),107) ;
//route_EB[1].print() ;
break ;
default: // straight thru
route_EB[i] = new routeDB(4) ; // linear path
if (myDB.EB_data.leftTurnLaneExists() | myDB.WB_data.leftTurnLaneExists()) {
route_EB[i].setRouteDBi(0, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2+(i-1)*myDB.LANE_WIDTH),0) ;
route_EB[i].setRouteDBi(1, new Point(intsc_left, (intsc_top+intsc_bottom)/2+(i-1)*myDB.LANE_WIDTH),99) ;
route_EB[i].setRouteDBi(2, new Point(intsc_right, (intsc_top+intsc_bottom)/2+(i-1)*myDB.LANE_WIDTH),104) ;
route_EB[i].setRouteDBi(3, new Point(intsc_right+link_length+50, (intsc_top+intsc_bottom)/2+(i-1)*myDB.LANE_WIDTH),104) ;
// signal strips, EB THRU
mySignalControl.myPhases[THRU_ASSIGN_PH[0]-1].sigbar_UL =
new Point(intsc_left-STOPBAR_WIDTH+2, center.y+myDB.LANE_WIDTH/2) ;
mySignalControl.myPhases[THRU_ASSIGN_PH[0]-1].sigbar_LR =
new Point(intsc_left-STOPBAR_WIDTH+5, intsc_bottom) ;
} else {
route_EB[i].setRouteDBi(0, new Point(intsc_left-link_length, (intsc_top+intsc_bottom)/2+(i-2)*myDB.LANE_WIDTH+myDB.LANE_WIDTH/2),0) ;
route_EB[i].setRouteDBi(1, new Point(intsc_left, (intsc_top+intsc_bottom)/2+(i-2)*myDB.LANE_WIDTH+myDB.LANE_WIDTH/2),99) ;
route_EB[i].setRouteDBi(2, new Point(intsc_right, (intsc_top+intsc_bottom)/2+(i-2)*myDB.LANE_WIDTH+myDB.LANE_WIDTH/2),104) ;
route_EB[i].setRouteDBi(3, new Point(intsc_right+link_length+50, (intsc_top+intsc_bottom)/2+(i-2)*myDB.LANE_WIDTH+myDB.LANE_WIDTH/2),104) ;
// signal strips, EB THRU, no medium
mySignalControl.myPhases[THRU_ASSIGN_PH[0]-1].sigbar_UL =
new Point(intsc_left-STOPBAR_WIDTH+2, center.y) ;
mySignalControl.myPhases[THRU_ASSIGN_PH[0]-1].sigbar_LR =
new Point(intsc_left-STOPBAR_WIDTH+5, intsc_bottom) ;
}
break ;
}
} // end of EB routes
// =======================================================================
// WB routes
// =======================================================================
for (i=0; i<wb_routeSize; i++) {
// initialize WB route DB
switch (i) {
case 0: // left
// check excl left turn?
if (myDB.WB_data.leftTurnLaneExists()) {
// left turn lane exists
route_WB[0] = new routeDB(8) ;
route_WB[0].setRouteDBi(0, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH),1) ;
route_WB[0].setRouteDBi(1, new Point(intsc_right+link_length/2-5, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH),1) ;
route_WB[0].setRouteDBi(2, new Point(intsc_right+link_length/2-15, (intsc_top+intsc_bottom)/2),1) ;
route_WB[0].setRouteDBi(3, new Point(intsc_right, (intsc_top+intsc_bottom)/2 ),99) ; //
route_WB[0].setRouteDBi(4, new Point((intsc_left+intsc_right)/2, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),99) ; //
route_WB[0].setRouteDBi(5, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH),99) ; //
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
route_WB[0].setRouteDBi(6, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, intsc_bottom),107) ; //
route_WB[0].setRouteDBi(7, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, intsc_bottom+link_length),107) ;
} else {
route_WB[0].setRouteDBi(6, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, intsc_bottom),107) ; //
route_WB[0].setRouteDBi(7, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, intsc_bottom+link_length),107) ;
}
// signal strips, WB LF
mySignalControl.myPhases[LEFT_ASSIGN_PH[1]-1].sigbar_UL =
new Point(intsc_right+STOPBAR_WIDTH-5, center.y-myDB.LANE_WIDTH/2) ;
mySignalControl.myPhases[LEFT_ASSIGN_PH[1]-1].sigbar_LR =
new Point(intsc_right+STOPBAR_WIDTH-2, center.y+myDB.LANE_WIDTH/2) ;
mySignalControl.protected_left[1] = true ;
//route_WB[0].print() ;
} else {
route_WB[0] = new routeDB(6) ;
if (myDB.EB_data.leftTurnLaneExists()) {
route_WB[0].setRouteDBi(0, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH),1) ;
route_WB[0].setRouteDBi(1, new Point(intsc_right, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH),99) ; //
route_WB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),99) ; //
route_WB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2+myDB.LANE_WIDTH/2),99) ; //
} else {
route_WB[0].setRouteDBi(0, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2 ),1) ;
route_WB[0].setRouteDBi(1, new Point(intsc_right, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),99) ; //
route_WB[0].setRouteDBi(2, new Point((intsc_left+intsc_right)/2, (intsc_top+intsc_bottom)/2-myDB.LANE_WIDTH/2),99) ; //
route_WB[0].setRouteDBi(3, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, (intsc_top+intsc_bottom)/2),99) ; //
}
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
route_WB[0].setRouteDBi(4, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, intsc_bottom),107) ; // 90 deg
route_WB[0].setRouteDBi(5, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH, intsc_bottom+link_length ),107) ;
} else {
route_WB[0].setRouteDBi(4, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, intsc_bottom),107) ; // 90 deg
route_WB[0].setRouteDBi(5, new Point((intsc_left+intsc_right)/2-myDB.LANE_WIDTH/2, intsc_bottom+link_length ),107) ;
}
//route_WB[0].print() ;
// signal strips, WB LF
mySignalControl.myPhases[LEFT_ASSIGN_PH[1]-1].sigbar_UL =
new Point(-99, -99) ;
mySignalControl.myPhases[LEFT_ASSIGN_PH[1]-1].sigbar_LR =
new Point(-99, -99) ;
//if (mySignalControl.inRing2(LEFT_ASSIGN_PH[1])) {
// ring 2
// mySignalControl.setRing2Seq_iThru(LEFT_ASSIGN_PH[1]-5) ;
//} else {
// ring 1
mySignalControl.setRing1Seq_i(2, 4) ;
//}
mySignalControl.protected_left[1] = false ;
}
break ;
case 1: // right
route_WB[1] = new routeDB(5) ;
route_WB[1].setRouteDBi(0, new Point(intsc_right+link_length, intsc_top+myDB.LANE_WIDTH/2),1) ;
route_WB[1].setRouteDBi(1, new Point(intsc_right, intsc_top+myDB.LANE_WIDTH/2),99) ; //
route_WB[1].setRouteDBi(2, new Point(intsc_right-myDB.LANE_WIDTH/2, intsc_top+myDB.LANE_WIDTH/4),99) ; //
route_WB[1].setRouteDBi(3, new Point(intsc_right-myDB.LANE_WIDTH/2, intsc_top),106) ; //
route_WB[1].setRouteDBi(4, new Point(intsc_right-myDB.LANE_WIDTH/2, intsc_top-link_length),106) ;
//route_WB[1].print() ;
break ;
default: // straight thru
route_WB[i] = new routeDB(4) ; // linear path
if (myDB.EB_data.leftTurnLaneExists() | myDB.WB_data.leftTurnLaneExists()) {
route_WB[i].setRouteDBi(0, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2-(i-1)*myDB.LANE_WIDTH),1) ;
route_WB[i].setRouteDBi(1, new Point(intsc_right, (intsc_top+intsc_bottom)/2-(i-1)*myDB.LANE_WIDTH),99) ;
route_WB[i].setRouteDBi(2, new Point(intsc_left, (intsc_top+intsc_bottom)/2-(i-1)*myDB.LANE_WIDTH),105) ;
route_WB[i].setRouteDBi(3, new Point(intsc_left-link_length-50, (intsc_top+intsc_bottom)/2-(i-1)*myDB.LANE_WIDTH),105) ;
// signal strips, WB THRU
mySignalControl.myPhases[THRU_ASSIGN_PH[1]-1].sigbar_UL =
new Point(intsc_right+STOPBAR_WIDTH-5, intsc_top) ;
mySignalControl.myPhases[THRU_ASSIGN_PH[1]-1].sigbar_LR =
new Point(intsc_right+STOPBAR_WIDTH-2, center.y-myDB.LANE_WIDTH/2) ;
} else {
route_WB[i].setRouteDBi(0, new Point(intsc_right+link_length, (intsc_top+intsc_bottom)/2-(i-2)*myDB.LANE_WIDTH-myDB.LANE_WIDTH/2),1) ;
route_WB[i].setRouteDBi(1, new Point(intsc_right, (intsc_top+intsc_bottom)/2-(i-2)*myDB.LANE_WIDTH-myDB.LANE_WIDTH/2),99) ;
route_WB[i].setRouteDBi(2, new Point(intsc_left, (intsc_top+intsc_bottom)/2-(i-2)*myDB.LANE_WIDTH-myDB.LANE_WIDTH/2),105) ;
route_WB[i].setRouteDBi(3, new Point(intsc_left-link_length-50, (intsc_top+intsc_bottom)/2-(i-2)*myDB.LANE_WIDTH-myDB.LANE_WIDTH/2),105) ;
// signal strips, WB THRU, no medium
mySignalControl.myPhases[THRU_ASSIGN_PH[1]-1].sigbar_UL =
new Point(intsc_right+STOPBAR_WIDTH-5, intsc_top) ;
mySignalControl.myPhases[THRU_ASSIGN_PH[1]-1].sigbar_LR =
new Point(intsc_right+STOPBAR_WIDTH-2, center.y) ;
}
break ;
}
} // end of WB routes
// create a new vehicle
//myCar = new Vehicle2D(0, 1, route_EB[1], 30f) ; // dir, route id, route, speed
// =======================================================================
// loop detector layout
// =======================================================================
int N ;
int ij=0 ;
int signal_head_offset = (myDB.LANE_WIDTH-myDB.SIGNAL_HEAD_SIZE)/2 ;
// loop detector
// EB
N = myDB.EB_data.getLaneSize()/2 ;
if (myDB.EB_data.leftTurnLaneExists()) {
// left turn exists
myDB.EB_data.detectorUL[0] = new Point(intsc_left-myDB.EB_data.LT_detector_dist, center.y-myDB.LOOP_DET_WIDTH/2) ;
myDB.EB_data.signalLit_UL[0] = new Point(intsc_left-myDB.SIGNAL_HEAD_SIZE, center.y-myDB.LANE_WIDTH/2+signal_head_offset) ;
myDB.EB_data.presence_detectorUL[0] = myDB.EB_data.detectorUL[0] ;
} else {
// left turn does not exist
myDB.EB_data.detectorUL[0] = new Point(-99, -99) ;
myDB.EB_data.presence_detectorUL[0] = new Point(-99, -99) ;
myDB.EB_data.signalLit_UL[0] = new Point(-99, -99) ;
}
if (myDB.EB_data.leftTurnLaneExists() | myDB.WB_data.leftTurnLaneExists()) {
for (ij=1; ij<=N; ij++) {
myDB.EB_data.detectorUL[ij] = new Point(intsc_left-myDB.EB_data.detector_dist, center.y-myDB.LOOP_DET_WIDTH/2 + ij*myDB.LANE_WIDTH) ;
myDB.EB_data.presence_detectorUL[ij] = new Point(intsc_left-myDB.EB_data.presence_detector_dist, center.y-myDB.LOOP_DET_WIDTH/2 + ij*myDB.LANE_WIDTH) ;
myDB.EB_data.signalLit_UL[ij] = new Point(intsc_left-myDB.SIGNAL_HEAD_SIZE, center.y-myDB.LANE_WIDTH/2 + signal_head_offset + ij*myDB.LANE_WIDTH) ;
}
} else {
for (ij=1; ij<=N; ij++) {
myDB.EB_data.detectorUL[ij] = new Point(intsc_left-myDB.EB_data.detector_dist, center.y-myDB.LOOP_DET_WIDTH/2 + myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH) ;
myDB.EB_data.presence_detectorUL[ij] = new Point(intsc_left-myDB.EB_data.presence_detector_dist, center.y-myDB.LOOP_DET_WIDTH/2 + myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH) ;
myDB.EB_data.signalLit_UL[ij] = new Point(intsc_left-myDB.SIGNAL_HEAD_SIZE, center.y-myDB.LANE_WIDTH/2 + signal_head_offset+myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH) ;
}
}
// WB
N = myDB.WB_data.getLaneSize()/2 ;
if (myDB.WB_data.leftTurnLaneExists()) {
// left turn exists
myDB.WB_data.detectorUL[0] = new Point(intsc_right+myDB.WB_data.LT_detector_dist-myDB.LT_LOOP_DET_LENGTH, center.y-myDB.LOOP_DET_WIDTH/2) ;
myDB.WB_data.signalLit_UL[0] = new Point(intsc_right, center.y-myDB.LANE_WIDTH/2+signal_head_offset) ;
myDB.WB_data.presence_detectorUL[0] = myDB.WB_data.detectorUL[0] ;
} else {
// left turn does not exist
myDB.WB_data.detectorUL[0] = new Point(-99, -99) ;
myDB.WB_data.presence_detectorUL[0] = new Point(-99, -99) ;
myDB.WB_data.signalLit_UL[0] = new Point(-99, -99) ;
}
if (myDB.EB_data.leftTurnLaneExists() | myDB.WB_data.leftTurnLaneExists()) {
for (ij=1; ij<=N; ij++) {
myDB.WB_data.detectorUL[ij] = new Point(intsc_right+myDB.WB_data.detector_dist-myDB.LOOP_DET_LENGTH, center.y-myDB.LOOP_DET_WIDTH/2 - ij*myDB.LANE_WIDTH) ;
myDB.WB_data.presence_detectorUL[ij] = new Point(intsc_right+myDB.WB_data.presence_detector_dist-myDB.PRESENCE_LOOP_DET_LENGTH, center.y-myDB.LOOP_DET_WIDTH/2 - ij*myDB.LANE_WIDTH) ;
myDB.WB_data.signalLit_UL[ij] = new Point(intsc_right, center.y-myDB.LANE_WIDTH/2 + signal_head_offset- ij*myDB.LANE_WIDTH) ;
}
} else {
for (ij=1; ij<=N; ij++) {
myDB.WB_data.detectorUL[ij] = new Point(intsc_right+myDB.WB_data.detector_dist-myDB.LOOP_DET_LENGTH, center.y-myDB.LOOP_DET_WIDTH/2 - myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH) ;
myDB.WB_data.presence_detectorUL[ij] = new Point(intsc_right+myDB.WB_data.presence_detector_dist-myDB.PRESENCE_LOOP_DET_LENGTH, center.y-myDB.LOOP_DET_WIDTH/2 - myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH) ;
myDB.WB_data.signalLit_UL[ij] = new Point(intsc_right, center.y-myDB.LANE_WIDTH/2 + signal_head_offset- myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH) ;
}
}
// NB
N = myDB.NB_data.getLaneSize()/2 ;
if (myDB.NB_data.leftTurnLaneExists()) {
// left turn exists
myDB.NB_data.detectorUL[0] = new Point(center.x-myDB.LOOP_DET_WIDTH/2, intsc_bottom+myDB.NB_data.LT_detector_dist-myDB.LT_LOOP_DET_LENGTH) ;
myDB.NB_data.signalLit_UL[0] = new Point(center.x-myDB.LANE_WIDTH/2+signal_head_offset, intsc_bottom) ;
myDB.NB_data.presence_detectorUL[0] = myDB.NB_data.detectorUL[0] ;
} else {
// left turn does not exist
myDB.NB_data.detectorUL[0] = new Point(-99, -99) ;
myDB.NB_data.presence_detectorUL[0] = new Point(-99, -99) ;
myDB.NB_data.signalLit_UL[0] = new Point(-99, -99) ;
}
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
for (ij=1; ij<=N; ij++) {
myDB.NB_data.detectorUL[ij] = new Point(center.x-myDB.LOOP_DET_WIDTH/2 + ij*myDB.LANE_WIDTH, intsc_bottom+myDB.NB_data.detector_dist-myDB.LOOP_DET_LENGTH) ;
myDB.NB_data.presence_detectorUL[ij] = new Point(center.x-myDB.LOOP_DET_WIDTH/2 + ij*myDB.LANE_WIDTH, intsc_bottom+myDB.NB_data.presence_detector_dist-myDB.PRESENCE_LOOP_DET_LENGTH) ;
myDB.NB_data.signalLit_UL[ij] = new Point(center.x-myDB.LANE_WIDTH/2 +signal_head_offset+ ij*myDB.LANE_WIDTH, intsc_bottom) ;
}
} else {
for (ij=1; ij<=N; ij++) {
myDB.NB_data.detectorUL[ij] = new Point(center.x-myDB.LOOP_DET_WIDTH/2 + myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH, intsc_bottom+myDB.NB_data.detector_dist-myDB.LOOP_DET_LENGTH) ;
myDB.NB_data.presence_detectorUL[ij] = new Point(center.x-myDB.LOOP_DET_WIDTH/2 + myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH, intsc_bottom+myDB.NB_data.presence_detector_dist-myDB.PRESENCE_LOOP_DET_LENGTH) ;
myDB.NB_data.signalLit_UL[ij] = new Point(center.x-myDB.LANE_WIDTH/2 + signal_head_offset+ myDB.LANE_WIDTH/2 +(ij-1)*myDB.LANE_WIDTH, intsc_bottom) ;
}
}
// SB
N = myDB.SB_data.getLaneSize()/2 ;
if (myDB.SB_data.leftTurnLaneExists()) {
// left turn exists
myDB.SB_data.detectorUL[0] = new Point(center.x-myDB.LOOP_DET_WIDTH/2, intsc_top-myDB.SB_data.LT_detector_dist) ;
myDB.SB_data.signalLit_UL[0] = new Point(center.x-myDB.LANE_WIDTH/2 + signal_head_offset, intsc_top-myDB.SIGNAL_HEAD_SIZE) ;
myDB.SB_data.presence_detectorUL[0] = myDB.SB_data.detectorUL[0] ;
} else {
// left turn does not exist
myDB.SB_data.detectorUL[0] = new Point(-99, -99) ;
myDB.SB_data.presence_detectorUL[0] = new Point(-99, -99) ;
myDB.SB_data.signalLit_UL[0] = new Point(-99, -99) ;
}
if (myDB.NB_data.leftTurnLaneExists() | myDB.SB_data.leftTurnLaneExists()) {
for (ij=1; ij<=N; ij++) {
myDB.SB_data.detectorUL[ij] = new Point(center.x-myDB.LOOP_DET_WIDTH/2 - ij*myDB.LANE_WIDTH, intsc_top-myDB.SB_data.detector_dist) ;
myDB.SB_data.presence_detectorUL[ij] = new Point(center.x-myDB.LOOP_DET_WIDTH/2 - ij*myDB.LANE_WIDTH, intsc_top-myDB.SB_data.presence_detector_dist) ;
myDB.SB_data.signalLit_UL[ij] = new Point(center.x-myDB.LANE_WIDTH/2 + signal_head_offset- ij*myDB.LANE_WIDTH, intsc_top-myDB.SIGNAL_HEAD_SIZE) ;
}
} else {
for (ij=1; ij<=N; ij++) {
myDB.SB_data.detectorUL[ij] = new Point(center.x-myDB.LOOP_DET_WIDTH/2 - myDB.LANE_WIDTH/2 -(ij-1)*myDB.LANE_WIDTH, intsc_top-myDB.SB_data.detector_dist) ;
myDB.SB_data.presence_detectorUL[ij] = new Point(center.x-myDB.LOOP_DET_WIDTH/2 - myDB.LANE_WIDTH/2 -(ij-1)*myDB.LANE_WIDTH, intsc_top-myDB.SB_data.presence_detector_dist) ;
myDB.SB_data.signalLit_UL[ij] = new Point(center.x-myDB.LANE_WIDTH/2 + signal_head_offset- myDB.LANE_WIDTH/2 -(ij-1)*myDB.LANE_WIDTH, intsc_top-myDB.SIGNAL_HEAD_SIZE) ;
}
}
// =======================================================================
// sim step thread
runThread_simStep = new Runnable() {
public void run() {
while (true) {
if (sim_step_once) {
if (controller_configured) {
if (myGlobalTime>0) {
// save a copy of current signal timing
saveStepSignalTiming() ;
}
sim_step_toolbar = true ;
startSim() ;
tLast = System.currentTimeMillis();
//myGlobalTime += 1f ; // update global time by 1 sec.
//System.out.println("1 Global Time="+myGlobalTime) ;
do {
try {Thread.sleep(100) ;} // 600 too much
catch (InterruptedException ie) {} ;
} while (!mySignalControl.step_finished) ;
myGlobalTime += 1f ; // update global time by 1 sec.
pauseSim() ;
if (mySignalControl.control_type==2 && sim_step_toolbar) {
// actuated by mouse
//System.out.println("step 1") ;
// clear extension detectors
statusBar_Message(mySignalControl.getRegisteredPhases()) ;
resetDetectors(1) ; // clear extension loop detectors
mySignalControl.resetEXTRegisters() ; // clear controller registers
// repaint() ; // run before clearPresencedetectors & Registers
/* for (int i=0; i<mySignalControl.NUM_PHASES; i++) {
if (mySignalControl.phaseStatus[i]) {
System.out.println("Phase "+(i+1)+" ON") ;
System.out.println("Lit = "+mySignalControl.phaseLitColor[i]) ;
}
}
*/
clearPresenceDetectorsOnGreen() ;
mySignalControl.clearPresenceRegistersOnGreen() ;
//repaint() ;
// System.out.println("R1 phase stage="+mySignalControl.actuatedTimer1.phase_stage) ;
}
//repaint() ; // use repaint thread
} else {
msgBox_title = "Controller Configuration" ;
msgBox_body = "Please configure signal controller and \ndownload controller settings first!" ;
msgBox_flag = true ;
} // if controller configurred
// reset button 3/29/07
tb.status = -1 ;
tb.repaint() ;