Add uuid r/w for sch pins, text, wires, etc.

Fixes https://gitlab.com/kicad/code/kicad/issues/7269
This commit is contained in:
Jeff Young 2021-01-25 22:01:49 +00:00
parent b576ccef61
commit 3702f2e0a9
4 changed files with 113 additions and 38 deletions

View File

@ -268,9 +268,12 @@ wxString SCH_COMPONENT::GetDatasheet() const
void SCH_COMPONENT::UpdatePins()
{
std::map<wxString, wxString> altPinMap;
std::map<wxString, KIID> pinUuidMap;
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
{
pinUuidMap[ pin->GetNumber() ] = pin->m_Uuid;
if( !pin->GetAlt().IsEmpty() )
altPinMap[ pin->GetNumber() ] = pin->GetAlt();
}
@ -292,10 +295,15 @@ void SCH_COMPONENT::UpdatePins()
m_pins.push_back( std::make_unique<SCH_PIN>( libPin, this ) );
auto ii = altPinMap.find( libPin->GetNumber() );
auto ii = pinUuidMap.find( libPin->GetNumber() );
if( ii != altPinMap.end() )
m_pins.back()->SetAlt( ii->second );
if( ii != pinUuidMap.end() )
const_cast<KIID&>( m_pins.back()->m_Uuid ) = ii->second;
auto iii = altPinMap.find( libPin->GetNumber() );
if( iii != altPinMap.end() )
m_pins.back()->SetAlt( iii->second );
m_pinMap[ libPin ] = i;

View File

@ -58,4 +58,5 @@
//#define SEXPR_SCHEMATIC_FILE_VERSION 20200827 // Remove host tag
//#define SEXPR_SCHEMATIC_FILE_VERSION 20200828 // Add footprint to symbol_instances.
//#define SEXPR_SCHEMATIC_FILE_VERSION 20201015 // Add sheet instance properties.
#define SEXPR_SCHEMATIC_FILE_VERSION 20210123 // Rename "unconnected" pintype to "no_connect".
//#define SEXPR_SCHEMATIC_FILE_VERSION 20210123 // Rename "unconnected" pintype to "no_connect".
#define SEXPR_SCHEMATIC_FILE_VERSION 20210125 // R/W uuids for pins, labels, wires, etc.

View File

@ -1792,8 +1792,14 @@ SCH_SHEET_PIN* SCH_SEXPR_PARSER::parseSchSheetPin( SCH_SHEET* aSheet )
parseEDA_TEXT( static_cast<EDA_TEXT*>( sheetPin.get() ) );
break;
case T_uuid:
NeedSYMBOL();
const_cast<KIID&>( sheetPin->m_Uuid ) = KIID( FromUTF8() );
NeedRIGHT();
break;
default:
Expecting( "at or effects" );
Expecting( "at, uuid or effects" );
}
}
@ -2310,35 +2316,42 @@ SCH_COMPONENT* SCH_SEXPR_PARSER::parseSchematicSymbol()
{
// Read an alternate pin designation
wxString number;
KIID uuid;
wxString alt;
NeedSYMBOL();
number = FromUTF8();
token = NextTok();
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
{
if( token != T_LEFT )
Expecting( T_LEFT );
token = NextTok();
if( token == T_alternate )
switch( token )
{
case T_alternate:
NeedSYMBOL();
alt = FromUTF8();
NeedRIGHT();
break;
case T_uuid:
NeedSYMBOL();
uuid = KIID( FromUTF8() );
NeedRIGHT();
break;
default:
Expecting( "alternate or uuid" );
}
else
{
Expecting( "alternate" );
}
// Create a proxy pin to hold the alternate designation until the parent
// component resolves its pins.
symbol->GetRawPins().emplace_back( std::make_unique<SCH_PIN>( symbol.get(),
number, alt ) );
NeedRIGHT();
const_cast<KIID&>( symbol->GetRawPins().back()->m_Uuid ) = uuid;
}
break;
@ -2388,6 +2401,12 @@ SCH_BITMAP* SCH_SEXPR_PARSER::parseImage()
NeedRIGHT();
break;
case T_uuid:
NeedSYMBOL();
const_cast<KIID&>( bitmap->m_Uuid ) = KIID( FromUTF8() );
NeedRIGHT();
break;
case T_data:
{
token = NextTok();
@ -2418,7 +2437,7 @@ SCH_BITMAP* SCH_SEXPR_PARSER::parseImage()
}
default:
Expecting( "at, scale, or data" );
Expecting( "at, scale, uuid or data" );
}
}
@ -2597,8 +2616,14 @@ SCH_NO_CONNECT* SCH_SEXPR_PARSER::parseNoConnect()
NeedRIGHT();
break;
case T_uuid:
NeedSYMBOL();
const_cast<KIID&>( no_connect->m_Uuid ) = KIID( FromUTF8() );
NeedRIGHT();
break;
default:
Expecting( "at" );
Expecting( "at or uuid" );
}
}
@ -2645,8 +2670,14 @@ SCH_BUS_WIRE_ENTRY* SCH_SEXPR_PARSER::parseBusEntry()
busEntry->SetStroke( stroke );
break;
case T_uuid:
NeedSYMBOL();
const_cast<KIID&>( busEntry->m_Uuid ) = KIID( FromUTF8() );
NeedRIGHT();
break;
default:
Expecting( "at, size, or stroke" );
Expecting( "at, size, uuid or stroke" );
}
}
@ -2704,8 +2735,14 @@ SCH_LINE* SCH_SEXPR_PARSER::parseLine()
line->SetStroke( stroke );
break;
case T_uuid:
NeedSYMBOL();
const_cast<KIID&>( line->m_Uuid ) = KIID( FromUTF8() );
NeedRIGHT();
break;
default:
Expecting( "at or stroke" );
Expecting( "at, uuid or stroke" );
}
}
@ -2796,6 +2833,12 @@ SCH_TEXT* SCH_SEXPR_PARSER::parseSchText()
}
break;
case T_uuid:
NeedSYMBOL();
const_cast<KIID&>( text->m_Uuid ) = KIID( FromUTF8() );
NeedRIGHT();
break;
case T_property:
if( text->Type() == SCH_GLOBAL_LABEL_T )
{
@ -2810,7 +2853,7 @@ SCH_TEXT* SCH_SEXPR_PARSER::parseSchText()
break;
default:
Expecting( "at, shape, iref or effects" );
Expecting( "at, shape, iref, uuid or effects" );
}
}

View File

@ -907,8 +907,10 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_COMPONENT* aSymbol, int aNestLevel )
m_out->Print( aNestLevel, "(symbol" );
if( !aSymbol->UseLibIdLookup() )
{
m_out->Print( 0, " (lib_name %s)",
m_out->Quotew( aSymbol->GetSchSymbolLibraryName() ).c_str() );
}
m_out->Print( 0, " (lib_id %s) (at %s %s %s)",
m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(),
@ -945,9 +947,7 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_COMPONENT* aSymbol, int aNestLevel )
m_out->Print( 0, "\n" );
// @todo Convert to full UUID if current UUID is a legacy time stamp.
m_out->Print( aNestLevel + 1, "(uuid %s)\n",
m_out->Quotew( aSymbol->m_Uuid.AsString() ).c_str() );
m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSymbol->m_Uuid.AsString() ) );
m_fieldId = MANDATORY_FIELDS;
@ -958,10 +958,17 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_COMPONENT* aSymbol, int aNestLevel )
for( const SCH_PIN* pin : aSymbol->GetPins() )
{
if( !pin->GetAlt().IsEmpty() )
if( pin->GetAlt().IsEmpty() )
{
m_out->Print( aNestLevel + 1, "(pin %s (alternate %s))\n",
m_out->Print( aNestLevel + 1, "(pin %s (uuid %s))\n",
m_out->Quotew( pin->GetNumber() ).c_str(),
TO_UTF8( aSymbol->m_Uuid.AsString() ) );
}
else
{
m_out->Print( aNestLevel + 1, "(pin %s (uuid %s) (alternate %s))\n",
m_out->Quotew( pin->GetNumber() ).c_str(),
TO_UTF8( aSymbol->m_Uuid.AsString() ),
m_out->Quotew( pin->GetAlt() ).c_str() );
}
}
@ -1033,6 +1040,9 @@ void SCH_SEXPR_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel )
m_out->Print( 0, " (scale %g)", aBitmap->GetImage()->GetScale() );
m_out->Print( 0, "\n" );
m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBitmap->m_Uuid.AsString() ) );
m_out->Print( aNestLevel + 1, "(data" );
wxMemoryOutputStream stream;
@ -1105,7 +1115,10 @@ void SCH_SEXPR_PLUGIN::saveSheet( SCH_SHEET* aSheet, int aNestLevel )
FormatAngle( getSheetPinAngle( pin->GetEdge() ) * 10.0 ).c_str() );
pin->Format( m_out, aNestLevel + 1, 0 );
m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token with font effects.
m_out->Print( aNestLevel + 2, "(uuid %s)\n", TO_UTF8( pin->m_Uuid.AsString() ) );
m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token.
}
m_out->Print( aNestLevel, ")\n" ); // Closes sheet token.
@ -1131,9 +1144,10 @@ void SCH_SEXPR_PLUGIN::saveNoConnect( SCH_NO_CONNECT* aNoConnect, int aNestLevel
{
wxCHECK_RET( aNoConnect != nullptr && m_out != nullptr, "" );
m_out->Print( aNestLevel, "(no_connect (at %s %s))\n",
m_out->Print( aNestLevel, "(no_connect (at %s %s) (uuid %s))\n",
FormatInternalUnits( aNoConnect->GetPosition().x ).c_str(),
FormatInternalUnits( aNoConnect->GetPosition().y ).c_str() );
FormatInternalUnits( aNoConnect->GetPosition().y ).c_str(),
TO_UTF8( aNoConnect->m_Uuid.AsString() ) );
}
@ -1160,6 +1174,9 @@ void SCH_SEXPR_PLUGIN::saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry, int aNestLev
formatStroke( m_out, aNestLevel + 1, aBusEntry->GetStroke() );
m_out->Print( 0, "\n" );
m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBusEntry->m_Uuid.AsString() ) );
m_out->Print( aNestLevel, ")\n" );
}
}
@ -1198,6 +1215,9 @@ void SCH_SEXPR_PLUGIN::saveLine( SCH_LINE* aLine, int aNestLevel )
formatStroke( m_out, aNestLevel + 1, line_stroke );
m_out->Print( 0, "\n" );
m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aLine->m_Uuid.AsString() ) );
m_out->Print( aNestLevel, ")\n" );
}
@ -1240,14 +1260,17 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel )
FormatAngle( aText->GetTextAngle() ).c_str() );
}
m_out->Print( 0, "\n" );
aText->Format( m_out, aNestLevel, 0 );
m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aText->m_Uuid.AsString() ) );
if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) )
{
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( aText );
saveField( label->GetIntersheetRefs(), aNestLevel + 1 );
}
m_out->Print( 0, "\n" );
aText->Format( m_out, aNestLevel, 0 );
m_out->Print( aNestLevel, ")\n" ); // Closes text token.
}