Skip to content

Commit

Permalink
support sparse polars with automatic interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
seandepagnier committed Mar 26, 2018
1 parent 939501f commit 4715200
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 91 deletions.
6 changes: 3 additions & 3 deletions VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET(PLUGIN_VERSION_MAJOR "1")
SET(PLUGIN_VERSION_MINOR "11")
SET(PLUGIN_VERSION_PATCH "2")
SET(PLUGIN_VERSION_DATE "2018-03-13")
SET(PLUGIN_VERSION_MINOR "12")
SET(PLUGIN_VERSION_PATCH "0")
SET(PLUGIN_VERSION_DATE "2018-03-25")
97 changes: 90 additions & 7 deletions WeatherRouting.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -25032,7 +25032,7 @@
</object>
</object>
</object>
<object class="Dialog" expanded="0">
<object class="Dialog" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
Expand Down Expand Up @@ -25094,7 +25094,7 @@
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxFlexGridSizer" expanded="0">
<object class="wxFlexGridSizer" expanded="1">
<property name="cols">1</property>
<property name="flexible_direction">wxBOTH</property>
<property name="growablecols"></property>
Expand All @@ -25106,11 +25106,11 @@
<property name="permission">none</property>
<property name="rows">0</property>
<property name="vgap">0</property>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">1</property>
<object class="wxNotebook" expanded="0">
<object class="wxNotebook" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
Expand Down Expand Up @@ -25188,11 +25188,11 @@
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="notebookpage" expanded="0">
<object class="notebookpage" expanded="1">
<property name="bitmap"></property>
<property name="label">Grid</property>
<property name="select">1</property>
<object class="wxPanel" expanded="0">
<object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
Expand Down Expand Up @@ -25266,7 +25266,7 @@
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxFlexGridSizer" expanded="0">
<object class="wxFlexGridSizer" expanded="1">
<property name="cols">1</property>
<property name="flexible_direction">wxBOTH</property>
<property name="growablecols">0</property>
Expand Down Expand Up @@ -25421,6 +25421,89 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Leave any cell blank to automatically interpolate from nearby values. Use a value of 0.0 to specify invalid (cannot be used)&#x0A; View the polar plot in the boat dialog while editing the polar.</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticText1351</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
</object>
Expand Down
26 changes: 19 additions & 7 deletions src/BoatDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ void BoatDialog::OnPaintPlot(wxPaintEvent& event)
break;
}

if(isnan(VB)) {
lastvalid = false;
continue;
}

double a;

switch(selection) {
Expand Down Expand Up @@ -389,6 +394,11 @@ void BoatDialog::OnPaintPlot(wxPaintEvent& event)
break;
}

if(isnan(VB)) {
lastvalid = false;
continue;
}

#if 0
double a;

Expand Down Expand Up @@ -514,9 +524,8 @@ void BoatDialog::OnPaintCrossOverChart(wxPaintEvent& event)
bool full = m_cbFullPlot->GetValue();
double scale;
int xc = full ? w / 2 : 0;
if(polar) {
if(polar)
scale = wxMin(full ? w/2 : w, h/2) / 40.0;
}

for(double VW = 0; VW < 40; VW += 10) {
if(polar) {
Expand Down Expand Up @@ -861,6 +870,7 @@ void BoatDialog::OnAddPolar( wxCommandEvent& event )
for(unsigned int i=0; i<paths.GetCount(); i++) {
wxString filename = paths[i], message;
Polar polar;
bool success;

for(unsigned int j=0; j<m_Boat.Polars.size(); j++)
if(m_Boat.Polars[j].FileName == filename)
Expand All @@ -875,15 +885,17 @@ void BoatDialog::OnAddPolar( wxCommandEvent& event )
file.Write(dummy_polar);
}

if(polar.Open(filename, message)) {
success = polar.Open(filename, message);
if(success) {
m_Boat.Polars.push_back(polar);
RepopulatePolars();
m_lPolars->SetItemState(m_Boat.Polars.size()-1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
generate = true;
} else {
wxMessageDialog md(this, message,
_("OpenCPN Weather Routing Plugin"),
wxICON_ERROR | wxOK );
}

if(!message.IsEmpty()) {
wxMessageDialog md(this, message, _("OpenCPN Weather Routing Plugin"),
success ? wxICON_WARNING : wxICON_ERROR | wxOK );
md.ShowModal();
}
skip:;
Expand Down
17 changes: 12 additions & 5 deletions src/EditPolarDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ void EditPolarDialog::SetPolarIndex(int i)

void EditPolarDialog::OnPolarGridChanged( wxGridEvent& event )
{
wxString str = m_gPolar->GetCellValue(event.GetRow(), event.GetCol());
if(str == "0")
str = "";
double VB;
m_gPolar->GetCellValue(event.GetRow(), event.GetCol()).ToDouble(&VB);
GetPolar()->wind_speeds[event.GetCol()].speeds[event.GetRow()] = VB;
if(!str.ToDouble(&VB))
VB = NAN;
GetPolar()->wind_speeds[event.GetCol()].orig_speeds[event.GetRow()] = VB;
GetPolar()->UpdateSpeeds();
m_BoatDialog->Refresh();
}

Expand Down Expand Up @@ -205,9 +210,11 @@ void EditPolarDialog::RebuildGrid()
m_gPolar->SetColLabelValue
( i, wxString::Format(_T("%4.1f"), GetPolar()->wind_speeds[i].VW));

for(unsigned int j = 0; j<GetPolar()->degree_steps.size(); j++)
m_gPolar->SetCellValue
(j, i, wxString::Format(_T("%4.1f"), GetPolar()->wind_speeds[i].speeds[j]));
for(unsigned int j = 0; j<GetPolar()->degree_steps.size(); j++) {
double v = GetPolar()->wind_speeds[i].orig_speeds[j];
wxString str = isnan(v) ? "" : v==0 ? "0.0" : wxString::Format(_T("%4.1f"), v);
m_gPolar->SetCellValue(j, i, str);
}
}

m_BoatDialog->Refresh();
Expand Down
Loading

0 comments on commit 4715200

Please sign in to comment.