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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <macros.h>
|
2016-08-17 15:24:04 +00:00
|
|
|
#include <board_commit.h>
|
2018-01-12 19:36:15 +00:00
|
|
|
#include <bitmaps.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.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>
|
2015-06-22 17:21:34 +00:00
|
|
|
#include <kiway.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
#include <dialog_exchange_footprints.h>
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
|
2018-02-06 09:54:11 +00:00
|
|
|
#define ID_MATCH_FP_ALL 4200
|
|
|
|
#define ID_MATCH_FP_REF 4201
|
|
|
|
#define ID_MATCH_FP_VAL 4202
|
|
|
|
#define ID_MATCH_FP_ID 4203
|
2018-02-05 19:46:55 +00:00
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
int DIALOG_EXCHANGE_FOOTPRINTS::m_matchModeForUpdate = ID_MATCH_FP_ALL;
|
|
|
|
int DIALOG_EXCHANGE_FOOTPRINTS::m_matchModeForExchange = ID_MATCH_FP_REF;
|
|
|
|
int DIALOG_EXCHANGE_FOOTPRINTS::m_matchModeForUpdateSelected = ID_MATCH_FP_REF;
|
|
|
|
int DIALOG_EXCHANGE_FOOTPRINTS::m_matchModeForExchangeSelected = ID_MATCH_FP_REF;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS( PCB_EDIT_FRAME* aParent, MODULE* aModule,
|
|
|
|
bool updateMode ) :
|
|
|
|
DIALOG_EXCHANGE_FOOTPRINTS_BASE( aParent ),
|
|
|
|
m_commit( aParent ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_currentModule( aModule ),
|
|
|
|
m_updateMode( updateMode )
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
2018-01-28 18:44:52 +00:00
|
|
|
wxString title = updateMode ? _( "Update Footprints from Library" ) : _( "Change Footprints" );
|
|
|
|
wxString verb = updateMode ? _( "Update" ) : _( "Change" );
|
2018-01-12 19:36:15 +00:00
|
|
|
wxString label;
|
2015-08-07 08:28:14 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
SetTitle( title );
|
2015-08-07 08:28:14 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
if( m_updateMode )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
|
|
|
label.Printf( m_matchAll->GetLabel(), verb );
|
|
|
|
m_matchAll->SetLabel( label );
|
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 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
if( m_currentModule )
|
2018-04-18 09:31:33 +00:00
|
|
|
{
|
2018-01-12 19:36:15 +00:00
|
|
|
m_newID->AppendText( FROM_UTF8( m_currentModule->GetFPID().Format().c_str() ) );
|
2018-04-18 09:31:33 +00:00
|
|
|
SetInitialFocus( m_newID );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetInitialFocus( m_specifiedRef );
|
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
m_newIDBrowseButton->SetBitmap( KiBitmap( small_library_xpm ) );
|
2018-01-12 19:36:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
if( m_currentModule )
|
|
|
|
{
|
2018-01-28 18:44:52 +00:00
|
|
|
m_upperSizer->FindItem( m_matchSpecifiedRef )->Show( false );
|
|
|
|
m_upperSizer->FindItem( m_specifiedRef )->Show( false );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
label.Printf( m_matchCurrentRef->GetLabel(), verb, m_currentModule->GetReference() );
|
|
|
|
m_matchCurrentRef->SetLabel( label );
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-01-28 18:44:52 +00:00
|
|
|
m_upperSizer->FindItem( m_matchSpecifiedValue )->Show( false );
|
|
|
|
m_upperSizer->FindItem( m_specifiedValue )->Show( false );
|
2017-08-18 18:26:45 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
label.Printf( m_matchCurrentValue->GetLabel(), verb, m_currentModule->GetValue() );
|
|
|
|
m_matchCurrentValue->SetLabel( label );
|
|
|
|
}
|
|
|
|
else
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
2018-01-28 18:44:52 +00:00
|
|
|
m_upperSizer->FindItem( m_matchCurrentRef )->Show( false );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
label.Printf( m_matchSpecifiedRef->GetLabel(), verb );
|
|
|
|
m_matchSpecifiedRef->SetLabel( label );
|
2009-06-20 19:09:43 +00:00
|
|
|
|
2018-01-28 18:44:52 +00:00
|
|
|
m_upperSizer->FindItem( m_matchCurrentValue )->Show( false );
|
2018-01-12 19:36:15 +00:00
|
|
|
|
|
|
|
label.Printf( m_matchSpecifiedValue->GetLabel(), verb );
|
|
|
|
m_matchSpecifiedValue->SetLabel( label );
|
|
|
|
}
|
2009-06-20 19:09:43 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
label.Printf( m_matchSpecifiedID->GetLabel(), verb );
|
|
|
|
m_matchSpecifiedID->SetLabel( label );
|
2018-01-28 18:44:52 +00:00
|
|
|
|
2018-09-12 15:18:01 +00:00
|
|
|
// Use ChangeValue() instead of SetValue() so we don't generate events.
|
2018-01-12 19:36:15 +00:00
|
|
|
if( m_currentModule )
|
2018-09-12 15:18:01 +00:00
|
|
|
m_specifiedID->ChangeValue( FROM_UTF8( m_currentModule->GetFPID().Format().c_str() ) );
|
2018-07-20 15:03:43 +00:00
|
|
|
m_specifiedIDBrowseButton->SetBitmap( KiBitmap( small_library_xpm ) );
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-01-28 18:44:52 +00:00
|
|
|
m_upperSizer->SetEmptyCellSize( wxSize( 0, 0 ) );
|
|
|
|
m_upperSizer->RecalcSizes();
|
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
// initialize match-mode
|
|
|
|
wxCommandEvent event;
|
|
|
|
switch( getMatchMode() )
|
|
|
|
{
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_ALL:
|
2018-01-12 19:36:15 +00:00
|
|
|
if( m_currentModule )
|
|
|
|
OnMatchRefClicked( event );
|
|
|
|
else
|
|
|
|
OnMatchAllClicked( event );
|
|
|
|
break;
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_REF:
|
2018-01-12 19:36:15 +00:00
|
|
|
OnMatchRefClicked( event );
|
2009-06-20 19:09:43 +00:00
|
|
|
break;
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_VAL:
|
2018-01-12 19:36:15 +00:00
|
|
|
OnMatchValueClicked( event );
|
|
|
|
break;
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_ID:
|
2018-01-12 19:36:15 +00:00
|
|
|
OnMatchIDClicked( event );
|
2009-06-20 19:09:43 +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" ) );
|
2018-04-18 09:31:33 +00:00
|
|
|
|
2018-07-31 11:16:58 +00:00
|
|
|
m_sdbSizerApply->SetDefault();
|
2018-04-18 09:31:33 +00:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
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
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
int DIALOG_EXCHANGE_FOOTPRINTS::getMatchMode()
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
|
|
|
if( m_updateMode )
|
|
|
|
return( m_currentModule ? m_matchModeForUpdateSelected : m_matchModeForUpdate );
|
|
|
|
else
|
|
|
|
return( m_currentModule ? m_matchModeForExchangeSelected : m_matchModeForExchange );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::setMatchMode( int aMatchMode )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
|
|
|
if( m_updateMode )
|
2015-07-28 15:33:18 +00:00
|
|
|
{
|
2018-01-12 19:36:15 +00:00
|
|
|
if( m_currentModule )
|
|
|
|
m_matchModeForUpdateSelected = aMatchMode;
|
|
|
|
else
|
|
|
|
m_matchModeForUpdate = aMatchMode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( m_currentModule )
|
|
|
|
m_matchModeForExchangeSelected = aMatchMode;
|
|
|
|
else
|
|
|
|
m_matchModeForExchange = aMatchMode;
|
|
|
|
}
|
|
|
|
}
|
2015-07-28 15:33:18 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
bool DIALOG_EXCHANGE_FOOTPRINTS::isMatch( MODULE* aModule )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-07-26 14:38:30 +00:00
|
|
|
LIB_ID specifiedID;
|
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
switch( getMatchMode() )
|
|
|
|
{
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_ALL:
|
2018-01-12 19:36:15 +00:00
|
|
|
return true;
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_REF:
|
2018-04-18 09:31:33 +00:00
|
|
|
// currentModule case goes through processCurrentModule, so we only have
|
2018-01-12 19:36:15 +00:00
|
|
|
// to handle specifiedRef case
|
|
|
|
return aModule->GetReference() == m_specifiedRef->GetValue();
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_VAL:
|
2018-01-12 19:36:15 +00:00
|
|
|
// currentValue must also check FPID so we don't get accidental matches that
|
|
|
|
// the user didn't intend
|
|
|
|
if( m_currentModule )
|
2018-04-18 09:31:33 +00:00
|
|
|
return aModule->GetValue() == m_currentModule->GetValue() && aModule->GetFPID() == m_currentModule->GetFPID();
|
2018-01-12 19:36:15 +00:00
|
|
|
else
|
|
|
|
return aModule->GetValue() == m_specifiedValue->GetValue();
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_ID:
|
2018-07-26 14:38:30 +00:00
|
|
|
specifiedID.Parse( m_specifiedID->GetValue(), LIB_ID::ID_PCB );
|
|
|
|
return aModule->GetFPID() == specifiedID;
|
2015-07-28 15:33:18 +00:00
|
|
|
}
|
2018-01-12 19:36:15 +00:00
|
|
|
return false; // just to quiet compiler warnings....
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
switch( getMatchMode() )
|
|
|
|
{
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_ALL:
|
2018-01-12 19:36:15 +00:00
|
|
|
return( m_matchAll );
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_REF:
|
2018-01-12 19:36:15 +00:00
|
|
|
return( m_matchCurrentRef->IsShown() ? m_matchCurrentRef : m_matchSpecifiedRef );
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_VAL:
|
2018-01-12 19:36:15 +00:00
|
|
|
return( m_matchCurrentValue->IsShown() ? m_matchCurrentValue : m_matchSpecifiedValue );
|
2018-02-06 09:54:11 +00:00
|
|
|
case ID_MATCH_FP_ID:
|
2018-01-12 19:36:15 +00:00
|
|
|
return( m_matchSpecifiedID );
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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[] =
|
|
|
|
{
|
|
|
|
m_matchCurrentRef, m_matchSpecifiedRef,
|
|
|
|
m_matchCurrentValue, m_matchCurrentValue,
|
|
|
|
m_matchSpecifiedValue, m_matchSpecifiedValue,
|
|
|
|
m_matchSpecifiedID, m_matchSpecifiedID,
|
|
|
|
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-02-06 09:54:11 +00:00
|
|
|
setMatchMode( ID_MATCH_FP_ALL );
|
2018-01-12 19:36:15 +00:00
|
|
|
m_matchAll->SetFocus();
|
|
|
|
}
|
|
|
|
|
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-02-06 09:54:11 +00:00
|
|
|
setMatchMode( ID_MATCH_FP_REF );
|
2018-01-12 19:36:15 +00:00
|
|
|
|
|
|
|
if( m_specifiedRef->IsShown() && event.GetEventObject() != m_specifiedRef )
|
|
|
|
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-02-06 09:54:11 +00:00
|
|
|
setMatchMode( ID_MATCH_FP_VAL );
|
2018-01-12 19:36:15 +00:00
|
|
|
|
|
|
|
if( m_specifiedValue->IsShown() && event.GetEventObject() != m_specifiedValue )
|
|
|
|
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-02-06 09:54:11 +00:00
|
|
|
setMatchMode( ID_MATCH_FP_ID );
|
2018-01-12 19:36:15 +00:00
|
|
|
|
|
|
|
if( m_specifiedID->IsShown() && event.GetEventObject() != m_specifiedID )
|
|
|
|
m_specifiedID->SetFocus();
|
|
|
|
}
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
void DIALOG_EXCHANGE_FOOTPRINTS::OnApplyClicked( wxCommandEvent& event )
|
2018-01-12 19:36:15 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
bool result = false;
|
|
|
|
wxBusyCursor dummy;
|
2018-01-12 19:36:15 +00:00
|
|
|
|
|
|
|
m_MessageWindow->Clear();
|
2018-05-21 22:28:26 +00:00
|
|
|
m_MessageWindow->Flush( true );
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-02-06 09:54:11 +00:00
|
|
|
if( getMatchMode() == ID_MATCH_FP_REF && m_currentModule )
|
2018-04-18 09:31:33 +00:00
|
|
|
result = processCurrentModule();
|
2018-01-12 19:36:15 +00:00
|
|
|
else
|
2018-04-18 09:31:33 +00:00
|
|
|
result = processMatchingModules();
|
2018-01-12 19:36:15 +00:00
|
|
|
|
|
|
|
if( result )
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
2018-01-12 19:36:15 +00:00
|
|
|
if( m_parent->GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
|
|
|
|
m_parent->Compile_Ratsnest( NULL, true );
|
2009-06-20 19:09:43 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
m_parent->GetCanvas()->Refresh();
|
2009-06-20 19:09:43 +00:00
|
|
|
}
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
m_commit.Push( wxT( "Changed footprint" ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
bool DIALOG_EXCHANGE_FOOTPRINTS::processCurrentModule()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
LIB_ID newFPID;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
if( m_updateMode )
|
|
|
|
newFPID = m_currentModule->GetFPID();
|
2013-11-24 17:48:14 +00:00
|
|
|
else
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
wxString newFPIDStr = m_newID->GetValue();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
if( newFPIDStr.IsEmpty() )
|
|
|
|
return false;
|
2018-01-12 19:36:15 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
newFPID.Parse( newFPIDStr, LIB_ID::ID_PCB, true );
|
2018-04-18 09:31:33 +00:00
|
|
|
}
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
return processModule( m_currentModule, newFPID );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
bool DIALOG_EXCHANGE_FOOTPRINTS::processMatchingModules()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-07-28 15:33:18 +00:00
|
|
|
MODULE* Module;
|
|
|
|
MODULE* PtBack;
|
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
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
if( !m_parent->GetBoard()->m_Modules )
|
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 )
|
|
|
|
{
|
|
|
|
newFPID.Parse( m_newID->GetValue(), LIB_ID::ID_PCB );
|
|
|
|
|
|
|
|
if( !newFPID.IsValid() )
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
/* The change is done from the last module because processModule() modifies the last item
|
|
|
|
* in the list.
|
|
|
|
* Note: for the first module in chain (the last here), Module->Back() points to the board
|
|
|
|
* or is NULL.
|
2009-06-20 19:09:43 +00:00
|
|
|
*/
|
2013-11-22 19:47:10 +00:00
|
|
|
Module = m_parent->GetBoard()->m_Modules.GetLast();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
for( ; Module && Module->Type() == PCB_MODULE_T; Module = PtBack )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-02-15 20:14:26 +00:00
|
|
|
PtBack = Module->Back();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
if( !isMatch( Module ) )
|
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
|
|
|
{
|
|
|
|
if( processModule( Module, Module->GetFPID()) )
|
|
|
|
change = true;
|
|
|
|
}
|
2018-01-12 19:36:15 +00:00
|
|
|
else
|
2018-04-18 09:31:33 +00:00
|
|
|
{
|
|
|
|
if( processModule( Module, newFPID ) )
|
|
|
|
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
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
bool DIALOG_EXCHANGE_FOOTPRINTS::processModule( MODULE* aModule, const LIB_ID& aNewFPID )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
LIB_ID oldFPID = aModule->GetFPID();
|
2017-08-18 18:26:45 +00:00
|
|
|
REPORTER& reporter = m_MessageWindow->Reporter();
|
2018-04-18 09:31:33 +00:00
|
|
|
wxString msg;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
// Load new module.
|
|
|
|
msg.Printf( _( "%s footprint \"%s\" (from \"%s\") to \"%s\"" ),
|
|
|
|
m_updateMode ? _( "Update" ) : _( "Change" ),
|
|
|
|
aModule->GetReference(),
|
|
|
|
oldFPID.Format().c_str(),
|
|
|
|
aNewFPID.Format().c_str() );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
MODULE* newModule = m_parent->LoadFootprint( aNewFPID );
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
if( !newModule )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
msg << ": " << _( "*** footprint not found ***" );
|
2017-08-18 18:26:45 +00:00
|
|
|
reporter.Report( msg, REPORTER::RPT_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
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
m_parent->Exchange_Module( aModule, newModule, m_commit,
|
|
|
|
m_removeExtraBox->GetValue(),
|
|
|
|
m_resetTextItemLayers->GetValue(),
|
|
|
|
m_resetTextItemEffects->GetValue() );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
if( aModule == m_currentModule )
|
|
|
|
m_currentModule = newModule;
|
2018-04-18 09:31:33 +00:00
|
|
|
|
2018-01-12 19:36:15 +00:00
|
|
|
if( aModule == m_parent->GetCurItem() )
|
|
|
|
m_parent->SetCurItem( newModule );
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2017-08-18 18:26:45 +00:00
|
|
|
msg += ": OK";
|
|
|
|
reporter.Report( msg, REPORTER::RPT_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
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
void processTextItem( const TEXTE_MODULE& aSrc, TEXTE_MODULE& aDest,
|
|
|
|
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 )
|
|
|
|
aDest.SetEffects( aSrc );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEXTE_MODULE* getMatchingTextItem( TEXTE_MODULE* aRefItem, MODULE* aModule )
|
|
|
|
{
|
|
|
|
for( auto iItem = aModule->GraphicalItemsList().GetFirst(); iItem; iItem = iItem->Next() )
|
|
|
|
{
|
|
|
|
TEXTE_MODULE* candidate = dyn_cast<TEXTE_MODULE*>( iItem );
|
|
|
|
if( candidate && candidate->GetText() == aRefItem->GetText() )
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EDIT_FRAME::Exchange_Module( MODULE* aSrc, MODULE* aDest, BOARD_COMMIT& aCommit,
|
|
|
|
bool deleteExtraTexts,
|
|
|
|
bool resetTextLayers, bool resetTextEffects )
|
|
|
|
{
|
|
|
|
aDest->SetParent( GetBoard() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* place module without ratsnest refresh: this will be made later
|
2016-08-17 15:24:04 +00:00
|
|
|
* when all modules are on board */
|
2018-04-18 09:31:33 +00:00
|
|
|
PlaceModule( aDest, nullptr, false );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-10-22 16:50:27 +00:00
|
|
|
// Copy full placement and pad net names (when possible)
|
|
|
|
// but not local settings like clearances (use library values)
|
2018-04-18 09:31:33 +00:00
|
|
|
aSrc->CopyNetlistSettings( aDest, false );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2018-05-10 11:14:54 +00:00
|
|
|
// Copy reference
|
2018-04-18 09:31:33 +00:00
|
|
|
processTextItem( aSrc->Reference(), aDest->Reference(),
|
|
|
|
// never reset reference text
|
|
|
|
false,
|
|
|
|
resetTextLayers, resetTextEffects );
|
|
|
|
|
|
|
|
// Copy value
|
|
|
|
processTextItem( aSrc->Value(), aDest->Value(),
|
|
|
|
// reset value text only when it is a proxy for the footprint ID
|
|
|
|
// (cf replacing value "MountingHole-2.5mm" with "MountingHole-4.0mm")
|
|
|
|
aSrc->GetValue() == aSrc->GetFPID().GetLibItemName(),
|
|
|
|
resetTextLayers, resetTextEffects );
|
|
|
|
|
|
|
|
// Copy fields in accordance with the reset* flags
|
|
|
|
for( BOARD_ITEM* item = aSrc->GraphicalItemsList().GetFirst(); item; item = item->Next() )
|
2017-01-23 20:30:11 +00:00
|
|
|
{
|
2018-04-18 09:31:33 +00:00
|
|
|
TEXTE_MODULE* srcItem = dyn_cast<TEXTE_MODULE*>( item );
|
|
|
|
|
|
|
|
if( srcItem )
|
|
|
|
{
|
|
|
|
TEXTE_MODULE* destItem = getMatchingTextItem( srcItem, aDest );
|
|
|
|
|
|
|
|
if( destItem )
|
|
|
|
processTextItem( *srcItem, *destItem, false, resetTextLayers, resetTextEffects );
|
|
|
|
else if( !deleteExtraTexts )
|
|
|
|
aDest->GraphicalItemsList().Append( new TEXTE_MODULE( *srcItem ) );
|
|
|
|
}
|
2017-01-23 20:30:11 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
// Updating other parameters
|
|
|
|
aDest->SetTimeStamp( aSrc->GetTimeStamp() );
|
|
|
|
aDest->SetPath( aSrc->GetPath() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
aCommit.Remove( aSrc );
|
|
|
|
aCommit.Add( aDest );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-08-17 15:24:04 +00:00
|
|
|
// @todo LEGACY should be unnecessary
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2018-04-18 09:31:33 +00:00
|
|
|
aDest->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
|
|
|
{
|
|
|
|
wxString newname;
|
|
|
|
|
|
|
|
KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true );
|
|
|
|
|
|
|
|
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
|
|
|
|