Remove long-dead revision support for LIB_IDs.
This commit is contained in:
parent
b1b4caee6a
commit
5cac8afe1d
|
@ -29,58 +29,6 @@
|
||||||
|
|
||||||
#include <macros.h> // TO_UTF8()
|
#include <macros.h> // TO_UTF8()
|
||||||
#include <lib_id.h>
|
#include <lib_id.h>
|
||||||
#include <kicad_string.h>
|
|
||||||
|
|
||||||
|
|
||||||
static inline bool isDigit( char c )
|
|
||||||
{
|
|
||||||
return c >= '0' && c <= '9';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char* EndsWithRev( const char* start, const char* tail, char separator )
|
|
||||||
{
|
|
||||||
bool sawDigit = false;
|
|
||||||
|
|
||||||
while( tail > start && isDigit( *--tail ) )
|
|
||||||
{
|
|
||||||
sawDigit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if sawDigit, tail points to the 'v' here.
|
|
||||||
|
|
||||||
if( sawDigit && tail-3 >= start )
|
|
||||||
{
|
|
||||||
tail -= 3;
|
|
||||||
|
|
||||||
if( tail[0]==separator && tail[1]=='r' && tail[2]=='e' && tail[3]=='v' )
|
|
||||||
{
|
|
||||||
return tail+1; // omit separator, return "revN[N..]"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if 0 // Not used
|
|
||||||
int RevCmp( const char* s1, const char* s2 )
|
|
||||||
{
|
|
||||||
int r = strncmp( s1, s2, 3 );
|
|
||||||
|
|
||||||
if( r || strlen(s1)<4 || strlen(s2)<4 )
|
|
||||||
{
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int rnum1 = atoi( s1+3 );
|
|
||||||
int rnum2 = atoi( s2+3 );
|
|
||||||
|
|
||||||
return -(rnum1 - rnum2); // swap the sign, higher revs first
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//----<Policy and field test functions>-------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
static inline int okLogical( const UTF8& aField )
|
static inline int okLogical( const UTF8& aField )
|
||||||
|
@ -91,31 +39,10 @@ static inline int okLogical( const UTF8& aField )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int okRevision( const UTF8& aField )
|
|
||||||
{
|
|
||||||
char rev[32]; // C string for speed
|
|
||||||
|
|
||||||
if( aField.size() >= 4 )
|
|
||||||
{
|
|
||||||
strncpy( rev, "x/", sizeof( rev ) );
|
|
||||||
strncat( rev, aField.c_str(), sizeof(rev)-strlen(rev)-1 );
|
|
||||||
|
|
||||||
if( EndsWithRev( rev, rev + strlen(rev), '/' ) == rev+2 )
|
|
||||||
return -1; // success
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0; // first character position "is in error", is best we can do.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//----</Policy and field test functions>-------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
void LIB_ID::clear()
|
void LIB_ID::clear()
|
||||||
{
|
{
|
||||||
m_libraryName.clear();
|
m_libraryName.clear();
|
||||||
m_itemName.clear();
|
m_itemName.clear();
|
||||||
m_revision.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,28 +50,10 @@ int LIB_ID::Parse( const UTF8& aId, bool aFix )
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
const char* buffer = aId.c_str();
|
size_t partNdx;
|
||||||
const char* rev = EndsWithRev( buffer, buffer+aId.length(), '/' );
|
int offset = -1;
|
||||||
size_t revNdx;
|
|
||||||
size_t partNdx;
|
|
||||||
int offset = -1;
|
|
||||||
|
|
||||||
//=====<revision>=====================================
|
//=====<library nickname>=============================
|
||||||
// in a LIB_ID like discret:R3/rev4
|
|
||||||
if( rev )
|
|
||||||
{
|
|
||||||
revNdx = rev - buffer;
|
|
||||||
|
|
||||||
// no need to check revision, EndsWithRev did that.
|
|
||||||
m_revision = aId.substr( revNdx );
|
|
||||||
--revNdx; // back up to omit the '/' which precedes the rev
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
revNdx = aId.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
//=====<name>=========================================
|
|
||||||
if( ( partNdx = aId.find( ':' ) ) != aId.npos )
|
if( ( partNdx = aId.find( ':' ) ) != aId.npos )
|
||||||
{
|
{
|
||||||
offset = SetLibNickname( aId.substr( 0, partNdx ) );
|
offset = SetLibNickname( aId.substr( 0, partNdx ) );
|
||||||
|
@ -160,10 +69,7 @@ int LIB_ID::Parse( const UTF8& aId, bool aFix )
|
||||||
}
|
}
|
||||||
|
|
||||||
//=====<item name>====================================
|
//=====<item name>====================================
|
||||||
if( partNdx >= revNdx )
|
UTF8 fpname = aId.substr( partNdx );
|
||||||
return partNdx; // Error: no library item name.
|
|
||||||
|
|
||||||
UTF8 fpname = aId.substr( partNdx, revNdx-partNdx );
|
|
||||||
|
|
||||||
// Be sure the item name is valid.
|
// Be sure the item name is valid.
|
||||||
// Some chars can be found in legacy files converted files from other EDA tools.
|
// Some chars can be found in legacy files converted files from other EDA tools.
|
||||||
|
@ -181,11 +87,9 @@ int LIB_ID::Parse( const UTF8& aId, bool aFix )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LIB_ID::LIB_ID( const wxString& aLibraryName, const wxString& aItemName,
|
LIB_ID::LIB_ID( const wxString& aLibraryName, const wxString& aItemName ) :
|
||||||
const wxString& aRevision ) :
|
|
||||||
m_libraryName( aLibraryName ),
|
m_libraryName( aLibraryName ),
|
||||||
m_itemName( aItemName ),
|
m_itemName( aItemName )
|
||||||
m_revision( aRevision )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,35 +105,14 @@ int LIB_ID::SetLibNickname( const UTF8& aLogical )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LIB_ID::SetLibItemName( const UTF8& aLibItemName, bool aTestForRev )
|
int LIB_ID::SetLibItemName( const UTF8& aLibItemName )
|
||||||
{
|
{
|
||||||
int separation = int( aLibItemName.find_first_of( "/" ) );
|
m_itemName = aLibItemName;
|
||||||
|
|
||||||
if( aTestForRev && separation != -1 )
|
|
||||||
{
|
|
||||||
m_itemName = aLibItemName.substr( 0, separation-1 );
|
|
||||||
return separation;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_itemName = aLibItemName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LIB_ID::SetRevision( const UTF8& aRevision )
|
|
||||||
{
|
|
||||||
int offset = okRevision( aRevision );
|
|
||||||
|
|
||||||
if( offset == -1 )
|
|
||||||
m_revision = aRevision;
|
|
||||||
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UTF8 LIB_ID::Format() const
|
UTF8 LIB_ID::Format() const
|
||||||
{
|
{
|
||||||
UTF8 ret;
|
UTF8 ret;
|
||||||
|
@ -242,31 +125,11 @@ UTF8 LIB_ID::Format() const
|
||||||
|
|
||||||
ret += m_itemName;
|
ret += m_itemName;
|
||||||
|
|
||||||
if( m_revision.size() )
|
|
||||||
{
|
|
||||||
ret += '/';
|
|
||||||
ret += m_revision;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UTF8 LIB_ID::GetLibItemNameAndRev() const
|
UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName )
|
||||||
{
|
|
||||||
UTF8 ret = m_itemName;
|
|
||||||
|
|
||||||
if( m_revision.size() )
|
|
||||||
{
|
|
||||||
ret += '/';
|
|
||||||
ret += m_revision;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName, const UTF8& aRevision )
|
|
||||||
{
|
{
|
||||||
UTF8 ret;
|
UTF8 ret;
|
||||||
int offset;
|
int offset;
|
||||||
|
@ -278,7 +141,8 @@ UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName, const U
|
||||||
if( offset != -1 )
|
if( offset != -1 )
|
||||||
{
|
{
|
||||||
THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ),
|
THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ),
|
||||||
wxString::FromUTF8( aLibraryName.c_str() ), aLibraryName.c_str(), 0, offset );
|
wxString::FromUTF8( aLibraryName.c_str() ), aLibraryName.c_str(),
|
||||||
|
0, offset );
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += aLibraryName;
|
ret += aLibraryName;
|
||||||
|
@ -287,23 +151,6 @@ UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName, const U
|
||||||
|
|
||||||
ret += aLibItemName; // TODO: Add validity test.
|
ret += aLibItemName; // TODO: Add validity test.
|
||||||
|
|
||||||
if( aRevision.size() )
|
|
||||||
{
|
|
||||||
offset = okRevision( aRevision );
|
|
||||||
|
|
||||||
if( offset != -1 )
|
|
||||||
{
|
|
||||||
THROW_PARSE_ERROR( _( "Illegal character found in revision" ),
|
|
||||||
wxString::FromUTF8( aRevision.c_str() ),
|
|
||||||
aRevision.c_str(),
|
|
||||||
0,
|
|
||||||
offset );
|
|
||||||
}
|
|
||||||
|
|
||||||
ret += '/';
|
|
||||||
ret += aRevision;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,12 +166,7 @@ int LIB_ID::compare( const LIB_ID& aLibId ) const
|
||||||
if( retv != 0 )
|
if( retv != 0 )
|
||||||
return retv;
|
return retv;
|
||||||
|
|
||||||
retv = m_itemName.compare( aLibId.m_itemName );
|
return m_itemName.compare( aLibId.m_itemName );
|
||||||
|
|
||||||
if( retv != 0 )
|
|
||||||
return retv;
|
|
||||||
|
|
||||||
return m_revision.compare( aLibId.m_revision );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -374,12 +216,12 @@ bool LIB_ID::isLegalChar( unsigned aUniChar )
|
||||||
switch( aUniChar )
|
switch( aUniChar )
|
||||||
{
|
{
|
||||||
case ':':
|
case ':':
|
||||||
case '/':
|
|
||||||
case '\t':
|
case '\t':
|
||||||
case '\n':
|
case '\n':
|
||||||
case '\r':
|
case '\r':
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
case '/':
|
||||||
case '\\':
|
case '\\':
|
||||||
case '<':
|
case '<':
|
||||||
case '>':
|
case '>':
|
||||||
|
@ -428,33 +270,3 @@ bool LIB_ID::isLegalLibraryNameChar( unsigned aUniChar )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
// @todo Move this test into the unit test framework.
|
|
||||||
|
|
||||||
void LIB_ID::Test()
|
|
||||||
{
|
|
||||||
static const char* lpids[] = {
|
|
||||||
"smt:R_0805/rev0",
|
|
||||||
"mysmt:R_0805/rev2",
|
|
||||||
"device:AXIAL-0500",
|
|
||||||
};
|
|
||||||
|
|
||||||
for( unsigned i=0; i<sizeof(lpids)/sizeof(lpids[0]); ++i )
|
|
||||||
{
|
|
||||||
// test some round tripping
|
|
||||||
|
|
||||||
LIB_ID lpid( lpids[i] ); // parse
|
|
||||||
|
|
||||||
// format
|
|
||||||
printf( "input:'%s' full:'%s' nickname: %s m_itemName:'%s' rev:'%s'\n",
|
|
||||||
lpids[i],
|
|
||||||
lpid.Format().c_str(),
|
|
||||||
lpid.GetLibNickname().c_str(),
|
|
||||||
lpid.GetLibItemName().c_str(),
|
|
||||||
lpid.GetRevision().c_str() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ LIB_TREE_NODE_LIB_ID::LIB_TREE_NODE_LIB_ID( LIB_TREE_NODE* aParent, LIB_TREE_ITE
|
||||||
m_Parent = aParent;
|
m_Parent = aParent;
|
||||||
|
|
||||||
m_LibId.SetLibNickname( aItem->GetLibNickname() );
|
m_LibId.SetLibNickname( aItem->GetLibNickname() );
|
||||||
m_LibId.SetLibItemName( aItem->GetName () );
|
m_LibId.SetLibItemName( aItem->GetName() );
|
||||||
|
|
||||||
m_Name = aItem->GetName();
|
m_Name = aItem->GetName();
|
||||||
m_Desc = aItem->GetDescription();
|
m_Desc = aItem->GetDescription();
|
||||||
|
|
|
@ -314,7 +314,7 @@ wxString LIB_SYMBOL::GetUnitReference( int aUnit )
|
||||||
void LIB_SYMBOL::SetName( const wxString& aName )
|
void LIB_SYMBOL::SetName( const wxString& aName )
|
||||||
{
|
{
|
||||||
m_name = aName;
|
m_name = aName;
|
||||||
m_libId.SetLibItemName( aName, false );
|
m_libId.SetLibItemName( aName );
|
||||||
|
|
||||||
GetValueField().SetText( aName );
|
GetValueField().SetText( aName );
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ bool RESCUE_CASE_CANDIDATE::PerformAction( RESCUER* aRescuer )
|
||||||
|
|
||||||
LIB_ID libId;
|
LIB_ID libId;
|
||||||
|
|
||||||
libId.SetLibItemName( m_new_name, false );
|
libId.SetLibItemName( m_new_name );
|
||||||
eachSymbol->SetLibId( libId );
|
eachSymbol->SetLibId( libId );
|
||||||
eachSymbol->ClearFlags();
|
eachSymbol->ClearFlags();
|
||||||
aRescuer->LogRescue( eachSymbol, m_requested_name, m_new_name );
|
aRescuer->LogRescue( eachSymbol, m_requested_name, m_new_name );
|
||||||
|
@ -329,7 +329,7 @@ bool RESCUE_CACHE_CANDIDATE::PerformAction( RESCUER* aRescuer )
|
||||||
|
|
||||||
LIB_ID libId;
|
LIB_ID libId;
|
||||||
|
|
||||||
libId.SetLibItemName( m_new_name, false );
|
libId.SetLibItemName( m_new_name );
|
||||||
eachSymbol->SetLibId( libId );
|
eachSymbol->SetLibId( libId );
|
||||||
eachSymbol->ClearFlags();
|
eachSymbol->ClearFlags();
|
||||||
aRescuer->LogRescue( eachSymbol, m_requested_name, m_new_name );
|
aRescuer->LogRescue( eachSymbol, m_requested_name, m_new_name );
|
||||||
|
@ -550,7 +550,7 @@ void RESCUER::UndoRescues()
|
||||||
{
|
{
|
||||||
LIB_ID libId;
|
LIB_ID libId;
|
||||||
|
|
||||||
libId.SetLibItemName( each_logitem.old_name, false );
|
libId.SetLibItemName( each_logitem.old_name );
|
||||||
each_logitem.symbol->SetLibId( libId );
|
each_logitem.symbol->SetLibId( libId );
|
||||||
each_logitem.symbol->ClearFlags();
|
each_logitem.symbol->ClearFlags();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1575,7 +1575,7 @@ SCH_SYMBOL* SCH_LEGACY_PLUGIN::loadSymbol( LINE_READER& aReader )
|
||||||
if( m_version > 3 )
|
if( m_version > 3 )
|
||||||
libId.Parse( libName, true );
|
libId.Parse( libName, true );
|
||||||
else
|
else
|
||||||
libId.SetLibItemName( libName, false );
|
libId.SetLibItemName( libName );
|
||||||
|
|
||||||
symbol->SetLibId( libId );
|
symbol->SetLibId( libId );
|
||||||
|
|
||||||
|
|
|
@ -65,10 +65,8 @@ public:
|
||||||
* @param aLibraryName is the library name used to look up the library item in the #LIB_TABLE.
|
* @param aLibraryName is the library name used to look up the library item in the #LIB_TABLE.
|
||||||
* @param aItemName is the name of the library item which is not parsed by the standard
|
* @param aItemName is the name of the library item which is not parsed by the standard
|
||||||
* LIB_ID::Parse() function.
|
* LIB_ID::Parse() function.
|
||||||
* @param aRevision is the revision of the library item.
|
|
||||||
*/
|
*/
|
||||||
LIB_ID( const wxString& aLibraryName, const wxString& aItemName,
|
LIB_ID( const wxString& aLibraryName, const wxString& aItemName );
|
||||||
const wxString& aRevision = wxEmptyString );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse LIB_ID with the information from @a aId.
|
* Parse LIB_ID with the information from @a aId.
|
||||||
|
@ -122,13 +120,7 @@ public:
|
||||||
* into the parameter at which an error was detected, usually because it
|
* into the parameter at which an error was detected, usually because it
|
||||||
* contained '/'.
|
* contained '/'.
|
||||||
*/
|
*/
|
||||||
int SetLibItemName( const UTF8& aLibItemName, bool aTestForRev = true );
|
int SetLibItemName( const UTF8& aLibItemName );
|
||||||
|
|
||||||
int SetRevision( const UTF8& aRevision );
|
|
||||||
|
|
||||||
const UTF8& GetRevision() const { return m_revision; }
|
|
||||||
|
|
||||||
UTF8 GetLibItemNameAndRev() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the fully formatted text of the LIB_ID in a UTF8 string.
|
* @return the fully formatted text of the LIB_ID in a UTF8 string.
|
||||||
|
@ -150,8 +142,7 @@ public:
|
||||||
*
|
*
|
||||||
* @throw PARSE_ERROR if any of the pieces are illegal.
|
* @throw PARSE_ERROR if any of the pieces are illegal.
|
||||||
*/
|
*/
|
||||||
static UTF8 Format( const UTF8& aLibraryName, const UTF8& aLibItemName,
|
static UTF8 Format( const UTF8& aLibraryName, const UTF8& aLibItemName );
|
||||||
const UTF8& aRevision = "" );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this LID_ID is valid.
|
* Check if this LID_ID is valid.
|
||||||
|
@ -175,7 +166,7 @@ public:
|
||||||
*/
|
*/
|
||||||
bool IsLegacy() const
|
bool IsLegacy() const
|
||||||
{
|
{
|
||||||
return m_libraryName.empty() && !m_itemName.empty() && m_revision.empty();
|
return m_libraryName.empty() && !m_itemName.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,7 +179,7 @@ public:
|
||||||
*/
|
*/
|
||||||
bool empty() const
|
bool empty() const
|
||||||
{
|
{
|
||||||
return m_libraryName.empty() && m_itemName.empty() && m_revision.empty();
|
return m_libraryName.empty() && m_itemName.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -266,7 +257,6 @@ protected:
|
||||||
|
|
||||||
UTF8 m_libraryName; ///< The nickname of the library or empty.
|
UTF8 m_libraryName; ///< The nickname of the library or empty.
|
||||||
UTF8 m_itemName; ///< The name of the entry in the logical library.
|
UTF8 m_itemName; ///< The name of the entry in the logical library.
|
||||||
UTF8 m_revision; ///< The revision of the entry.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -609,7 +609,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow()
|
||||||
commit.Modify( m_footprint );
|
commit.Modify( m_footprint );
|
||||||
|
|
||||||
LIB_ID fpID = m_footprint->GetFPID();
|
LIB_ID fpID = m_footprint->GetFPID();
|
||||||
fpID.SetLibItemName( m_FootprintNameCtrl->GetValue(), false );
|
fpID.SetLibItemName( m_FootprintNameCtrl->GetValue() );
|
||||||
m_footprint->SetFPID( fpID );
|
m_footprint->SetFPID( fpID );
|
||||||
|
|
||||||
m_footprint->SetDescription( m_DocCtrl->GetValue() );
|
m_footprint->SetDescription( m_DocCtrl->GetValue() );
|
||||||
|
|
|
@ -1038,7 +1038,7 @@ void PCB_IO::format( const FOOTPRINT* aFootprint, int aNestLevel ) const
|
||||||
|
|
||||||
if( m_ctl & CTL_OMIT_LIBNAME )
|
if( m_ctl & CTL_OMIT_LIBNAME )
|
||||||
m_out->Print( aNestLevel, "(footprint %s",
|
m_out->Print( aNestLevel, "(footprint %s",
|
||||||
m_out->Quotes( aFootprint->GetFPID().GetLibItemNameAndRev() ).c_str() );
|
m_out->Quotes( aFootprint->GetFPID().GetLibItemName() ).c_str() );
|
||||||
else
|
else
|
||||||
m_out->Print( aNestLevel, "(footprint %s",
|
m_out->Print( aNestLevel, "(footprint %s",
|
||||||
m_out->Quotes( aFootprint->GetFPID().Format() ).c_str() );
|
m_out->Quotes( aFootprint->GetFPID().Format() ).c_str() );
|
||||||
|
|
Loading…
Reference in New Issue