diff --git a/bitmap2component/bitmap2cmp_gui.cpp b/bitmap2component/bitmap2cmp_gui.cpp index 47d7de78ac..cc0c95f863 100644 --- a/bitmap2component/bitmap2cmp_gui.cpp +++ b/bitmap2component/bitmap2cmp_gui.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 1992-2010 jean-pierre.charras - * Copyright (C) 1992-2019 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2020 Kicad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -799,7 +799,7 @@ void BM2CMP_FRAME::exportEeschemaFormat() wxFileDialog fileDlg( this, _( "Create Symbol Library" ), path, wxEmptyString, - SchematicLibraryFileWildcard(), + LegacySymbolLibFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); int diag = fileDlg.ShowModal(); @@ -808,7 +808,7 @@ void BM2CMP_FRAME::exportEeschemaFormat() return; fn = fileDlg.GetPath(); - fn.SetExt( SchematicLibraryFileExtension ); + fn.SetExt( LegacySymbolLibFileExtension ); m_ConvertedFileName = fn.GetFullPath(); FILE* outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) ); diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index 1c994093fb..44068d9e80 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -116,7 +116,7 @@ wxString AddFileExtListToFilter( const std::vector& aExts ) const std::string KiCadSymbolLibFileExtension( "kicad_sym" ); const std::string SchematicSymbolFileExtension( "sym" ); -const std::string SchematicLibraryFileExtension( "lib" ); +const std::string LegacySymbolLibFileExtension( "lib" ); const std::string VrmlFileExtension( "wrl" ); @@ -180,7 +180,7 @@ wxString KiCadSymbolLibFileWildcard() } -wxString SchematicLibraryFileWildcard() +wxString LegacySymbolLibFileWildcard() { return _( "KiCad legacy symbol library files" ) + AddFileExtListToFilter( { "lib" } ); } diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 34f59d605b..bd65d7f631 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -489,7 +489,7 @@ const wxString PART_LIBS::CacheName( const wxString& aFullProjectFilename ) wxFileName name = aFullProjectFilename; name.SetName( name.GetName() + "-cache" ); - name.SetExt( SchematicLibraryFileExtension ); + name.SetExt( LegacySymbolLibFileExtension ); if( name.FileExists() ) return name.GetFullPath(); @@ -538,7 +538,7 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) // lib_names[] does not store the file extension. Set it. // Remember lib_names[i] can contain a '.' in name, so using a wxFileName // before adding the extension can create incorrect full filename - wxString fullname = lib_names[i] + "." + SchematicLibraryFileExtension; + wxString fullname = lib_names[i] + "." + LegacySymbolLibFileExtension; // Now the full name is set, we can use a wxFileName. wxFileName fn( fullname ); diff --git a/eeschema/dialogs/dialog_symbol_remap.cpp b/eeschema/dialogs/dialog_symbol_remap.cpp index 1172249773..b786a2f427 100644 --- a/eeschema/dialogs/dialog_symbol_remap.cpp +++ b/eeschema/dialogs/dialog_symbol_remap.cpp @@ -434,7 +434,7 @@ bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) // Back up the cache library. srcFileName.SetPath( Prj().GetProjectPath() ); srcFileName.SetName( Prj().GetProjectName() + "-cache" ); - srcFileName.SetExt( SchematicLibraryFileExtension ); + srcFileName.SetExt( LegacySymbolLibFileExtension ); destFileName = srcFileName; destFileName.SetName( destFileName.GetName() + timeStamp ); diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index f242a557b6..734b92ee23 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -80,7 +80,7 @@ static const std::map& fileTypes() { ID_PANEL_SYM_LIB_LEGACY, { "KiCad legacy symbol library file (*.lib)", - SchematicSymbolFileWildcard(), + LegacySymbolLibFileWildcard(), "", true, SCH_IO_MGR::SCH_LEGACY @@ -255,7 +255,7 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, attr = new wxGridCellAttr; attr->SetEditor( new GRID_CELL_SYMLIB_EDITOR( m_parent, &m_lastBrowseDir, - SchematicLibraryFileWildcard() ) ); + KiCadSymbolLibFileWildcard() ) ); g->SetColAttr( COL_URI, attr ); attr = new wxGridCellAttr; @@ -410,9 +410,9 @@ void PANEL_SYM_LIB_TABLE::pageChangedHandler( wxAuiNotebookEvent& event ) void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) { - wxString wildcards = SchematicLibraryFileWildcard(); + wxString wildcards = KiCadSymbolLibFileWildcard(); - wildcards += "|" + KiCadSymbolLibFileWildcard(); + wildcards += "|" + LegacySymbolLibFileWildcard(); wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir, wxEmptyString, wildcards, diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 48e879a4a7..3dffa6a14c 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -83,8 +83,6 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName, { wxString wildcards = KiCadSchematicFileWildcard(); - wildcards += "|" + LegacySchematicFileWildcard(); - wxFileDialog dlg( this, _( "Schematic Files" ), wxPathOnly( Prj().GetProjectFullName() ), schematicFileName.GetFullName(), wildcards, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); @@ -94,11 +92,7 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName, schematicFileName = dlg.GetPath(); - if( dlg.GetFilterIndex() == 1 - && schematicFileName.GetExt() != LegacySchematicFileExtension ) - schematicFileName.SetExt( LegacySchematicFileExtension ); - else if( dlg.GetFilterIndex() == 0 - && schematicFileName.GetExt() != KiCadSchematicFileExtension ) + if( schematicFileName.GetExt().IsEmpty() ) schematicFileName.SetExt( KiCadSchematicFileExtension ); } diff --git a/eeschema/libarch.cpp b/eeschema/libarch.cpp index edd3d15d95..154bed3b78 100644 --- a/eeschema/libarch.cpp +++ b/eeschema/libarch.cpp @@ -50,7 +50,7 @@ bool SCH_EDIT_FRAME::CreateArchiveLibraryCacheFile( bool aUseCurrentSheetFilenam fn = Schematic().RootScreen()->GetFileName(); fn.SetName( fn.GetName() + "-cache" ); - fn.SetExt( SchematicLibraryFileExtension ); + fn.SetExt( LegacySymbolLibFileExtension ); bool success = CreateArchiveLibrary( fn.GetFullPath() ); diff --git a/eeschema/libedit/lib_export.cpp b/eeschema/libedit/lib_export.cpp index bf5dac81a5..d431706dc9 100644 --- a/eeschema/libedit/lib_export.cpp +++ b/eeschema/libedit/lib_export.cpp @@ -47,17 +47,27 @@ void LIB_EDIT_FRAME::ImportPart() return; } + wxString wildcards = KiCadSymbolLibFileWildcard(); + + wildcards += "|" + LegacySymbolLibFileWildcard(); + wxFileDialog dlg( this, _( "Import Symbol" ), m_mruPath, wxEmptyString, - SchematicLibraryFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST ); + wildcards, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); if( dlg.ShowModal() == wxID_CANCEL ) return; wxFileName fn = dlg.GetPath(); + + if( fn.GetExt().IsEmpty() ) + fn.SetExt( (dlg.GetFilterIndex() == 0) ? + KiCadSymbolLibFileExtension : LegacySymbolLibFileExtension ); + m_mruPath = fn.GetPath(); wxArrayString symbols; - SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) ); + SCH_IO_MGR::SCH_FILE_T piType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() ); + SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( piType ) ); // TODO dialog to select the part to be imported if there is more than one try @@ -108,10 +118,10 @@ void LIB_EDIT_FRAME::ExportPart() wxFileName fn; fn.SetName( part->GetName().Lower() ); - fn.SetExt( SchematicLibraryFileExtension ); + fn.SetExt( KiCadSymbolLibFileExtension ); wxFileDialog dlg( this, _( "Export Symbol" ), m_mruPath, fn.GetFullName(), - SchematicLibraryFileWildcard(), wxFD_SAVE ); + KiCadSymbolLibFileWildcard(), wxFD_SAVE ); if( dlg.ShowModal() == wxID_CANCEL ) return; @@ -121,7 +131,7 @@ void LIB_EDIT_FRAME::ExportPart() LIB_PART* old_part = NULL; - SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) ); + SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); if( fn.FileExists() ) { @@ -165,7 +175,10 @@ void LIB_EDIT_FRAME::ExportPart() if( !fn.FileExists() ) pi->CreateSymbolLib( fn.GetFullPath() ); - pi->SaveSymbol( fn.GetFullPath(), new LIB_PART( *part ) ); + // The flattened symbol is most likely what the user would want. As some point in + // the future as more of the symbol library inheritance is implemented, this may have + // to be changes to save parts of inherited symbols. + pi->SaveSymbol( fn.GetFullPath(), part->Flatten().release() ); } catch( const IO_ERROR& ioe ) { diff --git a/eeschema/libedit/lib_manager.cpp b/eeschema/libedit/lib_manager.cpp index d66a91a995..a0d300a928 100644 --- a/eeschema/libedit/lib_manager.cpp +++ b/eeschema/libedit/lib_manager.cpp @@ -133,7 +133,7 @@ SYMBOL_LIB_TABLE_ROW* LIB_MANAGER::GetLibrary( const wxString& aLibrary ) const bool LIB_MANAGER::SaveLibrary( const wxString& aLibrary, const wxString& aFileName, SCH_IO_MGR::SCH_FILE_T aFileType ) { - wxCHECK( LibraryExists( aLibrary ), false ); + wxCHECK( aFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY && LibraryExists( aLibrary ), false ); wxFileName fn( aFileName ); wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false ); SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( aFileType ) ); @@ -271,8 +271,19 @@ bool LIB_MANAGER::ClearPartModified( const wxString& aAlias, const wxString& aLi bool LIB_MANAGER::IsLibraryReadOnly( const wxString& aLibrary ) const { wxCHECK( LibraryExists( aLibrary ), true ); + wxFileName fn( symTable()->GetFullURI( aLibrary ) ); - return ( fn.FileExists() && !fn.IsFileWritable() ) || !fn.IsDirWritable(); + + // From hence forth, legacy symbol libraries are not writable. + const SYMBOL_LIB_TABLE_ROW* row = dynamic_cast( + symTable()->FindRowByURI( fn.GetFullPath() ) ); + SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN; + + if( row ) + fileType = SCH_IO_MGR::EnumFromStr( row->GetType() ); + + return ( fileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY ) && fn.FileExists() && + ( !fn.IsFileWritable() || !fn.IsDirWritable() ); } @@ -648,6 +659,8 @@ bool LIB_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate, SYMBOL_LI if( aCreate ) { + wxCHECK( schFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY, false ); + try { aTable->CreateSymbolLib( libName ); diff --git a/eeschema/libedit/libedit.cpp b/eeschema/libedit/libedit.cpp index bac9973c66..23a3a6a4ad 100644 --- a/eeschema/libedit/libedit.cpp +++ b/eeschema/libedit/libedit.cpp @@ -813,7 +813,6 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile ) fn.SetExt( KiCadSymbolLibFileExtension ); wxString wildcards = KiCadSymbolLibFileWildcard(); - wildcards += "|" + SchematicLibraryFileWildcard(); wxFileDialog dlg( this, wxString::Format( _( "Save Library \"%s\" As..." ), aLibrary ), default_path, fn.GetFullName(), wildcards, @@ -824,16 +823,8 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile ) fn = dlg.GetPath(); - // Update the file extension and plugin if a different library type was selected. - if( dlg.GetFilterIndex() == 1 ) - { - fn.SetExt( SchematicLibraryFileExtension ); - fileType = SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY; - } - else - { + if( fn.GetExt().IsEmpty() ) fn.SetExt( KiCadSymbolLibFileExtension ); - } } else { @@ -841,11 +832,8 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile ) fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() ); } - wxFileName docFileName = fn; - docFileName.SetExt( DOC_EXT ); - // Verify the user has write privileges before attempting to save the library file. - if( !IsWritable( fn ) || !IsWritable( docFileName ) ) + if( !IsWritable( fn ) ) return false; ClearMsgPanel(); @@ -854,10 +842,6 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile ) if( !backupFile( fn, "bak" ) ) return false; - // Copy .dcm file to .bck. - if( !backupFile( docFileName, "bck" ) ) - return false; - if( !m_libMgr->SaveLibrary( aLibrary, fn.GetFullPath(), fileType ) ) { msg.Printf( _( "Failed to save changes to symbol library file \"%s\"" ), @@ -871,9 +855,6 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile ) ClearMsgPanel(); msg.Printf( _( "Symbol library file \"%s\" saved" ), fn.GetFullPath() ); - wxString msg1; - msg1.Printf( _( "Symbol library documentation file \"%s\" saved" ), docFileName.GetFullPath() ); - AppendMsgPanel( msg, msg1, BLUE ); RebuildSymbolUnitsList(); return true; diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index d461ab6664..29f9795471 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -113,7 +113,7 @@ static wxFileName GetRescueLibraryFileName( SCHEMATIC* aSchematic ) { wxFileName fn = aSchematic->GetFileName(); fn.SetName( fn.GetName() + wxT( "-rescue" ) ); - fn.SetExt( SchematicLibraryFileExtension ); + fn.SetExt( LegacySymbolLibFileExtension ); return fn; } diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 0794b51983..46d728356c 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -157,7 +157,7 @@ wxString SCH_EAGLE_PLUGIN::getLibName() wxFileName SCH_EAGLE_PLUGIN::getLibFileName() { - wxFileName fn( m_kiway->Prj().GetProjectPath(), getLibName(), SchematicLibraryFileExtension ); + wxFileName fn( m_kiway->Prj().GetProjectPath(), getLibName(), KiCadSymbolLibFileExtension ); return fn; } @@ -432,7 +432,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema wxCHECK_MSG( libTable, NULL, "Could not load symbol lib table." ); - m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) ); + m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); m_properties = std::make_unique(); ( *m_properties )[SCH_LEGACY_PLUGIN::PropBuffering] = ""; @@ -446,7 +446,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema // Add the new library to the project symbol library table. libTable->InsertRow( - new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri, wxString( "Legacy" ) ) ); + new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri, wxString( "KiCad" ) ) ); // Save project symbol library table. wxFileName fn( @@ -501,9 +501,9 @@ void SCH_EAGLE_PLUGIN::loadDrawing( wxXmlNode* aDrawingNode ) // wxXmlNode* settings = drawingChildren["settings"] - // Load schematic auto schematic = drawingChildren["schematic"]; + if( schematic ) loadSchematic( schematic ); } diff --git a/eeschema/sch_io_mgr.cpp b/eeschema/sch_io_mgr.cpp index 1377aa4030..db28ed88c6 100644 --- a/eeschema/sch_io_mgr.cpp +++ b/eeschema/sch_io_mgr.cpp @@ -60,6 +60,8 @@ SCH_PLUGIN* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType ) return new SCH_SEXPR_PLUGIN(); case SCH_EAGLE: return new SCH_EAGLE_PLUGIN(); + default: + ; } return NULL; @@ -153,7 +155,7 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& a SCH_FILE_T ret = SCH_KICAD; // default guess, unless detected otherwise. wxFileName fn( aLibPath ); - if( fn.GetExt() == SchematicLibraryFileExtension ) + if( fn.GetExt() == LegacySymbolLibFileExtension ) { ret = SCH_LEGACY; } diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index 819637a339..8a73490036 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -60,6 +60,7 @@ public: // ALTIUM, // etc. + SCH_FILE_UNKNOWN } ) /** diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index adf0132d33..f7a16b1a54 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Wayne Stambaugh - * Copyright (C) 2016-2017 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2016-2020 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -56,7 +56,7 @@ public: } SYMBOL_LIB_TABLE_ROW() : - type( SCH_IO_MGR::SCH_LEGACY ) + type( SCH_IO_MGR::SCH_KICAD ) { SetEnabled( true ); } diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 559ab16d36..234396d2c2 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -110,7 +110,7 @@ wxString AddFileExtListToFilter( const std::vector& aExts ); wxString formatWildcardExt( const wxString& aWildcard ); extern const std::string SchematicSymbolFileExtension; -extern const std::string SchematicLibraryFileExtension; +extern const std::string LegacySymbolLibFileExtension; extern const std::string SchematicBackupFileExtension; extern const std::string VrmlFileExtension; @@ -173,7 +173,7 @@ extern wxString ComponentFileWildcard(); extern wxString PageLayoutDescrFileWildcard(); extern wxString SchematicSymbolFileWildcard(); extern wxString KiCadSymbolLibFileWildcard(); -extern wxString SchematicLibraryFileWildcard(); +extern wxString LegacySymbolLibFileWildcard(); extern wxString ProjectFileWildcard(); extern wxString KiCadSchematicFileWildcard(); extern wxString LegacySchematicFileWildcard(); diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index c221cc1cfd..fd6912b0dc 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -283,7 +283,7 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type ) case TREE_SVG: return SVGFileExtension; case TREE_PAGE_LAYOUT_DESCR: return PageLayoutDescrFileExtension; case TREE_FOOTPRINT_FILE: return KiCadFootprintFileExtension; - case TREE_SCHEMATIC_LIBFILE: return SchematicLibraryFileExtension; + case TREE_SCHEMATIC_LIBFILE: return LegacySymbolLibFileExtension; default: return wxEmptyString; } }