-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhDrawArea.java
More file actions
executable file
·4529 lines (4175 loc) · 200 KB
/
hDrawArea.java
File metadata and controls
executable file
·4529 lines (4175 loc) · 200 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
/*
* hDrawArea.java
* Horizontal design class.
*
* Created on March 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 javax.swing.table.* ;
public class hDrawArea extends DoubleBufferedPanel
implements MouseListener, MouseMotionListener
{
toolbar tb; // toolbar
statusbar sb; // status bar
final int grid = 8; // drawarea grid size
final String NO_MAP_MSG = "No contour image loaded.\n\nPlease import contour map as background\nimage first!" ;
vDrawArea vDesign = new vDrawArea();
Applet myApplet ; // applet pointer from parent, Geometry_Design
MenuItem ptr_edit_undo ;
MenuItem ptr_edit_redo ;
MenuItem ptr_edit_delete ;
// variables here
public SHARED myDB = new SHARED() ;
int toolbarIndex = 0 ;
mPoint e0, e1 ; //= DBNull
boolean line_started = false ;
boolean curve_started = false ;
boolean modification_started = false ;
public Image image = null ;
public int imageW = 0, imageH=0 ;
//Graphics g ;
String contourImageFilepath ;
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 ;
// Horizontal geometry DB
public int hRoadDataCount = 0; // number of segments (line/curve)
int segLogIndex = -1;
int[] segLogBuffer = new int[16] ; // undo, redo log
int markLogIndex = -1 ;
int[] markLogBuffer = new int[16] ; // undo, redo log
int endMarkSize = 2 ; // square end mark, actual size (red) = 2*endMarkSize square
// other variables
int myAlpha = 255 ; // declare a Alpha variable
//Dim hAlignMarkerPen, elevationMarkerPen, currentPen As Pen
mPoint modificationInfo ;
String design_filename = "" ;
StationInfo sInfo ; // landmark station info
float calcMinRadius ; // calculated minimum radius (Rv)
int idSegment ;
private String landmarkPrintStr ; // save & print landmark data
private String tangentPrintStr ; // save and print tangent (PC, PT) data
private JTable stationTable = new JTable();
// window frame =================
myWindow frmAbout ;
myWindow frame_msgbox, frame_clearLandmarks ;
myWindow frame_curveSetting, updateRadius ;
myWindow frame_deleteSegment, frame_msgboxClearAll, frmElevationMarker ;
myWindow frame_editCurveSetting ;
myWindow frmEditElevationMarker ;
myWindow frmInsertElevationMarker ; // 2/28/07
myWindow frame_deleteTangent ;
myWindow frame_saveVDesign ; //11/13/06 added
public myWindow frame_settingsDesign, frame_settingsContour;
public myFrame frmVerticalAlign = new myFrame() ;
JFrame frmLandmarkTable = new JFrame("View Landmark Data") ;
JFrame frmTangentTable = new JFrame("View PC, PT Data") ;
PrintUtilities hd_pu, vd_pu ;
// Java GUI
TextField txtEle = new TextField("0");
Checkbox line; // station,landmark option
Checkbox curve; // station,landmark option
Checkbox tangent; // station,landmark option
TextField txtRadius; // curve radius setting
TextField txtEditRadius; // edit curve radius setting
TextField txtImgResol; // edit contour image resolution setting
TextField txtMapScale; // edit contour map scale setting
// design dettings
TextField txtSpeed; // design speed
TextField txtMaxcut; // max cut
TextField txtMaxfill; // max fill
TextField txtMaxgrade; // max grade
TextField txtMingrade; // min grade
TextField txtReactiontime; // reaction time
TextField txtDecel; // veh decel
TextField txtFricoef; // friction coefficient
TextField txtSFricoef; // side friction coefficient
TextField txtVCurLen; // max vertical curve length
TextField txtHCurRadius; // max horizontal curve radius
TextField txtMaxsuperE; // max super elevation
Choice listRoadwidth ;
TextField txtLanewidth; // lane width
Label lblRoadColor ;
Choice listRoadColor ;
TextField txtShoulderwidth; // shoulder width
TextField txtMarkersize; // landmark size
Label lblMarkerColor ;
Choice listMarkerColor; // end mark color
Choice listUnit ; // my unit
Label lblUnit1, lblUnit2, lblUnit3, lblUnit4;
Label lblUnit5, lblUnit6, lblUnit7, lblUnit8;
Label mX, mY, parentID ; // popElevationMarkForm
//PageFormat printPageFormat = new PageFormat() ;
Runnable runThread0 = null ; // stop on red light
public Thread tSetValign ;
public boolean setValign_flag = false ; // accessed from toolbar class
private boolean deleteTangent_flag = false ;
private boolean popCurveSettings_flag = false ;
private boolean popMsgBox_flag = false ;
private boolean viewRoadOnly_flag = false ;
private String msgBox_title = "" ;
private String msgBox_message = "" ;
private String item_clicked_str = "" ; // used for right mouse delete
private myIcon iconQ = new myIcon("question_mark") ;
//==================================================================
// class initialization
hDrawArea()
{
}
hDrawArea(toolbar t, statusbar s, MenuItem mUndo, MenuItem mRedo, MenuItem mDel)
{
tb = t;
sb = s;
ptr_edit_undo = mUndo ;
ptr_edit_redo = mRedo ;
ptr_edit_delete = mDel ;
setBackground(Color.white);
t.parent = this;
s.parent = this;
// =======================================================================
// bring vertical design to top display thread
// =====================================================================
runThread0 = new Runnable() {
public void run() {
while (true) {
if (popMsgBox_flag){
popMessageBox1(msgBox_title, msgBox_message);
popMsgBox_flag = false ;
} else if (setValign_flag){
newstatus(10, " Vertical Curve Design");
setValign_flag = false ;
} else if (deleteTangent_flag) {
popDeleteTangent("Delete Tangent Data","Do you want to delete tangent data pair?");
deleteTangent_flag = false ;
} else if (popCurveSettings_flag) {
popCurveSettings();
popCurveSettings_flag = false ;
} else {
tSetValign.yield();
try {Thread.sleep(100) ;}
catch (InterruptedException ie) {} ;
}
}
} // void run
} ; // runThread 0
tSetValign = new Thread(runThread0, "VerticalAlign") ;
tSetValign.start() ;
}
// object initialization
public void init(int flag) {
if (this.getMouseListeners().length==0) {
// add mouse listener if not already included
addMouseListener(this);
addMouseMotionListener(this);
}
frmAbout = new myWindow();
myDB.imageScale = (float)myDB.ContourImageResolution / (float)myDB.ContourScale; // // pixel/ft
if (flag==0) {
myDB.hAlignMarkCount = 0;
myDB.elevationMarkCount = 0;
myDB.vConstructMarkCount = 0;
myDB.currentElevationMarker = new mPointF(0f, 0f);
}
myDB.curveRadius = myDB.minHCurveRadius ; // set to min
//animationFlag = false;
int i ;
for (i=0;i<segLogBuffer.length;i++) {
segLogBuffer[i] = -1;
markLogBuffer[i] = -1;
}
push2SegLogBuffer(hRoadDataCount);
push2MarkLogBuffer(myDB.elevationMarkCount);
sb.setStatusBarText(3, new Float(Math.round(draw_scale*10f)/10f).toString()) ;
processImage();
}
// process image file
public void processImage() {
PixelGrabber pg=new PixelGrabber(image,0,0,-1,-1,true);
try{
if(pg.grabPixels()){
imageW=pg.getWidth();
imageH=pg.getHeight();
// int[] op=(int[]) pg.getPixels();
// int[] np=(int[]) new int[w*w];
// g.drawImage(image,0,0,this);
}
} catch(InterruptedException ie){
sb.setStatusBarText(1, "Error: "+ie.toString()) ;
}
}
// methods
// added 11/17/06 to process angle (deg) after generated by ATAN2
// when vectors span over +/- PI boundary
private double processAngle(double angle) {
double angle_ret=0 ;
if (angle > 180) {
angle_ret = angle - 360;
} else if (angle < -180) {
angle_ret = angle + 360 ;
} else {
angle_ret = angle ;
}
return angle_ret ;
}
// paint method to draw the panel area
public void paint(Graphics gr)
{
Graphics2D g = (Graphics2D)gr ;
int w=imageW;
int h=imageH;
if(image!=null){
if (draw_scale == 1) {
g.drawImage(image, translate.X, translate.Y, w, h, this);
} else {
// scaled repaint
g.drawImage(image, scaledxlate.X, scaledxlate.Y, CInt(w * draw_scale), CInt(h * draw_scale), this);
}
// line / curve construction
switch (toolbarIndex) {
case 3: // move
if (mouseHoldDown==true) {
//g.Clear(PictureBox1.BackColor)
if (draw_scale == 1 ) {
g.drawImage(image, translate.X + translate_delta.X, translate.Y + translate_delta.Y, w, h, this);
} else {
g.drawImage(image, scaledxlate.X + scaledxlate_delta.X, scaledxlate.Y + scaledxlate_delta.Y,
CInt(w * draw_scale), CInt(h * draw_scale), this);
}
}
break;
case 4: // // line
if (line_started && e0!=null && e1!=null) {
g.setColor(Color.red) ;
g.setStroke(new BasicStroke(2));
g.draw( new Rectangle( e0.X - 2, e0.Y - 2, 4, 4));
g.draw(new Rectangle( e1.X - 2, e1.Y - 2, 4, 4));
//currentPen = New Pen(Color.FromArgb(myAlpha, myPenColor), myRoadLaneSizes) //Set up the pen
g.setColor(myDB.myPenColor) ;
g.setStroke(new BasicStroke(CInt(myDB.myRoadLaneSizes)));
g.drawLine(e0.X, e0.Y, e1.X, e1.Y);
/*System.out.println("e0.x="+e0.X);
System.out.println("e0.y="+e0.Y);
System.out.println("e1.x="+e1.X);
System.out.println("e1.y="+e1.Y);
*/
}
break;
case 5: // // curve
if (curve_started==true && e1!=null ){
//currentPen = New Pen(Color.FromArgb(myAlpha, myPenColor), myRoadLaneSizes) //Set up the pen
g.setColor(myDB.myPenColor) ;
g.setStroke(new BasicStroke(CInt(myDB.myRoadLaneSizes)));
int pixelRadius ;
pixelRadius = CInt(myDB.curveRadius * myDB.imageScale * draw_scale) ; // trandform to draw scale
g.drawOval( e1.X - pixelRadius, e1.Y - pixelRadius, pixelRadius * 2, pixelRadius * 2);
//System.out.println("e0.x="+e0.X);
//System.out.println("e0.y="+e0.Y);
//System.out.println("r="+pixelRadius);
}
break;
} // end switch
// ==============================
int i ;
mPoint p1, p2 ;
// 11/16/06 modified
if (viewRoadOnly_flag) {
// view road only
if (myDB.elevationMarkCount >= 2 ) {
// 2 or more elevation data exists
for (i=1; i<myDB.elevationMarkCount; i++) {
p1 = drawTransform(myDB.elevationMarks[i-1].getLocation());// // start point
p2 = drawTransform(myDB.elevationMarks[i].getLocation());// // end point
int curveID, pixelRadius ;
float myRadius ;
mPoint pc ;
double start_angle, end_angle, angle_len ;
//g.setColor(myDB.hRoadData[0].getPenColor()) ;
g.setColor(myDB.myPenColor) ;
g.setStroke(new BasicStroke(CInt(myDB.myRoadLaneSizes*1.5))); // 2/9/07
//System.out.println("type="+myDB.elevationMarks[i-1].getSegmentType()) ;
switch (myDB.elevationMarks[i-1].getSegmentType()) {
case 1: // line
g.drawLine( p1.X, p1.Y, p2.X, p2.Y);
break ;
case 2: // Curve
curveID = myDB.elevationMarks[i-1].getParentIndex() ;
myRadius = myDB.hRoadData[curveID].getRadius() * draw_scale;
pixelRadius = CInt(myRadius * myDB.imageScale);
pc = drawTransform(myDB.hRoadData[curveID].getPoint1()) ; // curve center
start_angle = vectorAngle(pc, p1) ;
end_angle = vectorAngle(pc, p2) ;
angle_len = end_angle - start_angle ;
//System.out.println("start, end, len b4="+start_angle+","+end_angle+","+angle_len) ;
angle_len = processAngle(angle_len) ;
//System.out.println("len after="+angle_len) ;
//System.out.println("ID, radius="+curveID + ","+pixelRadius) ;
//System.out.println("vec1 len="+vectorLen(vector(pc, p1))) ;
//System.out.println("vec2 len="+vectorLen(vector(pc, p2))) ;
g.drawArc(pc.X - pixelRadius, pc.Y - pixelRadius, pixelRadius * 2, pixelRadius * 2,
CInt(start_angle), CInt(angle_len));
break ;
case 3: // tangent
if (myDB.elevationMarks[i].getSegmentType()==1) {
// line
g.drawLine( p1.X, p1.Y, p2.X, p2.Y);
} else {
curveID = myDB.elevationMarks[i-1].getParentIndex() ;
//System.out.println("landmark index="+(i+1)) ;
//System.out.println("curve ID="+curveID) ;
myRadius = myDB.hRoadData[curveID].getRadius() * draw_scale;
pixelRadius = CInt(myRadius * myDB.imageScale);
pc = drawTransform(myDB.hRoadData[curveID].getPoint1()) ;
start_angle = vectorAngle(pc, p1) ;
end_angle = vectorAngle(pc, p2) ;
angle_len = end_angle - start_angle ;
angle_len = processAngle(angle_len) ;
g.drawArc(pc.X - pixelRadius, pc.Y - pixelRadius, pixelRadius * 2, pixelRadius * 2,
CInt(start_angle), CInt(angle_len));
// curve
} // if
break ;
} // switch
} // for i
// end view road only
} else {
popMessageBox("View Road Only","Please place at least 2 elevation landmarks!");
viewRoadOnly_flag = false ;
}
} else {
// view design including construct line/curve
if (hRoadDataCount > 0) {
for (i=0;i<hRoadDataCount;i++){
if (!myDB.hRoadData[i].isDeleted()) {
// segment is not deleted
// repaint data
if (myDB.hRoadData[i].getRadius() > 0f) {
// curve
float myRadius ;
p1 = drawTransform(myDB.hRoadData[i].getPoint1());
g.setColor(Color.red) ;
g.setStroke(new BasicStroke(2));
g.draw(new Rectangle( CInt(p1.X - endMarkSize ),
CInt(p1.Y - endMarkSize ),
CInt(2 * endMarkSize ),
CInt(2 * endMarkSize ))) ;// // center
myRadius = myDB.hRoadData[i].getRadius() * draw_scale;
//myCurPen = New Pen(Color.FromArgb(myAlpha, hRoadData(i).getPenColor()), hRoadData(i).getPenWidth) //Set up the pen
g.setColor(myDB.hRoadData[i].getPenColor()) ;
g.setStroke(new BasicStroke(CInt(myDB.myRoadLaneSizes)));
int pixelRadius;
pixelRadius = CInt(myRadius * myDB.imageScale);
g.drawOval(p1.X - pixelRadius, p1.Y - pixelRadius, pixelRadius * 2, pixelRadius * 2);
} else {
// line
p1 = drawTransform(myDB.hRoadData[i].getPoint1());// // start point
p2 = drawTransform(myDB.hRoadData[i].getPoint2());// // end point
g.setColor(Color.red) ;
g.setStroke(new BasicStroke(2));
g.draw(new Rectangle( CInt(p1.X - endMarkSize ),
CInt(p1.Y - endMarkSize ),
CInt(2 * endMarkSize ),
CInt(2 * endMarkSize )));
g.draw(new Rectangle( CInt(p2.X - endMarkSize ),
CInt(p2.Y - endMarkSize ),
CInt(2 * endMarkSize ),
CInt(2 * endMarkSize )));
//myCurPen = New Pen(Color.FromArgb(myAlpha, hRoadData(i).getPenColor()), hRoadData(i).getPenWidth); ////Set up the pen
g.setColor(myDB.hRoadData[i].getPenColor()) ;
g.setStroke(new BasicStroke(CInt(myDB.myRoadLaneSizes)));
g.drawLine( p1.X, p1.Y, p2.X, p2.Y);
} // if line or curve
} // if not deleted
} // for
} //hRoadDataCount
} // if viewRoadOnly_flag
// hAlignMarks
if (myDB.hAlignMarkCount > 0) {
for (i=0;i<myDB.hAlignMarkCount;i++){
p1 = drawTransform(myDB.hAlignMarks[i].getLocation()); // // tangent point
g.setColor(Color.red) ;
g.setStroke(new BasicStroke(2));
g.drawOval( p1.X - 2, p1.Y - 2, 4, 4);
}
}
// elevation markers
//elevationMarkerPen = New Pen(Color.FromArgb(myAlpha, elevationMarkerColor), elevationMarkerSize) //Set up elevation marker pen
g.setColor(myDB.elevationMarkerColor) ;
g.setStroke(new BasicStroke(myDB.elevationMarkerSize));
if (myDB.elevationMarkCount > 0 ) {
for (i=0;i<myDB.elevationMarkCount;i++){
p1 = drawTransform(myDB.elevationMarks[i].getLocation()) ;// // marker point
g.drawOval( p1.X - 2, p1.Y - 2, 4, 4);
}
}
// animation
/*
If animationFlag Then
// animation ON
// draw a starting mark only
If myUnit = 1 Then
// US
p1 = drawTransform(New PointF(animatedVehPos.X / FT2M * imageScale, animatedVehPos.Z / FT2M * imageScale))
ElseIf myUnit = 2 Then
p1 = drawTransform(New PointF(animatedVehPos.X * imageScale, animatedVehPos.Z * imageScale))
End If
Dim pur_pen4 As Pen = New Pen(Color.Purple, 4)
g.DrawEllipse(pur_pen4, p1.X - 5, p1.Y - 5, 10, 10)
End If
*/
} // image != null?
else {
Rectangle r = bounds();
if(grid>0)
{
g.setColor(new Color(224,224,224)); // sub grid lines
for(int i=grid;i<r.height;i+=grid)
g.drawLine(0,i,r.width,i);
for(int i=grid;i<r.width;i+=grid)
g.drawLine(i,0,i,r.height);
g.setColor(new Color(184,184,184)); // major grid lines
for(int i=grid*10;i<r.height;i+=grid*10)
g.drawLine(0,i,r.width,i);
for(int i=grid*10;i<r.width;i+=grid*10)
g.drawLine(i,0,i,r.height);
} // draw grid
} // image=null?
} // end of paint
// mouse key down method
public boolean keyDown(Event e,int k)
{
return(true);
}
// update toolbar index
public void newstatus(int index, String str)
{
sb.setStatusBarText(0, str) ;
toolbarIndex = index ;
if (toolbarIndex==0) {
ptr_edit_delete.setEnabled(true) ;
} else {
ptr_edit_delete.setEnabled(false) ;
}
//for(grobj j = glist.ghead;j!=null;j=j.next)
//{ j.select = 0;
//}
if (toolbarIndex==4 | toolbarIndex==5 | toolbarIndex==8) {
// line curve & marker
ptr_edit_undo.setEnabled(true) ;
ptr_edit_redo.setEnabled(true) ;
} else {
ptr_edit_undo.setEnabled(false) ;
ptr_edit_redo.setEnabled(false) ;
}
switch (toolbarIndex) {
case 0: // pointer
break ;
case 1: // zoomin
changeDrawScale(0.1f);
repaint();
break ;
case 2: // zoom out
changeDrawScale(-0.1f);
repaint();
break ;
case 3: // move
break ;
case 4: // line
if (image==null){
popMessageBox("No Contour Map", NO_MAP_MSG);
//frame_msgbox.toFront() ;
}
viewRoadOnly_flag = false ; // 11/16/06
break ;
case 5: // curve
if (frame_curveSetting==null){
//popCurveSettings();
popCurveSettings_flag = true ;
} else { // not null
if (frame_curveSetting.isShowing()==false){
//popCurveSettings();
popCurveSettings_flag = true ;
} else {
frame_curveSetting.show();
}
frame_curveSetting.toFront();
}
viewRoadOnly_flag = false ; // 11/16/06
repaint();
break ;
case 6: // edit end point
if (image==null){
popMessageBox("No Contour Map", NO_MAP_MSG);
//frame_msgbox.toFront() ;
}
viewRoadOnly_flag = false ; // 11/16/06
break ;
case 7: // horizontal curve alignment
if (image==null){
popMessageBox("No Contour Map", NO_MAP_MSG);
//frame_msgbox.toFront() ;
} else {
tool_curvehAlignMarks();
}
viewRoadOnly_flag = false ; // 11/16/06
break ;
case 8: // place station, marker
if (image==null){
popMessageBox("No Contour Map", NO_MAP_MSG);
//frame_msgbox.toFront() ;
}
viewRoadOnly_flag = false ; // 11/16/06
break ;
case 9: // refresh, marker insert
//repaint();
// insert landmark
if (image==null){
popMessageBox("No Contour Map", NO_MAP_MSG);
//frame_msgbox.toFront() ;
}
viewRoadOnly_flag = false ;
break ;
case 10: // vertical curve design
if (image==null){
popMessageBox("No Contour Map", NO_MAP_MSG);
//frame_msgbox.toFront() ;
} else if (myDB.elevationMarkCount < 2 ) {
popMessageBox("Vertical Curve Design","Please place at least 2 elevation landmarks first!");
//frame_msgbox.toFront() ;
//} else if (design_filename.Length <= 0) {
// design filename does not exist
//result = MessageBox.Show("Save horizontal geometry design?", "Save Design", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
//If result = DialogResult.OK Then
// file_save_Click(Nothing, Nothing)
//End If
//startVerticalDesign();
} else {
//startVerticalDesign();
String status = checkLandmarks() ; // added 3/1/07
if (status.length()>0) {
popMessageBox("Landmark Data Error", "Error at landmark station "+status+
".\nPlease include tangent point when making \ntransition between line and curve segments.\n"+
"Use View->Station Landmarks to review data.");
} else {
if (frmVerticalAlign==null){
// javax.swing.SwingUtilities.invokeLater(new Runnable() {
// public void run() {
popVerticalAlign("Vertical Curve Design");
// }
// });
} else { // not null
if (frmVerticalAlign.isShowing()==false){
popVerticalAlign("Vertical Curve Design");
} else {
frmVerticalAlign.show();
}
} // if (frmVerticalAlign==null)
//javax.swing.SwingUtilities.invokeLater(new Runnable() {
// public void run() {
//try{
// Thread.sleep(500);
//} catch(InterruptedException e){
//System.out.println("Sleep Interrupted");
//}
frmVerticalAlign.toFront();
// }
//});
} // if
} // if elevationMarkCount < 2
break ;
}
//repaint();
}
public void changeDrawScale(float scale) {
draw_scale += scale ;
if (draw_scale > 5.0f) {
draw_scale = 5.0f;
}
else if (draw_scale < 0.1f) {
draw_scale = 0.1f ;
}
sb.setStatusBarText(3, new Float(Math.round(draw_scale*10f)/10f).toString()) ;
imageResize() ;
}
public void imageResize() {
Rectangle r = bounds();
scaledxlate.X = CInt(0.5f * r.width * (1 - draw_scale) + draw_scale * translate.X);
scaledxlate.Y = CInt(0.5f * r.height * (1 - draw_scale) + draw_scale * translate.Y);
repaint();
//PictureBox1.Invalidate()
}
//public boolean mouseDown(Event e, int x, int y)
public boolean mouseDown(int x, int y)
{
sb.setStatusBarText(2, Integer.toString(x)+","+Integer.toString(y)) ;
switch (toolbarIndex) {
case 3: // move
e0 = new mPoint(x, y) ;
mouseHoldDown = true ;
break ;
case 4: // line
line_started = true;
e0 = new mPoint(x, y) ;
//System.out.println("line-down");
break ;
case 5: // // curve
// construct curve
// if e.M MouseButtons.Left {
curve_started = true;
e0 = new mPoint(x, y) ;
// }
break ;
case 6: // // modify line/curve
// check if click a point or a line
modificationInfo = searchSegmentDB(transform(new mPoint(x, y))) ;
//System.out.println("X,Y = " + modificationInfo.X + "," + modificationInfo.Y) ;
if (modificationInfo.X >= 0 && modificationInfo.Y >= 0) {
// closest segment terminal found
modification_started = true;
}
break ;
} // end switch
return(true);
}
public mPoint searchSegmentDB(mPointF ptf ) {
// transform pt from screen pixel to actual unit
int i ;
float dist;
mPoint data = new mPoint(-1, -1);
for (i=0 ; i<hRoadDataCount; i++){
// check point 1 or center of radius if a circle
dist = distanceOf(myDB.hRoadData[i].getPoint1(), ptf);
//System.out.println("end pt1="+dist) ;
if (dist <= endMarkSize*2f/draw_scale ) { //Math.sqrt(2), 10/11/06
data.X = i;
data.Y = 1;
break;
}
// check poitn 2
dist = distanceOf(myDB.hRoadData[i].getPoint2(), ptf);
//System.out.println("end pt2="+dist) ;
if (dist <= endMarkSize*2f/draw_scale) { //Math.sqrt(2), 10/11/06
data.X = i;
data.Y = 2;
break;
}
}//end for
return data;
}
// transform mouse click position on the screen to pixel location on the digital map
public mPointF transform(mPoint input) {
mPointF ptf = new mPointF(0f,0f);
if (draw_scale == 1f) {
ptf.X = (input.X - translate.X);
ptf.Y = (input.Y - translate.Y);
} else {
ptf.X = (input.X - scaledxlate.X) / draw_scale;
ptf.Y = (input.Y - scaledxlate.Y) / draw_scale;
}
return ptf;
}
// transform location saved onthe DB to relative position on screen
public mPoint drawTransform(mPointF input) {
mPoint ptf = new mPoint(0,0);
if (draw_scale == 1) {
ptf.X = CInt(input.X + translate.X + translate_delta.X);
ptf.Y = CInt(input.Y + translate.Y + translate_delta.Y);
} else {
ptf.X = CInt(input.X * draw_scale + scaledxlate.X + scaledxlate_delta.X);
ptf.Y = CInt(input.Y * draw_scale + scaledxlate.Y + scaledxlate_delta.Y);
}
return ptf;
}
public int popSegLogBuffer() {
// pop the current # of data from log buffer
if (segLogIndex > 0) {
segLogIndex -= 1;
return segLogBuffer[segLogIndex];
} else {
return -99;
}
}
public int popMarkLogBuffer(){
// pop the current # of landmark data from log buffer
if (markLogIndex > 0) {
markLogIndex -= 1;
return markLogBuffer[markLogIndex];
} else {
return -99;
}
}
public void push2SegLogBuffer(int _myhRoadDataCount){
// save # of data into log buffer
if (segLogIndex == segLogBuffer.length - 1 ) {
// buffer fulled
// shift forward by 1
int i ;
for (i=0; i<segLogIndex; i++) {
segLogBuffer[i] = segLogBuffer[i + 1];
}
segLogBuffer[segLogIndex] = _myhRoadDataCount;
} else {
segLogIndex += 1;
segLogBuffer[segLogIndex] = _myhRoadDataCount;
}
}
public void push2MarkLogBuffer(int _myLandmarkCount ) {
// save # of data into log buffer
if (markLogIndex == markLogBuffer.length - 1) {
// buffer fulled
// shift forward by 1
int i;
for (i=0; i<markLogIndex;i++){
markLogBuffer[i] = markLogBuffer[i + 1];
}
markLogBuffer[markLogIndex] = _myLandmarkCount;
} else {
markLogIndex += 1;
markLogBuffer[markLogIndex] = _myLandmarkCount;
}
}
//public boolean mouseDrag(Event e, int x, int y)
public boolean mouseLeftDrag(int x, int y)
{
sb.setStatusBarText(2, Integer.toString(x)+","+Integer.toString(y)) ;
//System.out.println("toolbar index=" + toolbarIndex) ;
switch (toolbarIndex){
case 3: // move
if (image != null ){
if (e0!=null) { // Is Nothing And mouseHoldDown Then
if (draw_scale == 1) {
translate_delta.X = x - e0.X;
translate_delta.Y = y - e0.Y;
} else {
translate_delta.X = CInt((x - e0.X) / draw_scale);
translate_delta.Y = CInt((y - e0.Y) / draw_scale);
scaledxlate_delta.X = (x - e0.X);
scaledxlate_delta.Y = (y - e0.Y);
}
e1 = new mPoint(x,y);
repaint();
}
} // if image
else { // g is not defined
popMessageBox("No Contour Map", NO_MAP_MSG);
toolbarIndex = 0;
} // else
break;
case 4 : // line
if (image != null ){
e1 = new mPoint(x,y);
repaint();
}
else { // g is not defined
popMessageBox("No Contour Map", NO_MAP_MSG);
toolbarIndex = 0;
} // else
break;
case 5 : // curve
if (image != null ){
e1 = new mPoint(x,y);
repaint();
}
else { // g is not defined
popMessageBox("No Contour Map", NO_MAP_MSG);
toolbarIndex = 0;
} // else
break;
case 6: // modify
if (image != null ){
//System.out.println("modification_started=" + modification_started) ;
if (modification_started) { // modify end control point
int dataIndex = modificationInfo.X;
int pointId = modificationInfo.Y;
//System.out.println("x, y = " + dataIndex + ", " + pointId) ;
myDB.hRoadData[dataIndex].modifyPoint(pointId, transform(new mPoint(x,y)));
//System.out.println("idx="+dataIndex+", id="+pointId);
repaint();
}
e1 = new mPoint(x,y);
}
else { // g is not defined
popMessageBox("No Contour Map", NO_MAP_MSG);
toolbarIndex = 0;
} // else
break;
} // end switch
return (true);
}
//public boolean mouseUp(Event e, int x, int y)
public boolean mouseLeftUp(int x, int y)
{
int dataIndex = -1;
int tangentIndex = -1 ;
mPointF marker = transform(new mPoint(x,y));
sb.setStatusBarText(2, Integer.toString(x)+","+Integer.toString(y)) ;
switch (toolbarIndex){
case 0: // // pointer, select
checkItemSelect(transform(new mPoint(x,y)));
repaint();
break;
case 3: // // move
translate_delta = new mPoint(0, 0);
scaledxlate_delta = new mPoint(0, 0);
if (e1 != null ) {
mouseHoldDown = false;
if (draw_scale == 1) {
translate.X += e1.X - e0.X;
translate.Y += e1.Y - e0.Y;
} else {
translate.X += CInt((e1.X - e0.X) / draw_scale);
translate.Y += CInt((e1.Y - e0.Y) / draw_scale);
scaledxlate.X += (e1.X - e0.X);
scaledxlate.Y += (e1.Y - e0.Y);
}
e0 = null;
e1 = null;
repaint();
}
break;
case 4: // // line
if (e1 !=null && e0 != null) {
line_started = false;
myDB.hRoadData[hRoadDataCount] = new Data2D() ;
myDB.hRoadData[hRoadDataCount].saveData(transform(e0), transform(e1), myDB.myPenColor, myDB.myRoadLaneSizes);
// debug
//debugWindow.Text &= "P1=" & hRoadData(hRoadDataCount).getPoint1.X & ", " & hRoadData(hRoadDataCount).getPoint1.Y
//debugWindow.Text &= "P2=" & hRoadData(hRoadDataCount).getPoint2.X & ", " & hRoadData(hRoadDataCount).getPoint2.Y & vbCrLf
hRoadDataCount += 1;
// save # of data in log buffer
push2SegLogBuffer(hRoadDataCount);
e0 = null;
e1 = null;
repaint();
}
break;
case 5: // // curve
if ( e1 !=null ) {
curve_started = false;
myDB.hRoadData[hRoadDataCount] = new Data2D();
myDB.hRoadData[hRoadDataCount].saveData(transform(e1), myDB.curveRadius, myDB.myPenColor, myDB.myRoadLaneSizes);
hRoadDataCount += 1;
// save # of data in log buffer
push2SegLogBuffer(hRoadDataCount);
e0 = null;
e1 = null;
repaint();
}
break;
case 6: // // Modify
modification_started = false;
break;
case 8: // Set elevation marker
dataIndex = -1;
tangentIndex = -1 ;
marker = transform(new mPoint(x,y));
tangentIndex = checkTangentLandmarks(marker);
if (tangentIndex < 0) {
dataIndex = checkMarkLocation(marker);
} else {
dataIndex = tangentIndex;
}
//System.out.println("dataIndex="+dataIndex+", tangentIndex="+tangentIndex);
if (dataIndex < 0) {
popMessageBox( "Elevation Marker", "Please place marker on line/curve segments");
} else {
// comment out 3/4/06, using database point in checkMarkLocation()
//currentElevationMarker = marker
// pop screen to enter evelation & save marker data
if (frmElevationMarker != null) {
if (frmElevationMarker.isShowing()) {
frmElevationMarker.dispose();
}
}
sInfo = new StationInfo();
sInfo.title="Station (" + (myDB.elevationMarkCount + 1) + ")" ;
sInfo.CheckBox_edit = false;
sInfo.parentId = dataIndex;
sInfo.location = myDB.currentElevationMarker ;
sInfo.optionInit();
if (tangentIndex >= 0){
sInfo.tangent_option = true ;
sInfo.initial_state = 3 ; // tangent
} else if (myDB.hRoadData[dataIndex].getRadius() > 0) {
sInfo.curve_option = true ;
sInfo.initial_state = 2 ; // curve
} else {
sInfo.line_option = true ;
sInfo.initial_state = 1 ; // line
}
popElevationMarkerForm();