2007-08-20 01:20:48 +00:00
|
|
|
/**********************************************/
|
|
|
|
/* Footprints selection and loading functions */
|
|
|
|
/**********************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "eda_doc.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2010-11-20 10:59:59 +00:00
|
|
|
#include "dialog_get_component.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "pcbnew.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2010-08-10 18:34:26 +00:00
|
|
|
#include "module_editor_frame.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
|
|
|
#include "filter_reader.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-08 18:39:41 +00:00
|
|
|
class FOOTPRINT_ITEM
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-02-08 18:39:41 +00:00
|
|
|
FOOTPRINT_ITEM* Next;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString m_Name, m_Doc, m_KeyWord;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-11-20 10:59:59 +00:00
|
|
|
public:
|
2011-02-08 18:39:41 +00:00
|
|
|
FOOTPRINT_ITEM()
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
Next = NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-08 18:39:41 +00:00
|
|
|
~FOOTPRINT_ITEM()
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
}
|
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 );
|
|
|
|
static void ReadDocLib( const wxString& ModLibName );
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-08 18:39:41 +00:00
|
|
|
static FOOTPRINT_ITEM* MList;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Load_Module_From_BOARD
|
2010-06-14 20:16:47 +00:00
|
|
|
* load in Modedit a footfrint from the main board
|
|
|
|
* @param Module = the module to load. If NULL, a module reference will we asked to user
|
|
|
|
* @return true if a module isloaded, false otherwise.
|
|
|
|
*/
|
|
|
|
bool WinEDA_ModuleEditFrame::Load_Module_From_BOARD( MODULE* Module )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
MODULE* NewModule;
|
2008-12-08 15:27:13 +00:00
|
|
|
WinEDA_BasePcbFrame* parent = (WinEDA_BasePcbFrame*) GetParent();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Module == NULL )
|
|
|
|
{
|
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
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = Select_1_Module_From_BOARD( parent->GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Module == 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;
|
|
|
|
NewModule = new MODULE( GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
NewModule->Copy( Module );
|
|
|
|
NewModule->m_Link = Module->m_TimeStamp;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
Module = NewModule;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Add( Module );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
Module->m_Flags = 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
GetBoard()->m_NetInfo->BuildListOfNets();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
Place_Module( Module, NULL );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() != LAYER_N_FRONT )
|
2009-08-06 07:11:04 +00:00
|
|
|
Module->Flip( Module->m_Pos );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2010-06-14 20:16:47 +00:00
|
|
|
Rotate_Module( NULL, Module, 0, false );
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->ClrModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
Zoom_Automatique( TRUE );
|
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
|
|
|
|
|
|
|
MODULE* WinEDA_BasePcbFrame::Load_Module_From_Library( const wxString& library,
|
|
|
|
wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
MODULE* module;
|
2011-02-11 20:48:13 +00:00
|
|
|
wxPoint curspos = GetScreen()->GetCrossHairPosition();
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString ModuleName, keys;
|
|
|
|
static wxArrayString HistoryList;
|
2009-10-16 17:18:23 +00:00
|
|
|
static wxString lastCommponentName;
|
2009-11-14 22:15:22 +00:00
|
|
|
bool AllowWildSeach = TRUE;
|
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;
|
|
|
|
|
|
|
|
ModuleName = dlg.GetComponentName();
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( ModuleName.IsEmpty() ) /* Cancel command */
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
ModuleName.MakeUpper();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( ModuleName[0] == '=' ) // Selection by keywords
|
|
|
|
{
|
2010-06-14 20:16:47 +00:00
|
|
|
AllowWildSeach = false;
|
2007-08-20 01:20:48 +00:00
|
|
|
keys = ModuleName.AfterFirst( '=' );
|
2009-10-16 17:18:23 +00:00
|
|
|
ModuleName = Select_1_Module_From_List( this, library, wxEmptyString,
|
|
|
|
keys );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( ModuleName.IsEmpty() ) /* Cancel command */
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-10-16 17:18:23 +00:00
|
|
|
else if( ( ModuleName.Contains( wxT( "?" ) ) )
|
2009-11-14 22:15:22 +00:00
|
|
|
|| ( ModuleName.Contains( wxT( "*" ) ) ) ) // Selection wild card
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-06-14 20:16:47 +00:00
|
|
|
AllowWildSeach = false;
|
2009-11-14 22:15:22 +00:00
|
|
|
ModuleName = Select_1_Module_From_List( this, library, ModuleName,
|
|
|
|
wxEmptyString );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( ModuleName.IsEmpty() )
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2009-11-14 22:15:22 +00:00
|
|
|
return NULL; /* Cancel command. */
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-14 20:16:47 +00:00
|
|
|
module = Get_Librairie_Module( library, ModuleName, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( ( module == NULL ) && AllowWildSeach ) /* Search with wildcard */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-06-14 20:16:47 +00:00
|
|
|
AllowWildSeach = false;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString wildname = wxChar( '*' ) + ModuleName + wxChar( '*' );
|
|
|
|
ModuleName = wildname;
|
2009-10-16 17:18:23 +00:00
|
|
|
ModuleName = Select_1_Module_From_List( this, library, ModuleName,
|
|
|
|
wxEmptyString );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( ModuleName.IsEmpty() )
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2009-11-14 22:15:22 +00:00
|
|
|
return NULL; /* Cancel command. */
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
2009-04-06 16:05:25 +00:00
|
|
|
module = Get_Librairie_Module( library, ModuleName, TRUE );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( curspos );
|
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
lastCommponentName = ModuleName;
|
2007-08-20 01:20:48 +00:00
|
|
|
AddHistoryComponentName( HistoryList, ModuleName );
|
|
|
|
|
|
|
|
module->m_Flags = IS_NEW;
|
|
|
|
module->m_Link = 0;
|
|
|
|
module->m_TimeStamp = GetTimeStamp();
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
module->SetPosition( curspos );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
/* TODO: call RecalculateAllTracksNetcode() only if some pads pads have
|
|
|
|
* a netname.
|
2009-09-23 05:53:12 +00:00
|
|
|
* If all pads are not connected (usually the case in module libraries,
|
2009-06-05 15:57:41 +00:00
|
|
|
* rebuild only the pad and list of nets ( faster)
|
2009-11-14 22:15:22 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
// GetBoard()->m_Pcb->m_NetInfo->BuildListOfNets();
|
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 )
|
2009-05-21 12:45:21 +00:00
|
|
|
module->Draw( DrawPanel, 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
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Get_Librairie_Module
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2009-04-06 16:05:25 +00:00
|
|
|
* Read active libraries or one library to find and load a given module
|
2009-11-14 22:15:22 +00:00
|
|
|
* If found the module is linked to the tail of linked list of modules
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aLibraryFullFilename: the full filename of the library to read. If empty,
|
2009-11-14 22:15:22 +00:00
|
|
|
* all active libraries are read
|
2009-04-06 16:05:25 +00:00
|
|
|
* @param aModuleName = module name to load
|
|
|
|
* @param aDisplayMessageError = true to display an error message if any.
|
|
|
|
* @return a MODULE * pointer to the new module, or NULL
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2009-04-06 16:05:25 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module(
|
|
|
|
const wxString& aLibraryFullFilename,
|
|
|
|
const wxString& aModuleName,
|
|
|
|
bool aDisplayMessageError )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
int Found = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString Name;
|
|
|
|
wxString msg, tmp;
|
|
|
|
MODULE* NewModule;
|
|
|
|
FILE* file = NULL;
|
|
|
|
unsigned ii;
|
2009-04-06 16:05:25 +00:00
|
|
|
bool one_lib = aLibraryFullFilename.IsEmpty() ? false : true;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
for( ii = 0; ii < g_LibName_List.GetCount(); ii++ )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( one_lib )
|
2009-04-06 16:05:25 +00:00
|
|
|
fn = aLibraryFullFilename;
|
|
|
|
else
|
2009-04-08 18:06:22 +00:00
|
|
|
fn = wxFileName( wxEmptyString, g_LibName_List[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() ) );
|
2009-06-26 12:52:24 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ),
|
|
|
|
wxOK | wxICON_ERROR, this );
|
|
|
|
}
|
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 ) );
|
2009-04-05 20:49:15 +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
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Reading header ENTETE_LIBRAIRIE */
|
2011-01-14 17:43:30 +00:00
|
|
|
reader.ReadLine();
|
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
StrPurge( Line );
|
|
|
|
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "<%s> is not a valid Kicad PCB footprint library file." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( tmp ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ),
|
|
|
|
wxOK | wxICON_ERROR, this );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Reading the list of modules in the library. */
|
2007-08-20 01:20:48 +00:00
|
|
|
Found = 0;
|
2011-01-14 17:43:30 +00:00
|
|
|
while( !Found && reader.ReadLine() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( strnicmp( Line, "$MODULE", 6 ) == 0 )
|
|
|
|
break;
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
StrPurge( Line );
|
|
|
|
msg = CONV_FROM_UTF8( Line );
|
2009-04-06 16:05:25 +00:00
|
|
|
if( msg.CmpNoCase( aModuleName ) == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
Found = 1;
|
2009-11-14 22:15:22 +00:00
|
|
|
break; /* Found! */
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read library. */
|
2011-01-14 17:43:30 +00:00
|
|
|
while( Found && reader.ReadLine() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[1] != 'M' )
|
|
|
|
continue;
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) != 0 )
|
|
|
|
continue;
|
2011-01-16 05:11:17 +00:00
|
|
|
|
|
|
|
StrPurge( Line + 8 );
|
|
|
|
|
|
|
|
// Read module name.
|
2007-08-20 01:20:48 +00:00
|
|
|
Name = CONV_FROM_UTF8( Line + 8 );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( Name.CmpNoCase( aModuleName ) == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-01-05 05:21:35 +00:00
|
|
|
NewModule = new MODULE( GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Switch the locale to standard C (needed to print
|
|
|
|
// floating point numbers like 1.3)
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_C_standard();
|
2011-01-14 17:43:30 +00:00
|
|
|
NewModule->ReadDescr( &reader );
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Add( NewModule, ADD_APPEND );
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( wxEmptyString );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NewModule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Select_1_Module_From_List
|
2010-12-14 15:56:30 +00:00
|
|
|
* Display a list of modules found in active libraries or a given library
|
|
|
|
*
|
|
|
|
* @param aWindow - The active window.
|
|
|
|
* @param aLibraryFullFilename = library to list (if aLibraryFullFilename ==
|
2009-11-14 22:15:22 +00:00
|
|
|
* void, list all modules)
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aMask = Display filter (wildcard)( Mask = wxEmptyString if not used )
|
|
|
|
* @param aKeyWord = keyword list, to display a filtered list of module having
|
2009-11-14 22:15:22 +00:00
|
|
|
* one (or more) of these keyworks in their keywork list
|
|
|
|
* ( aKeyWord = wxEmptyString if not used )
|
2008-04-01 05:21:50 +00:00
|
|
|
*
|
2010-12-29 17:47:32 +00:00
|
|
|
* @return wxEmptyString if abort or fails, or the selected module name if Ok
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
wxString WinEDA_BasePcbFrame::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
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
unsigned ii;
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
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;
|
|
|
|
wxString libFullName;
|
2009-04-05 20:49:15 +00:00
|
|
|
FILE* file;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString msg;
|
2010-11-19 18:50:23 +00:00
|
|
|
wxArrayString itemslist;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
wxBeginBusyCursor();
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Find modules in libraries. */
|
2007-08-20 01:20:48 +00:00
|
|
|
for( ii = 0; ii < g_LibName_List.GetCount(); ii++ )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculate the full file name of the library. */
|
2009-04-06 16:05:25 +00:00
|
|
|
if( aLibraryFullFilename.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = wxFileName( wxEmptyString, g_LibName_List[ii],
|
|
|
|
ModuleFileExtension );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
2009-04-06 16:05:25 +00:00
|
|
|
fn = aLibraryFullFilename;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-02-08 18:39:41 +00:00
|
|
|
libFullName = wxGetApp().FindLibraryPath( fn );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-02-08 18:39:41 +00:00
|
|
|
if( libFullName.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +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() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ),
|
|
|
|
wxOK | wxICON_ERROR, this );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-08 18:39:41 +00:00
|
|
|
ReadDocLib( libFullName );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( !aKeyWord.IsEmpty() ) /* Don't read the library if selection
|
|
|
|
* by keywords, already read. */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aLibraryFullFilename.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-08 18:39:41 +00:00
|
|
|
file = wxFopen( libFullName, wxT( "rt" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( file == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aLibraryFullFilename.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-08 18:39:41 +00:00
|
|
|
FILE_LINE_READER fileReader( file, libFullName );
|
2011-01-14 17:43:30 +00:00
|
|
|
|
|
|
|
FILTER_READER reader( fileReader );
|
|
|
|
|
2008-10-05 10:56:43 +00:00
|
|
|
// Statusbar library loaded message
|
2009-11-14 22:15:22 +00:00
|
|
|
msg = _( "Library " ) + fn.GetFullPath() + _( " loaded" );
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( msg );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read header. */
|
2011-01-14 17:43:30 +00:00
|
|
|
reader.ReadLine();
|
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "<%s> is not a valid Kicad PCB footprint library file." ),
|
2011-02-08 18:39:41 +00:00
|
|
|
GetChars( libFullName ) );
|
|
|
|
wxMessageBox( msg, _( "Library Load Error" ), wxOK | wxICON_ERROR, this );
|
2009-04-05 20:49:15 +00:00
|
|
|
continue;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read library. */
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
|
|
|
if( strnicmp( Line, "$MODULE", 6 ) == 0 )
|
|
|
|
break;
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
strupper( Line );
|
|
|
|
msg = CONV_FROM_UTF8( StrPurge( Line ) );
|
2009-04-06 16:05:25 +00:00
|
|
|
if( aMask.IsEmpty() )
|
2010-11-19 18:50:23 +00:00
|
|
|
itemslist.Add( msg );
|
2010-06-14 20:16:47 +00:00
|
|
|
else if( WildCompareString( aMask, msg, false ) )
|
2010-11-19 18:50:23 +00:00
|
|
|
itemslist.Add( msg );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2009-11-14 22:15:22 +00:00
|
|
|
} /* End read INDEX */
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* End read library. */
|
2009-04-05 20:49:15 +00:00
|
|
|
file = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aLibraryFullFilename.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Create list of modules if search by keyword. */
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aKeyWord.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-08 18:39:41 +00:00
|
|
|
FOOTPRINT_ITEM* ItemMod = MList;
|
2007-08-20 01:20:48 +00:00
|
|
|
while( ItemMod != NULL )
|
|
|
|
{
|
2009-04-06 16:05:25 +00:00
|
|
|
if( KeyWordOk( aKeyWord, ItemMod->m_KeyWord ) )
|
2010-11-19 18:50:23 +00:00
|
|
|
itemslist.Add( ItemMod->m_Name );
|
2007-08-20 01:20:48 +00:00
|
|
|
ItemMod = ItemMod->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxEndBusyCursor();
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
msg.Printf( _( "Modules [%d items]" ), itemslist.GetCount() );
|
2010-12-14 15:56:30 +00:00
|
|
|
WinEDAListBox dlg( aWindow, msg, itemslist, OldName,
|
|
|
|
DisplayCmpDoc, GetComponentDialogPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
dlg.SortList();
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
CmpName = dlg.GetTextSelection();
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
|
|
|
CmpName.Empty();
|
|
|
|
|
|
|
|
while( MList != NULL )
|
|
|
|
{
|
2011-02-08 18:39:41 +00:00
|
|
|
FOOTPRINT_ITEM* NewMod = MList->Next;
|
2007-08-20 01:20:48 +00:00
|
|
|
delete MList;
|
|
|
|
MList = NewMod;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08 18:39:41 +00:00
|
|
|
FOOTPRINT_ITEM* Mod = MList;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( !Mod )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
Name.Empty();
|
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while( Mod )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( !Mod->m_Name.IsEmpty() && ( Mod->m_Name.CmpNoCase( Name ) == 0 ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
Mod = Mod->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Mod )
|
|
|
|
{
|
|
|
|
Name = !Mod->m_Doc.IsEmpty() ? Mod->m_Doc : wxT( "No Doc" );
|
|
|
|
Name += wxT( "\nKeyW: " );
|
|
|
|
Name += !Mod->m_KeyWord.IsEmpty() ? Mod->m_KeyWord : wxT( "No Keyword" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Name = wxEmptyString;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read the doc file and combine with a library ModLibName.
|
|
|
|
* Load in memory the list of docs string pointed to by mlist
|
|
|
|
* ModLibName = full file name of the library modules
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
static void ReadDocLib( const wxString& ModLibName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-08 18:39:41 +00:00
|
|
|
FOOTPRINT_ITEM* NewMod;
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
2009-04-05 20:49:15 +00:00
|
|
|
FILE* LibDoc;
|
|
|
|
wxFileName fn = ModLibName;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( EXT_DOC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( LibDoc = wxFopen( fn.GetFullPath(), wxT( "rt" ) ) ) == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
FILE_LINE_READER fileReader( LibDoc, fn.GetFullPath() );
|
|
|
|
|
|
|
|
FILTER_READER reader( fileReader );
|
|
|
|
|
|
|
|
reader.ReadLine();
|
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( strnicmp( Line, ENTETE_LIBDOC, L_ENTETE_LIB ) != 0 )
|
|
|
|
return;
|
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
|
|
|
if( Line[1] == 'E' )
|
2009-11-14 22:15:22 +00:00
|
|
|
break; ;
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[1] == 'M' ) /* Debut decription 1 module */
|
|
|
|
{
|
2011-02-08 18:39:41 +00:00
|
|
|
NewMod = new FOOTPRINT_ITEM();
|
2007-08-20 01:20:48 +00:00
|
|
|
NewMod->Next = MList;
|
|
|
|
MList = NewMod;
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[0] == '$' ) /* $EndMODULE */
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch( Line[0] )
|
|
|
|
{
|
|
|
|
case 'L': /* LibName */
|
|
|
|
NewMod->m_Name = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'K': /* KeyWords */
|
|
|
|
NewMod->m_KeyWord = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C': /* Doc */
|
|
|
|
NewMod->m_Doc = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-14 22:15:22 +00:00
|
|
|
} /* End read 1 module. */
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Select_1_Module_From_BOARD
|
2010-06-14 20:16:47 +00:00
|
|
|
* Display the list of modules currently existing on the BOARD
|
|
|
|
* @return a pointer to a module if this module is selected or NULL otherwise
|
|
|
|
* @param aPcb = the board from modules can be loaded
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-06-14 20:16:47 +00:00
|
|
|
MODULE* WinEDA_ModuleEditFrame::Select_1_Module_From_BOARD( BOARD* aPcb )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
MODULE* Module;
|
2009-11-14 22:15:22 +00:00
|
|
|
static wxString OldName; /* Save name of last module selectec. */
|
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
|
|
|
|
2010-06-14 20:16:47 +00:00
|
|
|
Module = aPcb->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
|
2010-11-19 18:50:23 +00:00
|
|
|
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
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
WinEDAListBox dlg( this, msg, listnames, wxEmptyString );
|
|
|
|
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;
|
|
|
|
|
2010-06-14 20:16:47 +00:00
|
|
|
Module = aPcb->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
if( CmpName == Module->m_Reference->m_Text )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|