2011-10-13 19:56:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-06-05 18:02:38 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2020-08-18 14:17:16 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-13 19:56:32 +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
|
|
|
|
*/
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <confirm.h>
|
2019-05-28 23:23:58 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2023-09-26 17:31:45 +00:00
|
|
|
#include <dialog_footprint_chooser.h>
|
2019-05-28 23:23:58 +00:00
|
|
|
#include <dialog_get_footprint_by_name.h>
|
2021-08-03 00:11:11 +00:00
|
|
|
#include <eda_list_dialog.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <footprint_edit_frame.h>
|
|
|
|
#include <footprint_tree_pane.h>
|
2018-01-31 12:37:36 +00:00
|
|
|
#include <footprint_viewer_frame.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <fp_lib_table.h>
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <pcb_io/pcb_io_mgr.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <kiway.h>
|
|
|
|
#include <lib_id.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <pcbnew_settings.h>
|
2023-07-08 23:55:27 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <view/view_controls.h>
|
2018-11-01 23:33:31 +00:00
|
|
|
#include <widgets/lib_tree.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <widgets/wx_progress_reporters.h>
|
2020-12-31 09:53:14 +00:00
|
|
|
#include <dialog_pad_properties.h>
|
2023-09-28 03:15:54 +00:00
|
|
|
#include <project_pcb.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
static wxArrayString s_FootprintHistoryList;
|
|
|
|
static unsigned s_FootprintHistoryMaxCount = 8;
|
2018-07-29 00:11:39 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
static void AddFootprintToHistory( const wxString& aName )
|
2018-07-29 00:11:39 +00:00
|
|
|
{
|
|
|
|
// Remove duplicates
|
2020-11-07 14:31:50 +00:00
|
|
|
for( int ii = s_FootprintHistoryList.GetCount() - 1; ii >= 0; --ii )
|
2018-07-29 00:11:39 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
if( s_FootprintHistoryList[ ii ] == aName )
|
|
|
|
s_FootprintHistoryList.RemoveAt((size_t) ii );
|
2018-07-29 00:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the new name at the beginning of the history list
|
2020-11-07 14:31:50 +00:00
|
|
|
s_FootprintHistoryList.Insert( aName, 0 );
|
2018-07-29 00:11:39 +00:00
|
|
|
|
|
|
|
// Remove extra names
|
2020-11-07 14:31:50 +00:00
|
|
|
while( s_FootprintHistoryList.GetCount() >= s_FootprintHistoryMaxCount )
|
|
|
|
s_FootprintHistoryList.RemoveAt( s_FootprintHistoryList.GetCount() - 1 );
|
2018-07-29 00:11:39 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2019-01-18 16:24:40 +00:00
|
|
|
#include <bitmaps.h>
|
2020-11-13 15:15:52 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( FOOTPRINT* aFootprint )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2019-01-18 16:24:40 +00:00
|
|
|
bool is_last_fp_from_brd = IsCurrentFPFromBoard();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* newFootprint = nullptr;
|
2019-09-05 22:00:47 +00:00
|
|
|
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
|
2014-05-05 07:46:07 +00:00
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
if( frame == nullptr ) // happens if no board editor opened
|
2014-05-05 07:46:07 +00:00
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
if( aFootprint == nullptr )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !frame->GetBoard() || !frame->GetBoard()->GetFirstFootprint() )
|
2010-06-14 20:16:47 +00:00
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
aFootprint = SelectFootprintFromBoard( frame->GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
if( aFootprint == nullptr )
|
2010-06-14 20:16:47 +00:00
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-12-31 09:53:14 +00:00
|
|
|
// Ensure we do not have the pad editor open (that is apseudo modal dlg).
|
|
|
|
// LoadFootprintFromBoard() can be called from the board editor, and we must ensure
|
|
|
|
// no footprint item is currently in edit
|
|
|
|
if( wxWindow::FindWindowByName( PAD_PROPERTIES_DLG_NAME ) )
|
|
|
|
wxWindow::FindWindowByName( PAD_PROPERTIES_DLG_NAME )->Close();
|
|
|
|
|
2018-08-11 19:35:58 +00:00
|
|
|
if( !Clear_Pcb( true ) )
|
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-01-31 14:08:05 +00:00
|
|
|
m_boardFootprintUuids.clear();
|
|
|
|
|
|
|
|
auto recordAndUpdateUuid =
|
|
|
|
[&]( BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
KIID newId;
|
|
|
|
m_boardFootprintUuids[ newId ] = aItem->m_Uuid;
|
|
|
|
const_cast<KIID&>( aItem->m_Uuid ) = newId;
|
|
|
|
};
|
|
|
|
|
|
|
|
newFootprint = (FOOTPRINT*) aFootprint->Clone(); // Keep existing uuids
|
2020-11-07 14:31:50 +00:00
|
|
|
newFootprint->SetParent( GetBoard() );
|
2022-11-12 13:39:21 +00:00
|
|
|
newFootprint->SetParentGroup( nullptr );
|
2020-11-07 14:31:50 +00:00
|
|
|
newFootprint->SetLink( aFootprint->m_Uuid );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
newFootprint->ClearFlags();
|
2021-01-31 14:08:05 +00:00
|
|
|
recordAndUpdateUuid( newFootprint );
|
2023-11-09 13:55:00 +00:00
|
|
|
newFootprint->RunOnDescendants(
|
2021-01-31 14:08:05 +00:00
|
|
|
[&]( BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
if( aItem->Type() == PCB_PAD_T )
|
|
|
|
aItem->SetLocked( false );
|
|
|
|
|
|
|
|
aItem->ClearFlags();
|
|
|
|
recordAndUpdateUuid( aItem );
|
|
|
|
} );
|
2015-02-18 00:01:02 +00:00
|
|
|
|
2020-11-10 20:31:52 +00:00
|
|
|
AddFootprintToBoard( newFootprint );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-01-09 12:08:04 +00:00
|
|
|
// Clear references to any net info, because the footprint editor does know any thing about
|
|
|
|
// nets handled by the current edited board.
|
2021-06-09 19:32:58 +00:00
|
|
|
// Moreover we do not want to save any reference to an unknown net when saving the footprint
|
2021-01-09 12:08:04 +00:00
|
|
|
// in lib cache so we force the ORPHANED dummy net info for all pads.
|
2020-11-07 14:31:50 +00:00
|
|
|
newFootprint->ClearAllNets();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
|
2020-11-10 21:20:03 +00:00
|
|
|
PlaceFootprint( newFootprint );
|
2023-02-19 03:40:07 +00:00
|
|
|
newFootprint->SetPosition( VECTOR2I( 0, 0 ) ); // cursor in GAL may not yet be initialized
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Put it on FRONT layer,
|
2020-11-16 00:45:43 +00:00
|
|
|
// because this is the default in Footprint Editor, and in libs
|
2020-11-07 14:31:50 +00:00
|
|
|
if( newFootprint->GetLayer() != F_Cu )
|
2022-07-24 15:49:46 +00:00
|
|
|
newFootprint->Flip( newFootprint->GetPosition(), frame->GetPcbNewSettings()->m_FlipLeftRight );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Put it in orientation 0,
|
2020-11-16 00:45:43 +00:00
|
|
|
// because this is the default orientation in Footprint Editor, and in libs
|
2022-01-13 17:27:36 +00:00
|
|
|
newFootprint->SetOrientation( ANGLE_0 );
|
2019-05-28 23:23:58 +00:00
|
|
|
|
2011-03-01 18:45:21 +00:00
|
|
|
Zoom_Automatique( false );
|
2010-06-14 20:16:47 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
m_adapter->SetPreselectNode( newFootprint->GetFPID(), 0 );
|
2018-08-25 15:12:08 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ClearUndoRedoList();
|
2021-05-28 19:07:04 +00:00
|
|
|
GetScreen()->SetContentModified( false );
|
2018-08-25 15:12:08 +00:00
|
|
|
|
2019-06-03 23:50:44 +00:00
|
|
|
// Update the save items if needed.
|
2019-01-18 16:24:40 +00:00
|
|
|
if( !is_last_fp_from_brd )
|
2019-06-03 23:50:44 +00:00
|
|
|
{
|
|
|
|
ReCreateMenuBar();
|
2019-01-18 16:24:40 +00:00
|
|
|
ReCreateHToolbar();
|
2020-06-18 13:49:32 +00:00
|
|
|
|
2024-06-08 13:00:18 +00:00
|
|
|
if( IsLibraryTreeShown() )
|
|
|
|
ToggleLibraryTree();
|
2019-06-03 23:50:44 +00:00
|
|
|
}
|
2019-01-18 16:24:40 +00:00
|
|
|
|
2021-04-09 02:09:06 +00:00
|
|
|
Update3DView( true, true );
|
2020-11-10 20:11:53 +00:00
|
|
|
UpdateView();
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree(); // update any previously-highlighted items
|
2018-11-01 23:33:31 +00:00
|
|
|
|
2010-06-14 20:16:47 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 01:14:17 +00:00
|
|
|
|
2023-09-26 17:31:45 +00:00
|
|
|
FOOTPRINT* PCB_BASE_FRAME::SelectFootprintFromLibrary( LIB_ID aPreselect )
|
2012-02-09 20:33:38 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
wxString footprintName;
|
2018-07-29 00:11:39 +00:00
|
|
|
LIB_ID fpid;
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = nullptr;
|
2011-12-07 05:28:49 +00:00
|
|
|
|
2018-04-27 14:24:12 +00:00
|
|
|
static wxString lastComponentName;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2023-09-26 17:31:45 +00:00
|
|
|
DIALOG_FOOTPRINT_CHOOSER dialog( this, aPreselect, s_FootprintHistoryList );
|
2018-07-29 00:11:39 +00:00
|
|
|
|
2023-09-28 13:09:45 +00:00
|
|
|
if( dialog.ShowModal() == wxID_CANCEL )
|
2021-04-22 21:20:34 +00:00
|
|
|
return nullptr;
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2023-09-26 17:31:45 +00:00
|
|
|
fpid = dialog.GetSelectedLibId();
|
2022-11-14 19:59:33 +00:00
|
|
|
|
2023-09-26 17:31:45 +00:00
|
|
|
if( !fpid.IsValid() )
|
|
|
|
return nullptr;
|
2012-02-09 20:33:38 +00:00
|
|
|
else
|
2023-09-26 17:31:45 +00:00
|
|
|
footprintName = fpid.Format().wx_str();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
try
|
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
footprint = loadFootprint( fpid );
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|
2020-08-18 14:17:16 +00:00
|
|
|
catch( const IO_ERROR& )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
if( footprint )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
lastComponentName = footprintName;
|
|
|
|
AddFootprintToHistory( footprintName );
|
2018-04-02 21:31:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
return footprint;
|
2018-04-02 21:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* PCB_BASE_FRAME::LoadFootprint( const LIB_ID& aFootprintId )
|
2013-11-22 19:47:10 +00:00
|
|
|
{
|
2021-04-22 21:20:34 +00:00
|
|
|
FOOTPRINT* footprint = nullptr;
|
2013-11-22 19:47:10 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
footprint = loadFootprint( aFootprintId );
|
2013-11-22 19:47:10 +00:00
|
|
|
}
|
2020-08-18 14:17:16 +00:00
|
|
|
catch( const IO_ERROR& )
|
2013-11-22 19:47:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
return footprint;
|
2013-11-22 19:47:10 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* PCB_BASE_FRAME::loadFootprint( const LIB_ID& aFootprintId )
|
2013-04-25 16:29:35 +00:00
|
|
|
{
|
2023-09-28 03:15:54 +00:00
|
|
|
FP_LIB_TABLE* fptbl = PROJECT_PCB::PcbFootprintLibs( &Prj() );
|
* 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
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
wxCHECK_MSG( fptbl, nullptr, wxT( "Cannot look up LIB_ID in NULL FP_LIB_TABLE." ) );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT *footprint = nullptr;
|
2020-12-04 12:13:11 +00:00
|
|
|
|
2021-03-30 09:38:03 +00:00
|
|
|
// When loading a footprint from a library in the footprint editor
|
|
|
|
// the items UUIDs must be keep and not reinitialized
|
|
|
|
bool keepUUID = IsType( FRAME_FOOTPRINT_EDITOR );
|
|
|
|
|
2017-07-27 12:49:06 +00:00
|
|
|
try
|
|
|
|
{
|
2021-03-30 09:38:03 +00:00
|
|
|
footprint = fptbl->FootprintLoadWithOptionalNickname( aFootprintId, keepUUID );
|
2017-07-27 12:49:06 +00:00
|
|
|
}
|
2020-08-18 14:17:16 +00:00
|
|
|
catch( const IO_ERROR& )
|
2017-07-27 12:49:06 +00:00
|
|
|
{
|
|
|
|
}
|
2015-02-17 16:32:47 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
if( footprint )
|
2023-05-24 12:39:25 +00:00
|
|
|
{
|
|
|
|
// If the footprint is found, clear all net info to be sure there are no broken links to
|
|
|
|
// any netinfo list (should be not needed, but it can be edited from the footprint editor )
|
2020-11-10 21:20:03 +00:00
|
|
|
footprint->ClearAllNets();
|
2015-02-17 16:32:47 +00:00
|
|
|
|
2023-07-10 16:15:37 +00:00
|
|
|
if( m_pcb && !m_pcb->IsFootprintHolder() )
|
2023-07-08 23:55:27 +00:00
|
|
|
{
|
2023-10-02 21:10:13 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_pcb->GetDesignSettings();
|
|
|
|
|
|
|
|
footprint->ApplyDefaultSettings( *m_pcb, bds.m_StyleFPFields, bds.m_StyleFPText,
|
|
|
|
bds.m_StyleFPShapes );
|
2023-07-08 23:55:27 +00:00
|
|
|
}
|
2023-05-24 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
return footprint;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* FOOTPRINT_EDIT_FRAME::SelectFootprintFromBoard( BOARD* aPcb )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
static wxString oldName; // Save name of last footprint selected.
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-11-18 19:27:27 +00:00
|
|
|
wxString fpname;
|
|
|
|
wxString msg;
|
|
|
|
wxArrayString listnames;
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : aPcb->Footprints() )
|
2020-11-10 21:20:03 +00:00
|
|
|
listnames.Add( footprint->GetReference() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2015-11-17 16:18:00 +00:00
|
|
|
msg.Printf( _( "Footprints [%u items]" ), (unsigned) listnames.GetCount() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString headers;
|
2013-11-18 19:27:27 +00:00
|
|
|
|
2015-11-17 16:18:00 +00:00
|
|
|
headers.Add( _( "Footprint" ) );
|
2013-11-18 19:27:27 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
2013-04-10 07:23:20 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
// Conversion from wxArrayString to vector of ArrayString
|
|
|
|
for( unsigned i = 0; i < listnames.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
wxArrayString item;
|
2013-11-18 19:27:27 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
item.Add( listnames[i] );
|
|
|
|
itemsToDisplay.push_back( item );
|
2013-04-10 07:23:20 +00:00
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, msg, headers, itemsToDisplay, wxEmptyString );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
2013-11-18 19:27:27 +00:00
|
|
|
fpname = dlg.GetTextSelection();
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2021-04-22 21:20:34 +00:00
|
|
|
return nullptr;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-11-18 19:27:27 +00:00
|
|
|
oldName = fpname;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2022-08-15 17:47:23 +00:00
|
|
|
for( FOOTPRINT* fp : aPcb->Footprints() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2022-08-15 17:47:23 +00:00
|
|
|
if( fpname == fp->GetReference() )
|
|
|
|
return fp;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 00:15:57 +00:00
|
|
|
return nullptr;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::SaveLibraryAs( const wxString& aLibraryPath )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2022-04-19 18:09:19 +00:00
|
|
|
const wxString& curLibPath = aLibraryPath;
|
|
|
|
wxString dstLibPath = CreateNewLibrary( wxEmptyString, aLibraryPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
if( !dstLibPath )
|
2018-07-29 15:33:58 +00:00
|
|
|
return false; // user aborted in CreateNewLibrary()
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2014-12-11 12:00:59 +00:00
|
|
|
wxBusyCursor dummy;
|
|
|
|
wxString msg;
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::PCB_FILE_T dstType = PCB_IO_MGR::GuessPluginTypeFromLibPath( dstLibPath );
|
|
|
|
PCB_IO_MGR::PCB_FILE_T curType = PCB_IO_MGR::GuessPluginTypeFromLibPath( curLibPath );
|
2023-08-26 19:28:53 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
if( dstType == PCB_IO_MGR::FILE_TYPE_NONE )
|
|
|
|
dstType = PCB_IO_MGR::KICAD_SEXP;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-12-27 20:39:29 +00:00
|
|
|
IO_RELEASER<PCB_IO> cur( PCB_IO_MGR::PluginFind( curType ) );
|
|
|
|
IO_RELEASER<PCB_IO> dst( PCB_IO_MGR::PluginFind( dstType ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( !cur )
|
|
|
|
{
|
2023-08-31 08:27:36 +00:00
|
|
|
msg = wxString::Format( _( "Unable to find a reader for '%s'." ), curLibPath );
|
2023-08-26 19:28:53 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !dst )
|
|
|
|
{
|
2023-08-31 08:27:36 +00:00
|
|
|
msg = wxString::Format( _( "Unable to find a writer for '%s'." ), dstLibPath );
|
2023-08-26 19:28:53 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
wxArrayString footprints;
|
2017-06-11 20:20:44 +00:00
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
cur->FootprintEnumerate( footprints, curLibPath, false );
|
2014-12-11 12:00:59 +00:00
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
for( unsigned i = 0; i < footprints.size(); ++i )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* footprint = cur->GetEnumeratedFootprint( curLibPath, footprints[i] );
|
2018-07-29 15:33:58 +00:00
|
|
|
dst->FootprintSave( dstLibPath, footprint );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2021-06-28 23:44:07 +00:00
|
|
|
msg = wxString::Format( _( "Footprint '%s' saved." ), footprints[i] );
|
2014-12-11 12:00:59 +00:00
|
|
|
SetStatusText( msg );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
DisplayError( this, ioe.What() );
|
2018-07-29 15:33:58 +00:00
|
|
|
return false;
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2021-06-28 23:44:07 +00:00
|
|
|
msg = wxString::Format( _( "Footprint library '%s' saved as '%s'." ),
|
2019-05-28 23:23:58 +00:00
|
|
|
curLibPath,
|
|
|
|
dstLibPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
DisplayInfoMessage( this, msg );
|
2014-12-11 12:00:59 +00:00
|
|
|
|
|
|
|
SetStatusText( wxEmptyString );
|
2018-07-29 15:33:58 +00:00
|
|
|
return true;
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
2019-05-28 23:23:58 +00:00
|
|
|
|
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
static FOOTPRINT* s_FootprintInitialCopy = nullptr; // Copy of footprint for abort/undo command
|
2019-05-28 23:23:58 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
static PICKED_ITEMS_LIST s_PickedList; // A pick-list to save initial footprint
|
|
|
|
// and dragged tracks
|
2019-05-28 23:23:58 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* PCB_BASE_FRAME::GetFootprintFromBoardByReference()
|
2019-05-28 23:23:58 +00:00
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
wxString footprintName;
|
2019-05-28 23:23:58 +00:00
|
|
|
wxArrayString fplist;
|
|
|
|
|
|
|
|
// Build list of available fp references, to display them in dialog
|
2022-02-04 22:44:59 +00:00
|
|
|
for( FOOTPRINT* fp : GetBoard()->Footprints() )
|
|
|
|
fplist.Add( fp->GetReference() + wxT( " ( " ) + fp->GetValue() + wxT( " )" ) );
|
2019-05-28 23:23:58 +00:00
|
|
|
|
|
|
|
fplist.Sort();
|
|
|
|
|
|
|
|
DIALOG_GET_FOOTPRINT_BY_NAME dlg( this, fplist );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK ) //Aborted by user
|
2021-04-22 21:20:34 +00:00
|
|
|
return nullptr;
|
2019-05-28 23:23:58 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
footprintName = dlg.GetValue();
|
|
|
|
footprintName.Trim( true );
|
|
|
|
footprintName.Trim( false );
|
2019-05-28 23:23:58 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
if( !footprintName.IsEmpty() )
|
2019-05-28 23:23:58 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
for( FOOTPRINT* fp : GetBoard()->Footprints() )
|
2019-05-28 23:23:58 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
if( fp->GetReference().CmpNoCase( footprintName ) == 0 )
|
|
|
|
return fp;
|
2019-05-28 23:23:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 00:15:57 +00:00
|
|
|
return nullptr;
|
2019-05-28 23:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void PCB_BASE_FRAME::PlaceFootprint( FOOTPRINT* aFootprint, bool aRecreateRatsnest )
|
2019-05-28 23:23:58 +00:00
|
|
|
{
|
2021-04-22 21:20:34 +00:00
|
|
|
if( aFootprint == nullptr )
|
2019-05-28 23:23:58 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
OnModify();
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
if( aFootprint->IsNew() )
|
2019-05-28 23:23:58 +00:00
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
SaveCopyInUndoList( aFootprint, UNDO_REDO::NEWITEM );
|
2019-05-28 23:23:58 +00:00
|
|
|
}
|
2020-11-10 21:20:03 +00:00
|
|
|
else if( aFootprint->IsMoving() )
|
2019-05-28 23:23:58 +00:00
|
|
|
{
|
2020-11-10 21:20:03 +00:00
|
|
|
ITEM_PICKER picker( nullptr, aFootprint, UNDO_REDO::CHANGED );
|
|
|
|
picker.SetLink( s_FootprintInitialCopy );
|
2019-05-28 23:23:58 +00:00
|
|
|
s_PickedList.PushItem( picker );
|
2021-04-22 21:20:34 +00:00
|
|
|
s_FootprintInitialCopy = nullptr; // the picker is now owner of s_ModuleInitialCopy.
|
2019-05-28 23:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( s_PickedList.GetCount() )
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
SaveCopyInUndoList( s_PickedList, UNDO_REDO::UNSPECIFIED );
|
2019-05-28 23:23:58 +00:00
|
|
|
|
|
|
|
// Clear list, but DO NOT delete items, because they are owned by the saved undo
|
|
|
|
// list and they therefore in use
|
|
|
|
s_PickedList.ClearItemsList();
|
|
|
|
}
|
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
aFootprint->SetPosition( GetCanvas()->GetViewControls()->GetCursorPosition() );
|
2020-11-10 21:20:03 +00:00
|
|
|
aFootprint->ClearFlags();
|
2019-05-28 23:23:58 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
delete s_FootprintInitialCopy;
|
2021-04-22 21:20:34 +00:00
|
|
|
s_FootprintInitialCopy = nullptr;
|
2019-05-28 23:23:58 +00:00
|
|
|
|
|
|
|
if( aRecreateRatsnest )
|
2020-11-10 21:20:03 +00:00
|
|
|
m_pcb->GetConnectivity()->Update( aFootprint );
|
2019-05-28 23:23:58 +00:00
|
|
|
|
2019-06-13 00:32:47 +00:00
|
|
|
if( aRecreateRatsnest )
|
2019-05-30 15:11:17 +00:00
|
|
|
Compile_Ratsnest( true );
|
2019-05-28 23:23:58 +00:00
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
SetMsgPanel( aFootprint );
|
2019-05-28 23:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|