Skip to content

Commit

Permalink
Merge pull request seandepagnier#209 from theeko74/comfort-status
Browse files Browse the repository at this point in the history
ADD comfort status in the WeatherRouting panel and ReportDialog
  • Loading branch information
seandepagnier authored Jun 14, 2018
2 parents 2329e41 + 079cc93 commit 2ed513e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
29 changes: 27 additions & 2 deletions src/ReportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ void ReportDialog::SetRouteMapOverlays(std::list<RouteMapOverlay*> routemapoverl
(_T("%d/%d"), (int)port_starboard, 100-(int)port_starboard)) + _T("<dt>");

if (d) {
page += _("Number of tacks") + wxString::Format(_T(": %d "), d->tacks) + _T("<dt>\n");
page += _("Number of tacks") + wxString::Format(_T(": %d "), d->tacks) + _T("<dt>");
}

// CUSTOMIZATION
// Display sailing comfort in the report
page += ("Sailing comfort") + wxString(_T(": ")) \
+ (*it)->sailingConditionText((*it)->RouteInfo(RouteMapOverlay::COMFORT)) \
+ _T("<dt>\n");

/* determine if currents significantly improve this (boat over ground speed average is 10% or
more faster than boat over water) then attempt to determine which current based on lat/lon
Expand Down Expand Up @@ -258,7 +264,26 @@ void ReportDialog::GenerateRoutesReport()
page += s.Format(_T("%d %B ")) + _("to") + e.Format(_T(" %d %B"));
}
}


// CUSTOMIZATION
// Display the best option to travel in order
// to get the most comfortable sailing
page += _T("<dt>");
page += _("Best Sailing Comfort") + wxString(_T(": "));
wxDateTime best_comfort_date;
int best_sailing_comfort = 6;
for(std::multimap< wxDateTime, RouteMapOverlay * >::iterator it3 = sort_by_start.begin(); it3 != sort_by_start.end(); it3++) {
RouteMapOverlay *r = it3->second;
if (best_comfort_date < r->StartTime() && best_sailing_comfort > r->RouteInfo(RouteMapOverlay::COMFORT))
{
best_comfort_date = r->StartTime();
best_sailing_comfort = r->RouteInfo(RouteMapOverlay::COMFORT);
}
}
page += RouteMapOverlay::sailingConditionText(best_sailing_comfort);
page += _T(" on ");
page += best_comfort_date.Format(_T("%x %X")) + _T(" UTC");

page += _T("<dt>");
page += _("Cyclones") + wxString(_T(": "));

Expand Down
25 changes: 23 additions & 2 deletions src/RouteMapOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ int RouteMapOverlay::sailingConditionLevel(const PlotData &plot) const
if (level_calc <= 0.5)
// Light conditions, enjoy ;-)
return 1;
if (level_calc > 0.5 && level_calc < 1)
if (level_calc > 0.5 && level_calc < 1)
// Can be tough
return 2;
if (level_calc >= 1)
Expand All @@ -568,7 +568,7 @@ int RouteMapOverlay::sailingConditionLevel(const PlotData &plot) const
return 0;
}

static wxColour sailingConditionColor(int level)
wxColour RouteMapOverlay::sailingConditionColor(int level)
{
switch (level) {
case 1:
Expand All @@ -581,6 +581,17 @@ static wxColour sailingConditionColor(int level)
return *wxBLACK;
}

wxString RouteMapOverlay::sailingConditionText(int level)
{
if (level == 1)
return _T("Good");
if (level == 2)
return _T("Bumpy");
if (level == 3)
return _T("Difficult");
return _T("N/A");
}

// -----------------------------------------------------


Expand Down Expand Up @@ -1261,6 +1272,7 @@ double RouteMapOverlay::RouteInfo(enum RouteInfoType type, bool cursor_route)
std::list<PlotData> &plotdata = GetPlotData(cursor_route);

double total = 0, count = 0, lat0 = 0, lon0 = 0;
int comfort = 0, current_comfort = 0;
for(std::list<PlotData>::iterator it=plotdata.begin(); it!=plotdata.end(); it++)
{
switch(type) {
Expand Down Expand Up @@ -1319,6 +1331,13 @@ double RouteMapOverlay::RouteInfo(enum RouteInfoType type, bool cursor_route)
if(heading_resolve(it->B - it->W) > 0)
total++;
break;
// CUSTOMIZATION
// Comfort on route
case COMFORT:
current_comfort = sailingConditionLevel(*it);
if (current_comfort > comfort)
comfort = current_comfort;
break;
default:
break;
}
Expand All @@ -1337,6 +1356,8 @@ double RouteMapOverlay::RouteInfo(enum RouteInfoType type, bool cursor_route)
total += DistGreatCircle_Plugin(lat0, lon0, configuration.EndLat, configuration.EndLon);
}
return total;
case COMFORT:
return comfort;
case PERCENTAGE_UPWIND:
case PORT_STARBOARD:
total *= 100.0;
Expand Down
7 changes: 6 additions & 1 deletion src/RouteMapOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RouteMapOverlay : public RouteMap
public:
enum RouteInfoType {DISTANCE, AVGSPEED, MAXSPEED, AVGSPEEDGROUND, MAXSPEEDGROUND,
AVGWIND, MAXWIND, MAXWINDGUST, AVGCURRENT, MAXCURRENT, AVGSWELL, MAXSWELL,
PERCENTAGE_UPWIND, PORT_STARBOARD, TACKS};
PERCENTAGE_UPWIND, PORT_STARBOARD, TACKS, COMFORT};

RouteMapOverlay();
~RouteMapOverlay();
Expand All @@ -65,6 +65,8 @@ class RouteMapOverlay : public RouteMap
// Customization ComfortDisplay
void RenderCourse(bool cursor_route, wrDC &dc, PlugIn_ViewPort &vp, bool comfortRoute = false);
int sailingConditionLevel(const PlotData &plot) const;
static wxColour sailingConditionColor(int level);
static wxString sailingConditionText(int level);

// Customization WindBarbsOnRoute
void RenderWindBarbsOnRoute(wrDC &dc, PlugIn_ViewPort &vp);
Expand Down Expand Up @@ -133,6 +135,9 @@ class RouteMapOverlay : public RouteMap

// Customization WindBarbsOnRoute
LineBuffer wind_barb_route_cache;

// Customization Sailing Comfort
int m_sailingComfort;

LineBuffer current_cache;
double current_cache_scale;
Expand Down
5 changes: 3 additions & 2 deletions src/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ const wxString SettingsDialog::column_names[] = {"", "Boat", "Start", "Start Tim
"Avg Wind", "Max Wind", "Max Wind Gust",
"Avg Current", "Max Current",
"Avg Swell", "Max Swell",
"Upwind Percentage",
"Port Starboard", "Tacks", "State"};
"Upwind Percentage", "Port Starboard",
"Tacks", "Sailing Comfort",
"State"};

SettingsDialog::SettingsDialog( wxWindow *parent )
#ifndef __WXOSX__
Expand Down
15 changes: 13 additions & 2 deletions src/WeatherRouting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const wxString WeatherRouting::column_names[NUM_COLS] = {"Visible", "Boat", "Sta
"Avg Current", "Max Current",
"Avg Swell", "Max Swell",
"Upwind Percentage",
"Port Starboard", "Tacks", "State"};
"Port Starboard", "Tacks", "Comfort",
"State"};

static int sortcol, sortorder = 1;
// sort callback. Sort by body.
Expand Down Expand Up @@ -1739,6 +1740,11 @@ void WeatherRoute::Update(WeatherRouting *wr, bool stateonly)
PortStarboard = wxString::Format(_T("%.0f/%.0f"), ps, 100-ps);

Tacks = wxString::Format(_T("%.0f"), routemapoverlay->RouteInfo(RouteMapOverlay::TACKS));

// CUSTOMIZATION
// Display sailing comfort
int comfort_level = routemapoverlay->RouteInfo(RouteMapOverlay::COMFORT);
Comfort = RouteMapOverlay::sailingConditionText(comfort_level);
}

if(!routemapoverlay->Valid())
Expand Down Expand Up @@ -1899,11 +1905,16 @@ void WeatherRouting::UpdateItem(long index, bool stateonly)
m_panel->m_lWeatherRoutes->SetItem(index, columns[PORT_STARBOARD], weatherroute->PortStarboard);
m_panel->m_lWeatherRoutes->SetColumnWidth(columns[PORT_STARBOARD], wxLIST_AUTOSIZE);
}

if(columns[TACKS] >= 0) {
m_panel->m_lWeatherRoutes->SetItem(index, columns[TACKS], weatherroute->Tacks);
m_panel->m_lWeatherRoutes->SetColumnWidth(columns[TACKS], wxLIST_AUTOSIZE);
}

if(columns[COMFORT] >= 0) {
m_panel->m_lWeatherRoutes->SetItem(index, columns[COMFORT], weatherroute->Comfort);
m_panel->m_lWeatherRoutes->SetColumnWidth(columns[COMFORT], wxLIST_AUTOSIZE);
}
}

if(columns[STATE] >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/WeatherRouting.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class WeatherRoute
AvgSpeed, MaxSpeed, AvgSpeedGround, MaxSpeedGround,
AvgWind, MaxWind, MaxWindGust,
AvgCurrent, MaxCurrent, AvgSwell, MaxSwell, UpwindPercentage, PortStarboard,
Tacks, State;
Tacks, State, Comfort;
RouteMapOverlay *routemapoverlay;
};

Expand All @@ -74,7 +74,7 @@ class WeatherRouting : public WeatherRoutingBase
enum {VISIBLE=0, BOAT, START, STARTTIME, END, ENDTIME, TIME, DISTANCE,
AVGSPEED, MAXSPEED, AVGSPEEDGROUND, MAXSPEEDGROUND,
AVGWIND, MAXWIND, MAXWINDGUST, AVGCURRENT, MAXCURRENT, AVGSWELL, MAXSWELL,
UPWIND_PERCENTAGE, PORT_STARBOARD, TACKS, STATE, NUM_COLS};
UPWIND_PERCENTAGE, PORT_STARBOARD, TACKS, COMFORT, STATE, NUM_COLS};
long columns[NUM_COLS];
static const wxString column_names[NUM_COLS];
int sashpos;
Expand Down

0 comments on commit 2ed513e

Please sign in to comment.