wxString GribRequestSetting::WriteMail()
{
    //define size limits for zyGrib
    int limit = IsZYGRIB ? 2 : 0;                                            //new limit  2 mb

    m_MailError_Nb = 0;
    //some useful strings
    const wxString s[] = { _T(","), _T(" ") };        //separators
    const wxString p[][11] = {{ _T("APCP"), _T("TCDC"), _T("AIRTMP"), _T("HTSGW,WVPER,WVDIR"),      //parameters Saildocs
        _T("SEATMP"), _T("GUST"), _T("CAPE"), wxEmptyString, wxEmptyString, _T("WIND500,HGT500"), wxEmptyString},
        {_T("PRECIP"), _T("CLOUD"), _T("TEMP"), _T("WVSIG WVWIND"), wxEmptyString, _T("GUST"),      //parameters zigrib
            _T("CAPE"), _T("A850"), _T("A700"), _T("A500"), _T("A300")} };

    wxString r_topmess,r_parameters,r_zone;
    //write the top part of the mail
    switch( m_pMailTo->GetCurrentSelection() ) {
    case SAILDOCS:                                                                         //Saildocs
        r_zone = toMailFormat(1, m_spMaxLat->GetValue() ) + _T(",") + toMailFormat(1, m_spMinLat->GetValue() ) + _T(",")
            + toMailFormat(2, m_spMinLon->GetValue() ) + _T(",") + toMailFormat(2, m_spMaxLon->GetValue() );
        r_topmess = wxT("send ");
        r_topmess.Append(m_pModel->GetStringSelection() + _T(":"));
        r_topmess.Append( r_zone  + _T("|"));
        r_topmess.Append(m_pResolution->GetStringSelection()).Append(_T(","))
            .Append(m_pResolution->GetStringSelection()).Append(_T("|"));
        double v;
        m_pInterval->GetStringSelection().ToDouble(&v);
        r_topmess.Append(wxString::Format(_T("0,%d,%d"), (int) v, (int) v*2));
        m_pTimeRange->GetStringSelection().ToDouble(&v);
        r_topmess.Append(wxString::Format(_T("..%d"), (int) v*24) + _T("|=\n"));
        break;
	case ZYGRIB:                                                                         //Zygrib
		double maxlon = (m_spMinLon->GetValue() > m_spMaxLon->GetValue() && m_spMaxLon->GetValue() < 0)?
			m_spMaxLon->GetValue() + 360 : m_spMaxLon->GetValue();
		r_zone = toMailFormat(1, m_spMinLat->GetValue() ) + toMailFormat(2, m_spMinLon->GetValue() ) + _T(" ")
			+ toMailFormat(1, m_spMaxLat->GetValue() ) + toMailFormat(2, maxlon );
        r_topmess = wxT("login : "******"\n"));
        r_topmess.Append(wxT("code :"));
        r_topmess.Append(m_pCode->GetValue() + _T("\n"));
        r_topmess.Append(wxT("area : "));
        r_topmess.append(r_zone + _T("\n"));
        r_topmess.Append(wxT("resol : "));
        r_topmess.append(m_pResolution->GetStringSelection() + _T("\n"));
        r_topmess.Append(wxT("days : "));
        r_topmess.append(m_pTimeRange->GetStringSelection() + _T("\n"));
        r_topmess.Append(wxT("hours : "));
        r_topmess.append(m_pInterval->GetStringSelection() + _T("\n"));
        if(m_pWaves->IsChecked()) {
            r_topmess.Append(wxT("waves : "));
            r_topmess.append(m_pWModel->GetStringSelection() + _T("\n"));
        }
        r_topmess.Append(wxT("meteo : "));
        r_topmess.append(m_pModel->GetStringSelection() + _T("\n"));
        if ( m_pLogin->GetValue().IsEmpty() || m_pCode->GetValue().IsEmpty() ) m_MailError_Nb = 6;
        break;
    }
    //write the parameters part of the mail
    switch( m_pModel->GetCurrentSelection() ) {
    case GFS:                                                                           //GFS
        r_parameters = wxT("WIND") + s[m_pMailTo->GetCurrentSelection()] + wxT("PRESS");    // the default minimum request parameters
        if( m_pRainfall->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][0] );
        if( m_pCloudCover->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][1] );
        if( m_pAirTemp->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][2] );
        if( m_pWaves->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][3] );
        if( m_pSeaTemp->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][4] );
        if( m_pWindGust->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][5] );
        if( m_pCAPE->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][6] );
        if(m_pAltitudeData->IsChecked() ){
            if( m_p850hpa->IsChecked() )
                r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][7] );
            if( m_p700hpa->IsChecked() )
                r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][8] );
            if( m_p500hpa->IsChecked() )
                r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][9] );
            if( m_p300hpa->IsChecked() )
                r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][10] );
        }
        break;
    case COAMPS:                                                                           //COAMPS
        r_parameters = wxT("WIND,PRMSL");                                 //the default parameters for this model
        break;
    case RTOFS:                                                                           //RTOFS
        r_parameters = wxT("CUR,WTMP");                                   //the default parameters for this model
        break;
    }
    if( !IsZYGRIB && m_cMovingGribEnabled->IsChecked())            //moving grib
        r_parameters.Append(wxString::Format(_T("|%d,%d"),m_sMovingSpeed->GetValue(),m_sMovingCourse->GetValue()));

    // line lenth limitation
    int j = 0;
    char c =  m_pMailTo->GetCurrentSelection() == SAILDOCS ? ',' : ' ';
    for( size_t i = 0; i < r_parameters.Len(); i++ ) {
        if(r_parameters.GetChar( i ) == '|' ) j--;                        //do not split Saildocs "moving" values
        if(r_parameters.GetChar( i ) == c ) j++;
        if( j > 6 ) {                                                       //no more than 6 parameters on the same line
            r_parameters.insert( i + 1 , m_pMailTo->GetCurrentSelection() == SAILDOCS ? _T("=\n") : _T("\n"));
            break;
        }
    }

    double size;
    m_MailError_Nb += EstimateFileSize( &size );

    m_tFileSize->SetLabel(wxString::Format( _T("%1.2f " ) , size ) + _("MB") );

    if( IsZYGRIB ) {
        m_tLimit->SetLabel(wxString( _T("( ") ) + _("Max") + wxString::Format(_T(" %d "), limit) + _("MB") + _T(" )") );
        if(size > limit) m_MailError_Nb += 2;
    } else
        m_tLimit->SetLabel(wxEmptyString);

    return wxString( r_topmess + r_parameters );
}
Esempio n. 2
0
wxString GribRequestSetting::WriteMail()
{
    m_MailError_Nb = 0;
    //some useful strings
    const wxString s[] = { _T(","), _T(" ") };        //separators
    const wxString p[][11] = {{ _T("APCP"), _T("TCDC"), _T("AIRTMP"), _T("HTSGW,WVPER,WVDIR"),      //parameters Saildocs
        _T("SEATMP"), wxEmptyString, _T("CAPE"), wxEmptyString, wxEmptyString, _T("WIND500,HGT500"), wxEmptyString}, 
        {_T("PRECIP"), _T("CLOUD"), _T("TEMP"), _T("WVSIG WVWIND"), wxEmptyString, _T("GUST"),      //parameters zigrib
            _T("CAPE"), _T("A850"), _T("A700"), _T("A500"), _T("A300")} };

    wxString r_topmess,r_parameters,r_zone;
    //write the top part of the mail
    switch( m_pMailTo->GetCurrentSelection() ) {
    case SAILDOCS:                                                                         //Saildocs
        r_zone = toMailFormat(1, m_LatmaxBase) + _T(",") + toMailFormat(1, m_LatminBase) + _T(",")
            + toMailFormat(2, m_LonminBase) + _T(",") + toMailFormat(2, m_LonmaxBase);
        r_topmess = wxT("send ");
        r_topmess.Append(m_pModel->GetStringSelection() + _T(":"));
        r_topmess.Append( r_zone  + _T("|"));
        r_topmess.Append(m_pResolution->GetStringSelection()).Append(_T(","))
            .Append(m_pResolution->GetStringSelection()).Append(_T("|"));
        double v;
        m_pInterval->GetStringSelection().ToDouble(&v);
        r_topmess.Append(wxString::Format(_T("0,%d,%d"), (int) v, (int) v*2));
        m_pTimeRange->GetStringSelection().ToDouble(&v);
        r_topmess.Append(wxString::Format(_T("..%d"), (int) v*24) + _T("|=\n"));
        break;
    case ZYGRIB:                                                                         //Zygrib
        r_zone = toMailFormat(1, m_LatminBase) + toMailFormat(2, m_LonminBase) + _T(" ")
            + toMailFormat(1, m_LatmaxBase) + toMailFormat(2, m_LonmaxBase);
        r_topmess = wxT("login : "******"\n"));
        r_topmess.Append(wxT("code :"));
        r_topmess.Append(m_pCode->GetValue() + _T("\n"));
        r_topmess.Append(wxT("area : "));
        r_topmess.append(r_zone + _T("\n"));
        r_topmess.Append(wxT("resol : "));
        r_topmess.append(m_pResolution->GetStringSelection() + _T("\n"));
        r_topmess.Append(wxT("days : "));
        r_topmess.append(m_pTimeRange->GetStringSelection() + _T("\n"));
        r_topmess.Append(wxT("hours : "));
        r_topmess.append(m_pInterval->GetStringSelection() + _T("\n"));
        if(m_pWaves->IsChecked()) {
            r_topmess.Append(wxT("waves : "));
            r_topmess.append(m_pWModel->GetStringSelection() + _T("\n"));
        }
        r_topmess.Append(wxT("meteo : "));
        r_topmess.append(m_pModel->GetStringSelection() + _T("\n"));
        if ( m_pLogin->GetValue().IsEmpty() || m_pCode->GetValue().IsEmpty() ) m_MailError_Nb =1;
        break;
    }
    //write the parameters part of the mail
    switch( m_pModel->GetCurrentSelection() ) {
    case GFS:                                                                           //GFS
        r_parameters = wxT("WIND") + s[m_pMailTo->GetCurrentSelection()] + wxT("PRESS");    // the default minimum request parameters
        if( m_pRainfall->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][0] );
        if( m_pCloudCover->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][1] );
        if( m_pAirTemp->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][2] );
        if( m_pWaves->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][3] );
        if( m_pSeaTemp->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][4] );
        if( m_pWindGust->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][5] );
        if( m_pCAPE->IsChecked() )
            r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][6] );
        if(m_pAltitudeData->IsChecked() ){
            if( m_p850hpa->IsChecked() )
                r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][7] );
            if( m_p700hpa->IsChecked() )
                r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][8] );
            if( m_p500hpa->IsChecked() )
                r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][9] );
            if( m_p300hpa->IsChecked() )
                r_parameters.Append( s[m_pMailTo->GetCurrentSelection()] + p[m_pMailTo->GetCurrentSelection()][10] );
        }

        break;
    case COAMPS:                                                                           //COAMPS
        r_parameters = wxT("WIND,PRMSL");                                 //the default parameters for this model
        break;
    case RTOFS:                                                                           //RTOFS
        r_parameters = wxT("CUR,WTMP");                                   //the default parameters for this model
        break;
    }
    if( !IsZYGRIB && m_cMovingGribEnabled->IsChecked())            //moving grib
        r_parameters.Append(wxString::Format(_T("|%d,%d"),m_sMovingSpeed->GetValue(),m_sMovingCourse->GetValue()));

    if( !EstimateFileSize() ) m_MailError_Nb += 2;
    return wxString( r_topmess + r_parameters );
}
bool GribRequestSetting::DoRenderZoneOverlay()
{
    wxPoint p;
    GetCanvasPixLL( m_Vp, &p, m_Lat, m_Lon);

    int x = (m_StartPoint.x < p.x) ? m_StartPoint.x : p.x;
    int y = (m_StartPoint.y < p.y) ? m_StartPoint.y : p.y;

    int zw = fabs( (double ) p.x - m_StartPoint.x );
    int zh = fabs( (double ) p.y - m_StartPoint.y );

    wxPoint center;
    center.x = x + (zw / 2);
    center.y = y + (zh / 2);

    wxFont *font = OCPNGetFont(_("Dialog"), 10);
    wxColour pen_color, back_color;
    GetGlobalColor( _T ( "DASHR" ), &pen_color );
    GetGlobalColor( _T ( "YELO1" ), &back_color );

    int label_offsetx = 5, label_offsety = 1;

    double size;
    EstimateFileSize( &size );

    wxString label( _("Coord. ") );
    label.Append( toMailFormat(1, m_spMaxLat->GetValue()) + _T(" "));
    label.Append( toMailFormat(0, m_spMinLon->GetValue()) + _T(" "));
    label.Append( toMailFormat(1, m_spMinLat->GetValue()) + _T(" "));
    label.Append( toMailFormat(0, m_spMaxLon->GetValue()) + _T("\n"));
    label.Append( _T("Estim. Size ") ).Append((wxString::Format( _T("%1.2f " ) , size ) + _("MB") ) );

    if( m_pdc ) {
        wxPen pen(pen_color);
        pen.SetWidth(3);
        m_pdc->SetPen( pen );
        m_pdc->SetBrush( *wxTRANSPARENT_BRUSH);
        m_pdc->DrawRectangle(x, y, zw, zh);



        int w, h, sl;
#ifdef __WXMAC__
        wxScreenDC sdc;
        sdc.GetMultiLineTextExtent(label, &w, &h, &sl, font);
#else
        m_pdc->GetMultiLineTextExtent(label, &w, &h, &sl, font);
#endif
        w += 2*label_offsetx, h += 2*label_offsety;
        x = center.x - (w / 2);
        y = center.y - (h / 2);

        wxBitmap bm(w, h);
        wxMemoryDC mdc(bm);
        mdc.Clear();

        mdc.SetFont( *font );
        mdc.SetBrush(back_color);
        mdc.SetPen(*wxTRANSPARENT_PEN);
        mdc.SetTextForeground(wxColor( 0, 0, 0 ));
        mdc.DrawRectangle(0, 0, w, h);
        mdc.DrawLabel( label, wxRect( label_offsetx, label_offsety, w, h ) );

        wxImage im = bm.ConvertToImage();
        im.InitAlpha();
        w = im.GetWidth(), h = im.GetHeight();
        for( int j = 0; j < h; j++ )
			for( int i = 0; i < w; i++ )
				im.SetAlpha( i, j, 155 );

        m_pdc->DrawBitmap(im, x, y, true);

    } else {

#ifdef ocpnUSE_GL
    TexFont m_TexFontlabel;
    m_TexFontlabel.Build(*font);

    glColor3ub(pen_color.Red(), pen_color.Green(), pen_color.Blue() );

    glPushAttrib(GL_COLOR_BUFFER_BIT | GL_LINE_BIT | GL_ENABLE_BIT |
                     GL_POLYGON_BIT | GL_HINT_BIT );

   glEnable( GL_LINE_SMOOTH );
   glEnable( GL_BLEND );
   glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
   glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
   glLineWidth( 3.f );

   glBegin( GL_LINES );
   glVertex2d( x, y );
   glVertex2d( x+zw, y );
   glVertex2d( x+zw, y );
   glVertex2d( x+zw, y+zh );
   glVertex2d( x+zw, y+zh );
   glVertex2d( x, y+zh );
   glVertex2d( x, y+zh );
   glVertex2d( x, y );
   glEnd();

   int w, h;
   glColor4ub(back_color.Red(), back_color.Green(), back_color.Blue(), 155 );
   m_TexFontlabel.GetTextExtent(label, &w, &h );

    w += 2*label_offsetx, h += 2*label_offsety;
    x = center.x - (w / 2);
    y = center.y - (h / 2);

   /* draw text background */
   glBegin(GL_QUADS);
   glVertex2i(x,   y);
   glVertex2i(x+w, y);
   glVertex2i(x+w, y+h);
   glVertex2i(x,   y+h);
   glEnd();

   /* draw text */
   glColor3ub( 0, 0, 0 );

   glEnable(GL_TEXTURE_2D);
   m_TexFontlabel.RenderString(label, x + label_offsetx, y + label_offsety);
   glDisable(GL_TEXTURE_2D);

   glDisable( GL_BLEND );

#endif
    }
    return true;
}