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>
|
2016-11-20 23:35:08 +00:00
|
|
|
* Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>
|
2017-01-31 07:55:02 +00:00
|
|
|
* Copyright (C) 1992-2017 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>
|
2014-05-22 13:01:58 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <macros.h>
|
2016-08-17 15:24:04 +00:00
|
|
|
#include <board_commit.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
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>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2017-01-31 07:55:02 +00:00
|
|
|
#include <dialog_exchange_modules.h>
|
2012-03-08 17:47:23 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2015-06-22 17:21:34 +00:00
|
|
|
#include <kiway.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-22 17:21:34 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
static bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName );
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
int DIALOG_EXCHANGE_MODULE::m_selectionMode = 0;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( PCB_EDIT_FRAME* parent, MODULE* Module ) :
|
2016-08-17 15:24:04 +00:00
|
|
|
DIALOG_EXCHANGE_MODULE_BASE( parent ), m_commit( parent )
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
2013-11-22 19:47:10 +00:00
|
|
|
m_parent = parent;
|
|
|
|
m_currentModule = Module;
|
|
|
|
init();
|
2009-06-20 19:09:43 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2015-08-20 18:13:18 +00:00
|
|
|
Center();
|
2009-06-20 19:09:43 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::OnQuit( wxCommandEvent& event )
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
2013-11-22 19:47:10 +00:00
|
|
|
m_selectionMode = m_Selection->GetSelection();
|
2015-06-22 17:21:34 +00:00
|
|
|
Show( false );
|
|
|
|
EndQuasiModal( wxID_CANCEL );
|
2009-06-20 19:09:43 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::init()
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
|
|
|
SetFocus();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-08-20 18:13:18 +00:00
|
|
|
m_CurrentFootprintFPID->AppendText( FROM_UTF8( m_currentModule->GetFPID().Format().c_str() ) );
|
|
|
|
m_NewFootprintFPID->AppendText( FROM_UTF8( m_currentModule->GetFPID().Format().c_str() ) );
|
|
|
|
m_CmpValue->AppendText( m_currentModule->GetValue() );
|
|
|
|
m_CmpReference->AppendText( m_currentModule->GetReference() );
|
2015-08-07 08:28:14 +00:00
|
|
|
m_Selection->SetString( 0, wxString::Format(
|
2016-03-14 18:20:19 +00:00
|
|
|
_( "Change footprint of '%s'" ),
|
2015-08-07 08:28:14 +00:00
|
|
|
GetChars( m_currentModule->GetReference() ) ) );
|
2016-03-14 18:20:19 +00:00
|
|
|
wxString fpname = m_CurrentFootprintFPID->GetValue().AfterLast( ':' );
|
2015-08-07 08:28:14 +00:00
|
|
|
|
|
|
|
if( fpname.IsEmpty() ) // Happens for old fp names
|
2015-08-20 18:13:18 +00:00
|
|
|
fpname = m_CurrentFootprintFPID->GetValue();
|
2015-08-07 08:28:14 +00:00
|
|
|
|
|
|
|
m_Selection->SetString( 1, wxString::Format(
|
2016-03-14 18:20:19 +00:00
|
|
|
_( "Change footprints '%s'" ),
|
2015-08-07 08:28:14 +00:00
|
|
|
GetChars( fpname.Left( 12 ) ) ) );
|
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
m_Selection->SetSelection( m_selectionMode );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
// Enable/disable widgets:
|
|
|
|
wxCommandEvent event;
|
|
|
|
OnSelectionClicked( event );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::OnOkClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-22 19:47:10 +00:00
|
|
|
m_selectionMode = m_Selection->GetSelection();
|
2015-07-28 15:33:18 +00:00
|
|
|
bool result = false;
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
switch( m_Selection->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0:
|
2015-07-28 15:33:18 +00:00
|
|
|
result = changeCurrentFootprint();
|
2009-06-20 19:09:43 +00:00
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
case 1:
|
2015-07-28 15:33:18 +00:00
|
|
|
result = changeSameFootprints( false );
|
2009-06-20 19:09:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2015-07-28 15:33:18 +00:00
|
|
|
result = changeSameFootprints( true );
|
2009-06-20 19:09:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2015-07-28 15:33:18 +00:00
|
|
|
result = changeAllFootprints();
|
2009-06-20 19:09:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-28 15:33:18 +00:00
|
|
|
|
|
|
|
if( result )
|
|
|
|
{
|
|
|
|
if( m_parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
|
|
|
|
m_parent->Compile_Ratsnest( NULL, true );
|
|
|
|
|
|
|
|
m_parent->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:24:04 +00:00
|
|
|
m_commit.Push( wxT( "Changed footprint" ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::OnSelectionClicked( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
bool enable = true;
|
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
switch( m_Selection->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2013-11-24 17:48:14 +00:00
|
|
|
enable = false;
|
2009-06-20 19:09:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2015-08-20 18:13:18 +00:00
|
|
|
m_NewFootprintFPID->Enable( enable );
|
2013-11-24 17:48:14 +00:00
|
|
|
m_Browsebutton->Enable( enable );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::RebuildCmpList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-29 03:08:14 +00:00
|
|
|
wxFileName fn;
|
|
|
|
wxString msg;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
// Build the .cmp file name from the board name
|
2013-11-22 19:47:10 +00:00
|
|
|
fn = m_parent->GetBoard()->GetFileName();
|
2012-03-08 17:47:23 +00:00
|
|
|
fn.SetExt( ComponentFileExtension );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( RecreateCmpFile( m_parent->GetBoard(), fn.GetFullPath() ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
msg.Printf( _( "File '%s' created\n" ),
|
|
|
|
GetChars( fn.GetFullPath() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2013-11-24 17:48:14 +00:00
|
|
|
else
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
msg.Printf( _( "** Could not create file '%s' ***\n" ),
|
|
|
|
GetChars( fn.GetFullPath() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
m_WinMessages->AppendText( msg );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
bool DIALOG_EXCHANGE_MODULE::changeCurrentFootprint()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-08-20 18:13:18 +00:00
|
|
|
wxString newmodulename = m_NewFootprintFPID->GetValue();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( newmodulename == wxEmptyString )
|
2015-07-28 15:33:18 +00:00
|
|
|
return false;
|
2009-08-06 07:11:04 +00:00
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
return change_1_Module( m_currentModule, newmodulename, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
bool DIALOG_EXCHANGE_MODULE::changeSameFootprints( bool aUseValue )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString msg;
|
2015-07-28 15:33:18 +00:00
|
|
|
MODULE* Module;
|
|
|
|
MODULE* PtBack;
|
2009-08-06 07:11:04 +00:00
|
|
|
bool change = false;
|
2015-08-20 18:13:18 +00:00
|
|
|
wxString newmodulename = m_NewFootprintFPID->GetValue();
|
2013-09-08 18:31:21 +00:00
|
|
|
wxString value;
|
2016-11-20 23:35:08 +00:00
|
|
|
LIB_ID lib_reference;
|
2009-08-06 07:11:04 +00:00
|
|
|
bool check_module_value = false;
|
2009-11-20 14:55:20 +00:00
|
|
|
int ShowErr = 3; // Post 3 error messages max.
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
if( m_parent->GetBoard()->m_Modules == NULL )
|
2015-07-28 15:33:18 +00:00
|
|
|
return false;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( newmodulename == wxEmptyString )
|
2015-07-28 15:33:18 +00:00
|
|
|
return false;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
lib_reference = m_currentModule->GetFPID();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
if( aUseValue )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-06-26 12:52:24 +00:00
|
|
|
check_module_value = true;
|
2013-11-22 19:47:10 +00:00
|
|
|
value = m_currentModule->GetValue();
|
2015-08-06 17:11:51 +00:00
|
|
|
msg.Printf( _( "Change footprint %s -> %s (for value = %s)?" ),
|
2013-11-22 19:47:10 +00:00
|
|
|
GetChars( FROM_UTF8( m_currentModule->GetFPID().Format().c_str() ) ),
|
2009-11-20 14:55:20 +00:00
|
|
|
GetChars( newmodulename ),
|
2013-11-22 19:47:10 +00:00
|
|
|
GetChars( m_currentModule->GetValue() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-06 17:11:51 +00:00
|
|
|
msg.Printf( _( "Change footprint %s -> %s ?" ),
|
2013-09-18 11:15:17 +00:00
|
|
|
GetChars( FROM_UTF8( lib_reference.Format().c_str() ) ),
|
|
|
|
GetChars( newmodulename ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
2015-07-28 15:33:18 +00:00
|
|
|
return false;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
/* The change is done from the last module because
|
2015-07-28 15:33:18 +00:00
|
|
|
* change_1_Module () modifies the last item in the list.
|
|
|
|
*
|
|
|
|
* note: for the first module in chain (the last here), Module->Back()
|
2009-11-20 14:55:20 +00:00
|
|
|
* points 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
|
|
|
|
2011-10-01 19:24:27 +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
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
if( lib_reference != Module->GetFPID() )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( check_module_value )
|
|
|
|
{
|
2013-03-13 18:53:58 +00:00
|
|
|
if( value.CmpNoCase( Module->GetValue() ) != 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
if( change_1_Module( Module, newmodulename, ShowErr ) )
|
2009-06-26 12:52:24 +00:00
|
|
|
change = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
else if( ShowErr )
|
|
|
|
ShowErr--;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
bool DIALOG_EXCHANGE_MODULE::changeAllFootprints()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-01 18:06:03 +00:00
|
|
|
MODULE* Module, * PtBack;
|
2009-08-06 07:11:04 +00:00
|
|
|
bool change = false;
|
2013-11-22 19:47:10 +00:00
|
|
|
int ShowErr = 3; // Post 3 error max.
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
if( m_parent->GetBoard()->m_Modules == NULL )
|
2015-07-28 15:33:18 +00:00
|
|
|
return false;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
if( !IsOK( this, _( "Are you sure you want to change all footprints?" ) ) )
|
2015-07-28 15:33:18 +00:00
|
|
|
return false;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
/* The change is done from the last module because the function
|
2015-07-28 15:33:18 +00:00
|
|
|
* change_1_Module () modifies the last module in the list
|
|
|
|
*
|
|
|
|
* note: for the first module in chain (the last here), Module->Back()
|
2009-11-20 14:55:20 +00:00
|
|
|
* points 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
|
|
|
|
2011-10-01 19:24:27 +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
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
if( change_1_Module( Module, Module->GetFPID(), ShowErr ) )
|
2009-06-26 12:52:24 +00:00
|
|
|
change = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
else if( ShowErr )
|
|
|
|
ShowErr--;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-07-28 15:33:18 +00:00
|
|
|
bool DIALOG_EXCHANGE_MODULE::change_1_Module( MODULE* aModule,
|
2016-11-20 23:35:08 +00:00
|
|
|
const LIB_ID& aNewFootprintFPID,
|
2013-11-22 19:47:10 +00:00
|
|
|
bool aShowError )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-08-17 15:24:04 +00:00
|
|
|
MODULE* newModule;
|
2011-11-29 03:08:14 +00:00
|
|
|
wxString line;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
if( aModule == NULL )
|
2009-08-06 07:11:04 +00:00
|
|
|
return false;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
wxBusyCursor dummy;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Copy parameters from the old module.
|
2016-11-20 23:35:08 +00:00
|
|
|
LIB_ID oldFootprintFPID = aModule->GetFPID();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Load module.
|
2014-11-02 12:44:57 +00:00
|
|
|
line.Printf( _( "Change footprint '%s' (from '%s') to '%s'" ),
|
2013-11-22 19:47:10 +00:00
|
|
|
GetChars( aModule->GetReference() ),
|
2013-11-24 17:48:14 +00:00
|
|
|
oldFootprintFPID.Format().c_str(),
|
|
|
|
aNewFootprintFPID.Format().c_str() );
|
2011-11-29 03:08:14 +00:00
|
|
|
m_WinMessages->AppendText( line );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
newModule = m_parent->LoadFootprint( aNewFootprintFPID );
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
if( newModule == NULL ) // New module not found, redraw the old one.
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
m_WinMessages->AppendText( wxT( " No\n" ) );
|
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
|
|
|
|
2016-08-17 15:24:04 +00:00
|
|
|
m_parent->Exchange_Module( aModule, newModule, m_commit );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
if( aModule == m_currentModule )
|
|
|
|
m_currentModule = newModule;
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
m_WinMessages->AppendText( wxT( " OK\n" ) );
|
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
|
|
|
|
2016-08-17 15:24:04 +00:00
|
|
|
void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
|
|
|
|
MODULE* aNewModule,
|
|
|
|
BOARD_COMMIT& aCommit )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-06 07:11:04 +00:00
|
|
|
aNewModule->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 */
|
2011-09-16 14:13:02 +00:00
|
|
|
PlaceModule( aNewModule, NULL, true );
|
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)
|
|
|
|
aOldModule->CopyNetlistSettings( aNewModule, false );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-10-22 16:50:27 +00:00
|
|
|
// Copy reference and value
|
2013-03-13 18:53:58 +00:00
|
|
|
aNewModule->SetReference( aOldModule->GetReference() );
|
|
|
|
aNewModule->SetValue( aOldModule->GetValue() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
// Compare the footprint name only, in case the nickname is empty or in case
|
|
|
|
// user moved the footprint to a new library. Chances are if footprint name is
|
|
|
|
// same then the footprint is very nearly the same and the two texts should
|
|
|
|
// be kept at same size, position, and rotation.
|
|
|
|
if( aNewModule->GetFPID().GetLibItemName() == aOldModule->GetFPID().GetLibItemName() )
|
|
|
|
{
|
|
|
|
aNewModule->Reference().SetEffects( aOldModule->Reference() );
|
|
|
|
aNewModule->Value().SetEffects( aOldModule->Value() );
|
|
|
|
}
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Updating other parameters
|
2011-12-12 08:37:05 +00:00
|
|
|
aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() );
|
2013-03-13 18:53:58 +00:00
|
|
|
aNewModule->SetPath( aOldModule->GetPath() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2016-08-17 15:24:04 +00:00
|
|
|
aCommit.Remove( aOldModule );
|
|
|
|
aCommit.Add( aNewModule );
|
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;
|
2011-12-21 13:42:02 +00:00
|
|
|
aNewModule->ClearFlags();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-20 18:13:18 +00:00
|
|
|
// Displays the list of available footprints in library name and select a footprint.
|
2009-06-20 19:09:43 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::BrowseAndSelectFootprint( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString newname;
|
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
newname = m_parent->SelectFootprint( m_parent, wxEmptyString, wxEmptyString, wxEmptyString,
|
2014-05-09 18:35:48 +00:00
|
|
|
Prj().PcbFootprintLibs() );
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( newname != wxEmptyString )
|
2015-08-20 18:13:18 +00:00
|
|
|
m_NewFootprintFPID->SetValue( newname );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
|
2015-06-22 17:21:34 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::ViewAndSelectFootprint( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString newname;
|
|
|
|
|
|
|
|
KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true );
|
|
|
|
|
|
|
|
if( frame->ShowModal( &newname, this ) )
|
|
|
|
{
|
2015-08-20 18:13:18 +00:00
|
|
|
m_NewFootprintFPID->SetValue( newname );
|
2015-06-22 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-29 03:08:14 +00:00
|
|
|
wxFileName fn;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
MODULE* module = GetBoard()->m_Modules;
|
2011-11-29 03:08:14 +00:00
|
|
|
wxString msg;
|
|
|
|
wxString wildcard;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( module == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2014-11-02 12:44:57 +00:00
|
|
|
DisplayError( this, _( "No footprints!" ) );
|
2009-03-30 15:36:41 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
// Build the .cmp file name from the board name
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = GetBoard()->GetFileName();
|
2012-03-08 17:47:23 +00:00
|
|
|
fn.SetExt( ComponentFileExtension );
|
|
|
|
wildcard = wxGetTranslation( ComponentFileWildcard );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
|
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
wxFileDialog dlg( this, _( "Save Footprint Association File" ), pro_dir,
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.GetFullName(), wildcard,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2009-03-30 15:36:41 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = dlg.GetPath();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
if( ! RecreateCmpFile( GetBoard(), fn.GetFullPath() ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
msg.Printf( _( "Could not create file '%s'" ), GetChars(fn.GetFullPath() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
DisplayError( this, msg );
|
2009-03-30 15:36:41 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2013-11-22 19:47:10 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2015-08-06 17:11:51 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName )
|
|
|
|
{
|
|
|
|
FILE* cmpFile;
|
|
|
|
|
|
|
|
cmpFile = wxFopen( aFullCmpFileName, wxT( "wt" ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
if( cmpFile == NULL )
|
|
|
|
return false;
|
|
|
|
|
2015-06-14 17:58:57 +00:00
|
|
|
fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( DateAndTime() ) );
|
2013-11-22 19:47:10 +00:00
|
|
|
|
|
|
|
MODULE* module = aBrd->m_Modules;
|
|
|
|
for( ; module != NULL; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2013-11-22 19:47:10 +00:00
|
|
|
fprintf( cmpFile, "\nBeginCmp\n" );
|
2016-03-14 18:20:19 +00:00
|
|
|
fprintf( cmpFile, "TimeStamp = %8.8lX\n", (unsigned long)module->GetTimeStamp() );
|
2013-11-22 19:47:10 +00:00
|
|
|
fprintf( cmpFile, "Path = %s\n", TO_UTF8( module->GetPath() ) );
|
|
|
|
fprintf( cmpFile, "Reference = %s;\n",
|
|
|
|
!module->GetReference().IsEmpty() ?
|
|
|
|
TO_UTF8( module->GetReference() ) : "[NoRef]" );
|
|
|
|
fprintf( cmpFile, "ValeurCmp = %s;\n",
|
|
|
|
!module->GetValue().IsEmpty() ?
|
|
|
|
TO_UTF8( module->GetValue() ) : "[NoVal]" );
|
|
|
|
fprintf( cmpFile, "IdModule = %s;\n", module->GetFPID().Format().c_str() );
|
|
|
|
fprintf( cmpFile, "EndCmp\n" );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 19:47:10 +00:00
|
|
|
fprintf( cmpFile, "\nEndListe\n" );
|
|
|
|
fclose( cmpFile );
|
|
|
|
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|