From 20f0ddfd306f5c45888c75b78cd16f79fb2f56bd Mon Sep 17 00:00:00 2001 From: didier Date: Wed, 13 Jun 2018 23:22:13 +0200 Subject: [PATCH 1/3] FIX wind bars on route always visible even if visible is not set --- src/RouteMapOverlay.cpp | 4 ++++ src/WeatherRouting.cpp | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/RouteMapOverlay.cpp b/src/RouteMapOverlay.cpp index 560b8613..5b0a1ce5 100644 --- a/src/RouteMapOverlay.cpp +++ b/src/RouteMapOverlay.cpp @@ -452,6 +452,10 @@ void RouteMapOverlay::Render(wxDateTime time, SettingsDialog &settingsdialog, SetColor(dc, Darken(DestinationColor), true); SetWidth(dc, RouteThickness/2, true); RenderBoatOnCourse(false, time, dc, vp); + + // Start WindBarbsOnRoute customization + if (settingsdialog.m_cbDisplayWindBarbsOnRoute->GetValue()) + RenderWindBarbsOnRoute(dc, vp); if(MarkAtPolarChange) { SetColor(dc, Darken(DestinationColor), true); diff --git a/src/WeatherRouting.cpp b/src/WeatherRouting.cpp index e7165f91..fc08079a 100644 --- a/src/WeatherRouting.cpp +++ b/src/WeatherRouting.cpp @@ -377,10 +377,6 @@ void WeatherRouting::Render(wrDC &dc, PlugIn_ViewPort &vp) if(weatherroute->routemapoverlay->m_bEndRouteVisible) { weatherroute->routemapoverlay->Render(time, m_SettingsDialog, dc, vp, true); - - // Start WindBarbsOnRoute customization - if (m_SettingsDialog.m_cbDisplayWindBarbsOnRoute->GetValue()) - weatherroute->routemapoverlay->RenderWindBarbsOnRoute(dc, vp); } } @@ -389,11 +385,6 @@ void WeatherRouting::Render(wrDC &dc, PlugIn_ViewPort &vp) it != currentroutemaps.end(); it++) { (*it)->Render(time, m_SettingsDialog, dc, vp, false); - // Wind barbs on route - if (it == currentroutemaps.begin() && - m_SettingsDialog.m_cbDisplayWindBarbsOnRoute->GetValue()) - (*it)->RenderWindBarbsOnRoute(dc, vp); - if(it == currentroutemaps.begin() && m_SettingsDialog.m_cbDisplayWindBarbs->GetValue()) (*it)->RenderWindBarbs(dc, vp); From 1998a45c2c2e076d538211f6baac1731de9d595c Mon Sep 17 00:00:00 2001 From: didier Date: Wed, 13 Jun 2018 23:33:58 +0200 Subject: [PATCH 2/3] make more methods private --- src/RouteMapOverlay.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/RouteMapOverlay.h b/src/RouteMapOverlay.h index ddeb956e..7434b966 100644 --- a/src/RouteMapOverlay.h +++ b/src/RouteMapOverlay.h @@ -54,22 +54,12 @@ class RouteMapOverlay : public RouteMap ~RouteMapOverlay(); bool SetCursorLatLon(double lat, double lon); - void RenderIsoRoute(IsoRoute *r, wxColour &grib_color, wxColour &climatology_color, - wrDC &dc, PlugIn_ViewPort &vp); void Render(wxDateTime time, SettingsDialog &settingsdialog, wrDC &dc, PlugIn_ViewPort &vp, bool justendroute); - void RenderPolarChangeMarks(bool cursor_route, wrDC &dc, PlugIn_ViewPort &vp); - void RenderBoatOnCourse(bool cursor_route, wxDateTime time, wrDC &dc, PlugIn_ViewPort &vp); - - // 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); + void RenderWindBarbs(wrDC &dc, PlugIn_ViewPort &vp); void RenderCurrent(wrDC &dc, PlugIn_ViewPort &vp); @@ -105,6 +95,19 @@ class RouteMapOverlay : public RouteMap private: void RenderAlternateRoute(IsoRoute *r, bool each_parent, wrDC &dc, PlugIn_ViewPort &vp); + + void RenderIsoRoute(IsoRoute *r, wxColour &grib_color, wxColour &climatology_color, + wrDC &dc, PlugIn_ViewPort &vp); + void RenderPolarChangeMarks(bool cursor_route, wrDC &dc, PlugIn_ViewPort &vp); + void RenderBoatOnCourse(bool cursor_route, wxDateTime time, wrDC &dc, PlugIn_ViewPort &vp); + + // Customization ComfortDisplay + void RenderCourse(bool cursor_route, wrDC &dc, PlugIn_ViewPort &vp, bool comfortRoute = false); + + // Customization WindBarbsOnRoute + void RenderWindBarbsOnRoute(wrDC &dc, PlugIn_ViewPort &vp); + int sailingConditionLevel(const PlotData &plot) const; + virtual bool TestAbort() { return Finished(); } RouteMapOverlayThread *m_Thread; From fbb4dea92303355d21b471b6b079a382cc622a5a Mon Sep 17 00:00:00 2001 From: didier Date: Thu, 21 Jun 2018 09:08:22 +0200 Subject: [PATCH 3/3] cleanup RenderWindBarbsOnRoute move offseting in pushTransformedBuffer which knows arrow size and do it with the proper rotation. There's no cache so use the current viewport and don't re-rotate, it's done with the viewport. --- src/LineBufferOverlay.cpp | 21 ++++++++++++++------ src/LineBufferOverlay.h | 4 ++-- src/RouteMapOverlay.cpp | 40 +++++++-------------------------------- 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/src/LineBufferOverlay.cpp b/src/LineBufferOverlay.cpp index ade50a16..a26e9c51 100644 --- a/src/LineBufferOverlay.cpp +++ b/src/LineBufferOverlay.cpp @@ -49,7 +49,7 @@ void LineBuffer::Finalize() buffer.clear(); } -void LineBuffer::pushTransformedBuffer(LineBuffer &buffer, int x, int y, double ang, bool south) +void LineBuffer::pushTransformedBuffer(LineBuffer &buffer, int x, int y, double ang, bool south, bool head) { // transform vertexes by angle float sa = sinf( ang ), ca = cosf( ang ); @@ -57,12 +57,21 @@ void LineBuffer::pushTransformedBuffer(LineBuffer &buffer, int x, int y, double float m[2][2] = {{ ca, -sa}, { sa, ca}}; - if(south) - m[0][0] = -m[0][0], m[1][0] = -m[1][0]; + if(south) { + m[0][0] = -m[0][0]; + m[1][0] = -m[1][0]; + } + if(head) { + // Calculate the offset to put the head + // of the arrow on the point (and not the + // middle of the arrow). + x += (int)(0.5 * 35 * sa); + y -= (int)(0.5 * 35 * ca); + } for(int i=0; i < 2*buffer.count; i+=2) { float *k = buffer.lines + 2*i; - pushLine(k[0]*m[0][0] + k[1]*m[0][1] + x, k[0]*m[1][0] + k[1]*m[1][1] + y, + pushLine(k[0]*m[0][0] + k[1]*m[0][1] + x , k[0]*m[1][0] + k[1]*m[1][1] + y, k[2]*m[0][0] + k[3]*m[0][1] + x, k[2]*m[1][0] + k[3]*m[1][1] + y); } } @@ -203,7 +212,7 @@ LineBufferOverlay::LineBufferOverlay() } -void LineBufferOverlay::pushWindArrowWithBarbs(LineBuffer &buffer, int x, int y, double vkn, double ang, bool south) +void LineBufferOverlay::pushWindArrowWithBarbs(LineBuffer &buffer, int x, int y, double vkn, double ang, bool south, bool head) { int cacheidx; @@ -219,7 +228,7 @@ void LineBufferOverlay::pushWindArrowWithBarbs(LineBuffer &buffer, int x, int y, cacheidx = 13; else return; - buffer.pushTransformedBuffer(m_WindArrowCache[cacheidx], x, y, ang, south); + buffer.pushTransformedBuffer(m_WindArrowCache[cacheidx], x, y, ang, south, head); } void LineBufferOverlay::pushSingleArrow( LineBuffer &buffer, int x, int y, double vkn, double ang, bool south) diff --git a/src/LineBufferOverlay.h b/src/LineBufferOverlay.h index d4ea6fbf..21da95a5 100644 --- a/src/LineBufferOverlay.h +++ b/src/LineBufferOverlay.h @@ -35,7 +35,7 @@ class LineBuffer { void pushLine( float x0, float y0, float x1, float y1 ); void Finalize(); - void pushTransformedBuffer(LineBuffer &buffer, int x, int y, double ang, bool south=false); + void pushTransformedBuffer(LineBuffer &buffer, int x, int y, double ang, bool south=false, bool head=false); void draw(wxDC *dc); void drawTransformed(wxDC *dc, wxPoint offset, double ang); @@ -58,7 +58,7 @@ class LineBufferOverlay { public: LineBufferOverlay(); - void pushWindArrowWithBarbs(LineBuffer &buffer, int x, int y, double vkn, double ang, bool south=false); + void pushWindArrowWithBarbs(LineBuffer &buffer, int x, int y, double vkn, double ang, bool south=false, bool head=false); void pushSingleArrow( LineBuffer &buffer, int x, int y, double vkn, double ang, bool south=false); private: diff --git a/src/RouteMapOverlay.cpp b/src/RouteMapOverlay.cpp index 560b8613..fbb057f2 100644 --- a/src/RouteMapOverlay.cpp +++ b/src/RouteMapOverlay.cpp @@ -694,19 +694,14 @@ void RouteMapOverlay::RenderWindBarbsOnRoute(wrDC &dc, PlugIn_ViewPort &vp) * OpenCPN's licence * March, 2018 */ - + if (vp.bValid == false) + return; + RouteMapConfiguration configuration = GetConfiguration(); - - + // Create a specific viewport at position (0,0) // to draw the winds barbs, and then translate it PlugIn_ViewPort nvp = vp; - nvp.clat = configuration.StartLat, nvp.clon = configuration.StartLon; - nvp.pix_width = 0; - nvp.pix_height = 0; - nvp.rotation = 0; - nvp.skew = 0; - // calculate wind barbs along the route by looping // over [GetPlotData(false)] list which contains lat, // lon, wind info for each points, only if needed. @@ -725,17 +720,10 @@ void RouteMapOverlay::RenderWindBarbsOnRoute(wrDC &dc, PlugIn_ViewPort &vp) double VW = it->VW; double W = it->W; - // Calculate the offset to put the head - // of the arrow on the route (and not the - // middle of the arrow) for readability. - int xOffset, yOffset; - xOffset = (int)(0.5 * 35 * sin(deg2rad(W))); - yOffset = (int)(0.5 * 35 * cos(deg2rad(W))); - // Draw barbs g_barbsOnRoute_LineBufferOverlay.pushWindArrowWithBarbs( - wind_barb_route_cache, p.x + xOffset, p.y - yOffset, VW, - deg2rad(W) + nvp.rotation, it->lat < 0 + wind_barb_route_cache, p.x, p.y, VW, + deg2rad(W) + nvp.rotation, it->lat < 0, true ); } wind_barb_route_cache.Finalize(); @@ -753,12 +741,6 @@ void RouteMapOverlay::RenderWindBarbsOnRoute(wrDC &dc, PlugIn_ViewPort &vp) #ifdef ocpnUSE_GL else { - // Translate and rotate the matrix - // anyway, event if cached - glPushMatrix(); - glTranslated(point.x, point.y, 0); - glRotated(vp.rotation*180/M_PI, 0, 0, 1); - // Anti-aliasing options to render // wind barbs at best quality (copy from grip_pi) glEnable(GL_BLEND); @@ -772,15 +754,7 @@ void RouteMapOverlay::RenderWindBarbsOnRoute(wrDC &dc, PlugIn_ViewPort &vp) } #endif - if(dc.GetDC()) { - // Draw the wind barbs with a correction - // in all cases on position and rotation - LineBuffer tb; - tb.pushTransformedBuffer(wind_barb_route_cache, point.x, point.y, vp.rotation); - tb.Finalize(); - tb.draw(dc.GetDC()); - } else - wind_barb_route_cache.draw(NULL); + wind_barb_route_cache.draw(dc.GetDC()); #ifdef ocpnUSE_GL if(!dc.GetDC()) {