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
|
unit dlheader;
{$mode objfpc}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Spin, uPascalTZ, appsettings,
LCLIntf
//, Grids
//, StrUtils
;
type
{ TDLHeaderForm }
TDLHeaderForm = class(TForm)
Button1: TButton;
CloseButton: TButton;
CoverOffsetEntry: TLabeledEdit;
DataSupplierEntry: TLabeledEdit;
DefinitionsLink: TLabel;
TZRefLink: TLabel;
EditPositionButton: TButton;
FieldOfViewEntry: TLabeledEdit;
FiltersPerChannelEntry: TComboBox;
PDFDocButton: TButton;
SelectedGroupBox: TGroupBox;
InstrumentIDEntry: TLabeledEdit;
InvalidInstrumentID: TLabel;
Label10: TLabel;
Label11: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
LocationNameEntry: TLabeledEdit;
MeasurementDirectionPerChannelEntry: TLabeledEdit;
MovingStationaryDirectionCombo: TComboBox;
MovingStationaryPositionCombo: TComboBox;
NumberOfChannelsEntry: TSpinEdit;
PositionEntry: TLabeledEdit;
ScrollBox1: TScrollBox;
SerialNumber: TLabeledEdit;
TimeSynchEntry: TLabeledEdit;
TZLocationBox: TComboBox;
TZRegionBox: TComboBox;
UserComment1: TLabeledEdit;
UserComment2: TEdit;
UserComment3: TEdit;
UserComment4: TEdit;
UserComment5: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PDFDocButtonClick(Sender: TObject);
procedure CloseButtonClick(Sender: TObject);
procedure EditPositionButtonClick(Sender: TObject);
procedure CoverOffsetEntryChange(Sender: TObject);
procedure DefinitionsLinkClick(Sender: TObject);
procedure DefinitionsLinkMouseEnter(Sender: TObject);
procedure DefinitionsLinkMouseLeave(Sender: TObject);
procedure FiltersPerChannelEntryChange(Sender: TObject);
procedure FieldOfViewEntryChange(Sender: TObject);
procedure MeasurementDirectionPerChannelEntryChange(Sender: TObject);
procedure MovingStationaryDirectionComboChange(Sender: TObject);
procedure MovingStationaryPositionComboChange(Sender: TObject);
procedure DataSupplierEntryChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure InstrumentIDEntryChange(Sender: TObject);
procedure NumberOfChannelsEntryChange(Sender: TObject);
procedure TimeSynchEntryChange(Sender: TObject);
procedure LocationNameEntryChange(Sender: TObject);
procedure TZLocationBoxChange(Sender: TObject);
procedure TZRefLinkClick(Sender: TObject);
procedure TZRegionBoxChange(Sender: TObject);
procedure UserComment1Change(Sender: TObject);
procedure UserComment2Change(Sender: TObject);
procedure UserComment3Change(Sender: TObject);
procedure UserComment4Change(Sender: TObject);
procedure UserComment5Change(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
procedure ReadINI();
function CheckInstrumentID() : Boolean;
end;
var
SerialINIsection: String;
DLHeaderForm: TDLHeaderForm;
AZones: TStringList;
ptz :TPascalTZ;
TZInitialLoad:Boolean = True;
LoadingValues:Boolean = False;
implementation
uses Unit1
, worldmap
, logcont
, header_utils
;
{ TDLHeaderForm }
{ Save the TZ selection. }
procedure TDLHeaderForm.TZLocationBoxChange(Sender: TObject);
begin
if not LoadingValues then begin
vConfigurations.WriteString(SerialINIsection,'Local time zone',TZLocationBox.Text);
SelectedTZLocation:=vConfigurations.ReadString(SerialINIsection,'Local time zone');
end;
end;
procedure TDLHeaderForm.TZRefLinkClick(Sender: TObject);
begin
{Link to very complete Wikipedia list of time zones with offsets explained}
OpenURL('https://en.wikipedia.org/wiki/List_of_tz_database_time_zones');
end;
procedure TDLHeaderForm.TZRegionBoxChange(Sender: TObject);
begin
if not LoadingValues then begin
{ Clear out location because region has changed. }
//TZLocationBox.Text:=''; { not needed, and in Mac, this always clears the field on INI for some strange GUI threading issue}
{ Save the TZ region selection. }
SelectedTZRegion:=TZRegionBox.Text;
Application.ProcessMessages;
vConfigurations.WriteString(SerialINIsection,'Local region',SelectedTZRegion);
{ Read the region database table. }
ptz.Destroy;
ptz := TPascalTZ.Create();
ptz.ParseDatabaseFromFile(appsettings.TZDirectory+SelectedTZRegion);
Azones.Clear;
ptz.GetTimeZoneNames(AZones,true); //only geo name = true
TZLocationBox.Items.Clear;
TZLocationBox.Items.AddStrings(AZones);
end;
end;
procedure TDLHeaderForm.FormCreate(Sender: TObject);
begin
{ Initialize required variables. }
AZones:=TStringList.Create;
ptz := TPascalTZ.Create();
CheckInstrumentID;
end;
procedure TDLHeaderForm.FormDestroy(Sender: TObject);
begin
AZones.Destroy;
ptz.Destroy;
end;
procedure TDLHeaderForm.Button1Click(Sender: TObject);
begin
{check specific timezone, from upascaltz example wiki}
if ptz.TimeZoneExists('Australia/AS') then
StatusMessage('tz exists.') else
StatusMessage('tz does not exist.');
end;
procedure TDLHeaderForm.DataSupplierEntryChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Data Supplier',DataSupplierEntry.Text);
end;
procedure TDLHeaderForm.MovingStationaryPositionComboChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Moving Stationary Position',MovingStationaryPositionCombo.Text);
end;
procedure TDLHeaderForm.MovingStationaryDirectionComboChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Moving Stationary Direction',MovingStationaryDirectionCombo.Text);
end;
procedure TDLHeaderForm.FiltersPerChannelEntryChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Filters Per Channel',FiltersPerChannelEntry.Text);
end;
procedure TDLHeaderForm.CoverOffsetEntryChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'CoverOffset',CoverOffsetEntry.Text);
end;
procedure TDLHeaderForm.DefinitionsLinkClick(Sender: TObject);
begin
OpenURL(DefinitionsLink.Caption);
end;
procedure TDLHeaderForm.DefinitionsLinkMouseEnter(Sender: TObject);
begin
DefinitionsLink.Cursor := crHandPoint;
DefinitionsLink.Font.Color := clBlue;
DefinitionsLink.Font.Style := [fsUnderline];
if Pos('http://www.', DefinitionsLink.Caption) = 0 then
DefinitionsLink.Caption := 'http://www.' + DefinitionsLink.Caption;
end;
procedure TDLHeaderForm.DefinitionsLinkMouseLeave(Sender: TObject);
begin
DefinitionsLink.Font.Style := [];
if Pos('http://www.', DefinitionsLink.Caption) > 0 then
DefinitionsLink.Caption := Copy(DefinitionsLink.Caption, Pos('http://www.', DefinitionsLink.Caption) + Length('http://www.'), Length(DefinitionsLink.Caption));
end;
procedure TDLHeaderForm.CloseButtonClick(Sender: TObject);
begin
Close;
end;
procedure TDLHeaderForm.PDFDocButtonClick(Sender: TObject);
begin
OpenDocument(appsettings.DataDirectory+'47_SKYGLOW_DEFINITIONS.PDF');
end;
procedure TDLHeaderForm.EditPositionButtonClick(Sender: TObject);
begin
worldmap.FormWorldmap.WorldmapShow('DLHeader', PositionEntry.Text );
end;
procedure TDLHeaderForm.UserComment1Change(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'UserComment1',UserComment1.Text);
end;
procedure TDLHeaderForm.UserComment2Change(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'UserComment2',UserComment2.Text);
end;
procedure TDLHeaderForm.UserComment3Change(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'UserComment3',UserComment3.Text);
end;
procedure TDLHeaderForm.UserComment4Change(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'UserComment4',UserComment4.Text);
end;
procedure TDLHeaderForm.UserComment5Change(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'UserComment5',UserComment5.Text);
end;
procedure TDLHeaderForm.FieldOfViewEntryChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Field Of View',FieldOfViewEntry.Text);
end;
procedure TDLHeaderForm.ReadINI();
var
pieces: TStringList;
begin
{Prevent other routines from affecting the Time zone location name}
TZInitialLoad:=True;
{Prepare for parsing}
pieces := TStringList.Create;
pieces.Delimiter := ',';
pieces.StrictDelimiter := False; {will be parsing spaces }
{Determine the section based on the selected serial number}
SerialINIsection:='Serial:'+Unit1.SelectedUnitSerialNumber;
{ Pull Timezone information from INI file if it exists.}
SelectedTZRegion:= vConfigurations.ReadString(SerialINIsection,'Local region');
TZRegionBox.Text:=SelectedTZRegion;
if (FileExists(appsettings.TZDirectory+SelectedTZRegion) and (length(SelectedTZRegion)>0))then begin
ptz.Destroy;
ptz := TPascalTZ.Create();
ptz.ParseDatabaseFromFile(appsettings.TZDirectory+SelectedTZRegion);
ptz.GetTimeZoneNames(AZones,true); //only geo name = true, does not show short names
TZLocationBox.Items.Clear;
TZLocationBox.Items.AddStrings(AZones);
end;
{ Read the previously recorded entries. }
SelectedTZLocation:=vConfigurations.ReadString(SerialINIsection,'Local time zone');
TZLocationBox.Text:=SelectedTZLocation;
InstrumentIDEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Instrument ID');
DataSupplierEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Data Supplier');
LocationNameEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Location Name');
PositionEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Position');
{Parse location}
pieces.DelimitedText := PositionEntry.Text;
if pieces.Count>1 then begin
MyLatitude:=StrToFloatDef(pieces.Strings[0],0);
MyLongitude:=StrToFloatDef(pieces.Strings[1],0);
end else begin
MyLatitude:=0;
MyLongitude:=0;
end;
//Parse elevation
if pieces.Count>2 then begin
MyElevation:=StrToFloatDef(pieces.Strings[2],0);
end else begin
MyElevation:=0;
end;
TimeSynchEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Time Synchronization');
MovingStationaryPositionCombo.Text:=vConfigurations.ReadString(SerialINIsection,'Moving Stationary Position');
MovingStationaryDirectionCombo.Text:=vConfigurations.ReadString(SerialINIsection,'Moving Stationary Direction');
NumberOfChannelsEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Number Of Channels');
FiltersPerChannelEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Filters Per Channel');
MeasurementDirectionPerChannelEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Measurement Direction Per Channel');
FieldOfViewEntry.Text:=vConfigurations.ReadString(SerialINIsection,'Field Of View');
CoverOffsetEntry.Text:=vConfigurations.ReadString(SerialINIsection,'CoverOffset');
UserComment1.Text:=vConfigurations.ReadString(SerialINIsection,'UserComment1');
UserComment2.Text:=vConfigurations.ReadString(SerialINIsection,'UserComment2');
UserComment3.Text:=vConfigurations.ReadString(SerialINIsection,'UserComment3');
UserComment4.Text:=vConfigurations.ReadString(SerialINIsection,'UserComment4');
UserComment5.Text:=vConfigurations.ReadString(SerialINIsection,'UserComment5');
//GPS tab
FormLogCont.GPSPortSelect.Text:=vConfigurations.ReadString(SerialINIsection,'GPS Port');
logcont.GPSBaudrate:=StrToIntDef(vConfigurations.ReadString(SerialINIsection,'GPS Baud','4800'),4800);
FormLogCont.GPSBaudSelect.Text:=IntToStr(logcont.GPSBaudrate);
FormLogCont.GPSEnable.Checked:=vConfigurations.ReadBool(SerialINIsection,'GPS Enabled');
//GoTo tab
logcont.GotoBaudrate:=StrToIntDef(vConfigurations.ReadString('GoToSettings','GoTo Baud',''),9600);
FormLogCont.GoToBaudSelect.Text:=IntToStr(logcont.GoToBaudrate);
//Write hardware identifier (Ethernet-MAC, USB-ID)
{This detail is not chosen by the user, it is automatically stored after reading other header information.}
vConfigurations.WriteString(SerialINIsection,'HardwareID',SelectedHardwareID);
if Assigned(pieces) then
FreeAndNil(pieces);
TZInitialLoad:=False; {Allow other routines to affect the Time zone location name}
end;
procedure TDLHeaderForm.MeasurementDirectionPerChannelEntryChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Measurement Direction Per Channel',MeasurementDirectionPerChannelEntry.Text);
end;
function TDLHeaderForm.CheckInstrumentID() : Boolean;
var
CheckChar: char;
begin
CheckInstrumentID:=True; {Assume that text is valid}
for CheckChar in InstrumentIDEntry.Text do
if not (CheckChar in ['0'..'9','A'..'Z','a'..'z','_','-']) then
CheckInstrumentID:=False;
InvalidInstrumentID.Visible:=not CheckInstrumentID;
end;
procedure TDLHeaderForm.InstrumentIDEntryChange(Sender: TObject);
begin
if not LoadingValues then begin
Application.ProcessMessages; //Wait for widgets to become visible
if CheckInstrumentID then
vConfigurations.WriteString(SerialINIsection,'Instrument ID',InstrumentIDEntry.Text);
end;
end;
procedure TDLHeaderForm.NumberOfChannelsEntryChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Number Of Channels',NumberOfChannelsEntry.Text);
end;
procedure TDLHeaderForm.TimeSynchEntryChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Time Synchronization',TimeSynchEntry.Text);
end;
procedure TDLHeaderForm.LocationNameEntryChange(Sender: TObject);
begin
if not LoadingValues then
vConfigurations.WriteString(SerialINIsection,'Location Name',LocationNameEntry.Text)
end;
initialization
{$I dlheader.lrs}
end.
|