2012-06-08 09:56:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-10-25 16:58:04 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2013-11-22 19:47:10 +00:00
|
|
|
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2017-11-12 00:31:38 +00:00
|
|
|
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
|
2018-02-06 09:54:11 +00:00
|
|
|
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-08 09:56:42 +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
|
|
|
|
*/
|
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
#include <bitmaps.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <board_commit.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <dialog_exchange_footprints.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <kiway.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <pcb_group.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2014-05-09 18:35:48 +00:00
|
|
|
#include <project.h>
|
2017-08-18 18:26:45 +00:00
|
|
|
#include <wx_html_report_panel.h>
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
|
2020-11-24 11:59:12 +00:00
|
|
|
#define ID_MATCH_FP_ALL 4200
|
2018-10-22 15:01:29 +00:00
|
|
|
#define ID_MATCH_FP_SELECTED 4201
|
2020-11-24 11:59:12 +00:00
|
|
|
#define ID_MATCH_FP_REF 4202
|
|
|
|
#define ID_MATCH_FP_VAL 4203
|
|
|
|
#define ID_MATCH_FP_ID 4204
|
2018-02-05 19:46:55 +00:00
|
|
|
|
2018-10-15 15:09:03 +00:00
|
|
|
|
|
|
|
int g_matchModeForUpdate = ID_MATCH_FP_ALL;
|
2018-10-22 15:01:29 +00:00
|
|
|
int g_matchModeForUpdateSelected = ID_MATCH_FP_SELECTED;
|
2018-10-15 15:09:03 +00:00
|
|
|
int g_matchModeForExchange = ID_MATCH_FP_REF;
|
2018-10-22 15:01:29 +00:00
|
|
|
int g_matchModeForExchangeSelected = ID_MATCH_FP_SELECTED;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-11-24 11:59:12 +00:00
|
|
|
// { update, change }
|
|
|
|
bool g_removeExtraTextItems[2] = { false, false };
|
|
|
|
bool g_resetTextItemLayers[2] = { false, true };
|
|
|
|
bool g_resetTextItemEffects[2] = { false, true };
|
|
|
|
bool g_resetFabricationAttrs[2] = { false, true };
|
|
|
|
bool g_reset3DModels[2] = { true, true };
|
2019-11-05 17:38:29 +00:00
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS( PCB_EDIT_FRAME* aParent,
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* aFootprint,
|
2018-10-22 15:01:29 +00:00
|
|
|
bool updateMode, bool selectedMode ) :
|
2020-10-14 23:37:26 +00:00
|
|
|
DIALOG_EXCHANGE_FOOTPRINTS_BASE( aParent ),
|
|
|
|
m_commit( aParent ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_currentFootprint( aFootprint ),
|
|
|
|
m_updateMode( updateMode )
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
2020-10-30 19:48:22 +00:00
|
|
|
if( !updateMode )
|
|
|
|
{
|
|
|
|
SetTitle( _( "Change Footprints" ) );
|
|
|
|
m_matchAll->SetLabel( _( "Change all footprints on board" ) );
|
2021-06-17 22:34:19 +00:00
|
|
|
m_matchSelected->SetLabel( _( "Change selected footprint(s)" ) );
|
2020-10-30 19:48:22 +00:00
|
|
|
m_matchSpecifiedRef->SetLabel( _( "Change footprints matching reference designator:" ) );
|
|
|
|
m_matchSpecifiedValue->SetLabel( _( "Change footprints matching value:" ) );
|
|
|
|
m_matchSpecifiedID->SetLabel( _( "Change footprints with library id:" ) );
|
|
|
|
m_resetTextItemLayers->SetLabel( _( "Update text layers and visibilities" ) );
|
|
|
|
m_resetTextItemEffects->SetLabel( _( "Update text sizes, styles and positions" ) );
|
2020-11-24 11:59:12 +00:00
|
|
|
m_resetFabricationAttrs->SetLabel( _( "Update fabrication attributes" ) );
|
2020-10-30 19:48:22 +00:00
|
|
|
m_reset3DModels->SetLabel( _( "Update 3D models" ) );
|
|
|
|
}
|
2015-08-07 08:28:14 +00:00
|
|
|
|
2020-11-24 11:59:12 +00:00
|
|
|
#if 0 // translator hint
|
|
|
|
wxString x = _( "Update/reset strings: there are two cases these descriptions need to cover: "
|
|
|
|
"the user made overrides to a footprint on the PCB and wants to remove them, "
|
|
|
|
"or the user made changes to the library footprint and wants to propagate "
|
|
|
|
"them back to the PCB." );
|
|
|
|
#endif
|
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
if( m_updateMode )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
m_changeSizer->Show( false );
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-28 18:44:52 +00:00
|
|
|
m_upperSizer->FindItem( m_matchAll )->Show( false );
|
2021-03-08 02:59:07 +00:00
|
|
|
m_newIDBrowseButton->SetBitmap( KiBitmap( BITMAPS::small_library ) );
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
if( m_currentFootprint )
|
2018-10-22 15:01:29 +00:00
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
m_newID->AppendText( FROM_UTF8( m_currentFootprint->GetFPID().Format().c_str() ) );
|
2018-10-22 15:01:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
m_upperSizer->FindItem( m_matchSelected )->Show( false );
|
|
|
|
|
2018-10-15 15:09:03 +00:00
|
|
|
// Use ChangeValue() instead of SetValue() so we don't generate events.
|
2020-10-14 23:37:26 +00:00
|
|
|
if( m_currentFootprint )
|
|
|
|
m_specifiedRef->ChangeValue( m_currentFootprint->GetReference() );
|
2009-06-20 19:09:43 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
if( m_currentFootprint )
|
|
|
|
m_specifiedValue->ChangeValue( m_currentFootprint->GetValue() );
|
2009-06-20 19:09:43 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
if( m_currentFootprint )
|
|
|
|
m_specifiedID->ChangeValue( FROM_UTF8( m_currentFootprint->GetFPID().Format().c_str() ) );
|
2018-10-15 15:09:03 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
m_specifiedIDBrowseButton->SetBitmap( KiBitmap( BITMAPS::small_library ) );
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-01-28 18:44:52 +00:00
|
|
|
m_upperSizer->SetEmptyCellSize( wxSize( 0, 0 ) );
|
2019-11-20 16:45:30 +00:00
|
|
|
// The upper sizer has its content modified: re-layout it:
|
|
|
|
m_upperSizer->Layout();
|
2018-01-28 18:44:52 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
// initialize match-mode
|
2018-10-22 15:01:29 +00:00
|
|
|
if( m_updateMode )
|
|
|
|
m_matchMode = selectedMode ? &g_matchModeForUpdateSelected : &g_matchModeForUpdate;
|
|
|
|
else
|
|
|
|
m_matchMode = selectedMode ? &g_matchModeForExchangeSelected : &g_matchModeForExchange;
|
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
wxCommandEvent event;
|
2018-10-22 15:01:29 +00:00
|
|
|
event.SetEventObject( this );
|
|
|
|
|
|
|
|
switch( *m_matchMode )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
case ID_MATCH_FP_ALL: OnMatchAllClicked( event ); break;
|
|
|
|
case ID_MATCH_FP_SELECTED: OnMatchSelectedClicked( event ); break;
|
|
|
|
case ID_MATCH_FP_REF: OnMatchRefClicked( event ); break;
|
|
|
|
case ID_MATCH_FP_VAL: OnMatchValueClicked( event ); break;
|
|
|
|
case ID_MATCH_FP_ID: OnMatchIDClicked( event ); break;
|
|
|
|
default: break;
|
2009-06-20 19:09:43 +00:00
|
|
|
}
|
2018-04-18 09:31:33 +00:00
|
|
|
|
2020-09-15 22:52:53 +00:00
|
|
|
m_removeExtraBox->SetValue( g_removeExtraTextItems[ m_updateMode ? 0 : 1 ] );
|
|
|
|
m_resetTextItemLayers->SetValue( g_resetTextItemLayers[ m_updateMode ? 0 : 1 ] );
|
|
|
|
m_resetTextItemEffects->SetValue( g_resetTextItemEffects[ m_updateMode ? 0 : 1 ] );
|
|
|
|
m_resetFabricationAttrs->SetValue( g_resetFabricationAttrs[ m_updateMode ? 0 : 1 ] );
|
|
|
|
m_reset3DModels->SetValue( g_reset3DModels[ m_updateMode ? 0 : 1 ] );
|
2019-11-05 17:38:29 +00:00
|
|
|
|
2019-11-16 23:03:46 +00:00
|
|
|
m_MessageWindow->SetLazyUpdate( true );
|
2021-02-25 15:05:26 +00:00
|
|
|
m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
|
2019-11-16 23:03:46 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
// DIALOG_SHIM needs a unique hash_key because classname is not sufficient
|
|
|
|
// because the update and change versions of this dialog have different controls.
|
|
|
|
m_hash_key = TO_UTF8( GetTitle() );
|
|
|
|
|
|
|
|
// Ensure m_closeButton (with id = wxID_CANCEL) has the right label
|
|
|
|
// (to fix automatic renaming of button label )
|
2018-07-31 11:16:58 +00:00
|
|
|
m_sdbSizerCancel->SetLabel( _( "Close" ) );
|
2020-10-30 19:48:22 +00:00
|
|
|
|
|
|
|
if( m_updateMode )
|
|
|
|
m_sdbSizerOK->SetLabel( _( "Update" ) );
|
|
|
|
else
|
|
|
|
m_sdbSizerOK->SetLabel( _( "Change" ) );
|
|
|
|
|
2020-05-06 19:49:58 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
2018-04-18 09:31:33 +00:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
2015-07-28 15:33:18 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2019-11-05 17:38:29 +00:00
|
|
|
DIALOG_EXCHANGE_FOOTPRINTS::~DIALOG_EXCHANGE_FOOTPRINTS()
|
|
|
|
{
|
2020-09-15 22:52:53 +00:00
|
|
|
g_removeExtraTextItems[ m_updateMode ? 0 : 1 ] = m_removeExtraBox->GetValue();
|
|
|
|
g_resetTextItemLayers[ m_updateMode ? 0 : 1 ] = m_resetTextItemLayers->GetValue();
|
|
|
|
g_resetTextItemEffects[ m_updateMode ? 0 : 1 ] = m_resetTextItemEffects->GetValue();
|
|
|
|
g_resetFabricationAttrs[ m_updateMode ? 0 : 1 ] = m_resetFabricationAttrs->GetValue();
|
|
|
|
g_reset3DModels[ m_updateMode ? 0 : 1 ] = m_reset3DModels->GetValue();
|
2019-11-05 17:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool DIALOG_EXCHANGE_FOOTPRINTS::isMatch( FOOTPRINT* aFootprint )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-07-26 14:38:30 +00:00
|
|
|
LIB_ID specifiedID;
|
|
|
|
|
2018-10-22 15:01:29 +00:00
|
|
|
switch( *m_matchMode )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_ALL:
|
2018-01-12 19:36:15 +00:00
|
|
|
return true;
|
2018-10-22 15:01:29 +00:00
|
|
|
case ID_MATCH_FP_SELECTED:
|
2021-06-17 22:34:19 +00:00
|
|
|
return aFootprint == m_currentFootprint || aFootprint->IsSelected();
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_REF:
|
2020-10-14 23:37:26 +00:00
|
|
|
return WildCompareString( m_specifiedRef->GetValue(), aFootprint->GetReference(), false );
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_VAL:
|
2020-10-14 23:37:26 +00:00
|
|
|
return WildCompareString( m_specifiedValue->GetValue(), aFootprint->GetValue(), false );
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_ID:
|
2020-12-17 23:32:23 +00:00
|
|
|
specifiedID.Parse( m_specifiedID->GetValue() );
|
2020-10-14 23:37:26 +00:00
|
|
|
return aFootprint->GetFPID() == specifiedID;
|
2018-10-15 15:09:03 +00:00
|
|
|
default:
|
|
|
|
return false; // just to quiet compiler warnings....
|
2015-07-28 15:33:18 +00:00
|
|
|
}
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
2015-07-28 15:33:18 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
wxRadioButton* DIALOG_EXCHANGE_FOOTPRINTS::getRadioButtonForMode()
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
switch( *m_matchMode )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
case ID_MATCH_FP_ALL: return m_matchAll;
|
|
|
|
case ID_MATCH_FP_SELECTED: return m_matchSelected;
|
|
|
|
case ID_MATCH_FP_REF: return m_matchSpecifiedRef;
|
|
|
|
case ID_MATCH_FP_VAL: return m_matchSpecifiedValue;
|
|
|
|
case ID_MATCH_FP_ID: return m_matchSpecifiedID;
|
|
|
|
default: return nullptr;
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::updateMatchModeRadioButtons( wxUpdateUIEvent& )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-02-10 16:07:02 +00:00
|
|
|
wxRadioButton* rb_button = getRadioButtonForMode();
|
|
|
|
|
|
|
|
wxRadioButton* rb_butt_list[] =
|
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
m_matchAll,
|
|
|
|
m_matchSelected,
|
2018-10-15 15:09:03 +00:00
|
|
|
m_matchSpecifiedRef,
|
|
|
|
m_matchSpecifiedValue,
|
|
|
|
m_matchSpecifiedID,
|
2018-02-10 16:07:02 +00:00
|
|
|
nullptr // end of list
|
|
|
|
};
|
|
|
|
|
|
|
|
// Ensure the button state is ok. Only one button can be checked
|
|
|
|
// Change button state only if its state is incorrect, otherwise
|
|
|
|
// we have issues depending on the platform.
|
|
|
|
for( int ii = 0; rb_butt_list[ii]; ++ii )
|
|
|
|
{
|
|
|
|
bool state = rb_butt_list[ii] == rb_button;
|
|
|
|
|
|
|
|
if( rb_butt_list[ii]->GetValue() != state )
|
|
|
|
rb_butt_list[ii]->SetValue( state );
|
|
|
|
}
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::OnMatchAllClicked( wxCommandEvent& event )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
*m_matchMode = ID_MATCH_FP_ALL;
|
|
|
|
|
|
|
|
if( event.GetEventObject() == this )
|
|
|
|
SetInitialFocus( m_matchAll );
|
|
|
|
else
|
|
|
|
m_matchAll->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::OnMatchSelectedClicked( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
*m_matchMode = ID_MATCH_FP_SELECTED;
|
|
|
|
|
|
|
|
if( event.GetEventObject() == this )
|
|
|
|
SetInitialFocus( m_matchSelected );
|
|
|
|
else
|
|
|
|
m_matchSelected->SetFocus();
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-10 16:07:02 +00:00
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::OnMatchRefClicked( wxCommandEvent& event )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
*m_matchMode = ID_MATCH_FP_REF;
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-10-22 15:01:29 +00:00
|
|
|
if( event.GetEventObject() == this )
|
|
|
|
SetInitialFocus( m_specifiedRef );
|
|
|
|
else if( event.GetEventObject() != m_specifiedRef )
|
2018-01-12 19:36:15 +00:00
|
|
|
m_specifiedRef->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::OnMatchValueClicked( wxCommandEvent& event )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
*m_matchMode = ID_MATCH_FP_VAL;
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-10-22 15:01:29 +00:00
|
|
|
if( event.GetEventObject() == this )
|
|
|
|
SetInitialFocus( m_specifiedValue );
|
|
|
|
else if( event.GetEventObject() != m_specifiedValue )
|
2018-01-12 19:36:15 +00:00
|
|
|
m_specifiedValue->SetFocus();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::OnMatchIDClicked( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-10-22 15:01:29 +00:00
|
|
|
*m_matchMode = ID_MATCH_FP_ID;
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-10-22 15:01:29 +00:00
|
|
|
if( event.GetEventObject() == this )
|
|
|
|
SetInitialFocus( m_specifiedID );
|
|
|
|
else if( event.GetEventObject() != m_specifiedID )
|
2018-01-12 19:36:15 +00:00
|
|
|
m_specifiedID->SetFocus();
|
|
|
|
}
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2020-05-06 19:49:58 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::OnOKClicked( wxCommandEvent& event )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
wxBusyCursor dummy;
|
2018-01-12 19:36:15 +00:00
|
|
|
|
|
|
|
m_MessageWindow->Clear();
|
2019-11-16 23:03:46 +00:00
|
|
|
m_MessageWindow->Flush( false );
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
if( processMatchingFootprints() )
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
2019-06-13 00:32:47 +00:00
|
|
|
m_parent->Compile_Ratsnest( true );
|
2019-06-13 17:28:55 +00:00
|
|
|
m_parent->GetCanvas()->Refresh();
|
2009-06-20 19:09:43 +00:00
|
|
|
}
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2019-11-16 23:03:46 +00:00
|
|
|
m_MessageWindow->Flush( false );
|
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
m_commit.Push( wxT( "Changed footprint" ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
bool DIALOG_EXCHANGE_FOOTPRINTS::processMatchingFootprints()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-06 07:11:04 +00:00
|
|
|
bool change = false;
|
2018-07-26 14:38:30 +00:00
|
|
|
LIB_ID newFPID;
|
2013-09-08 18:31:21 +00:00
|
|
|
wxString value;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( m_parent->GetBoard()->Footprints().empty() )
|
2015-07-28 15:33:18 +00:00
|
|
|
return false;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
if( !m_updateMode )
|
|
|
|
{
|
2020-12-17 23:32:23 +00:00
|
|
|
newFPID.Parse( m_newID->GetValue() );
|
2018-07-26 14:38:30 +00:00
|
|
|
|
|
|
|
if( !newFPID.IsValid() )
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
/* The change is done from the last footprint because processFootprint() modifies the last
|
|
|
|
* item in the list.
|
2009-06-20 19:09:43 +00:00
|
|
|
*/
|
2020-11-12 23:50:33 +00:00
|
|
|
for( auto it = m_parent->GetBoard()->Footprints().rbegin();
|
|
|
|
it != m_parent->GetBoard()->Footprints().rend(); it++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2019-05-31 00:15:57 +00:00
|
|
|
auto mod = *it;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2019-05-31 00:15:57 +00:00
|
|
|
if( !isMatch( mod ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
if( m_updateMode )
|
2018-04-18 09:31:33 +00:00
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( processFootprint( mod, mod->GetFPID() ) )
|
2018-04-18 09:31:33 +00:00
|
|
|
change = true;
|
|
|
|
}
|
2018-01-12 19:36:15 +00:00
|
|
|
else
|
2018-04-18 09:31:33 +00:00
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
if( processFootprint( mod, newFPID ) )
|
2018-04-18 09:31:33 +00:00
|
|
|
change = true;
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
return change;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
bool DIALOG_EXCHANGE_FOOTPRINTS::processFootprint( FOOTPRINT* aFootprint, const LIB_ID& aNewFPID )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
LIB_ID oldFPID = aFootprint->GetFPID();
|
2018-04-18 09:31:33 +00:00
|
|
|
wxString msg;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
// Load new footprint.
|
2020-11-23 21:51:27 +00:00
|
|
|
if( m_updateMode )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Update footprint %s from '%s' to '%s'" ),
|
|
|
|
aFootprint->GetReference(),
|
|
|
|
oldFPID.Format().c_str(),
|
|
|
|
aNewFPID.Format().c_str() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Change footprint %s from '%s' to '%s'" ),
|
|
|
|
aFootprint->GetReference(),
|
|
|
|
oldFPID.Format().c_str(),
|
|
|
|
aNewFPID.Format().c_str() );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* newFootprint = m_parent->LoadFootprint( aNewFPID );
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
if( !newFootprint )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
msg << ": " << _( "*** footprint not found ***" );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_MessageWindow->Report( msg, RPT_SEVERITY_ERROR );
|
2009-08-06 07:11:04 +00:00
|
|
|
return false;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
m_parent->ExchangeFootprint( aFootprint, newFootprint, m_commit,
|
|
|
|
m_removeExtraBox->GetValue(),
|
|
|
|
m_resetTextItemLayers->GetValue(),
|
|
|
|
m_resetTextItemEffects->GetValue(),
|
|
|
|
m_resetFabricationAttrs->GetValue(),
|
2020-11-24 22:16:41 +00:00
|
|
|
m_reset3DModels->GetValue() );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
if( aFootprint == m_currentFootprint )
|
|
|
|
m_currentFootprint = newFootprint;
|
2018-04-18 09:31:33 +00:00
|
|
|
|
2017-08-18 18:26:45 +00:00
|
|
|
msg += ": OK";
|
2020-03-04 09:48:18 +00:00
|
|
|
m_MessageWindow->Report( msg, RPT_SEVERITY_ACTION );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void processTextItem( const FP_TEXT& aSrc, FP_TEXT& aDest,
|
2018-04-18 09:31:33 +00:00
|
|
|
bool resetText, bool resetTextLayers, bool resetTextEffects )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
if( !resetText )
|
|
|
|
aDest.SetText( aSrc.GetText() );
|
|
|
|
|
|
|
|
if( !resetTextLayers )
|
|
|
|
{
|
|
|
|
aDest.SetLayer( aSrc.GetLayer() );
|
|
|
|
aDest.SetVisible( aSrc.IsVisible() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !resetTextEffects )
|
2019-07-11 17:19:05 +00:00
|
|
|
{
|
|
|
|
// Careful: the visible bit is also in Effects
|
|
|
|
bool visible = aDest.IsVisible();
|
2018-04-18 09:31:33 +00:00
|
|
|
aDest.SetEffects( aSrc );
|
2019-07-11 17:19:05 +00:00
|
|
|
aDest.SetVisible( visible );
|
|
|
|
}
|
2021-03-09 12:24:28 +00:00
|
|
|
|
|
|
|
aDest.SetLocked( aSrc.IsLocked() );
|
2018-04-18 09:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FP_TEXT* getMatchingTextItem( FP_TEXT* aRefItem, FOOTPRINT* aFootprint )
|
2018-04-18 09:31:33 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<FP_TEXT*> candidates;
|
2020-05-04 23:11:32 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
|
2018-04-18 09:31:33 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* candidate = dyn_cast<FP_TEXT*>( item );
|
2018-10-15 15:09:03 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
if( candidate && candidate->GetText() == aRefItem->GetText() )
|
2020-05-04 23:11:32 +00:00
|
|
|
candidates.push_back( candidate );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( candidates.size() == 0 )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if( candidates.size() == 1 )
|
|
|
|
return candidates[0];
|
|
|
|
|
|
|
|
// Try refining the match by layer
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<FP_TEXT*> candidatesOnSameLayer;
|
2020-05-04 23:11:32 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
for( FP_TEXT* candidate : candidates )
|
2020-05-04 23:11:32 +00:00
|
|
|
{
|
|
|
|
if( candidate->GetLayer() == aRefItem->GetLayer() )
|
|
|
|
candidatesOnSameLayer.push_back( candidate );
|
2018-04-18 09:31:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 23:11:32 +00:00
|
|
|
if( candidatesOnSameLayer.size() == 1 )
|
|
|
|
return candidatesOnSameLayer[0];
|
|
|
|
|
|
|
|
// Last ditch effort: refine by position
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<FP_TEXT*> candidatesAtSamePos;
|
2020-05-04 23:11:32 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
for( FP_TEXT* candidate : candidatesOnSameLayer.size() ? candidatesOnSameLayer : candidates )
|
2020-05-04 23:11:32 +00:00
|
|
|
{
|
|
|
|
if( candidate->GetPos0() == aRefItem->GetPos0() )
|
|
|
|
candidatesAtSamePos.push_back( candidate );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( candidatesAtSamePos.size() > 0 )
|
|
|
|
return candidatesAtSamePos[0];
|
|
|
|
else if( candidatesOnSameLayer.size() > 0 )
|
|
|
|
return candidatesOnSameLayer[0];
|
|
|
|
else
|
|
|
|
return candidates[0];
|
2018-04-18 09:31:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 18:52:49 +00:00
|
|
|
#include <wx/log.h>
|
2020-11-13 15:15:52 +00:00
|
|
|
void PCB_EDIT_FRAME::ExchangeFootprint( FOOTPRINT* aExisting, FOOTPRINT* aNew,
|
|
|
|
BOARD_COMMIT& aCommit, bool deleteExtraTexts,
|
|
|
|
bool resetTextLayers, bool resetTextEffects,
|
|
|
|
bool resetFabricationAttrs, bool reset3DModels )
|
2018-04-18 09:31:33 +00:00
|
|
|
{
|
2020-09-25 17:37:03 +00:00
|
|
|
PCB_GROUP* parentGroup = aExisting->GetParentGroup();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
if( parentGroup )
|
|
|
|
{
|
|
|
|
parentGroup->RemoveItem( aExisting );
|
|
|
|
parentGroup->AddItem( aNew );
|
|
|
|
}
|
|
|
|
|
|
|
|
aNew->SetParent( GetBoard() );
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
PlaceFootprint( aNew, false );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2021-01-25 13:58:30 +00:00
|
|
|
// PlaceFootprint will move the footprint to the cursor position, which we don't want. Copy
|
2019-07-31 22:57:30 +00:00
|
|
|
// the original position across.
|
2020-09-25 17:37:03 +00:00
|
|
|
aNew->SetPosition( aExisting->GetPosition() );
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
if( aNew->GetLayer() != aExisting->GetLayer() )
|
2020-09-30 22:02:05 +00:00
|
|
|
aNew->Flip( aNew->GetPosition(), m_settings->m_FlipLeftRight );
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
if( aNew->GetOrientation() != aExisting->GetOrientation() )
|
|
|
|
aNew->SetOrientation( aExisting->GetOrientation() );
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
aNew->SetLocked( aExisting->IsLocked() );
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2021-08-16 18:52:49 +00:00
|
|
|
// Now transfer the net info from "old" pads to the new footprint
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : aNew->Pads() )
|
2019-07-12 21:02:10 +00:00
|
|
|
{
|
2021-08-16 18:52:49 +00:00
|
|
|
PAD* pad_model = nullptr;
|
|
|
|
|
|
|
|
// Skip pad not on a copper layer, because we only want to transfer the net info
|
|
|
|
if( !pad->IsOnCopperLayer() )
|
|
|
|
continue;
|
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
// Pads with no numbers are never connected to a net
|
|
|
|
if( pad->GetNumber().IsEmpty() )
|
2021-08-16 18:52:49 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Search for a similar pad on a copper layer, to reuse net info
|
|
|
|
PAD* last_pad = nullptr;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
pad_model = aExisting->FindPadByNumber( pad->GetNumber(), last_pad );
|
2021-08-16 18:52:49 +00:00
|
|
|
|
|
|
|
if( !pad_model )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( pad_model->IsOnCopperLayer() ) // a candidate is found
|
|
|
|
break;
|
|
|
|
|
|
|
|
last_pad = pad_model;
|
|
|
|
}
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2021-08-16 18:52:49 +00:00
|
|
|
if( pad_model )
|
2019-07-22 01:48:38 +00:00
|
|
|
{
|
2021-08-16 18:52:49 +00:00
|
|
|
pad->SetLocalRatsnestVisible( pad_model->GetLocalRatsnestVisible() );
|
|
|
|
pad->SetPinFunction( pad_model->GetPinFunction() );
|
2019-07-22 01:48:38 +00:00
|
|
|
}
|
2021-03-01 11:12:03 +00:00
|
|
|
|
2021-08-16 18:52:49 +00:00
|
|
|
pad->SetNetCode( pad_model ? pad_model->GetNetCode() : NETINFO_LIST::UNCONNECTED );
|
2019-07-12 21:02:10 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2018-05-10 11:14:54 +00:00
|
|
|
// Copy reference
|
2020-09-25 17:37:03 +00:00
|
|
|
processTextItem( aExisting->Reference(), aNew->Reference(),
|
2018-04-18 09:31:33 +00:00
|
|
|
// never reset reference text
|
|
|
|
false,
|
|
|
|
resetTextLayers, resetTextEffects );
|
|
|
|
|
|
|
|
// Copy value
|
2020-09-25 17:37:03 +00:00
|
|
|
processTextItem( aExisting->Value(), aNew->Value(),
|
2018-04-18 09:31:33 +00:00
|
|
|
// reset value text only when it is a proxy for the footprint ID
|
|
|
|
// (cf replacing value "MountingHole-2.5mm" with "MountingHole-4.0mm")
|
2020-09-25 17:37:03 +00:00
|
|
|
aExisting->GetValue() == aExisting->GetFPID().GetLibItemName(),
|
2018-04-18 09:31:33 +00:00
|
|
|
resetTextLayers, resetTextEffects );
|
|
|
|
|
|
|
|
// Copy fields in accordance with the reset* flags
|
2020-09-25 17:37:03 +00:00
|
|
|
for( BOARD_ITEM* item : aExisting->GraphicalItems() )
|
2017-01-23 20:30:11 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* srcItem = dyn_cast<FP_TEXT*>( item );
|
2018-04-18 09:31:33 +00:00
|
|
|
|
|
|
|
if( srcItem )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* destItem = getMatchingTextItem( srcItem, aNew );
|
2018-04-18 09:31:33 +00:00
|
|
|
|
|
|
|
if( destItem )
|
|
|
|
processTextItem( *srcItem, *destItem, false, resetTextLayers, resetTextEffects );
|
|
|
|
else if( !deleteExtraTexts )
|
2020-10-04 23:34:59 +00:00
|
|
|
aNew->Add( new FP_TEXT( *srcItem ) );
|
2018-04-18 09:31:33 +00:00
|
|
|
}
|
2017-01-23 20:30:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
if( !resetFabricationAttrs )
|
2020-09-25 17:37:03 +00:00
|
|
|
aNew->SetAttributes( aExisting->GetAttributes() );
|
2020-08-26 21:43:38 +00:00
|
|
|
|
2019-08-25 21:10:15 +00:00
|
|
|
// Copy 3D model settings in accordance with the reset* flag
|
|
|
|
if( !reset3DModels )
|
2020-09-25 17:37:03 +00:00
|
|
|
aNew->Models() = aExisting->Models(); // Linked list of 3D models.
|
2019-08-25 21:10:15 +00:00
|
|
|
|
2019-07-12 21:02:10 +00:00
|
|
|
// Updating other parameters
|
2020-09-25 17:37:03 +00:00
|
|
|
const_cast<KIID&>( aNew->m_Uuid ) = aExisting->m_Uuid;
|
|
|
|
aNew->SetProperties( aExisting->GetProperties() );
|
|
|
|
aNew->SetPath( aExisting->GetPath() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
aCommit.Remove( aExisting );
|
|
|
|
aCommit.Add( aNew );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
aNew->ClearFlags();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::ViewAndSelectFootprint( wxCommandEvent& event )
|
2015-06-22 17:21:34 +00:00
|
|
|
{
|
2018-12-16 21:03:58 +00:00
|
|
|
wxString newname = m_newID->GetValue();
|
2015-06-22 17:21:34 +00:00
|
|
|
|
2019-09-05 22:00:47 +00:00
|
|
|
KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_VIEWER_MODAL, true );
|
2015-06-22 17:21:34 +00:00
|
|
|
|
|
|
|
if( frame->ShowModal( &newname, this ) )
|
|
|
|
{
|
2018-01-12 19:36:15 +00:00
|
|
|
if( event.GetEventObject() == m_newIDBrowseButton )
|
|
|
|
m_newID->SetValue( newname );
|
|
|
|
else
|
|
|
|
m_specifiedID->SetValue( newname );
|
2015-06-22 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|