1 unit filter;
2
3 {
4 Copyright (C) 2005-2008 Olaf Klein, o.b.klein@gpsbabel.org
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
19 }
20
21 interface
22
23 uses
24 gnugettext, gnugettextDx,
25 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
26 StdCtrls, ComCtrls, Buttons, Mask, ExtCtrls, Registry,
27 common, utils;
28
29 type
30 TfrmFilter = class(TForm)
31 gbTracks: TGroupBox;
32 cbTrackTitle: TCheckBox;
33 edTrackTitleValue: TEdit;
34 cbTrackSplit: TCheckBox;
35 cbTrackTime: TCheckBox;
36 udTimeHours: TUpDown;
37 edTrackTimeHours: TEdit;
38 udTimeMinutes: TUpDown;
39 edTrackTimeMinutes: TEdit;
40 edTrackTimeDays: TEdit;
41 udTimeDays: TUpDown;
42 edTrackTimeSeconds: TEdit;
43 udTimeSeconds: TUpDown;
44 lbTimePlusMinus: TLabel;
45 lbTimeDays: TLabel;
46 lbTimeHours: TLabel;
47 lbTimeMinutes: TLabel;
48 lbTimeSeconds: TLabel;
49 cbTrackStart: TCheckBox;
50 dtpTrackStartDate: TDateTimePicker;
51 dtpTrackStartTime: TDateTimePicker;
52 cbTrackStop: TCheckBox;
53 dtpTrackStopDate: TDateTimePicker;
54 dtpTrackStopTime: TDateTimePicker;
55 gbRoutes: TGroupBox;
56 cbRouteSimplify: TCheckBox;
57 lbRouteSimplifyCount: TLabel;
58 edRoutesSimplifyMaxPoints: TMaskEdit;
59 udRouteSompifyMaxPoints: TUpDown;
60 lbRouteSimplifyText: TLabel;
61 pnBottom: TPanel;
62 btnOK: TBitBtn;
63 gbWaypoints: TGroupBox;
64 cbWayptMergeDupLoc: TCheckBox;
65 cbReverse: TCheckBox;
66 cbWayptMergeDupNames: TCheckBox;
67 cbWayptMergeDistance: TCheckBox;
68 cobWayptMergeDistUnit: TComboBox;
69 edWayptMergeDist: TEdit;
70 cbWayptSort: TCheckBox;
71 cbWayptMergeDups: TCheckBox;
72 btnCancel: TBitBtn;
73 cbTrackPack: TCheckBox;
74 cbTrackMerge: TCheckBox;
75 BitBtn1: TBitBtn;
76 cbWayptRadius: TCheckBox;
77 edWayptRadius: TEdit;
78 cobWayptRadiusUnit: TComboBox;
79 lbWayptRadiusLat: TLabel;
80 lbWayptRadiusLon: TLabel;
81 edWayptRadiusLat: TEdit;
82 edWayptRadiusLon: TEdit;
83 cbTrackRangeTimeZone: TCheckBox;
84 btnHelp: TBitBtn;
85 cbGPSfix: TCheckBox;
86 cbTrackCourse: TCheckBox;
87 cbTrackSpeed: TCheckBox;
88 gbTransform: TGroupBox;
89 cobTransformType: TComboBox;
90 cbTransform: TCheckBox;
91 cbTransformDelete: TCheckBox;
92 cobGPSfixes: TComboBox;
93 Panel1: TPanel;
94 gbMisc: TGroupBox;
95 cbSwapData: TCheckBox;
96 procedure cbTrackTimeClick(Sender: TObject);
97 procedure FormCreate(Sender: TObject);
98 procedure cbTrackTitleClick(Sender: TObject);
99 procedure btnOKClick(Sender: TObject);
100 procedure cbTrackStartClick(Sender: TObject);
101 procedure cbTrackStopClick(Sender: TObject);
102 procedure cbRouteSimplifyClick(Sender: TObject);
103 procedure cbTrackPackClick(Sender: TObject);
104 procedure cbTrackMergeClick(Sender: TObject);
105 procedure cbWayptMergeDistanceClick(Sender: TObject);
106 procedure cbWayptMergeDupsClick(Sender: TObject);
107 procedure cbWayptRadiusClick(Sender: TObject);
108 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
109 procedure FormShow(Sender: TObject);
110 procedure FormKeyDown(Sender: TObject; var Key: Word;
111 Shift: TShiftState);
112 procedure btnHelpClick(Sender: TObject);
113 procedure cbTransformClick(Sender: TObject);
114 procedure FormClose(Sender: TObject; var Action: TCloseAction);
115 procedure cbGPSfixClick(Sender: TObject);
116 private
117 { Private-Deklarationen }
118 lTrackTimeList: TList;
119 FTracksEnabled: Boolean;
120 FInitialValues: string;
AnyCheckednull121 function AnyChecked(Control: TWinControl): Boolean;
122 procedure EnableList(List: TList; Enable: Boolean = True);
123 procedure SetTracksEnabled(const Value: Boolean);
AllValidnull124 function AllValid: Boolean;
ValidateNumericalnull125 function ValidateNumerical(AEdit: TCustomEdit; AMin, AMax: Extended): Boolean;
126 procedure ChangeCheckBoxesChecked(AComponent: TComponent; Restore: Boolean = False);
127 procedure LoadSettingsFromInifile();
128 procedure LoadSettingsFromRegistry();
129 procedure StoreSettingsToInifile();
130 procedure StoreSettingsToRegistry();
131 public
132 { Public-Deklarationen }
CmdLinenull133 function CmdLine: string;
134 property TracksEnabled: Boolean read FTracksEnabled write SetTracksEnabled;
135 end;
136
137 type
138 eOutOfRange = class(Exception);
139
140 var
141 frmFilter: TfrmFilter = nil;
142
143 implementation
144
145 {$R *.DFM}
146
147 procedure FixPosition(AControl, LeftFromMe: TControl; IsText: Boolean);
148 begin
149 AControl.Left := LeftFromMe.Left + LeftFromMe.Width;
150 if (IsText) then
151 AControl.Left := AControl.Left + 4;
152 end;
153
154 procedure EnableAll(Parent: TWinControl; Enable: Boolean);
155 var
156 i: Integer;
157 c: TComponent;
158 master: TComponent;
159 ctrl: TControl;
160 begin
161 if (Parent = nil) then Exit;
162 master := Parent.Owner;
163 if (master = nil) then Exit;
164 for i := 0 to master.ComponentCount - 1 do
165 begin
166 c := master.Components[i];
167 if not(c.InheritsFrom(TControl)) then Continue;
168 ctrl := Pointer(c);
169 if not(ctrl.Parent = Parent) then Continue;
170 ctrl.Enabled := Enable;
171 end;
172 end;
173
174 { TfrmFilter }
175
176 procedure TfrmFilter.FormCreate(Sender: TObject);
177 var
178 CurrentTime: TDateTime;
179
180 begin
181 TranslateComponent(SELF);
182 RestoreBounds('filter_form', Self);
183
184 cobTransformType.Items.Clear;
185 cobTransformType.Items.Add(_('Waypoints') + ' -> ' + _('Routes'));
186 cobTransformType.Items.Add(_('Routes') + ' -> ' + _('Waypoints'));
187 cobTransformType.Items.Add(_('Routes') + ' -> ' + _('Tracks'));
188 cobTransformType.Items.Add(_('Tracks') + ' -> ' + _('Routes'));
189 cobTransformType.Items.Add(_('Waypoints') + ' -> ' + _('Tracks'));
190 cobTransformType.Items.Add(_('Tracks') + ' -> ' + _('Waypoints'));
191 cobTransformType.ItemIndex := 0;
192
193 CurrentTime := SysUtils.Now;
194 dtpTrackStartDate.DateTime := Int(CurrentTime);
195 dtpTrackStopDate.DateTime := Int(CurrentTime);
196
197 lTrackTimeList := TList.Create;
198
199 lTrackTimeList.Add(edTrackTimeDays);
200 lTrackTimeList.Add(edTrackTimeHours);
201 lTrackTimeList.Add(edTrackTimeMinutes);
202 lTrackTimeList.Add(edTrackTimeSeconds);
203
204 EnableList(lTrackTimeList, False);
205
206 FixPosition(edTrackTimeDays, lbTimePlusMinus, True);
207 FixPosition(udTimeDays, edTrackTimeDays, False);
208 FixPosition(lbTimeDays, udTimeDays, True);
209
210 FixPosition(edTrackTimeHours, lbTimeDays, True);
211 FixPosition(udTimeHours, edTrackTimeHours, False);
212 FixPosition(lbTimeHours, udTimeHours, True);
213
214 FixPosition(edTrackTimeMinutes, lbTimeHours, True);
215 FixPosition(udTimeMinutes, edTrackTimeMinutes, False);
216 FixPosition(lbTimeMinutes, udTimeMinutes, True);
217
218 FixPosition(edTrackTimeSeconds, lbTimeMinutes, True);
219 FixPosition(udTimeSeconds, edTrackTimeSeconds, False);
220 FixPosition(lbTimeSeconds, udTimeSeconds, True);
221
222 FixPosition(lbWayptRadiusLat, cobWayptRadiusUnit, True);
223 FixPosition(edWayptRadiusLat, lbWayptRadiusLat, True);
224 FixPosition(lbWayptRadiusLon, edWayptRadiusLat, True);
225 FixPosition(edWayptRadiusLon, lbWayptRadiusLon, True);
226
227 // will not be translated, fill by hand
228
229 cobWayptMergeDistUnit.Items.Add(_('Feet'));
230 cobWayptMergeDistUnit.Items.Add(_('Meter'));
231 cobWayptMergeDistUnit.ItemIndex := 0;
232
233 cobWayptRadiusUnit.Items.Add(_('Miles'));
234 cobWayptRadiusUnit.Items.Add(_('Kilometer'));
235 cobWayptRadiusUnit.ItemIndex := 0;
236
237 dtpTrackStopTime.Time := 1 - (1.0 / (24*60*60));
238
239 // Enable/Disable depending on gpsbabel.exe version
240
241 if (common.gpsbabel_vfmt < '001.002.007') then
242 begin
243 EnableAll(gbTracks, False);
244 gbTracks.Hint := Format(_('Not supported by gpsbabel.exe, release %s!'), [
245 gpsbabel_version]);
246 gbTracks.ShowHint := True;
247 end;
248
249 if not(gpsbabel_knows_inifile) then
250 begin
251 cbGPSfix.Enabled := False;
252 cbTrackCourse.Enabled := False;
253 cbTrackSpeed.Enabled := False;
254 cobGPSfixes.Enabled := False;
255 end;
256
257 LoadSettingsFromRegistry();
258
259 gbTransform.Enabled := (common.gpsbabel_vfmt >= '001.003.002');
260 EnableAll(gbTransform, gbTransform.Enabled);
261
262 cobTransformType.Enabled := cbTransform.Checked;
263 cbTransformDelete.Enabled := cbTransform.Checked;
264
265 cbSwapData.Enabled := gpsbabel_knows_swap_filter;
266 gbMisc.Enabled := (cbSwapData.Enabled { or ... });
267 end;
268
ValidateNumericalnull269 function TfrmFilter.ValidateNumerical(AEdit: TCustomEdit; AMin, AMax: Extended): Boolean;
270 var
271 s: string;
272 v: Extended;
273 begin
274 Result := True;
275 if not(AEdit.Enabled) then Exit;
276 if (ModalResult <> mrOK) then Exit;
277
278 Result := False;
279 s := Trim(AEdit.Text);
280 if (s = '') then s := '0';
281 while (Pos(',', s) <> 0) do
282 s[Pos(',', s)] := '.';
283
284 AEdit.Text := s;
285
286 try
287 v := SysUtils.StrToFloat(s);
288 except
289 on E: EConvertError do
290 begin
291 AEdit.SetFocus;
292 raise;
293 end;
294 end;
295
296 if (v < AMin) or (v > AMax) then
297 begin
298 AEdit.SetFocus;
299 raise eOutOfRange.CreateFmt(_('Value (%s) out of range (%g to %g)!'),
300 [s, AMin, AMax]);
301 end;
302 Result := True;
303 end;
304
305 procedure TfrmFilter.cbTrackTimeClick(Sender: TObject);
306 begin
307 EnableList(lTrackTimeList, cbTrackTime.Checked);
308 end;
309
310 procedure TfrmFilter.EnableList(List: TList; Enable: Boolean);
311 var
312 i: Integer;
313 o: TObject;
314 begin
315 for i := 0 to List.Count - 1 do
316 begin
317 o := Pointer(List.Items[i]);
318 if (o is TControl) then
319 with o as TControl do
320 Enabled := Enable;
321 end;
322 end;
323
324 procedure TfrmFilter.cbTrackTitleClick(Sender: TObject);
325 begin
326 edTrackTitleValue.Enabled := cbTrackTitle.Checked;
327 end;
328
TfrmFilter.CmdLinenull329 function TfrmFilter.CmdLine: string;
330
331 procedure SimpleOption(var CmdLine: string; CheckBox: TCheckBox; const Option: string);
332 begin
333 if (CheckBox.Checked) then
334 CmdLine := Format('%s -x %s', [CmdLine, Option]);
335 end;
336
337 var
338 s: string;
339 tz_Info: TTimeZoneInformation;
340 dt: TDateTime;
341 dt_bias: TDateTime;
342 begin
343 Result := '';
344 if not AnyChecked(Self) then Exit;
345
346 Result := '';
347
348 if cbSwapData.Checked then
349 begin
350 Result := Format('%s -x %s', [Result, 'swap']);
351 end;
352
353 if gbTransform.Enabled and cbTransform.Checked then
354 begin
355 Result := Format('%s -x %s', [Result, 'transform,']);
356 case cobTransformType.ItemIndex of
357 0: Result := Result + 'rte=wpt';
358 1: Result := Result + 'wpt=rte';
359 2: Result := Result + 'trk=rte';
360 3: Result := Result + 'rte=trk';
361 4: Result := Result + 'trk=wpt';
362 5: Result := Result + 'wpt=trk';
363 end;
364 if cbTransformDelete.Checked then
365 Result := Result + ',del=y' else
366 Result := Result + ',del=n';
367 end;
368 if AnyChecked(gbWaypoints) then
369 begin
370 if cbWayptMergeDups.Checked and
371 (cbWayptMergeDupNames.Checked or cbWayptMergeDupLoc.Checked) then
372 begin
373 Result := Format('%s -x %s', [Result, 'duplicate']);
374 if cbWayptMergeDupNames.Checked then
375 Result := Format('%s,%s', [Result, 'shortname']);
376 if cbWayptMergeDupLoc.Checked then
377 Result := Format('%s,%s', [Result, 'location']);
378 end;
379 if cbWayptMergeDistance.Checked then
380 begin
381 Result := Format('%s -x position,distance=%s', [Result, edWayptMergeDist.Text]);
382 if (cobWayptMergeDistUnit.ItemIndex = 0) then
383 Result := Result + 'f' else
384 Result := Result + 'm';
385 end;
386 if cbWayptRadius.Checked then
387 begin
388 Result := Format('%s -x radius,distance=%s', [Result, edWayptRadius.Text]);
389 if (cobWayptRadiusUnit.ItemIndex = 0) then
390 Result := Result + 'M' else
391 Result := Result + 'K';
392 Result := Format('%s,lat=%s,lon=%s', [Result, edWayptRadiusLat.Text, edWayptRadiusLon.Text]);
393 end;
394 SimpleOption(Result, cbWayptSort, 'sort');
395 end;
396
397 if AnyChecked(gbTracks) then
398 begin
399 Result := Format('%s -x %s', [Result, 'track']);
400 if cbTrackTitle.Checked then
401 Result := Format('%s,title="%s"', [Result, edTrackTitleValue.Text]);
402
403 if cbTrackTime.Checked then
404 begin
405 s := Format('%sd%sh%sm%ss',
406 [edTrackTimeDays.Text, edTrackTimeHours.Text,
407 edTrackTimeMinutes.Text, edTrackTimeSeconds.Text]);
408 if (s <> '0d0h0m0s') then
409 Result := Format('%s,move=%s', [Result, s]);
410 end;
411
412 if cbTrackPack.Checked then
413 Result := Format('%s,pack', [Result])
414 else if cbTrackMerge.Checked then
415 Result := Format('%s,merge', [Result]);
416
417 if cbTrackSplit.Checked then
418 Result := Format('%s,split', [Result]);
419
420 if (cbTrackRangeTimeZone.Enabled and cbTrackRangeTimeZone.Checked) then
421 begin
422 Windows.GetTimeZoneInformation(tz_Info);
423 tz_Info.Bias := tz_Info.Bias + tz_Info.DaylightBias;
424 dt_bias := tz_Info.Bias / (24*60);
425 end
426 else
427 dt_bias := 0.0;
428
429 if cbTrackStart.Checked then
430 begin
431 dt := Int(dtpTrackStartDate.DateTime) + Frac(dtpTrackStartTime.DateTime) + dt_bias;
432 Result := Format('%s,start=%s', [
433 Result,
434 FormatDateTime('yyyymmddhhnnss', dt)]);
435 end;
436 if cbTrackStop.Checked then
437 begin
438 dt := Int(dtpTrackStopDate.DateTime) + Frac(dtpTrackStopTime.DateTime) + dt_bias;
439 Result := Format('%s,stop=%s', [
440 Result,
441 FormatDateTime('yyyymmddhhnnss', dt)]);
442 end;
443 if cbGPSfix.Checked then
444 Result := Format('%s,fix=%s', [Result, cobGPSfixes.Text]);
445 if cbTrackCourse.Checked then
446 Result := Format('%s,course', [Result]);
447 if cbTrackSpeed.Checked then
448 Result := Format('%s,speed', [Result]);
449 end;
450
451 if AnyChecked(gbRoutes) then
452 begin
453 if cbRouteSimplify.Checked then
454 Result := Format('%s -x simplify,count=%s',
455 [Result, Trim(edRoutesSimplifyMaxPoints.Text)]);
456
457 SimpleOption(Result, cbReverse, 'reverse');
458 end;
459 end;
460
AnyCheckednull461 function TfrmFilter.AnyChecked(Control: TWinControl): Boolean;
462 var
463 i: Integer;
464 c: TWinControl;
465 begin
466 Result := False;
467 for i := 0 to Self.ComponentCount - 1 do
468 begin
469 c := Pointer(Self.Components[i]);
470 if not(c.InheritsFrom(TWinControl)) then Continue;
471 if (c.parent <> Control) then Continue;
472
473 if ((c is TCheckBox) and TCheckBox(c).Enabled) then
474 Result := TCheckBox(c).Checked else
475 if ((c is TGroupBox) and c.Enabled) then
476 Result := AnyChecked(c) else
477 if (c is TPanel) then
478 Result := AnyChecked(c);
479
480 if (Result) then Exit;
481 end;
482 end;
483
484 procedure TfrmFilter.SetTracksEnabled(const Value: Boolean);
485 begin
486 FTracksEnabled := Value;
487 gbTracks.Enabled := Value;
488 end;
489
TfrmFilter.AllValidnull490 function TfrmFilter.AllValid: Boolean;
491 begin
492 Result := True;
493 end;
494
495 procedure TfrmFilter.btnOKClick(Sender: TObject);
496 begin
497 if AllValid then
498 begin
499 // StoreSettingsToInifile();
500 StoreSettingsToRegistry();
501 ModalResult := mrOK;
502 end;
503 end;
504
505 procedure TfrmFilter.cbTrackStartClick(Sender: TObject);
506 begin
507 dtpTrackStartDate.Enabled := cbTrackStart.Checked;
508 dtpTrackStartTime.Enabled := cbTrackStart.Checked;
509 cbTrackRangeTimeZone.Enabled :=
510 cbTrackStart.Checked or cbTrackStop.Checked;
511 end;
512
513 procedure TfrmFilter.cbTrackStopClick(Sender: TObject);
514 begin
515 dtpTrackStopDate.Enabled := cbTrackStop.Checked;
516 dtpTrackStopTime.Enabled := cbTrackStop.Checked;
517 cbTrackRangeTimeZone.Enabled :=
518 cbTrackStart.Checked or cbTrackStop.Checked;
519 end;
520
521 procedure TfrmFilter.cbRouteSimplifyClick(Sender: TObject);
522 begin
523 edRoutesSimplifyMaxPoints.Enabled := cbRouteSimplify.Checked;
524 end;
525
526 procedure TfrmFilter.cbTrackPackClick(Sender: TObject);
527 begin
528 if cbTrackPack.Checked then
529 cbTrackMerge.Checked := False;
530 end;
531
532 procedure TfrmFilter.cbTrackMergeClick(Sender: TObject);
533 begin
534 if cbTrackMerge.Checked then
535 cbTrackPack.Checked := False;
536 end;
537
538 procedure TfrmFilter.cbWayptMergeDistanceClick(Sender: TObject);
539 begin
540 edWayptMergeDist.Enabled := cbWayptMergeDistance.Checked;
541 cobWayptMergeDistUnit.Enabled := cbWayptMergeDistance.Checked;
542 end;
543
544 procedure TfrmFilter.cbWayptMergeDupsClick(Sender: TObject);
545 begin
546 cbWayptMergeDupLoc.Enabled := cbWayptMergeDups.Checked;
547 cbWayptMergeDupNames.Enabled := cbWayptMergeDups.Checked;
548 end;
549
550 procedure TfrmFilter.cbWayptRadiusClick(Sender: TObject);
551 begin
552 edWayptRadius.Enabled := cbWayptRadius.Checked;
553 cobWayptRadiusUnit.Enabled := cbWayptRadius.Checked;
554 edWayptRadiusLat.Enabled := cbWayptRadius.Checked;
555 edWayptRadiusLon.Enabled := cbWayptRadius.Checked;
556 end;
557
558 procedure TfrmFilter.FormCloseQuery(Sender: TObject;
559 var CanClose: Boolean);
560 begin
561 if (ModalResult <> mrOK) then
562 begin
563 ChangeCheckBoxesChecked(Self, True);
564 CanClose := True;
565 Exit;
566 end;
567 CanClose :=
568 ValidateNumerical(edWayptRadius, 0, 99999) and
569 ValidateNumerical(edWayptRadiusLat, -90, 90) and
570 ValidateNumerical(edWayptRadiusLon, -180, 180) and
571 ValidateNumerical(edWayptMergeDist, 0, 99999999) and
572 ValidateNumerical(edRoutesSimplifyMaxPoints, 1, 9999);
573 ChangeCheckBoxesChecked(Self, False);
574 end;
575
576 procedure TfrmFilter.FormShow(Sender: TObject);
577 begin
578 ChangeCheckBoxesChecked(Self);
579 FInitialValues := CmdLine;
580 end;
581
582 procedure TfrmFilter.ChangeCheckBoxesChecked(AComponent: TComponent; Restore: Boolean = False);
583 var
584 i, j: Integer;
585 c: TComponent;
586 begin
587 j := AComponent.ComponentCount;
588 for i := 0 to j - 1 do
589 begin
590 c := AComponent.Components[i];
591 if (c is TCheckBox) then
592 begin
593 if (Restore) then
594 TCheckBox(c).Checked := (c.Tag <> 0) else
595 c.Tag := Integer(TCheckBox(c).Checked);
596 end
597 else if (c.ComponentCount > 0) then
598 ChangeCheckBoxesChecked(c);
599 end;
600 end;
601
602 procedure TfrmFilter.FormKeyDown(Sender: TObject; var Key: Word;
603 Shift: TShiftState);
604 var
605 str: string;
606 begin
607 if (Key <> 27) then Exit;
608
609
610 str := Self.CmdLine;
611 if (str <> FInitialValues) then
612 begin
613 if not(MessageDlg(_('Discard changes?'), mtWarning, mbOKCancel, 0) = mrOK) then
614 Exit;
615 end;
616 ModalResult := mrCancel;
617 end;
618
619 procedure TfrmFilter.btnHelpClick(Sender: TObject);
620 begin
621 WinOpenURL(readme_html_path + '#Data_Filters');
622 end;
623
624 procedure TfrmFilter.LoadSettingsFromInifile();
625 var
626 c: TComponent;
627 i: Integer;
628 l: TStrings;
629 s: string;
630 begin
631 (*
632 l := TStringList.Create;
633 try
634 gpsbabel_ini.ReadSection('GPSBabelGUI', l);
635 for i := 0 to l.Count - 1 do
636 begin
637 s := l.Strings[i];
638 c := SELF.FindComponent('cb' + s);
639 if (c <> nil) and (c is TCheckbox) then
640 TCheckbox(c).Checked := (gpsbabel_ini.ReadString('GPSBabelGUI', s, '0') <> '0');
641 end;
642 edTrackTitleValue.Text := gpsbabel_ini.ReadString('track', 'title',
643 edTrackTitleValue.Text);
644 edRoutesSimplifyMaxPoints.Text := gpsbabel_ini.ReadString('simplify', 'count',
645 edRoutesSimplifyMaxPoints.Text);
646 finally
647 l.Free;
648 end;
649 *)
650 end;
651
652 procedure TfrmFilter.StoreSettingsToInifile();
653 var
654 i: Integer;
655 c: TComponent;
656 begin
657 (*
658 for i := 0 to SELF.ComponentCount - 1 do
659 begin
660 c := SELF.Components[i];
661 if (c is TCheckBox) then
662 begin
663 if TCheckBox(c).Checked then
664 gpsbabel_ini.WriteString('GPSBabelGUI', Copy(TCheckbox(c).Name, 3, 256), '1')
665 else
666 gpsbabel_ini.DeleteKey('GPSBabelGUI', Copy(TCheckbox(c).Name, 3, 256));
667 end;
668 end;
669
670 if cbTrackTitle.Checked then
671 gpsbabel_ini.WriteString('track', 'title', edTrackTitleValue.Text)
672 else
673 gpsbabel_ini.DeleteKey('track', 'title');
674
675 if cbRouteSimplify.Checked then
676 gpsbabel_ini.WriteString('simplify', 'count', edRoutesSimplifyMaxPoints.Text)
677 else
678 gpsbabel_ini.DeleteKey('simplify', 'count');
679 *)
680 end;
681
682 procedure TfrmFilter.StoreSettingsToRegistry();
683 var
684 i: Integer;
685 c: TComponent;
686 r: TRegistry;
687 begin
688 r := TRegistry.Create;
689 try
690 r.RootKey := HKEY_CURRENT_USER;
691 if not(r.OpenKey('\SOFTWARE\GPSBabel', True)) then Exit;
692
693 for i := 0 to SELF.ComponentCount - 1 do
694 begin
695 c := SELF.Components[i];
696 if (c is TCheckbox) then
697 r.WriteBool('filter:' + Copy(c.Name, 3, 256), TCheckBox(c).Checked)
698 else if (c is TEdit) then
699 r.WriteString('filter:' + Copy(c.Name, 3, 256), TEdit(c).Text)
700 else if (c is TCombobox) then
701 r.WriteString('filter:' + Copy(c.Name, 4, 256), IntToStr(TCombobox(c).ItemIndex));
702 end;
703 finally
704 r.Free;
705 end;
706 end;
707
708 procedure TfrmFilter.LoadSettingsFromRegistry();
709 var
710 i: Integer;
711 c: TComponent;
712 r: TRegistry;
713 s: string;
714 u: TUpDown;
715
ReadStringnull716 function ReadString(R: TRegistry; const Key, Def: string): string;
717 begin
718 if R.ValueExists(Key) then
719 Result := R.ReadString(Key)
720 else
721 Result := Def;
722 end;
723
724 begin
725 r := TRegistry.Create;
726 try
727 r.RootKey := HKEY_CURRENT_USER;
728 if not(r.OpenKey('\SOFTWARE\GPSBabel', True)) then Exit;
729
730 for i := 0 to SELF.ComponentCount - 1 do
731 begin
732 c := SELF.Components[i];
733 try
734 if (c is TCheckbox) then
735 TCheckBox(c).Checked := r.ReadBool('filter:' + Copy(c.Name, 3, 256))
736 else if (c is TEdit) then
737 begin
738 s := ReadString(r, 'filter:' + Copy(c.Name, 3, 256), TEdit(c).Text);
739 if HasUpDown(TEdit(c), u) then
740 u.Position := StrToInt(s)
741 else
742 TEdit(c).Text := s;
743 end
744 else if (c is TCombobox) then
745 begin
746 s := ReadString(r, 'filter:' + Copy(c.Name, 4, 256), '0');
747 TCombobox(c).ItemIndex := StrToIntDef(s, 0);
748 end;
749 except
750 on E: Exception do ;
751 end;
752 end;
753 finally
754 r.Free;
755 end;
756 end;
757
758 procedure TfrmFilter.cbTransformClick(Sender: TObject);
759 begin
760 cobTransformType.Enabled := cbTransform.Checked;
761 cbTransformDelete.Enabled := cbTransform.Checked;
762 end;
763
764 procedure TfrmFilter.FormClose(Sender: TObject; var Action: TCloseAction);
765 begin
766 StoreBounds('filter_form', Self);
767 end;
768
769 procedure TfrmFilter.cbGPSfixClick(Sender: TObject);
770 begin
771 cobGPSfixes.Enabled := TCheckBox(Sender).Checked;
772 end;
773
774 end.
775