Repository navigation
Expand file tree
/
Copy pathEdit2.pas
More file actions
2194 lines (2110 loc) · 70.2 KB
/
Copy pathEdit2.pas
File metadata and controls
2194 lines (2110 loc) · 70.2 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
unit Edit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, ExtCtrls, Menus, Types, StdCtrls, Clipbrd, math, Printers;
type
TTectData = (td_DipDir, td_Dip, td_fpDipDir, td_fpDip, td_Azimuth, td_plunge,
td_sense, td_Quality, td_Comment, td_unknown, td_NDataset, td_Integer,
td_Pitch);
TDataValidity = (dv_valid, dv_invalid, dv_empty);
TEdit2Frm = class(TForm)
StringGrid1: TStringGrid;
Panel1: TPanel;
MainMenu1: TMainMenu;
EditFile1: TMenuItem;
New1: TMenuItem;
Open1: TMenuItem;
Close1: TMenuItem;
Separator1: TMenuItem;
Save1: TMenuItem;
Saveas1: TMenuItem;
Separator5: TMenuItem;
Sort1: TMenuItem;
Convert1: TMenuItem;
Correct1: TMenuItem;
Separator2: TMenuItem;
Print1: TMenuItem;
PriStp: TMenuItem;
Separator3: TMenuItem;
Exit1: TMenuItem;
EditEdit: TMenuItem;
Undo1: TMenuItem;
Redo1: TMenuItem;
N3: TMenuItem;
EditCut: TMenuItem;
EditCopy: TMenuItem;
EditPaste: TMenuItem;
Delete1: TMenuItem;
N2: TMenuItem;
Find1: TMenuItem;
FindNext1: TMenuItem;
Replace1: TMenuItem;
SelectAll1: TMenuItem;
Settings1: TMenuItem;
Fonts1: TMenuItem;
N6: TMenuItem;
Options1: TMenuItem;
NewD2ndVersion1: TMenuItem;
OD2ndVersion1: TMenuItem;
SaveDialog1: TSaveDialog;
Editor1: TMenuItem;
PopupMenu1: TPopupMenu;
Undo2: TMenuItem;
Redo2: TMenuItem;
N4: TMenuItem;
Cut1: TMenuItem;
Copy1: TMenuItem;
Paste1: TMenuItem;
Delete2: TMenuItem;
N5: TMenuItem;
SelectAll2: TMenuItem;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
E2Y: TEdit;
E2Z: TEdit;
Label4: TLabel;
E2Location: TEdit;
E2X: TEdit;
E2Lithology: TEdit;
E2Date: TEdit;
Label6: TLabel;
Label7: TLabel;
N7: TMenuItem;
Selectdataset1: TMenuItem;
N8: TMenuItem;
Deletedataset1: TMenuItem;
Goto1: TMenuItem;
First1: TMenuItem;
Last1: TMenuItem;
Next1: TMenuItem;
Previous1: TMenuItem;
New2: TMenuItem;
Insertdataset1: TMenuItem;
E2Formation: TEdit;
Label8: TLabel;
E2Remarks: TEdit;
Label5: TLabel;
E2Age: TEdit;
Label9: TLabel;
Label10: TLabel;
E2TectUnit: TEdit;
procedure Open(Sender: TObject; const AFilename, AParentFileName: string; const AExtension: TExtension; ANew, AReadOnly : boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure OD2ndVersion1Click(Sender: TObject);
procedure NewD2ndVersion1Click(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Save1Click(Sender: TObject);
function Saveas1Click(Sender: TObject): Boolean;
procedure Open1Click(Sender: TObject);
procedure New1Click(Sender: TObject);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1SelectCell(Sender: TObject; Col, Row: Longint;
var CanSelect: Boolean);
procedure Fonts1Click(Sender: TObject);
procedure Options1Click(Sender: TObject);
procedure EditEditClick(Sender: TObject);
procedure EditCopyClick(Sender: TObject);
procedure EditPasteClick(Sender: TObject);
procedure Close1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Sort1Click(Sender: TObject);
procedure Convert1Click(Sender: TObject);
procedure Correct1Click(Sender: TObject);
procedure EditFile1Click(Sender: TObject);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Undo1Click(Sender: TObject);
procedure StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PopupMenu1Popup(Sender: TObject);
procedure E2YChange(Sender: TObject);
procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure EditCutClick(Sender: TObject);
procedure StringGrid1DblClick(Sender: TObject);
procedure Delete1Click(Sender: TObject);
procedure Deletedataset1Click(Sender: TObject);
procedure DeleteRows(Sender: TObject);
procedure DeleteRow(FRow: LongInt);
procedure Selectdataset1Click(Sender: TObject);
procedure SelectAll1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Goto1Click(Sender: TObject);
procedure First1Click(Sender: TObject);
procedure Last1Click(Sender: TObject);
procedure Next1Click(Sender: TObject);
procedure Previous1Click(Sender: TObject);
procedure Redo1Click(Sender: TObject);
procedure Insertdataset1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Print1Click(Sender: TObject);
procedure PriStpClick(Sender: TObject);
procedure StringGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FillPrintCanvas(MyCanvas: TCanvas);
private
FModified: boolean;
procedure SetModified(Value: boolean);
property Modified: boolean read FModified write SetModified;
protected
MyFileName, MyParentFileName: string;
E2Extension: TExtension;
new, failed, BeepOn, undoing, CanCloseForm, creating,
fundo, StartSelecting, ReadOnly, FExternalFileFormat: boolean;
Sense,Quality: Integer;
Azimuth,Plunge, DipDir, Dip : Single;
OldCol, OldRow: Integer;
MouseCol, MouseRow, DeltaCol, DeltaRow, DeltaMouseCol, DeltaMouseRow, coldummy, rowdummy : LongInt;
DrawingSelection: TGridRect;
E2LocationInfo: TLocationInfo;
function GetColidentifier(FCol: Integer): String;
function CanDrop(FRange: TGridRect): Boolean;
procedure SwapSelection(var ASelection: TRect; vertical: Boolean);
procedure GetTargetRect(FString: String; var FGridRect: TGridRect);
procedure NewRow(Sender: TObject);
function CheckData(Sender: TObject; FCol, FRow: LongInt): TDatavalidity;
function AutoFillCell(Sender: TObject; FCol, FRow: LongInt): Boolean;
function GetDataType(FCol: Integer): TTectData;
function CheckRow(Sender: TObject; var FCol: LongInt; FRow: Longint): TDatavalidity;
procedure StringGrid1ShowEditor(Sender: TObject);
procedure StringGrid1SelectCells(Sender: TObject; Shift: TShiftState; X, Y: Integer);
//procedure StringGrid1WMTimer; message WM_Timer;
end;
var Edit2Frm: TEdit2Frm;
function FloatToString2(FValue: Double; digits1,digits2: Integer): String;
implementation
uses Tecmain, FileOps;
{$R *.DFM}
procedure TEdit2Frm.StringGrid1ShowEditor(Sender: TObject);
begin
if StringGrid1.inplaceeditor<>nil then case GetDataType(StringGrid1.Col) of
td_dipdir, td_fpDipDir, td_Azimuth: StringGrid1.InplaceEditor.Maxlength:=6;
td_Dip, td_fpDip, td_Plunge: StringGrid1.InplaceEditor.Maxlength:=5;
td_Sense, td_Quality: StringGrid1.InplaceEditor.Maxlength:=1;
td_Comment: StringGrid1.InplaceEditor.Maxlength:=255;
end;
end;
procedure TEdit2Frm.SetModified(Value: boolean);
begin
if Value then
begin
TecMainWin.StatusBar1.Panels.Items[0].Text:='Modified';
TecMainWin.SaveBtn.Enabled:=true;
end
else
begin
TecMainWin.StatusBar1.Panels.Items[0].Text:='';
TecMainWin.SaveBtn.Enabled:=false;
end;
If FModified<>Value then FModified:=Value;
end;
procedure TEdit2Frm.Open(Sender: TObject; const AFilename, AParentFileName: string; const AExtension: TExtension; ANew, AReadOnly : boolean);
var f: textfile;
i: integer;
NoComment: boolean;
Comment: String;
AzimB, PlungeB,AzimP, PlungeP, AzimT, PlungeT, Pitch: Single;
Bew: Integer;
begin
Screen.Cursor:= crHourglass;
Creating:= true;
BeepOn:=E2BeepOn;
MyFileName := AFilename;
MyParentFileName := AParentFilename;
ReadOnly:=AReadOnly;
E2Extension := AExtension;
if e2extension=ptf then
begin
readonly:=true;
saveas1.enabled:=false;
end;
if readonly then
begin
Deletedataset1.enabled:=false;
Insertdataset1.enabled:=false;
for I := 0 to ComponentCount -1 do
if Components[I] is TEdit then (Components[I] as TEdit).Readonly:=true;
end;
New:=ANew;
Caption := Caption +' - ['+ ExtractFilename(MyFileName) +']';
Modified:= false;
with StringGrid1 do
begin
Font:=TecMainWin.Edit2FontDialog.Font;
Case E2Extension of
COR, FPL, HOE, PEF, PEK, STF:
begin
ColCount:=8;
cells[0,0]:='Dataset';
cells[1,0]:='DipDir';
cells[2,0]:='Dip';
cells[3,0]:='Azimuth';
cells[4,0]:='Plunge';
cells[5,0]:='Sense';
cells[6,0]:='Quality';
cells[7,0]:='Comment';
end;
PTF:
begin
ColCount:=15;
cells[0,0]:='Dataset';
cells[1,0]:='DipDir';
cells[2,0]:='Dip';
cells[3,0]:='Azimuth';
cells[4,0]:='Plunge';
cells[5,0]:='Sense';
cells[6,0]:='Quality';
cells[7,0]:='P-Azimuth';
cells[8,0]:='P-Plunge';
cells[9,0]:='T-Azimuth';
cells[10,0]:='T-Plunge';
cells[11,0]:='B-Azimuth';
cells[12,0]:='B-Plunge';
cells[13,0]:='Pitch';
cells[14,0]:='Bew';
end;
PLN:
begin
ColCount:=4;
cells[0,0]:='Dataset';
cells[1,0]:='DipDir';
cells[2,0]:='Dip';
cells[3,0]:='Comment';
end;
LIN:
begin
ColCount:=4;
cells[0,0]:='Dataset';
cells[1,0]:='Azimuth';
cells[2,0]:='Plunge';
cells[3,0]:='Comment';
end;
AZI:
begin
ColCount:=3;
cells[0,0]:='Dataset';
cells[1,0]:='Azimuth';
cells[2,0]:='Comment';
end;
end; //end case
end;
i:=1;
if not New then
try
E2LocationInfo:=GetLocInfo(MyFileName);
with E2LocationInfo do
begin
E2Location.Text:=LocName;
E2X.Text:=x;
E2Y.Text:=y;
E2Z.Text:=z;
E2Date.Text:=Date;
E2Lithology.Text:=Lithology;
E2Formation.Text:=Formation;
E2Age.Text:=Age;
E2TectUnit.Text:=TectUnit;
E2Remarks.Text:=Remarks;
end;
AssignFile(f,myfilename);
try
Reset(f);
if not SeekEof(f) then
begin
while not SeekEof(F) and not failed do
begin
case E2Extension of
AZI:
begin
ReadAZIDataset(f, Azimuth,failed, Nocomment, Comment);
if not failed and NoComment then
begin
with StringGrid1 do
begin
cells[0,i]:=IntToStr(i);
cells[1,i]:=floattostring2(Azimuth,3,2);
cells[2,i]:=comment;
end;
end;
end;
COR,FPL, HOE, PEF, PEK, STF:
begin
ReadFPLDataset(f, Sense, Quality, DipDir, Dip, Azimuth, Plunge, failed, NoComment, E2Extension, comment);
if not failed and NoComment then
begin
with StringGrid1 do
begin
cells[0,i]:=IntToStr(i);
cells[1,i]:=floattostring2(DipDir,3,2);
cells[2,i]:=floattostring2(Dip,2,2);
cells[3,i]:=floattostring2(Azimuth,3,2);
cells[4,i]:=floattostring2(Plunge,2,2);
cells[5,i]:=IntToStr(Sense);
cells[6,i]:=IntToStr(Quality);
cells[7,i]:=comment;
end;
end;
end;
PTF:
begin
ReadPTFDataset(f, Sense, Quality, DipDir, Dip, Azimuth, Plunge, AzimB, PlungeB,
AzimP, PlungeP, AzimT, PlungeT, Pitch, Bew, failed, NoComment);
if not failed and NoComment then
begin
with StringGrid1 do
begin
cells[0,i]:=IntToStr(i);
cells[1,i]:=floattostring2(DipDir,3,2);
cells[2,i]:=floattostring2(Dip,2,2);
cells[3,i]:=floattostring2(Azimuth,3,2);
cells[4,i]:=floattostring2(Plunge,2,2);
cells[5,i]:=IntToStr(Sense);
cells[6,i]:=IntToStr(Quality);
cells[7,i]:=floattostring2(AzimP,3,2);
cells[8,i]:=floattostring2(PlungeP,2,2);
cells[9,i]:=floattostring2(AzimT,3,2);
cells[10,i]:=floattostring2(PlungeT,2,2);
cells[11,i]:=floattostring2(AzimB,3,2);
cells[12,i]:=floattostring2(PlungeB,2,2);
cells[13,i]:=floattostring2(Pitch,2,2);
cells[14,i]:=IntToStr(Bew);
end;
end;
end;
PLN, LIN:
begin
ReadPLNDataset(f, DipDir, Dip, failed, Nocomment, Comment);
if not failed and NoComment then
begin
with StringGrid1 do
begin
cells[0,i]:=IntToStr(i);
cells[1,i]:=floattostring2(DipDir,3,2);
cells[2,i]:=floattostring2(Dip,2,2);
cells[3,i]:=comment;
end;
end;
end;
else failed:= true;
end;
if not failed and NoComment then
begin
If not seekeof(f) then inc(i);
end
else if not NoComment and (i>0) then dec(i);
if i<1 then
begin
i:=1;
StringGrid1.cells[0,i]:=IntToStr(i);
end;
StringGrid1.RowCount := i+1;
end;
end;
finally
CloseFile(F);
Screen.Cursor:=crDefault;
end;
except {can not open file}
On EInOutError do
begin
Globalfailed:=true;
Screen.Cursor:=crDefault;
MessageDlg('Can not open '+MyFileName+' !'#$A#$D+
'File might be in use by another application.',
mtError,[mbOk], 0);
Close;
Exit;
end;
end //end if not new
else
begin
if FileExists(MyParentFileName) then
begin
E2LocationInfo:=GetLocInfo(MyParentFileName);
with E2LocationInfo do
begin
E2Location.Text:=LocName;
E2X.Text:=x;
E2Y.Text:=y;
E2Z.Text:=z;
E2Date.Text:=Date;
E2Lithology.Text:=Lithology;
E2Formation.Text:=Formation;
E2Age.Text:=Age;
E2TectUnit.Text:=TectUnit;
E2Remarks.Text:=Remarks;
end;
end;
StringGrid1.cells[0,1]:=IntToStr(1);
Screen.Cursor:=crDefault; //Bugfix 990123
end;
If Failed then
begin
GlobalFailed:=True;
ReadError(Self,MyFileName,i-1);
Close;
end
else
begin
undoing:=false;
//StringGrid1SelectCell(nil, 1,1, fCanselect);
with StringGrid1 do
begin
OldCol:=Col;
OldRow:=Row;
MouseCol:=Col;
MouseRow:=Row;
ColWidths[ColCount-1]:=ClientWidth-(colcount-1)*DefaultColWidth-(colcount+1)*GridLineWidth;
end;
creating:=false; //bugfix 981029
end;
end;
procedure TEdit2Frm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
TecMainWin.StatusBar1.Panels.Items[0].Text:='';
TecMainWin.StatusBar1.Panels.Items[1].Text:='';
if TecMainWin.MDIChildCount <=1 then
TecMainWin.Window1.Enabled := false;
TecMainWin.PrintBtn.Enabled:=false;
TecMainWin.PasteBtn.Enabled:=false;
TecMainWin.CopyBtn.Enabled:=false;
TecMainWin.SaveBtn.Enabled:=false;
end;
procedure TEdit2Frm.OD2ndVersion1Click(Sender: TObject);
begin
TecMainWin.OD2ndVersion1Click(Sender);
end;
procedure TEdit2Frm.NewD2ndVersion1Click(Sender: TObject);
begin
TecMainWin.NewD2ndVersion1Click(Sender);
end;
procedure TEdit2Frm.FormResize(Sender: TObject);
begin
With StringGrid1 do
ColWidths[ColCount-1]:=ClientWidth-(colcount-1)*DefaultColWidth-(colcount+1)*GridLineWidth;
end;
procedure TEdit2Frm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
const
SWarningText = 'Save changes to %s?';
begin
if Modified then
begin
MessageBeep(MB_ICONHAND);
case MessageDlg(Format(SWarningText, [MyFileName]), mtConfirmation,
[mbYes, mbNo, mbCancel], 0) of
idYes:
begin
Save1Click(Self);
canclose:=CanCloseForm;
end;
idCancel: CanClose := False;
idNo: Modified:=false; //bugfix 980705
end;
end;
end;
procedure TEdit2Frm.Save1Click(Sender: TObject);
var FCol, FRow : LongInt;
g: TextFile;
SenseQual, SenseDummy: integer;
textdummy: String;
begin
Screen.Cursor:=crHourGlass;
textdummy:=TecMainWin.Statusbar1.Panels[0].Text;
TecMainWin.Statusbar1.Panels[0].Text:='Checking data consistency. Please wait...';
FRow:=1;
Repeat with StringGrid1 do
begin
Case Checkrow(Sender, FCol, FRow) of
dv_invalid:
begin
Col:=FCol;
Row:=FRow;
options:=options+[goEditing];
editormode:=true;
if inplaceeditor<>nil then InplaceEditor.Perform(EM_SETSEL,0,-1);
If BeepOn then MessageBeep(0);
TecMainWin.Statusbar1.Panels[0].Text:=textdummy;
Screen.Cursor:=crDefault;
MessageDlg('Invalid data in Cell '+ GetColIdentifier(FCol)+' '+IntToStr(FRow)+'.'+#$D#$A+
'Processing stopped.', mtError, [mbOK, mbHelp], 520);
cancloseform:=false;
exit;
end;
dv_empty:
begin
DeleteRow(FRow);
if fRow>FixedRows then Dec(FRow);
SetFocus;
end;
end; //case
if frow=StringGrid1.rowcount-1 then break;
inc(FRow);
end; // with StringGrid1 do...
until FRow=StringGrid1.Rowcount;
TecMainWin.Statusbar1.Panels[0].Text:=textdummy;
If not IsTFPFileFormat(MyFilename) then
begin
Screen.Cursor:=crDefault;
Case MessageDlg('Data will be converted to a TFP-fileformat.', mtWarning,[mbOk, mbHelp], 515) of
mrOK:
begin
textdummy:=MyFilename;
case extractextension(MyFilename) of
HOE, PEK, STF: MyFilename:=ChangeFileExt(MyFilename, '.cor');
PEF: MyFilename:=ChangeFileExt(MyFilename, '.fpl');
end;
E2Extension:=ExtractExtension(MyFilename);
if not SaveAs1Click(Sender) then
begin
MyFilename:=Textdummy;
E2Extension:=ExtractExtension(MyFilename);
exit;
end;
end;
else exit;
end;
Screen.Cursor:=crHourGlass;
end
else
if New or (Sender=SaveAs1) then
begin
Screen.Cursor:=crDefault;
if not SaveAs1Click(Sender) then exit;
Screen.Cursor:=crHourGlass;
end;
//Extension:=ExtractExtension(MyFilename);
With E2LocationInfo do
begin
LocName:=E2Location.Text;
x:=E2X.Text;
y:=E2Y.Text;
z:=E2Z.Text;
Date:=E2Date.Text;
Lithology:=E2Lithology.Text;
Formation:=E2Formation.Text;
Age:=E2Age.Text;
TectUnit:=E2TectUnit.Text;
Remarks:=E2Remarks.Text;
end;
LocInfoToFile(MyFileName, E2LocationInfo);
AssignFile(g, MyFileName);
Append(g);
for FRow:= 1 to StringGrid1.Rowcount-1 do
begin
case E2Extension of
COR, FPL:
begin
try
SenseDummy:=StrToInt(StringGrid1.Cells[5, FRow]);
except
on EConvertError do
If StringGrid1.Cells[5, FRow]='+' then SenseDummy:=1
else if StringGrid1.Cells[5, FRow]='-' then SenseDummy:=2
else Sensedummy:=0;
end;
try
if sensedummy<>0 then
begin
if StrToInt(StringGrid1.Cells[6, FRow])<>0 then SenseQual:=10*Sensedummy+StrToInt(StringGrid1.Cells[6, FRow])
else SenseQual:=StrToInt(StringGrid1.Cells[5, FRow]);
end
else SenseQual:=0;
except
on EConvertError do SenseQual:=0;
end;
Write(g,SenseQual,filelistseparator,StringGrid1.Cells[1,FRow],filelistseparator,
StringGrid1.Cells[2,FRow],filelistseparator, StringGrid1.Cells[3,FRow],
filelistseparator, StringGrid1.Cells[4,FRow]);
FCol:=7;
end;
PLN, LIN:
begin
Write(g,StringGrid1.Cells[1,FRow],filelistseparator,
StringGrid1.Cells[2,FRow]);
FCol:=3;
end;
AZI:
begin
Write(g,StringGrid1.Cells[1,FRow]);
FCol:=2;
end;
else break;
end;
if FRow<StringGrid1.RowCount then
if StringGrid1.Cells[FCol,FRow]='' then writeln(g) //comment field is empty
else Writeln(g, filelistseparator, StringGrid1.Cells[FCol,FRow]) //write comment and begin a new line if not last dataset
else if StringGrid1.Cells[FCol,FRow]<>'' then Write(g, filelistseparator, StringGrid1.Cells[FCol,FRow]); //last dataset only
end;
Closefile(g);
Modified := false;
CanCloseForm:=true;
Screen.Cursor:=crDefault;
end;
function TEdit2Frm.Saveas1Click(Sender: TObject): Boolean;
var saveflag,exitflag, retryflag: boolean;
ext : Tstring4;
begin
Result:=false;
with SaveDialog1 do
begin
InitialDir:=GetCurrentDir; //Bugfix 20000408 (Win2000)
FileName := MyFileName;
FilterIndex:=1;//EditSaveFilterIndexStore;
end;
retryflag:=false;
Repeat
Exitflag:=false;
If not retryflag then
case E2Extension of
FPL: SaveDialog1.Filter:='Fault plane files (*.fpl)|*.fpl|All files (*.*)|*.*';
COR: SaveDialog1.Filter:='Corrected files (*.cor)|*.cor|All files (*.*)|*.*';
PLN: SaveDialog1.Filter:='Plane files (*.pln)|*.pln|All files (*.*)|*.*';
LIN: SaveDialog1.Filter:='Lineation files (*.lin)|*.lin|All files (*.*)|*.*';
AZI: SaveDialog1.Filter:='Azimutal data files (*.azi)|*.azi|All files (*.*)|*.*';
PTF: SaveDialog1.Filter:='pt-axes files (*.t??)|*.t??|All files (*.*)|*.*';
end;
SaveFlag:= SaveDialog1.Execute;
If SaveFlag then
begin
if ExtractFileExt(SaveDialog1.FileName)='' then
case E2Extension of
fpl: ext := '.fpl';
cor: ext := '.cor';
pln: ext := '.pln';
lin: ext := '.lin';
azi: ext := '.azi';
end
else ext:=ExtractFileExt(SaveDialog1.Filename);
ExitFlag:=True;
If FileExists(ChangeFileExt(SaveDialog1.FileName,ext)) then
Case MessageDlg(ChangeFileExt(SaveDialog1.FileName,ext)+#$A#$D+
'already exists! Overwrite?', mtWarning,[mbYes,mbRetry,mbCancel], 0) of
mrCancel:
begin
Saveflag:=false;
exit;
end;
mrYes: ExitFlag:=True;
mrRetry:
begin
ExitFlag:=False;
retryflag:=true;
end;
end;
end else exitflag:=true;
until exitflag;
if saveflag then
begin
SaveDialog1.FileName := ChangeFileExt(SaveDialog1.FileName,ext);
MyFileName := SaveDialog1.FileName;
Caption := ExtractFileName(MyFileName);
New:=False;
EditSaveFilterIndexStore:=SaveDialog1.FilterIndex;
Result:=true;
end;
end;
procedure TEdit2Frm.Open1Click(Sender: TObject);
begin
TecMainWin.EditOpenChild(Sender);
end;
procedure TEdit2Frm.New1Click(Sender: TObject);
begin
TecMainWin.EditNewChild(Sender);
end;
function TEdit2Frm.GetDataType(FCol: Integer): TTectData;
begin
case fcol of
0: begin
Result:=td_NDataset;
exit;
end;
end;
Case E2Extension of
fpl, cor, stf, hoe, pek, pef:
Case FCol of
1: Result:= td_fpDipDir;
2: Result:= td_fpDip;
3: Result:= td_Azimuth;
4: Result:= td_Plunge;
5: Result:= td_Sense;
6: Result:= td_Quality;
7: Result:= td_Comment;
else Result:=td_unknown;
end;
ptf:
Case FCol of
1: Result:= td_fpDipDir;
2: Result:= td_fpDip;
3, 7, 9, 11: Result:= td_Azimuth;
4,8,10,12: Result:= td_Plunge;
5: Result:= td_Sense;
6: Result:= td_Quality;
13: Result:= td_Pitch;
14: Result:= td_Integer;
else Result:=td_unknown;
end;
pln:
Case FCol of
1: Result:=td_DipDir;
2: Result:=td_Dip;
3: Result:=td_Comment;
else Result:=td_unknown;
end;
lin:
Case FCol of
1: Result:=td_Azimuth;
2: Result:=td_Plunge;
3: Result:=td_Comment;
else Result:=td_unknown;
end;
azi:
Case FCol of
1: Result:= td_Azimuth;
2: Result:= td_Comment;
else Result:=td_unknown;
end;
end;
end;
function TEdit2Frm.CheckData(Sender: TObject; FCol, FRow: LongInt): TDatavalidity;
var value: Single;
position: Integer;
MyDatatype: TTectData;
begin
With StringGrid1 do
begin
MyDatatype:=GetDataType(FCol);
if (Cells[FCol, FRow]='') and undoing then
begin
undoing:=false;
result:=dv_valid;
exit;
end;
if (Cells[FCol, FRow]='') and (MyDatatype<> td_Comment) and (MyDatatype<> td_Quality) then
begin
result:=dv_empty;
exit;
end;
if (Cells[FCol, FRow]='') and (MyDatatype= td_Quality) then //bugfix for leaving quality cells empty
begin //990331 f.r.
Cells[FCol, FRow]:='0';
result:=dv_valid;
exit;
end;
result:=dv_invalid;
val(Cells[FCol, FRow],value,position);
If (position<>0) and (MyDatatype<> td_Comment) and (MyDatatype<>td_Sense) then exit;
Case MyDatatype of
td_DipDir, td_fpDipDir, td_Azimuth:
begin
if (Value<359.99) and (Value>=0) then
begin
result:=dv_valid;
Cells[FCol, FRow]:=floattostring2(Value,3,2);
end;
end;
td_Dip, td_fpDip, td_Plunge:
begin
if (Value<89.95) and (Value>=0.009999) then
begin
result:=dv_valid;
Cells[FCol, FRow]:=floattostring2(Value,2,2);
end;
end;
td_Sense: if (Value<=5) and (Value>=0) and (position=0) or (Cells[FCol, FRow]='+') or (Cells[FCol, FRow]='-')
then result:=dv_valid;
td_Pitch: result:=dv_valid;
td_Integer: if abs(frac(value))<0.001 then result:=dv_valid;
td_Quality: if (Value<=4) and (Value>=0) then result:=dv_valid;
td_Comment: result:=dv_valid;
end;
end;
end;
function TEdit2Frm.AutoFillCell(Sender: TObject; FCol, FRow: LongInt): Boolean;
begin
Result:=false;
If StringGrid1.Cells[FCol, FRow]<>'' then exit;
If FRow>StringGrid1.FixedRows then
begin
if StringGrid1.Cells[FCol, FRow-1]<>'' then
begin
case GetDataType(FCol) of
td_Comment: {};
td_Quality: if StringGrid1.Cells[FCol-1, FRow]='0' then StringGrid1.Cells[FCol, FRow]:='0'
else StringGrid1.Cells[FCol, FRow]:=StringGrid1.Cells[FCol, FRow-1];
else StringGrid1.Cells[FCol, FRow]:=StringGrid1.Cells[FCol, FRow-1];
end;
end;
end
else Case GetDataType(FCol) of
td_Quality: StringGrid1.Cells[FCol, FRow]:='0';
td_Sense: StringGrid1.Cells[FCol, FRow]:='0';
end;
Result:=true;
end;
function TEdit2Frm.CheckRow(Sender: TObject; var FCol: LongInt; FRow: LongInt): TDatavalidity;
var j, aempty: Integer;
firstinvalidcell: LongInt;
begin
aempty:=0;
firstinvalidcell:=0;
result:=dv_valid;
For j:=1 to StringGrid1.Colcount-2 do
begin
FCol:=j;
case CheckData(Sender, FCol, FRow) of
dv_invalid:
begin
Result:=dv_invalid;
exit;
end;
dv_empty: //if frow=StringGrid1.rowcount-1 then
begin
Result:=dv_empty;
if firstinvalidcell=0 then firstinvalidcell:=j;
inc(aempty);
end;
dv_valid: //bugfix 990803 to delete empty last row in fpl and cor files
if (aempty = StringGrid1.ColCount - 3) and (StringGrid1.ColCount - 3 > 0) then
begin //bugfix 080305 to avoid accidential deleting of azimuthal data (all rows were deleted)
Result:=dv_empty;
if firstinvalidcell=0 then firstinvalidcell:=j;
inc(aempty);
end;
{else
begin
Result:=dv_invalid;
exit;
end;}
end;
end;
if (result=dv_empty) then
if (aempty<>StringGrid1.colcount-2) then
begin
result:=dv_invalid;
fcol:=firstinvalidcell;
end;
end;
procedure TEdit2Frm.SwapSelection(var ASelection: TRect; vertical: Boolean);
var dummy: Integer;
begin
if vertical then
begin
dummy:=aselection.top;
aselection.top:=aselection.bottom;
aselection.bottom:=dummy;
end
else
begin
dummy:=aselection.left;
aselection.left:=aselection.right;
aselection.right:=dummy;
end;
end;
procedure TEdit2Frm.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var OldSelection: TRect;
myselection: TRect;
SelChanged: Boolean;
ACol, MyCol, MyRow: LongInt;
begin
if readonly then case key of
vk_delete, vk_back:
begin
key:=0;
exit;
end;
end;
With StringGrid1 do
case key of
17:
begin
key:=0;
Refresh;
exit;
end;
vk_delete:
begin
for MyRow:= Selection.Top to Selection.Bottom do
for MyCol := Selection.Left to Selection.Right do
Cells[MyCol, MyRow]:='';
key:=0;
modified:=true;
exit;
end;
vk_tab:
begin
if not readonly then
begin
If E2AutoFill then AutoFillCell(Sender,Col,Row);
If CheckData(Sender, Col, Row)<>dv_valid then
begin
If BeepOn then Windows.Beep(200, 50);
MessageDlg('You entered invalid data!', mtError, [mbOK, mbHelp], 520);
key:=0;
options:=options+[goEditing];
editormode:=true;
if inplaceeditor<>nil then InplaceEditor.Perform(EM_SETSEL,0,-1);
exit;
end;
If (Col=ColCount-1) and (Row=RowCount-1) then
begin
If CheckRow(Sender, ACol, Row)=dv_valid then //Check all data in row
begin
Key:=0;
NewRow(Sender);
end
else
begin
Key:=0;
Col:=ACol;
If BeepOn then Windows.Beep(200,50); //goto cell with wrong content
MessageDlg('Invalid data in Cell '+ GetColIdentifier(ACol)+
' '+IntToStr(ACol)+'.'+#$D#$A+
'Processing stopped.', mtError , [mbOK, mbHelp], 520);
options:=options+[goEditing];
editormode:=true;
If inplaceeditor<>nil then InplaceEditor.Perform(EM_SETSEL,0,-1);