2012-12-28 20:52:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-01-16 14:47:08 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-12-28 20:52:12 +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-10-22 20:41:26 +00:00
|
|
|
#include <wx/ffile.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2021-08-03 00:11:11 +00:00
|
|
|
#include <eda_list_dialog.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <filter_reader.h>
|
2013-05-28 16:54:59 +00:00
|
|
|
#include <fp_lib_table.h>
|
2013-11-29 18:29:41 +00:00
|
|
|
#include <validators.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/dialog_text_entry.h>
|
2018-08-25 15:12:08 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
2021-09-29 15:39:43 +00:00
|
|
|
#include <tools/board_editor_control.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2018-08-25 15:12:08 +00:00
|
|
|
#include <board_commit.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <footprint_edit_frame.h>
|
2012-03-08 17:47:23 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-11-25 12:22:40 +00:00
|
|
|
#include <plugins/kicad/pcb_plugin.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <plugins/legacy/legacy_plugin.h>
|
2018-09-15 00:37:40 +00:00
|
|
|
#include <env_paths.h>
|
2021-01-29 01:08:36 +00:00
|
|
|
#include <paths.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2022-07-10 02:44:49 +00:00
|
|
|
#include <project/project_file.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <footprint_editor_settings.h>
|
2018-10-03 21:44:17 +00:00
|
|
|
#include "footprint_viewer_frame.h"
|
2022-02-19 19:29:27 +00:00
|
|
|
#include "tools/pad_tool.h"
|
2021-06-04 00:26:58 +00:00
|
|
|
#include <wx/choicdlg.h>
|
|
|
|
#include <wx/filedlg.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
// unique, "file local" translations:
|
|
|
|
|
|
|
|
|
2014-07-23 10:28:48 +00:00
|
|
|
static const wxString INFO_LEGACY_LIB_WARN_EDIT(
|
|
|
|
_( "Writing/modifying legacy libraries (.mod files) is not allowed\n"\
|
|
|
|
"Please save the current library to the new .pretty format\n"\
|
|
|
|
"and update your footprint lib table\n"\
|
|
|
|
"to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
|
|
|
|
|
|
|
|
static const wxString INFO_LEGACY_LIB_WARN_DELETE(
|
|
|
|
_( "Modifying legacy libraries (.mod files) is not allowed\n"\
|
|
|
|
"Please save the current library under the new .pretty format\n"\
|
2014-07-25 17:49:14 +00:00
|
|
|
"and update your footprint lib table\n"\
|
2014-07-23 10:28:48 +00:00
|
|
|
"before deleting a footprint" ) );
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
/**
|
2020-11-14 22:00:12 +00:00
|
|
|
* Prompt the user for a footprint file to open.
|
2016-05-10 19:07:35 +00:00
|
|
|
* @param aParent - parent window for the dialog
|
|
|
|
* @param aLastPath - last opened path
|
|
|
|
*/
|
2017-05-23 18:07:36 +00:00
|
|
|
static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxString& aLastPath )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2017-05-23 18:07:36 +00:00
|
|
|
static int lastFilterIndex = 0; // To store the last choice during a session.
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString wildCard;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2017-11-12 00:31:38 +00:00
|
|
|
wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
|
|
|
|
<< ModLegacyExportFileWildcard() << wxChar( '|' )
|
2018-12-17 02:20:55 +00:00
|
|
|
<< GedaPcbFootprintLibFileWildcard() << wxChar( '|' )
|
2019-01-08 11:57:39 +00:00
|
|
|
<< AllFilesWildcard();
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2020-05-08 18:10:47 +00:00
|
|
|
wxFileDialog dlg( aParent, _( "Import Footprint" ), aLastPath, wxEmptyString, wildCard,
|
2016-05-10 19:07:35 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
dlg.SetFilterIndex( lastFilterIndex );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2016-05-10 19:07:35 +00:00
|
|
|
return wxFileName();
|
2016-09-14 22:36:45 +00:00
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
lastFilterIndex = dlg.GetFilterIndex();
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
return wxFileName( dlg.GetPath() );
|
|
|
|
}
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a file to detect the type.
|
|
|
|
* @param aFile - open file to be read. File pointer will be closed.
|
|
|
|
* @param aFileName - file name to be read
|
2022-01-16 14:47:08 +00:00
|
|
|
* @param aName - wxString to receive the footprint name if type is LEGACY
|
2016-05-10 19:07:35 +00:00
|
|
|
*/
|
2018-03-03 13:34:46 +00:00
|
|
|
static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
|
|
|
|
wxString* aName )
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
|
|
|
FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
|
|
|
|
WHITESPACE_FILTER_READER reader( freader );
|
|
|
|
IO_MGR::PCB_FILE_T file_type;
|
|
|
|
|
|
|
|
wxASSERT( aName );
|
|
|
|
|
|
|
|
reader.ReadLine();
|
|
|
|
char* line = reader.Line();
|
|
|
|
|
2021-11-22 15:48:05 +00:00
|
|
|
if( !line )
|
|
|
|
{
|
|
|
|
return IO_MGR::FILE_TYPE_NONE;
|
|
|
|
}
|
|
|
|
|
2021-02-02 08:53:30 +00:00
|
|
|
// first .kicad_mod file versions starts by "(module"
|
|
|
|
// recent .kicad_mod file versions starts by "(footprint"
|
|
|
|
if( strncasecmp( line, "(module", strlen( "(module" ) ) == 0
|
|
|
|
|| strncasecmp( line, "(footprint", strlen( "(footprint" ) ) == 0 )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
file_type = IO_MGR::KICAD_SEXP;
|
2016-05-10 19:07:35 +00:00
|
|
|
*aName = aFileName.GetName();
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
2016-08-16 08:27:09 +00:00
|
|
|
else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2016-05-10 19:07:35 +00:00
|
|
|
file_type = IO_MGR::LEGACY;
|
2018-03-03 13:34:46 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
while( reader.ReadLine() )
|
|
|
|
{
|
2016-08-16 08:27:09 +00:00
|
|
|
if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
|
|
|
*aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-16 08:27:09 +00:00
|
|
|
else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
|
|
|
file_type = IO_MGR::GEDA_PCB;
|
|
|
|
*aName = aFileName.GetName();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file_type = IO_MGR::FILE_TYPE_NONE;
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
return file_type;
|
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
/**
|
|
|
|
* Parse a footprint using a PLUGIN.
|
|
|
|
* @param aFileName - file name to parse
|
|
|
|
* @param aFileType - type of the file
|
|
|
|
* @param aName - name of the footprint
|
|
|
|
*/
|
2020-11-14 22:00:12 +00:00
|
|
|
static FOOTPRINT* parse_footprint_with_plugin( const wxFileName& aFileName,
|
|
|
|
IO_MGR::PCB_FILE_T aFileType,
|
|
|
|
const wxString& aName )
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
switch( aFileType )
|
2012-10-22 20:41:26 +00:00
|
|
|
{
|
2020-11-14 22:00:12 +00:00
|
|
|
case IO_MGR::GEDA_PCB: path = aFileName.GetPath(); break;
|
|
|
|
case IO_MGR::LEGACY: path = aFileName.GetFullPath(); break;
|
|
|
|
default: wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) ); break;
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( aFileType ) );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
return pi->FootprintLoad( path, aName );
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
/**
|
|
|
|
* Parse a KICAD footprint.
|
|
|
|
* @param aFileName - file name to parse
|
|
|
|
*/
|
2020-11-14 22:00:12 +00:00
|
|
|
static FOOTPRINT* parse_footprint_kicad( const wxFileName& aFileName )
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
2021-11-25 12:22:40 +00:00
|
|
|
wxString fcontents;
|
|
|
|
PCB_PLUGIN pcb_io;
|
|
|
|
wxFFile f( aFileName.GetFullPath() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
if( !f.IsOpened() )
|
2020-12-17 09:47:39 +00:00
|
|
|
return nullptr;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
f.ReadAll( &fcontents );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
return dynamic_cast<FOOTPRINT*>( pcb_io.Parse( fcontents ) );
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
/**
|
2020-12-17 09:47:39 +00:00
|
|
|
* Try to load a footprint, returning nullptr if the file couldn't be accessed.
|
2016-05-10 19:07:35 +00:00
|
|
|
* @param aFileName - file name to load
|
|
|
|
* @param aFileType - type of the file to load
|
|
|
|
* @param aName - footprint name
|
|
|
|
*/
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
|
|
|
|
const wxString& aName )
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint;
|
2016-05-10 19:07:35 +00:00
|
|
|
|
|
|
|
switch( aFileType )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2016-05-10 19:07:35 +00:00
|
|
|
case IO_MGR::GEDA_PCB:
|
|
|
|
case IO_MGR::LEGACY:
|
2020-11-14 22:00:12 +00:00
|
|
|
footprint = parse_footprint_with_plugin( aFileName, aFileType, aName );
|
2016-05-10 19:07:35 +00:00
|
|
|
break;
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
case IO_MGR::KICAD_SEXP:
|
2020-11-14 22:00:12 +00:00
|
|
|
footprint = parse_footprint_kicad( aFileName );
|
2016-05-10 19:07:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
|
2020-12-17 09:47:39 +00:00
|
|
|
footprint = nullptr;
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
return footprint;
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* FOOTPRINT_EDIT_FRAME::ImportFootprint( const wxString& aName )
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
2023-07-09 20:38:58 +00:00
|
|
|
FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings();
|
|
|
|
wxFileName fn;
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
if( aName != wxT("") )
|
|
|
|
fn = aName;
|
|
|
|
else
|
2023-07-09 20:38:58 +00:00
|
|
|
fn = getFootprintFilenameFromUser( this, m_mruPath );
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
if( !fn.IsOk() )
|
2020-12-17 09:47:39 +00:00
|
|
|
return nullptr;
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
FILE* fp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
if( !fp )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
wxString msg = wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() );
|
2016-05-10 19:07:35 +00:00
|
|
|
DisplayError( this, msg );
|
2020-12-17 09:47:39 +00:00
|
|
|
return nullptr;
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2023-07-09 20:38:58 +00:00
|
|
|
m_mruPath = fn.GetPath();
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
wxString footprintName;
|
|
|
|
IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &footprintName );
|
2016-05-10 19:07:35 +00:00
|
|
|
|
|
|
|
if( fileType == IO_MGR::FILE_TYPE_NONE )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
DisplayError( this, _( "Not a footprint file." ) );
|
2020-12-17 09:47:39 +00:00
|
|
|
return nullptr;
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 09:47:39 +00:00
|
|
|
FOOTPRINT* footprint = nullptr;
|
2016-05-10 19:07:35 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
footprint = try_load_footprint( fn, fileType, footprintName );
|
2016-05-10 19:07:35 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
if( !footprint )
|
2012-04-17 01:35:43 +00:00
|
|
|
{
|
2020-05-08 18:10:47 +00:00
|
|
|
wxString msg = wxString::Format( _( "Unable to load footprint '%s' from '%s'" ),
|
2020-11-10 21:20:03 +00:00
|
|
|
footprintName,
|
2020-05-08 18:10:47 +00:00
|
|
|
fn.GetFullPath() );
|
2016-05-10 19:07:35 +00:00
|
|
|
DisplayError( this, msg );
|
2020-12-17 09:47:39 +00:00
|
|
|
return nullptr;
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-10 19:07:35 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
DisplayError( this, ioe.What() );
|
2017-05-23 18:07:36 +00:00
|
|
|
|
|
|
|
// if the footprint is not loaded, exit.
|
|
|
|
// However, even if an error happens, it can be loaded, because in KICAD and GPCB format,
|
|
|
|
// a fp library is a set of separate files, and the error(s) are not necessary when
|
|
|
|
// reading the selected file
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
if( !footprint )
|
2020-12-17 09:47:39 +00:00
|
|
|
return nullptr;
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
footprint->SetFPID( LIB_ID( wxEmptyString, footprintName ) );
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Insert footprint in list
|
2020-11-10 21:20:03 +00:00
|
|
|
AddFootprintToBoard( footprint );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Display info :
|
2020-11-10 21:20:03 +00:00
|
|
|
SetMsgPanel( footprint );
|
|
|
|
PlaceFootprint( footprint );
|
2014-07-22 07:50:40 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
footprint->SetPosition( wxPoint( 0, 0 ) );
|
2014-07-22 07:50:40 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->BuildListOfNets();
|
2020-11-10 20:11:53 +00:00
|
|
|
UpdateView();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
return footprint;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::ExportFootprint( FOOTPRINT* aFootprint )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
wxFileName fn;
|
|
|
|
FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
if( !aFootprint )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
fn.SetName( aFootprint->GetFPID().GetLibItemName() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2017-11-12 00:31:38 +00:00
|
|
|
wxString wildcard = KiCadFootprintLibFileWildcard();
|
2008-03-12 11:49:16 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
fn.SetExt( KiCadFootprintFileExtension );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2023-07-09 20:38:58 +00:00
|
|
|
if( !cfg->m_LastExportPath.empty() )
|
|
|
|
fn.SetPath( cfg->m_LastExportPath );
|
2020-01-13 01:44:19 +00:00
|
|
|
else
|
|
|
|
fn.SetPath( m_mruPath );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2020-05-08 18:10:47 +00:00
|
|
|
wxFileDialog dlg( this, _( "Export Footprint" ), fn.GetPath(), fn.GetFullName(),
|
2013-05-28 16:54:59 +00:00
|
|
|
wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = dlg.GetPath();
|
2023-07-09 20:38:58 +00:00
|
|
|
cfg->m_LastExportPath = fn.GetPath();
|
2008-03-12 11:49:16 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
try
|
|
|
|
{
|
2012-10-22 20:41:26 +00:00
|
|
|
// Export as *.kicad_pcb format, using a strategy which is specifically chosen
|
|
|
|
// as an example on how it could also be used to send it to the system clipboard.
|
|
|
|
|
2021-11-25 12:22:40 +00:00
|
|
|
PCB_PLUGIN pcb_io(CTL_FOR_LIBRARY );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
/* This footprint should *already* be "normalized" in a way such that
|
|
|
|
orientation is zero, etc., since it came from the Footprint Editor.
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
aFootprint->SetParent( 0 );
|
|
|
|
aFootprint->SetOrientation( 0 );
|
2012-10-22 20:41:26 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
pcb_io.Format( aFootprint );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
|
|
|
FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
|
2016-02-22 14:38:35 +00:00
|
|
|
|
2020-12-17 09:47:39 +00:00
|
|
|
if( fp == nullptr )
|
2016-02-22 14:38:35 +00:00
|
|
|
{
|
2023-01-19 00:53:16 +00:00
|
|
|
DisplayErrorMessage( this, wxString::Format( _( "Insufficient permissions to write file '%s'." ),
|
2020-02-20 12:11:04 +00:00
|
|
|
dlg.GetPath() ) );
|
2016-02-22 14:38:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
|
|
|
|
fclose( fp );
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2012-04-17 01:35:43 +00:00
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
DisplayError( this, ioe.What() );
|
2012-04-17 01:35:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2021-06-18 10:38:08 +00:00
|
|
|
wxString msg = wxString::Format( _( "Footprint exported to file '%s'." ), dlg.GetPath() );
|
2009-04-17 08:51:02 +00:00
|
|
|
DisplayInfoMessage( this, msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2021-06-18 10:38:08 +00:00
|
|
|
wxString PCB_BASE_EDIT_FRAME::CreateNewProjectLibrary( const wxString& aLibName,
|
|
|
|
const wxString& aProposedName )
|
|
|
|
{
|
|
|
|
return createNewLibrary( aLibName, aProposedName, Prj().PcbFootprintLibs() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary( const wxString& aLibName,
|
|
|
|
const wxString& aProposedName )
|
2012-11-19 16:19:38 +00:00
|
|
|
{
|
2021-01-29 01:08:36 +00:00
|
|
|
FP_LIB_TABLE* table = selectLibTable();
|
|
|
|
|
2021-06-18 10:38:08 +00:00
|
|
|
return createNewLibrary( aLibName, aProposedName, table );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PCB_BASE_EDIT_FRAME::createNewLibrary( const wxString& aLibName,
|
|
|
|
const wxString& aProposedName,
|
|
|
|
FP_LIB_TABLE* aTable )
|
|
|
|
{
|
|
|
|
// Kicad cannot write legacy format libraries, only .pretty new format because the legacy
|
|
|
|
// format cannot handle current features.
|
|
|
|
// The footprint library is actually a directory.
|
|
|
|
|
|
|
|
if( aTable == nullptr )
|
2021-01-29 01:08:36 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
|
2021-06-18 10:38:08 +00:00
|
|
|
wxString initialPath = aProposedName.IsEmpty() ? Prj().GetProjectPath() : aProposedName;
|
2018-07-29 15:33:58 +00:00
|
|
|
wxFileName fn;
|
2018-10-03 21:44:17 +00:00
|
|
|
bool doAdd = false;
|
2021-06-18 10:38:08 +00:00
|
|
|
bool isGlobal = ( aTable == &GFootprintTable );
|
2017-08-26 12:04:56 +00:00
|
|
|
|
|
|
|
if( aLibName.IsEmpty() )
|
|
|
|
{
|
2018-07-29 15:33:58 +00:00
|
|
|
fn = initialPath;
|
2017-10-03 10:30:23 +00:00
|
|
|
|
2021-01-29 01:08:36 +00:00
|
|
|
if( !LibraryFileBrowser( false, fn, KiCadFootprintLibPathWildcard(),
|
|
|
|
KiCadFootprintLibPathExtension, false, isGlobal,
|
|
|
|
PATHS::GetDefaultUserFootprintsPath() ) )
|
2018-11-04 12:32:54 +00:00
|
|
|
{
|
2017-08-26 12:04:56 +00:00
|
|
|
return wxEmptyString;
|
2018-11-04 12:32:54 +00:00
|
|
|
}
|
2017-08-26 12:04:56 +00:00
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
doAdd = true;
|
2017-08-26 12:04:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-29 15:33:58 +00:00
|
|
|
fn = aLibName;
|
2017-08-26 12:04:56 +00:00
|
|
|
|
|
|
|
if( !fn.IsAbsolute() )
|
2018-03-03 13:34:46 +00:00
|
|
|
{
|
|
|
|
fn.SetName( aLibName );
|
2017-08-26 12:04:56 +00:00
|
|
|
fn.MakeAbsolute( initialPath );
|
2018-03-03 13:34:46 +00:00
|
|
|
}
|
2017-08-26 12:04:56 +00:00
|
|
|
|
2018-03-03 13:34:46 +00:00
|
|
|
// Enforce the .pretty extension:
|
2017-08-26 12:04:56 +00:00
|
|
|
fn.SetExt( KiCadFootprintLibPathExtension );
|
|
|
|
}
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
// We can save fp libs only using IO_MGR::KICAD_SEXP format (.pretty libraries)
|
2020-09-01 23:08:57 +00:00
|
|
|
IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
|
|
|
|
wxString libPath = fn.GetFullPath();
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-09-01 23:08:57 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2020-09-01 23:08:57 +00:00
|
|
|
bool writable = false;
|
|
|
|
bool exists = false;
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
writable = pi->IsFootprintLibWritable( libPath );
|
|
|
|
exists = true; // no exception was thrown, lib must exist.
|
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& )
|
2021-06-18 10:38:08 +00:00
|
|
|
{
|
|
|
|
// best efforts....
|
|
|
|
}
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
if( exists )
|
|
|
|
{
|
|
|
|
if( !writable )
|
|
|
|
{
|
2021-06-18 10:38:08 +00:00
|
|
|
wxString msg = wxString::Format( _( "Library %s is read only." ), libPath );
|
2020-08-31 13:19:57 +00:00
|
|
|
ShowInfoBarError( msg );
|
2012-11-19 16:19:38 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-10 14:33:04 +00:00
|
|
|
wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
|
|
|
|
KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
dlg.SetOKLabel( _( "Overwrite" ) );
|
2018-08-29 22:37:20 +00:00
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2018-07-10 14:33:04 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2012-11-19 16:19:38 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
pi->FootprintLibDelete( libPath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pi->FootprintLibCreate( libPath );
|
2018-10-03 21:44:17 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.What() );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( doAdd )
|
2021-06-18 10:38:08 +00:00
|
|
|
AddLibrary( libPath, aTable );
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
return libPath;
|
|
|
|
}
|
2018-09-15 00:37:40 +00:00
|
|
|
|
|
|
|
|
2021-01-29 01:08:36 +00:00
|
|
|
FP_LIB_TABLE* PCB_BASE_EDIT_FRAME::selectLibTable( bool aOptional )
|
2018-10-03 21:44:17 +00:00
|
|
|
{
|
2021-01-29 01:08:36 +00:00
|
|
|
// If no project is loaded, always work with the global table
|
|
|
|
if( Prj().IsNullProject() )
|
2018-10-03 21:44:17 +00:00
|
|
|
{
|
2021-01-29 01:08:36 +00:00
|
|
|
FP_LIB_TABLE* ret = &GFootprintTable;
|
|
|
|
|
|
|
|
if( aOptional )
|
2018-11-04 12:32:54 +00:00
|
|
|
{
|
2021-01-29 01:08:36 +00:00
|
|
|
wxMessageDialog dlg( this, _( "Add the library to the global library table?" ),
|
|
|
|
_( "Add To Global Library Table" ), wxYES_NO );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
ret = nullptr;
|
2018-11-04 12:32:54 +00:00
|
|
|
}
|
2021-01-29 01:08:36 +00:00
|
|
|
|
|
|
|
return ret;
|
2018-10-03 21:44:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 01:08:36 +00:00
|
|
|
wxArrayString libTableNames;
|
|
|
|
libTableNames.Add( _( "Global" ) );
|
|
|
|
libTableNames.Add( _( "Project" ) );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
2021-01-29 01:08:36 +00:00
|
|
|
wxSingleChoiceDialog dlg( this, _( "Choose the Library Table to add the library to:" ),
|
|
|
|
_( "Add To Library Table" ), libTableNames );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
2021-01-29 01:08:36 +00:00
|
|
|
if( aOptional )
|
|
|
|
{
|
|
|
|
dlg.FindWindow( wxID_CANCEL )->SetLabel( _( "Skip" ) );
|
|
|
|
dlg.FindWindow( wxID_OK )->SetLabel( _( "Add" ) );
|
|
|
|
}
|
2018-10-03 21:44:17 +00:00
|
|
|
|
2021-01-29 01:08:36 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
switch( dlg.GetSelection() )
|
2020-08-07 19:22:15 +00:00
|
|
|
{
|
2021-01-29 01:08:36 +00:00
|
|
|
case 0: return &GFootprintTable;
|
|
|
|
case 1: return Prj().PcbFootprintLibs();
|
|
|
|
default: return nullptr;
|
2020-08-07 19:22:15 +00:00
|
|
|
}
|
2021-01-29 01:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename, FP_LIB_TABLE* aTable )
|
|
|
|
{
|
2021-06-18 10:38:08 +00:00
|
|
|
if( aTable == nullptr )
|
2021-01-29 01:08:36 +00:00
|
|
|
aTable = selectLibTable();
|
2020-08-07 19:22:15 +00:00
|
|
|
|
2021-06-18 10:38:08 +00:00
|
|
|
if( aTable == nullptr )
|
|
|
|
return wxEmptyString;
|
2021-01-29 01:08:36 +00:00
|
|
|
|
|
|
|
bool isGlobal = ( aTable == &GFootprintTable );
|
|
|
|
|
|
|
|
wxFileName fn( aFilename );
|
2020-08-07 19:22:15 +00:00
|
|
|
|
2021-01-29 01:08:36 +00:00
|
|
|
if( aFilename.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( !LibraryFileBrowser( true, fn, KiCadFootprintLibPathWildcard(),
|
|
|
|
KiCadFootprintLibPathExtension, true, isGlobal,
|
|
|
|
PATHS::GetDefaultUserFootprintsPath() ) )
|
2020-08-07 19:22:15 +00:00
|
|
|
{
|
2021-01-29 01:08:36 +00:00
|
|
|
return false;
|
2020-08-07 19:22:15 +00:00
|
|
|
}
|
2018-10-03 21:44:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 01:08:36 +00:00
|
|
|
wxString libPath = fn.GetFullPath();
|
|
|
|
wxString libName = fn.GetName();
|
|
|
|
|
|
|
|
if( libName.IsEmpty() )
|
|
|
|
return false;
|
2023-01-06 18:07:23 +00:00
|
|
|
IO_MGR::PCB_FILE_T lib_type = IO_MGR::GuessPluginTypeFromLibPath( libPath );
|
2021-01-29 01:08:36 +00:00
|
|
|
|
2023-01-06 18:07:23 +00:00
|
|
|
wxString type = IO_MGR::ShowType( lib_type );
|
|
|
|
|
|
|
|
// KiCad lib is our default guess. So it might not have the .pretty extension
|
|
|
|
// In this case, the extension is part of the library name
|
|
|
|
if( lib_type == IO_MGR::KICAD_SEXP && fn.GetExt() != KiCadFootprintLibPathExtension )
|
|
|
|
libName = fn.GetFullName();
|
2018-10-03 21:44:17 +00:00
|
|
|
|
|
|
|
// try to use path normalized to an environmental variable or project path
|
|
|
|
wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-06-18 10:38:08 +00:00
|
|
|
FP_LIB_TABLE_ROW* row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
|
2021-01-29 01:08:36 +00:00
|
|
|
aTable->InsertRow( row );
|
|
|
|
|
|
|
|
if( isGlobal )
|
2018-07-29 15:33:58 +00:00
|
|
|
GFootprintTable.Save( FP_LIB_TABLE::GetGlobalTableFileName() );
|
2021-01-29 01:08:36 +00:00
|
|
|
else
|
2018-07-29 15:33:58 +00:00
|
|
|
Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() );
|
2012-11-19 16:19:38 +00:00
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2012-11-19 16:19:38 +00:00
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
DisplayError( this, ioe.What() );
|
2018-10-03 21:44:17 +00:00
|
|
|
return false;
|
2012-11-19 16:19:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 22:00:47 +00:00
|
|
|
auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
|
|
|
if( editor )
|
2019-06-02 20:07:57 +00:00
|
|
|
{
|
2019-06-06 11:45:28 +00:00
|
|
|
LIB_ID libID( libName, wxEmptyString );
|
2018-10-03 21:44:17 +00:00
|
|
|
editor->SyncLibraryTree( true );
|
2019-06-06 11:45:28 +00:00
|
|
|
editor->FocusOnLibID( libID );
|
2019-06-02 20:07:57 +00:00
|
|
|
}
|
2018-10-03 21:44:17 +00:00
|
|
|
|
2019-09-05 22:00:47 +00:00
|
|
|
auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
|
|
|
if( viewer )
|
|
|
|
viewer->ReCreateLibraryList();
|
|
|
|
|
|
|
|
return true;
|
2012-11-19 16:19:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary( const LIB_ID& aFPID, bool aConfirm )
|
2012-11-19 16:19:38 +00:00
|
|
|
{
|
2018-09-13 15:39:14 +00:00
|
|
|
if( !aFPID.IsValid() )
|
2018-07-26 20:19:46 +00:00
|
|
|
return false;
|
|
|
|
|
2018-09-13 15:39:14 +00:00
|
|
|
wxString nickname = aFPID.GetLibNickname();
|
|
|
|
wxString fpname = aFPID.GetLibItemName();
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2014-07-23 10:28:48 +00:00
|
|
|
// Legacy libraries are readable, but modifying legacy format is not allowed
|
|
|
|
// So prompt the user if he try to delete a footprint from a legacy lib
|
2018-07-26 20:19:46 +00:00
|
|
|
wxString libfullname = Prj().PcbFootprintLibs()->FindRow( nickname )->GetFullURI();
|
2014-07-23 10:28:48 +00:00
|
|
|
|
2018-07-26 20:19:46 +00:00
|
|
|
if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
|
2014-07-23 10:28:48 +00:00
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_DELETE );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-09 18:35:48 +00:00
|
|
|
if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
|
2013-11-27 06:04:04 +00:00
|
|
|
{
|
2020-08-31 13:19:57 +00:00
|
|
|
wxString msg = wxString::Format( _( "Library '%s' is read only." ), nickname );
|
|
|
|
ShowInfoBarError( msg );
|
2013-11-27 06:04:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Confirmation
|
2020-05-08 18:10:47 +00:00
|
|
|
wxString msg = wxString::Format( _( "Delete footprint '%s' from library '%s'?" ),
|
|
|
|
fpname.GetData(),
|
|
|
|
nickname.GetData() );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2018-09-13 15:39:14 +00:00
|
|
|
if( aConfirm && !IsOK( this, msg ) )
|
2013-11-27 06:04:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-05-09 18:35:48 +00:00
|
|
|
Prj().PcbFootprintLibs()->FootprintDelete( nickname, fpname );
|
2013-11-27 06:04:04 +00:00
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2013-11-27 06:04:04 +00:00
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
DisplayError( this, ioe.What() );
|
2013-11-27 06:04:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 18:10:47 +00:00
|
|
|
msg.Printf( _( "Footprint '%s' deleted from library '%s'" ),
|
|
|
|
fpname.GetData(),
|
|
|
|
nickname.GetData() );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
|
|
|
SetStatusText( msg );
|
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-09 16:45:36 +00:00
|
|
|
void PCB_EDIT_FRAME::ExportFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName,
|
|
|
|
wxString* aLibPath )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-12-17 09:47:39 +00:00
|
|
|
if( GetBoard()->GetFirstFootprint() == nullptr )
|
2013-11-27 06:04:04 +00:00
|
|
|
{
|
2020-11-09 16:45:36 +00:00
|
|
|
DisplayInfoMessage( this, _( "No footprints to export!" ) );
|
2013-11-27 06:04:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
wxString footprintName;
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
|
2020-10-21 10:31:06 +00:00
|
|
|
auto resetReference =
|
2020-11-13 15:15:52 +00:00
|
|
|
[]( FOOTPRINT* aFootprint )
|
2020-10-21 10:31:06 +00:00
|
|
|
{
|
2020-10-21 17:50:47 +00:00
|
|
|
aFootprint->SetReference( "REF**" );
|
2020-10-21 10:31:06 +00:00
|
|
|
};
|
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
if( !aStoreInNewLib )
|
|
|
|
{
|
|
|
|
// The footprints are saved in an existing .pretty library in the fp lib table
|
2020-11-10 18:07:14 +00:00
|
|
|
PROJECT& prj = Prj();
|
2015-09-28 08:46:00 +00:00
|
|
|
wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
|
|
|
|
wxString nickname = SelectLibrary( last_nickname );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
if( !nickname ) // Aborted
|
|
|
|
return;
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2021-08-21 17:59:14 +00:00
|
|
|
bool map = IsOK( this, wxString::Format( _( "Update footprints on board to refer to %s?" ),
|
|
|
|
nickname ) );
|
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : GetBoard()->Footprints() )
|
2015-09-28 08:46:00 +00:00
|
|
|
{
|
2020-10-21 10:31:06 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2020-10-21 10:31:06 +00:00
|
|
|
if( !footprint->GetFPID().GetLibItemName().empty() ) // Handle old boards.
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* fpCopy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
|
2020-10-21 10:31:06 +00:00
|
|
|
|
|
|
|
resetReference( fpCopy );
|
|
|
|
tbl->FootprintSave( nickname, fpCopy, true );
|
|
|
|
|
|
|
|
delete fpCopy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
2015-09-28 08:46:00 +00:00
|
|
|
{
|
2020-10-21 10:31:06 +00:00
|
|
|
DisplayError( this, ioe.What() );
|
2015-09-28 08:46:00 +00:00
|
|
|
}
|
2021-08-21 17:59:14 +00:00
|
|
|
|
|
|
|
if( map )
|
|
|
|
{
|
|
|
|
LIB_ID id = footprint->GetFPID();
|
|
|
|
id.SetLibNickname( nickname );
|
|
|
|
footprint->SetFPID( id );
|
|
|
|
}
|
2015-09-28 08:46:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-11-27 06:04:04 +00:00
|
|
|
{
|
2015-09-28 08:46:00 +00:00
|
|
|
// The footprints are saved in a new .pretty library.
|
|
|
|
// If this library already exists, all previous footprints will be deleted
|
2017-08-26 12:04:56 +00:00
|
|
|
wxString libPath = CreateNewLibrary( aLibName );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
if( libPath.IsEmpty() ) // Aborted
|
2013-11-27 06:04:04 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-10 18:07:14 +00:00
|
|
|
if( aLibPath )
|
|
|
|
*aLibPath = libPath;
|
2018-02-04 10:47:37 +00:00
|
|
|
|
2021-08-21 17:59:14 +00:00
|
|
|
wxString libNickname;
|
|
|
|
bool map = IsOK( this, _( "Update footprints on board to refer to new library?" ) );
|
|
|
|
|
|
|
|
if( map )
|
|
|
|
{
|
|
|
|
const LIB_TABLE_ROW* row = Prj().PcbFootprintLibs()->FindRowByURI( libPath );
|
|
|
|
|
|
|
|
if( row )
|
|
|
|
libNickname = row->GetNickName();
|
|
|
|
}
|
|
|
|
|
2020-11-10 18:07:14 +00:00
|
|
|
IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
|
2014-05-09 18:35:48 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : GetBoard()->Footprints() )
|
2013-11-27 06:04:04 +00:00
|
|
|
{
|
2015-09-28 08:46:00 +00:00
|
|
|
try
|
2013-11-27 06:04:04 +00:00
|
|
|
{
|
2020-10-21 10:31:06 +00:00
|
|
|
if( !footprint->GetFPID().GetLibItemName().empty() ) // Handle old boards.
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* fpCopy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
|
2020-10-21 10:31:06 +00:00
|
|
|
|
|
|
|
resetReference( fpCopy );
|
|
|
|
pi->FootprintSave( libPath, fpCopy );
|
|
|
|
|
2023-06-28 20:56:46 +00:00
|
|
|
// Remove reference to the group before deleting
|
|
|
|
fpCopy->SetParentGroup( nullptr );
|
|
|
|
|
2020-10-21 10:31:06 +00:00
|
|
|
delete fpCopy;
|
|
|
|
}
|
2013-11-27 06:04:04 +00:00
|
|
|
}
|
2015-09-28 08:46:00 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2013-11-27 06:04:04 +00:00
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
DisplayError( this, ioe.What() );
|
2013-11-27 06:04:04 +00:00
|
|
|
}
|
2021-08-21 17:59:14 +00:00
|
|
|
|
|
|
|
if( map )
|
|
|
|
{
|
|
|
|
LIB_ID id = footprint->GetFPID();
|
|
|
|
id.SetLibNickname( libNickname );
|
|
|
|
footprint->SetFPID( id );
|
|
|
|
}
|
2013-11-27 06:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::SaveFootprint( FOOTPRINT* aFootprint )
|
2018-07-26 20:19:46 +00:00
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !aFootprint ) // Happen if no footprint loaded
|
2019-07-19 17:06:16 +00:00
|
|
|
return false;
|
|
|
|
|
2022-02-19 19:29:27 +00:00
|
|
|
PAD_TOOL* padTool = m_toolManager->GetTool<PAD_TOOL>();
|
|
|
|
|
|
|
|
if( padTool->InPadEditMode() )
|
|
|
|
m_toolManager->RunAction( PCB_ACTIONS::recombinePad, true );
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
wxString libraryName = aFootprint->GetFPID().GetLibNickname();
|
|
|
|
wxString footprintName = aFootprint->GetFPID().GetLibItemName();
|
|
|
|
bool nameChanged = m_footprintNameWhenLoaded != footprintName;
|
2018-07-26 20:19:46 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( aFootprint->GetLink() != niluuid )
|
2018-08-25 15:12:08 +00:00
|
|
|
{
|
2018-09-13 23:39:40 +00:00
|
|
|
if( SaveFootprintToBoard( false ) )
|
|
|
|
{
|
|
|
|
m_footprintNameWhenLoaded = footprintName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
2021-02-20 14:23:45 +00:00
|
|
|
{
|
2018-09-13 23:39:40 +00:00
|
|
|
return false;
|
2021-02-20 14:23:45 +00:00
|
|
|
}
|
2018-08-25 15:12:08 +00:00
|
|
|
}
|
2018-11-01 23:33:31 +00:00
|
|
|
else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
|
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
if( SaveFootprintAs( aFootprint ) )
|
2018-11-01 23:33:31 +00:00
|
|
|
{
|
|
|
|
m_footprintNameWhenLoaded = footprintName;
|
|
|
|
SyncLibraryTree( true );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
2021-02-20 14:23:45 +00:00
|
|
|
{
|
2018-11-01 23:33:31 +00:00
|
|
|
return false;
|
2021-02-20 14:23:45 +00:00
|
|
|
}
|
2018-11-01 23:33:31 +00:00
|
|
|
}
|
2018-07-26 20:19:46 +00:00
|
|
|
|
|
|
|
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
|
|
|
|
|
|
|
|
// Legacy libraries are readable, but modifying legacy format is not allowed
|
|
|
|
// So prompt the user if he try to add/replace a footprint in a legacy lib
|
2023-01-21 17:18:38 +00:00
|
|
|
wxString libfullname;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
libfullname = tbl->FindRow( libraryName )->GetFullURI();
|
|
|
|
}
|
|
|
|
catch( IO_ERROR& error )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, error.What() );
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-26 20:19:46 +00:00
|
|
|
|
|
|
|
if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-13 23:39:40 +00:00
|
|
|
if( nameChanged )
|
|
|
|
{
|
|
|
|
LIB_ID oldFPID( libraryName, m_footprintNameWhenLoaded );
|
2020-11-10 20:31:52 +00:00
|
|
|
DeleteFootprintFromLibrary( oldFPID, false );
|
2018-09-13 23:39:40 +00:00
|
|
|
}
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !SaveFootprintInLibrary( aFootprint, libraryName ) )
|
2018-10-03 21:44:17 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( nameChanged )
|
2018-07-26 20:19:46 +00:00
|
|
|
{
|
2018-10-03 21:44:17 +00:00
|
|
|
m_footprintNameWhenLoaded = footprintName;
|
|
|
|
SyncLibraryTree( true );
|
|
|
|
}
|
2018-07-26 20:19:46 +00:00
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-21 10:57:15 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::DuplicateFootprint( FOOTPRINT* aFootprint )
|
|
|
|
{
|
|
|
|
LIB_ID fpID = aFootprint->GetFPID();
|
|
|
|
wxString libraryName = fpID.GetLibNickname();
|
|
|
|
wxString footprintName = fpID.GetLibItemName();
|
|
|
|
|
|
|
|
// Legacy libraries are readable, but modifying legacy format is not allowed
|
|
|
|
// So prompt the user if he try to add/replace a footprint in a legacy lib
|
|
|
|
wxString libFullName = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
|
|
|
|
|
|
|
|
if( IO_MGR::GuessPluginTypeFromLibPath( libFullName ) == IO_MGR::LEGACY )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
|
|
|
|
int i = 1;
|
|
|
|
wxString newName = footprintName;
|
|
|
|
|
|
|
|
// Append a number to the name until the name is unique in the library.
|
|
|
|
while( tbl->FootprintExists( libraryName, newName ) )
|
|
|
|
newName.Printf( "%s_%d", footprintName, i++ );
|
|
|
|
|
|
|
|
aFootprint->SetFPID( LIB_ID( libraryName, newName ) );
|
|
|
|
|
|
|
|
if( aFootprint->GetValue() == footprintName )
|
|
|
|
aFootprint->SetValue( newName );
|
|
|
|
|
|
|
|
return SaveFootprintInLibrary( aFootprint, libraryName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( FOOTPRINT* aFootprint,
|
2020-11-10 20:31:52 +00:00
|
|
|
const wxString& aLibraryName )
|
2018-10-03 21:44:17 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-11-10 20:31:52 +00:00
|
|
|
aFootprint->SetFPID( LIB_ID( wxEmptyString, aFootprint->GetFPID().GetLibItemName() ) );
|
2018-07-26 20:19:46 +00:00
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
Prj().PcbFootprintLibs()->FootprintSave( aLibraryName, aFootprint );
|
2018-07-26 20:19:46 +00:00
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
aFootprint->SetFPID( LIB_ID( aLibraryName, aFootprint->GetFPID().GetLibItemName() ) );
|
2018-10-03 21:44:17 +00:00
|
|
|
return true;
|
2018-07-26 20:19:46 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.What() );
|
2018-07-27 09:18:24 +00:00
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
aFootprint->SetFPID( LIB_ID( aLibraryName, aFootprint->GetFPID().GetLibItemName() ) );
|
2018-10-03 21:44:17 +00:00
|
|
|
return false;
|
2018-09-13 23:39:40 +00:00
|
|
|
}
|
2018-07-26 20:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-25 15:12:08 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew )
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
// update footprint in the current board,
|
2018-08-25 15:12:08 +00:00
|
|
|
// not just add it to the board with total disregard for the netlist...
|
2019-09-05 22:00:47 +00:00
|
|
|
PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
|
2018-08-25 15:12:08 +00:00
|
|
|
|
2020-12-17 09:47:39 +00:00
|
|
|
if( pcbframe == nullptr ) // happens when the board editor is not active (or closed)
|
2018-08-25 15:12:08 +00:00
|
|
|
{
|
2020-08-31 13:19:57 +00:00
|
|
|
ShowInfoBarError( _( "No board currently open." ) );
|
2018-08-25 15:12:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
BOARD* mainpcb = pcbframe->GetBoard();
|
2020-12-17 09:47:39 +00:00
|
|
|
FOOTPRINT* sourceFootprint = nullptr;
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* editorFootprint = GetBoard()->GetFirstFootprint();
|
2018-08-25 15:12:08 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
// Search the old footprint (source) if exists
|
2018-08-25 15:12:08 +00:00
|
|
|
// Because this source could be deleted when editing the main board...
|
2020-11-10 21:20:03 +00:00
|
|
|
if( editorFootprint->GetLink() != niluuid ) // this is not a new footprint ...
|
2018-08-25 15:12:08 +00:00
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
sourceFootprint = nullptr;
|
2018-08-25 15:12:08 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* candidate : mainpcb->Footprints() )
|
2018-08-25 15:12:08 +00:00
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
if( editorFootprint->GetLink() == candidate->m_Uuid )
|
2019-05-31 00:15:57 +00:00
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
sourceFootprint = candidate;
|
2018-08-25 15:12:08 +00:00
|
|
|
break;
|
2019-05-31 00:15:57 +00:00
|
|
|
}
|
2018-08-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-17 09:47:39 +00:00
|
|
|
if( !aAddNew && sourceFootprint == nullptr ) // source not found
|
2018-08-25 15:12:08 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-06 08:48:33 +00:00
|
|
|
TOOL_MANAGER* pcb_ToolManager = pcbframe->GetToolManager();
|
2022-02-27 07:38:19 +00:00
|
|
|
|
2022-03-06 08:48:33 +00:00
|
|
|
if( aAddNew && pcb_ToolManager->GetTool<BOARD_EDITOR_CONTROL>()->PlacingFootprint() )
|
2021-09-29 15:39:43 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Previous footprint placement still in progress." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-25 15:12:08 +00:00
|
|
|
m_toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
BOARD_COMMIT commit( pcbframe );
|
|
|
|
|
2021-01-31 14:08:05 +00:00
|
|
|
// Create a copy for the board, first using Clone() to keep existing Uuids, and then either
|
|
|
|
// resetting the uuids to the board values or assigning new Uuids.
|
|
|
|
FOOTPRINT* newFootprint = static_cast<FOOTPRINT*>( editorFootprint->Clone() );
|
2020-11-10 21:20:03 +00:00
|
|
|
newFootprint->SetParent( mainpcb );
|
|
|
|
newFootprint->SetLink( niluuid );
|
2018-08-25 15:12:08 +00:00
|
|
|
|
2021-01-31 14:08:05 +00:00
|
|
|
auto fixUuid =
|
|
|
|
[&]( KIID& aUuid )
|
|
|
|
{
|
|
|
|
if( editorFootprint->GetLink() != niluuid && m_boardFootprintUuids.count( aUuid ) )
|
|
|
|
aUuid = m_boardFootprintUuids[ aUuid ];
|
|
|
|
else
|
|
|
|
aUuid = KIID();
|
|
|
|
};
|
|
|
|
|
|
|
|
fixUuid( const_cast<KIID&>( newFootprint->m_Uuid ) );
|
|
|
|
newFootprint->RunOnChildren(
|
|
|
|
[&]( BOARD_ITEM* aChild )
|
|
|
|
{
|
|
|
|
fixUuid( const_cast<KIID&>( aChild->m_Uuid ) );
|
|
|
|
} );
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
if( sourceFootprint ) // this is an update command
|
2018-08-25 15:12:08 +00:00
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
// In the main board the new footprint replaces the old one (pos, orient, ref, value,
|
|
|
|
// connections and properties are kept) and the sourceFootprint (old footprint) is
|
|
|
|
// deleted
|
|
|
|
pcbframe->ExchangeFootprint( sourceFootprint, newFootprint, commit );
|
2020-11-13 11:17:15 +00:00
|
|
|
commit.Push( wxT( "Update footprint" ) );
|
2018-08-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
else // This is an insert command
|
|
|
|
{
|
2019-06-13 17:28:55 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
|
2019-06-13 13:34:38 +00:00
|
|
|
VECTOR2D cursorPos = viewControls->GetCursorPosition();
|
2018-08-25 15:12:08 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
commit.Add( newFootprint );
|
2019-06-13 13:34:38 +00:00
|
|
|
viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
|
2020-11-10 21:20:03 +00:00
|
|
|
pcbframe->PlaceFootprint( newFootprint );
|
|
|
|
newFootprint->SetPosition( wxPoint( 0, 0 ) );
|
2019-06-13 13:34:38 +00:00
|
|
|
viewControls->SetCrossHairCursorPosition( cursorPos, false );
|
2020-11-10 21:20:03 +00:00
|
|
|
const_cast<KIID&>( newFootprint->m_Uuid ) = KIID();
|
2020-11-13 11:17:15 +00:00
|
|
|
commit.Push( wxT( "Insert footprint" ) );
|
2019-04-15 21:09:14 +00:00
|
|
|
|
2019-05-27 16:16:54 +00:00
|
|
|
pcbframe->Raise();
|
2022-02-27 07:38:19 +00:00
|
|
|
pcb_ToolManager->RunAction( PCB_ACTIONS::placeFootprint, true, newFootprint );
|
2018-08-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
newFootprint->ClearFlags();
|
2018-08-25 15:12:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
static int ID_SAVE_AS_NAME = 4172;
|
|
|
|
static int ID_MAKE_NEW_LIBRARY = 4173;
|
2018-02-22 00:17:04 +00:00
|
|
|
|
2014-07-23 10:28:48 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
EDA_LIST_DIALOG* FOOTPRINT_EDIT_FRAME::buildSaveAsDialog( const wxString& aFootprintName,
|
|
|
|
const wxString& aLibraryPreselect )
|
|
|
|
{
|
2022-07-23 18:30:32 +00:00
|
|
|
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
2022-07-10 02:44:49 +00:00
|
|
|
PROJECT_FILE& project = Kiway().Prj().GetProjectFile();
|
2022-04-19 18:09:19 +00:00
|
|
|
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
|
|
|
|
std::vector<wxString> nicknames = tbl->GetLogicalLibs();
|
2018-02-22 00:17:04 +00:00
|
|
|
wxArrayString headers;
|
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
|
|
|
|
2019-12-02 23:33:45 +00:00
|
|
|
headers.Add( _( "Nickname" ) );
|
|
|
|
headers.Add( _( "Description" ) );
|
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
for( const wxString& nickname : nicknames )
|
2014-07-23 10:28:48 +00:00
|
|
|
{
|
2022-07-23 18:30:32 +00:00
|
|
|
if( alg::contains( project.m_PinnedFootprintLibs, nickname )
|
|
|
|
|| alg::contains( cfg->m_Session.pinned_fp_libs, nickname ) )
|
2022-07-10 02:44:49 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
|
|
|
|
item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname );
|
|
|
|
item.Add( tbl->GetDescription( nickname ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const wxString& nickname : nicknames )
|
|
|
|
{
|
2022-07-23 18:30:32 +00:00
|
|
|
if( !alg::contains( project.m_PinnedFootprintLibs, nickname )
|
|
|
|
&& !alg::contains( cfg->m_Session.pinned_fp_libs, nickname ) )
|
2022-07-10 02:44:49 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
|
|
|
|
item.Add( nickname );
|
|
|
|
item.Add( tbl->GetDescription( nickname ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
2014-07-23 10:28:48 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
EDA_LIST_DIALOG* dlg = new EDA_LIST_DIALOG( this, _( "Save Footprint As" ), headers,
|
2022-07-10 02:44:49 +00:00
|
|
|
itemsToDisplay, aLibraryPreselect, false );
|
2022-04-19 18:09:19 +00:00
|
|
|
|
|
|
|
dlg->SetListLabel( _( "Save in library:" ) );
|
|
|
|
dlg->SetOKLabel( _( "Save" ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2018-07-24 21:16:59 +00:00
|
|
|
wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
wxStaticText* label = new wxStaticText( dlg, wxID_ANY, _( "Name:" ) );
|
2018-07-24 21:16:59 +00:00
|
|
|
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
wxTextCtrl* nameTextCtrl = new wxTextCtrl( dlg, ID_SAVE_AS_NAME, aFootprintName );
|
2018-07-24 21:16:59 +00:00
|
|
|
bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
|
2020-11-13 15:15:52 +00:00
|
|
|
nameValidator.SetCharExcludes( FOOTPRINT::StringLibNameInvalidChars( false ) );
|
2018-02-22 00:17:04 +00:00
|
|
|
nameTextCtrl->SetValidator( nameValidator );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
wxButton* newLibraryButton = new wxButton( dlg, ID_MAKE_NEW_LIBRARY, _( "New Library..." ) );
|
|
|
|
dlg->m_ButtonsSizer->Prepend( 80, 20 );
|
|
|
|
dlg->m_ButtonsSizer->Prepend( newLibraryButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
|
|
|
|
|
|
|
|
dlg->GetSizer()->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
|
|
|
|
|
|
|
dlg->Bind( wxEVT_BUTTON,
|
|
|
|
[dlg]( wxCommandEvent& )
|
|
|
|
{
|
|
|
|
dlg->EndModal( ID_MAKE_NEW_LIBRARY );
|
|
|
|
}, ID_MAKE_NEW_LIBRARY );
|
2012-12-10 11:18:42 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
// Move nameTextCtrl to the head of the tab-order
|
2022-04-19 18:09:19 +00:00
|
|
|
if( dlg->GetChildren().DeleteObject( nameTextCtrl ) )
|
|
|
|
dlg->GetChildren().Insert( nameTextCtrl );
|
2012-12-10 11:18:42 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
dlg->SetInitialFocus( nameTextCtrl );
|
2018-03-09 00:49:46 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
dlg->Layout();
|
|
|
|
dlg->GetSizer()->Fit( dlg );
|
2011-07-08 07:12:28 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
return dlg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( FOOTPRINT* aFootprint )
|
|
|
|
{
|
|
|
|
if( aFootprint == nullptr )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
|
|
|
|
|
|
|
|
SetMsgPanel( aFootprint );
|
|
|
|
|
|
|
|
wxString libraryName = aFootprint->GetFPID().GetLibNickname();
|
|
|
|
wxString footprintName = aFootprint->GetFPID().GetLibItemName();
|
|
|
|
bool updateValue = aFootprint->GetValue() == footprintName;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
std::unique_ptr<EDA_LIST_DIALOG> dlg;
|
|
|
|
|
|
|
|
while( !done )
|
|
|
|
{
|
|
|
|
dlg.reset( buildSaveAsDialog( footprintName, libraryName ) );
|
|
|
|
|
|
|
|
int ret = dlg->ShowModal();
|
|
|
|
|
|
|
|
if( ret == wxID_CANCEL )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if( ret == wxID_OK )
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
else if( ret == ID_MAKE_NEW_LIBRARY )
|
|
|
|
{
|
|
|
|
wxFileName newLibrary( CreateNewLibrary() );
|
|
|
|
libraryName = newLibrary.GetName();
|
|
|
|
}
|
|
|
|
}
|
2018-02-22 00:17:04 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
libraryName = dlg->GetTextSelection();
|
2018-02-22 00:17:04 +00:00
|
|
|
|
|
|
|
if( libraryName.IsEmpty() )
|
2011-07-08 07:12:28 +00:00
|
|
|
{
|
2020-12-17 09:47:39 +00:00
|
|
|
DisplayError( this, _( "No library specified. Footprint could not be saved." ) );
|
2018-02-22 00:17:04 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
footprintName = static_cast<wxTextCtrl*>( dlg->FindWindow( ID_SAVE_AS_NAME ) )->GetValue();
|
2018-02-22 00:17:04 +00:00
|
|
|
footprintName.Trim( true );
|
|
|
|
footprintName.Trim( false );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
if( footprintName.IsEmpty() )
|
2013-11-27 06:04:04 +00:00
|
|
|
{
|
2020-12-17 09:47:39 +00:00
|
|
|
DisplayError( this, _( "No footprint name specified. Footprint could not be saved." ) );
|
2018-02-22 00:17:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-09 18:35:48 +00:00
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
aFootprint->SetFPID( LIB_ID( libraryName, footprintName ) );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2018-06-11 13:42:43 +00:00
|
|
|
if( updateValue )
|
2020-11-10 20:31:52 +00:00
|
|
|
aFootprint->SetValue( footprintName );
|
2018-06-11 13:42:43 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
// Legacy libraries are readable, but modifying legacy format is not allowed
|
|
|
|
// So prompt the user if he try to add/replace a footprint in a legacy lib
|
|
|
|
wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
|
|
|
|
IO_MGR::PCB_FILE_T piType = IO_MGR::GuessPluginTypeFromLibPath( libfullname );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
if( piType == IO_MGR::LEGACY )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT );
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
bool footprintExists = tbl->FootprintExists( libraryName, footprintName );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
if( footprintExists )
|
2018-10-24 20:43:42 +00:00
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "Footprint %s already exists in %s." ),
|
|
|
|
footprintName,
|
|
|
|
libraryName );
|
2018-10-26 00:14:04 +00:00
|
|
|
KIDIALOG chkdlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
chkdlg.SetOKLabel( _( "Overwrite" ) );
|
2018-10-24 20:43:42 +00:00
|
|
|
|
2018-10-26 00:14:04 +00:00
|
|
|
if( chkdlg.ShowModal() == wxID_CANCEL )
|
2018-10-24 20:43:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
if( !SaveFootprintInLibrary( aFootprint, libraryName ) )
|
2011-02-22 20:59:16 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2018-10-24 20:14:36 +00:00
|
|
|
// Once saved-as a board footprint is no longer a board footprint
|
2020-11-10 20:31:52 +00:00
|
|
|
aFootprint->SetLink( niluuid );
|
2018-10-24 20:14:36 +00:00
|
|
|
|
2020-12-18 01:44:16 +00:00
|
|
|
wxString fmt = footprintExists ? _( "Footprint '%s' replaced in '%s'" )
|
|
|
|
: _( "Footprint '%s' added to '%s'" );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
|
|
|
|
SetStatusText( msg );
|
2021-02-20 14:36:28 +00:00
|
|
|
UpdateTitle();
|
2019-06-19 02:23:53 +00:00
|
|
|
ReCreateHToolbar();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::RevertFootprint()
|
|
|
|
{
|
2022-11-12 13:39:21 +00:00
|
|
|
if( GetScreen()->IsContentModified() && m_originalFootprintCopy )
|
2018-10-03 21:44:17 +00:00
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
wxString msg = wxString::Format( _( "Revert '%s' to last version saved?" ),
|
2020-11-10 21:20:03 +00:00
|
|
|
GetLoadedFPID().GetLibItemName().wx_str() );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
|
|
|
if( ConfirmRevertDialog( this, msg ) )
|
|
|
|
{
|
|
|
|
Clear_Pcb( false );
|
2022-11-12 13:39:21 +00:00
|
|
|
AddFootprintToBoard( static_cast<FOOTPRINT*>( m_originalFootprintCopy->Clone() ) );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
|
2021-04-09 02:09:06 +00:00
|
|
|
Update3DView( true, true );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ClearUndoRedoList();
|
2021-05-28 19:07:04 +00:00
|
|
|
GetScreen()->SetContentModified( false );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
2020-11-10 20:11:53 +00:00
|
|
|
UpdateView();
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2018-10-03 21:44:17 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-24 20:47:57 +00:00
|
|
|
FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( const wxString& aFootprintName, bool aQuiet )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
wxString footprintName = aFootprintName;
|
2010-07-20 18:11:34 +00:00
|
|
|
|
2021-09-24 17:35:36 +00:00
|
|
|
// Static to store user preference for a session
|
|
|
|
static int footprintType = 1;
|
2021-10-07 18:29:51 +00:00
|
|
|
int footprintTranslated = FP_SMD;
|
2021-09-24 17:35:36 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
// Ask for the new footprint name
|
2021-09-24 20:47:57 +00:00
|
|
|
if( footprintName.IsEmpty() && !aQuiet )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2020-05-08 18:10:47 +00:00
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( this, _( "Enter footprint name:" ), _( "New Footprint" ),
|
2021-09-24 17:35:36 +00:00
|
|
|
footprintName, _( "Footprint type:" ),
|
2021-10-18 17:03:47 +00:00
|
|
|
{ _( "Through hole" ), _( "SMD" ), _( "Other" ) },
|
|
|
|
footprintType );
|
2020-11-10 21:20:03 +00:00
|
|
|
dlg.SetTextValidator( FOOTPRINT_NAME_VALIDATOR( &footprintName ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2020-12-17 09:47:39 +00:00
|
|
|
return nullptr; //Aborted by user
|
2021-09-24 17:35:36 +00:00
|
|
|
|
2021-10-07 18:29:51 +00:00
|
|
|
footprintType = dlg.GetChoice();
|
|
|
|
|
|
|
|
switch( footprintType )
|
2021-09-24 17:35:36 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
case 0: footprintTranslated = FP_THROUGH_HOLE; break;
|
|
|
|
case 1: footprintTranslated = FP_SMD; break;
|
|
|
|
default: footprintTranslated = 0; break;
|
2021-09-24 17:35:36 +00:00
|
|
|
}
|
2010-07-20 18:11:34 +00:00
|
|
|
}
|
2011-09-26 20:32:56 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprintName.Trim( true );
|
|
|
|
footprintName.Trim( false );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( footprintName.IsEmpty() )
|
2010-07-20 18:11:34 +00:00
|
|
|
{
|
2021-09-24 20:47:57 +00:00
|
|
|
if( !aQuiet )
|
|
|
|
DisplayInfoMessage( this, _( "No footprint name defined." ) );
|
|
|
|
|
2020-12-17 09:47:39 +00:00
|
|
|
return nullptr;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
// Creates the new footprint and add it to the head of the linked list of footprints
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = new FOOTPRINT( GetBoard() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Update its name in lib
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->SetFPID( LIB_ID( wxEmptyString, footprintName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2021-10-07 18:29:51 +00:00
|
|
|
footprint->SetAttributes( footprintTranslated );
|
2021-09-24 17:35:36 +00:00
|
|
|
|
2020-05-12 17:40:56 +00:00
|
|
|
PCB_LAYER_ID txt_layer;
|
2015-01-28 10:00:48 +00:00
|
|
|
wxPoint default_pos;
|
2015-01-30 18:42:46 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& settings = GetDesignSettings();
|
2015-01-28 10:00:48 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Reference().SetText( settings.m_DefaultFPTextItems[0].m_Text );
|
|
|
|
footprint->Reference().SetVisible( settings.m_DefaultFPTextItems[0].m_Visible );
|
2020-05-12 17:40:56 +00:00
|
|
|
txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[0].m_Layer;
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Reference().SetLayer( txt_layer );
|
2020-05-12 17:40:56 +00:00
|
|
|
default_pos.y -= settings.GetTextSize( txt_layer ).y / 2;
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Reference().SetPosition( default_pos );
|
2020-05-12 17:40:56 +00:00
|
|
|
default_pos.y += settings.GetTextSize( txt_layer ).y;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Value().SetText( settings.m_DefaultFPTextItems[1].m_Text );
|
|
|
|
footprint->Value().SetVisible( settings.m_DefaultFPTextItems[1].m_Visible );
|
2020-05-12 17:40:56 +00:00
|
|
|
txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[1].m_Layer;
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Value().SetLayer( txt_layer );
|
2020-05-12 17:40:56 +00:00
|
|
|
default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Value().SetPosition( default_pos );
|
2020-05-12 17:40:56 +00:00
|
|
|
default_pos.y += settings.GetTextSize( txt_layer ).y;
|
2020-05-08 18:10:47 +00:00
|
|
|
|
2020-05-09 06:59:00 +00:00
|
|
|
for( size_t i = 2; i < settings.m_DefaultFPTextItems.size(); ++i )
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
FP_TEXT* textItem = new FP_TEXT( footprint );
|
2020-05-08 18:10:47 +00:00
|
|
|
textItem->SetText( settings.m_DefaultFPTextItems[i].m_Text );
|
|
|
|
textItem->SetVisible( settings.m_DefaultFPTextItems[i].m_Visible );
|
2020-05-12 17:40:56 +00:00
|
|
|
txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[i].m_Layer;
|
|
|
|
textItem->SetLayer( txt_layer );
|
|
|
|
default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
|
2020-05-08 18:10:47 +00:00
|
|
|
textItem->SetPosition( default_pos );
|
2020-05-12 17:40:56 +00:00
|
|
|
default_pos.y += settings.GetTextSize( txt_layer ).y;
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->GraphicalItems().push_back( textItem );
|
2020-05-08 18:10:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( footprint->GetReference().IsEmpty() )
|
|
|
|
footprint->SetReference( footprintName );
|
2020-05-08 18:10:47 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( footprint->GetValue().IsEmpty() )
|
|
|
|
footprint->SetValue( footprintName );
|
2020-05-08 18:10:47 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->RunOnChildren(
|
2020-05-08 18:10:47 +00:00
|
|
|
[&] ( BOARD_ITEM* aChild )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( aChild->Type() == PCB_FP_TEXT_T )
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* textItem = static_cast<FP_TEXT*>( aChild );
|
|
|
|
PCB_LAYER_ID layer = textItem->GetLayer();
|
2020-05-08 18:10:47 +00:00
|
|
|
|
|
|
|
textItem->SetTextThickness( settings.GetTextThickness( layer ) );
|
|
|
|
textItem->SetTextSize( settings.GetTextSize( layer ) );
|
|
|
|
textItem->SetItalic( settings.GetTextItalic( layer ) );
|
|
|
|
textItem->SetKeepUpright( settings.GetTextUpright( layer ) );
|
|
|
|
}
|
|
|
|
} );
|
2008-11-10 20:45:24 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
SetMsgPanel( footprint );
|
|
|
|
return footprint;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-27 06:04:04 +00:00
|
|
|
wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
|
|
|
wxArrayString headers;
|
2013-11-18 16:04:23 +00:00
|
|
|
|
|
|
|
headers.Add( _( "Nickname" ) );
|
|
|
|
headers.Add( _( "Description" ) );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2022-07-23 18:30:32 +00:00
|
|
|
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
2022-07-10 02:44:49 +00:00
|
|
|
PROJECT_FILE& project = Kiway().Prj().GetProjectFile();
|
|
|
|
FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
|
2013-05-28 16:54:59 +00:00
|
|
|
std::vector< wxArrayString > itemsToDisplay;
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2020-05-08 18:10:47 +00:00
|
|
|
for( const wxString& nickname : nicknames )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
2022-07-23 18:30:32 +00:00
|
|
|
if( alg::contains( project.m_PinnedFootprintLibs, nickname )
|
|
|
|
|| alg::contains( cfg->m_Session.pinned_fp_libs, nickname ) )
|
2022-07-10 02:44:49 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
2013-11-18 16:04:23 +00:00
|
|
|
|
2022-07-10 02:44:49 +00:00
|
|
|
item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname );
|
|
|
|
item.Add( fptbl->GetDescription( nickname ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
|
|
|
}
|
2013-11-18 16:04:23 +00:00
|
|
|
|
2022-07-10 02:44:49 +00:00
|
|
|
for( const wxString& nickname : nicknames )
|
|
|
|
{
|
2022-07-23 18:30:32 +00:00
|
|
|
if( !alg::contains( project.m_PinnedFootprintLibs, nickname )
|
|
|
|
&& !alg::contains( cfg->m_Session.pinned_fp_libs, nickname ) )
|
2022-07-10 02:44:49 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
|
|
|
|
item.Add( nickname );
|
|
|
|
item.Add( fptbl->GetDescription( nickname ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|
|
|
|
|
2022-07-10 02:44:49 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Select Library" ), headers, itemsToDisplay, aNicknameExisting,
|
|
|
|
false );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2013-11-27 06:04:04 +00:00
|
|
|
return wxEmptyString;
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2020-05-08 18:10:47 +00:00
|
|
|
return dlg.GetTextSelection();
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|