Skip to content

Commit

Permalink
prepare for alpha release
Browse files Browse the repository at this point in the history
  • Loading branch information
RooieDirk committed Jan 18, 2018
1 parent d052cad commit 41b2c79
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 103 deletions.
Binary file modified Help page.odt
Binary file not shown.
11 changes: 5 additions & 6 deletions src/SharedStuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Meassurement::Meassurement ()
lon=181.0;
methode=0;
enabled=true;
MeassurementRemarks=wxEmptyString;
}

Meassurement::~Meassurement ()
Expand Down Expand Up @@ -74,14 +75,15 @@ ship_data::~ship_data()

double SolarAzimuth( wxDateTime dt, double latitude, double longitude)
{
//dt.MakeUTC();
spa_data spa; //declare the SPA structure
int result;
//float min, sec;

//enter required input values into SPA structure

spa.year = dt.GetHour(0);
spa.month = dt.GetMonth(0);
spa.year = dt.GetYear();
spa.month = dt.GetMonth(0)+1; //GetMonth returns 0-11
spa.day = dt.GetDay(0);
spa.hour = dt.GetHour(0);
spa.minute = dt.GetMinute(0);
Expand All @@ -100,15 +102,12 @@ double SolarAzimuth( wxDateTime dt, double latitude, double longitude)
spa.function = SPA_ZA; //calculate zenith and azimuth

//call the SPA calculate function and pass the SPA structure

result = spa_calculate(&spa);

if (result == 0) //check for SPA errors
{
return spa.azimuth;
//display the results inside the SPA structure


//display the results inside the SPA structure
} else printf("SPA Error Code: %d\n", result);

return 0;
Expand Down
1 change: 1 addition & 0 deletions src/SharedStuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Meassurement : public wxObject
double lon;
int methode;
bool enabled;
wxString MeassurementRemarks;
compass_data* c_data;
wxString Choise1 = _("Relative bearing (Righthand bearing)");
wxString Choise2 = _("Bearing using \'Navigate to\'");
Expand Down
116 changes: 72 additions & 44 deletions src/bearingdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ const long BearingDlg::ID_STATICTEXT9 = wxNewId();
const long BearingDlg::ID_STATICTEXT10 = wxNewId();
const long BearingDlg::ID_STATICTEXT11 = wxNewId();
const long BearingDlg::ID_VARCTRL = wxNewId();
const long BearingDlg::ID_REMARKSCTRL = wxNewId();
//*)

BearingDlg::BearingDlg(wxWindow* parent, Meassurement* Mess, wxWindowID id,const wxPoint& pos,const wxSize& size, bool fullsize )
{
//(*Initialize(BearingDlg)
localMesData = Mess;

Remarks_value = wxEmptyString;
wxFlexGridSizer* FlexGridSizer1;
wxGridBagSizer* GridBagSizer1;
wxStdDialogButtonSizer* StdDialogButtonSizer1;
Expand All @@ -65,14 +66,14 @@ BearingDlg::BearingDlg(wxWindow* parent, Meassurement* Mess, wxWindowID id,const
Move(wxDefaultPosition);
FlexGridSizer1 = new wxFlexGridSizer(3, 1, 0, 0);
StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Methode"));
Choice = new wxChoice(this, ID_CHOICE, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE"));
Choice->SetSelection( Choice->Append(_("Bearing")) );
//Choice->Append(_("Relative bearing (Righthand bearing)"));
Choice->Append(_("Bearing using \'Navigate to\'"));
//Choice->Append(_("Steaming into \'Navigate to\'"));
Choice->Append(_("Steaming into"));// leading line"));
Choice->Append(_("Sun bearing"));
Choice->Append(_("Sun bearing shadowline"));
wxArrayString aS;
aS.Insert(_("Bearing"), devBEARING);
aS.Insert(_("Sun bearing"), devSUN_BEARING);
aS.Insert(_("Sun bearing shadowline"), devSUN_SHADOW);
//aS.Insert(_("Bearing from Route"), devBEARING_FROM_ROUTE);
Choice = new wxChoice (this, ID_CHOICE, wxDefaultPosition, wxDefaultSize, aS, 0, wxDefaultValidator, _T("ID_CHOICE"));
Choice->SetSelection( devBEARING );
StaticBoxSizer1->Add(Choice, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer1->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
GridBagSizer1 = new wxGridBagSizer(0, 0);
Expand All @@ -84,10 +85,13 @@ BearingDlg::BearingDlg(wxWindow* parent, Meassurement* Mess, wxWindowID id,const
GridBagSizer1->Add(DPickerCtrl, wxGBPosition(0, 1), wxDefaultSpan, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
TPickerCtrl = new wxTimePickerCtrl(this, ID_TIMEPICKERCTRL, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxTP_DEFAULT, wxDefaultValidator, _T("ID_TIMEPICKERCTRL"));
GridBagSizer1->Add(TPickerCtrl, wxGBPosition(0, 2), wxDefaultSpan, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);

BearingChoice = new wxChoice(this, ID_CHOICE, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_STATICTEXT2"));
BearingChoice->Append(_("Compass bearing"));
BearingChoice->Append(_("Righthand bearing"));
wxArrayString aSb;
aSb.Insert(_("Compass bearing"), devCOMPASBEARING);
aSb.Insert(_("Righthand bearing"), devRIGHTHANDBEARING);
BearingChoice = new wxChoice (this, ID_CHOICE, wxDefaultPosition, wxDefaultSize, aSb, 0, wxDefaultValidator, _T("ID_CHOICE"));
BearingChoice->SetSelection( 0);
GridBagSizer1->Add(BearingChoice, wxGBPosition(2, 0), wxDefaultSpan, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);

StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Compass Course"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
GridBagSizer1->Add(StaticText2, wxGBPosition(1, 0), wxDefaultSpan, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
// Allow floating point numbers from 0 to 360 with 1 decimal
Expand Down Expand Up @@ -135,19 +139,18 @@ BearingDlg::BearingDlg(wxWindow* parent, Meassurement* Mess, wxWindowID id,const
StaticText6 = new wxStaticText(this, ID_STATICTEXT6, _("True Bearing"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
GridBagSizer1->Add(StaticText6, wxGBPosition(3, 0), wxDefaultSpan, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);

BearingChoice = new wxChoice(this, ID_STATICTEXT4, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_STATICTEXT4"));
BearingChoice->Append(_("Compass bearing"));
BearingChoice->Append(_("Righthand bearing"));
BearingChoice->SetSelection( 0);
StaticText12 = new wxStaticText(this, ID_STATICTEXT6, _("Remarks"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
GridBagSizer1->Add(StaticText12, wxGBPosition(6, 0), wxDefaultSpan, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);

RemarksCtr = new wxTextCtrl(this, ID_REMARKSCTRL, _("Text"), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE, wxTextValidator(wxFILTER_ALPHA, &Remarks_value), _T("ID_REMARKSCTRL"));
GridBagSizer1->Add(RemarksCtr, wxGBPosition(6, 1), wxGBSpan(1, 2), wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);

//StaticText4 = new wxStaticText(this, ID_STATICTEXT4, _("Compass Bearing"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
GridBagSizer1->Add(BearingChoice, wxGBPosition(2, 0), wxDefaultSpan, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_OK, wxEmptyString));
StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_CANCEL, wxEmptyString));
StdDialogButtonSizer1->Realize();

GridBagSizer1->Add(StdDialogButtonSizer1, wxGBPosition(6, 1), wxGBSpan(1, 2), wxALL|wxEXPAND|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
GridBagSizer1->Add(StdDialogButtonSizer1, wxGBPosition(7, 1), wxGBSpan(1, 2), wxALL|wxEXPAND|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);

FlexGridSizer1->Add(GridBagSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(FlexGridSizer1);
Expand All @@ -157,7 +160,7 @@ BearingDlg::BearingDlg(wxWindow* parent, Meassurement* Mess, wxWindowID id,const
CopyMessObjToDlg();
GPS_UpdateTime = 0;

Connect(ID_CHOICE,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&BearingDlg::ChoiseSelect);
Connect(ID_CHOICE,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&BearingDlg::OnChoiseSelect);
//Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&BearingDlg::OnClose);
Connect(wxID_ANY,wxEVT_COMMAND_TEXT_ENTER,(wxObjectEventFunction)&BearingDlg::OnTextCtrlEnter);
Connect(wxID_ANY,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&BearingDlg::OnTextCtrlEnter);
Expand All @@ -177,10 +180,11 @@ bool BearingDlg::Show(bool show)
{
bool temp = wxDialog::Show(show);
UpdateFlag = true; //Set updateflag after Textctr's are updated
Dev_PI->DoRouteLegRequest();
return temp;
}

void BearingDlg::ChoiseSelect(wxCommandEvent& event)
void BearingDlg::OnChoiseSelect(wxCommandEvent& event)
{
SetSunBearing(GetDateTime());
}
Expand Down Expand Up @@ -228,12 +232,11 @@ void BearingDlg::SetDateTime(wxDateTime dt)
DT_value = dt;
DPickerCtrl->SetValue(DT_value);
TPickerCtrl->SetValue(DT_value);
if (Choice->GetSelection()==3) //SunBearing
TrueBearingCtrl->ChangeValue( (wxString::Format(_("%03.1f"), SolarAzimuth( GetDateTime(), localMesData->lat, localMesData->lon) ) ) );
if (Choice->GetSelection()==devSUN_BEARING) //SunBearing
TrueBearingCtrl->ChangeValue( (wxString::Format(_("%05.1f"), SolarAzimuth( GetDateTime(), localMesData->lat, localMesData->lon) ) ) );

if (Choice->GetSelection()==4) //SunBearing shadow {
TrueBearingCtrl->ChangeValue( (wxString::Format(_("%03.1f"), limit_degrees(SolarAzimuth( GetDateTime(), localMesData->lat, localMesData->lon )+180) ) ) );

if (Choice->GetSelection()==devSUN_SHADOW) //SunBearing shadow {
TrueBearingCtrl->ChangeValue( (wxString::Format(_("%05.1f"), limit_degrees(SolarAzimuth( GetDateTime(), localMesData->lat, localMesData->lon )+180) ) ) );
}

wxDateTime BearingDlg::GetDateTime()
Expand All @@ -255,6 +258,7 @@ void BearingDlg::CopyDlgToMessObj ()
localMesData->datetime = GetDateTime();
localMesData->enabled = true;
localMesData->methode = Choice->GetSelection();
localMesData->MeassurementRemarks = Remarks_value;
}
void BearingDlg::CopyMessObjToDlg()
{
Expand All @@ -265,6 +269,7 @@ void BearingDlg::CopyMessObjToDlg()
DEV_value =localMesData->deviation;
SetDateTime( localMesData->datetime );
Choice->SetSelection(localMesData->methode);
Remarks_value = localMesData->MeassurementRemarks;
}
void BearingDlg::SetPositionFix(PlugIn_Position_Fix_Ex &pfix)
{
Expand All @@ -278,7 +283,7 @@ void BearingDlg::SetPositionFix(PlugIn_Position_Fix_Ex &pfix)
if ( UpdateFlag)
{
GetMessageVariation(localMesData->lat, localMesData->lon);
VariationCtrl->SetValue(wxString::Format(_("%f"), pfix.Var));
Dev_PI->DoRouteLegRequest();

if (GPS_UpdateTime <= 0)
{
Expand Down Expand Up @@ -306,7 +311,6 @@ void BearingDlg::SetNMEATimeFix(wxDateTime dt)
SetSunBearing(GetDateTime());

w->SetFocus(); // restore focus
wxPuts(_("BearingDlg::SetNMEATimeFix ") + dt.FormatISOTime());
}
UpdateFlag = TempFlag;

Expand All @@ -315,10 +319,10 @@ void BearingDlg::SetSunBearing(wxDateTime t)
{
bool TempFlag = UpdateFlag;
wxWindow *w = FindFocus();
if (Choice->GetSelection()==3) //SunBearing
TrueBearingCtrl->ChangeValue( (wxString::Format(_("%03.1f"), SolarAzimuth( GetDateTime(), localMesData->lat, localMesData->lon) ) ) );
if (Choice->GetSelection()==4) //SunBearing shadow
TrueBearingCtrl->ChangeValue( (wxString::Format(_("%03.1f"), limit_degrees(SolarAzimuth( GetDateTime(), localMesData->lat, localMesData->lon )+180) ) ) );
if (Choice->GetSelection()==devSUN_BEARING) //SunBearing
TrueBearingCtrl->ChangeValue( (wxString::Format(_("%05.1f"), SolarAzimuth( GetDateTime(), localMesData->lat, localMesData->lon) ) ) );
if (Choice->GetSelection()==devSUN_SHADOW) //SunBearing shadow
TrueBearingCtrl->ChangeValue( (wxString::Format(_("%05.1f"), limit_degrees(SolarAzimuth( GetDateTime(), localMesData->lat, localMesData->lon )+180) ) ) );
w->SetFocus(); // restore focus
UpdateFlag = TempFlag;
}
Expand All @@ -336,9 +340,6 @@ void BearingDlg::SetNMEAHeading(double hd)
w->SetFocus(); // restore focus
}
UpdateFlag = TempFlag;


wxPuts(_("BearingDlg::SetNMEAHeading"));
}

void BearingDlg::SetMessageVariation(wxString &message_id, wxString &message_body)
Expand All @@ -350,25 +351,52 @@ void BearingDlg::SetMessageVariation(wxString &message_id, wxString &message_bod

//TODO check lat/lon to make sure it is our requested message and not an otherone.
// get the DECL value from the JSON message
VariationCtrl->ChangeValue( v[_T("Decl")].AsString() );
wxPuts(_("VariationCtrl->ChangeValue Variation changed from messgae"));
VariationCtrl->ChangeValue( wxString::Format( _T("%05.1f"), v[_T("Decl")].AsDouble()) );
}
}
void BearingDlg::SetMessageRouteActiveLeg(wxString &message_id, wxString &message_body)
{
if ( UpdateFlag){
wxJSONReader r;
wxJSONValue v;
r.Parse(message_body, &v);

if ( v[_("error")].AsBool() ) // error means no active route avalable
{
if (Choice != NULL) // then we remove the option from the choice control
if(Choice->GetCount() > devBEARING_FROM_ROUTE )
Choice->Delete(devBEARING_FROM_ROUTE);
}
else // no error so there is an active route
{
if (Choice != NULL)
{
//If there was no active route choice available make it and select it.
if (Choice->GetCount() <= devBEARING_FROM_ROUTE )
{
Choice->Insert(_("Bearing from Route"), devBEARING_FROM_ROUTE);
Choice->SetSelection(devBEARING_FROM_ROUTE);
}

if ( Choice->GetSelection() == devBEARING_FROM_ROUTE )
{
TrueBearingCtrl->ChangeValue( wxString::Format( _T("%05.1f"), v[_T("bearing")].AsDouble() ) );
}
}
}
}
}
void BearingDlg::GetMessageVariation(double lat, double lon)
{
if ( (abs(lat) < 90.0) && (abs(lon) < 180.0) ) //valid position
if ( (abs(lat) < 90.0) && (abs(lon) <= 180.0) ) //valid position
{
wxJSONValue v;
v[_T("Lat")] = lat;
v[_T("Lon")] = lon;
v[_T("Year")] = GetDateTime().GetYear();
v[_T("Month")] = GetDateTime().GetMonth();
v[_T("Day")] = GetDateTime().GetDay();
Dev_PI->RequestPliginMessage( _T("WMM_VARIATION_REQUEST"), v);
Dev_PI->RequestPluginMessage( _T("WMM_VARIATION_REQUEST"), v);
}
}
// void BearingDlg::UpdateContrs()
// {
//
// }

19 changes: 17 additions & 2 deletions src/bearingdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
// class BearingDlg;
// BearingDlg* B_Dlg;

enum {
devBEARING = 0,
devSUN_BEARING = 1,
devSUN_SHADOW = 2,
devBEARING_FROM_ROUTE = 3
};
enum{
devCOMPASBEARING = 0,
devRIGHTHANDBEARING = 1
};

class BearingDlg: public wxDialog
{
public:
Expand All @@ -65,9 +76,11 @@ class BearingDlg: public wxDialog
wxStaticText* StaticText9;
wxStaticText* StaticText10;
wxStaticText* StaticText11;
wxStaticText* StaticText12;
wxTextCtrl* TrueBearingCtrl;
wxTextCtrl* CompassBearingCtrl;
wxTextCtrl* VariationCtrl;
wxTextCtrl* RemarksCtr;
void SetDateTime(wxDateTime dt);
wxDateTime GetDateTime();

Expand All @@ -79,12 +92,13 @@ class BearingDlg: public wxDialog
wxDateTime DT_value;
float LAT_value;
float LON_value;

wxString Remarks_value;
void SetPositionFix(PlugIn_Position_Fix_Ex &pfix);
void SetNMEATimeFix(wxDateTime dt);
void SetNMEAHeading(double hd);
void SetSunBearing(wxDateTime t);
void SetMessageVariation(wxString &message_id, wxString &message_body);
void SetMessageRouteActiveLeg(wxString &message_id, wxString &message_body);

protected:
//(*Identifiers(BearingDlg)
Expand All @@ -106,12 +120,13 @@ class BearingDlg: public wxDialog
static const long ID_STATICTEXT10;
static const long ID_STATICTEXT11;
static const long ID_VARCTRL;
static const long ID_REMARKSCTRL;

//*)

private:
void OnClose(wxCloseEvent& event);
void ChoiseSelect(wxCommandEvent& event);
void OnChoiseSelect(wxCommandEvent& event);
void OnTimeSelect(wxCommandEvent& event);
void OnTextCtrlEnter(wxCommandEvent& event);
//void OnChoiceCtrlEnter(wxCommandEvent& event);
Expand Down
Loading

0 comments on commit 41b2c79

Please sign in to comment.