-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit3.pas
393 lines (323 loc) · 9.35 KB
/
Unit3.pas
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
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ValEdit, StdCtrls, GeoClasses, GeoString, GeoFiles, LangLoader;
type
TForm3 = class(TForm)
ComboBox1: TComboBox;
ListBox1: TListBox;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Button1: TButton;
Label4: TLabel;
ComboBox2: TComboBox;
Label5: TLabel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
ComboBox3: TComboBox;
ValueList: TStringGrid;
Label6: TLabel;
Edit3: TEdit;
Label7: TLabel;
Edit4: TComboBox;
Button5: TButton;
isLocal: TCheckBox;
procedure Button4Click(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure ComboBox3Change(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FindNew(Cat, Cap :String);
procedure Button5Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure RefreshLists;
procedure Button1Click(Sender: TObject);
procedure ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
oldidx : integer = -1;
implementation
uses MainForm, Unit4;
{$R *.dfm}
procedure TForm3.Button4Click(Sender: TObject);
begin
ListBox1.OnClick(nil);
end;
procedure TForm3.ComboBox2Change(Sender: TObject);
var PrjType, SK, i: integer;
begin
PrjType := ComboBox2.ItemIndex;
Valuelist.RowCount:=1;
Valuelist.ColWidths[0] := 180;
Valuelist.ColWidths[1] := Valuelist.Width - 185;
Valuelist.Enabled := true;
case PrjType of
2,3,4: begin
Valuelist.RowCount := 5;
Valuelist.FixedCols := 1;
ValueList.Cells[0,0]:= inf[18];
ValueList.Cells[0,1]:= inf[19];
ValueList.Cells[0,2]:= inf[20];
ValueList.Cells[0,3]:= inf[21];
ValueList.Cells[0,4]:= inf[22];
if isLocal.Checked then
begin
Valuelist.RowCount := 11;
ValueList.Cells[0,5]:= inf[55];
ValueList.Cells[0,6]:= inf[56];
ValueList.Cells[0,7]:= inf[57];
ValueList.Cells[0,8]:= inf[58];
ValueList.Cells[0,9]:= inf[59];
ValueList.Cells[0,10]:= inf[60];
end;
end;
0,1: begin
Valuelist.FixedCols := 1;
Valuelist.Enabled := false;
ValueList.Cells[0,0]:= '';
ValueList.Cells[1,0]:= '';
end;
end;
if Valuelist.Enabled then
Begin
SK := FindCoordinateSystemByCaption(ListBox1.Items[ListBox1.ItemIndex]);
if SK<>-1 then
for i := 0 to ValueList.RowCount do
if i<= length(CoordinateSystemList[SK].Parameters)-1 then
ValueList.Cells[1,i]:= FloatToStr(CoordinateSystemList[SK].Parameters[i])
else
ValueList.Cells[1,i]:= '0';
End;
end;
procedure TForm3.ComboBox3Change(Sender: TObject);
begin
if ComboBox3.ItemIndex<>-1 then
Form1.findCat(ComboBox3.Items[ComboBox3.ItemIndex], Form3.ListBox1);
Form3.ListBox1.ItemIndex:=0;
Form3.ListBox1.OnClick(nil);
end;
procedure TForm3.ListBox1Click(Sender: TObject);
var SK, i :integer;
begin
if ListBox1.ItemIndex <= -1 then
exit;
SK := FindCoordinateSystemByCaption(ListBox1.Items[ListBox1.ItemIndex]);
if SK=-1 then
exit;
Button3.Enabled := true;
Button4.Enabled := true;
Button5.Enabled := true;
Edit1.Text := CoordinateSystemList[SK].Name;
Edit2.Text := CoordinateSystemList[SK].Caption;
Edit3.Text := CoordinateSystemList[SK].FileName;
Edit4.Text := CoordinateSystemList[SK].Category;
isLocal.Checked := CoordinateSystemList[SK].isLocalized;
ComboBox1.ItemIndex := CoordinateSystemList[SK].DatumN;
Combobox2.ItemIndex := CoordinateSystemList[SK].ProjectionType;
Combobox2.OnChange(nil);
for i := 0 to length(CoordinateSystemList[SK].Parameters)-1 do
if i <= Valuelist.RowCount-1 then
ValueList.Cells[1,i]:= FloatToStr(CoordinateSystemList[SK].Parameters[i]);
end;
procedure TForm3.Button2Click(Sender: TObject);
var i, j : integer;
FileName, dir: string;
CS :TCoordinateSystem;
ParNames : TStringList;
begin
j := 0;
for i := 0 to Length(CoordinateSystemList)-1 do
if (CoordinateSystemList[i].Name = Edit1.Text)or(CoordinateSystemList[i].Caption = Edit2.Text) then
inc(j);
if j >= 1 then
begin
MessageDlg(inf[31],mtError,[mbOk],6);
exit;
end;
dir := '';
for j:= length(Edit3.Text) downto 0 do
if Edit3.Text[j]='\' then
begin
dir := Copy(Edit3.Text,1,j);
break;
end;
i := 1;
repeat
FileName:= dir + 'User' + IntToStr(i)+'.txt';
inc(i);
until Fileexists(FileName) = false;
Edit3.Text := Filename;
CS.Name := Edit1.Text;
CS.Caption := Edit2.Text;
CS.Category := Edit4.Text;
CS.ProjectionType := ComboBox2.ItemIndex;
CS.DatumN := ComboBox1.ItemIndex;
CS.FileName := FileName;
ParNames := TStringList.Create;
if ValueList.Enabled then
Begin
SetLength(CS.Parameters,ValueList.RowCount);
for i := 0 to ValueList.RowCount-1 do
begin
ParNames.Add(ValueList.Cells[0,i]);
CS.Parameters[i] := StrToFloat2(ValueList.Cells[1,i]);
end;
end;
SaveCoordinateSystemToFile(Filename, CS, ParNames);
FindNew(CS.Category, CS.Caption);
Parnames.Destroy;
end;
procedure TForm3.Button3Click(Sender: TObject);
var i, j, Current : integer;
FileName, dir: string;
CS :TCoordinateSystem;
ParNames : TStringList;
begin
j := 0;
Current := FindCoordinateSystemByCaption(ListBox1.Items[ListBox1.ItemIndex]);
for i := 0 to Length(CoordinateSystemList)-1 do
if ( (CoordinateSystemList[i].Name = Edit1.Text)
or (CoordinateSystemList[i].Caption = Edit2.Text) )
and (i<>Current) then
inc(j);
if j >= 1 then
begin
MessageDlg(inf[31],mtError,[mbOk],6);
exit;
end;
dir := '';
for j:= length(Edit3.Text) downto 0 do
if Edit3.Text[j]='\' then
begin
dir := Copy(Edit3.Text,1,j);
FileName := Copy(Edit3.Text,j+1,Length(Edit3.Text)-j);
break;
end;
ForceDirectories(dir+ 'Backup\');
CopyFile(PChar(Edit3.Text), PChar(dir+ 'Backup\' + Filename), false);
FileName := Edit3.Text;
CS.Name := Edit1.Text;
CS.Caption := Edit2.Text;
CS.Category := Edit4.Text;
CS.ProjectionType := ComboBox2.ItemIndex;
CS.DatumN := ComboBox1.ItemIndex;
CS.FileName := FileName;
ParNames := TStringList.Create;
if ValueList.Enabled then
Begin
SetLength(CS.Parameters,ValueList.RowCount);
for i := 0 to ValueList.RowCount-1 do
begin
ParNames.Add(ValueList.Cells[0,i]);
CS.Parameters[i] := StrToFloat2(ValueList.Cells[1,i]);
end;
end;
DeleteCoordinateSystem(Current);
SaveCoordinateSystemToFile(Filename, CS, ParNames);
FindNew(CS.Category, CS.Caption);
Parnames.Destroy;
end;
procedure TForm3.FindNew(Cat, Cap: String);
var i: integer;
begin
Combobox3.Items.Clear;
for i := 0 to Length(CoorinateSystemCategories)-1 do
Combobox3.Items.Add(CoorinateSystemCategories[i]);
for i :=0 to Combobox1.Items.Count - 1 do
if ComboBox3.Items[i] = Cat then
begin
ComboBox3.ItemIndex := i;
break;
end;
ComboBox3.OnChange(nil);
for i :=0 to ListBox1.Items.Count-1 do
if ListBox1.Items[i]=Cap then
begin
ListBox1.ItemIndex := i;
break;
end;
ListBox1.OnClick(nil);
end;
procedure TForm3.Button5Click(Sender: TObject);
var j : integer;
FileName, dir: string;
begin
dir := '';
for j:= length(Edit3.Text) downto 0 do
if Edit3.Text[j]='\' then
begin
dir := Copy(Edit3.Text,1,j);
FileName := Copy(Edit3.Text,j+1,Length(Edit3.Text)-j);
break;
end;
ForceDirectories(dir+ 'Deleted\');
CopyFile(PChar(Edit3.Text), PChar(dir+ 'Deleted\' + Filename), false);
DeleteFile(PChar(Edit3.Text));
Button3.Enabled := false;
Button4.Enabled := false;
Button5.Enabled := false;
DeleteCoordinateSystem(FindCoordinateSystemByCaption(ListBox1.Items[ListBox1.ItemIndex]));
ComboBox3.OnChange(nil);
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Form1.ReInit;
end;
procedure TForm3.RefreshLists;
var i: integer;
begin
SetCurrentDir(Form1.MyDir);
ComboBox1.Clear;
for i := 0 to Length(DatumList)-1 do
Combobox1.Items.Add(DatumList[i].Caption);
ComboBox3.OnChange(nil);
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
Form4.RefreshLists;
Form4.ListBox1.ItemIndex := ComboBox1.ItemIndex;
Form4.ListBox1.OnClick(nil);
Form4.ShowModal;
end;
procedure TForm3.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
idx : Longint;
begin
with Sender as TListBox do begin
idx := ItemAtPos(Point(x,y),True);
if (idx < 0) or (idx = oldidx) then
Exit;
Application.ProcessMessages;
Application.CancelHint;
oldidx := idx;
HintX := TListBox(Sender).itemRect(idx).Left;
HintY := TListBox(Sender).itemRect(idx).Top;
Hint := '';
if Canvas.TextWidth(Items[idx]) > Width - 24 then
Hint:=Items[idx];
end;
end;
procedure TForm3.FormActivate(Sender: TObject);
begin
SetCurrentDir(Form1.MyDir);
end;
procedure TForm3.FormShow(Sender: TObject);
begin
ListBox1.OnClick(nil);
end;
end.