Skip to content

Commit

Permalink
Merge branch 'master' of github.com:seandepagnier/weather_routing_pi
Browse files Browse the repository at this point in the history
  • Loading branch information
seandepagnier committed Aug 27, 2018
2 parents a8fa7c4 + 4469501 commit 7ce1496
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 61 deletions.
21 changes: 15 additions & 6 deletions src/LineBufferOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,29 @@ 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 );

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);
}
}
Expand Down Expand Up @@ -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;

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/LineBufferOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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:

Expand Down
44 changes: 11 additions & 33 deletions src/RouteMapOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -694,19 +698,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.
Expand All @@ -725,17 +724,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();
Expand All @@ -753,12 +745,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);
Expand All @@ -772,15 +758,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()) {
Expand Down
25 changes: 14 additions & 11 deletions src/RouteMapOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions src/WeatherRouting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
Expand Down

0 comments on commit 7ce1496

Please sign in to comment.