2012-12-28 20:52:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-12-02 21:52:14 +00:00
|
|
|
* Copyright (C) 1992-2019 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>
|
2015-09-25 19:38:09 +00:00
|
|
|
#include <fctsys.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>
|
|
|
|
#include <kiface_i.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <filter_reader.h>
|
|
|
|
#include <macros.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>
|
2018-03-12 22:45:17 +00:00
|
|
|
#include <dialog_text_entry.h>
|
2018-08-25 15:12:08 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.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>
|
2012-10-22 20:41:26 +00:00
|
|
|
#include <kicad_plugin.h>
|
|
|
|
#include <legacy_plugin.h>
|
2018-09-15 00:37:40 +00:00
|
|
|
#include <env_paths.h>
|
2018-10-03 21:44:17 +00:00
|
|
|
#include "footprint_viewer_frame.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:
|
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
#define FMT_OK_DELETE _( "OK to delete footprint \"%s\" in library \"%s\"" )
|
2013-12-10 19:24:10 +00:00
|
|
|
#define FMT_IMPORT_MODULE _( "Import Footprint" )
|
2017-12-15 11:37:46 +00:00
|
|
|
#define FMT_FILE_NOT_FOUND _( "File \"%s\" not found" )
|
2013-12-10 19:24:10 +00:00
|
|
|
#define FMT_NOT_MODULE _( "Not a footprint file" )
|
2017-12-16 19:46:55 +00:00
|
|
|
#define FMT_MOD_NOT_FOUND _( "Unable to find or load footprint \"%s\" from lib path \"%s\"" )
|
2017-12-15 11:37:46 +00:00
|
|
|
#define FMT_LIB_READ_ONLY _( "Library \"%s\" is read only, not writable" )
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2013-12-10 19:24:10 +00:00
|
|
|
#define FMT_EXPORT_MODULE _( "Export Footprint" )
|
|
|
|
#define FMT_SAVE_MODULE _( "Save Footprint" )
|
|
|
|
#define FMT_MOD_REF _( "Enter footprint name:" )
|
2017-12-15 11:37:46 +00:00
|
|
|
#define FMT_EXPORTED _( "Footprint exported to file \"%s\"" )
|
|
|
|
#define FMT_MOD_DELETED _( "Footprint \"%s\" deleted from library \"%s\"" )
|
2013-12-10 19:24:10 +00:00
|
|
|
#define FMT_MOD_CREATE _( "New Footprint" )
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2013-12-10 19:24:10 +00:00
|
|
|
#define FMT_NO_REF_ABORTED _( "No footprint name defined." )
|
2013-11-27 06:04:04 +00:00
|
|
|
#define FMT_SELECT_LIB _( "Select Library" )
|
2012-11-19 16:19:38 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
#define EXPORT_IMPORT_LASTPATH_KEY wxT( "import_last_path" )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
/**
|
|
|
|
* Prompt the user for a module file to open.
|
|
|
|
* @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
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
wxFileDialog dlg( aParent, FMT_IMPORT_MODULE, aLastPath, wxEmptyString, wildCard,
|
|
|
|
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
|
|
|
|
* @param aName - wxString to receive the module name iff type is LEGACY
|
|
|
|
*/
|
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();
|
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
|
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
|
|
|
|
*/
|
|
|
|
static MODULE* parse_module_with_plugin(
|
|
|
|
const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
|
|
|
|
const wxString& aName )
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
switch( aFileType )
|
2012-10-22 20:41:26 +00:00
|
|
|
{
|
2016-05-10 19:07:35 +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" ) );
|
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
static MODULE* parse_module_kicad( const wxFileName& aFileName )
|
|
|
|
{
|
|
|
|
wxString fcontents;
|
|
|
|
PCB_IO 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() )
|
|
|
|
return NULL;
|
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
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
return dynamic_cast<MODULE*>( pcb_io.Parse( fcontents ) );
|
|
|
|
}
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
/**
|
|
|
|
* Try to load a footprint, returning NULL if the file couldn't be accessed.
|
|
|
|
* @param aFileName - file name to load
|
|
|
|
* @param aFileType - type of the file to load
|
|
|
|
* @param aName - footprint name
|
|
|
|
*/
|
|
|
|
MODULE* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
|
|
|
|
const wxString& aName )
|
|
|
|
{
|
|
|
|
MODULE* module;
|
|
|
|
|
|
|
|
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:
|
|
|
|
module = parse_module_with_plugin( aFileName, aFileType, aName );
|
|
|
|
break;
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
case IO_MGR::KICAD_SEXP:
|
2016-05-10 19:07:35 +00:00
|
|
|
module = parse_module_kicad( aFileName );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
|
|
|
|
module = NULL;
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
return module;
|
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
MODULE* FOOTPRINT_EDIT_FRAME::Import_Module( const wxString& aName )
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
|
|
|
wxString lastOpenedPathForLoading = m_mruPath;
|
2018-08-01 11:22:50 +00:00
|
|
|
wxConfigBase* cfg = Kiface().KifaceSettings();
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2018-08-01 11:22:50 +00:00
|
|
|
if( cfg )
|
|
|
|
cfg->Read( EXPORT_IMPORT_LASTPATH_KEY, &lastOpenedPathForLoading );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
wxFileName fn;
|
|
|
|
|
|
|
|
if( aName != wxT("") )
|
|
|
|
fn = aName;
|
|
|
|
else
|
|
|
|
fn = getFootprintFilenameFromUser( this, lastOpenedPathForLoading );
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
if( !fn.IsOk() )
|
|
|
|
return NULL;
|
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 )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( FMT_FILE_NOT_FOUND, GetChars( fn.GetFullPath() ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2018-08-01 11:22:50 +00:00
|
|
|
if( cfg ) // Save file path
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
|
|
|
lastOpenedPathForLoading = fn.GetPath();
|
2018-08-01 11:22:50 +00:00
|
|
|
cfg->Write( EXPORT_IMPORT_LASTPATH_KEY, lastOpenedPathForLoading );
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
wxString moduleName;
|
|
|
|
IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &moduleName );
|
|
|
|
|
|
|
|
if( fileType == IO_MGR::FILE_TYPE_NONE )
|
|
|
|
{
|
|
|
|
DisplayError( this, FMT_NOT_MODULE );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:07:36 +00:00
|
|
|
MODULE* module = NULL;
|
2016-05-10 19:07:35 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
module = try_load_footprint( fn, fileType, moduleName );
|
|
|
|
|
|
|
|
if( !module )
|
2012-04-17 01:35:43 +00:00
|
|
|
{
|
2016-05-10 19:07:35 +00:00
|
|
|
wxString msg = wxString::Format(
|
|
|
|
FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetFullPath() ) );
|
|
|
|
DisplayError( this, msg );
|
2012-04-17 01:35:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
if( !module )
|
|
|
|
return NULL;
|
2016-05-10 19:07:35 +00:00
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2018-09-13 23:39:40 +00:00
|
|
|
module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Insert footprint in list
|
2018-09-25 14:23:38 +00:00
|
|
|
AddModuleToBoard( module );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Display info :
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( module );
|
2011-09-16 14:13:02 +00:00
|
|
|
PlaceModule( module, NULL );
|
2014-07-22 07:50:40 +00:00
|
|
|
|
|
|
|
if( IsGalCanvasActive() )
|
|
|
|
module->SetPosition( wxPoint( 0, 0 ) );
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->BuildListOfNets();
|
2014-07-09 11:50:27 +00:00
|
|
|
updateView();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
* 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
|
|
|
wxFileName fn;
|
2018-08-01 11:22:50 +00:00
|
|
|
wxConfigBase* cfg = Kiface().KifaceSettings();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
* 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
|
|
|
if( !aModule )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
|
2017-07-24 19:02:59 +00:00
|
|
|
fn.SetName( aModule->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
|
|
|
|
2018-08-01 11:22:50 +00:00
|
|
|
if( cfg )
|
2012-11-19 16:19:38 +00:00
|
|
|
{
|
|
|
|
wxString path;
|
2018-08-01 11:22:50 +00:00
|
|
|
cfg->Read( EXPORT_IMPORT_LASTPATH_KEY, &path, m_mruPath );
|
2012-11-19 16:19:38 +00:00
|
|
|
fn.SetPath( path );
|
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxFileDialog dlg( this, FMT_EXPORT_MODULE, 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();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2018-08-01 11:22:50 +00:00
|
|
|
if( cfg ) // Save file path
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2018-08-01 11:22:50 +00:00
|
|
|
cfg->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
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.
|
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
PCB_IO pcb_io( CTL_FOR_LIBRARY );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
|
|
|
/* This module should *already* be "normalized" in a way such that
|
|
|
|
orientation is zero, etc., since it came from module editor.
|
|
|
|
|
|
|
|
module->SetTimeStamp( 0 );
|
|
|
|
module->SetParent( 0 );
|
|
|
|
module->SetOrientation( 0 );
|
|
|
|
*/
|
|
|
|
|
|
|
|
pcb_io.Format( aModule );
|
|
|
|
|
|
|
|
FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
|
2016-02-22 14:38:35 +00:00
|
|
|
|
|
|
|
if( fp == NULL )
|
|
|
|
{
|
|
|
|
wxMessageBox( wxString::Format(
|
2017-12-15 11:37:46 +00:00
|
|
|
_( "Unable to create or write file \"%s\"" ),
|
2016-02-22 14:38:35 +00:00
|
|
|
GetChars( dlg.GetPath() ) ) );
|
|
|
|
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
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_EXPORTED, GetChars( 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
|
|
|
|
2017-08-26 12:04:56 +00:00
|
|
|
wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary(const wxString& aLibName )
|
2012-11-19 16:19:38 +00:00
|
|
|
{
|
2014-07-23 10:28:48 +00:00
|
|
|
// Kicad cannot write legacy format libraries, only .pretty new format
|
|
|
|
// because the legacy format cannot handle current features.
|
2015-09-26 06:46:25 +00:00
|
|
|
// The footprint library is actually a directory
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2014-12-11 12:00:59 +00:00
|
|
|
wxString initialPath = wxPathOnly( Prj().GetProjectFullName() );
|
2018-07-29 15:33:58 +00:00
|
|
|
wxFileName fn;
|
2018-10-03 21:44:17 +00:00
|
|
|
bool doAdd = false;
|
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
|
|
|
|
2018-11-04 12:32:54 +00:00
|
|
|
if( !LibraryFileBrowser( false, fn,
|
2019-01-22 13:21:26 +00:00
|
|
|
KiCadFootprintLibPathWildcard(), KiCadFootprintLibPathExtension) )
|
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)
|
|
|
|
IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
|
2018-07-29 15:33:58 +00:00
|
|
|
wxString libPath = fn.GetFullPath();
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
|
|
|
|
|
|
|
|
bool writable = false;
|
|
|
|
bool exists = false;
|
|
|
|
|
|
|
|
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& )
|
2018-07-29 15:33:58 +00:00
|
|
|
{ }
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
if( exists )
|
|
|
|
{
|
|
|
|
if( !writable )
|
|
|
|
{
|
2018-07-29 15:33:58 +00:00
|
|
|
wxString msg = wxString::Format( FMT_LIB_READ_ONLY, libPath );
|
2012-11-19 16:19:38 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
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 )
|
|
|
|
AddLibrary( libPath );
|
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
|
|
|
|
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename )
|
|
|
|
{
|
|
|
|
wxFileName fn( aFilename );
|
|
|
|
|
|
|
|
if( aFilename.IsEmpty() )
|
|
|
|
{
|
2018-11-04 12:32:54 +00:00
|
|
|
if( !LibraryFileBrowser( true, fn,
|
|
|
|
KiCadFootprintLibPathWildcard(), KiCadFootprintLibPathExtension,
|
|
|
|
true ) )
|
|
|
|
{
|
2018-10-03 21:44:17 +00:00
|
|
|
return false;
|
2018-11-04 12:32:54 +00:00
|
|
|
}
|
2018-10-03 21:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString libPath = fn.GetFullPath();
|
|
|
|
wxString libName = fn.GetName();
|
|
|
|
|
|
|
|
if( libName.IsEmpty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool saveInGlobalTable = false;
|
|
|
|
bool saveInProjectTable = false;
|
|
|
|
wxArrayString libTableNames;
|
|
|
|
|
|
|
|
libTableNames.Add( _( "Global" ) );
|
|
|
|
libTableNames.Add( _( "Project" ) );
|
|
|
|
|
|
|
|
switch( SelectSingleOption( this, _( "Select Library Table" ),
|
|
|
|
_( "Choose the Library Table to add the library to:" ),
|
|
|
|
libTableNames ) )
|
|
|
|
{
|
|
|
|
case 0: saveInGlobalTable = true; break;
|
|
|
|
case 1: saveInProjectTable = true; break;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString type = IO_MGR::ShowType( IO_MGR::GuessPluginTypeFromLibPath( libPath ) );
|
|
|
|
|
|
|
|
// try to use path normalized to an environmental variable or project path
|
|
|
|
wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() );
|
|
|
|
|
|
|
|
if( normalizedPath.IsEmpty() )
|
|
|
|
normalizedPath = libPath;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2018-07-29 15:33:58 +00:00
|
|
|
if( saveInGlobalTable )
|
|
|
|
{
|
2018-10-03 21:44:17 +00:00
|
|
|
auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
|
2018-07-29 15:33:58 +00:00
|
|
|
GFootprintTable.InsertRow( row );
|
|
|
|
GFootprintTable.Save( FP_LIB_TABLE::GetGlobalTableFileName() );
|
|
|
|
}
|
|
|
|
else if( saveInProjectTable )
|
|
|
|
{
|
2018-10-03 21:44:17 +00:00
|
|
|
auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
|
2018-07-29 15:33:58 +00:00
|
|
|
Prj().PcbFootprintLibs()->InsertRow( row );
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_PCB_MODULE_EDITOR, false );
|
|
|
|
|
|
|
|
if( editor )
|
|
|
|
editor->SyncLibraryTree( true );
|
|
|
|
|
|
|
|
auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_PCB_MODULE_VIEWER, false );
|
|
|
|
|
|
|
|
if( viewer )
|
|
|
|
viewer->ReCreateLibraryList();
|
|
|
|
|
|
|
|
return true;
|
2012-11-19 16:19:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-13 15:39:14 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( 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
|
|
|
{
|
2018-07-26 14:38:30 +00:00
|
|
|
wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), nickname );
|
2013-11-27 06:04:04 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Confirmation
|
|
|
|
wxString msg = wxString::Format( FMT_OK_DELETE, fpname.GetData(), nickname.GetData() );
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.Printf( FMT_MOD_DELETED, fpname.GetData(), nickname.GetData() );
|
|
|
|
|
|
|
|
SetStatusText( msg );
|
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-03 13:34:46 +00:00
|
|
|
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
|
|
|
|
wxString* aLibPath )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-11-27 06:04:04 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
|
|
|
{
|
2015-09-26 06:46:25 +00:00
|
|
|
DisplayInfoMessage( this, _( "No footprints to archive!" ) );
|
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
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
if( !aStoreInNewLib )
|
|
|
|
{
|
|
|
|
// The footprints are saved in an existing .pretty library in the fp lib table
|
|
|
|
PROJECT& prj = Prj();
|
|
|
|
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
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() )
|
|
|
|
{
|
2018-03-03 13:34:46 +00:00
|
|
|
if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
|
2015-09-28 08:46:00 +00:00
|
|
|
tbl->FootprintSave( nickname, curr_fp, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
DisplayError( this, ioe.What() );
|
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;
|
|
|
|
|
2018-02-04 10:47:37 +00:00
|
|
|
|
|
|
|
if( aLibPath ) *aLibPath = libPath;
|
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
|
2015-09-28 08:46:00 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
|
2014-05-09 18:35:48 +00:00
|
|
|
|
2015-09-28 08:46:00 +00:00
|
|
|
for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() )
|
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
|
|
|
{
|
2018-03-03 13:34:46 +00:00
|
|
|
if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
|
2015-09-28 08:46:00 +00:00
|
|
|
pi->FootprintSave( libPath, curr_fp );
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2018-07-26 20:19:46 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::SaveFootprint( MODULE* aModule )
|
|
|
|
{
|
|
|
|
wxString libraryName = aModule->GetFPID().GetLibNickname();
|
|
|
|
wxString footprintName = aModule->GetFPID().GetLibItemName();
|
2018-09-13 23:39:40 +00:00
|
|
|
bool nameChanged = m_footprintNameWhenLoaded != footprintName;
|
2018-07-26 20:19:46 +00:00
|
|
|
|
2018-08-25 15:12:08 +00:00
|
|
|
if( aModule->GetLink() )
|
|
|
|
{
|
2018-09-13 23:39:40 +00:00
|
|
|
if( SaveFootprintToBoard( false ) )
|
|
|
|
{
|
|
|
|
m_footprintNameWhenLoaded = footprintName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
2018-08-25 15:12:08 +00:00
|
|
|
}
|
2018-11-01 23:33:31 +00:00
|
|
|
else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( SaveFootprintAs( aModule ) )
|
|
|
|
{
|
|
|
|
m_footprintNameWhenLoaded = footprintName;
|
|
|
|
SyncLibraryTree( true );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
|
wxString libfullname = tbl->FindRow( libraryName )->GetFullURI();
|
|
|
|
|
|
|
|
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 );
|
|
|
|
DeleteModuleFromLibrary( oldFPID, false );
|
|
|
|
}
|
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
if( !saveFootprintInLibrary( aModule, libraryName ) )
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FOOTPRINT_EDIT_FRAME::saveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
aModule->SetFPID( LIB_ID( wxEmptyString, aModule->GetFPID().GetLibItemName() ) );
|
2018-07-26 20:19:46 +00:00
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
Prj().PcbFootprintLibs()->FootprintSave( aLibraryName, aModule );
|
2018-07-26 20:19:46 +00:00
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
|
|
|
|
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
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
// update module in the current board,
|
|
|
|
// not just add it to the board with total disregard for the netlist...
|
|
|
|
PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
|
|
|
|
|
|
|
|
if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _("No board currently open." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOARD* mainpcb = pcbframe->GetBoard();
|
|
|
|
MODULE* source_module = NULL;
|
|
|
|
MODULE* module_in_edit = GetBoard()->m_Modules;
|
|
|
|
|
|
|
|
// Search the old module (source) if exists
|
|
|
|
// Because this source could be deleted when editing the main board...
|
|
|
|
if( module_in_edit->GetLink() ) // this is not a new module ...
|
|
|
|
{
|
|
|
|
source_module = mainpcb->m_Modules;
|
|
|
|
|
|
|
|
for( ; source_module != NULL; source_module = source_module->Next() )
|
|
|
|
{
|
|
|
|
if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aAddNew && source_module == NULL ) // source not found
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aAddNew && source_module != NULL )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Footprint already exists on board." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
BOARD_COMMIT commit( pcbframe );
|
|
|
|
|
|
|
|
// Create the "new" module
|
|
|
|
MODULE* newmodule = new MODULE( *module_in_edit );
|
|
|
|
newmodule->SetParent( mainpcb );
|
|
|
|
newmodule->SetLink( 0 );
|
|
|
|
|
|
|
|
if( source_module ) // this is an update command
|
|
|
|
{
|
|
|
|
// In the main board,
|
|
|
|
// the new module replace the old module (pos, orient, ref, value
|
|
|
|
// and connexions are kept)
|
|
|
|
// and the source_module (old module) is deleted
|
|
|
|
pcbframe->Exchange_Module( source_module, newmodule, commit );
|
|
|
|
newmodule->SetTimeStamp( module_in_edit->GetLink() );
|
|
|
|
commit.Push( wxT( "Update module" ) );
|
|
|
|
}
|
|
|
|
else // This is an insert command
|
|
|
|
{
|
|
|
|
wxPoint cursor_pos = pcbframe->GetCrossHairPosition();
|
|
|
|
|
|
|
|
commit.Add( newmodule );
|
|
|
|
pcbframe->SetCrossHairPosition( wxPoint( 0, 0 ) );
|
|
|
|
pcbframe->PlaceModule( newmodule, NULL );
|
|
|
|
newmodule->SetPosition( wxPoint( 0, 0 ) );
|
|
|
|
pcbframe->SetCrossHairPosition( cursor_pos );
|
|
|
|
newmodule->SetTimeStamp( GetNewTimeStamp() );
|
|
|
|
commit.Push( wxT( "Insert module" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
newmodule->ClearFlags();
|
|
|
|
pcbframe->SetCurItem( NULL );
|
|
|
|
// @todo LEGACY should be unnecessary
|
|
|
|
mainpcb->m_Status_Pcb = 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-26 20:19:46 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( MODULE* aModule )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-07-05 12:46:14 +00:00
|
|
|
if( aModule == NULL )
|
|
|
|
return false;
|
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aModule );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
wxString libraryName = aModule->GetFPID().GetLibNickname();
|
|
|
|
wxString footprintName = aModule->GetFPID().GetLibItemName();
|
2018-06-11 13:42:43 +00:00
|
|
|
bool updateValue = ( aModule->GetValue() == footprintName );
|
2014-07-23 10:28:48 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
wxArrayString headers;
|
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
|
|
|
std::vector<wxString> nicknames = tbl->GetLogicalLibs();
|
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
for( const wxString& nickname : nicknames )
|
2014-07-23 10:28:48 +00:00
|
|
|
{
|
2018-02-22 00:17:04 +00:00
|
|
|
wxArrayString item;
|
2019-12-02 21:52:14 +00:00
|
|
|
item.Add( nickname );
|
|
|
|
item.Add( tbl->GetDescription( nickname ) );
|
2018-02-22 00:17:04 +00:00
|
|
|
itemsToDisplay.push_back( item );
|
2014-07-23 10:28:48 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, FMT_SAVE_MODULE, headers, itemsToDisplay, libraryName );
|
2018-07-24 21:16:59 +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
|
|
|
|
2018-07-24 21:16:59 +00:00
|
|
|
wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2018-03-03 13:34:46 +00:00
|
|
|
wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
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 );
|
2018-03-07 18:57:00 +00:00
|
|
|
nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( false ) );
|
2018-02-22 00:17:04 +00:00
|
|
|
nameTextCtrl->SetValidator( nameValidator );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2018-07-24 21:16:59 +00:00
|
|
|
wxSizer* mainSizer = dlg.GetSizer();
|
|
|
|
mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
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
|
|
|
|
if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
|
|
|
|
dlg.GetChildren().Insert( nameTextCtrl );
|
2012-12-10 11:18:42 +00:00
|
|
|
|
2018-07-24 21:16:59 +00:00
|
|
|
dlg.SetInitialFocus( nameTextCtrl );
|
2018-03-09 00:49:46 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
dlg.Layout();
|
|
|
|
mainSizer->Fit( &dlg );
|
2011-07-08 07:12:28 +00:00
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return false; // canceled by user
|
|
|
|
|
|
|
|
libraryName = dlg.GetTextSelection();
|
|
|
|
|
|
|
|
if( libraryName.IsEmpty() )
|
2011-07-08 07:12:28 +00:00
|
|
|
{
|
2018-02-22 00:17:04 +00:00
|
|
|
DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) );
|
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
footprintName = nameTextCtrl->GetValue();
|
|
|
|
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
|
|
|
{
|
2018-02-22 00:17:04 +00:00
|
|
|
DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) );
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-09 18:35:48 +00:00
|
|
|
|
2018-04-29 08:44:05 +00:00
|
|
|
aModule->SetFPID( LIB_ID( libraryName, footprintName ) );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2018-06-11 13:42:43 +00:00
|
|
|
if( updateValue )
|
|
|
|
aModule->SetValue( footprintName );
|
|
|
|
|
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
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
bool module_exists = tbl->FootprintExists( libraryName, footprintName );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2018-10-24 20:43:42 +00:00
|
|
|
if( module_exists )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-03 21:44:17 +00:00
|
|
|
if( !saveFootprintInLibrary( aModule, 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
|
|
|
|
aModule->SetLink( 0 );
|
|
|
|
|
2018-02-22 00:17:04 +00:00
|
|
|
wxString fmt = module_exists ? _( "Component \"%s\" replaced in \"%s\"" ) :
|
|
|
|
_( "Component \"%s\" added in \"%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 );
|
2018-10-02 20:05:14 +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()
|
|
|
|
{
|
|
|
|
if( GetScreen()->IsModify() && m_revertModule )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ),
|
|
|
|
GetChars( GetLoadedFPID().GetLibItemName() ) );
|
|
|
|
|
|
|
|
if( ConfirmRevertDialog( this, msg ) )
|
|
|
|
{
|
|
|
|
Clear_Pcb( false );
|
|
|
|
AddModuleToBoard( (MODULE*) m_revertModule->Clone() );
|
|
|
|
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
|
|
|
|
Update3DView();
|
|
|
|
|
|
|
|
GetScreen()->ClearUndoRedoList();
|
|
|
|
GetScreen()->ClrModify();
|
|
|
|
|
|
|
|
updateView();
|
|
|
|
m_canvas->Refresh();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2015-01-28 10:00:48 +00:00
|
|
|
// Creates a new footprint at position 0,0 which contains the minimal items:
|
|
|
|
// the reference and the value.
|
|
|
|
// Value : initialized to the footprint name.
|
|
|
|
// put on fab layer (front side)
|
|
|
|
// Reference : initialized to a default value (REF**).
|
|
|
|
// put on silkscreen layer (front side)
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
wxString moduleName = aModuleName;
|
2010-07-20 18:11:34 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
// Ask for the new module name
|
2010-07-20 18:11:34 +00:00
|
|
|
if( moduleName.IsEmpty() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2018-03-12 22:45:17 +00:00
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName );
|
2014-08-24 22:49:31 +00:00
|
|
|
dlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &moduleName ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2010-07-20 18:11:34 +00:00
|
|
|
return NULL; //Aborted by user
|
|
|
|
}
|
2011-09-26 20:32:56 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
moduleName.Trim( true );
|
|
|
|
moduleName.Trim( false );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2013-12-10 19:24:10 +00:00
|
|
|
if( moduleName.IsEmpty() )
|
2010-07-20 18:11:34 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
DisplayInfoMessage( this, FMT_NO_REF_ABORTED );
|
2010-07-20 18:11:34 +00:00
|
|
|
return NULL;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
// Creates the new module and add it to the head of the linked list of modules
|
2015-01-28 10:00:48 +00:00
|
|
|
MODULE* module = new MODULE( GetBoard() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
// Update parameters: timestamp ...
|
2012-11-19 16:19:38 +00:00
|
|
|
module->SetLastEditTime();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Update its name in lib
|
2018-07-26 14:38:30 +00:00
|
|
|
module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
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
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Update reference:
|
2015-01-30 18:42:46 +00:00
|
|
|
if( settings.m_RefDefaultText.IsEmpty() )
|
|
|
|
module->SetReference( moduleName );
|
|
|
|
else
|
|
|
|
module->SetReference( settings.m_RefDefaultText );
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
PCB_LAYER_ID layer = ToLAYER_ID( settings.m_RefDefaultlayer );
|
|
|
|
module->Reference().SetThickness( settings.GetTextThickness( layer ) );
|
|
|
|
module->Reference().SetTextSize( settings.GetTextSize( layer ) );
|
|
|
|
module->Reference().SetItalic( settings.GetTextItalic( layer ) );
|
|
|
|
module->Reference().SetKeepUpright( settings.GetTextUpright( layer ) );
|
|
|
|
default_pos.y = GetDesignSettings().GetTextSize( layer ).y / 2;
|
2015-01-28 10:00:48 +00:00
|
|
|
module->Reference().SetPosition( default_pos );
|
2018-04-28 15:22:25 +00:00
|
|
|
module->Reference().SetLayer( layer );
|
2015-01-30 18:42:46 +00:00
|
|
|
module->Reference().SetVisible( settings.m_RefDefaultVisibility );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Set the value field to a default value
|
2015-01-30 18:42:46 +00:00
|
|
|
if( settings.m_ValueDefaultText.IsEmpty() )
|
|
|
|
module->SetValue( moduleName );
|
|
|
|
else
|
|
|
|
module->SetValue( settings.m_ValueDefaultText );
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
layer = ToLAYER_ID( settings.m_ValueDefaultlayer );
|
|
|
|
module->Value().SetThickness( settings.GetTextThickness( layer ) );
|
|
|
|
module->Value().SetTextSize( settings.GetTextSize( layer ) );
|
|
|
|
module->Value().SetItalic( settings.GetTextItalic( layer ) );
|
|
|
|
module->Value().SetKeepUpright( settings.GetTextUpright( layer ) );
|
2015-01-28 10:00:48 +00:00
|
|
|
default_pos.y = -default_pos.y;
|
|
|
|
module->Value().SetPosition( default_pos );
|
2018-04-28 15:22:25 +00:00
|
|
|
module->Value().SetLayer( layer );
|
2015-01-30 18:42:46 +00:00
|
|
|
module->Value().SetVisible( settings.m_ValueDefaultVisibility );
|
2008-11-10 20:45:24 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( module );
|
2012-11-19 16:19:38 +00:00
|
|
|
return module;
|
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
|
|
|
|
2014-05-09 18:35:48 +00:00
|
|
|
FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
|
* 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
|
|
|
|
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
|
|
|
|
2013-11-18 16:04:23 +00:00
|
|
|
for( unsigned i = 0; i < nicknames.size(); i++ )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
2013-11-18 16:04:23 +00:00
|
|
|
|
|
|
|
item.Add( nicknames[i] );
|
* 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
|
|
|
item.Add( fptbl->GetDescription( nicknames[i] ) );
|
2013-11-18 16:04:23 +00:00
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
|
|
|
|
2013-11-27 06:04:04 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, aNicknameExisting );
|
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
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
wxString nickname = dlg.GetTextSelection();
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
wxLogDebug( wxT( "Chose footprint library \"%s\"." ), GetChars( nickname ) );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-11-27 06:04:04 +00:00
|
|
|
return nickname;
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|