Commit 5560cb54 authored by Wayne Stambaugh's avatar Wayne Stambaugh

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.
parent 4e94d8e7
......@@ -38,6 +38,7 @@
#include <wildcards_and_files_ext.h>
#include <footprint_info.h>
#include <io_mgr.h>
#include <fp_lib_table.h>
#include <class_module.h>
......@@ -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<fpnames.GetCount(); ++i )
{
std::auto_ptr<MODULE> 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;
}
......@@ -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();
......
/**
* @file title_block_shape.cpp
* @file title_block_shapes.cpp
* @brief description of graphic items and texts to build a title block
*/
......
/**
* @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
*/
......
......@@ -34,6 +34,10 @@
#include <kicad_string.h>
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.
......
......@@ -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
......
......@@ -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.
......
......@@ -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
......
......@@ -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
......
/************************************************/
/* 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 <fctsys.h>
#include <confirm.h>
......@@ -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 );
}
}
......
/**
* @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.
......
/**
* @file pcbnew/netlist_reader_firstformat.cpp
* @file pcbnew/legacy_netlist_reader.cpp
*/
/*
......
......@@ -36,10 +36,10 @@
#include <gestfich.h>
#include <wxPcbStruct.h>
#include <dialog_helpers.h>
#include <richio.h>
#include <filter_reader.h>
#include <pcbcommon.h>
#include <macros.h>
#include <fp_lib_table.h>
#include <class_board.h>
#include <class_module.h>
......@@ -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<wxArrayString> 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
......@@ -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,39 +465,54 @@ 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
{
libraries.Add( aLibraryFullFilename );
}
if( libraries.IsEmpty() )
{
DisplayError( aWindow, _( "No footprint libraries were specified." ) );
return wxEmptyString;
}
MList.ReadFootprintFiles( libraries );
#else
wxASSERT( aTable != NULL );
wxASSERT( aTable != NULL );
if( aLibraryFullFilename.IsEmpty() )
{
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 );
FP_LIB_TABLE::ROW row = *aTable->FindRow( libNames[i] );
libTable.InsertRow( row );
}
#endif
}
else
{
libraries.Add( aLibraryFullFilename );
FP_LIB_TABLE::ROW row = *aTable->FindRow( aLibraryFullFilename );
libTable.InsertRow( row );
}
if( libraries.IsEmpty() )
if( libTable.IsEmpty() )
{
DisplayError( aWindow, _( "No footprint libraries were specified." ) );
return wxEmptyString;
}
// Find modules in libraries.
MList.ReadFootprintFiles( libraries );
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();
......
This diff is collapsed.
/*
* 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 <wxBasePcbFrame.h>
#include <io_mgr.h>
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
......
......@@ -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 );
}
......@@ -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();
}
......
......@@ -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 ) );
......
......@@ -34,6 +34,8 @@
#include <netlist_reader.h>
#include <reporter.h>
#include <wildcards_and_files_ext.h>
#include <fpid.h>
#include <fp_lib_table.h>
#include <class_board.h>
#include <class_module.h>
......@@ -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
/**
* @file pcbnew/netlist_reader_common.cpp
* @file netlist_reader.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
......
......@@ -24,7 +24,7 @@
*/
/**
* @file PCBPolygon.h
* @file pcb_polygon.h
*/
#ifndef PCB_POLYGON_H_
......
......@@ -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 );
}
}
}
......
......@@ -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();
......
......@@ -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.
*/
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment