From 7fe863c9d06fee4e23299b64f4c38db735365ea2 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 22 Nov 2023 12:32:41 -0500 Subject: [PATCH] Quote UUIDs in schematic format --- .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 8db81217ec..7939bc6b95 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -53,6 +53,7 @@ #include #include #include // for MAX_UNIT_COUNT_PER_PACKAGE definition +#include #include #include #include @@ -370,7 +371,7 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet ) m_out->Print( 0, "(kicad_sch (version %d) (generator \"eeschema\") (generator_version \"%s\")\n\n", SEXPR_SCHEMATIC_FILE_VERSION, GetMajorMinorVersion().c_str().AsChar() ); - m_out->Print( 1, "(uuid %s)\n\n", TO_UTF8( screen->m_uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, screen->m_uuid ); screen->GetPageSettings().Format( m_out, 1, 0 ); m_out->Print( 0, "\n" ); @@ -738,7 +739,7 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchema m_out->Print( 0, "\n" ); - m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSymbol->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, aSymbol->m_Uuid ); m_nextFreeFieldId = MANDATORY_FIELDS; @@ -786,15 +787,15 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchema { if( pin->GetAlt().IsEmpty() ) { - m_out->Print( aNestLevel + 1, "(pin %s (uuid %s))\n", - m_out->Quotew( pin->GetNumber() ).c_str(), - TO_UTF8( pin->m_Uuid.AsString() ) ); + m_out->Print( aNestLevel + 1, "(pin %s ", m_out->Quotew( pin->GetNumber() ).c_str() ); + KICAD_FORMAT::FormatUuid( m_out, pin->m_Uuid ); + m_out->Print( aNestLevel + 1, ")\n" ); } else { - m_out->Print( aNestLevel + 1, "(pin %s (uuid %s) (alternate %s))\n", - m_out->Quotew( pin->GetNumber() ).c_str(), - TO_UTF8( pin->m_Uuid.AsString() ), + m_out->Print( aNestLevel + 1, "(pin %s ", m_out->Quotew( pin->GetNumber() ).c_str() ); + KICAD_FORMAT::FormatUuid( m_out, pin->m_Uuid ); + m_out->Print( aNestLevel + 1, " (alternate %s))\n", m_out->Quotew( pin->GetAlt() ).c_str() ); } } @@ -949,7 +950,7 @@ void SCH_SEXPR_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel ) m_out->Print( 0, "\n" ); - m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBitmap->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, aBitmap->m_Uuid ); m_out->Print( aNestLevel + 1, "(data" ); @@ -1006,7 +1007,7 @@ void SCH_SEXPR_PLUGIN::saveSheet( SCH_SHEET* aSheet, int aNestLevel ) KiROUND( aSheet->GetBackgroundColor().b * 255.0 ), aSheet->GetBackgroundColor().a ); - m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSheet->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, aSheet->m_Uuid ); m_nextFreeFieldId = SHEET_MANDATORY_FIELDS; @@ -1028,7 +1029,7 @@ void SCH_SEXPR_PLUGIN::saveSheet( SCH_SHEET* aSheet, int aNestLevel ) pin->Format( m_out, aNestLevel + 1, 0 ); - m_out->Print( aNestLevel + 2, "(uuid %s)\n", TO_UTF8( pin->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, pin->m_Uuid ); m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token. } @@ -1127,7 +1128,7 @@ void SCH_SEXPR_PLUGIN::saveJunction( SCH_JUNCTION* aJunction, int aNestLevel ) KiROUND( aJunction->GetColor().b * 255.0 ), FormatDouble2Str( aJunction->GetColor().a ).c_str() ); - m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aJunction->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, aJunction->m_Uuid ); m_out->Print( aNestLevel, ")\n" ); } @@ -1137,12 +1138,13 @@ 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) (uuid %s))\n", + m_out->Print( aNestLevel, "(no_connect (at %s %s)", EDA_UNIT_UTILS::FormatInternalUnits( schIUScale, aNoConnect->GetPosition().x ).c_str(), EDA_UNIT_UTILS::FormatInternalUnits( schIUScale, - aNoConnect->GetPosition().y ).c_str(), - TO_UTF8( aNoConnect->m_Uuid.AsString() ) ); + aNoConnect->GetPosition().y ).c_str() ); + KICAD_FORMAT::FormatUuid( m_out, aNoConnect->m_Uuid ); + m_out->Print( aNestLevel, ")\n" ); } @@ -1174,7 +1176,7 @@ void SCH_SEXPR_PLUGIN::saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry, int aNestLev m_out->Print( 0, "\n" ); - m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBusEntry->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, aBusEntry->m_Uuid ); m_out->Print( aNestLevel, ")\n" ); } @@ -1249,7 +1251,7 @@ void SCH_SEXPR_PLUGIN::saveLine( SCH_LINE* aLine, int aNestLevel ) line_stroke.Format( m_out, schIUScale, aNestLevel + 1 ); m_out->Print( 0, "\n" ); - m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aLine->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, aLine->m_Uuid ); m_out->Print( aNestLevel, ")\n" ); } @@ -1328,7 +1330,7 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel ) m_out->Print( 0, "\n" ); aText->EDA_TEXT::Format( m_out, aNestLevel, 0 ); - m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aText->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, aText->m_Uuid ); if( label ) { @@ -1366,7 +1368,7 @@ void SCH_SEXPR_PLUGIN::saveTextBox( SCH_TEXTBOX* aTextBox, int aNestLevel ) aTextBox->EDA_TEXT::Format( m_out, aNestLevel, 0 ); if( aTextBox->m_Uuid != niluuid ) - m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aTextBox->m_Uuid.AsString() ) ); + KICAD_FORMAT::FormatUuid( m_out, aTextBox->m_Uuid ); m_out->Print( aNestLevel, ")\n" ); }