From 5560cb54e2a459db80b1a073a1e05b9b5ed32ed4 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Tue, 28 May 2013 12:54:59 -0400 Subject: [PATCH] More Pcbnew footprint library table work in progress. * Add footprint library table loading to footprint editor. * Overload FOOTPRINT_INFO::ReadFootprintFiles() to read footprints from the footprint library tables. * Fix a bug in FP_LIB_TABLE::IsEmpty() when the table has a fallback table. * Add code to FOOTPRINT_EDIT_FRAME to use footprint library tables. * Add an optional build time version of PCB_EDIT_FRAME::loadFootprints() to populate netlist footprints from footprint library table. * Remove adding footprints to board whenever GetModuleLibrary() is called and move loading locally as required. * Add missing source file license comments and coding policy fixes. --- common/footprint_info.cpp | 56 ++++ common/fp_lib_table.cpp | 9 + common/title_block_shapes.cpp | 2 +- common/title_block_shapes_gost.cpp | 2 +- include/footprint_info.h | 8 +- include/fp_lib_table.h | 2 +- include/worksheet_shape_builder.h | 1 + include/wxBasePcbFrame.h | 3 +- pcbnew/edit.cpp | 9 +- pcbnew/editmod.cpp | 39 ++- pcbnew/kicad_netlist_reader.cpp | 2 +- pcbnew/legacy_netlist_reader.cpp | 2 +- pcbnew/librairi.cpp | 64 +++- pcbnew/loadcmp.cpp | 92 ++++-- pcbnew/modedit.cpp | 352 ++++++++++++---------- pcbnew/module_editor_frame.h | 35 ++- pcbnew/moduleframe.cpp | 13 +- pcbnew/modview.cpp | 6 +- pcbnew/modview_frame.cpp | 14 +- pcbnew/netlist.cpp | 93 ++++++ pcbnew/netlist_reader.cpp | 2 +- pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h | 2 +- pcbnew/pcbframe.cpp | 17 ++ pcbnew/pcbnew_config.cpp | 16 - pcbnew/specctra_export.cpp | 1 + pcbnew/xchgmod.cpp | 18 +- 26 files changed, 598 insertions(+), 262 deletions(-) diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index 212a28a3e9..cc5368a5af 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -124,3 +125,58 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames ) return true; } + + +bool FOOTPRINT_LIST::ReadFootprintFiles( FP_LIB_TABLE& aTable ) +{ + // Clear data before reading files + m_filesNotFound.Empty(); + m_filesInvalid.Empty(); + m_List.clear(); + + std::vector< wxString > libNickNames = aTable.GetLogicalLibs(); + + // Parse Libraries Listed + for( unsigned ii = 0; ii < libNickNames.size(); ii++ ) + { + const FP_LIB_TABLE::ROW* row = aTable.FindRow( libNickNames[ii] ); + + wxCHECK2_MSG( row != NULL, continue, + wxString::Format( wxT( "No library name <%s> found in footprint library " + "table." ), GetChars( libNickNames[ii] ) ) ); + try + { + PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::EnumFromStr( row->GetType() ) ) ); + + wxString path = FP_LIB_TABLE::ExpandSubstitutions( row->GetFullURI() ); + wxArrayString fpnames = pi->FootprintEnumerate( path ); + + for( unsigned i=0; i m( pi->FootprintLoad( path, fpnames[i] ) ); + + // we're loading what we enumerated, all must be there. + wxASSERT( m.get() ); + + FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO(); + + fpinfo->SetLibraryName( libNickNames[ii] ); + fpinfo->SetLibraryPath( path ); + fpinfo->m_Module = fpnames[i]; + fpinfo->m_padCount = m->GetPadCount(); + fpinfo->m_KeyWord = m->GetKeywords(); + fpinfo->m_Doc = m->GetDescription(); + + AddItem( fpinfo ); + } + } + catch( IO_ERROR ioe ) + { + m_filesInvalid << ioe.errorText << wxT( "\n" ); + } + } + + m_List.sort(); + + return true; +} diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 8eb08658b4..b03f8d3a2e 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -310,6 +310,15 @@ const wxString FP_LIB_TABLE::ExpandSubstitutions( const wxString aString ) } +bool FP_LIB_TABLE::IsEmpty() const +{ + if( fallBack == NULL ) + return rows.empty(); + + return fallBack->IsEmpty() && rows.empty(); +} + + void FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR ) { wxFileName fn = GetGlobalTableFileName(); diff --git a/common/title_block_shapes.cpp b/common/title_block_shapes.cpp index b76062935b..b00f95c49a 100644 --- a/common/title_block_shapes.cpp +++ b/common/title_block_shapes.cpp @@ -1,5 +1,5 @@ /** - * @file title_block_shape.cpp + * @file title_block_shapes.cpp * @brief description of graphic items and texts to build a title block */ diff --git a/common/title_block_shapes_gost.cpp b/common/title_block_shapes_gost.cpp index 2b467a5826..e5ccad4ba9 100644 --- a/common/title_block_shapes_gost.cpp +++ b/common/title_block_shapes_gost.cpp @@ -1,5 +1,5 @@ /** - * @file title_block_shape_gost.h + * @file title_block_shapes_gost.cpp * @brief description of graphic items and texts to build a title block * using GOST standard */ diff --git a/include/footprint_info.h b/include/footprint_info.h index 7f073aa1ca..b52fcf997a 100644 --- a/include/footprint_info.h +++ b/include/footprint_info.h @@ -34,6 +34,10 @@ #include + +class FP_LIB_TABLE; + + /* * Class FOOTPRINT_INFO * is a helper class to handle the list of footprints available in libraries. It stores @@ -136,7 +140,9 @@ public: * * @param aFootprintsLibNames = an array string giving the list of libraries to load */ - bool ReadFootprintFiles( wxArrayString & aFootprintsLibNames ); + bool ReadFootprintFiles( wxArrayString& aFootprintsLibNames ); + + bool ReadFootprintFiles( FP_LIB_TABLE& aTable ); }; /// FOOTPRINT object list sort function. diff --git a/include/fp_lib_table.h b/include/fp_lib_table.h index 955bb6d306..8c86d00aaa 100644 --- a/include/fp_lib_table.h +++ b/include/fp_lib_table.h @@ -359,7 +359,7 @@ public: * Function IsEmpty * @return true if the footprint library table is empty. */ - bool IsEmpty() const { return rows.empty(); } + bool IsEmpty() const; /** * Function ExpandEnvSubsitutions diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h index 172885cdec..c0d27da722 100644 --- a/include/worksheet_shape_builder.h +++ b/include/worksheet_shape_builder.h @@ -256,6 +256,7 @@ public: * * @param aPaperFormat The paper size type, for basic inscriptions. * @param aFileName The file name, for basic inscriptions. + * @param aSheetPathHumanReadable The human readable sheet path. * @param aTitleBlock The sheet title block, for basic inscriptions. * @param aLineColor The color for drawing and fixed text. * @param aTextColor The color for user inscriptions. diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 6a01be4d43..842b9059d6 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -402,12 +402,11 @@ public: * if it is a short name, the file is searched in all library valid paths * @param aFootprintName is the footprint to load * @param aDisplayError = true to display an error message if any. - * @param aAddToBoard Set to true to add the footprint to the board if found. * * @return MODULE* - new module, or NULL */ MODULE* loadFootprintFromLibrary( const wxString& aLibraryPath, const wxString& aFootprintName, - bool aDisplayError, bool aAddToBoard = true ); + bool aDisplayError ); /** * Function loadFootprintFromLibraries diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 5639a2946d..c89dfc68dc 100755 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -193,7 +193,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor(); if( editorFrame == NULL ) { - editorFrame = new FOOTPRINT_EDIT_FRAME( this ); + editorFrame = new FOOTPRINT_EDIT_FRAME( this, m_footprintLibTable ); editorFrame->Show( true ); editorFrame->Zoom_Automatique( false ); } @@ -809,10 +809,11 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) OnModify(); } { - FOOTPRINT_EDIT_FRAME * editorFrame = - FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor(); + FOOTPRINT_EDIT_FRAME * editorFrame = FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor(); + + if( editorFrame == NULL ) - editorFrame = new FOOTPRINT_EDIT_FRAME( this ); + editorFrame = new FOOTPRINT_EDIT_FRAME( this, m_footprintLibTable ); editorFrame->Load_Module_From_BOARD( (MODULE*)GetCurItem() ); SetCurItem( NULL ); // the current module could be deleted by diff --git a/pcbnew/editmod.cpp b/pcbnew/editmod.cpp index 33e997ff4d..1f217d6194 100644 --- a/pcbnew/editmod.cpp +++ b/pcbnew/editmod.cpp @@ -1,7 +1,30 @@ -/************************************************/ -/* Module editor: Dialog box for editing module */ -/* properties and characteristics */ -/************************************************/ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * @file edit.cpp + * @brief Module editor dialog box for editing module properties and characteristics. + */ #include #include @@ -50,10 +73,10 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC ) if( retvalue == 2 ) { - FOOTPRINT_EDIT_FRAME * editorFrame = - FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor(); + FOOTPRINT_EDIT_FRAME* editorFrame = FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor(); + if( editorFrame == NULL ) - editorFrame = new FOOTPRINT_EDIT_FRAME( this ); + editorFrame = new FOOTPRINT_EDIT_FRAME( this, m_footprintLibTable ); editorFrame->Load_Module_From_BOARD( Module ); SetCurItem( NULL ); @@ -89,7 +112,7 @@ void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item ) DisplayError( this, _( "Cannot delete VALUE!" ) ); break; - default: + default: DeleteTextModule( text ); } } diff --git a/pcbnew/kicad_netlist_reader.cpp b/pcbnew/kicad_netlist_reader.cpp index 9b60167d08..6cdd613810 100644 --- a/pcbnew/kicad_netlist_reader.cpp +++ b/pcbnew/kicad_netlist_reader.cpp @@ -1,5 +1,5 @@ /** - * @file pcbnew/netlist_reader_kicad.cpp + * @file kicad_netlist_reader.cpp */ /* * This program source code file is part of KiCad, a free EDA CAD application. diff --git a/pcbnew/legacy_netlist_reader.cpp b/pcbnew/legacy_netlist_reader.cpp index 7bd95830e2..364959a904 100644 --- a/pcbnew/legacy_netlist_reader.cpp +++ b/pcbnew/legacy_netlist_reader.cpp @@ -1,5 +1,5 @@ /** - * @file pcbnew/netlist_reader_firstformat.cpp + * @file pcbnew/legacy_netlist_reader.cpp */ /* diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index 72cc975729..7c4aa15d20 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -36,10 +36,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -93,7 +93,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module() { // use the clipboard for this in the future? - // Some day it might be useful save the last library type selected aong with the path. + // Some day it might be useful save the last library type selected along with the path. static int lastFilterIndex = 0; wxString lastOpenedPathForLoading; wxConfig* config = wxGetApp().GetSettings(); @@ -298,7 +298,7 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule ) } wxFileDialog dlg( this, FMT_EXPORT_MODULE, fn.GetPath(), fn.GetFullName(), - wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); + wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if( dlg.ShowModal() == wxID_CANCEL ) return; @@ -655,7 +655,7 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibPath, if( aDisplayDialog ) { wxString msg = wxString::Format( FMT_MOD_EXISTS, - footprintName.GetData(), aLibPath.GetData() ); + footprintName.GetData(), aLibPath.GetData() ); SetStatusText( msg ); } @@ -748,16 +748,18 @@ MODULE* PCB_BASE_FRAME::Create_1_Module( const wxString& aModuleName ) } +#if !defined( USE_FP_LIB_TABLE ) + void FOOTPRINT_EDIT_FRAME::Select_Active_Library() { if( g_LibraryNames.GetCount() == 0 ) return; wxArrayString headers; - headers.Add( wxT("Library") ); - + headers.Add( _( "Library" ) ); + std::vector itemsToDisplay; - + // Conversion from wxArrayString to vector of ArrayString for( unsigned i = 0; i < g_LibraryNames.GetCount(); i++ ) { @@ -765,6 +767,7 @@ void FOOTPRINT_EDIT_FRAME::Select_Active_Library() item.Add( g_LibraryNames[i] ); itemsToDisplay.push_back( item ); } + EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, getLibNickName() ); if( dlg.ShowModal() != wxID_OK ) @@ -793,3 +796,50 @@ void FOOTPRINT_EDIT_FRAME::Select_Active_Library() updateTitle(); } +#else + +void FOOTPRINT_EDIT_FRAME::Select_Active_Library() +{ + if( m_footprintLibTable->IsEmpty() ) + return; + + wxArrayString headers; + headers.Add( _( "Library" ) ); + + std::vector< wxArrayString > itemsToDisplay; + std::vector< wxString > libNames = m_footprintLibTable->GetLogicalLibs(); + + for( unsigned i = 0; i < libNames.size(); i++ ) + { + wxArrayString item; + item.Add( libNames[i] ); + itemsToDisplay.push_back( item ); + } + + EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, getLibNickName() ); + + if( dlg.ShowModal() != wxID_OK ) + return; + + setLibNickName( dlg.GetTextSelection() ); + wxString uri = m_footprintLibTable->FindRow( dlg.GetTextSelection() )->GetFullURI(); + wxFileName fileName = FP_LIB_TABLE::ExpandSubstitutions( uri ); + + if( fileName.IsOk() && fileName.FileExists() ) + { + setLibPath( fileName.GetFullPath() ); + } + else + { + wxString msg = wxString::Format( FMT_BAD_PATHS, GetChars( dlg.GetTextSelection() ) ); + + DisplayError( this, msg ); + + setLibNickName( wxEmptyString ); + setLibPath( wxEmptyString ); + } + + updateTitle(); +} + +#endif diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index 2cd9db7dec..ae766cd6cc 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -180,7 +180,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, moduleName = full_fpname.AfterLast( '/' ); libName = full_fpname.BeforeLast( '/' ); #else - libName = SelectFootprintFromLibBrowser(); + moduleName = SelectFootprintFromLibBrowser(); #endif } else @@ -219,7 +219,25 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, } } +#if !defined( USE_FP_LIB_TABLE ) module = GetModuleLibrary( libName, moduleName, false ); +#else + FPID fpid; + + wxCHECK_MSG( fpid.Parse( TO_UTF8( moduleName ) ) < 0, NULL, + wxString::Format( wxT( "Could not parse FPID string <%s>." ), + GetChars( moduleName ) ) ); + + try + { + module = loadFootprint( fpid ); + } + catch( IO_ERROR ioe ) + { + wxLogDebug( wxT( "An error occurred attemping to load footprint <%s>.\n\nError: %s" ), + fpid.Format().c_str(), GetChars( ioe.errorText ) ); + } +#endif if( !module && allowWildSeach ) // Search with wild card { @@ -237,7 +255,25 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, } else { +#if !defined( USE_FP_LIB_TABLE ) module = GetModuleLibrary( libName, moduleName, true ); +#else + FPID fpid; + + wxCHECK_MSG( fpid.Parse( TO_UTF8( moduleName ) ) < 0, NULL, + wxString::Format( wxT( "Could not parse FPID string <%s>." ), + GetChars( moduleName ) ) ); + + try + { + module = loadFootprint( fpid ); + } + catch( IO_ERROR ioe ) + { + wxLogDebug( wxT( "An error occurred attemping to load footprint <%s>.\n\nError: %s" ), + fpid.Format().c_str(), GetChars( ioe.errorText ) ); + } +#endif } } @@ -246,6 +282,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, if( module ) { + GetBoard()->Add( module, ADD_APPEND ); lastComponentName = moduleName; AddHistoryComponentName( HistoryList, moduleName ); @@ -289,8 +326,7 @@ MODULE* PCB_BASE_FRAME::GetModuleLibrary( const wxString& aLibraryPath, MODULE* PCB_BASE_FRAME::loadFootprintFromLibrary( const wxString& aLibraryPath, const wxString& aFootprintName, - bool aDisplayError, - bool aAddToBoard ) + bool aDisplayError ) { try { @@ -315,9 +351,6 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibrary( const wxString& aLibraryPath, return NULL; } - if( aAddToBoard ) - GetBoard()->Add( footprint, ADD_APPEND ); - SetStatusText( wxEmptyString ); return footprint; } @@ -357,6 +390,7 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries( DisplayError( this, msg ); showed_error = true; } + continue; } @@ -364,7 +398,6 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries( if( footprint ) { - GetBoard()->Add( footprint, ADD_APPEND ); SetStatusText( wxEmptyString ); return footprint; } @@ -432,25 +465,14 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, wxString CmpName; wxString msg; wxArrayString libraries; + FP_LIB_TABLE libTable; std::vector< wxArrayString > rows; +#if !defined( USE_FP_LIB_TABLE ) if( aLibraryFullFilename.IsEmpty() ) { -#if !defined( USE_FP_LIB_TABLE ) libraries = g_LibraryNames; -#else - wxASSERT( aTable != NULL ); - - std::vector< wxString > libNames = aTable->GetLogicalLibs(); - - for( unsigned i = 0; i < libNames.size(); i++ ) - { - wxString uri = aTable->FindRow( libNames[i] )->GetFullURI(); - uri = FP_LIB_TABLE::ExpandSubstitutions( uri ); - libraries.Add( uri ); - } -#endif } else { @@ -463,8 +485,34 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, return wxEmptyString; } - // Find modules in libraries. MList.ReadFootprintFiles( libraries ); +#else + wxASSERT( aTable != NULL ); + + if( aLibraryFullFilename.IsEmpty() ) + { + std::vector< wxString > libNames = aTable->GetLogicalLibs(); + + for( unsigned i = 0; i < libNames.size(); i++ ) + { + FP_LIB_TABLE::ROW row = *aTable->FindRow( libNames[i] ); + libTable.InsertRow( row ); + } + } + else + { + FP_LIB_TABLE::ROW row = *aTable->FindRow( aLibraryFullFilename ); + libTable.InsertRow( row ); + } + + if( libTable.IsEmpty() ) + { + DisplayError( aWindow, _( "No footprint libraries were specified." ) ); + return wxEmptyString; + } + + MList.ReadFootprintFiles( libTable ); +#endif if( MList.GetCount() == 0 ) { @@ -536,7 +584,7 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, CmpName = dlg.GetTextSelection(); #if defined( USE_FP_LIB_TABLE ) - CmpName += wxT( ":" ) + dlg.GetTextSelection( 1 ); + CmpName = dlg.GetTextSelection( 1 ) + wxT( ":" ) + CmpName; #endif SkipNextLeftButtonReleaseEvent(); diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 50aad23fcf..dc3c6b5e25 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -1,3 +1,26 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + /** * @file modedit.cpp */ @@ -232,102 +255,100 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_OPEN_MODULE_VIEWER: + { + FOOTPRINT_VIEWER_FRAME * viewer = FOOTPRINT_VIEWER_FRAME::GetActiveFootprintViewer(); + + if( viewer == NULL ) { - FOOTPRINT_VIEWER_FRAME * viewer = FOOTPRINT_VIEWER_FRAME::GetActiveFootprintViewer(); - - if( viewer == NULL ) - { - viewer = new FOOTPRINT_VIEWER_FRAME( this, m_footprintLibTable, NULL ); - viewer->Show( true ); - viewer->Zoom_Automatique( false ); - } - else - { - if( viewer->IsIconized() ) - viewer->Iconize( false ); - - viewer->Raise(); - - // Raising the window does not set the focus on Linux. This should work on - // any platform. - if( wxWindow::FindFocus() != viewer ) - viewer->SetFocus(); - } + viewer = new FOOTPRINT_VIEWER_FRAME( this, m_footprintLibTable, NULL ); + viewer->Show( true ); + viewer->Zoom_Automatique( false ); } - break; + else + { + if( viewer->IsIconized() ) + viewer->Iconize( false ); + + viewer->Raise(); + + // Raising the window does not set the focus on Linux. This should work on + // any platform. + if( wxWindow::FindFocus() != viewer ) + viewer->SetFocus(); + } + } + break; case ID_MODEDIT_DELETE_PART: DeleteModuleFromCurrentLibrary(); break; case ID_MODEDIT_NEW_MODULE: + { + Clear_Pcb( true ); + GetScreen()->ClearUndoRedoList(); + SetCurItem( NULL ); + GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); + + MODULE* module = Create_1_Module( wxEmptyString ); + + if( module ) // i.e. if create module command not aborted { - Clear_Pcb( true ); - GetScreen()->ClearUndoRedoList(); - SetCurItem( NULL ); - GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); + // Initialize data relative to nets and netclasses (for a new + // module the defaults are used) + // This is mandatory to handle and draw pads + GetBoard()->BuildListOfNets(); + redraw = true; + module->SetPosition( wxPoint( 0, 0 ) ); - MODULE* module = Create_1_Module( wxEmptyString ); + if( GetBoard()->m_Modules ) + GetBoard()->m_Modules->ClearFlags(); - if( module ) // i.e. if create module command not aborted - { - // Initialize data relative to nets and netclasses (for a new - // module the defaults are used) - // This is mandatory to handle and draw pads - GetBoard()->BuildListOfNets(); - redraw = true; - module->SetPosition( wxPoint( 0, 0 ) ); - - if( GetBoard()->m_Modules ) - GetBoard()->m_Modules->ClearFlags(); - - Zoom_Automatique( false ); - } + Zoom_Automatique( false ); } - break; + } + break; case ID_MODEDIT_NEW_MODULE_FROM_WIZARD: + { + Clear_Pcb( true ); + GetScreen()->ClearUndoRedoList(); + SetCurItem( NULL ); + GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); + + wxSemaphore semaphore( 0, 1 ); + FOOTPRINT_WIZARD_FRAME *wizard = new FOOTPRINT_WIZARD_FRAME( this, &semaphore, + KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT ); + wizard->Show( true ); + wizard->Zoom_Automatique( false ); + + while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event { - Clear_Pcb( true ); - GetScreen()->ClearUndoRedoList(); - SetCurItem( NULL ); - GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); - - wxSemaphore semaphore( 0, 1 ); - FOOTPRINT_WIZARD_FRAME *wizard = new FOOTPRINT_WIZARD_FRAME( this, &semaphore, - KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT ); - wizard->Show( true ); - wizard->Zoom_Automatique( false ); - - while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event - { - wxYield(); - wxMilliSleep( 50 ); - } - - MODULE* module = wizard->GetBuiltFootprint(); - - if( module ) // i.e. if create module command not aborted - { - /* Here we should make a copy of the object before adding to board*/ - module->SetParent( (EDA_ITEM*)GetBoard() ); - GetBoard()->m_Modules.Append( module ); - - // Initialize data relative to nets and netclasses (for a new - // module the defaults are used) - // This is mandatory to handle and draw pads - GetBoard()->BuildListOfNets(); - redraw = true; - module->SetPosition( wxPoint( 0, 0 ) ); - - if( GetBoard()->m_Modules ) - GetBoard()->m_Modules->ClearFlags(); - - - } - - wizard->Destroy(); + wxYield(); + wxMilliSleep( 50 ); } + + MODULE* module = wizard->GetBuiltFootprint(); + + if( module ) // i.e. if create module command not aborted + { + /* Here we should make a copy of the object before adding to board*/ + module->SetParent( (EDA_ITEM*)GetBoard() ); + GetBoard()->m_Modules.Append( module ); + + // Initialize data relative to nets and netclasses (for a new + // module the defaults are used) + // This is mandatory to handle and draw pads + GetBoard()->BuildListOfNets(); + redraw = true; + module->SetPosition( wxPoint( 0, 0 ) ); + + if( GetBoard()->m_Modules ) + GetBoard()->m_Modules->ClearFlags(); + } + + wizard->Destroy(); + } break; case ID_MODEDIT_SAVE_LIBMODULE: @@ -340,84 +361,84 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_MODEDIT_INSERT_MODULE_IN_BOARD: case ID_MODEDIT_UPDATE_MODULE_IN_BOARD: + { + // update module in the current board, + // not just add it to the board with total disregard for the netlist... + PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) GetParent(); + BOARD* mainpcb = pcbframe->GetBoard(); + MODULE* source_module = NULL; + MODULE* module_in_edit = GetBoard()->m_Modules; + + // Search the old module (source) if exists + // Because this source could be deleted when editing the main board... + if( module_in_edit->GetLink() ) // this is not a new module ... { - // update module in the current board, - // not just add it to the board with total disregard for the netlist... - PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) GetParent(); - BOARD* mainpcb = pcbframe->GetBoard(); - MODULE* source_module = NULL; - MODULE* module_in_edit = GetBoard()->m_Modules; + source_module = mainpcb->m_Modules; - // Search the old module (source) if exists - // Because this source could be deleted when editing the main board... - if( module_in_edit->GetLink() ) // this is not a new module ... + for( ; source_module != NULL; source_module = (MODULE*) source_module->Next() ) { - source_module = mainpcb->m_Modules; - - for( ; source_module != NULL; source_module = (MODULE*) source_module->Next() ) - { - if( module_in_edit->GetLink() == source_module->GetTimeStamp() ) - break; - } + if( module_in_edit->GetLink() == source_module->GetTimeStamp() ) + break; } - - if( ( source_module == NULL ) - && ( id == ID_MODEDIT_UPDATE_MODULE_IN_BOARD ) ) // source not found - { - wxString msg; - msg.Printf( _( "Unable to find the footprint source on the main board" ) ); - msg << _( "\nCannot update the footprint" ); - DisplayError( this, msg ); - break; - } - - if( ( source_module != NULL ) - && ( id == ID_MODEDIT_INSERT_MODULE_IN_BOARD ) ) // source not found - { - wxString msg; - msg.Printf( _( "A footprint source was found on the main board" ) ); - msg << _( "\nCannot insert this footprint" ); - DisplayError( this, msg ); - break; - } - - // Create the "new" module - MODULE* newmodule = new MODULE( *module_in_edit ); - newmodule->SetParent( mainpcb ); - newmodule->SetLink( 0 ); - - // Put the footprint in the main pcb linked list. - mainpcb->Add( newmodule ); - - if( source_module ) // this is an update command - { - // In the main board, - // the new module replace the old module (pos, orient, ref, value - // and connexions are kept) - // and the source_module (old module) is deleted - PICKED_ITEMS_LIST pickList; - pcbframe->Exchange_Module( source_module, newmodule, &pickList ); - newmodule->SetTimeStamp( module_in_edit->GetLink() ); - - if( pickList.GetCount() ) - pcbframe->SaveCopyInUndoList( pickList, UR_UNSPECIFIED ); - } - else // This is an insert command - { - wxPoint cursor_pos = pcbframe->GetScreen()->GetCrossHairPosition(); - pcbframe->GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); - pcbframe->PlaceModule( newmodule, NULL ); - pcbframe->GetScreen()->SetCrossHairPosition( cursor_pos ); - newmodule->SetTimeStamp( GetNewTimeStamp() ); - pcbframe->SaveCopyInUndoList( newmodule, UR_NEW ); - } - - newmodule->ClearFlags(); - GetScreen()->ClrModify(); - pcbframe->SetCurItem( NULL ); - mainpcb->m_Status_Pcb = 0; } - break; + + if( ( source_module == NULL ) + && ( id == ID_MODEDIT_UPDATE_MODULE_IN_BOARD ) ) // source not found + { + wxString msg; + msg.Printf( _( "Unable to find the footprint source on the main board" ) ); + msg << _( "\nCannot update the footprint" ); + DisplayError( this, msg ); + break; + } + + if( ( source_module != NULL ) + && ( id == ID_MODEDIT_INSERT_MODULE_IN_BOARD ) ) // source not found + { + wxString msg; + msg.Printf( _( "A footprint source was found on the main board" ) ); + msg << _( "\nCannot insert this footprint" ); + DisplayError( this, msg ); + break; + } + + // Create the "new" module + MODULE* newmodule = new MODULE( *module_in_edit ); + newmodule->SetParent( mainpcb ); + newmodule->SetLink( 0 ); + + // Put the footprint in the main pcb linked list. + mainpcb->Add( newmodule ); + + if( source_module ) // this is an update command + { + // In the main board, + // the new module replace the old module (pos, orient, ref, value + // and connexions are kept) + // and the source_module (old module) is deleted + PICKED_ITEMS_LIST pickList; + pcbframe->Exchange_Module( source_module, newmodule, &pickList ); + newmodule->SetTimeStamp( module_in_edit->GetLink() ); + + if( pickList.GetCount() ) + pcbframe->SaveCopyInUndoList( pickList, UR_UNSPECIFIED ); + } + else // This is an insert command + { + wxPoint cursor_pos = pcbframe->GetScreen()->GetCrossHairPosition(); + pcbframe->GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); + pcbframe->PlaceModule( newmodule, NULL ); + pcbframe->GetScreen()->SetCrossHairPosition( cursor_pos ); + newmodule->SetTimeStamp( GetNewTimeStamp() ); + pcbframe->SaveCopyInUndoList( newmodule, UR_NEW ); + } + + newmodule->ClearFlags(); + GetScreen()->ClrModify(); + pcbframe->SetCurItem( NULL ); + mainpcb->m_Status_Pcb = 0; + } + break; case ID_MODEDIT_IMPORT_PART: if( ! Clear_Pcb( true ) ) @@ -459,22 +480,22 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_MODEDIT_LOAD_MODULE: - { - PCB_EDIT_FRAME* parent = (PCB_EDIT_FRAME*) GetParent(); - wxString libPath = getLibPath(); // might be empty + wxLogDebug( wxT( "Loading module from library " ) + getLibPath() ); - wxLogDebug( wxT( "Loading module from library " ) + libPath ); + GetScreen()->ClearUndoRedoList(); + SetCurItem( NULL ); + Clear_Pcb( true ); + GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); - GetScreen()->ClearUndoRedoList(); - SetCurItem( NULL ); - Clear_Pcb( true ); - GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); - LoadModuleFromLibrary( libPath, parent->GetFootprintLibraryTable(), true ); - redraw = true; - } +#if !defined( USE_FP_LIB_TABLE ) + LoadModuleFromLibrary( getLibPath(), m_footprintLibTable, true ); +#else + LoadModuleFromLibrary( getLibNickName(), m_footprintLibTable, true ); +#endif + redraw = true; if( GetBoard()->m_Modules ) - GetBoard()->m_Modules->ClearFlags(); + GetBoard()->m_Modules->ClearFlags(); // if either m_Reference or m_Value are gone, reinstall them - // otherwise you cannot see what you are doing on board @@ -881,6 +902,7 @@ void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent ) } } + EDA_COLOR_T FOOTPRINT_EDIT_FRAME::GetGridColor() const { return g_ColorsSettings.GetItemColor( GRID_VISIBLE ); diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index cfeb996627..e8c4fc0493 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -1,3 +1,26 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + /** * @file module_editor_frame.h * @brief Definition of class FOOTPRINT_EDIT_FRAME. @@ -9,10 +32,14 @@ #include #include + +class FP_LIB_TABLE; + + class FOOTPRINT_EDIT_FRAME : public PCB_BASE_FRAME { public: - FOOTPRINT_EDIT_FRAME( PCB_EDIT_FRAME* aParent ); + FOOTPRINT_EDIT_FRAME( PCB_EDIT_FRAME* aParent, FP_LIB_TABLE* aTable ); ~FOOTPRINT_EDIT_FRAME(); @@ -87,7 +114,7 @@ public: * Function OnSaveLibraryAs * saves the current library to a new name and/or library type. * - * @note Saving as a new library type requires the plug-in to support saving libraris. + * @note Saving as a new library type requires the plug-in to support saving libraries * @see PLUGIN::FootprintSave and PLUGIN::FootprintLibCreate */ void OnSaveLibraryAs( wxCommandEvent& aEvent ); @@ -360,7 +387,7 @@ public: /** * Function DlgGlobalChange_PadSettings - * changes pad caracteristics for the given footprint + * changes pad characteristics for the given footprint * or all footprints which look like the given footprint. * Options are set by the opened dialog. * @param aPad is the pattern. The given footprint is the parent of this pad @@ -380,7 +407,7 @@ public: DECLARE_EVENT_TABLE() protected: - static BOARD* s_Pcb; ///< retain board accross invocations of module editor + static BOARD* s_Pcb; ///< retain board across invocations of module editor /** * Function GetComponentFromUndoList diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index f7b1d60fdd..44d5d122fa 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -156,7 +156,7 @@ END_EVENT_TABLE() #define FOOTPRINT_EDIT_FRAME_NAME wxT( "ModEditFrame" ) -FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( PCB_EDIT_FRAME* aParent ) : +FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( PCB_EDIT_FRAME* aParent, FP_LIB_TABLE* aTable ) : PCB_BASE_FRAME( aParent, MODULE_EDITOR_FRAME_TYPE, wxEmptyString, wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() ) @@ -166,6 +166,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( PCB_EDIT_FRAME* aParent ) : m_showAxis = true; // true to show X and Y axis on screen m_showGridAxis = true; // show the grid origin axis m_HotkeysZoomAndGridList = g_Module_Editor_Hokeys_Descr; + m_footprintLibTable = aTable; // Give an icon wxIcon icon; @@ -258,20 +259,22 @@ FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME() m_Pcb = 0; } + const wxChar* FOOTPRINT_EDIT_FRAME::GetFootprintEditorFrameName() { return FOOTPRINT_EDIT_FRAME_NAME; } + /* return a reference to the current opened Footprint editor * or NULL if no Footprint editor currently opened */ FOOTPRINT_EDIT_FRAME* FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor() { - return (FOOTPRINT_EDIT_FRAME*) - wxWindow::FindWindowByName(GetFootprintEditorFrameName()); + return (FOOTPRINT_EDIT_FRAME*) wxWindow::FindWindowByName( GetFootprintEditorFrameName() ); } + BOARD_DESIGN_SETTINGS& FOOTPRINT_EDIT_FRAME::GetDesignSettings() const { // get the BOARD_DESIGN_SETTINGS from the parent editor, not our BOARD. @@ -337,7 +340,7 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) // at case ID_MODEDIT_SAVE_LIBMODULE if( GetBoard()->m_Modules && getLibPath() != wxEmptyString ) { - if( Save_Module_In_Library( getLibPath(), GetBoard()->m_Modules, true, true )) + if( Save_Module_In_Library( getLibPath(), GetBoard()->m_Modules, true, true ) ) { // save was correct GetScreen()->ClrModify(); @@ -489,6 +492,7 @@ void FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, // for next cursor position // ( shift or ctrl key down are PAN command with mouse wheel) bool snapToGrid = true; + if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) ) snapToGrid = false; @@ -612,4 +616,3 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() SetTitle( title ); } - diff --git a/pcbnew/modview.cpp b/pcbnew/modview.cpp index a923535d3c..2fb378ef84 100644 --- a/pcbnew/modview.cpp +++ b/pcbnew/modview.cpp @@ -205,7 +205,11 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) SetCurItem( NULL ); // Delete the current footprint GetBoard()->m_Modules.DeleteAll(); - GetModuleLibrary( GetSelectedLibraryFullName(), m_footprintName, true ); + MODULE* footprint = GetModuleLibrary( GetSelectedLibraryFullName(), m_footprintName, true ); + + if( footprint ) + GetBoard()->Add( footprint, ADD_APPEND ); + Update3D_Frame(); } diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index d95939ce74..a051ea942d 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -204,8 +204,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, if( !m_libraryName.IsEmpty() && !m_footprintName.IsEmpty() ) { #if !defined( USE_FP_LIB_TABLE ) - GetModuleLibrary( m_libraryName + wxT(".") + LegacyFootprintLibPathExtension, - m_footprintName, false ); + MODULE* footprint = GetModuleLibrary( m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension, + m_footprintName, false ); + + if( footprint ) + GetBoard()->Add( footprint, ADD_APPEND ); #else FPID id; id.SetLibNickname( TO_UTF8( m_libraryName ) ); @@ -496,8 +499,11 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) // Delete the current footprint GetBoard()->m_Modules.DeleteAll(); #if !defined( USE_FP_LIB_TABLE ) - GetModuleLibrary( m_libraryName + wxT(".") + LegacyFootprintLibPathExtension, - m_footprintName, true ); + MODULE* footprint = GetModuleLibrary( m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension, + m_footprintName, true ); + + if( footprint ) + GetBoard()->Add( footprint, ADD_APPEND ); #else FPID id; id.SetLibNickname( TO_UTF8( m_libraryName ) ); diff --git a/pcbnew/netlist.cpp b/pcbnew/netlist.cpp index 4e63907abd..bf9d60567d 100644 --- a/pcbnew/netlist.cpp +++ b/pcbnew/netlist.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -157,6 +159,8 @@ MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName() } +#if !defined( USE_FP_LIB_TABLE ) + void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) throw( IO_ERROR, PARSE_ERROR ) { @@ -252,3 +256,92 @@ void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) component->SetModule( module ); } } + +#else + +void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) + throw( IO_ERROR, PARSE_ERROR ) +{ + bool loadFootprint; + wxString msg; + wxString lastFootprintLibName; + COMPONENT* component; + MODULE* module = 0; + MODULE* fpOnBoard; + + if( aNetlist.IsEmpty() || m_footprintLibTable->IsEmpty() ) + return; + + aNetlist.SortByFootprintName(); + + for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ ) + { + component = aNetlist.GetComponent( ii ); + + // Check if component footprint is already on BOARD and only load the footprint from + // the library if it's needed. + if( aNetlist.IsFindByTimeStamp() ) + fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetTimeStamp(), true ); + else + fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetReference() ); + + loadFootprint = (fpOnBoard == NULL) || + (fpOnBoard->GetPath() != component->GetFootprintName()); + + if( loadFootprint && (component->GetFootprintName() != lastFootprintLibName) ) + { + module = NULL; + + FPID fpid; + + if( fpid.Parse( TO_UTF8( component->GetFootprintName() ) ) >= 0 ) + { + if( aReporter ) + { + msg.Printf( _( "*** Warning: Component \"%s\" footprint ID <%s> is not " + "valid. ***\n" ), + GetChars( component->GetReference() ), + GetChars( component->GetFootprintName() ) ); + aReporter->Report( msg ); + } + + continue; + } + + module = PCB_BASE_FRAME::loadFootprint( fpid ); + + if( module ) + { + lastFootprintLibName = component->GetFootprintName(); + } + + if( module == NULL ) + { + if( aReporter ) + { + wxString msg; + msg.Printf( _( "*** Warning: component `%s` footprint <%s> was not found in " + "any libraries in the footprint library table. ***\n" ), + GetChars( component->GetReference() ), + GetChars( component->GetFootprintName() ) ); + aReporter->Report( msg ); + } + + continue; + } + } + else + { + // Footprint already loaded from a library, duplicate it (faster) + if( module == NULL ) + continue; // Module does not exist in any library. + + module = new MODULE( *module ); + } + + if( loadFootprint && module != NULL ) + component->SetModule( module ); + } +} + +#endif diff --git a/pcbnew/netlist_reader.cpp b/pcbnew/netlist_reader.cpp index ee41b3187c..a62b086382 100644 --- a/pcbnew/netlist_reader.cpp +++ b/pcbnew/netlist_reader.cpp @@ -1,5 +1,5 @@ /** - * @file pcbnew/netlist_reader_common.cpp + * @file netlist_reader.cpp */ /* * This program source code file is part of KiCad, a free EDA CAD application. diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h index 822822760b..90ffdbd745 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h @@ -24,7 +24,7 @@ */ /** - * @file PCBPolygon.h + * @file pcb_polygon.h */ #ifndef PCB_POLYGON_H_ diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index a744fe4038..0c8e065a21 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -442,6 +442,23 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, syncLayerWidgetLayer(); m_auimgr.Update(); + + if( m_globalFootprintTable == NULL ) + { + try + { + m_globalFootprintTable = new FP_LIB_TABLE(); + FP_LIB_TABLE::LoadGlobalTable( *m_globalFootprintTable ); + } + catch( IO_ERROR ioe ) + { + wxString msg; + msg.Printf( _( "An error occurred attempting to load the global footprint library " + "table:\n\n%s" ), GetChars( ioe.errorText ) ); + DisplayError( this, msg ); + } + } + } diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index d96272b27e..94a9d9f89b 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -538,22 +538,6 @@ void PCB_EDIT_FRAME::ReadMacros() void PCB_EDIT_FRAME::loadFootprintLibTable() { - if( m_globalFootprintTable == NULL ) - { - try - { - m_globalFootprintTable = new FP_LIB_TABLE(); - FP_LIB_TABLE::LoadGlobalTable( *m_globalFootprintTable ); - } - catch( IO_ERROR ioe ) - { - wxString msg; - msg.Printf( _( "An error occurred attempting to load the global footprint library " - "table:\n\n%s" ), GetChars( ioe.errorText ) ); - DisplayError( this, msg ); - } - } - delete m_footprintLibTable; wxFileName fn = GetBoard()->GetFileName(); diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 40393e5e5c..96b027c217 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -258,6 +258,7 @@ static POINT mapPt( const wxPoint& pt ) * if found, removes it from the TYPE_COLLECTOR and returns it, else returns NULL. * @param aPoint The starting or ending point to search for. * @param items The list to remove from. + * @param aLimit is the distance from \a aPoint that still constitutes a valid find. * @return DRAWSEGMENT* - The first DRAWSEGMENT that has a start or end point matching * aPoint, otherwise NULL if none. */ diff --git a/pcbnew/xchgmod.cpp b/pcbnew/xchgmod.cpp index 15804bc945..32ee549465 100644 --- a/pcbnew/xchgmod.cpp +++ b/pcbnew/xchgmod.cpp @@ -476,6 +476,8 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module, return false; } + m_Parent->GetBoard()->Add( NewModule, ADD_APPEND ); + if( Module == m_CurrentModule ) m_CurrentModule = NewModule; @@ -489,16 +491,6 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module, } -/** - * Function Exchange_Module - * Replaces OldModule by NewModule, using OldModule settings: - * position, orientation, pad netnames ...) - * OldModule is deleted or put in undo list. - * @param aOldModule = footprint to replace - * @param aNewModule = footprint to put - * @param aUndoPickList = the undo list used to save OldModule. If null, - * OldModule is deleted - */ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule, MODULE* aNewModule, PICKED_ITEMS_LIST* aUndoPickList ) @@ -597,12 +589,6 @@ void DIALOG_EXCHANGE_MODULE::BrowseAndSelectFootprint( wxCommandEvent& event ) } -/** - * Function RecreateBOMFileFromBoard - * Recreates a .cmp file from the current loaded board - * this is the same as created by CvPcb. - * can be used if this file is lost - */ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent ) { wxFileName fn;