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 @@ ...@@ -38,6 +38,7 @@
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <footprint_info.h> #include <footprint_info.h>
#include <io_mgr.h> #include <io_mgr.h>
#include <fp_lib_table.h>
#include <class_module.h> #include <class_module.h>
...@@ -124,3 +125,58 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames ) ...@@ -124,3 +125,58 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames )
return true; 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 ) ...@@ -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 ) void FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR )
{ {
wxFileName fn = GetGlobalTableFileName(); 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 * @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 * @brief description of graphic items and texts to build a title block
* using GOST standard * using GOST standard
*/ */
......
...@@ -34,6 +34,10 @@ ...@@ -34,6 +34,10 @@
#include <kicad_string.h> #include <kicad_string.h>
class FP_LIB_TABLE;
/* /*
* Class FOOTPRINT_INFO * Class FOOTPRINT_INFO
* is a helper class to handle the list of footprints available in libraries. It stores * is a helper class to handle the list of footprints available in libraries. It stores
...@@ -136,7 +140,9 @@ public: ...@@ -136,7 +140,9 @@ public:
* *
* @param aFootprintsLibNames = an array string giving the list of libraries to load * @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. /// FOOTPRINT object list sort function.
......
...@@ -359,7 +359,7 @@ public: ...@@ -359,7 +359,7 @@ public:
* Function IsEmpty * Function IsEmpty
* @return true if the footprint library table is empty. * @return true if the footprint library table is empty.
*/ */
bool IsEmpty() const { return rows.empty(); } bool IsEmpty() const;
/** /**
* Function ExpandEnvSubsitutions * Function ExpandEnvSubsitutions
......
...@@ -256,6 +256,7 @@ public: ...@@ -256,6 +256,7 @@ public:
* *
* @param aPaperFormat The paper size type, for basic inscriptions. * @param aPaperFormat The paper size type, for basic inscriptions.
* @param aFileName The file name, 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 aTitleBlock The sheet title block, for basic inscriptions.
* @param aLineColor The color for drawing and fixed text. * @param aLineColor The color for drawing and fixed text.
* @param aTextColor The color for user inscriptions. * @param aTextColor The color for user inscriptions.
......
...@@ -402,12 +402,11 @@ public: ...@@ -402,12 +402,11 @@ public:
* if it is a short name, the file is searched in all library valid paths * if it is a short name, the file is searched in all library valid paths
* @param aFootprintName is the footprint to load * @param aFootprintName is the footprint to load
* @param aDisplayError = true to display an error message if any. * @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 * @return MODULE* - new module, or NULL
*/ */
MODULE* loadFootprintFromLibrary( const wxString& aLibraryPath, const wxString& aFootprintName, MODULE* loadFootprintFromLibrary( const wxString& aLibraryPath, const wxString& aFootprintName,
bool aDisplayError, bool aAddToBoard = true ); bool aDisplayError );
/** /**
* Function loadFootprintFromLibraries * Function loadFootprintFromLibraries
......
...@@ -193,7 +193,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -193,7 +193,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor(); FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor();
if( editorFrame == NULL ) if( editorFrame == NULL )
{ {
editorFrame = new FOOTPRINT_EDIT_FRAME( this ); editorFrame = new FOOTPRINT_EDIT_FRAME( this, m_footprintLibTable );
editorFrame->Show( true ); editorFrame->Show( true );
editorFrame->Zoom_Automatique( false ); editorFrame->Zoom_Automatique( false );
} }
...@@ -809,10 +809,11 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -809,10 +809,11 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
OnModify(); OnModify();
} }
{ {
FOOTPRINT_EDIT_FRAME * editorFrame = FOOTPRINT_EDIT_FRAME * editorFrame = FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor();
FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor();
if( editorFrame == NULL ) if( editorFrame == NULL )
editorFrame = new FOOTPRINT_EDIT_FRAME( this ); editorFrame = new FOOTPRINT_EDIT_FRAME( this, m_footprintLibTable );
editorFrame->Load_Module_From_BOARD( (MODULE*)GetCurItem() ); editorFrame->Load_Module_From_BOARD( (MODULE*)GetCurItem() );
SetCurItem( NULL ); // the current module could be deleted by SetCurItem( NULL ); // the current module could be deleted by
......
/************************************************/ /*
/* Module editor: Dialog box for editing module */ * This program source code file is part of KiCad, a free EDA CAD application.
/* properties and characteristics */ *
/************************************************/ * 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 <fctsys.h>
#include <confirm.h> #include <confirm.h>
...@@ -50,10 +73,10 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC ) ...@@ -50,10 +73,10 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC )
if( retvalue == 2 ) if( retvalue == 2 )
{ {
FOOTPRINT_EDIT_FRAME * editorFrame = FOOTPRINT_EDIT_FRAME* editorFrame = FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor();
FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor();
if( editorFrame == NULL ) if( editorFrame == NULL )
editorFrame = new FOOTPRINT_EDIT_FRAME( this ); editorFrame = new FOOTPRINT_EDIT_FRAME( this, m_footprintLibTable );
editorFrame->Load_Module_From_BOARD( Module ); editorFrame->Load_Module_From_BOARD( Module );
SetCurItem( NULL ); SetCurItem( NULL );
...@@ -89,7 +112,7 @@ void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item ) ...@@ -89,7 +112,7 @@ void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item )
DisplayError( this, _( "Cannot delete VALUE!" ) ); DisplayError( this, _( "Cannot delete VALUE!" ) );
break; break;
default: default:
DeleteTextModule( text ); 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. * 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 @@ ...@@ -36,10 +36,10 @@
#include <gestfich.h> #include <gestfich.h>
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <dialog_helpers.h> #include <dialog_helpers.h>
#include <richio.h>
#include <filter_reader.h> #include <filter_reader.h>
#include <pcbcommon.h> #include <pcbcommon.h>
#include <macros.h> #include <macros.h>
#include <fp_lib_table.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
...@@ -93,7 +93,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module() ...@@ -93,7 +93,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
{ {
// use the clipboard for this in the future? // 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; static int lastFilterIndex = 0;
wxString lastOpenedPathForLoading; wxString lastOpenedPathForLoading;
wxConfig* config = wxGetApp().GetSettings(); wxConfig* config = wxGetApp().GetSettings();
...@@ -298,7 +298,7 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule ) ...@@ -298,7 +298,7 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule )
} }
wxFileDialog dlg( this, FMT_EXPORT_MODULE, fn.GetPath(), fn.GetFullName(), 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 ) if( dlg.ShowModal() == wxID_CANCEL )
return; return;
...@@ -655,7 +655,7 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibPath, ...@@ -655,7 +655,7 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibPath,
if( aDisplayDialog ) if( aDisplayDialog )
{ {
wxString msg = wxString::Format( FMT_MOD_EXISTS, wxString msg = wxString::Format( FMT_MOD_EXISTS,
footprintName.GetData(), aLibPath.GetData() ); footprintName.GetData(), aLibPath.GetData() );
SetStatusText( msg ); SetStatusText( msg );
} }
...@@ -748,16 +748,18 @@ MODULE* PCB_BASE_FRAME::Create_1_Module( const wxString& aModuleName ) ...@@ -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() void FOOTPRINT_EDIT_FRAME::Select_Active_Library()
{ {
if( g_LibraryNames.GetCount() == 0 ) if( g_LibraryNames.GetCount() == 0 )
return; return;
wxArrayString headers; wxArrayString headers;
headers.Add( wxT("Library") ); headers.Add( _( "Library" ) );
std::vector<wxArrayString> itemsToDisplay; std::vector<wxArrayString> itemsToDisplay;
// Conversion from wxArrayString to vector of ArrayString // Conversion from wxArrayString to vector of ArrayString
for( unsigned i = 0; i < g_LibraryNames.GetCount(); i++ ) for( unsigned i = 0; i < g_LibraryNames.GetCount(); i++ )
{ {
...@@ -765,6 +767,7 @@ void FOOTPRINT_EDIT_FRAME::Select_Active_Library() ...@@ -765,6 +767,7 @@ void FOOTPRINT_EDIT_FRAME::Select_Active_Library()
item.Add( g_LibraryNames[i] ); item.Add( g_LibraryNames[i] );
itemsToDisplay.push_back( item ); itemsToDisplay.push_back( item );
} }
EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, getLibNickName() ); EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, getLibNickName() );
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
...@@ -793,3 +796,50 @@ void FOOTPRINT_EDIT_FRAME::Select_Active_Library() ...@@ -793,3 +796,50 @@ void FOOTPRINT_EDIT_FRAME::Select_Active_Library()
updateTitle(); 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, ...@@ -180,7 +180,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
moduleName = full_fpname.AfterLast( '/' ); moduleName = full_fpname.AfterLast( '/' );
libName = full_fpname.BeforeLast( '/' ); libName = full_fpname.BeforeLast( '/' );
#else #else
libName = SelectFootprintFromLibBrowser(); moduleName = SelectFootprintFromLibBrowser();
#endif #endif
} }
else else
...@@ -219,7 +219,25 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, ...@@ -219,7 +219,25 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
} }
} }
#if !defined( USE_FP_LIB_TABLE )
module = GetModuleLibrary( libName, moduleName, false ); 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 if( !module && allowWildSeach ) // Search with wild card
{ {
...@@ -237,7 +255,25 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, ...@@ -237,7 +255,25 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
} }
else else
{ {
#if !defined( USE_FP_LIB_TABLE )
module = GetModuleLibrary( libName, moduleName, true ); 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, ...@@ -246,6 +282,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
if( module ) if( module )
{ {
GetBoard()->Add( module, ADD_APPEND );
lastComponentName = moduleName; lastComponentName = moduleName;
AddHistoryComponentName( HistoryList, moduleName ); AddHistoryComponentName( HistoryList, moduleName );
...@@ -289,8 +326,7 @@ MODULE* PCB_BASE_FRAME::GetModuleLibrary( const wxString& aLibraryPath, ...@@ -289,8 +326,7 @@ MODULE* PCB_BASE_FRAME::GetModuleLibrary( const wxString& aLibraryPath,
MODULE* PCB_BASE_FRAME::loadFootprintFromLibrary( const wxString& aLibraryPath, MODULE* PCB_BASE_FRAME::loadFootprintFromLibrary( const wxString& aLibraryPath,
const wxString& aFootprintName, const wxString& aFootprintName,
bool aDisplayError, bool aDisplayError )
bool aAddToBoard )
{ {
try try
{ {
...@@ -315,9 +351,6 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibrary( const wxString& aLibraryPath, ...@@ -315,9 +351,6 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibrary( const wxString& aLibraryPath,
return NULL; return NULL;
} }
if( aAddToBoard )
GetBoard()->Add( footprint, ADD_APPEND );
SetStatusText( wxEmptyString ); SetStatusText( wxEmptyString );
return footprint; return footprint;
} }
...@@ -357,6 +390,7 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries( ...@@ -357,6 +390,7 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries(
DisplayError( this, msg ); DisplayError( this, msg );
showed_error = true; showed_error = true;
} }
continue; continue;
} }
...@@ -364,7 +398,6 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries( ...@@ -364,7 +398,6 @@ MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries(
if( footprint ) if( footprint )
{ {
GetBoard()->Add( footprint, ADD_APPEND );
SetStatusText( wxEmptyString ); SetStatusText( wxEmptyString );
return footprint; return footprint;
} }
...@@ -432,39 +465,54 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, ...@@ -432,39 +465,54 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
wxString CmpName; wxString CmpName;
wxString msg; wxString msg;
wxArrayString libraries; wxArrayString libraries;
FP_LIB_TABLE libTable;
std::vector< wxArrayString > rows; std::vector< wxArrayString > rows;
#if !defined( USE_FP_LIB_TABLE )
if( aLibraryFullFilename.IsEmpty() ) if( aLibraryFullFilename.IsEmpty() )
{ {
#if !defined( USE_FP_LIB_TABLE )
libraries = g_LibraryNames; libraries = g_LibraryNames;
}
else
{
libraries.Add( aLibraryFullFilename );
}
if( libraries.IsEmpty() )
{
DisplayError( aWindow, _( "No footprint libraries were specified." ) );
return wxEmptyString;
}
MList.ReadFootprintFiles( libraries );
#else #else
wxASSERT( aTable != NULL ); wxASSERT( aTable != NULL );
if( aLibraryFullFilename.IsEmpty() )
{
std::vector< wxString > libNames = aTable->GetLogicalLibs(); std::vector< wxString > libNames = aTable->GetLogicalLibs();
for( unsigned i = 0; i < libNames.size(); i++ ) for( unsigned i = 0; i < libNames.size(); i++ )
{ {
wxString uri = aTable->FindRow( libNames[i] )->GetFullURI(); FP_LIB_TABLE::ROW row = *aTable->FindRow( libNames[i] );
uri = FP_LIB_TABLE::ExpandSubstitutions( uri ); libTable.InsertRow( row );
libraries.Add( uri );
} }
#endif
} }
else 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." ) ); DisplayError( aWindow, _( "No footprint libraries were specified." ) );
return wxEmptyString; return wxEmptyString;
} }
// Find modules in libraries. MList.ReadFootprintFiles( libTable );
MList.ReadFootprintFiles( libraries ); #endif
if( MList.GetCount() == 0 ) if( MList.GetCount() == 0 )
{ {
...@@ -536,7 +584,7 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, ...@@ -536,7 +584,7 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
CmpName = dlg.GetTextSelection(); CmpName = dlg.GetTextSelection();
#if defined( USE_FP_LIB_TABLE ) #if defined( USE_FP_LIB_TABLE )
CmpName += wxT( ":" ) + dlg.GetTextSelection( 1 ); CmpName = dlg.GetTextSelection( 1 ) + wxT( ":" ) + CmpName;
#endif #endif
SkipNextLeftButtonReleaseEvent(); SkipNextLeftButtonReleaseEvent();
......
/*
* 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 * @file modedit.cpp
*/ */
...@@ -232,102 +255,100 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -232,102 +255,100 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_OPEN_MODULE_VIEWER: case ID_OPEN_MODULE_VIEWER:
{ {
FOOTPRINT_VIEWER_FRAME * viewer = FOOTPRINT_VIEWER_FRAME::GetActiveFootprintViewer(); FOOTPRINT_VIEWER_FRAME * viewer = FOOTPRINT_VIEWER_FRAME::GetActiveFootprintViewer();
if( viewer == NULL ) if( viewer == NULL )
{ {
viewer = new FOOTPRINT_VIEWER_FRAME( this, m_footprintLibTable, NULL ); viewer = new FOOTPRINT_VIEWER_FRAME( this, m_footprintLibTable, NULL );
viewer->Show( true ); viewer->Show( true );
viewer->Zoom_Automatique( false ); viewer->Zoom_Automatique( false );
} }
else else
{ {
if( viewer->IsIconized() ) if( viewer->IsIconized() )
viewer->Iconize( false ); viewer->Iconize( false );
viewer->Raise(); viewer->Raise();
// Raising the window does not set the focus on Linux. This should work on // Raising the window does not set the focus on Linux. This should work on
// any platform. // any platform.
if( wxWindow::FindFocus() != viewer ) if( wxWindow::FindFocus() != viewer )
viewer->SetFocus(); viewer->SetFocus();
}
} }
break; }
break;
case ID_MODEDIT_DELETE_PART: case ID_MODEDIT_DELETE_PART:
DeleteModuleFromCurrentLibrary(); DeleteModuleFromCurrentLibrary();
break; break;
case ID_MODEDIT_NEW_MODULE: case ID_MODEDIT_NEW_MODULE:
{ {
Clear_Pcb( true ); Clear_Pcb( true );
GetScreen()->ClearUndoRedoList(); GetScreen()->ClearUndoRedoList();
SetCurItem( NULL ); SetCurItem( NULL );
GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) );
MODULE* module = Create_1_Module( wxEmptyString ); MODULE* module = Create_1_Module( wxEmptyString );
if( module ) // i.e. if create module command not aborted if( module ) // i.e. if create module command not aborted
{ {
// Initialize data relative to nets and netclasses (for a new // Initialize data relative to nets and netclasses (for a new
// module the defaults are used) // module the defaults are used)
// This is mandatory to handle and draw pads // This is mandatory to handle and draw pads
GetBoard()->BuildListOfNets(); GetBoard()->BuildListOfNets();
redraw = true; redraw = true;
module->SetPosition( wxPoint( 0, 0 ) ); module->SetPosition( wxPoint( 0, 0 ) );
if( GetBoard()->m_Modules ) if( GetBoard()->m_Modules )
GetBoard()->m_Modules->ClearFlags(); GetBoard()->m_Modules->ClearFlags();
Zoom_Automatique( false ); Zoom_Automatique( false );
}
} }
break; }
break;
case ID_MODEDIT_NEW_MODULE_FROM_WIZARD: case ID_MODEDIT_NEW_MODULE_FROM_WIZARD:
{ {
Clear_Pcb( true ); Clear_Pcb( true );
GetScreen()->ClearUndoRedoList(); GetScreen()->ClearUndoRedoList();
SetCurItem( NULL ); SetCurItem( NULL );
GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); 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 wxSemaphore semaphore( 0, 1 );
// module the defaults are used) FOOTPRINT_WIZARD_FRAME *wizard = new FOOTPRINT_WIZARD_FRAME( this, &semaphore,
// This is mandatory to handle and draw pads KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT );
GetBoard()->BuildListOfNets(); wizard->Show( true );
redraw = true; wizard->Zoom_Automatique( false );
module->SetPosition( wxPoint( 0, 0 ) );
if( GetBoard()->m_Modules ) while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event
GetBoard()->m_Modules->ClearFlags(); {
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 ) );
wizard->Destroy(); if( GetBoard()->m_Modules )
GetBoard()->m_Modules->ClearFlags();
} }
wizard->Destroy();
}
break; break;
case ID_MODEDIT_SAVE_LIBMODULE: case ID_MODEDIT_SAVE_LIBMODULE:
...@@ -340,84 +361,84 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -340,84 +361,84 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_MODEDIT_INSERT_MODULE_IN_BOARD: case ID_MODEDIT_INSERT_MODULE_IN_BOARD:
case ID_MODEDIT_UPDATE_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, source_module = mainpcb->m_Modules;
// 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 ...
{
source_module = mainpcb->m_Modules;
for( ; source_module != NULL; source_module = (MODULE*) source_module->Next() ) for( ; source_module != NULL; source_module = (MODULE*) source_module->Next() )
{
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; if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
msg.Printf( _( "Unable to find the footprint source on the main board" ) ); break;
msg << _( "\nCannot update the footprint" );
DisplayError( this, msg );
break;
} }
}
if( ( source_module != NULL ) if( ( source_module == NULL )
&& ( id == ID_MODEDIT_INSERT_MODULE_IN_BOARD ) ) // source not found && ( id == ID_MODEDIT_UPDATE_MODULE_IN_BOARD ) ) // source not found
{ {
wxString msg; wxString msg;
msg.Printf( _( "A footprint source was found on the main board" ) ); msg.Printf( _( "Unable to find the footprint source on the main board" ) );
msg << _( "\nCannot insert this footprint" ); msg << _( "\nCannot update the footprint" );
DisplayError( this, msg ); DisplayError( this, msg );
break; break;
} }
// Create the "new" module if( ( source_module != NULL )
MODULE* newmodule = new MODULE( *module_in_edit ); && ( id == ID_MODEDIT_INSERT_MODULE_IN_BOARD ) ) // source not found
newmodule->SetParent( mainpcb ); {
newmodule->SetLink( 0 ); wxString msg;
msg.Printf( _( "A footprint source was found on the main board" ) );
msg << _( "\nCannot insert this footprint" );
DisplayError( this, msg );
break;
}
// Put the footprint in the main pcb linked list. // Create the "new" module
mainpcb->Add( newmodule ); MODULE* newmodule = new MODULE( *module_in_edit );
newmodule->SetParent( mainpcb );
newmodule->SetLink( 0 );
if( source_module ) // this is an update command // Put the footprint in the main pcb linked list.
{ mainpcb->Add( newmodule );
// 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(); if( source_module ) // this is an update command
GetScreen()->ClrModify(); {
pcbframe->SetCurItem( NULL ); // In the main board,
mainpcb->m_Status_Pcb = 0; // 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 );
} }
break;
newmodule->ClearFlags();
GetScreen()->ClrModify();
pcbframe->SetCurItem( NULL );
mainpcb->m_Status_Pcb = 0;
}
break;
case ID_MODEDIT_IMPORT_PART: case ID_MODEDIT_IMPORT_PART:
if( ! Clear_Pcb( true ) ) if( ! Clear_Pcb( true ) )
...@@ -459,22 +480,22 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -459,22 +480,22 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_MODEDIT_LOAD_MODULE: case ID_MODEDIT_LOAD_MODULE:
{ wxLogDebug( wxT( "Loading module from library " ) + getLibPath() );
PCB_EDIT_FRAME* parent = (PCB_EDIT_FRAME*) GetParent();
wxString libPath = getLibPath(); // might be empty
wxLogDebug( wxT( "Loading module from library " ) + libPath ); GetScreen()->ClearUndoRedoList();
SetCurItem( NULL );
Clear_Pcb( true );
GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) );
GetScreen()->ClearUndoRedoList(); #if !defined( USE_FP_LIB_TABLE )
SetCurItem( NULL ); LoadModuleFromLibrary( getLibPath(), m_footprintLibTable, true );
Clear_Pcb( true ); #else
GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) ); LoadModuleFromLibrary( getLibNickName(), m_footprintLibTable, true );
LoadModuleFromLibrary( libPath, parent->GetFootprintLibraryTable(), true ); #endif
redraw = true; redraw = true;
}
if( GetBoard()->m_Modules ) if( GetBoard()->m_Modules )
GetBoard()->m_Modules->ClearFlags(); GetBoard()->m_Modules->ClearFlags();
// if either m_Reference or m_Value are gone, reinstall them - // if either m_Reference or m_Value are gone, reinstall them -
// otherwise you cannot see what you are doing on board // otherwise you cannot see what you are doing on board
...@@ -881,6 +902,7 @@ void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent ) ...@@ -881,6 +902,7 @@ void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent )
} }
} }
EDA_COLOR_T FOOTPRINT_EDIT_FRAME::GetGridColor() const EDA_COLOR_T FOOTPRINT_EDIT_FRAME::GetGridColor() const
{ {
return g_ColorsSettings.GetItemColor( GRID_VISIBLE ); return g_ColorsSettings.GetItemColor( GRID_VISIBLE );
......
/*
* 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 * @file module_editor_frame.h
* @brief Definition of class FOOTPRINT_EDIT_FRAME. * @brief Definition of class FOOTPRINT_EDIT_FRAME.
...@@ -9,10 +32,14 @@ ...@@ -9,10 +32,14 @@
#include <wxBasePcbFrame.h> #include <wxBasePcbFrame.h>
#include <io_mgr.h> #include <io_mgr.h>
class FP_LIB_TABLE;
class FOOTPRINT_EDIT_FRAME : public PCB_BASE_FRAME class FOOTPRINT_EDIT_FRAME : public PCB_BASE_FRAME
{ {
public: public:
FOOTPRINT_EDIT_FRAME( PCB_EDIT_FRAME* aParent ); FOOTPRINT_EDIT_FRAME( PCB_EDIT_FRAME* aParent, FP_LIB_TABLE* aTable );
~FOOTPRINT_EDIT_FRAME(); ~FOOTPRINT_EDIT_FRAME();
...@@ -87,7 +114,7 @@ public: ...@@ -87,7 +114,7 @@ public:
* Function OnSaveLibraryAs * Function OnSaveLibraryAs
* saves the current library to a new name and/or library type. * 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 * @see PLUGIN::FootprintSave and PLUGIN::FootprintLibCreate
*/ */
void OnSaveLibraryAs( wxCommandEvent& aEvent ); void OnSaveLibraryAs( wxCommandEvent& aEvent );
...@@ -360,7 +387,7 @@ public: ...@@ -360,7 +387,7 @@ public:
/** /**
* Function DlgGlobalChange_PadSettings * 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. * or all footprints which look like the given footprint.
* Options are set by the opened dialog. * Options are set by the opened dialog.
* @param aPad is the pattern. The given footprint is the parent of this pad * @param aPad is the pattern. The given footprint is the parent of this pad
...@@ -380,7 +407,7 @@ public: ...@@ -380,7 +407,7 @@ public:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
protected: 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 * Function GetComponentFromUndoList
......
...@@ -156,7 +156,7 @@ END_EVENT_TABLE() ...@@ -156,7 +156,7 @@ END_EVENT_TABLE()
#define FOOTPRINT_EDIT_FRAME_NAME wxT( "ModEditFrame" ) #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, PCB_BASE_FRAME( aParent, MODULE_EDITOR_FRAME_TYPE, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() ) KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() )
...@@ -166,6 +166,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( PCB_EDIT_FRAME* aParent ) : ...@@ -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_showAxis = true; // true to show X and Y axis on screen
m_showGridAxis = true; // show the grid origin axis m_showGridAxis = true; // show the grid origin axis
m_HotkeysZoomAndGridList = g_Module_Editor_Hokeys_Descr; m_HotkeysZoomAndGridList = g_Module_Editor_Hokeys_Descr;
m_footprintLibTable = aTable;
// Give an icon // Give an icon
wxIcon icon; wxIcon icon;
...@@ -258,20 +259,22 @@ FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME() ...@@ -258,20 +259,22 @@ FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME()
m_Pcb = 0; m_Pcb = 0;
} }
const wxChar* FOOTPRINT_EDIT_FRAME::GetFootprintEditorFrameName() const wxChar* FOOTPRINT_EDIT_FRAME::GetFootprintEditorFrameName()
{ {
return FOOTPRINT_EDIT_FRAME_NAME; return FOOTPRINT_EDIT_FRAME_NAME;
} }
/* return a reference to the current opened Footprint editor /* return a reference to the current opened Footprint editor
* or NULL if no Footprint editor currently opened * or NULL if no Footprint editor currently opened
*/ */
FOOTPRINT_EDIT_FRAME* FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor() FOOTPRINT_EDIT_FRAME* FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor()
{ {
return (FOOTPRINT_EDIT_FRAME*) return (FOOTPRINT_EDIT_FRAME*) wxWindow::FindWindowByName( GetFootprintEditorFrameName() );
wxWindow::FindWindowByName(GetFootprintEditorFrameName());
} }
BOARD_DESIGN_SETTINGS& FOOTPRINT_EDIT_FRAME::GetDesignSettings() const BOARD_DESIGN_SETTINGS& FOOTPRINT_EDIT_FRAME::GetDesignSettings() const
{ {
// get the BOARD_DESIGN_SETTINGS from the parent editor, not our BOARD. // get the BOARD_DESIGN_SETTINGS from the parent editor, not our BOARD.
...@@ -337,7 +340,7 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) ...@@ -337,7 +340,7 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
// at case ID_MODEDIT_SAVE_LIBMODULE // at case ID_MODEDIT_SAVE_LIBMODULE
if( GetBoard()->m_Modules && getLibPath() != wxEmptyString ) 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 // save was correct
GetScreen()->ClrModify(); GetScreen()->ClrModify();
...@@ -489,6 +492,7 @@ void FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, ...@@ -489,6 +492,7 @@ void FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition,
// for next cursor position // for next cursor position
// ( shift or ctrl key down are PAN command with mouse wheel) // ( shift or ctrl key down are PAN command with mouse wheel)
bool snapToGrid = true; bool snapToGrid = true;
if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) ) if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) )
snapToGrid = false; snapToGrid = false;
...@@ -612,4 +616,3 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() ...@@ -612,4 +616,3 @@ void FOOTPRINT_EDIT_FRAME::updateTitle()
SetTitle( title ); SetTitle( title );
} }
...@@ -205,7 +205,11 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) ...@@ -205,7 +205,11 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
SetCurItem( NULL ); SetCurItem( NULL );
// Delete the current footprint // Delete the current footprint
GetBoard()->m_Modules.DeleteAll(); 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(); Update3D_Frame();
} }
......
...@@ -204,8 +204,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, ...@@ -204,8 +204,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
if( !m_libraryName.IsEmpty() && !m_footprintName.IsEmpty() ) if( !m_libraryName.IsEmpty() && !m_footprintName.IsEmpty() )
{ {
#if !defined( USE_FP_LIB_TABLE ) #if !defined( USE_FP_LIB_TABLE )
GetModuleLibrary( m_libraryName + wxT(".") + LegacyFootprintLibPathExtension, MODULE* footprint = GetModuleLibrary( m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension,
m_footprintName, false ); m_footprintName, false );
if( footprint )
GetBoard()->Add( footprint, ADD_APPEND );
#else #else
FPID id; FPID id;
id.SetLibNickname( TO_UTF8( m_libraryName ) ); id.SetLibNickname( TO_UTF8( m_libraryName ) );
...@@ -496,8 +499,11 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) ...@@ -496,8 +499,11 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
// Delete the current footprint // Delete the current footprint
GetBoard()->m_Modules.DeleteAll(); GetBoard()->m_Modules.DeleteAll();
#if !defined( USE_FP_LIB_TABLE ) #if !defined( USE_FP_LIB_TABLE )
GetModuleLibrary( m_libraryName + wxT(".") + LegacyFootprintLibPathExtension, MODULE* footprint = GetModuleLibrary( m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension,
m_footprintName, true ); m_footprintName, true );
if( footprint )
GetBoard()->Add( footprint, ADD_APPEND );
#else #else
FPID id; FPID id;
id.SetLibNickname( TO_UTF8( m_libraryName ) ); id.SetLibNickname( TO_UTF8( m_libraryName ) );
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <netlist_reader.h> #include <netlist_reader.h>
#include <reporter.h> #include <reporter.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <fpid.h>
#include <fp_lib_table.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
...@@ -157,6 +159,8 @@ MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName() ...@@ -157,6 +159,8 @@ MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName()
} }
#if !defined( USE_FP_LIB_TABLE )
void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter )
throw( IO_ERROR, PARSE_ERROR ) throw( IO_ERROR, PARSE_ERROR )
{ {
...@@ -252,3 +256,92 @@ void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) ...@@ -252,3 +256,92 @@ void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter )
component->SetModule( module ); 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. * This program source code file is part of KiCad, a free EDA CAD application.
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
*/ */
/** /**
* @file PCBPolygon.h * @file pcb_polygon.h
*/ */
#ifndef PCB_POLYGON_H_ #ifndef PCB_POLYGON_H_
......
...@@ -442,6 +442,23 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, ...@@ -442,6 +442,23 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
syncLayerWidgetLayer(); syncLayerWidgetLayer();
m_auimgr.Update(); 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() ...@@ -538,22 +538,6 @@ void PCB_EDIT_FRAME::ReadMacros()
void PCB_EDIT_FRAME::loadFootprintLibTable() 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; delete m_footprintLibTable;
wxFileName fn = GetBoard()->GetFileName(); wxFileName fn = GetBoard()->GetFileName();
......
...@@ -258,6 +258,7 @@ static POINT mapPt( const wxPoint& pt ) ...@@ -258,6 +258,7 @@ static POINT mapPt( const wxPoint& pt )
* if found, removes it from the TYPE_COLLECTOR and returns it, else returns NULL. * 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 aPoint The starting or ending point to search for.
* @param items The list to remove from. * @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 * @return DRAWSEGMENT* - The first DRAWSEGMENT that has a start or end point matching
* aPoint, otherwise NULL if none. * aPoint, otherwise NULL if none.
*/ */
......
...@@ -476,6 +476,8 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module, ...@@ -476,6 +476,8 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module,
return false; return false;
} }
m_Parent->GetBoard()->Add( NewModule, ADD_APPEND );
if( Module == m_CurrentModule ) if( Module == m_CurrentModule )
m_CurrentModule = NewModule; m_CurrentModule = NewModule;
...@@ -489,16 +491,6 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module, ...@@ -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, void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
MODULE* aNewModule, MODULE* aNewModule,
PICKED_ITEMS_LIST* aUndoPickList ) PICKED_ITEMS_LIST* aUndoPickList )
...@@ -597,12 +589,6 @@ void DIALOG_EXCHANGE_MODULE::BrowseAndSelectFootprint( wxCommandEvent& event ) ...@@ -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 ) void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
{ {
wxFileName fn; 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