2011-10-13 19:56:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 1992-2011 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
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file pcbnew/loadcmp.cpp
|
|
|
|
* @brief Footprints selection and loading functions.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "eda_doc.h"
|
|
|
|
#include "kicad_string.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "filter_reader.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "macros.h"
|
|
|
|
#include "pcbcommon.h"
|
|
|
|
|
|
|
|
#include "class_board.h"
|
|
|
|
#include "class_module.h"
|
|
|
|
|
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "module_editor_frame.h"
|
2011-02-22 20:59:16 +00:00
|
|
|
#include "footprint_info.h"
|
2011-07-06 16:40:54 +00:00
|
|
|
#include "class_footprint_library.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "dialog_get_component.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
static void DisplayCmpDoc( wxString& Name );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
static FOOTPRINT_LIST MList;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
MODULE* newModule;
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_BASE_FRAME* parent = (PCB_BASE_FRAME*) GetParent();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( aModule == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-06-14 20:16:47 +00:00
|
|
|
if( ! parent->GetBoard() || ! parent->GetBoard()->m_Modules )
|
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
aModule = Select_1_Module_From_BOARD( parent->GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( aModule == NULL )
|
2010-06-14 20:16:47 +00:00
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
SetCurItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-06-14 20:16:47 +00:00
|
|
|
Clear_Pcb( false );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2012-01-14 19:50:32 +00:00
|
|
|
newModule = new MODULE( *aModule );
|
|
|
|
newModule->SetParent( GetBoard() );
|
2011-12-12 08:37:05 +00:00
|
|
|
newModule->m_Link = aModule->GetTimeStamp();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
aModule = newModule;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
GetBoard()->Add( aModule );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
aModule->ClearFlags();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->BuildListOfNets();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) );
|
2011-12-07 05:28:49 +00:00
|
|
|
PlaceModule( aModule, NULL );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Put it on FRONT layer,
|
|
|
|
// because this is the default in ModEdit, and in libs
|
2011-12-07 05:28:49 +00:00
|
|
|
if( aModule->GetLayer() != LAYER_N_FRONT )
|
|
|
|
aModule->Flip( aModule->m_Pos );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Put it in orientation 0,
|
|
|
|
// because this is the default orientation in ModEdit, and in libs
|
2011-12-07 05:28:49 +00:00
|
|
|
Rotate_Module( NULL, aModule, 0, false );
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->ClrModify();
|
2011-03-01 18:45:21 +00:00
|
|
|
Zoom_Automatique( false );
|
2010-06-14 20:16:47 +00:00
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& library, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
MODULE* module;
|
|
|
|
wxPoint curspos = GetScreen()->GetCrossHairPosition();
|
|
|
|
wxString moduleName, keys;
|
|
|
|
bool AllowWildSeach = true;
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
static wxArrayString HistoryList;
|
2009-10-16 17:18:23 +00:00
|
|
|
static wxString lastCommponentName;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
/* Ask for a component name or key words */
|
2010-11-20 10:59:59 +00:00
|
|
|
DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), HistoryList,
|
2009-10-16 17:18:23 +00:00
|
|
|
_( "Place Module" ), false );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
dlg.SetComponentName( lastCommponentName );
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2009-10-16 17:18:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
moduleName = dlg.GetComponentName();
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( moduleName.IsEmpty() ) /* Cancel command */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
moduleName.MakeUpper();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( moduleName[0] == '=' ) // Selection by keywords
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-06-14 20:16:47 +00:00
|
|
|
AllowWildSeach = false;
|
2011-12-07 05:28:49 +00:00
|
|
|
keys = moduleName.AfterFirst( '=' );
|
|
|
|
moduleName = Select_1_Module_From_List( this, library, wxEmptyString, keys );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( moduleName.IsEmpty() ) /* Cancel command */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 05:28:49 +00:00
|
|
|
else if( ( moduleName.Contains( wxT( "?" ) ) )
|
|
|
|
|| ( moduleName.Contains( wxT( "*" ) ) ) ) // Selection wild card
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-06-14 20:16:47 +00:00
|
|
|
AllowWildSeach = false;
|
2011-12-07 05:28:49 +00:00
|
|
|
moduleName = Select_1_Module_From_List( this, library, moduleName, wxEmptyString );
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( moduleName.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2009-11-14 22:15:22 +00:00
|
|
|
return NULL; /* Cancel command. */
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
module = GetModuleLibrary( library, moduleName, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
if( ( module == NULL ) && AllowWildSeach ) /* Search with wild card */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-06-14 20:16:47 +00:00
|
|
|
AllowWildSeach = false;
|
2011-12-07 05:28:49 +00:00
|
|
|
wxString wildname = wxChar( '*' ) + moduleName + wxChar( '*' );
|
|
|
|
moduleName = wildname;
|
|
|
|
moduleName = Select_1_Module_From_List( this, library, moduleName, wxEmptyString );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( moduleName.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2009-11-14 22:15:22 +00:00
|
|
|
return NULL; /* Cancel command. */
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
module = GetModuleLibrary( library, moduleName, true );
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( curspos );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
lastCommponentName = moduleName;
|
|
|
|
AddHistoryComponentName( HistoryList, moduleName );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
module->SetFlags( IS_NEW );
|
2007-08-20 01:20:48 +00:00
|
|
|
module->m_Link = 0;
|
2011-12-12 08:37:05 +00:00
|
|
|
module->SetTimeStamp( GetNewTimeStamp() );
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
module->SetPosition( curspos );
|
2012-01-04 19:10:33 +00:00
|
|
|
// Put it on FRONT layer,
|
|
|
|
// (Can be stored on BACK layer if the lib is an archive built from a board)
|
|
|
|
if( module->GetLayer() != LAYER_N_FRONT )
|
|
|
|
module->Flip( module->m_Pos );
|
|
|
|
// Put in in orientation 0,
|
|
|
|
// even if it is not saved with with orientation 0 in lib
|
|
|
|
// (Can happen if the lib is an archive built from a board)
|
|
|
|
Rotate_Module( NULL, module, 0, false );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
|
|
|
RecalculateAllTracksNetcode();
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( DC )
|
2011-12-22 13:28:11 +00:00
|
|
|
module->Draw( m_canvas, DC, GR_OR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::GetModuleLibrary( const wxString& aLibraryFullFilename,
|
|
|
|
const wxString& aModuleName,
|
|
|
|
bool aDisplayMessageError )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
|
|
|
wxString msg, tmp;
|
2011-12-07 05:28:49 +00:00
|
|
|
MODULE* newModule;
|
2009-04-05 20:49:15 +00:00
|
|
|
FILE* file = NULL;
|
2011-12-07 05:28:49 +00:00
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
bool one_lib = aLibraryFullFilename.IsEmpty() ? false : true;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
for( unsigned ii = 0; ii < g_LibraryNames.GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( one_lib )
|
2009-04-06 16:05:25 +00:00
|
|
|
fn = aLibraryFullFilename;
|
|
|
|
else
|
2011-09-27 20:43:18 +00:00
|
|
|
fn = wxFileName( wxEmptyString, g_LibraryNames[ii], ModuleFileExtension );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-08 18:06:22 +00:00
|
|
|
tmp = wxGetApp().FindLibraryPath( fn );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( !tmp )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( aDisplayMessageError )
|
2009-06-26 12:52:24 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "PCB footprint library file <%s> not found in search paths." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullName() ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ), wxOK | wxICON_ERROR, this );
|
2009-06-26 12:52:24 +00:00
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = wxFopen( tmp, wxT( "rt" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( file == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg.Printf( _( "Could not open PCB footprint library file <%s>." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( tmp ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ), wxOK | wxICON_ERROR, this );
|
2007-08-20 01:20:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
FILE_LINE_READER fileReader( file, tmp );
|
|
|
|
|
|
|
|
FILTER_READER reader( fileReader );
|
|
|
|
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Scan Lib: %s" ), GetChars( tmp ) );
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( msg );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
FOOTPRINT_LIBRARY curr_lib( file, &reader );
|
|
|
|
|
|
|
|
if( !curr_lib.IsLibrary() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
msg.Printf( _( "<%s> is not a valid KiCad PCB footprint library file." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( tmp ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ), wxOK | wxICON_ERROR, this );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
// Reading the list of modules in the library.
|
2011-07-06 16:40:54 +00:00
|
|
|
curr_lib.ReadSectionIndex();
|
|
|
|
bool found = curr_lib.FindInList( aModuleName );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
// Read library.
|
2011-07-06 16:40:54 +00:00
|
|
|
if( found )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
wxString name;
|
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
fileReader.Rewind();
|
2011-09-27 20:43:18 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
while( reader.ReadLine() )
|
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
char* line = reader.Line();
|
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
StrPurge( line + 8 );
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( strnicmp( line, "$MODULE", 7 ) != 0 )
|
|
|
|
continue;
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
// Read module name.
|
2011-12-07 05:28:49 +00:00
|
|
|
name = FROM_UTF8( line + 8 );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( name.CmpNoCase( aModuleName ) == 0 )
|
2011-07-06 16:40:54 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
newModule = new MODULE( GetBoard() );
|
2011-07-06 16:40:54 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
// Temporarily switch the locale to standard C (needed to print
|
2011-07-06 16:40:54 +00:00
|
|
|
// floating point numbers like 1.3)
|
2011-12-07 05:28:49 +00:00
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
newModule->ReadDescr( &reader );
|
|
|
|
|
|
|
|
GetBoard()->Add( newModule, ADD_APPEND );
|
2011-07-06 16:40:54 +00:00
|
|
|
SetStatusText( wxEmptyString );
|
2011-12-07 05:28:49 +00:00
|
|
|
return newModule;
|
2011-07-06 16:40:54 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( one_lib )
|
2009-04-06 16:05:25 +00:00
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
if( aDisplayMessageError )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Module <%s> not found" ), GetChars( aModuleName ) );
|
2009-04-06 16:05:25 +00:00
|
|
|
DisplayError( NULL, msg );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
wxString PCB_BASE_FRAME::Select_1_Module_From_List( EDA_DRAW_FRAME* aWindow,
|
|
|
|
const wxString& aLibraryFullFilename,
|
|
|
|
const wxString& aMask,
|
|
|
|
const wxString& aKeyWord )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
static wxString OldName; /* Save the name of the last module loaded. */
|
2011-02-08 18:39:41 +00:00
|
|
|
wxString CmpName;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString msg;
|
2011-02-22 20:59:16 +00:00
|
|
|
wxArrayString libnames_list;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
if( aLibraryFullFilename.IsEmpty() )
|
2011-09-27 20:43:18 +00:00
|
|
|
libnames_list = g_LibraryNames;
|
2011-02-22 20:59:16 +00:00
|
|
|
else
|
|
|
|
libnames_list.Add( aLibraryFullFilename );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Find modules in libraries. */
|
2011-02-22 20:59:16 +00:00
|
|
|
MList.ReadFootprintFiles( libnames_list );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
wxArrayString footprint_names_list;
|
2011-05-09 19:44:06 +00:00
|
|
|
|
|
|
|
if( !aKeyWord.IsEmpty() ) // Create a list of modules found by keyword.
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-22 20:59:16 +00:00
|
|
|
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-22 20:59:16 +00:00
|
|
|
if( KeyWordOk( aKeyWord, MList.GetItem(ii).m_KeyWord ) )
|
|
|
|
footprint_names_list.Add( MList.GetItem(ii).m_Module );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-09 19:44:06 +00:00
|
|
|
else if( !aMask.IsEmpty() ) // Create a list of modules found by pattern
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
wxString& candidate = MList.GetItem(ii).m_Module;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-05-09 19:44:06 +00:00
|
|
|
if( WildCompareString( aMask, candidate, false ) )
|
|
|
|
footprint_names_list.Add( candidate );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Create the full list of modules
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2011-02-22 20:59:16 +00:00
|
|
|
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
|
|
|
|
footprint_names_list.Add( MList.GetItem(ii).m_Module );
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( footprint_names_list.GetCount() )
|
|
|
|
{
|
2012-01-04 06:18:38 +00:00
|
|
|
msg.Printf( _( "Modules [%d items]" ), (int) footprint_names_list.GetCount() );
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG dlg( aWindow, msg, footprint_names_list, OldName,
|
|
|
|
DisplayCmpDoc, GetComponentDialogPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
CmpName = dlg.GetTextSelection();
|
|
|
|
else
|
|
|
|
CmpName.Empty();
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2011-07-06 16:40:54 +00:00
|
|
|
{
|
2011-09-27 20:43:18 +00:00
|
|
|
DisplayError( aWindow, _( "No footprint found" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
CmpName.Empty();
|
2011-07-06 16:40:54 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( CmpName != wxEmptyString )
|
|
|
|
OldName = CmpName;
|
|
|
|
|
|
|
|
return CmpName;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Find and display the doc Component Name
|
|
|
|
* The list of doc is pointed to by mlist.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
static void DisplayCmpDoc( wxString& Name )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-22 20:59:16 +00:00
|
|
|
FOOTPRINT_INFO* module_info = MList.GetModuleInfo( Name );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
if( !module_info )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
Name.Empty();
|
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
Name = module_info->m_Doc.IsEmpty() ? wxT( "No Doc" ) : module_info->m_Doc;
|
|
|
|
Name += wxT( "\nKeyW: " );
|
|
|
|
Name += module_info->m_KeyWord.IsEmpty() ? wxT( "No Keyword" ) : module_info->m_KeyWord;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
MODULE* FOOTPRINT_EDIT_FRAME::Select_1_Module_From_BOARD( BOARD* aPcb )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
MODULE* module;
|
2011-08-26 17:01:17 +00:00
|
|
|
static wxString OldName; /* Save name of last module selected. */
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString CmpName, msg;
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
wxArrayString listnames;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
module = aPcb->m_Modules;
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
for( ; module != NULL; module = (MODULE*) module->Next() )
|
|
|
|
listnames.Add( module->m_Reference->m_Text );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
msg.Printf( _( "Modules [%d items]" ), listnames.GetCount() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, msg, listnames, wxEmptyString );
|
2010-11-19 18:50:23 +00:00
|
|
|
dlg.SortList();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
CmpName = dlg.GetTextSelection();
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
OldName = CmpName;
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
module = aPcb->m_Modules;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
for( ; module != NULL; module = (MODULE*) module->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
if( CmpName == module->m_Reference->m_Text )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|