예제 #1
0
void LIB_EDIT_FRAME::OnImportPart( wxCommandEvent& event )
{
    wxString msg;
    m_lastDrawItem = NULL;
    wxString libName = getTargetLib();

    if( !m_libMgr->LibraryExists( libName ) )
    {
        libName = SelectLibraryFromList();

        if( !m_libMgr->LibraryExists( libName ) )
            return;
    }

    wxFileDialog dlg( this, _( "Import Symbol" ), m_mruPath,
                      wxEmptyString, SchematicLibraryFileWildcard(),
                      wxFD_OPEN | wxFD_FILE_MUST_EXIST );

    if( dlg.ShowModal() == wxID_CANCEL )
        return;

    wxFileName fn = dlg.GetPath();
    m_mruPath = fn.GetPath();

    wxArrayString symbols;
    SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );

    // TODO dialog to select the part to be imported if there is more than one
    try
    {
        pi->EnumerateSymbolLib( symbols, fn.GetFullPath() );
    }
    catch( const IO_ERROR& ioe )
    {
        msg.Printf( _( "Cannot import symbol library \"%s\"." ), fn.GetFullPath() );
        DisplayErrorMessage( this, msg, ioe.What() );
        return;
    }

    if( symbols.empty() )
    {
        msg.Printf( _( "Symbol library file \"%s\" is empty." ), fn.GetFullPath() );
        DisplayError( this,  msg );
        return;
    }

    wxString symbolName = symbols[0];
    LIB_ALIAS* entry = pi->LoadSymbol( fn.GetFullPath(), symbolName );

    if( m_libMgr->PartExists( symbols[0], libName ) )
    {
        msg.Printf( _( "Symbol \"%s\" already exists in library \"%s\"." ), symbolName, libName );
        DisplayError( this,  msg );
        return;
    }

    m_libMgr->UpdatePart( entry->GetPart(), libName );
    SyncLibraries( false );
    loadPart( symbolName, libName, 1 );
}
예제 #2
0
bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
{
    wxFileName fn = m_libMgr->GetUniqueLibraryName();

    if( !LibraryFileBrowser( !aCreateNew, fn, SchematicLibraryFileWildcard(),
                             SchematicLibraryFileExtension, false ) )
    {
        return false;
    }

    wxString libName = fn.GetName();

    if( libName.IsEmpty() )
        return false;

    if( m_libMgr->LibraryExists( libName ) )
    {
        DisplayError( this, wxString::Format( _( "Library \"%s\" already exists" ), libName ) );
        return false;
    }

    // Select the target library table (global/project)
    SYMBOL_LIB_TABLE* libTable = selectSymLibTable();

    if( !libTable )
        return false;

    if( aCreateNew )
    {
        if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
        {
            DisplayError( this, wxString::Format( _( "Could not create the library file '%s'.\n"
                                                     "Check write permission." ),
                                                  fn.GetFullPath() ) );
            return false;
        }
    }
    else
    {
        if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
        {
            DisplayError( this, _( "Could not open the library file." ) );
            return false;
        }
    }

    bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
    saveSymbolLibTables( globalTable, !globalTable );

    return true;
}
예제 #3
0
void LIB_EDIT_FRAME::OnExportPart( wxCommandEvent& event )
{
    wxString msg, title;
    LIB_PART* part = getTargetPart();

    if( !part )
    {
        DisplayError( this, _( "There is no symbol selected to save." ) );
        return;
    }

    wxFileName fn;

    fn.SetName( part->GetName().Lower() );
    fn.SetExt( SchematicLibraryFileExtension );

    wxFileDialog dlg( this, _( "Export Symbol" ), m_mruPath, fn.GetFullName(),
                      SchematicLibraryFileWildcard(), wxFD_SAVE );

    if( dlg.ShowModal() == wxID_CANCEL )
        return;

    fn = dlg.GetPath();
    fn.MakeAbsolute();

    LIB_PART* old_part = NULL;

    SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );

    if( fn.FileExists() )
    {
        try
        {
            LIB_ALIAS* alias = pi->LoadSymbol( fn.GetFullPath(), part->GetName() );

            if( alias )
                old_part = alias->GetPart();
        }
        catch( const IO_ERROR& ioe )
        {
            msg.Printf( _( "Error occurred attempting to load symbol library file \"%s\"" ),
                        fn.GetFullPath() );
            DisplayErrorMessage( this, msg, ioe.What() );
            return;
        }

        if( old_part )
        {
            msg.Printf( _( "Symbol \"%s\" already exists in \"%s\"." ),
                        part->GetName(),
                        fn.GetFullName() );

            KIDIALOG errorDlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
            errorDlg.SetOKLabel( _( "Overwrite" ) );
            errorDlg.DoNotShowCheckbox( __FILE__, __LINE__ );

            if( errorDlg.ShowModal() == wxID_CANCEL )
                return;
        }
    }

    if( fn.Exists() && !fn.IsDirWritable() )
    {
        msg.Printf( _( "Write permissions are required to save library \"%s\"." ), fn.GetFullPath() );
        DisplayError( this, msg );
        return;
    }

    try
    {
        if( !fn.FileExists() )
            pi->CreateSymbolLib( fn.GetFullPath() );

        pi->SaveSymbol( fn.GetFullPath(), new LIB_PART( *part ) );
    }
    catch( const IO_ERROR& ioe )
    {
        msg = _( "Failed to create symbol library file " ) + fn.GetFullPath();
        DisplayErrorMessage( this, msg, ioe.What() );
        msg.Printf( _( "Error creating symbol library \"%s\"" ), fn.GetFullName() );
        SetStatusText( msg );
        return;
    }

    m_mruPath = fn.GetPath();
    m_lastDrawItem = NULL;
    SetDrawItem( NULL );

    msg.Printf( _( "Symbol \"%s\" saved in library \"%s\"" ), part->GetName(), fn.GetFullPath() );
    SetStatusText( msg );

    // See if the user wants it added to a library table (global or project)
    SYMBOL_LIB_TABLE* libTable = selectSymLibTable( true );

    if( libTable )
    {
        if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
        {
            DisplayError( this, _( "Could not open the library file." ) );
            return;
        }

        bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
        saveSymbolLibTables( globalTable, !globalTable );
    }
}