2011-11-11 20:10:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-06-07 15:33:12 +00:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-10-06 18:07:43 +00:00
|
|
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
2018-08-23 11:48:14 +00:00
|
|
|
* Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-11 20:10:24 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
2018-08-23 11:48:14 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_library.h>
|
2012-09-28 17:47:41 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2017-10-31 11:13:20 +00:00
|
|
|
#include <eeschema_id.h>
|
2017-11-12 17:55:20 +00:00
|
|
|
#include <lib_manager.h>
|
2009-04-05 20:49:15 +00:00
|
|
|
#include <wx/filename.h>
|
|
|
|
|
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::OnImportPart( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
wxString msg;
|
2009-09-25 18:49:04 +00:00
|
|
|
m_lastDrawItem = NULL;
|
2017-11-12 17:55:20 +00:00
|
|
|
wxString libName = getTargetLib();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2017-11-13 11:30:03 +00:00
|
|
|
if( !m_libMgr->LibraryExists( libName ) )
|
|
|
|
{
|
|
|
|
libName = SelectLibraryFromList();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( libName ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
wxFileDialog dlg( this, _( "Import Symbol" ), m_mruPath,
|
2017-11-12 00:31:38 +00:00
|
|
|
wxEmptyString, SchematicLibraryFileWildcard(),
|
2009-04-13 05:58:11 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2008-04-16 19:12:40 +00:00
|
|
|
return;
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
wxFileName fn = dlg.GetPath();
|
2015-09-25 19:38:09 +00:00
|
|
|
m_mruPath = fn.GetPath();
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
wxArrayString symbols;
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
// TODO dialog to select the part to be imported if there is more than one
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
try
|
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
pi->EnumerateSymbolLib( symbols, fn.GetFullPath() );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2017-10-06 18:07:43 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Cannot import symbol library \"%s\"." ), fn.GetFullPath() );
|
2017-10-06 18:07:43 +00:00
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
2009-09-18 14:56:05 +00:00
|
|
|
return;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2008-04-16 19:12:40 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( symbols.empty() )
|
2008-04-16 19:12:40 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Symbol library file \"%s\" is empty." ), fn.GetFullPath() );
|
2009-09-18 14:56:05 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
2008-04-16 19:12:40 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
wxString symbolName = symbols[0];
|
|
|
|
LIB_ALIAS* entry = pi->LoadSymbol( fn.GetFullPath(), symbolName );
|
2016-10-14 23:26:48 +00:00
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
if( m_libMgr->PartExists( symbols[0], libName ) )
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Symbol \"%s\" already exists in library \"%s\"." ), symbolName, libName );
|
2017-11-12 17:55:20 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
m_libMgr->UpdatePart( entry->GetPart(), libName );
|
2018-08-25 12:21:09 +00:00
|
|
|
SyncLibraries( false );
|
2017-11-12 17:55:20 +00:00
|
|
|
loadPart( symbolName, libName, 1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::OnExportPart( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-11-12 17:55:20 +00:00
|
|
|
wxString msg, title;
|
|
|
|
LIB_PART* part = getTargetPart();
|
2008-04-16 19:12:40 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( !part )
|
2008-04-16 19:12:40 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
DisplayError( this, _( "There is no symbol selected to save." ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
return;
|
2008-04-16 19:12:40 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
wxFileName fn;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
fn.SetName( part->GetName().Lower() );
|
2012-09-28 17:47:41 +00:00
|
|
|
fn.SetExt( SchematicLibraryFileExtension );
|
2008-04-16 19:12:40 +00:00
|
|
|
|
2017-10-31 11:13:20 +00:00
|
|
|
wxFileDialog dlg( this, _( "Export Symbol" ), m_mruPath, fn.GetFullName(),
|
2018-08-23 18:41:24 +00:00
|
|
|
SchematicLibraryFileWildcard(), wxFD_SAVE );
|
2008-04-16 19:12:40 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2008-04-16 19:12:40 +00:00
|
|
|
return;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = dlg.GetPath();
|
2017-10-06 18:07:43 +00:00
|
|
|
fn.MakeAbsolute();
|
2008-04-16 19:12:40 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
LIB_PART* old_part = NULL;
|
2008-04-16 19:12:40 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
|
|
|
|
|
|
|
if( fn.FileExists() )
|
2012-10-25 15:41:20 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
LIB_ALIAS* alias = pi->LoadSymbol( fn.GetFullPath(), part->GetName() );
|
|
|
|
|
|
|
|
if( alias )
|
|
|
|
old_part = alias->GetPart();
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error occurred attempting to load symbol library file \"%s\"" ),
|
2017-10-06 18:07:43 +00:00
|
|
|
fn.GetFullPath() );
|
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( old_part )
|
|
|
|
{
|
2018-08-23 18:41:24 +00:00
|
|
|
msg.Printf( _( "Symbol \"%s\" already exists in \"%s\"." ),
|
|
|
|
part->GetName(),
|
|
|
|
fn.GetFullName() );
|
|
|
|
|
2018-07-10 14:33:04 +00:00
|
|
|
KIDIALOG errorDlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
errorDlg.SetOKLabel( _( "Overwrite" ) );
|
2018-08-29 22:37:20 +00:00
|
|
|
errorDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
2017-10-06 18:07:43 +00:00
|
|
|
|
2018-07-10 14:33:04 +00:00
|
|
|
if( errorDlg.ShowModal() == wxID_CANCEL )
|
2017-10-06 18:07:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-25 15:41:20 +00:00
|
|
|
}
|
2017-10-06 18:07:43 +00:00
|
|
|
|
|
|
|
if( fn.Exists() && !fn.IsDirWritable() )
|
2011-11-11 20:10:24 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Write permissions are required to save library \"%s\"." ), fn.GetFullPath() );
|
2011-11-11 20:10:24 +00:00
|
|
|
DisplayError( this, msg );
|
2017-10-06 18:07:43 +00:00
|
|
|
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() );
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error creating symbol library \"%s\"" ), fn.GetFullName() );
|
2017-01-27 15:56:36 +00:00
|
|
|
SetStatusText( msg );
|
2011-11-11 20:10:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
m_mruPath = fn.GetPath();
|
2017-12-18 05:21:00 +00:00
|
|
|
m_lastDrawItem = NULL;
|
|
|
|
SetDrawItem( NULL );
|
2011-11-11 20:10:24 +00:00
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Symbol \"%s\" saved in library \"%s\"" ), part->GetName(), fn.GetFullPath() );
|
2010-03-16 18:22:59 +00:00
|
|
|
SetStatusText( msg );
|
2018-08-23 11:48:14 +00:00
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|