From cf86e18f5cd0f830ea1975724e15d9c8ecbfe4ab Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 8 May 2013 16:47:23 -0400 Subject: [PATCH] Footprint library table work, minor fixes, and code cleaning. * Fix a bug when full file name and path are passed to FOOTPRINT_INFO:: ReadFootprintFiles() which I created in bug fix lp:593989. * Fix a wxString debug assertion in EDA_APP::InitEDA_Appl() when the KICAD environment variable is defined as an empty string. * Add error dialog when libraries cannot be found in system search path when loading footprint using the select footprint dialog. * Add footprint library name column to the EDA_LIST_DIALOG when selecting footprints from the list. * Allow reading all columns from the selected row in EDA_LIST_DIALOG. * Remove redundant sort from EDA_LIST_DIALOG constructor * Add library name member variable and accessors to FOOTPRINT_INFO. * Make headers translatable for Eeschema select component from list dialog. * Add some helper methods to FPID for identifying the FPID type and validity. * Remove a bunch of trailing whitespace and add missing license comments. --- common/displlst.cpp | 91 +++++++++---- common/edaappl.cpp | 2 +- common/footprint_info.cpp | 37 +++--- cvpcb/class_DisplayFootprintsFrame.cpp | 3 +- eeschema/database.cpp | 38 +++++- eeschema/selpart.cpp | 6 +- include/dialog_helpers.h | 10 +- include/footprint_info.h | 42 +++++- include/fp_lib_table.h | 6 + include/fpid.h | 19 +++ include/wxBasePcbFrame.h | 10 +- pcbnew/librairi.cpp | 4 +- pcbnew/loadcmp.cpp | 175 +++++++++++++++---------- pcbnew/module_editor_frame.h | 4 +- pcbnew/modview.cpp | 50 ++++--- pcbnew/modview_frame.h | 43 ++++-- pcbnew/pcb_parser.cpp | 60 ++++----- pcbnew/pcbnew.cpp | 37 ++++-- pcbnew/xchgmod.cpp | 6 +- 19 files changed, 432 insertions(+), 211 deletions(-) diff --git a/common/displlst.cpp b/common/displlst.cpp index c026bc3e28..5dcaca5f52 100644 --- a/common/displlst.cpp +++ b/common/displlst.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 1992-2013 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 + */ + /** * @file displlst.cpp */ @@ -25,22 +49,21 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl column.SetId( i ); column.SetText( aItemHeaders.Item( i ) ); column.SetWidth( 300 / aItemHeaders.Count() ); - EDA_LIST_DIALOG_BASE::m_listBox->InsertColumn( i, column ); + m_listBox->InsertColumn( i, column ); } - + InsertItems( aItemList, 0 ); - - if( m_sortList ) - sortList(); if( !aRefText.IsEmpty() ) // try to select the item matching aRefText { for( unsigned ii = 0; ii < aItemList.size(); ii++ ) + { if( aItemList[ii][0] == aRefText ) { m_listBox->SetItemState( ii, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); break; } + } } if( m_callBackFct == NULL ) @@ -85,12 +108,25 @@ void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event ) sortList(); } -wxString EDA_LIST_DIALOG::GetTextSelection() + +wxString EDA_LIST_DIALOG::GetTextSelection( int aColumn ) { - long item = -1; + wxCHECK_MSG( aColumn < m_listBox->GetColumnCount(), wxEmptyString, + wxT( "Invalid list control column." ) ); + + wxListItem info; + wxString text; + long item = -1; item = m_listBox->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); - wxString text = m_listBox->GetItemText( item ); - return text; + + info.m_mask = wxLIST_MASK_TEXT; + info.m_itemId = item; + info.m_col = aColumn; + + if( !m_listBox->GetItem( info ) ) + return wxEmptyString; + + return info.m_text; } @@ -99,7 +135,7 @@ void EDA_LIST_DIALOG::Append( const wxArrayString& itemList ) long itemIndex = m_listBox->InsertItem( m_listBox->GetItemCount(), itemList[0] ); m_listBox->SetItemData( itemIndex, (long) &(itemList[0]) ); - + // Adding the next columns content for( unsigned i = 1; i < itemList.size(); i++ ) { @@ -107,18 +143,26 @@ void EDA_LIST_DIALOG::Append( const wxArrayString& itemList ) } } -void EDA_LIST_DIALOG::InsertItems( const std::vector& itemList, - int position ) + +void EDA_LIST_DIALOG::InsertItems( const std::vector< wxArrayString >& itemList, int position ) { - for( unsigned i = 0; i < itemList.size(); i++ ) + for( unsigned row = 0; row < itemList.size(); row++ ) { - long itemIndex = m_listBox->InsertItem( position+i, itemList[i].Item( 0 ) ); - m_listBox->SetItemData( itemIndex, (long) &( itemList[i].Item( 0 ) ) ); - - // Adding the next columns content - for( unsigned j = 1; j < itemList[i].GetCount(); j++ ) + wxASSERT( (int) itemList[row].GetCount() == m_listBox->GetColumnCount() ); + + for( unsigned col = 0; col < itemList[row].GetCount(); col++ ) { - m_listBox->SetItem( itemIndex, j, itemList[i].Item( j ) ); + long itemIndex; + + if( col == 0 ) + { + itemIndex = m_listBox->InsertItem( row+position, itemList[row].Item( col ) ); + m_listBox->SetItemData( itemIndex, (long) &itemList[row].Item( col ) ); + } + else + { + m_listBox->SetItem( itemIndex, col, itemList[row].Item( col ) ); + } } } @@ -135,7 +179,7 @@ void EDA_LIST_DIALOG::onCancelClick( wxCommandEvent& event ) void EDA_LIST_DIALOG::onListItemSelected( wxListEvent& event ) { - + if( m_callBackFct ) { m_messages->Clear(); @@ -167,13 +211,14 @@ void EDA_LIST_DIALOG::onClose( wxCloseEvent& event ) /* Sort alphabetically, case insensitive. */ static int wxCALLBACK MyCompareFunction( long aItem1, long aItem2, long aSortData ) -{ +{ wxString* component1Name = (wxString*) aItem1; wxString* component2Name = (wxString*) aItem2; - - return StrNumCmp( *component1Name, *component2Name, INT_MAX, true ); + + return StrNumCmp( *component1Name, *component2Name, INT_MAX, true ); } + void EDA_LIST_DIALOG::sortList() { m_listBox->SortItems( MyCompareFunction, 0 ); diff --git a/common/edaappl.cpp b/common/edaappl.cpp index 0b78a94840..355e7e8976 100644 --- a/common/edaappl.cpp +++ b/common/edaappl.cpp @@ -326,7 +326,7 @@ void EDA_APP::InitEDA_Appl( const wxString& aName, EDA_APP_T aId ) { m_KicadEnv.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); - if( m_KicadEnv.Last() != '/' ) + if( !m_KicadEnv.IsEmpty() && m_KicadEnv.Last() != '/' ) m_KicadEnv += UNIX_STRING_DIR_SEP; } diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index 9daa2072a5..e94c522c18 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -48,20 +48,6 @@ #include -/* Read the list of libraries (*.mod files) - * for each module are stored - * the module name - * documentation string - * associated keywords - * lib name - * Module description format: - * $MODULE c64acmd First line of module description - * Li c64acmd DIN connector Library reference - * Cd Europe 96 AC male vertical documentation string - * Kw PAD_CONN DIN associated keywords - * ...... other data (pads, outlines ..) - * $Endmodule - */ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames ) { // Clear data before reading files @@ -76,12 +62,17 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames ) // Parse Libraries Listed for( unsigned ii = 0; ii < aFootprintsLibNames.GetCount(); ii++ ) { - wxFileName filename( wxEmptyString, aFootprintsLibNames[ii], - LegacyFootprintLibPathExtension ); + // File names can be fully qualified or file name only. + wxFileName filename = aFootprintsLibNames[ii]; - wxString libPath = wxGetApp().FindLibraryPath( filename ); + if( !filename.IsAbsolute() ) + { + filename = wxFileName( wxEmptyString, aFootprintsLibNames[ii], + LegacyFootprintLibPathExtension ); + filename = wxGetApp().FindLibraryPath( filename ); + } - if( !libPath ) + if( !filename.FileExists() ) { m_filesNotFound << filename.GetFullName() << wxT( "\n" ); continue; @@ -89,19 +80,21 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames ) try { - wxArrayString fpnames = pi->FootprintEnumerate( libPath ); + wxArrayString fpnames = pi->FootprintEnumerate( filename.GetFullPath() ); for( unsigned i=0; i m( pi->FootprintLoad( libPath, fpnames[i] ) ); + std::auto_ptr m( pi->FootprintLoad( filename.GetFullPath(), + fpnames[i] ) ); // we're loading what we enumerated, all must be there. wxASSERT( m.get() ); FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO(); + fpinfo->SetLibraryName( filename.GetName() ); + fpinfo->SetLibraryPath( filename.GetFullPath() ); fpinfo->m_Module = fpnames[i]; - fpinfo->m_LibName = libPath; fpinfo->m_padCount = m->GetPadCount(); fpinfo->m_KeyWord = m->GetKeywords(); fpinfo->m_Doc = m->GetDescription(); @@ -111,7 +104,7 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames ) } catch( IO_ERROR ioe ) { - m_filesInvalid << ioe.errorText << wxT("\n"); + m_filesInvalid << ioe.errorText << wxT( "\n" ); } } } diff --git a/cvpcb/class_DisplayFootprintsFrame.cpp b/cvpcb/class_DisplayFootprintsFrame.cpp index 71d334b868..7f006ca337 100644 --- a/cvpcb/class_DisplayFootprintsFrame.cpp +++ b/cvpcb/class_DisplayFootprintsFrame.cpp @@ -533,9 +533,10 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() const wxChar *libname; if( module_info ) - libname = GetChars( module_info->m_LibName ); + libname = GetChars( module_info->GetLibraryPath() ); else libname = GetChars( wxT( "???" ) ); + msg.Printf( _( "Lib: %s" ), libname ); SetStatusText( msg, 0 ); diff --git a/eeschema/database.cpp b/eeschema/database.cpp index 1fc1802311..5071a13cdc 100644 --- a/eeschema/database.cpp +++ b/eeschema/database.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 1992-2013 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 + */ + /** * @file database.cpp */ @@ -16,6 +40,7 @@ extern void DisplayCmpDocAndKeywords( wxString& Name ); + // Used in DataBaseGetName: this is a callback function for EDA_LIST_DIALOG // to display keywords and description of a component void DisplayCmpDocAndKeywords( wxString& Name ) @@ -31,6 +56,7 @@ void DisplayCmpDocAndKeywords( wxString& Name ) Name += wxT( "\nKey Words: " ) + CmpEntry->GetKeyWords(); } + /* * Displays a list of filtered components found in libraries for selection, * Keys is a list of keywords to filter components which do not match these keywords @@ -56,9 +82,9 @@ wxString DataBaseGetName( EDA_DRAW_FRAME* frame, wxString& Keys, wxString& BufNa if( nameList.empty() ) { - if( !BufName.IsEmpty() ) + if( !BufName.IsEmpty() ) { - if( !Keys.IsEmpty() ) + if( !Keys.IsEmpty() ) { msg.Printf( _( "No components found matching name search criteria '%s' and key search criteria '%s'" ), GetChars( BufName ), GetChars( Keys ) ); @@ -71,7 +97,7 @@ wxString DataBaseGetName( EDA_DRAW_FRAME* frame, wxString& Keys, wxString& BufNa } else { - if( !Keys.IsEmpty() ) + if( !Keys.IsEmpty() ) { msg.Printf( _( "No components found matching key search criteria '%s'" ), GetChars( Keys ) ); @@ -88,9 +114,9 @@ wxString DataBaseGetName( EDA_DRAW_FRAME* frame, wxString& Keys, wxString& BufNa } wxArrayString headers; - headers.Add( wxT("Component") ); - headers.Add( wxT("Library") ); - + headers.Add( _( "Component" ) ); + headers.Add( _( "Library" ) ); + // Show candidate list: wxString cmpname; EDA_LIST_DIALOG dlg( frame, _( "Select Component" ), headers, nameList, cmpname, diff --git a/eeschema/selpart.cpp b/eeschema/selpart.cpp index 73775c266a..6368deedc8 100644 --- a/eeschema/selpart.cpp +++ b/eeschema/selpart.cpp @@ -28,10 +28,10 @@ CMP_LIBRARY* SelectLibraryFromList( EDA_DRAW_FRAME* frame ) wxArrayString headers; headers.Add( wxT("Library") ); - + libNamesList = CMP_LIBRARY::GetLibraryNames(); std::vector itemsToDisplay; - + // Conversion from wxArrayString to vector of ArrayString for( unsigned i = 0; i < libNamesList.GetCount(); i++ ) { @@ -77,7 +77,7 @@ int DisplayComponentsNamesInLib( EDA_DRAW_FRAME* frame, headers.Add( wxT("Component") ); headers.Add( wxT("Library") ); std::vector itemsToDisplay; - + // Conversion from wxArrayString to vector of ArrayString for( unsigned i = 0; i < nameList.GetCount(); i++ ) { diff --git a/include/dialog_helpers.h b/include/dialog_helpers.h index 45e3ecfb13..963242223e 100644 --- a/include/dialog_helpers.h +++ b/include/dialog_helpers.h @@ -78,7 +78,15 @@ public: void Append( const wxArrayString& aItemStr ); void InsertItems( const std::vector& aItemList, int aPosition = 0 ); - wxString GetTextSelection(); + + /** + * Function GetTextSelection + * return the selected text from \a aColumn in the wxListCtrl in the dialog. + * + * @param aColumn is the column to return the text from. + * @return a wxString object containing the selected text from \a aColumn. + */ + wxString GetTextSelection( int aColumn = 0 ); private: void onClose( wxCloseEvent& event ); diff --git a/include/footprint_info.h b/include/footprint_info.h index e76a881fe5..ed2cd6cd45 100644 --- a/include/footprint_info.h +++ b/include/footprint_info.h @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2011 Jean-Pierre Charras, + * 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 + */ + /* * @file footprint_info.h */ @@ -12,14 +36,16 @@ /* * Class FOOTPRINT_INFO - * is a helper class to handle the list of footprints - * available in libraries. It stores footprint names, doc and keywords + * is a helper class to handle the list of footprints available in libraries. It stores + * footprint names, doc and keywords */ class FOOTPRINT_INFO { + wxString m_libName; ///< Name of the library containing this module excluding path and ext. + wxString m_libPath; ///< The full library name and path associated the footprint. + public: wxString m_Module; ///< Module name. - wxString m_LibName; ///< Name of the library containing this module. int m_Num; ///< Order number in the display list. wxString m_Doc; ///< Footprint description. wxString m_KeyWord; ///< Footprint key words. @@ -30,6 +56,14 @@ public: m_Num = 0; m_padCount = 0; } + + const wxString& GetFootprintName() const { return m_Module; } + + void SetLibraryName( const wxString& aLibName ) { m_libName = aLibName; } + const wxString& GetLibraryName() const { return m_libName; } + + void SetLibraryPath( const wxString& aLibPath ) { m_libPath = aLibPath; } + const wxString& GetLibraryPath() const { return m_libPath; } }; @@ -85,7 +119,7 @@ public: /** * Function ReadFootprintFiles - * Read the list of libraries (*.mod files) and populates m_List ( list of availaible + * Read the list of libraries (*.mod files) and populates m_List ( list of available * modules in libs ). * for each module, are stored * the module name diff --git a/include/fp_lib_table.h b/include/fp_lib_table.h index 899bc9679a..7010421844 100644 --- a/include/fp_lib_table.h +++ b/include/fp_lib_table.h @@ -365,6 +365,12 @@ public: */ static const wxString ExpandSubtitutions( const wxString aString ); + /** + * Function IsEmpty + * @return true if the footprint library table is empty. + */ + bool IsEmpty() const { return rows.empty(); } + protected: /** diff --git a/include/fpid.h b/include/fpid.h index 657a6a7101..babbb2293c 100644 --- a/include/fpid.h +++ b/include/fpid.h @@ -133,6 +133,25 @@ public: const std::string& aRevision ) throw( PARSE_ERROR ); + /** + * Function IsValid + * @return true is the #FPID is valid. + * + * A valid #FPID must have both the footprint library nickname and the footprint name + * defined. The revision field is optional. + * + * @note A return value of true does not indicated that the #FPID is a valid #FP_LIB_TABLE + * entry. + */ + bool IsValid() const { return !nickname.empty() && !footprint.empty(); } + + + /** + * Function IsLegacy + * @return true if the #FPID only has the #footprint name defined. + */ + bool IsLegacy() const { return nickname.empty() && !footprint.empty() && revision.empty(); } + /** * Function clear * clears the contents of the library nickname, footprint name, and revision strings. diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 970c1ed6ff..24e6332e45 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -432,7 +432,7 @@ public: bool aDisplayError ); /** - * Function Select_1_Module_From_List + * Function SelectFootprint * Display a list of modules found in active libraries or a given library * @param aWindow = the current window ( parent window ) * @param aLibraryFullFilename = library to list (if aLibraryFullFilename @@ -445,10 +445,10 @@ public: * * @return wxEmptyString if abort or fails, or the selected module name if Ok */ - wxString Select_1_Module_From_List( EDA_DRAW_FRAME* aWindow, - const wxString& aLibraryFullFilename, - const wxString& aMask, - const wxString& aKeyWord ); + wxString SelectFootprint( EDA_DRAW_FRAME* aWindow, + const wxString& aLibraryFullFilename, + const wxString& aMask, + const wxString& aKeyWord ); /** * Function Load_Module_From_Library diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index 81e8efa549..966f116703 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -464,8 +464,8 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary() bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary() { wxString libPath = getLibPath(); - wxString footprintName = Select_1_Module_From_List( this, libPath, - wxEmptyString, wxEmptyString ); + wxString footprintName = PCB_BASE_FRAME::SelectFootprint( this, libPath, + wxEmptyString, wxEmptyString ); if( !footprintName ) return false; diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index f4d4070605..49116062b4 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -68,7 +68,7 @@ bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule ) if( ! parent->GetBoard() || ! parent->GetBoard()->m_Modules ) return false; - aModule = Select_1_Module_From_BOARD( parent->GetBoard() ); + aModule = SelectFootprint( parent->GetBoard() ); } if( aModule == NULL ) @@ -114,6 +114,7 @@ bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule ) */ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser( void ) { + wxString fpname; wxSemaphore semaphore( 0, 1 ); // Close the current Lib browser, if opened, and open a new one, in "modal" mode: @@ -132,11 +133,13 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser( void ) wxMilliSleep( 50 ); } +#if !defined( USE_FP_LIB_TABLE ) // Returns the full fp name, i.e. the lib name and th fp name, - // separated by a '/' - // (/ is now an illegal char in fp names) - wxString fpname = viewer->GetSelectedLibraryFullName(); - fpname << wxT("/") << viewer->GetSelectedFootprint(); + // separated by a '/' (/ is now an illegal char in fp names) + fpname = viewer->GetSelectedLibraryFullName() + wxT( "/" ) + viewer->GetSelectedFootprint(); +#else + fpname = viewer->GetSelectedLibrary() + wxT( ":" ) + viewer->GetSelectedFootprint(); +#endif viewer->Destroy(); @@ -145,8 +148,8 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser( void ) MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, - bool aUseFootprintViewer, - wxDC* aDC ) + bool aUseFootprintViewer, + wxDC* aDC ) { MODULE* module; wxPoint curspos = GetScreen()->GetCrossHairPosition(); @@ -158,8 +161,7 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, static wxString lastComponentName; // Ask for a component name or key words - DIALOG_GET_COMPONENT dlg( this, HistoryList, - _( "Load Module" ), aUseFootprintViewer ); + DIALOG_GET_COMPONENT dlg( this, HistoryList, _( "Load Module" ), aUseFootprintViewer ); dlg.SetComponentName( lastComponentName ); @@ -168,12 +170,15 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, if( dlg.m_GetExtraFunction ) { - // SelectFootprintFromLibBrowser() returns the - // "full" footprint name, i.e. - // / + // SelectFootprintFromLibBrowser() returns the "full" footprint name, i.e. + // / or FPID format "lib_name:fp_name:rev#" +#if !defined( USE_FP_LIB_TABLE ) wxString full_fpname = SelectFootprintFromLibBrowser(); moduleName = full_fpname.AfterLast( '/' ); libName = full_fpname.BeforeLast( '/' ); +#else + libName = SelectFootprintFromLibBrowser(); +#endif } else { @@ -186,41 +191,41 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, return NULL; } - if( dlg.IsKeyword() ) // Selection by keywords + if( dlg.IsKeyword() ) // Selection by keywords { allowWildSeach = false; keys = moduleName; - moduleName = Select_1_Module_From_List( this, libName, wxEmptyString, keys ); + moduleName = SelectFootprint( this, libName, wxEmptyString, keys ); - if( moduleName.IsEmpty() ) // Cancel command + if( moduleName.IsEmpty() ) // Cancel command { m_canvas->MoveCursorToCrossHair(); return NULL; } } - else if( ( moduleName.Contains( wxT( "?" ) ) ) - || ( moduleName.Contains( wxT( "*" ) ) ) ) // Selection wild card + else if( moduleName.Contains( wxT( "?" ) ) + || moduleName.Contains( wxT( "*" ) ) ) // Selection wild card { allowWildSeach = false; - moduleName = Select_1_Module_From_List( this, libName, moduleName, wxEmptyString ); + moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString ); if( moduleName.IsEmpty() ) { m_canvas->MoveCursorToCrossHair(); - return NULL; // Cancel command. + return NULL; // Cancel command. } } module = GetModuleLibrary( libName, moduleName, false ); - if( !module && allowWildSeach ) // Search with wild card + if( !module && allowWildSeach ) // Search with wild card { allowWildSeach = false; wxString wildname = wxChar( '*' ) + moduleName + wxChar( '*' ); moduleName = wildname; - moduleName = Select_1_Module_From_List( this, libName, moduleName, wxEmptyString ); + moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString ); if( moduleName.IsEmpty() ) { @@ -243,11 +248,10 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, module->SetFlags( IS_NEW ); module->SetLink( 0 ); - + module->SetPosition( curspos ); module->SetTimeStamp( GetNewTimeStamp() ); GetBoard()->m_Status_Pcb = 0; - module->SetPosition( curspos ); // Put it on FRONT layer, // (Can be stored flipped if the lib is an archive built from a board) @@ -271,7 +275,7 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, MODULE* PCB_BASE_FRAME::GetModuleLibrary( const wxString& aLibraryPath, const wxString& aFootprintName, - bool aDisplayError ) + bool aDisplayError ) { if( aLibraryPath.IsEmpty() ) return loadFootprintFromLibraries( aFootprintName, aDisplayError ); @@ -298,7 +302,7 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibrary( const wxString& aLibraryPath, if( aDisplayError ) { wxString msg = wxString::Format( - _( "Footprint %s not found in library <%s>" ), + _( "Footprint %s not found in library <%s>." ), aFootprintName.GetData(), libPath.GetData() ); @@ -334,7 +338,8 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries( for( unsigned ii = 0; ii < g_LibraryNames.GetCount(); ii++ ) { - wxFileName fn = wxFileName( wxEmptyString, g_LibraryNames[ii], LegacyFootprintLibPathExtension ); + wxFileName fn = wxFileName( wxEmptyString, g_LibraryNames[ii], + LegacyFootprintLibPathExtension ); wxString libPath = wxGetApp().FindLibraryPath( fn ); @@ -367,7 +372,7 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries( if( aDisplayError ) { wxString msg = wxString::Format( - _( "Footprint %s not found in any library" ), + _( "Footprint %s not found in any library." ), aFootprintName.GetData() ); DisplayError( NULL, msg ); @@ -413,71 +418,105 @@ MODULE* PCB_BASE_FRAME::loadFootprint( const wxString& aFootprintName ) } -wxString PCB_BASE_FRAME::Select_1_Module_From_List( EDA_DRAW_FRAME* aWindow, - const wxString& aLibraryFullFilename, - const wxString& aMask, - const wxString& aKeyWord ) +wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, + const wxString& aLibraryFullFilename, + const wxString& aMask, + const wxString& aKeyWord ) { - static wxString OldName; // Save the name of the last module loaded. - wxString CmpName; - wxString msg; - wxArrayString libnames_list; + static wxString OldName; // Save the name of the last module loaded. + wxString CmpName; + wxString msg; + wxArrayString libraries; + std::vector< wxArrayString > rows; + if( aLibraryFullFilename.IsEmpty() ) - libnames_list = g_LibraryNames; + libraries = g_LibraryNames; else - libnames_list.Add( aLibraryFullFilename ); + libraries.Add( aLibraryFullFilename ); + + if( libraries.IsEmpty() ) + { + DisplayError( aWindow, _( "No footprint libraries were specified." ) ); + return wxEmptyString; + } // Find modules in libraries. - MList.ReadFootprintFiles( libnames_list ); + MList.ReadFootprintFiles( libraries ); - wxArrayString footprint_names_list; + if( MList.GetCount() == 0 ) + { + wxString tmp; - if( !aKeyWord.IsEmpty() ) // Create a list of modules found by keyword. + for( unsigned i = 0; i < libraries.GetCount(); i++ ) + { + tmp += libraries[i] + wxT( "\n" ); + } + + msg.Printf( _( "No footprints could be read from library file(s):\n\n%s\nin any of " + "the library search paths. Verify your system is configured properly " + "so the footprint libraries can be found." ), GetChars( tmp ) ); + DisplayError( aWindow, msg ); + return wxEmptyString; + } + + if( !aKeyWord.IsEmpty() ) // Create a list of modules found by keyword. { for( unsigned ii = 0; ii < MList.GetCount(); ii++ ) { - if( KeyWordOk( aKeyWord, MList.GetItem(ii).m_KeyWord ) ) - footprint_names_list.Add( MList.GetItem(ii).m_Module ); + if( KeyWordOk( aKeyWord, MList.GetItem( ii ).m_KeyWord ) ) + { + wxArrayString cols; + cols.Add( MList.GetItem( ii ).GetFootprintName() ); + cols.Add( MList.GetItem( ii ).GetLibraryName() ); + rows.push_back( cols ); + } } } - else if( !aMask.IsEmpty() ) // Create a list of modules found by pattern + 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; + wxString& candidate = MList.GetItem( ii ).m_Module; if( WildCompareString( aMask, candidate, false ) ) - footprint_names_list.Add( candidate ); + { + wxArrayString cols; + cols.Add( MList.GetItem( ii ).GetFootprintName() ); + cols.Add( MList.GetItem( ii ).GetLibraryName() ); + rows.push_back( cols ); + } } } - else // Create the full list of modules + else // Create the full list of modules { for( unsigned ii = 0; ii < MList.GetCount(); ii++ ) - footprint_names_list.Add( MList.GetItem(ii).m_Module ); + { + wxArrayString cols; + cols.Add( MList.GetItem( ii ).GetFootprintName() ); + cols.Add( MList.GetItem( ii ).GetLibraryName() ); + rows.push_back( cols ); + } } - if( footprint_names_list.GetCount() ) + if( !rows.empty() ) { wxArrayString headers; - headers.Add( wxT("Module") ); - std::vector itemsToDisplay; - // Conversion from wxArrayString to vector of ArrayString - for( unsigned i = 0; i < footprint_names_list.GetCount(); i++ ) - { - wxArrayString item; - item.Add( footprint_names_list[i] ); - itemsToDisplay.push_back( item ); - } + headers.Add( _( "Module" ) ); + headers.Add( _( "Library" ) ); - msg.Printf( _( "Modules [%d items]" ), (int) footprint_names_list.GetCount() ); - EDA_LIST_DIALOG dlg( aWindow, msg, headers, itemsToDisplay, OldName, - DisplayCmpDoc ); + msg.Printf( _( "Modules [%d items]" ), (int) rows.size() ); + EDA_LIST_DIALOG dlg( aWindow, msg, headers, rows, OldName, DisplayCmpDoc ); if( dlg.ShowModal() == wxID_OK ) { CmpName = dlg.GetTextSelection(); + +#if defined( USE_FP_LIB_TABLE ) + CmpName += wxT( ":" ) + dlg.GetTextSelection( 1 ); +#endif + SkipNextLeftButtonReleaseEvent(); } else @@ -485,13 +524,15 @@ wxString PCB_BASE_FRAME::Select_1_Module_From_List( EDA_DRAW_FRAME* aWindow, } else { - DisplayError( aWindow, _( "No footprint found" ) ); + DisplayError( aWindow, _( "No footprint found." ) ); CmpName.Empty(); } if( CmpName != wxEmptyString ) OldName = CmpName; + wxLogDebug( wxT( "Footprint <%s> was selected." ), GetChars( CmpName ) ); + return CmpName; } @@ -506,13 +547,12 @@ static void DisplayCmpDoc( wxString& Name ) return; } - 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; + Name = _( "Description: " ) + module_info->m_Doc; + Name += _( "\nKey words: " ) + module_info->m_KeyWord; } -MODULE* FOOTPRINT_EDIT_FRAME::Select_1_Module_From_BOARD( BOARD* aPcb ) +MODULE* FOOTPRINT_EDIT_FRAME::SelectFootprint( BOARD* aPcb ) { MODULE* module; static wxString OldName; // Save name of last module selected. @@ -528,7 +568,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Select_1_Module_From_BOARD( BOARD* aPcb ) msg.Printf( _( "Modules [%d items]" ), listnames.GetCount() ); wxArrayString headers; - headers.Add( wxT("Module") ); + headers.Add( _( "Module" ) ); std::vector itemsToDisplay; // Conversion from wxArrayString to vector of ArrayString @@ -538,6 +578,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Select_1_Module_From_BOARD( BOARD* aPcb ) item.Add( listnames[i] ); itemsToDisplay.push_back( item ); } + EDA_LIST_DIALOG dlg( this, msg, headers, itemsToDisplay, wxEmptyString, NULL, SORT_LIST ); if( dlg.ShowModal() == wxID_OK ) @@ -592,7 +633,7 @@ void FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs( wxCommandEvent& aEvent ) } wxString msg = wxString::Format( - _( "Footprint library <%s> saved as <%s>" ), + _( "Footprint library <%s> saved as <%s>." ), GetChars( curLibPath ), GetChars( dstLibPath ) ); DisplayInfoMessage( this, msg ); diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index fe51bfe96a..cfeb996627 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -285,12 +285,12 @@ public: bool Load_Module_From_BOARD( MODULE* Module ); /** - * Function Select_1_Module_From_BOARD + * Function SelectFootprint * 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 */ - MODULE* Select_1_Module_From_BOARD( BOARD* aPcb ); + MODULE* SelectFootprint( BOARD* aPcb ); // functions to edit footprint edges diff --git a/pcbnew/modview.cpp b/pcbnew/modview.cpp index e366493cbc..1ffeab8726 100644 --- a/pcbnew/modview.cpp +++ b/pcbnew/modview.cpp @@ -1,5 +1,29 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2004-2012 KiCad Developers, see change_log.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 + */ + /** - * @file viewlibs.cpp + * @file modview.cpp */ #include @@ -85,7 +109,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event ) return; wxArrayString headers; - headers.Add( wxT("Library") ); + headers.Add( wxT( "Library" ) ); std::vector itemsToDisplay; // Conversion from wxArrayString to vector of ArrayString @@ -95,6 +119,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event ) item.Add( g_LibraryNames[i] ); itemsToDisplay.push_back( item ); } + EDA_LIST_DIALOG dlg( this, _( "Select Current Library:" ), headers, itemsToDisplay, m_libraryName ); @@ -110,35 +135,35 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event ) ReCreateFootprintList(); int id = m_LibList->FindString( m_libraryName ); + if( id >= 0 ) m_LibList->SetSelection( id ); } -/** - * Function SelectCurrentFootprint - * Selects the current footprint name and display it - */ + void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event ) { - wxString libname = m_libraryName + wxT(".") + LegacyFootprintLibPathExtension; + wxString libname = m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension; MODULE* oldmodule = GetBoard()->m_Modules; MODULE * module = Load_Module_From_Library( libname, false ); + if( module ) { module->SetPosition( wxPoint( 0, 0 ) ); - // Only one fotprint allowed: remove the previous footprint (if exists) + // Only one footprint allowed: remove the previous footprint (if exists) if( oldmodule ) { GetBoard()->Remove( oldmodule ); delete oldmodule; } + m_footprintName = module->GetLibRef(); module->ClearFlags(); SetCurItem( NULL ); Zoom_Automatique( false ); - m_canvas->Refresh( ); + m_canvas->Refresh(); Update3D_Frame(); m_FootprintList->SetStringSelection( m_footprintName ); } @@ -147,7 +172,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event ) const wxString FOOTPRINT_VIEWER_FRAME::GetSelectedLibraryFullName( void ) { - wxString fullname = m_libraryName + wxT(".") + LegacyFootprintLibPathExtension; + wxString fullname = m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension; return fullname; } @@ -188,11 +213,6 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) } -/** - * Function RedrawActiveWindow - * Display the current selected component. - * If the component is an alias, the ROOT component is displayed -*/ void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) { if( !GetBoard() ) diff --git a/pcbnew/modview_frame.h b/pcbnew/modview_frame.h index b07a9002b7..f034df5525 100644 --- a/pcbnew/modview_frame.h +++ b/pcbnew/modview_frame.h @@ -45,23 +45,23 @@ class FOOTPRINT_VIEWER_FRAME : public PCB_BASE_FRAME private: // List of libraries (for selection ) wxSashLayoutWindow* m_LibListWindow; - wxListBox* m_LibList; // The list of libs names - wxSize m_LibListSize; // size of the window + wxListBox* m_LibList; // The list of libs names + wxSize m_LibListSize; // size of the window // List of components in the selected library wxSashLayoutWindow* m_FootprintListWindow; - wxListBox* m_FootprintList; // The list of footprint names - wxSize m_FootprintListSize; // size of the window + wxListBox* m_FootprintList; // The list of footprint names + wxSize m_FootprintListSize; // size of the window // Flags - wxSemaphore* m_Semaphore; // != NULL if the frame must emulate a modal dialog - wxString m_configPath; // subpath for configuration + wxSemaphore* m_Semaphore; // != NULL if the frame must emulate a modal dialog + wxString m_configPath; // subpath for configuration protected: - static wxString m_libraryName; // Current selected libary - static wxString m_footprintName; // Current selected footprint - static wxString m_selectedFootprintName; // When the viewer is used to select a footprint - // the selected footprint is here + static wxString m_libraryName; // Current selected library + static wxString m_footprintName; // Current selected footprint + static wxString m_selectedFootprintName; // When the viewer is used to select a footprint + // the selected footprint is here public: FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* parent, wxSemaphore* semaphore = NULL, @@ -86,7 +86,14 @@ public: wxString& GetSelectedFootprint( void ) const { return m_selectedFootprintName; } const wxString GetSelectedLibraryFullName( void ); + /** + * Function GetSelectedLibrary + * @return the selected library name from the #FP_LIB_TABLE. + */ + const wxString& GetSelectedLibrary() { return m_libraryName; } + virtual EDA_COLOR_T GetGridColor( void ) const; + private: void OnSize( wxSizeEvent& event ); @@ -109,7 +116,14 @@ private: void ReCreateFootprintList(); void Process_Special_Functions( wxCommandEvent& event ); void DisplayLibInfos(); + + /** + * Function RedrawActiveWindow + * Display the current selected component. + * If the component is an alias, the ROOT component is displayed + */ void RedrawActiveWindow( wxDC* DC, bool EraseBg ); + void OnCloseWindow( wxCloseEvent& Event ); void ReCreateHToolbar(); void ReCreateVToolbar(); @@ -150,6 +164,10 @@ private: void SelectCurrentLibrary( wxCommandEvent& event ); + /** + * Function SelectCurrentFootprint + * Selects the current footprint name and display it + */ void SelectCurrentFootprint( wxCommandEvent& event ); /** @@ -161,7 +179,8 @@ private: /** * Function SelectAndViewFootprint * Select and load the next or the previous footprint - * if no current footprint, Rebuild the list of footprints availlable in a given footprint library + * if no current footprint, Rebuild the list of footprints available in a given footprint + * library * @param aMode = NEXT_PART or PREVIOUS_PART */ void SelectAndViewFootprint( int aMode ); @@ -179,7 +198,7 @@ private: * must be called after a footprint selection * Updates the 3D view and 3D frame title. * @param aForceReloadFootprint = true to reload data (default) - * = false to update title only -(aftre creating the 3D viewer) + * = false to update title only -(after creating the 3D viewer) */ void Update3D_Frame( bool aForceReloadFootprint = true ); diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 9535ffad55..353ca582af 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -612,40 +612,40 @@ void PCB_PARSER::parseTITLE_BLOCK() throw( IO_ERROR, PARSE_ERROR ) break; case T_comment: + { + int commentNumber = parseInt( "comment" ); + + switch( commentNumber ) { - int commentNumber = parseInt( "comment" ); - - switch( commentNumber ) - { - case 1: - NextTok(); - titleBlock.SetComment1( FromUTF8() ); - break; - - case 2: - NextTok(); - titleBlock.SetComment2( FromUTF8() ); - break; - - case 3: - NextTok(); - titleBlock.SetComment3( FromUTF8() ); - break; - - case 4: - NextTok(); - titleBlock.SetComment4( FromUTF8() ); - break; - - default: - wxString err; - err.Printf( wxT( "%d is not a valid title block comment number" ), commentNumber ); - THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); - } - + case 1: + NextTok(); + titleBlock.SetComment1( FromUTF8() ); break; + + case 2: + NextTok(); + titleBlock.SetComment2( FromUTF8() ); + break; + + case 3: + NextTok(); + titleBlock.SetComment3( FromUTF8() ); + break; + + case 4: + NextTok(); + titleBlock.SetComment4( FromUTF8() ); + break; + + default: + wxString err; + err.Printf( wxT( "%d is not a valid title block comment number" ), commentNumber ); + THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } + break; + } + default: Expecting( "title, date, rev, company, or comment" ); } diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 279829bb44..65ac98731c 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -62,7 +62,7 @@ bool g_Show_Module_Ratsnest; bool g_Raccord_45_Auto = true; bool g_Alternate_Track_Posture = false; bool g_Track_45_Only_Allowed = true; // True to allow horiz, vert. and 45deg only tracks -bool g_Segments_45_Only; // True to allow horiz, vert. and 45deg only graphic segments +bool g_Segments_45_Only; // True to allow horiz, vert. and 45deg only graphic segments bool g_TwoSegmentTrackBuild = true; LAYER_NUM g_Route_Layer_TOP; @@ -78,7 +78,7 @@ wxPoint g_Offset_Module; /* Distance to offset module trace when movi * this is of the responsibility to users to create this file * if they want to have a list of footprints */ -wxString g_DocModulesFileName = wxT( "footprints_doc/footprints.pdf" ); +wxString g_DocModulesFileName = wxT( "footprints_doc/footprints.pdf" ); wxArrayString g_LibraryNames; @@ -101,11 +101,12 @@ void EDA_APP::MacOpenFile( const wxString& fileName ) frame->LoadOnePcbFile( fileName, false ); } + bool EDA_APP::OnInit() { wxFileName fn; PCB_EDIT_FRAME* frame = NULL; - wxString msg; + wxString msg; #ifdef KICAD_SCRIPTING if ( !pcbnewInitPythonScripting() ) @@ -130,9 +131,10 @@ bool EDA_APP::OnInit() if( fn.GetExt() != PcbFileExtension && fn.GetExt() != LegacyPcbFileExtension ) { - msg.Printf( _( "Pcbnew file <%s> has a wrong extension.\n\ -Changing extension to .%s." ), GetChars( fn.GetFullPath() ), - GetChars( PcbFileExtension ) ); + msg.Printf( _( "Pcbnew file <%s> has a wrong extension.\n" + "Changing extension to .%s." ), + GetChars( fn.GetFullPath() ), + GetChars( PcbFileExtension ) ); fn.SetExt( PcbFileExtension ); wxMessageBox( msg ); } @@ -185,6 +187,11 @@ Changing extension to .%s." ), GetChars( fn.GetFullPath() ), // Some will be overwritten after loading the board file frame->LoadProjectSettings( fn.GetFullPath() ); + // Set the KISYSMOD environment variable for the current process if it is not already + // defined. This is required to expand the global footprint library table paths. + if( !wxGetEnv( wxT( "KISYSMOD" ), &msg ) && !GetLibraryPathList().IsEmpty() ) + wxSetEnv( wxT( "KISYSMOD" ), GetLibraryPathList()[0] ); + /* Load file specified in the command line. */ if( fn.IsOk() ) { @@ -210,13 +217,16 @@ Changing extension to .%s." ), GetChars( fn.GetFullPath() ), // Try to find a legacy file with the same name: wxFileName fn_legacy = fn; fn_legacy.SetExt( LegacyPcbFileExtension ); + if( fn_legacy.FileExists() ) { - msg.Printf( _( "File <%s> does not exist.\n\ -However a legacy file <%s> exists.\nDo you want to load it?\n\ -It will be saved under the new file format" ), + msg.Printf( _( "File <%s> does not exist.\n" + "However a legacy file <%s> exists.\n" + "Do you want to load it?\n" + "It will be saved under the new file format." ), GetChars( fn.GetFullPath() ), GetChars( fn_legacy.GetFullPath() ) ); + if( IsOK( frame, msg ) ) { file_exists = true; @@ -225,7 +235,7 @@ It will be saved under the new file format" ), filename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); frame->GetBoard()->SetFileName( filename ); frame->UpdateTitle(); - frame->OnModify(); // Ready to save theboard inder the new fmt + frame->OnModify(); // Ready to save the board under the new format } } } @@ -234,6 +244,7 @@ It will be saved under the new file format" ), { // File does not exists: prepare an empty board if( ! fn.GetPath().IsEmpty() ) wxSetWorkingDirectory( fn.GetPath() ); + frame->GetBoard()->SetFileName( fn.GetFullPath( wxPATH_UNIX ) ); frame->UpdateTitle(); frame->UpdateFileHistory( frame->GetBoard()->GetFileName() ); @@ -267,12 +278,14 @@ It will be saved under the new file format" ), return true; } + #if 0 // for some reason KiCad classes do not implement OnExit // if I add it in the declaration, I need to fix it in every application // so for now make a note TODO TODO // we need to clean up python when the application exits -int EDA_APP::OnExit() { +int EDA_APP::OnExit() +{ // Restore the thread state and tell Python to cleanup after itself. // wxPython will do its own cleanup as part of that process. This is done // in OnExit instead of ~MyApp because OnExit is only called if OnInit is @@ -284,5 +297,3 @@ int EDA_APP::OnExit() { } #endif - - diff --git a/pcbnew/xchgmod.cpp b/pcbnew/xchgmod.cpp index dafa481d23..9e529c247c 100644 --- a/pcbnew/xchgmod.cpp +++ b/pcbnew/xchgmod.cpp @@ -589,10 +589,8 @@ void DIALOG_EXCHANGE_MODULE::BrowseAndSelectFootprint( wxCommandEvent& event ) { wxString newname; - newname = m_Parent->Select_1_Module_From_List( m_Parent, - wxEmptyString, - wxEmptyString, - wxEmptyString ); + newname = m_Parent->SelectFootprint( m_Parent, wxEmptyString, wxEmptyString, wxEmptyString ); + if( newname != wxEmptyString ) m_NewModule->SetValue( newname ); }