mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 17:03:44 +00:00
Schematic plugins refactoring, fixes for PCB plugins.
- Move PLUGIN_FILE_DESC to common. - SCH_PLUGIN: rename Load -> LoadSchematicFile, Save -> SaveSchematicFile. - Use PLUGIN_FILE_DESC and CanRead* in schematic plugins. - Return none/unknown types from Find/GuessPluginType functions. - Iterate over file types for file wildcards. - Clean-up header checking in IO plugins. - Use PCB plugin list in IO_MGR::GuessPluginTypeFromLibPath.
This commit is contained in:
parent
7428f3d452
commit
e128896ba6
common
eeschema
dialogs
eeschema.cppeeschema_helpers.cppfiles-io.cppsch_io_mgr.cppsch_io_mgr.hsch_plugin.cppsch_plugins
altium
cadstar
database
eagle
kicad
legacy
ltspice
symbol_editor
symbol_lib_table.cppsymbol_library_manager.cppinclude
pcbnew
files.cppfootprint_libraries_utils.cppio_mgr.cppio_mgr.hload_select_footprint.cppplugin.cpp
plugins/eagle
tools
qa
@ -382,6 +382,7 @@ set( COMMON_SRCS
|
||||
origin_transforms.cpp
|
||||
page_info.cpp
|
||||
paths.cpp
|
||||
plugin_file_desc.cpp
|
||||
printout.cpp
|
||||
project.cpp
|
||||
ptree.cpp
|
||||
|
32
common/plugin_file_desc.cpp
Normal file
32
common/plugin_file_desc.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <plugin_file_desc.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <wx/translation.h>
|
||||
|
||||
|
||||
wxString PLUGIN_FILE_DESC::FileFilter() const
|
||||
{
|
||||
return wxGetTranslation( m_Description ) + AddFileExtListToFilter( m_FileExtensions );
|
||||
}
|
@ -130,7 +130,6 @@ const std::string KiCadSymbolLibFileExtension( "kicad_sym" );
|
||||
const std::string SchematicSymbolFileExtension( "sym" );
|
||||
const std::string LegacySymbolLibFileExtension( "lib" );
|
||||
const std::string LegacySymbolDocumentFileExtension( "dcm" );
|
||||
const std::string LtspiceSymbolExtension( "asy" );
|
||||
|
||||
const std::string VrmlFileExtension( "wrl" );
|
||||
|
||||
@ -138,12 +137,10 @@ const std::string ProjectFileExtension( "kicad_pro" );
|
||||
const std::string LegacyProjectFileExtension( "pro" );
|
||||
const std::string ProjectLocalSettingsFileExtension( "kicad_prl" );
|
||||
const std::string LegacySchematicFileExtension( "sch" );
|
||||
const std::string EagleSchematicFileExtension( "sch" );
|
||||
const std::string CadstarSchematicFileExtension( "csa" );
|
||||
const std::string CadstarPartsLibraryFileExtension( "lib" );
|
||||
const std::string KiCadSchematicFileExtension( "kicad_sch" );
|
||||
const std::string SpiceFileExtension( "cir" );
|
||||
const std::string LtspiceSchematicExtension( "asc" );
|
||||
const std::string CadstarNetlistFileExtension( "frp" );
|
||||
const std::string OrCadPcb2NetlistFileExtension( "net" );
|
||||
const std::string NetlistFileExtension( "net" );
|
||||
@ -214,12 +211,6 @@ wxString AllFilesWildcard()
|
||||
}
|
||||
|
||||
|
||||
wxString SchematicSymbolFileWildcard()
|
||||
{
|
||||
return _( "KiCad drawing symbol files" ) + AddFileExtListToFilter( { "sym" } );
|
||||
}
|
||||
|
||||
|
||||
wxString KiCadSymbolLibFileWildcard()
|
||||
{
|
||||
return _( "KiCad symbol library files" )
|
||||
@ -227,28 +218,6 @@ wxString KiCadSymbolLibFileWildcard()
|
||||
}
|
||||
|
||||
|
||||
wxString LegacySymbolLibFileWildcard()
|
||||
{
|
||||
return _( "KiCad legacy symbol library files" ) + AddFileExtListToFilter( { "lib" } );
|
||||
}
|
||||
|
||||
|
||||
wxString DatabaseLibFileWildcard()
|
||||
{
|
||||
return _( "KiCad database library files" )
|
||||
+ AddFileExtListToFilter( { DatabaseLibraryFileExtension } );
|
||||
}
|
||||
|
||||
|
||||
wxString AllSymbolLibFilesWildcard()
|
||||
{
|
||||
return _( "All symbol library files" )
|
||||
+ AddFileExtListToFilter( { KiCadSymbolLibFileExtension,
|
||||
DatabaseLibraryFileExtension,
|
||||
"lib" } );
|
||||
}
|
||||
|
||||
|
||||
wxString ProjectFileWildcard()
|
||||
{
|
||||
return _( "KiCad project files" ) + AddFileExtListToFilter( { ProjectFileExtension } );
|
||||
@ -290,43 +259,12 @@ wxString KiCadSchematicFileWildcard()
|
||||
}
|
||||
|
||||
|
||||
wxString AltiumSchematicFileWildcard()
|
||||
{
|
||||
return _( "Altium schematic files" ) + AddFileExtListToFilter( { "SchDoc" } );
|
||||
}
|
||||
|
||||
|
||||
wxString CadstarPartsLibraryFileWildcard()
|
||||
{
|
||||
return _( "CADSTAR Parts Library files" )
|
||||
+ AddFileExtListToFilter( { CadstarPartsLibraryFileExtension } );
|
||||
}
|
||||
|
||||
|
||||
wxString CadstarSchematicArchiveFileWildcard()
|
||||
{
|
||||
return _( "CADSTAR Schematic Archive files" ) + AddFileExtListToFilter( { "csa" } );
|
||||
}
|
||||
|
||||
|
||||
wxString CadstarArchiveFilesWildcard()
|
||||
{
|
||||
return _( "CADSTAR Archive files" ) + AddFileExtListToFilter( { "csa", "cpa" } );
|
||||
}
|
||||
|
||||
|
||||
wxString EagleSchematicFileWildcard()
|
||||
{
|
||||
return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );
|
||||
}
|
||||
|
||||
|
||||
wxString LtspiceSchematicFileWildcard()
|
||||
{
|
||||
return _( "LTspice schematic files" ) + AddFileExtListToFilter( { "asc" } );
|
||||
}
|
||||
|
||||
|
||||
wxString EagleFilesWildcard()
|
||||
{
|
||||
return _( "Eagle XML files" ) + AddFileExtListToFilter( { "sch", "brd" } );
|
||||
|
@ -572,7 +572,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena
|
||||
|
||||
try
|
||||
{
|
||||
pi->Save( newAbsoluteFilename, m_sheet, &schematic );
|
||||
pi->SaveSchematicFile( newAbsoluteFilename, m_sheet, &schematic );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
|
@ -116,6 +116,10 @@ public:
|
||||
if( aCol == COL_URI )
|
||||
{
|
||||
SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::GuessPluginTypeFromLibPath( aValue );
|
||||
|
||||
if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
|
||||
pluginType = SCH_IO_MGR::SCH_KICAD;
|
||||
|
||||
SetValue( aRow, COL_TYPE, SCH_IO_MGR::ShowType( pluginType ) );
|
||||
}
|
||||
}
|
||||
@ -270,11 +274,38 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
|
||||
|
||||
attr = new wxGridCellAttr;
|
||||
|
||||
wxString wildcards = AllSymbolLibFilesWildcard()
|
||||
+ "|" + KiCadSymbolLibFileWildcard()
|
||||
+ "|" + LegacySymbolLibFileWildcard();
|
||||
wxString fileFiltersStr;
|
||||
wxString allWildcardsStr;
|
||||
|
||||
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
||||
{
|
||||
if( fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY )
|
||||
continue; // this is "Import non-KiCad schematic"
|
||||
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
||||
|
||||
if( !pi )
|
||||
continue;
|
||||
|
||||
const PLUGIN_FILE_DESC& desc = pi->GetLibraryFileDesc();
|
||||
|
||||
if( desc.m_FileExtensions.empty() )
|
||||
continue;
|
||||
|
||||
if( !fileFiltersStr.IsEmpty() )
|
||||
fileFiltersStr += wxChar( '|' );
|
||||
|
||||
fileFiltersStr += desc.FileFilter();
|
||||
|
||||
for( const std::string& ext : desc.m_FileExtensions )
|
||||
allWildcardsStr << wxT( "*." ) << formatWildcardExt( ext ) << wxT( ";" );
|
||||
}
|
||||
|
||||
fileFiltersStr = _( "All supported formats" ) + wxT( "|" ) + allWildcardsStr + wxT( "|" )
|
||||
+ fileFiltersStr;
|
||||
|
||||
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
|
||||
&cfg->m_lastSymbolLibDir, wildcards,
|
||||
&cfg->m_lastSymbolLibDir, fileFiltersStr,
|
||||
true, m_project->GetProjectPath() ) );
|
||||
aGrid->SetColAttr( COL_URI, attr );
|
||||
|
||||
@ -533,11 +564,32 @@ void PANEL_SYM_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
|
||||
|
||||
void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
|
||||
{
|
||||
wxString wildcards = AllSymbolLibFilesWildcard()
|
||||
+ "|" + KiCadSymbolLibFileWildcard()
|
||||
+ "|" + LegacySymbolLibFileWildcard()
|
||||
+ "|" + DatabaseLibFileWildcard()
|
||||
+ "|" + CadstarPartsLibraryFileWildcard();
|
||||
wxString fileFiltersStr;
|
||||
wxString allWildcardsStr;
|
||||
|
||||
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
||||
{
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
||||
|
||||
if( !pi )
|
||||
continue;
|
||||
|
||||
const PLUGIN_FILE_DESC& desc = pi->GetLibraryFileDesc();
|
||||
|
||||
if( desc.m_FileExtensions.empty() )
|
||||
continue;
|
||||
|
||||
if( !fileFiltersStr.IsEmpty() )
|
||||
fileFiltersStr += wxChar( '|' );
|
||||
|
||||
fileFiltersStr += desc.FileFilter();
|
||||
|
||||
for( const std::string& ext : desc.m_FileExtensions )
|
||||
allWildcardsStr << wxT( "*." ) << formatWildcardExt( ext ) << wxT( ";" );
|
||||
}
|
||||
|
||||
fileFiltersStr = _( "All supported formats" ) + wxT( "|" ) + allWildcardsStr + wxT( "|" )
|
||||
+ fileFiltersStr;
|
||||
|
||||
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
|
||||
|
||||
@ -546,7 +598,7 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
|
||||
if( m_cur_grid == m_project_grid )
|
||||
openDir = m_lastProjectLibDir;
|
||||
|
||||
wxFileDialog dlg( this, _( "Select Library" ), openDir, wxEmptyString, wildcards,
|
||||
wxFileDialog dlg( this, _( "Select Library" ), openDir, wxEmptyString, fileFiltersStr,
|
||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
|
||||
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
@ -595,6 +647,10 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
|
||||
|
||||
// attempt to auto-detect the plugin type
|
||||
SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::GuessPluginTypeFromLibPath( filePath );
|
||||
|
||||
if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
|
||||
pluginType = SCH_IO_MGR::SCH_KICAD;
|
||||
|
||||
m_cur_grid->SetCellValue( last_row, COL_TYPE, SCH_IO_MGR::ShowType( pluginType ) );
|
||||
|
||||
// try to use path normalized to an environmental variable or project path
|
||||
|
@ -82,7 +82,7 @@ static std::unique_ptr<SCHEMATIC> readSchematicFromFile( const std::string& aFil
|
||||
manager.LoadProject( "" );
|
||||
schematic->Reset();
|
||||
schematic->SetProject( &manager.Prj() );
|
||||
schematic->SetRoot( pi->Load( aFilename, schematic.get() ) );
|
||||
schematic->SetRoot( pi->LoadSchematicFile( aFilename, schematic.get() ) );
|
||||
schematic->CurrentSheet().push_back( &schematic->Root() );
|
||||
|
||||
SCH_SCREENS screens( schematic->Root() );
|
||||
|
@ -128,7 +128,7 @@ SCHEMATIC* EESCHEMA_HELPERS::LoadSchematic( wxString& aFileName, SCH_IO_MGR::SCH
|
||||
|
||||
try
|
||||
{
|
||||
schematic->SetRoot( pi->Load( aFileName, schematic ) );
|
||||
schematic->SetRoot( pi->LoadSchematicFile( aFileName, schematic ) );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
|
@ -240,7 +240,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||
{
|
||||
{
|
||||
wxBusyCursor busy;
|
||||
Schematic().SetRoot( pi->Load( fullFileName, &Schematic() ) );
|
||||
Schematic().SetRoot( pi->LoadSchematicFile( fullFileName, &Schematic() ) );
|
||||
}
|
||||
|
||||
if( !pi->GetError().IsEmpty() )
|
||||
@ -620,39 +620,37 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent )
|
||||
bool setProject = Prj().GetProjectFullName().IsEmpty() || Kiface().IsSingle();
|
||||
wxString path = wxPathOnly( Prj().GetProjectFullName() );
|
||||
|
||||
std::list<std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>> loaders;
|
||||
wxString fileFiltersStr;
|
||||
wxString allWildcardsStr;
|
||||
|
||||
// Import Altium schematic files.
|
||||
loaders.emplace_back( AltiumSchematicFileWildcard(), SCH_IO_MGR::SCH_ALTIUM );
|
||||
|
||||
// Import CADSTAR Schematic Archive files.
|
||||
loaders.emplace_back( CadstarSchematicArchiveFileWildcard(), SCH_IO_MGR::SCH_CADSTAR_ARCHIVE );
|
||||
|
||||
// Import Eagle schematic files.
|
||||
loaders.emplace_back( EagleSchematicFileWildcard(), SCH_IO_MGR::SCH_EAGLE );
|
||||
|
||||
// Import LTspice schematic files.
|
||||
loaders.emplace_back( LtspiceSchematicFileWildcard(), SCH_IO_MGR::SCH_LTSPICE );
|
||||
|
||||
wxString fileFilters;
|
||||
wxString allWildcards;
|
||||
|
||||
for( std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>& loader : loaders )
|
||||
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
||||
{
|
||||
if( !fileFilters.IsEmpty() )
|
||||
fileFilters += wxChar( '|' );
|
||||
if( fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY )
|
||||
continue; // this is "Import non-KiCad schematic"
|
||||
|
||||
fileFilters += wxGetTranslation( loader.first );
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
||||
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin( SCH_IO_MGR::FindPlugin( loader.second ) );
|
||||
wxCHECK( plugin, /*void*/ );
|
||||
allWildcards += wxS( "*." ) + formatWildcardExt( plugin->GetFileExtension() ) + wxS( ";" );
|
||||
if( !pi )
|
||||
continue;
|
||||
|
||||
const PLUGIN_FILE_DESC& desc = pi->GetSchematicFileDesc();
|
||||
|
||||
if( desc.m_FileExtensions.empty() )
|
||||
continue;
|
||||
|
||||
if( !fileFiltersStr.IsEmpty() )
|
||||
fileFiltersStr += wxChar( '|' );
|
||||
|
||||
fileFiltersStr += desc.FileFilter();
|
||||
|
||||
for( const std::string& ext : desc.m_FileExtensions )
|
||||
allWildcardsStr << wxT( "*." ) << formatWildcardExt( ext ) << wxT( ";" );
|
||||
}
|
||||
|
||||
fileFilters = _( "All supported formats" ) + wxS( "|" ) + allWildcards + wxS( "|" ) +
|
||||
fileFilters;
|
||||
fileFiltersStr = _( "All supported formats" ) + wxT( "|" ) + allWildcardsStr + wxT( "|" )
|
||||
+ fileFiltersStr;
|
||||
|
||||
wxFileDialog dlg( this, _( "Import Schematic" ), path, wxEmptyString, fileFilters,
|
||||
wxFileDialog dlg( this, _( "Import Schematic" ), path, wxEmptyString, fileFiltersStr,
|
||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST ); // TODO
|
||||
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
@ -683,18 +681,23 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent )
|
||||
|
||||
SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
|
||||
|
||||
for( std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>& loader : loaders )
|
||||
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
||||
{
|
||||
if( fn.GetExt().CmpNoCase( SCH_IO_MGR::GetFileExtension( loader.second ) ) == 0 )
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
||||
|
||||
if( !pi )
|
||||
continue;
|
||||
|
||||
if( pi->CanReadSchematicFile( fn.GetFullPath() ) )
|
||||
{
|
||||
pluginType = loader.second;
|
||||
pluginType = fileType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
|
||||
{
|
||||
wxLogError( _( "Unexpected file extension: '%s'." ), fn.GetExt() );
|
||||
wxLogError( _( "No loader can read the specified file: '%s'." ), fn.GetFullPath() );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -749,11 +752,15 @@ bool SCH_EDIT_FRAME::saveSchematicFile( SCH_SHEET* aSheet, const wxString& aSave
|
||||
|
||||
SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::GuessPluginTypeFromSchPath(
|
||||
schematicFileName.GetFullPath() );
|
||||
|
||||
if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
|
||||
pluginType = SCH_IO_MGR::SCH_KICAD;
|
||||
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) );
|
||||
|
||||
try
|
||||
{
|
||||
pi->Save( tempFile, aSheet, &Schematic() );
|
||||
pi->SaveSchematicFile( tempFile, aSheet, &Schematic() );
|
||||
success = true;
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
@ -1255,7 +1262,7 @@ void SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
|
||||
|
||||
pi->SetReporter( errorReporter.m_Reporter );
|
||||
pi->SetProgressReporter( &progressReporter );
|
||||
Schematic().SetRoot( pi->Load( aFileName, &Schematic() ) );
|
||||
Schematic().SetRoot( pi->LoadSchematicFile( aFileName, &Schematic() ) );
|
||||
|
||||
if( errorReporter.m_Reporter->HasMessage() )
|
||||
{
|
||||
|
@ -32,9 +32,11 @@
|
||||
#include <sch_plugins/cadstar/cadstar_sch_archive_plugin.h>
|
||||
#include <sch_plugins/database/sch_database_plugin.h>
|
||||
#include <sch_plugins/ltspice/ltspice_sch_plugin.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <common.h> // for ExpandEnvVarSubstitutions
|
||||
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <kiway_player.h>
|
||||
|
||||
#define FMT_UNIMPLEMENTED _( "Plugin \"%s\" does not implement the \"%s\" function." )
|
||||
#define FMT_NOTFOUND _( "Plugin type \"%s\" is not found." )
|
||||
|
||||
@ -59,12 +61,12 @@ SCH_PLUGIN* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType )
|
||||
|
||||
switch( aFileType )
|
||||
{
|
||||
case SCH_LEGACY: return new SCH_LEGACY_PLUGIN();
|
||||
case SCH_KICAD: return new SCH_SEXPR_PLUGIN();
|
||||
case SCH_LEGACY: return new SCH_LEGACY_PLUGIN();
|
||||
case SCH_ALTIUM: return new SCH_ALTIUM_PLUGIN();
|
||||
case SCH_CADSTAR_ARCHIVE: return new CADSTAR_SCH_ARCHIVE_PLUGIN();
|
||||
case SCH_EAGLE: return new SCH_EAGLE_PLUGIN();
|
||||
case SCH_DATABASE: return new SCH_DATABASE_PLUGIN();
|
||||
case SCH_EAGLE: return new SCH_EAGLE_PLUGIN();
|
||||
case SCH_LTSPICE: return new SCH_LTSPICE_PLUGIN();
|
||||
default: return nullptr;
|
||||
}
|
||||
@ -89,12 +91,12 @@ const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType )
|
||||
|
||||
switch( aType )
|
||||
{
|
||||
case SCH_LEGACY: return wxString( wxT( "Legacy" ) );
|
||||
case SCH_KICAD: return wxString( wxT( "KiCad" ) );
|
||||
case SCH_LEGACY: return wxString( wxT( "Legacy" ) );
|
||||
case SCH_ALTIUM: return wxString( wxT( "Altium" ) );
|
||||
case SCH_CADSTAR_ARCHIVE: return wxString( wxT( "CADSTAR Schematic Archive" ) );
|
||||
case SCH_EAGLE: return wxString( wxT( "EAGLE" ) );
|
||||
case SCH_DATABASE: return wxString( wxT( "Database" ) );
|
||||
case SCH_EAGLE: return wxString( wxT( "EAGLE" ) );
|
||||
case SCH_LTSPICE: return wxString( wxT( "LTspice" ) );
|
||||
default: return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ),
|
||||
aType );
|
||||
@ -108,114 +110,73 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr( const wxString& aType )
|
||||
// text spellings. If you change the spellings, you will obsolete
|
||||
// library tables, so don't do change, only additions are ok.
|
||||
|
||||
if( aType == wxT( "Legacy" ) )
|
||||
return SCH_LEGACY;
|
||||
else if( aType == wxT( "KiCad" ) )
|
||||
if( aType == wxT( "KiCad" ) )
|
||||
return SCH_KICAD;
|
||||
else if( aType == wxT( "Legacy" ) )
|
||||
return SCH_LEGACY;
|
||||
else if( aType == wxT( "Altium" ) )
|
||||
return SCH_ALTIUM;
|
||||
else if( aType == wxT( "CADSTAR Schematic Archive" ) )
|
||||
return SCH_CADSTAR_ARCHIVE;
|
||||
else if( aType == wxT( "EAGLE" ) )
|
||||
return SCH_EAGLE;
|
||||
else if( aType == wxT( "Database" ) )
|
||||
return SCH_DATABASE;
|
||||
else if( aType == wxT( "EAGLE" ) )
|
||||
return SCH_EAGLE;
|
||||
else if( aType == wxT( "LTspice" ) )
|
||||
return SCH_LTSPICE;
|
||||
|
||||
// wxASSERT( blow up here )
|
||||
|
||||
return SCH_FILE_T( -1 );
|
||||
return SCH_FILE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
const wxString SCH_IO_MGR::GetFileExtension( SCH_FILE_T aFileType )
|
||||
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath, int aCtl )
|
||||
{
|
||||
wxString ext = wxEmptyString;
|
||||
SCH_PLUGIN* plugin = FindPlugin( aFileType );
|
||||
|
||||
if( plugin != nullptr )
|
||||
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
||||
{
|
||||
ext = plugin->GetFileExtension();
|
||||
ReleasePlugin( plugin );
|
||||
bool isKiCad = fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY;
|
||||
|
||||
if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
|
||||
continue;
|
||||
|
||||
if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
|
||||
continue;
|
||||
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
||||
|
||||
if( !pi )
|
||||
continue;
|
||||
|
||||
if( pi->CanReadLibrary( aLibPath ) )
|
||||
return fileType;
|
||||
}
|
||||
|
||||
return ext;
|
||||
return SCH_IO_MGR::SCH_FILE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
const wxString SCH_IO_MGR::GetLibraryFileExtension( SCH_FILE_T aFileType )
|
||||
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromSchPath( const wxString& aSchematicPath,
|
||||
int aCtl )
|
||||
{
|
||||
wxString ext = wxEmptyString;
|
||||
SCH_PLUGIN* plugin = FindPlugin( aFileType );
|
||||
|
||||
if( plugin != nullptr )
|
||||
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
||||
{
|
||||
ext = plugin->GetLibraryFileExtension();
|
||||
ReleasePlugin( plugin );
|
||||
bool isKiCad = fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY;
|
||||
|
||||
if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
|
||||
continue;
|
||||
|
||||
if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
|
||||
continue;
|
||||
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
||||
|
||||
if( !pi )
|
||||
continue;
|
||||
|
||||
if( pi->CanReadSchematicFile( aSchematicPath ) )
|
||||
return fileType;
|
||||
}
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
||||
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath )
|
||||
{
|
||||
SCH_FILE_T ret = SCH_KICAD; // default guess, unless detected otherwise.
|
||||
wxFileName fn( aLibPath );
|
||||
wxString ext = fn.GetExt().Lower();
|
||||
|
||||
// .lib is shared between CADSTAR and Legacy KiCad file formats. Let's read the header
|
||||
if( ext == LegacySymbolLibFileExtension )
|
||||
{
|
||||
wxString fullName = ExpandEnvVarSubstitutions( aLibPath, nullptr );
|
||||
|
||||
// Of course the file should exist to be read. If not, use the SCH_LEGACY
|
||||
// format: it is more usual than SCH_CADSTAR_ARCHIVE
|
||||
if( !wxFileExists( fullName ) )
|
||||
return SCH_LEGACY;
|
||||
|
||||
for( SCH_FILE_T pluginType : { SCH_LEGACY, SCH_CADSTAR_ARCHIVE } )
|
||||
{
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) );
|
||||
|
||||
if( pi )
|
||||
{
|
||||
if( pi->CheckHeader( fullName ) )
|
||||
return pluginType;
|
||||
}
|
||||
}
|
||||
|
||||
// If not found, use the SCH_LEGACY.
|
||||
return SCH_LEGACY;
|
||||
}
|
||||
|
||||
for( SCH_IO_MGR::SCH_FILE_T piType : SCH_IO_MGR::SCH_FILE_T_vector )
|
||||
{
|
||||
if( SCH_IO_MGR::GetLibraryFileExtension( piType ).Lower() == ext )
|
||||
{
|
||||
ret = piType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromSchPath( const wxString& aSchematicPath )
|
||||
{
|
||||
SCH_FILE_T ret = SCH_KICAD; // default guess, unless detected otherwise.
|
||||
wxFileName fn( aSchematicPath );
|
||||
|
||||
if( fn.GetExt() == LegacySchematicFileExtension )
|
||||
{
|
||||
ret = SCH_LEGACY;
|
||||
}
|
||||
else if( fn.GetExt() == KiCadSchematicFileExtension )
|
||||
{
|
||||
ret = SCH_KICAD;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return SCH_IO_MGR::SCH_FILE_UNKNOWN;
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
#ifndef _SCH_IO_MGR_H_
|
||||
#define _SCH_IO_MGR_H_
|
||||
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
@ -23,11 +20,16 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SCH_IO_MGR_H_
|
||||
#define _SCH_IO_MGR_H_
|
||||
|
||||
#include <richio.h>
|
||||
#include <import_export.h>
|
||||
#include <map>
|
||||
#include <enum_vector.h>
|
||||
#include <reporter.h>
|
||||
#include <i18n_utility.h>
|
||||
#include <plugin_file_desc.h>
|
||||
|
||||
|
||||
class SCH_SHEET;
|
||||
@ -56,8 +58,8 @@ public:
|
||||
// clang-format off
|
||||
DEFINE_ENUM_VECTOR( SCH_FILE_T,
|
||||
{
|
||||
SCH_LEGACY, ///< Legacy Eeschema file formats prior to s-expression.
|
||||
SCH_KICAD, ///< The s-expression version of the schematic.
|
||||
SCH_LEGACY, ///< Legacy Eeschema file formats prior to s-expression.
|
||||
SCH_ALTIUM, ///< Altium file format
|
||||
SCH_CADSTAR_ARCHIVE, ///< CADSTAR Schematic Archive
|
||||
SCH_DATABASE, ///< KiCad database library
|
||||
@ -103,40 +105,22 @@ public:
|
||||
*/
|
||||
static SCH_FILE_T EnumFromStr( const wxString& aFileType );
|
||||
|
||||
/**
|
||||
* Return the schematic file extension for \a aFileType.
|
||||
*
|
||||
* @param aFileType is the #SCH_FILE_T type.
|
||||
*
|
||||
* @return the file extension for \a aFileType or an empty string if \a aFileType is invalid.
|
||||
*/
|
||||
static const wxString GetFileExtension( SCH_FILE_T aFileType );
|
||||
|
||||
/**
|
||||
* Return the symbol library file extension (if any) for \a aFileType.
|
||||
*
|
||||
* @param aFileType is the #SCH_FILE_T type.
|
||||
*
|
||||
* @return the file extension for \a aFileType or an empty string if \a aFileType is invalid.
|
||||
*/
|
||||
static const wxString GetLibraryFileExtension( SCH_FILE_T aFileType );
|
||||
|
||||
/**
|
||||
* Return a plugin type given a symbol library using the file extension of \a aLibPath.
|
||||
*/
|
||||
static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
|
||||
static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath, int aCtl = 0 );
|
||||
|
||||
/**
|
||||
* Return a plugin type given a schematic using the file extension of \a aSchematicPath.
|
||||
*/
|
||||
static SCH_FILE_T GuessPluginTypeFromSchPath( const wxString& aSchematicPath );
|
||||
static SCH_FILE_T GuessPluginTypeFromSchPath( const wxString& aSchematicPath, int aCtl = 0 );
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Base class that schematic file and library loading and saving plugins should derive from.
|
||||
* Implementations can provide either Load() or Save() functions, or both.
|
||||
* SCH_PLUGINs throw exceptions, so it is best that you wrap your calls to these
|
||||
* Implementations can provide either LoadSchematicFile() or SaveSchematicFile() functions,
|
||||
* or both. SCH_PLUGINs throw exceptions, so it is best that you wrap your calls to these
|
||||
* functions in a try catch block. Plugins throw exceptions because it is illegal
|
||||
* for them to have any user interface calls in them whatsoever, i.e. no windowing
|
||||
* or screen printing at all.
|
||||
@ -144,9 +128,9 @@ public:
|
||||
* <pre>
|
||||
* try
|
||||
* {
|
||||
* SCH_IO_MGR::Load(...);
|
||||
* SCH_IO_MGR::LoadSchematicFile(...);
|
||||
* or
|
||||
* SCH_IO_MGR::Save(...);
|
||||
* SCH_IO_MGR::SaveSchematicFile(...);
|
||||
* }
|
||||
* catch( const IO_ERROR& ioe )
|
||||
* {
|
||||
@ -176,14 +160,26 @@ public:
|
||||
virtual void SetProgressReporter( PROGRESS_REPORTER* aReporter ) {}
|
||||
|
||||
/**
|
||||
* Return the file extension for the #SCH_PLUGIN.
|
||||
* Returns schematic file description for the #SCH_PLUGIN.
|
||||
*/
|
||||
virtual const wxString GetFileExtension() const = 0;
|
||||
virtual const PLUGIN_FILE_DESC GetSchematicFileDesc() const;
|
||||
|
||||
/**
|
||||
* Return the library file extension for the #SCH_PLUGIN object.
|
||||
* Returns symbol library description for the #SCH_PLUGIN.
|
||||
*/
|
||||
virtual const wxString GetLibraryFileExtension() const = 0;
|
||||
virtual const PLUGIN_FILE_DESC GetLibraryFileDesc() const;
|
||||
|
||||
/**
|
||||
* Checks if this SCH_PLUGIN can read the specified schematic file.
|
||||
* If not overriden, extension check is used.
|
||||
*/
|
||||
virtual bool CanReadSchematicFile( const wxString& aFileName ) const;
|
||||
|
||||
/**
|
||||
* Checks if this SCH_PLUGIN can read the specified symbol library file.
|
||||
* If not overriden, extension check is used.
|
||||
*/
|
||||
virtual bool CanReadLibrary( const wxString& aFileName ) const;
|
||||
|
||||
/**
|
||||
* Return the modification hash from the library cache.
|
||||
@ -226,9 +222,9 @@ public:
|
||||
* wrong, using line number and character offsets of the input file if
|
||||
* possible.
|
||||
*/
|
||||
virtual SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr );
|
||||
virtual SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr );
|
||||
|
||||
/**
|
||||
* Write \a aSchematic to a storage file in a format that this #SCH_PLUGIN implementation
|
||||
@ -255,8 +251,9 @@ public:
|
||||
*
|
||||
* @throw IO_ERROR if there is a problem saving or exporting.
|
||||
*/
|
||||
virtual void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr );
|
||||
virtual void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet,
|
||||
SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr );
|
||||
|
||||
/**
|
||||
* Populate a list of #LIB_SYMBOL alias names contained within the library \a aLibraryPath.
|
||||
@ -493,14 +490,6 @@ public:
|
||||
return GetAvailableSymbolFields( aNames );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the first line in @a aFileName begins with the expected header.
|
||||
*
|
||||
* @param aFileName is the name of the file to use as input
|
||||
*
|
||||
*/
|
||||
virtual bool CheckHeader( const wxString& aFileName );
|
||||
|
||||
/**
|
||||
* Return an error string to the caller.
|
||||
*
|
||||
@ -579,6 +568,13 @@ public:
|
||||
return plugin;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
static bool fileStartsWithPrefix( const wxString& aFilePath, const wxString& aPrefix,
|
||||
bool aIgnoreWhitespace );
|
||||
|
||||
static bool fileStartsWithBinaryHeader( const wxString& aFilePath,
|
||||
const std::vector<uint8_t>& aHeader );
|
||||
};
|
||||
|
||||
#endif // _SCH_IO_MGR_H_
|
||||
|
@ -2,7 +2,7 @@
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 CERN
|
||||
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* @author Wayne Stambaugh <stambaughw@gmail.com>
|
||||
*
|
||||
@ -21,9 +21,14 @@
|
||||
*/
|
||||
|
||||
#include <string_utf8_map.h>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <sch_io_mgr.h>
|
||||
#include <wx/translation.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/txtstrm.h>
|
||||
|
||||
#define FMT_UNIMPLEMENTED wxT( "Plugin \"%s\" does not implement the \"%s\" function." )
|
||||
#define NOT_IMPLEMENTED( aCaller ) \
|
||||
@ -32,21 +37,100 @@
|
||||
wxString::FromUTF8( aCaller ).GetData() ) );
|
||||
|
||||
|
||||
const PLUGIN_FILE_DESC SCH_PLUGIN::GetSchematicFileDesc() const
|
||||
{
|
||||
return PLUGIN_FILE_DESC( wxEmptyString, {} );
|
||||
}
|
||||
|
||||
|
||||
const PLUGIN_FILE_DESC SCH_PLUGIN::GetLibraryFileDesc() const
|
||||
{
|
||||
return PLUGIN_FILE_DESC( wxEmptyString, {} );
|
||||
}
|
||||
|
||||
|
||||
bool SCH_PLUGIN::CanReadSchematicFile( const wxString& aFileName ) const
|
||||
{
|
||||
const std::vector<std::string>& exts = GetSchematicFileDesc().m_FileExtensions;
|
||||
|
||||
wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
|
||||
|
||||
for( const std::string& ext : exts )
|
||||
{
|
||||
if( fileExt == wxString( ext ).Lower() )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_PLUGIN::CanReadLibrary( const wxString& aFileName ) const
|
||||
{
|
||||
const PLUGIN_FILE_DESC& desc = GetLibraryFileDesc();
|
||||
|
||||
if( desc.m_IsFile )
|
||||
{
|
||||
const std::vector<std::string>& exts = desc.m_FileExtensions;
|
||||
|
||||
wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
|
||||
|
||||
for( const std::string& ext : exts )
|
||||
{
|
||||
if( fileExt == wxString( ext ).Lower() )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wxDir dir( aFileName );
|
||||
|
||||
if( !dir.IsOpened() )
|
||||
return false;
|
||||
|
||||
std::vector<std::string> exts = desc.m_ExtensionsInDir;
|
||||
std::unordered_set<wxString> lowerExts;
|
||||
|
||||
for( const std::string& ext : exts )
|
||||
lowerExts.emplace( wxString( ext ).MakeLower() );
|
||||
|
||||
wxString filenameStr;
|
||||
|
||||
bool cont = dir.GetFirst( &filenameStr, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN );
|
||||
while( cont )
|
||||
{
|
||||
wxString ext = wxS( "" );
|
||||
|
||||
int idx = filenameStr.Find( '.', true );
|
||||
if( idx != -1 )
|
||||
ext = filenameStr.Mid( idx + 1 ).MakeLower();
|
||||
|
||||
if( lowerExts.count( ext ) )
|
||||
return true;
|
||||
|
||||
cont = dir.GetNext( &filenameStr );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void SCH_PLUGIN::SaveLibrary( const wxString& aFileName, const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
NOT_IMPLEMENTED( __FUNCTION__ );
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
||||
SCH_SHEET* SCH_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
NOT_IMPLEMENTED( __FUNCTION__ );
|
||||
}
|
||||
|
||||
|
||||
void SCH_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
void SCH_PLUGIN::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
|
||||
NOT_IMPLEMENTED( __FUNCTION__ );
|
||||
@ -128,15 +212,54 @@ void SCH_PLUGIN::SymbolLibOptions( STRING_UTF8_MAP* aListToAppendTo ) const
|
||||
}
|
||||
|
||||
|
||||
bool SCH_PLUGIN::CheckHeader( const wxString& aFileName )
|
||||
{
|
||||
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
|
||||
NOT_IMPLEMENTED( __FUNCTION__ );
|
||||
}
|
||||
|
||||
|
||||
const wxString& SCH_PLUGIN::GetError() const
|
||||
{
|
||||
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
|
||||
NOT_IMPLEMENTED( __FUNCTION__ );
|
||||
}
|
||||
|
||||
|
||||
bool SCH_PLUGIN::fileStartsWithPrefix( const wxString& aFilePath, const wxString& aPrefix,
|
||||
bool aIgnoreWhitespace )
|
||||
{
|
||||
wxFFileInputStream input( aFilePath );
|
||||
|
||||
if( input.IsOk() && !input.Eof() )
|
||||
{
|
||||
// Find first non-empty line
|
||||
wxTextInputStream text( input );
|
||||
wxString line = text.ReadLine();
|
||||
|
||||
if( aIgnoreWhitespace )
|
||||
{
|
||||
while( line.IsEmpty() )
|
||||
line = text.ReadLine().Trim( false /*trim from left*/ );
|
||||
}
|
||||
|
||||
if( line.StartsWith( aPrefix ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_PLUGIN::fileStartsWithBinaryHeader( const wxString& aFilePath,
|
||||
const std::vector<uint8_t>& aHeader )
|
||||
{
|
||||
wxFFileInputStream input( aFilePath );
|
||||
|
||||
if( input.IsOk() && !input.Eof() )
|
||||
{
|
||||
if( input.GetLength() < aHeader.size() )
|
||||
return false;
|
||||
|
||||
std::vector<uint8_t> parsedHeader( aHeader.size() );
|
||||
if( !input.ReadAll( parsedHeader.data(), parsedHeader.size() ) )
|
||||
return false;
|
||||
|
||||
return parsedHeader == aHeader;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -160,32 +160,12 @@ const wxString SCH_ALTIUM_PLUGIN::GetName() const
|
||||
}
|
||||
|
||||
|
||||
const wxString SCH_ALTIUM_PLUGIN::GetFileExtension() const
|
||||
{
|
||||
return "SchDoc";
|
||||
}
|
||||
|
||||
|
||||
const wxString SCH_ALTIUM_PLUGIN::GetLibraryFileExtension() const
|
||||
{
|
||||
return "SchLib";
|
||||
}
|
||||
|
||||
|
||||
int SCH_ALTIUM_PLUGIN::GetModifyHash() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_ALTIUM_PLUGIN::CheckHeader( const wxString& aFileName )
|
||||
{
|
||||
// TODO
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
wxString SCH_ALTIUM_PLUGIN::getLibName()
|
||||
{
|
||||
if( m_libName.IsEmpty() )
|
||||
@ -218,8 +198,9 @@ wxFileName SCH_ALTIUM_PLUGIN::getLibFileName()
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_ALTIUM_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
||||
SCH_SHEET* SCH_ALTIUM_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
wxCHECK( !aFileName.IsEmpty() && aSchematic, nullptr );
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
|
||||
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2021-2023 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
|
||||
@ -55,17 +55,21 @@ public:
|
||||
|
||||
void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; }
|
||||
|
||||
const wxString GetFileExtension() const override;
|
||||
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
|
||||
{
|
||||
return PLUGIN_FILE_DESC( _HKI( "Altium schematic files" ), { "SchDoc" } );
|
||||
}
|
||||
|
||||
const wxString GetLibraryFileExtension() const override;
|
||||
/*const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
|
||||
{
|
||||
return PLUGIN_FILE_DESC( _HKI( "Altium schematic library files" ), { "SchLib" } );
|
||||
}*/
|
||||
|
||||
int GetModifyHash() const override;
|
||||
|
||||
SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
bool CheckHeader( const wxString& aFileName ) override;
|
||||
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
// unimplemented functions. Will trigger a not_implemented IO error.
|
||||
//void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2020 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
|
||||
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2020-2023 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 as published by the
|
||||
@ -44,26 +44,16 @@ const wxString CADSTAR_SCH_ARCHIVE_PLUGIN::GetName() const
|
||||
}
|
||||
|
||||
|
||||
const wxString CADSTAR_SCH_ARCHIVE_PLUGIN::GetFileExtension() const
|
||||
{
|
||||
return CadstarSchematicFileExtension;
|
||||
}
|
||||
|
||||
|
||||
const wxString CADSTAR_SCH_ARCHIVE_PLUGIN::GetLibraryFileExtension() const
|
||||
{
|
||||
return CadstarPartsLibraryFileExtension;
|
||||
}
|
||||
|
||||
|
||||
int CADSTAR_SCH_ARCHIVE_PLUGIN::GetModifyHash() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
||||
SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::LoadSchematicFile( const wxString& aFileName,
|
||||
SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
wxCHECK( !aFileName.IsEmpty() && aSchematic, nullptr );
|
||||
|
||||
@ -174,14 +164,6 @@ SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::Load( const wxString& aFileName, SCHEMATI
|
||||
}
|
||||
|
||||
|
||||
bool CADSTAR_SCH_ARCHIVE_PLUGIN::CheckHeader( const wxString& aFileName )
|
||||
{
|
||||
// TODO: write a parser for the cpa header. For now assume it is valid
|
||||
// and throw exceptions when parsing
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CADSTAR_SCH_ARCHIVE_PLUGIN::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
|
||||
const wxString& aLibraryPath,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <sch_io_mgr.h>
|
||||
#include <reporter.h>
|
||||
#include <lib_symbol.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
|
||||
|
||||
class SCH_SHEET;
|
||||
@ -57,17 +58,23 @@ public:
|
||||
m_progressReporter = aReporter;
|
||||
}
|
||||
|
||||
const wxString GetFileExtension() const override;
|
||||
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
|
||||
{
|
||||
return PLUGIN_FILE_DESC( _HKI( "CADSTAR Schematic Archive files" ),
|
||||
{ CadstarSchematicFileExtension } );
|
||||
}
|
||||
|
||||
const wxString GetLibraryFileExtension() const override;
|
||||
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
|
||||
{
|
||||
return PLUGIN_FILE_DESC( _HKI( "CADSTAR Parts Library files" ),
|
||||
{ CadstarPartsLibraryFileExtension } );
|
||||
}
|
||||
|
||||
int GetModifyHash() const override;
|
||||
|
||||
SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
bool CheckHeader( const wxString& aFileName ) override;
|
||||
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
|
||||
const wxString& aLibraryPath,
|
||||
|
@ -207,13 +207,6 @@ void SCH_DATABASE_PLUGIN::GetDefaultSymbolFields( std::vector<wxString>& aNames
|
||||
}
|
||||
|
||||
|
||||
bool SCH_DATABASE_PLUGIN::CheckHeader( const wxString& aFileName )
|
||||
{
|
||||
// TODO: Implement this sometime; but CheckHeader isn't even called...
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_DATABASE_PLUGIN::TestConnection( wxString* aErrorMsg )
|
||||
{
|
||||
if( m_conn && m_conn->IsConnected() )
|
||||
|
@ -2,7 +2,7 @@
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 Jon Evans <jon@craftyjon.com>
|
||||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2022-2023 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 as published by the
|
||||
@ -49,15 +49,10 @@ public:
|
||||
return wxT( "Database library" );
|
||||
}
|
||||
|
||||
const wxString GetLibraryFileExtension() const override
|
||||
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
|
||||
{
|
||||
return DatabaseLibraryFileExtension;
|
||||
}
|
||||
|
||||
const wxString GetFileExtension() const override
|
||||
{
|
||||
wxFAIL_MSG( "Database libraries are not schematic files! Fix call site." );
|
||||
return DatabaseLibraryFileExtension;
|
||||
return PLUGIN_FILE_DESC( _HKI( "KiCad database library files" ),
|
||||
{ DatabaseLibraryFileExtension } );
|
||||
}
|
||||
|
||||
int GetModifyHash() const override { return 0; }
|
||||
@ -81,8 +76,6 @@ public:
|
||||
|
||||
void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
|
||||
|
||||
bool CheckHeader( const wxString& aFileName ) override;
|
||||
|
||||
// Database libraries can never be written using the symbol editing API
|
||||
bool IsSymbolLibWritable( const wxString& aLibraryPath ) override
|
||||
{
|
||||
|
@ -375,18 +375,6 @@ const wxString SCH_EAGLE_PLUGIN::GetName() const
|
||||
}
|
||||
|
||||
|
||||
const wxString SCH_EAGLE_PLUGIN::GetFileExtension() const
|
||||
{
|
||||
return wxT( "sch" );
|
||||
}
|
||||
|
||||
|
||||
const wxString SCH_EAGLE_PLUGIN::GetLibraryFileExtension() const
|
||||
{
|
||||
return wxT( "lbr" );
|
||||
}
|
||||
|
||||
|
||||
int SCH_EAGLE_PLUGIN::GetModifyHash() const
|
||||
{
|
||||
return 0;
|
||||
@ -413,8 +401,9 @@ void SCH_EAGLE_PLUGIN::checkpoint()
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
||||
SCH_SHEET* SCH_EAGLE_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
wxASSERT( !aFileName || aSchematic != nullptr );
|
||||
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
||||
@ -2724,23 +2713,43 @@ void SCH_EAGLE_PLUGIN::adjustNetLabels()
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EAGLE_PLUGIN::CheckHeader( const wxString& aFileName )
|
||||
bool SCH_EAGLE_PLUGIN::CanReadSchematicFile( const wxString& aFileName ) const
|
||||
{
|
||||
// Open file and check first line
|
||||
wxTextFile tempFile;
|
||||
if( !SCH_PLUGIN::CanReadSchematicFile( aFileName ) )
|
||||
return false;
|
||||
|
||||
tempFile.Open( aFileName );
|
||||
wxString firstline;
|
||||
return checkHeader( aFileName );
|
||||
}
|
||||
|
||||
// read the first line
|
||||
firstline = tempFile.GetFirstLine();
|
||||
wxString secondline = tempFile.GetNextLine();
|
||||
wxString thirdline = tempFile.GetNextLine();
|
||||
tempFile.Close();
|
||||
|
||||
return firstline.StartsWith( wxT( "<?xml" ) )
|
||||
&& secondline.StartsWith( wxT( "<!DOCTYPE eagle SYSTEM" ) )
|
||||
&& thirdline.StartsWith( wxT( "<eagle version" ) );
|
||||
bool SCH_EAGLE_PLUGIN::CanReadLibrary( const wxString& aFileName ) const
|
||||
{
|
||||
if( !SCH_PLUGIN::CanReadLibrary( aFileName ) )
|
||||
return false;
|
||||
|
||||
return checkHeader( aFileName );
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EAGLE_PLUGIN::checkHeader( const wxString& aFileName ) const
|
||||
{
|
||||
wxFileInputStream input( aFileName );
|
||||
|
||||
if( !input.IsOk() )
|
||||
return false;
|
||||
|
||||
wxTextInputStream text( input );
|
||||
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
if( input.Eof() )
|
||||
return false;
|
||||
|
||||
if( text.ReadLine().Contains( wxS( "<!DOCTYPE eagle" ) ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2017 CERN
|
||||
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
@ -95,21 +95,30 @@ public:
|
||||
m_progressReporter = aReporter;
|
||||
}
|
||||
|
||||
const wxString GetFileExtension() const override;
|
||||
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
|
||||
{
|
||||
return PLUGIN_FILE_DESC( _HKI( "Eagle XML schematic files" ), { "sch" } );
|
||||
}
|
||||
|
||||
const wxString GetLibraryFileExtension() const override;
|
||||
/*const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
|
||||
{
|
||||
return PLUGIN_FILE_DESC( _HKI( "Eagle XML library files" ), { "lbr" } );
|
||||
}*/
|
||||
|
||||
bool CanReadSchematicFile( const wxString& aFileName ) const override;
|
||||
bool CanReadLibrary( const wxString& aFileName ) const override;
|
||||
|
||||
int GetModifyHash() const override;
|
||||
|
||||
SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
bool CheckHeader( const wxString& aFileName ) override;
|
||||
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
private:
|
||||
void checkpoint();
|
||||
|
||||
bool checkHeader( const wxString& aFileName ) const;
|
||||
|
||||
void loadDrawing( wxXmlNode* aDrawingNode );
|
||||
void loadLayerDefs( wxXmlNode* aLayers );
|
||||
void loadSchematic( wxXmlNode* aSchematicNode );
|
||||
|
@ -97,8 +97,9 @@ void SCH_SEXPR_PLUGIN::init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProp
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_SEXPR_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
||||
SCH_SHEET* SCH_SEXPR_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
wxASSERT( !aFileName || aSchematic != nullptr );
|
||||
|
||||
@ -328,8 +329,9 @@ void SCH_SEXPR_PLUGIN::LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet, int
|
||||
}
|
||||
|
||||
|
||||
void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
void SCH_SEXPR_PLUGIN::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet,
|
||||
SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
|
||||
wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
|
||||
@ -1613,21 +1615,6 @@ void SCH_SEXPR_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const STRING_U
|
||||
}
|
||||
|
||||
|
||||
bool SCH_SEXPR_PLUGIN::CheckHeader( const wxString& aFileName )
|
||||
{
|
||||
// Open file and check first line
|
||||
wxTextFile tempFile;
|
||||
|
||||
tempFile.Open( aFileName );
|
||||
wxString firstline;
|
||||
// read the first line
|
||||
firstline = tempFile.GetFirstLine();
|
||||
tempFile.Close();
|
||||
|
||||
return firstline.StartsWith( wxS( "EESchema" ) );
|
||||
}
|
||||
|
||||
|
||||
bool SCH_SEXPR_PLUGIN::IsSymbolLibWritable( const wxString& aLibraryPath )
|
||||
{
|
||||
wxFileName fn( aLibraryPath );
|
||||
|
@ -1,6 +1,3 @@
|
||||
#ifndef _SCH_SEXPR_PLUGIN_H_
|
||||
#define _SCH_SEXPR_PLUGIN_H_
|
||||
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
@ -23,11 +20,15 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SCH_SEXPR_PLUGIN_H_
|
||||
#define _SCH_SEXPR_PLUGIN_H_
|
||||
|
||||
#include <memory>
|
||||
#include <sch_io_mgr.h>
|
||||
#include <sch_file_versions.h>
|
||||
#include <sch_sheet_path.h>
|
||||
#include <stack>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
|
||||
|
||||
class KIWAY;
|
||||
@ -71,14 +72,16 @@ public:
|
||||
return wxT( "Eeschema s-expression" );
|
||||
}
|
||||
|
||||
const wxString GetFileExtension() const override
|
||||
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
|
||||
{
|
||||
return wxT( "kicad_sch" );
|
||||
return PLUGIN_FILE_DESC( _HKI( "KiCad s-expression schematic files" ),
|
||||
{ KiCadSchematicFileExtension } );
|
||||
}
|
||||
|
||||
const wxString GetLibraryFileExtension() const override
|
||||
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
|
||||
{
|
||||
return wxT( "kicad_sym" );
|
||||
return PLUGIN_FILE_DESC( _HKI( "KiCad symbol library files" ),
|
||||
{ KiCadSymbolLibFileExtension } );
|
||||
}
|
||||
|
||||
void SetProgressReporter( PROGRESS_REPORTER* aReporter ) override
|
||||
@ -95,15 +98,15 @@ public:
|
||||
|
||||
int GetModifyHash() const override;
|
||||
|
||||
SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
void LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet,
|
||||
int aVersion = SEXPR_SCHEMATIC_FILE_VERSION );
|
||||
|
||||
void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
void Format( SCH_SHEET* aSheet );
|
||||
|
||||
@ -129,7 +132,6 @@ public:
|
||||
void SaveLibrary( const wxString& aLibraryPath,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
bool CheckHeader( const wxString& aFileName ) override;
|
||||
bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
|
||||
|
||||
void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
|
||||
|
@ -121,8 +121,9 @@ void SCH_LEGACY_PLUGIN::checkpoint()
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
||||
SCH_SHEET* SCH_LEGACY_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
wxASSERT( !aFileName || aSchematic != nullptr );
|
||||
|
||||
@ -1450,8 +1451,9 @@ std::shared_ptr<BUS_ALIAS> SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader
|
||||
}
|
||||
|
||||
|
||||
void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
void SCH_LEGACY_PLUGIN::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet,
|
||||
SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
|
||||
wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
|
||||
@ -2231,18 +2233,21 @@ void SCH_LEGACY_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const STRING_
|
||||
}
|
||||
|
||||
|
||||
bool SCH_LEGACY_PLUGIN::CheckHeader( const wxString& aFileName )
|
||||
bool SCH_LEGACY_PLUGIN::CanReadSchematicFile( const wxString& aFileName ) const
|
||||
{
|
||||
// Open file and check first line
|
||||
wxTextFile tempFile;
|
||||
if( !SCH_PLUGIN::CanReadSchematicFile( aFileName ) )
|
||||
return false;
|
||||
|
||||
tempFile.Open( aFileName );
|
||||
wxString firstline;
|
||||
// read the first line
|
||||
firstline = tempFile.GetFirstLine();
|
||||
tempFile.Close();
|
||||
return fileStartsWithPrefix( aFileName, wxT( "EESchema" ), true );
|
||||
}
|
||||
|
||||
return firstline.StartsWith( wxS( "EESchema" ) );
|
||||
|
||||
bool SCH_LEGACY_PLUGIN::CanReadLibrary( const wxString& aFileName ) const
|
||||
{
|
||||
if( !SCH_PLUGIN::CanReadLibrary( aFileName ) )
|
||||
return false;
|
||||
|
||||
return fileStartsWithPrefix( aFileName, wxT( "EESchema" ), true );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,11 +1,8 @@
|
||||
#ifndef _SCH_LEGACY_PLUGIN_H_
|
||||
#define _SCH_LEGACY_PLUGIN_H_
|
||||
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 CERN
|
||||
* Copyright (C) 2016-2022 KiCad Developers, see change_log.txt for contributors.
|
||||
* Copyright (C) 2016-2023 KiCad Developers, see change_log.txt for contributors.
|
||||
*
|
||||
* @author Wayne Stambaugh <stambaughw@gmail.com>
|
||||
*
|
||||
@ -23,10 +20,14 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SCH_LEGACY_PLUGIN_H_
|
||||
#define _SCH_LEGACY_PLUGIN_H_
|
||||
|
||||
#include <memory>
|
||||
#include <sch_io_mgr.h>
|
||||
#include <stack>
|
||||
#include <general.h> // for EESCHEMA_VERSION definition
|
||||
#include <wildcards_and_files_ext.h>
|
||||
|
||||
|
||||
class KIWAY;
|
||||
@ -72,16 +73,22 @@ public:
|
||||
return wxT( "Eeschema-Legacy" );
|
||||
}
|
||||
|
||||
const wxString GetFileExtension() const override
|
||||
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
|
||||
{
|
||||
return wxT( "sch" );
|
||||
return PLUGIN_FILE_DESC( _HKI( "KiCad legacy schematic files" ),
|
||||
{ LegacySchematicFileExtension } );
|
||||
}
|
||||
|
||||
const wxString GetLibraryFileExtension() const override
|
||||
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
|
||||
{
|
||||
return wxT( "lib" );
|
||||
return PLUGIN_FILE_DESC( _HKI( "KiCad legacy symbol library files" ),
|
||||
{ LegacySymbolLibFileExtension } );
|
||||
}
|
||||
|
||||
bool CanReadSchematicFile( const wxString& aFileName ) const override;
|
||||
|
||||
bool CanReadLibrary( const wxString& aFileName ) const override;
|
||||
|
||||
void SetProgressReporter( PROGRESS_REPORTER* aReporter ) override
|
||||
{
|
||||
m_progressReporter = aReporter;
|
||||
@ -102,15 +109,15 @@ public:
|
||||
|
||||
int GetModifyHash() const override;
|
||||
|
||||
SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
|
||||
int version = EESCHEMA_VERSION );
|
||||
|
||||
void Save( const wxString& aFileName, SCH_SHEET* aScreen, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aScreen, SCHEMATIC* aSchematic,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
void Format( SCH_SHEET* aSheet );
|
||||
|
||||
@ -134,8 +141,7 @@ public:
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
void SaveLibrary( const wxString& aLibraryPath,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
bool CheckHeader( const wxString& aFileName ) override;
|
||||
|
||||
bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
|
||||
|
||||
const wxString& GetError() const override { return m_error; }
|
||||
|
@ -38,26 +38,15 @@ const wxString SCH_LTSPICE_PLUGIN::GetName() const
|
||||
}
|
||||
|
||||
|
||||
const wxString SCH_LTSPICE_PLUGIN::GetFileExtension() const
|
||||
{
|
||||
return wxT( "asc" );
|
||||
}
|
||||
|
||||
|
||||
const wxString SCH_LTSPICE_PLUGIN::GetLibraryFileExtension() const
|
||||
{
|
||||
return wxT( "lib" );
|
||||
}
|
||||
|
||||
|
||||
int SCH_LTSPICE_PLUGIN::GetModifyHash() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_LTSPICE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
||||
SCH_SHEET* SCH_LTSPICE_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties )
|
||||
{
|
||||
wxASSERT( !aFileName || aSchematic );
|
||||
|
||||
@ -125,9 +114,3 @@ SCH_SHEET* SCH_LTSPICE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSche
|
||||
|
||||
return rootSheet;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_LTSPICE_PLUGIN::CheckHeader( const wxString& aFileName )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -53,17 +53,21 @@ public:
|
||||
m_progressReporter = aReporter;
|
||||
}
|
||||
|
||||
const wxString GetFileExtension() const override;
|
||||
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
|
||||
{
|
||||
return PLUGIN_FILE_DESC( _HKI( "LTspice schematic files" ), { "asc" } );
|
||||
}
|
||||
|
||||
const wxString GetLibraryFileExtension() const override;
|
||||
/*const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
|
||||
{
|
||||
return PLUGIN_FILE_DESC( _HKI( "LTspice library files" ), { "lib" } );
|
||||
}*/
|
||||
|
||||
int GetModifyHash() const override;
|
||||
|
||||
SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
bool CheckHeader( const wxString& aFileName ) override;
|
||||
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
private:
|
||||
REPORTER* m_reporter; // current reporter for warnings/errors
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user