2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file xchgmod.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pcbcommon.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>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <dialog_exchange_modules_base.h>
|
2012-03-08 17:47:23 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-09 20:33:38 +00:00
|
|
|
static char* quiet_gcc_4_4_3; // GCC 4.4.3 and next ..
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
int s_SelectionMode = 0; // Remember the last exchange option, when exit dialog.
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
class DIALOG_EXCHANGE_MODULE : public DIALOG_EXCHANGE_MODULE_BASE
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_EDIT_FRAME* m_Parent;
|
|
|
|
MODULE* m_CurrentModule;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
public:
|
|
|
|
DIALOG_EXCHANGE_MODULE( PCB_EDIT_FRAME* aParent, MODULE* aModule );
|
2009-06-20 19:09:43 +00:00
|
|
|
~DIALOG_EXCHANGE_MODULE() { };
|
2009-05-01 18:06:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
private:
|
2009-11-20 14:55:20 +00:00
|
|
|
void OnSelectionClicked( wxCommandEvent& event );
|
|
|
|
void OnOkClick( wxCommandEvent& event );
|
|
|
|
void OnQuit( wxCommandEvent& event );
|
|
|
|
void BrowseAndSelectFootprint( wxCommandEvent& event );
|
|
|
|
void Init();
|
|
|
|
|
2011-03-23 15:18:44 +00:00
|
|
|
void Change_Current_Module();
|
2009-11-20 14:55:20 +00:00
|
|
|
void Change_ModuleId( bool aUseValue );
|
|
|
|
void Change_ModuleAll();
|
|
|
|
int Maj_ListeCmp( const wxString& reference, const wxString& old_name,
|
|
|
|
const wxString& new_name, bool ShowError );
|
|
|
|
bool Change_1_Module( MODULE* Module,
|
|
|
|
const wxString& new_module,
|
|
|
|
PICKED_ITEMS_LIST* aUndoPickList,
|
|
|
|
bool ShowError );
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( PCB_EDIT_FRAME* parent, MODULE* Module ) :
|
2009-06-20 19:09:43 +00:00
|
|
|
DIALOG_EXCHANGE_MODULE_BASE( parent )
|
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
m_CurrentModule = Module;
|
2009-06-20 19:09:43 +00:00
|
|
|
Init();
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::InstallExchangeModuleFrame( MODULE* Module )
|
2009-06-20 19:09:43 +00:00
|
|
|
{
|
|
|
|
DIALOG_EXCHANGE_MODULE dialog( this, Module );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
s_SelectionMode = m_Selection->GetSelection();
|
2011-04-16 15:03:21 +00:00
|
|
|
EndModal( 0 );
|
2009-06-20 19:09:43 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::Init()
|
|
|
|
{
|
|
|
|
SetFocus();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
m_OldModule->AppendText( m_CurrentModule->GetLibRef() );
|
|
|
|
m_NewModule->AppendText( m_CurrentModule->GetLibRef() );
|
|
|
|
m_OldValue->AppendText( m_CurrentModule->GetValue() );
|
2009-06-20 19:09:43 +00:00
|
|
|
m_Selection->SetSelection( s_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
|
|
|
{
|
2009-06-20 19:09:43 +00:00
|
|
|
s_SelectionMode = m_Selection->GetSelection();
|
|
|
|
switch( m_Selection->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0:
|
2011-03-23 15:18:44 +00:00
|
|
|
Change_Current_Module();
|
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:
|
|
|
|
Change_ModuleId( false );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
Change_ModuleId( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
Change_ModuleAll();
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
{
|
2009-06-20 19:09:43 +00:00
|
|
|
switch( m_Selection->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
m_NewModule->Enable( true );
|
2009-06-26 12:52:24 +00:00
|
|
|
m_Browsebutton->Enable( true );
|
2009-06-20 19:09:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
m_NewModule->Enable( false );
|
2009-06-26 12:52:24 +00:00
|
|
|
m_Browsebutton->Enable( false );
|
2009-06-20 19:09:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
/*
|
2009-11-20 14:55:20 +00:00
|
|
|
* Updates the file name.CMP (if any) after an exchange module
|
|
|
|
* (By command changeMod), if the modules are managed by this file
|
2008-03-22 18:08:44 +00:00
|
|
|
*
|
2009-11-20 14:55:20 +00:00
|
|
|
* If ShowError! = 0 displays error message if the file. Cmp is not found.
|
|
|
|
* Return 1 if error
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-06-20 19:09:43 +00:00
|
|
|
int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
|
|
|
|
const wxString& old_name,
|
|
|
|
const wxString& new_name,
|
|
|
|
bool ShowError )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-29 03:08:14 +00:00
|
|
|
wxFileName fn;
|
|
|
|
wxFileName tmpFileName;
|
|
|
|
FILE* FichCmp, * NewFile;
|
|
|
|
char line[1024];
|
|
|
|
wxString msg;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( old_name == new_name )
|
2011-03-23 15:18:44 +00:00
|
|
|
return 0;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-03-23 15:18:44 +00:00
|
|
|
/* Build CMP file name by changing the extension of NetList filename */
|
2012-08-29 16:59:50 +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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
FichCmp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( FichCmp == NULL )
|
|
|
|
{
|
|
|
|
if( ShowError )
|
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "file <%s> not found" ), GetChars( fn.GetFullPath() ) );
|
2009-06-20 19:09:43 +00:00
|
|
|
m_WinMessages->AppendText( msg );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
tmpFileName = fn;
|
|
|
|
tmpFileName.SetExt( wxT( "$$$" ) );
|
|
|
|
NewFile = wxFopen( tmpFileName.GetFullPath(), wxT( "wt" ) );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( NewFile == NULL )
|
|
|
|
{
|
|
|
|
if( ShowError )
|
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Unable to create file <%s>" ),
|
2009-11-20 14:55:20 +00:00
|
|
|
GetChars( tmpFileName.GetFullPath() ) );
|
2009-06-20 19:09:43 +00:00
|
|
|
m_WinMessages->AppendText( msg );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-02-06 07:14:51 +00:00
|
|
|
quiet_gcc_4_4_3 = fgets( line, sizeof(line), FichCmp );
|
2011-11-29 03:08:14 +00:00
|
|
|
|
2012-02-04 20:30:00 +00:00
|
|
|
fprintf( NewFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( DateAndTime() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
bool start_descr = false;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
while( fgets( line, sizeof(line), FichCmp ) != NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-29 03:08:14 +00:00
|
|
|
if( strnicmp( line, "Reference = ", 9 ) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
char buf[1024];
|
2011-11-29 03:08:14 +00:00
|
|
|
strcpy( buf, line + 12 );
|
2007-08-23 04:28:46 +00:00
|
|
|
strtok( buf, ";\n\r" );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( stricmp( buf, TO_UTF8( reference ) ) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-06-26 12:52:24 +00:00
|
|
|
start_descr = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
if( (strnicmp( line, "Begin", 5 ) == 0) || (strnicmp( line, "End", 3 ) == 0) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-08-06 07:11:04 +00:00
|
|
|
start_descr = false;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
if( start_descr && strnicmp( line, "IdModule", 8 ) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-29 03:08:14 +00:00
|
|
|
sprintf( line + 8, " = %s;\n", TO_UTF8( new_name ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = wxT( " * in <" ) + fn.GetFullPath() + wxT( ">.\n" );
|
2009-06-20 19:09:43 +00:00
|
|
|
m_WinMessages->AppendText( msg );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
start_descr = false;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
fputs( line, NewFile );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( FichCmp );
|
|
|
|
fclose( NewFile );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxRemoveFile( fn.GetFullPath() );
|
|
|
|
wxRenameFile( tmpFileName.GetFullPath(), fn.GetFullPath() );
|
2007-08-23 04:28:46 +00:00
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Change the module at the current cursor position.
|
|
|
|
* Retains the following:
|
|
|
|
* - Same direction
|
|
|
|
* - Same position
|
|
|
|
* - Same text value and ref
|
|
|
|
* - Same NetNames for pads same name
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-23 15:18:44 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::Change_Current_Module()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString newmodulename = m_NewModule->GetValue();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( newmodulename == wxEmptyString )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
PICKED_ITEMS_LIST pickList;
|
|
|
|
|
|
|
|
if( Change_1_Module( m_CurrentModule, newmodulename, &pickList, true ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2010-10-25 12:33:00 +00:00
|
|
|
if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
|
|
|
|
m_Parent->Compile_Ratsnest( NULL, true );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh();
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-08-06 07:11:04 +00:00
|
|
|
|
|
|
|
if( pickList.GetCount() )
|
|
|
|
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
/*
|
2009-11-20 14:55:20 +00:00
|
|
|
* Change of all modules with the same name as that lib
|
|
|
|
* Retains:
|
|
|
|
* - Same direction
|
|
|
|
* - Same position
|
|
|
|
* - Same text value and ref
|
|
|
|
* - Same NetNames for pads same name
|
|
|
|
* And replacing the old module with the new module
|
|
|
|
* Note: m_CurrentModule no longer on the module reference
|
|
|
|
* since it has been changed!
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-06-20 19:09:43 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString msg;
|
2009-02-15 20:14:26 +00:00
|
|
|
MODULE* Module, * PtBack;
|
2009-08-06 07:11:04 +00:00
|
|
|
bool change = false;
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString newmodulename = m_NewModule->GetValue();
|
2009-06-26 12:52:24 +00:00
|
|
|
wxString value, 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
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( m_Parent->GetBoard()->m_Modules == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( newmodulename == wxEmptyString )
|
|
|
|
return;
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
lib_reference = m_CurrentModule->GetLibRef();
|
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-03-13 18:53:58 +00:00
|
|
|
value = m_CurrentModule->GetValue();
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Change modules %s -> %s (for value = %s)?" ),
|
2013-03-13 18:53:58 +00:00
|
|
|
GetChars( m_CurrentModule->GetLibRef() ),
|
2009-11-20 14:55:20 +00:00
|
|
|
GetChars( newmodulename ),
|
2013-03-13 18:53:58 +00:00
|
|
|
GetChars( m_CurrentModule->GetValue() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Change modules %s -> %s ?" ),
|
2009-11-20 14:55:20 +00:00
|
|
|
GetChars( lib_reference ), GetChars( newmodulename ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* The change is done from the last module for the routine
|
|
|
|
* Change_1_Module () modifies the last module in the list.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-08-06 07:11:04 +00:00
|
|
|
PICKED_ITEMS_LIST pickList;
|
2009-11-20 14:55:20 +00:00
|
|
|
|
|
|
|
/* note: for the first module in chain (the last here), Module->Back()
|
|
|
|
* points the board or is NULL
|
2009-06-20 19:09:43 +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-03-13 18:53:58 +00:00
|
|
|
if( lib_reference.CmpNoCase( Module->GetLibRef() ) != 0 )
|
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
|
|
|
|
2009-10-14 18:14:58 +00:00
|
|
|
if( Change_1_Module( Module, newmodulename, &pickList, ShowErr ) )
|
2009-06-26 12:52:24 +00:00
|
|
|
change = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
else if( ShowErr )
|
|
|
|
ShowErr--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( change )
|
|
|
|
{
|
2010-10-25 12:33:00 +00:00
|
|
|
if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
|
|
|
|
m_Parent->Compile_Ratsnest( NULL, true );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh();
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-08-06 07:11:04 +00:00
|
|
|
|
|
|
|
if( pickList.GetCount() )
|
|
|
|
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
/*
|
2009-11-20 14:55:20 +00:00
|
|
|
* Change all modules with module of the same name in library.
|
|
|
|
* Maintains:
|
|
|
|
* - Same direction
|
|
|
|
* - Same position
|
|
|
|
* - Same text value and ref
|
|
|
|
* - Same NetNames for pads same name
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-06-20 19:09:43 +00:00
|
|
|
void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
|
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;
|
2009-11-20 14:55:20 +00:00
|
|
|
int ShowErr = 3; // Post 3 error messages max.
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( m_Parent->GetBoard()->m_Modules == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( !IsOK( this, _( "Change ALL modules ?" ) ) )
|
|
|
|
return;
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* The change is done from the last module for the routine
|
|
|
|
* Change_1_Module () modifies the last module in the list
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-20 14:55:20 +00:00
|
|
|
PICKED_ITEMS_LIST pickList;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* note: for the first module in chain (the last here), Module->Back()
|
|
|
|
* points the board or is NULL
|
2009-06-20 19:09:43 +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-03-13 18:53:58 +00:00
|
|
|
if( Change_1_Module( Module, Module->GetLibRef(), &pickList, ShowErr ) )
|
2009-06-26 12:52:24 +00:00
|
|
|
change = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
else if( ShowErr )
|
|
|
|
ShowErr--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( change )
|
|
|
|
{
|
2010-10-25 12:33:00 +00:00
|
|
|
if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
|
|
|
|
m_Parent->Compile_Ratsnest( NULL, true );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh();
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
if( pickList.GetCount() )
|
|
|
|
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
/*
|
2009-11-20 14:55:20 +00:00
|
|
|
* Change the number empr module with the module name new_module
|
|
|
|
* - Same direction
|
|
|
|
* - Same position
|
|
|
|
* - Same text value and ref
|
|
|
|
* - Same NetNames for pads same name
|
|
|
|
* Returns:
|
|
|
|
* False if no change (if the new module is not free)
|
|
|
|
* True if OK
|
|
|
|
* Ratsnest must be recalculated after module exchange
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-20 14:55:20 +00:00
|
|
|
bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module,
|
|
|
|
const wxString& new_module,
|
|
|
|
PICKED_ITEMS_LIST* aUndoPickList,
|
|
|
|
bool ShowError )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString namecmp, oldnamecmp;
|
|
|
|
MODULE* NewModule;
|
2011-11-29 03:08:14 +00:00
|
|
|
wxString line;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-15 20:14:26 +00:00
|
|
|
if( Module == 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
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Copy parameters from the old module. */
|
2013-03-13 18:53:58 +00:00
|
|
|
oldnamecmp = Module->GetLibRef();
|
2007-08-23 04:28:46 +00:00
|
|
|
namecmp = new_module;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Load module. */
|
2013-04-09 17:49:01 +00:00
|
|
|
line.Printf( _( "Change module %s (from %s) " ),
|
2013-03-13 18:53:58 +00:00
|
|
|
GetChars( Module->GetReference() ),
|
2009-11-20 14:55:20 +00:00
|
|
|
GetChars( oldnamecmp ) );
|
2011-11-29 03:08:14 +00:00
|
|
|
m_WinMessages->AppendText( line );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-06-26 12:52:24 +00:00
|
|
|
namecmp.Trim( true );
|
2009-08-06 07:11:04 +00:00
|
|
|
namecmp.Trim( false );
|
2011-09-16 14:13:02 +00:00
|
|
|
NewModule = m_Parent->GetModuleLibrary( wxEmptyString, namecmp, ShowError );
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( NewModule == NULL ) /* New module not found, redraw the old one. */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-06-20 19:09:43 +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
|
|
|
|
2009-02-15 20:14:26 +00:00
|
|
|
if( Module == m_CurrentModule )
|
2007-08-23 04:28:46 +00:00
|
|
|
m_CurrentModule = NewModule;
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2013-04-09 17:49:01 +00:00
|
|
|
m_WinMessages->AppendText( wxT( "OK\n" ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
m_Parent->Exchange_Module( Module, NewModule, aUndoPickList );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
Maj_ListeCmp( NewModule->GetReference(), oldnamecmp, namecmp, ShowError );
|
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
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Exchange_Module
|
2009-08-06 07:11:04 +00:00
|
|
|
* Replaces OldModule by NewModule, using OldModule settings:
|
|
|
|
* position, orientation, pad netnames ...)
|
|
|
|
* OldModule is deleted or put in undo list.
|
|
|
|
* @param aOldModule = footprint to replace
|
|
|
|
* @param aNewModule = footprint to put
|
2009-11-20 14:55:20 +00:00
|
|
|
* @param aUndoPickList = the undo list used to save OldModule. If null,
|
|
|
|
* OldModule is deleted
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
|
|
|
|
MODULE* aNewModule,
|
|
|
|
PICKED_ITEMS_LIST* aUndoPickList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
wxPoint oldpos;
|
2008-12-14 19:45:05 +00:00
|
|
|
D_PAD* pad, * old_pad;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( ( aOldModule->Type() != PCB_MODULE_T ) || ( aNewModule->Type() != PCB_MODULE_T ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-03-01 19:26:17 +00:00
|
|
|
wxMessageBox( wxT( "PCB_EDIT_FRAME::Exchange_Module() StuctType error" ) );
|
2009-08-06 07:11:04 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
aNewModule->SetParent( GetBoard() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2011-02-11 20:48:13 +00:00
|
|
|
oldpos = GetScreen()->GetCrossHairPosition();
|
2013-03-13 18:53:58 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( aOldModule->GetPosition(), false );
|
2009-06-20 19:09:43 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* place module without ratsnest refresh: this will be made later
|
2009-06-20 19:09:43 +00:00
|
|
|
* when all modules are on board
|
|
|
|
*/
|
2011-09-16 14:13:02 +00:00
|
|
|
PlaceModule( aNewModule, NULL, true );
|
2011-05-03 14:23:17 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( oldpos, false );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-06-26 12:52:24 +00:00
|
|
|
/* Flip footprint if needed */
|
2009-08-06 07:11:04 +00:00
|
|
|
if( aOldModule->GetLayer() != aNewModule->GetLayer() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2013-03-13 18:53:58 +00:00
|
|
|
aNewModule->Flip( aNewModule->GetPosition() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-06-26 12:52:24 +00:00
|
|
|
/* Rotate footprint if needed */
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aOldModule->GetOrientation() != aNewModule->GetOrientation() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2013-03-13 18:53:58 +00:00
|
|
|
Rotate_Module( NULL, aNewModule, aOldModule->GetOrientation(), false );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-06-26 12:52:24 +00:00
|
|
|
/* Update 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
|
|
|
|
2009-11-20 14:55:20 +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
|
|
|
|
2009-06-26 12:52:24 +00:00
|
|
|
/* Update pad netnames ( when possible) */
|
2013-03-18 19:36:07 +00:00
|
|
|
pad = aNewModule->Pads();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
for( ; pad != NULL; pad = pad->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-14 19:45:05 +00:00
|
|
|
pad->SetNetname( wxEmptyString );
|
|
|
|
pad->SetNet( 0 );
|
2013-03-18 19:36:07 +00:00
|
|
|
old_pad = aOldModule->Pads();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
for( ; old_pad != NULL; old_pad = old_pad->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-16 17:03:25 +00:00
|
|
|
if( pad->PadNameEqual( old_pad ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-01 18:06:03 +00:00
|
|
|
pad->SetNetname( old_pad->GetNetname() );
|
2008-12-14 19:45:05 +00:00
|
|
|
pad->SetNet( old_pad->GetNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
if( aUndoPickList )
|
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
GetBoard()->Remove( aOldModule );
|
|
|
|
ITEM_PICKER picker_old( aOldModule, UR_DELETED );
|
|
|
|
ITEM_PICKER picker_new( aNewModule, UR_NEW );
|
|
|
|
aUndoPickList->PushItem( picker_old );
|
|
|
|
aUndoPickList->PushItem( picker_new );
|
2009-08-06 07:11:04 +00:00
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
else
|
2011-09-20 13:57:40 +00:00
|
|
|
{
|
2009-08-06 07:11:04 +00:00
|
|
|
aOldModule->DeleteStructure();
|
2011-09-20 13:57:40 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2011-12-21 13:42:02 +00:00
|
|
|
aNewModule->ClearFlags();
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
/*
|
2009-11-20 14:55:20 +00:00
|
|
|
* Displays the list of modules in library name and select 1 name.
|
2009-05-01 18:06:03 +00:00
|
|
|
*/
|
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;
|
|
|
|
|
|
|
|
newname = m_Parent->Select_1_Module_From_List( m_Parent,
|
|
|
|
wxEmptyString,
|
|
|
|
wxEmptyString,
|
|
|
|
wxEmptyString );
|
|
|
|
if( newname != wxEmptyString )
|
|
|
|
m_NewModule->SetValue( newname );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-30 15:36:41 +00:00
|
|
|
/**
|
|
|
|
* Function RecreateBOMFileFromBoard
|
|
|
|
* Recreates a .cmp file from the current loaded board
|
2011-09-30 18:15:37 +00:00
|
|
|
* this is the same as created by CvPcb.
|
2009-03-30 15:36:41 +00:00
|
|
|
* can be used if this file is lost
|
|
|
|
*/
|
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;
|
|
|
|
FILE* FichCmp;
|
|
|
|
char line[1024];
|
|
|
|
MODULE* Module = GetBoard()->m_Modules;
|
|
|
|
wxString msg;
|
|
|
|
wxString wildcard;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( Module == NULL )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "No Modules!" ) );
|
2009-03-30 15:36:41 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Calculation file name by changing the extension name to NetList */
|
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
|
|
|
|
2010-02-28 18:26:48 +00:00
|
|
|
wxFileDialog dlg( this, _( "Save Component Files" ), wxGetCwd(),
|
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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
FichCmp = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( FichCmp == NULL )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Unable to create file " ) + 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
|
|
|
}
|
|
|
|
|
2012-02-06 07:14:51 +00:00
|
|
|
quiet_gcc_4_4_3 = fgets( line, sizeof(line), FichCmp );
|
2011-11-08 16:37:25 +00:00
|
|
|
fprintf( FichCmp, "Cmp-Mod V01 Genere par PcbNew le %s\n", TO_UTF8( DateAndTime() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
fprintf( FichCmp, "\nBeginCmp\n" );
|
2011-12-12 08:37:05 +00:00
|
|
|
fprintf( FichCmp, "TimeStamp = %8.8lX\n", Module->GetTimeStamp() );
|
2013-03-13 18:53:58 +00:00
|
|
|
fprintf( FichCmp, "Path = %s\n", TO_UTF8( Module->GetPath() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( FichCmp, "Reference = %s;\n",
|
2013-03-13 18:53:58 +00:00
|
|
|
!Module->GetReference().IsEmpty() ?
|
|
|
|
TO_UTF8( Module->GetReference() ) : "[NoRef]" );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( FichCmp, "ValeurCmp = %s;\n",
|
2013-03-13 18:53:58 +00:00
|
|
|
!Module->GetValue().IsEmpty() ?
|
|
|
|
TO_UTF8( Module->GetValue() ) : "[NoVal]" );
|
|
|
|
fprintf( FichCmp, "IdModule = %s;\n", TO_UTF8( Module->GetLibRef() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( FichCmp, "EndCmp\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( FichCmp, "\nEndListe\n" );
|
|
|
|
fclose( FichCmp );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|