double PlotDialog::GetValue(PlotData &data, int var)
{
    switch(var) {
    case BOAT_VELOCITY_GROUND:         return data.VBG;
    case BOAT_COURSE_GROUND:           return data.BG;
    case BOAT_VELOCITY_WATER:          return data.VB;
    case BOAT_COURSE_WATER:            return data.B;
    case WIND_VELOCITY:                return data.VW;
    case WIND_DIRECTION:               return heading_resolve(data.B - data.W);
    case WIND_COURSE:                  return data.W;
    case WIND_VELOCITY_GROUND:         return data.VWG;
    case WIND_DIRECTION_GROUND:        return heading_resolve(data.BG - data.WG);
    case WIND_COURSE_GROUND:           return data.WG;
    case APPARENT_WIND_VELOCITY:
        return BoatPlan::VelocityApparentWind(data.VB, deg2rad(GetValue(data, WIND_DIRECTION)), data.VW);
    case APPARENT_WIND_DIRECTION: {
        return rad2deg(BoatPlan::DirectionApparentWind
                       (GetValue(data, APPARENT_WIND_VELOCITY), data.VB,
                        deg2rad(GetValue(data, WIND_DIRECTION)), data.VW));
    }
    case CURRENT_VELOCITY: return data.VC;
    case CURRENT_DIRECTION: return data.C;
    case SIG_WAVE_HEIGHT: return data.WVHT;
    }
    return NAN;
}
void RouteMapOverlay::DrawLine(Position *p1, wxColour &color1, Position *p2, wxColour &color2,
                               wrDC &dc, PlugIn_ViewPort &vp)
{
#if 0
    double p1plon, p2plon;
    if(fabs(vp.clon) > 90)
        p1plon = positive_degrees(p1->lon), p2plon = positive_degrees(p2->lon);
    else
        p1plon = heading_resolve(p1->lon), p2plon = heading_resolve(p2->lon);

    if((p1plon+180 < vp.clon && p2plon+180 > vp.clon) ||
       (p1plon+180 > vp.clon && p2plon+180 < vp.clon) ||
       (p1plon-180 < vp.clon && p2plon-180 > vp.clon) ||
       (p1plon-180 > vp.clon && p2plon-180 < vp.clon))
        return;
#endif

    wxPoint p1p, p2p;
    GetCanvasPixLL(&vp, &p1p, p1->lat, p1->lon);
    GetCanvasPixLL(&vp, &p2p, p2->lat, p2->lon);

    SetColor(dc, color1);
    if(dc.GetDC())
        dc.DrawLine(p1p.x, p1p.y, p2p.x, p2p.y);
    else {
        glVertex2d(p1p.x, p1p.y);
        SetColor(dc, color2);
        glVertex2d(p2p.x, p2p.y);
    }
}
Пример #3
0
int BoatPlan::TrySwitchBoatPlan(double VW, double H, double Swell,
                                     const wxDateTime &gribtime, double lat, double lon, int &daytime)

{
    H = abs(heading_resolve(H)); /* make this work for both tacks */

    for(unsigned int i=0; i<SwitchPlans.size(); i++) {
        SwitchPlan &p = SwitchPlans[i];
        if(p.MaxWindSpeed >= VW)     continue;
        if(p.MinWindSpeed <= VW)     continue;
        if(p.MaxWindDirection >= H)  continue;
        if(p.MinWindDirection <= H)  continue;
        if(p.MaxWaveHeight >= Swell) continue;
        if(p.MinWaveHeight <= Swell) continue;
        if(!p.DayTime) {
            if(ComputeDayTime(gribtime, lat, lon, daytime)) continue;
        } else if(!p.NightTime)
            if(!ComputeDayTime(gribtime, lat, lon, daytime)) continue;
        return i;
    }
    return -1;
}
Пример #4
0
void BoatDialog::OnMouseEventsPolarPlot( wxMouseEvent& event )
{
#if 0
    if(event.Leaving()) {
        m_stTrueWindAngle->SetLabel(_("N/A"));
        m_stTrueWindKnots->SetLabel(_("N/A"));
        m_stApparentWindAngle->SetLabel(_("N/A"));
        m_stApparentWindKnots->SetLabel(_("N/A"));
        m_stBoatAngle->SetLabel(_("N/A"));
        m_stBoatKnots->SetLabel(_("N/A"));
        return;
    }

    wxPoint p = event.GetPosition();
    int w, h;
    m_PlotWindow->GetSize( &w, &h);

    /* range + to - */
    double W, VW, B, VB, A, VA;
    double windspeed;

    switch(m_lPlotType->GetSelection()) {
    case 0:
        if(m_cPlotType->GetSelection() == 0) { // polar
            if(!m_PlotScale)
                return;
            
            double x = (double)p.x - w/2;
            double y = (double)p.y - h/2;
            
            /* range +- */
            x /= m_PlotScale;
            y /= m_PlotScale;
            
            B = rad2posdeg(atan2(x, -y));
        } else
            B = (double)p.x/w*360;
        
        windspeed = m_sWindSpeed->GetValue();
        break;
    case 1:
    {
        B = m_sWindDirection->GetValue();
        double i = (double)p.x/w*num_wind_speeds;
        int i0 = floor(i), i1 = ceil(i);
        double d = i - i0;
        windspeed = (1-d)*wind_speeds[i0] + d*wind_speeds[i1];
    } break;
    }

    switch(m_cPlotVariable->GetSelection()) {
    case 0: // true wind
        W = B;
        VW = windspeed;
        VB = m_Boat.Plans[m_SelectedSailPlan].Speed(W, VW);

        VA = BoatPlan::VelocityApparentWind(VB, W, VW);
        A = rad2posdeg(BoatPlan::DirectionApparentWind(VA, VB, W, VW));
        break;
    case 1:
        A = heading_resolve(B);
        VW = windspeed;
        VB = m_Boat.Plans[m_SelectedSailPlan].SpeedAtApparentWindDirection(A, VW, &W);
        W = positive_degrees(W);

        VA = BoatPlan::VelocityApparentWind(VB, W, VW);
        break;
    case 2:
        W = B;
        VA = windspeed;
        VB = m_Boat.Plans[m_SelectedSailPlan].SpeedAtApparentWindSpeed(W, VA);
        VW = BoatPlan::VelocityTrueWind(VA, VB, W);
        A = rad2posdeg(BoatPlan::DirectionApparentWind(VA, VB, W, VW));
        break;
    case 3:
        A = heading_resolve(B);
        VA = windspeed;
        VB = m_Boat.Plans[m_SelectedSailPlan].SpeedAtApparentWind(A, VA, &W);
        W = positive_degrees(W);
        VW = BoatPlan::VelocityTrueWind(VA, VB, W);
    }

    m_stBoatAngle->SetLabel(wxString::Format(_T("%03.0f"), B));
    m_stBoatKnots->SetLabel(wxString::Format(_T("%.1f"), VB));

    int newmousew = round(B);
    if(newmousew != m_MouseW) {
        m_MouseW = newmousew;
        RefreshPlots();
    }
    
    m_stTrueWindAngle->SetLabel(wxString::Format(_T("%03.0f"), W));
    m_stTrueWindKnots->SetLabel(wxString::Format(_T("%.1f"), VW));

    m_stApparentWindAngle->SetLabel(wxString::Format(_T("%03.0f"), A));

    m_stApparentWindKnots->SetLabel(wxString::Format(_T("%.1f"), VA));
#endif
}