Skip to content

Commit

Permalink
CQ WPX - editable exchange field (starting number or #) (#280)
Browse files Browse the repository at this point in the history
Improve error checking while editing Exchange field.
- Exchange field is now editable for CQ WPX Contest.
- User can specify a number or `#`.
  - The number is the starting serial NR.
- The `#` represents the auto-generated sequence number. The initial
value will be randomly generated when running with `Mid-Contest` or `End
of Contest` Serial NR modes.
- Improved error checking and reporting
- fixes #278
  • Loading branch information
w7sst authored Mar 8, 2024
2 parents 9d6fdd6 + 381aa37 commit 409d6bd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Ini.pas
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ TContestDefinition = record
Key: 'CqWpx';
ExchType1: etRST;
ExchType2: etSerialNr;
ExchFieldEditable: False;
ExchFieldEditable: True;
ExchDefault: '5NN #';
Msg: '''RST <serial>'' (e.g. 5NN #|123)';
T:scWpx),
Expand Down
1 change: 1 addition & 0 deletions Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ object MainForm: TMainForm
CharCase = ecUpperCase
TabOrder = 1
Text = '3A ON'
OnChange = ExchangeEditChange
OnExit = ExchangeEditExit
end
end
Expand Down
38 changes: 29 additions & 9 deletions Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ TFieldDefinition = record
// Adding a contest: define contest-specific field types
// Exchange Field 1 settings/rules
Exchange1Settings: array[TExchange1Type] of TFieldDefinition = (
(C: 'RST'; R: '[5E][9N][9N]'; L: 3; T:Ord(etRST)),
(C: 'RST'; R: '[1-5E][1-9N][1-9N]'; L: 3; T:Ord(etRST)),
(C: 'Name'; R: '[A-Z][A-Z]*'; L: 10; T:Ord(etOpName)),
(C: 'Class'; R: '[1-9][0-9]*[A-F]'; L: 3; T:Ord(etFdClass))
);

// Exchange Field 2 settings/rules
Exchange2Settings: array[TExchange2Type] of TFieldDefinition = (
(C: 'Nr.'; R: '([0-9][0-9]*)|(#)'; L: 4; T:Ord(etSerialNr)),
(C: 'Nr.'; R: '([0-9OTN]+)|(#)'; L: 4; T:Ord(etSerialNr)),
(C: 'Exch'; R: '[0-9A-Z]*'; L: 12; T:Ord(etGenericField)),
(C: 'Section'; R: '([A-Z][A-Z])|([A-Z][A-Z][A-Z])'; L: 3; T:Ord(etArrlSection)),
(C: 'State/Prov'; R: '[ABCDFGHIKLMNOPQRSTUVWY][ABCDEFHIJKLMNORSTUVXYZ]';
Expand Down Expand Up @@ -355,6 +355,7 @@ TMainForm = class(TForm)
procedure mnuShowCallsignInfoClick(Sender: TObject);
procedure SimContestComboChange(Sender: TObject);
procedure SimContestComboPopulate;
procedure ExchangeEditChange(Sender: TObject);
procedure ExchangeEditExit(Sender: TObject);
procedure Edit4Exit(Sender: TObject);
procedure SpinEdit1Exit(Sender: TObject);
Expand All @@ -363,6 +364,7 @@ TMainForm = class(TForm)
private
MustAdvance: boolean; // Controls when Exchange fields advance
UserCallsignDirty: boolean; // SetMyCall is called after callsign edits
UserExchangeDirty: boolean; // SetMyExchange is called after exchange edits
CWSpeedDirty: boolean; // SetWpm is called after CW Speed edits
RitLocal: integer; // tracks incremented RIT Value
function CreateContest(AContestId : TSimContest) : TContest;
Expand Down Expand Up @@ -397,11 +399,11 @@ TMainForm = class(TForm)
procedure PopupScoreHst;
procedure Advance;
procedure SetContest(AContestNum: TSimContest);
procedure SetMyExchange(const AExchange: string);
function SetMyExchange(const AExchange: string) : Boolean;
procedure SetMySerialNR;
procedure SetQsk(Value: boolean);
procedure SetWpm(AWpm : integer);
procedure SetMyCall(ACall: string);
function SetMyCall(ACall: string) : Boolean;
procedure SetPitch(PitchNo: integer);
procedure SetBw(BwNo: integer);
procedure ReadCheckboxes;
Expand Down Expand Up @@ -476,6 +478,9 @@ procedure TMainForm.FormCreate(Sender: TObject);
ListView2.Visible:= False;
ListView2.Clear;

UserCallsignDirty := False;
UserExchangeDirty := False;

// populate and sort SimContestCombo
SimContestComboPopulate;

Expand Down Expand Up @@ -1025,9 +1030,16 @@ procedure TMainForm.Edit4Exit(Sender: TObject);
SetMyCall(Trim(Edit4.Text));
end;

procedure TMainForm.ExchangeEditChange(Sender: TObject);
begin
// exchange edit callsign edit has occurred; allows SetMyCall to be called.
UserExchangeDirty := True;
end;

procedure TMainForm.ExchangeEditExit(Sender: TObject);
begin
SetMyExchange(Trim(ExchangeEdit.Text));
if UserExchangeDirty then
SetMyExchange(Trim(ExchangeEdit.Text));
end;

procedure TMainForm.SetContest(AContestNum: TSimContest);
Expand Down Expand Up @@ -1110,7 +1122,7 @@ procedure TMainForm.SetContest(AContestNum: TSimContest);
My "sent" exchange types (Tst.Me.SentExchTypes) have been previously set by
SetMyCall().
}
procedure TMainForm.SetMyExchange(const AExchange: string);
function TMainForm.SetMyExchange(const AExchange: string) : Boolean;
var
sl: TStringList;
SentExchTypes : TExchTypes;
Expand All @@ -1136,6 +1148,7 @@ procedure TMainForm.SetMyExchange(const AExchange: string);
if not ValidateExchField(Field1Def, sl[0]) or
not ValidateExchField(Field2Def, sl[1]) then
begin
Result := False;
sbar.Caption := Format('Invalid exchange: ''%s'' - expecting %s.',
[AExchange, ActiveContest.Msg]);

Expand All @@ -1150,6 +1163,7 @@ procedure TMainForm.SetMyExchange(const AExchange: string);
end
else
begin
Result := True;
sbar.Visible := mnuShowCallsignInfo.Checked;
sbar.Font.Color := clDefault;
sbar.Caption := '';
Expand All @@ -1167,6 +1181,7 @@ procedure TMainForm.SetMyExchange(const AExchange: string);
// update application's title bar
UpdateTitleBar;

UserExchangeDirty := False;
finally
sl.Free;
end;
Expand All @@ -1189,7 +1204,7 @@ procedure TMainForm.SetMySerialNR;
end;


procedure TMainForm.SetMyCall(ACall: string);
function TMainForm.SetMyCall(ACall: string) : Boolean;
var
err : string;
begin
Expand All @@ -1202,14 +1217,15 @@ procedure TMainForm.SetMyCall(ACall: string);
if not Tst.OnSetMyCall(ACall, err) then
begin
MessageDlg(err, mtError, [mbOK], 0);
Result := False;
Exit;
end;
assert(Tst.Me.SentExchTypes = Tst.GetSentExchTypes(skMyStation, ACall));

// update my "sent" exchange information.
// depends on: contest, my call, sent exchange (ExchangeEdit).
// SetMyExchange() may report an error in the status field.
SetMyExchange(Trim(ExchangeEdit.Text));
Result := SetMyExchange(Trim(ExchangeEdit.Text));

// update "received" Exchange field types, labels and length settings
// (e.g. RST, Nr.). depends on: contest, my call and dx station's call.
Expand Down Expand Up @@ -1704,7 +1720,11 @@ procedure TMainForm.Run(Value: TRunMode);
to check the accuracy of the entered QSO.
}
if UserCallsignDirty then
SetMyCall(Trim(Edit4.Text));
if not SetMyCall(Trim(Edit4.Text)) then
Exit;
if UserExchangeDirty then
if not SetMyExchange(Trim(ExchangeEdit.Text)) then
Exit;

// load call history and other contest-specific setup before starting
if not Tst.OnContestPrepareToStart(Ini.Call, ExchangeEdit.Text) then
Expand Down

0 comments on commit 409d6bd

Please sign in to comment.