Esempio n. 1
0
void GRIBUIDialog::OpenFile(bool newestFile)
{
    m_bpPlay->SetBitmap(*m_bPlay);
    m_bpPlay->SetToolTip(_("Play"));
    m_tPlayStop.Stop();

    m_cRecordForecast->Clear();
    /* this should be un-commented to avoid a memory leak,
       but for some reason it crbashes windows */
//    delete m_bGRIBActiveFile;
    m_pTimelineSet = NULL;

    //get more recent file in default directory if necessary
    wxFileName f( m_file_name );
    if( newestFile || f.GetFullName().IsEmpty() ) m_file_name = GetNewestFileInDirectory();

    m_bGRIBActiveFile = new GRIBFile( m_file_name,
                                      pPlugIn->GetCopyFirstCumRec(),
                                      pPlugIn->GetCopyMissWaveRec() );    

    ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
    if(rsa->GetCount() < 2)
        m_TimeLineHours = 0;
    else {
        GribRecordSet &first=rsa->Item(0), &last = rsa->Item(rsa->GetCount()-1);
        
        wxTimeSpan span = wxDateTime(last.m_Reference_Time) - wxDateTime(first.m_Reference_Time);
        m_TimeLineHours = span.GetHours();
        m_sTimeline->Enable();
    }
    m_sTimeline->SetValue(0);
    
    wxFileName fn( m_file_name );
    SetLabel( fn.GetFullName() );

    if( m_bGRIBActiveFile ) {
        if( m_bGRIBActiveFile->IsOK() ) { 
            //there could be valid but empty file
            if( rsa->GetCount() == 0 ) {
                m_bGRIBActiveFile = NULL;
                pPlugIn->GetGRIBOverlayFactory()->SetMessage( _("Error:  No valid data in this file!") );
            } else
                PopulateComboDataList( 0 );
        } else {
            if( fn.IsDir() ) {
                pPlugIn->GetGRIBOverlayFactory()->SetMessage( _("Warning:  Empty directory!") );
                SetLabel( fn.GetFullPath() );
            }
            else
                pPlugIn->GetGRIBOverlayFactory()->SetMessage( m_bGRIBActiveFile->GetLastMessage() );
	}
        SetFactoryOptions();
        DisplayDataGRS();
        PopulateTrackingControls();
    }
}
Esempio n. 2
0
void GRIBUIDialog::TimelineChanged(bool sync)
{
    if(!m_bGRIBActiveFile)
        return;

    wxDateTime time = TimelineTime();
    SetGribTimelineRecordSet(GetTimeLineRecordSet(time));

    /* get closest index to update combo box */
    unsigned int i;
    ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
    wxDateTime itime, ip1time;
    for(i=0; i<rsa->GetCount()-1; i++) {
        itime = rsa->Item(i).m_Reference_Time;
        ip1time = rsa->Item(i+1).m_Reference_Time;
        if(ip1time >= time)
            break;
    }

    if(time - itime < ip1time - time)
        m_cRecordForecast->SetSelection(i);
    else
        m_cRecordForecast->SetSelection(i+1);

    if(sync)
        return;

//    m_cRecordForecast->ToggleWindowStyle(wxCB_READONLY);
        m_cRecordForecast->SetValue( TToString( time, pPlugIn->GetTimeZone() ) );
//    m_cRecordForecast->ToggleWindowStyle(wxCB_READONLY);
    
    pPlugIn->SendTimelineMessage(time);
    RequestRefresh( pParent );
}
Esempio n. 3
0
wxDateTime GRIBUIDialog::MinTime()
{
    ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
    if(rsa && rsa->GetCount()) {
        GribRecordSet &first = rsa->Item(0);
        return first.m_Reference_Time;
    }
    return wxDateTime(0.0);
}
Esempio n. 4
0
void GRIBUIDialog::PopulateComboDataList( int index )
{
    m_cRecordForecast->Clear();

    ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
    for( size_t i = 0; i < rsa->GetCount(); i++ ) {
        wxDateTime t( rsa->Item( i ).m_Reference_Time );

        m_cRecordForecast->Append( TToString( t, pPlugIn->GetTimeZone() ) );
    }
    m_cRecordForecast->SetSelection( index );
}
Esempio n. 5
0
void GRIBUIDialog::OpenFile()
{
    m_tbPlayStop->SetValue(false);
    m_tPlayStop.Stop();

    m_cRecordForecast->Clear();
    /* this should be un-commented to avoid a memory leak,
       but for some reason it crbashes windows */
//    delete m_bGRIBActiveFile;
    m_bGRIBActiveFile = new GRIBFile( m_file_name,
                                      pPlugIn->GetCopyFirstCumRec(),
                                      pPlugIn->GetCopyMissWaveRec() );    

    ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
    if(rsa->GetCount() < 2)
        m_TimeLineHours = 0;
    else {
        GribRecordSet &first=rsa->Item(0), &last = rsa->Item(rsa->GetCount()-1);
        
        wxTimeSpan span = wxDateTime(last.m_Reference_Time) - wxDateTime(first.m_Reference_Time);
        m_TimeLineHours = span.GetHours();
        m_sTimeline->Enable();
    }
    m_sTimeline->SetValue(0);
    
    wxFileName fn( m_file_name );
    SetLabel( fn.GetFullName() );
    
    if( m_bGRIBActiveFile ) {
        if( m_bGRIBActiveFile->IsOK() ) { 
            PopulateComboDataList( 0 );
            SetFactoryOptions();
            DisplayDataGRS();
            PopulateTrackingControls();
        } else 
            pPlugIn->GetGRIBOverlayFactory()->SetMessage( m_bGRIBActiveFile->GetLastMessage() );
    }    
}
Esempio n. 6
0
GribTimelineRecordSet* GRIBUIDialog::GetTimeLineRecordSet(wxDateTime time)
{
    unsigned int i, im1;
    ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();

    wxDateTime curtime;
    for(i=0; i<rsa->GetCount(); i++) {
        GribRecordSet &cur=rsa->Item(i);
        curtime = cur.m_Reference_Time;
        if(curtime >= time)
            break;
    }
    im1 = i-1;
    if(i == 0)
        im1 = 0;
    
    wxDateTime mintime = MinTime();
    double minute2 = (curtime - mintime).GetMinutes();
    curtime = rsa->Item(im1).m_Reference_Time;
    double minute1 = (curtime - mintime).GetMinutes();
    double nminute = (time - mintime).GetMinutes();
    
    if(minute2<minute1 || nminute < minute1 || nminute > minute2)
        return NULL;

    double interp_const;
    if(minute1 == minute2)
        interp_const = 0;
    else 
        interp_const = (nminute-minute1) / (minute2-minute1);
    
    if(!m_OverlaySettings.m_bInterpolate)
        interp_const = round(interp_const);

    GribRecordSet &GRS1 = rsa->Item(im1), &GRS2 = rsa->Item(i);
    return new GribTimelineRecordSet(GRS1, GRS2, interp_const);
}
Esempio n. 7
0
void grib_pi::OnToolbarToolCallback(int id)
{
    if( !::wxIsBusy() ) ::wxBeginBusyCursor();

    bool starting = false;

    double scale_factor = GetOCPNGUIToolScaleFactor_PlugIn();
    if( scale_factor != m_GUIScaleFactor ) starting = true;

    m_GUIScaleFactor = scale_factor;
    
    if(!m_pGribCtrlBar)
    {
        starting = true;
        long style = m_DialogStyle == ATTACHED_HAS_CAPTION ? wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU : wxBORDER_NONE|wxSYSTEM_MENU;
        m_pGribCtrlBar = new GRIBUICtrlBar(m_parent_window, wxID_ANY, wxEmptyString, wxDefaultPosition,
                wxDefaultSize, style, this);
        m_pGribCtrlBar->SetScaledBitmap(m_GUIScaleFactor);
        
        wxMenu* dummy = new wxMenu(_T("Plugin"));
        wxMenuItem* table = new wxMenuItem( dummy, wxID_ANY, wxString( _("Weather table") ), wxEmptyString, wxITEM_NORMAL );
#ifdef __WXMSW__
        wxFont *qFont = OCPNGetFont(_("Menu"), 10);
        table->SetFont(*qFont);
#endif
        m_MenuItem = AddCanvasContextMenuItem(table, this);
        SetCanvasContextMenuItemViz(m_MenuItem, false);

        // Create the drawing factory
        m_pGRIBOverlayFactory = new GRIBOverlayFactory( *m_pGribCtrlBar );
        m_pGRIBOverlayFactory->SetTimeZone( m_bTimeZone );
        m_pGRIBOverlayFactory->SetParentSize( m_display_width, m_display_height);
        m_pGRIBOverlayFactory->SetSettings( m_bGRIBUseHiDef, m_bGRIBUseGradualColors );

        m_pGribCtrlBar->OpenFile( m_bLoadLastOpenFile == 0 );

    }

    if( m_pGribCtrlBar->GetFont() != *OCPNGetFont(_("Dialog"), 10) ) starting = true;

    //Toggle GRIB overlay display
    m_bShowGrib = !m_bShowGrib;

    //    Toggle dialog?
    if(m_bShowGrib) {
        if( starting ) {
            SetDialogFont( m_pGribCtrlBar );
	    m_pGribCtrlBar->SetScaledBitmap( m_GUIScaleFactor );
            m_pGribCtrlBar->SetDialogsStyleSizePosition( true );
            m_pGribCtrlBar->Refresh();
        } else {
            MoveDialog( m_pGribCtrlBar, GetCtrlBarXY(), wxPoint( 20, 60) );
            if( m_DialogStyle >> 1 == SEPARATED ) {
                MoveDialog( m_pGribCtrlBar->GetCDataDialog(), GetCursorDataXY(), wxPoint( 20, 170));
                m_pGribCtrlBar->GetCDataDialog()->Show( m_pGribCtrlBar->m_CDataIsShown );
                }
        }
        m_pGribCtrlBar->Show();
        if( m_pGribCtrlBar->m_bGRIBActiveFile ) {
            if( m_pGribCtrlBar->m_bGRIBActiveFile->IsOK() ) {
                ArrayOfGribRecordSets *rsa = m_pGribCtrlBar->m_bGRIBActiveFile->GetRecordSetArrayPtr();
                if(rsa->GetCount() > 1) SetCanvasContextMenuItemViz( m_MenuItem, true);
            }
        }
        // Toggle is handled by the CtrlBar but we must keep plugin manager b_toggle updated
        // to actual status to ensure correct status upon CtrlBar rebuild
        SetToolbarItemState( m_leftclick_tool_id, m_bShowGrib );
        RequestRefresh(m_parent_window); // refresh main window
    } else