Convert footprint definitions from wxString to FPID.
* Use FPID instead of wxString in MODULE object. * Use FPID instead of wxString when loading and saving files. * Use FPID in COMPONENT object. * Add wxString helper functions and comparison operators to FPID. * Add fp_lib token to pcb and netlist file formats. * Add code to load and save FPIDs to pcb file format. * Fix segfault when deleting invalid footprint library tables in Pcbnew in non footprint library table build. * Fix bug when counting the number of mod files in EDA_APP::SetFootprintLibTablePath();
This commit is contained in:
parent
9ab7c18f46
commit
230c5f8f5a
|
@ -619,7 +619,7 @@ void EDA_APP::SetDefaultSearchPaths( void )
|
|||
}
|
||||
}
|
||||
|
||||
#if 1 && defined( DEBUG )
|
||||
#if 0 && defined( DEBUG )
|
||||
wxLogDebug( wxT( "Library search paths:" ) );
|
||||
|
||||
for( unsigned i = 0; i < m_libSearchPaths.GetCount(); i++ )
|
||||
|
@ -1188,7 +1188,7 @@ bool EDA_APP::SetFootprintLibTablePath()
|
|||
for( unsigned i = 0; i < GetLibraryPathList().GetCount(); i++ )
|
||||
{
|
||||
unsigned cnt = wxDir::GetAllFiles( GetLibraryPathList()[i], &tmp, wxT( "*.mod" ),
|
||||
wxDIR_DEFAULT & ~wxDIR_HIDDEN );
|
||||
wxDIR_FILES );
|
||||
|
||||
if( cnt > modFileCount )
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <memory>
|
||||
#include <wx/wx.h> // _()
|
||||
|
||||
#include <macros.h> // TO_UTF8()
|
||||
#include <fpid.h>
|
||||
|
||||
|
||||
|
@ -185,6 +186,23 @@ FPID::FPID( const std::string& aId ) throw( PARSE_ERROR )
|
|||
}
|
||||
|
||||
|
||||
FPID::FPID( const wxString& aId ) throw( PARSE_ERROR )
|
||||
{
|
||||
std::string id = TO_UTF8( aId );
|
||||
|
||||
int offset = Parse( id );
|
||||
|
||||
if( offset != -1 )
|
||||
{
|
||||
THROW_PARSE_ERROR( _( "Illegal character found in FPID string" ),
|
||||
wxString::FromUTF8( id.c_str() ),
|
||||
id.c_str(),
|
||||
0,
|
||||
offset );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int FPID::SetLibNickname( const std::string& aLogical )
|
||||
{
|
||||
int offset = okLogical( aLogical );
|
||||
|
@ -198,6 +216,12 @@ int FPID::SetLibNickname( const std::string& aLogical )
|
|||
}
|
||||
|
||||
|
||||
int FPID::SetLibNickname( const wxString& aLogical )
|
||||
{
|
||||
return SetLibNickname( std::string( TO_UTF8( aLogical ) ) );
|
||||
}
|
||||
|
||||
|
||||
int FPID::SetFootprintName( const std::string& aFootprintName )
|
||||
{
|
||||
int separation = int( aFootprintName.find_first_of( "/" ) );
|
||||
|
@ -216,6 +240,12 @@ int FPID::SetFootprintName( const std::string& aFootprintName )
|
|||
}
|
||||
|
||||
|
||||
int FPID::SetFootprintName( const wxString& aFootprintName )
|
||||
{
|
||||
return SetFootprintName( std::string( TO_UTF8( aFootprintName ) ) );
|
||||
}
|
||||
|
||||
|
||||
int FPID::SetRevision( const std::string& aRevision )
|
||||
{
|
||||
int offset = okRevision( aRevision );
|
||||
|
|
|
@ -12,6 +12,7 @@ fields
|
|||
footprint
|
||||
footprints
|
||||
fp
|
||||
fp_lib
|
||||
lib
|
||||
libpart
|
||||
libparts
|
||||
|
|
|
@ -72,6 +72,7 @@ font
|
|||
fp_arc
|
||||
fp_circle
|
||||
fp_curve
|
||||
fp_lib
|
||||
fp_line
|
||||
fp_poly
|
||||
fp_text
|
||||
|
|
|
@ -165,7 +165,7 @@ void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event )
|
|||
bool found = false;
|
||||
m_ListCmp->SetSelection( ii++, true );
|
||||
|
||||
if( !component->GetFootprintName().IsEmpty() )
|
||||
if( !component->GetFPID().empty() )
|
||||
continue;
|
||||
|
||||
BOOST_FOREACH( FOOTPRINT_ALIAS& alias, aliases )
|
||||
|
|
|
@ -342,7 +342,7 @@ void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event )
|
|||
|
||||
for( unsigned jj = selection+1; jj < m_netlist.GetCount(); jj++ )
|
||||
{
|
||||
if( m_netlist.GetComponent( jj )->GetFootprintName().IsEmpty() )
|
||||
if( m_netlist.GetComponent( jj )->GetFPID().empty() )
|
||||
{
|
||||
m_ListCmp->SetSelection( wxNOT_FOUND, false ); // Remove all selections
|
||||
m_ListCmp->SetSelection( jj );
|
||||
|
@ -368,7 +368,7 @@ void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
|
|||
|
||||
for( int kk = selection-1; kk >= 0; kk-- )
|
||||
{
|
||||
if( m_netlist.GetComponent( kk )->GetFootprintName().IsEmpty() )
|
||||
if( m_netlist.GetComponent( kk )->GetFPID().empty() )
|
||||
{
|
||||
m_ListCmp->SetSelection( wxNOT_FOUND, false ); // Remove all selections
|
||||
m_ListCmp->SetSelection( kk );
|
||||
|
@ -405,7 +405,9 @@ void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event )
|
|||
|
||||
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
|
||||
{
|
||||
m_netlist.GetComponent( i )->SetFootprintName( wxEmptyString );
|
||||
FPID fpid;
|
||||
|
||||
m_netlist.GetComponent( i )->SetFPID( fpid );
|
||||
SetNewPkg( wxEmptyString );
|
||||
}
|
||||
|
||||
|
@ -521,7 +523,7 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
|
|||
// selected footprint.
|
||||
if( FindFocus() == m_ListCmp || FindFocus() == m_LibraryList )
|
||||
{
|
||||
wxString module = component->GetFootprintName();
|
||||
wxString module = FROM_UTF8( component->GetFPID().GetFootprintName().c_str() );
|
||||
|
||||
bool found = false;
|
||||
|
||||
|
@ -781,8 +783,8 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist()
|
|||
// not the actual name of the footprint.
|
||||
for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
|
||||
{
|
||||
if( m_netlist.GetComponent( ii )->GetFootprintName() == wxT( "$noname" ) )
|
||||
m_netlist.GetComponent( ii )->SetFootprintName( wxEmptyString );
|
||||
if( m_netlist.GetComponent( ii )->GetFPID().GetFootprintName() == std::string( "$noname" ) )
|
||||
m_netlist.GetComponent( ii )->SetFPID( FPID( wxEmptyString ) );
|
||||
}
|
||||
|
||||
// Sort components by reference:
|
||||
|
@ -832,8 +834,7 @@ bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName )
|
|||
retval |= fprintf( outputFile, "TimeStamp = %s;\n", TO_UTF8( component->GetTimeStamp() ) );
|
||||
retval |= fprintf( outputFile, "Reference = %s;\n", TO_UTF8( component->GetReference() ) );
|
||||
retval |= fprintf( outputFile, "ValeurCmp = %s;\n", TO_UTF8( component->GetValue() ) );
|
||||
retval |= fprintf( outputFile, "IdModule = %s;\n",
|
||||
TO_UTF8( component->GetFootprintName() ) );
|
||||
retval |= fprintf( outputFile, "IdModule = %s;\n", component->GetFPID().Format().c_str() );
|
||||
retval |= fprintf( outputFile, "EndCmp\n" );
|
||||
}
|
||||
|
||||
|
@ -908,7 +909,7 @@ void CVPCB_MAINFRAME::BuildCmpListBox()
|
|||
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
|
||||
GetChars( component->GetReference() ),
|
||||
GetChars( component->GetValue() ),
|
||||
GetChars( component->GetFootprintName() ) );
|
||||
GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
|
||||
m_ListCmp->m_ComponentList.Add( msg );
|
||||
}
|
||||
|
||||
|
|
|
@ -71,16 +71,16 @@ void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName )
|
|||
|
||||
// Check to see if the component has already a footprint set.
|
||||
|
||||
hasFootprint = !(component->GetFootprintName().IsEmpty());
|
||||
hasFootprint = !component->GetFPID().empty();
|
||||
|
||||
component->SetFootprintName( aFootprintName );
|
||||
component->SetFPID( FPID( aFootprintName ) );
|
||||
|
||||
// create the new component description
|
||||
|
||||
description.Printf( CMP_FORMAT, componentIndex + 1,
|
||||
GetChars( component->GetReference() ),
|
||||
GetChars( component->GetValue() ),
|
||||
GetChars( component->GetFootprintName() ) );
|
||||
GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
|
||||
|
||||
// If the component hasn't had a footprint associated with it
|
||||
// it now has, so we decrement the count of components without
|
||||
|
@ -136,10 +136,10 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
|
|||
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
|
||||
GetChars( component->GetReference() ),
|
||||
GetChars( component->GetValue() ),
|
||||
GetChars( component->GetFootprintName() ) );
|
||||
GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
|
||||
m_ListCmp->AppendLine( msg );
|
||||
|
||||
if( component->GetFootprintName().IsEmpty() )
|
||||
if( component->GetFPID().empty() )
|
||||
m_undefinedComponentCnt += 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,8 @@ public:
|
|||
*/
|
||||
FPID( const std::string& aId ) throw( PARSE_ERROR );
|
||||
|
||||
FPID( const wxString& aId ) throw( PARSE_ERROR );
|
||||
|
||||
/**
|
||||
* Function Parse
|
||||
* [re-]stuffs this FPID with the information from @a aId.
|
||||
|
@ -98,6 +100,8 @@ public:
|
|||
*/
|
||||
int SetLibNickname( const std::string& aNickname );
|
||||
|
||||
int SetLibNickname( const wxString& aNickname );
|
||||
|
||||
/**
|
||||
* Function GetFootprintName
|
||||
* returns the footprint name, i.e. footprintName.
|
||||
|
@ -110,6 +114,8 @@ public:
|
|||
*/
|
||||
int SetFootprintName( const std::string& aFootprintName );
|
||||
|
||||
int SetFootprintName( const wxString& aFootprintName );
|
||||
|
||||
int SetRevision( const std::string& aRevision );
|
||||
|
||||
const std::string& GetRevision() const { return revision; }
|
||||
|
@ -175,7 +181,9 @@ public:
|
|||
int compare( const FPID& aFPID ) const;
|
||||
|
||||
bool operator <( const FPID& aFPID ) const { return this->compare( aFPID ) < 0; }
|
||||
bool operator >( const FPID& aFPID ) const { return this->compare( aFPID ) > 0; }
|
||||
bool operator ==( const FPID& aFPID ) const { return this->compare( aFPID ) == 0; }
|
||||
bool operator !=( const FPID& aFPID ) const { return !(*this == aFPID); }
|
||||
|
||||
#if defined(DEBUG)
|
||||
static void Test();
|
||||
|
|