void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event )
{
/*
    if( GetScreen()->IsModify() )
    {
        if( !IsOK( this, _( "Board Modified: Continue ?" ) ) )
            return;
    }
*/

    wxString fullFileName = GetBoard()->GetFileName();
    wxString path;
    wxString name;
    wxString ext;

    wxString sessionExt( wxT( ".ses" ) );
    wxString mask = wxT( "*" ) + sessionExt;

    wxFileName::SplitPath( fullFileName, &path, &name, &ext );
    name += sessionExt;

    fullFileName = EDA_FILE_SELECTOR( _( "Merge Specctra Session file:" ),
                                      path,
                                      name,
                                      sessionExt,
                                      mask,
                                      this,
                                      wxFD_OPEN,
                                      false );

    if( fullFileName == wxEmptyString )
        return;

    SPECCTRA_DB     db;
    LOCALE_IO       toggle;

    try
    {
        db.LoadSESSION( fullFileName );
        db.FromSESSION( GetBoard() );
    }
    catch( const IO_ERROR& ioe )
    {
        wxString msg = ioe.errorText;
        msg += '\n';
        msg += _("BOARD may be corrupted, do not save it.");
        msg += '\n';
        msg += _("Fix problem and try again.");

        DisplayError( this, msg );
        return;
    }

    OnModify();
    GetBoard()->m_Status_Pcb = 0;

    /* At this point we should call Compile_Ratsnest()
     * but this could be time consumming.
     * So if incorrect number of Connected and No connected pads is accepted
     * until Compile_Ratsnest() is called (when track tool selected for instance)
     * leave the next line commented
     * Otherwise uncomment this line
    */
    //Compile_Ratsnest( NULL, true );

    SetStatusText( wxString( _( "Session file imported and merged OK." ) ) );

    m_canvas->Refresh( true );
}
Example #2
0
void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event )
{
    wxString fullFileName = GetBoard()->GetFileName();
    wxString path;
    wxString name;
    wxString ext;

    wxString sessionExt( wxT( ".ses" ) );
    wxString mask = wxT( "*" ) + sessionExt;

    wxFileName::SplitPath( fullFileName, &path, &name, &ext );
    name += sessionExt;

    fullFileName = EDA_FILE_SELECTOR( _( "Merge Specctra Session file:" ),
                                      path,
                                      name,
                                      sessionExt,
                                      mask,
                                      this,
                                      wxFD_OPEN,
                                      false );

    if( fullFileName == wxEmptyString )
    {
        return;
    }

    SetCurItem( NULL );

    // To avoid issues with undo/redo lists (dangling pointers)
    // clear the lists
    // todo: use undo/redo feature
    GetScreen()->ClearUndoRedoList();

    SPECCTRA_DB     db;
    LOCALE_IO       toggle;

    try
    {
        db.LoadSESSION( fullFileName );
        db.FromSESSION( GetBoard() );
    }
    catch( const IO_ERROR& ioe )
    {
        wxString msg = _(
                "Board may be corrupted, do not save it.\n"
                "Fix problem and try again"
                );

        wxString extra = ioe.What();

        DisplayErrorMessage( this, msg, extra);
        return;
    }

    OnModify();
    GetBoard()->m_Status_Pcb = 0;

    GetBoard()->GetConnectivity()->Clear();
    GetBoard()->GetConnectivity()->Build( GetBoard() );

    if( GetGalCanvas() )    // Update view:
    {
        auto view = GetGalCanvas()->GetView();

        // Update footprint positions
        view->RecacheAllItems();

        // add imported tracks (previous tracks are removed, therfore all are new)
        for( TRACK* track = GetBoard()->m_Track; track; track = track->Next() )
        {
            view->Add( track );
        }
   }

    SetStatusText( wxString( _( "Session file imported and merged OK." ) ) );

    Refresh();
}