23#include <boost/test/unit_test.hpp>
69#include <wx/filename.h>
71#include <wx/imagpng.h>
72#include <wx/mstream.h>
92 std::unique_ptr<SCHEMATIC> schematic;
101 wxString dest = wxFileName::CreateTempFileName( wxT(
"kicad_qa_sch_downgrade" ) );
102 wxRemoveFile( dest );
103 dest += wxT(
".kicad_sch" );
107 std::ifstream file( dest.ToStdString() );
108 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
110 wxRemoveFile( dest );
113 BOOST_CHECK_MESSAGE( content.find(
"(version " + std::to_string( aTarget.m_schVersion ) +
")" )
114 != std::string::npos,
115 "Downgraded schematic does not carry the target version stamp" );
123 if( !unsupported.empty() )
125 std::string msg =
"Downgraded schematic uses tokens " + aTarget.m_name.ToStdString() +
" cannot parse:";
127 for(
const std::string& token : unsupported )
151 wxString dest = wxFileName::CreateTempFileName( wxT(
"kicad_qa_symlib" ) );
152 wxRemoveFile( dest );
153 dest += wxT(
".kicad_sym" );
159 std::vector<LIB_SYMBOL*> symbols;
170 std::ifstream file( dest.ToStdString() );
171 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
174 BOOST_CHECK( content.find(
"(version " + std::to_string(
kicad9.m_symLibVersion ) +
")" ) != std::string::npos );
177 std::vector<LIB_SYMBOL*> reloaded;
179 BOOST_CHECK( !reloaded.empty() );
181 wxRemoveFile( dest );
190 wxString dest = wxFileName::CreateTempFileName( wxT(
"kicad_qa_symlib10" ) );
191 wxRemoveFile( dest );
192 dest += wxT(
".kicad_sym" );
198 std::vector<LIB_SYMBOL*> symbols;
208 std::ifstream file( dest.ToStdString() );
209 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
211 wxRemoveFile( dest );
213 BOOST_CHECK( content.find(
"(version " + std::to_string(
kicad10.m_symLibVersion ) +
")" ) != std::string::npos );
221 wxString dest = wxFileName::CreateTempFileName( wxT(
"kicad_qa_symlib_inherit" ) );
222 wxRemoveFile( dest );
223 dest += wxT(
".kicad_sym" );
230 std::vector<LIB_SYMBOL*> symbols;
234 std::stable_sort( symbols.begin(), symbols.end(),
237 return a->GetInheritanceDepth() < b->GetInheritanceDepth();
246 std::ifstream file( dest.ToStdString() );
247 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
249 wxRemoveFile( dest );
251 size_t parentPos = content.find(
"(symbol \"CAP\"" );
252 size_t childRef = content.find(
"(extends \"CAP\")" );
256 BOOST_CHECK( parentPos < childRef );
266 std::unique_ptr<SCHEMATIC> schematic;
270 SCH_SHEET* sheet = schematic->GetTopLevelSheet();
290 wxString dest = wxFileName::CreateTempFileName( wxT(
"kicad_qa_sch_imgscale" ) );
291 wxRemoveFile( dest );
292 dest += wxT(
".kicad_sch" );
297 std::ifstream file( dest.ToStdString() );
298 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
300 wxRemoveFile( dest );
303 BOOST_CHECK_CLOSE( written, originalScale * legacyPPI / ppi, 0.1 );
305 0.5 * legacyPPI / ppi, 0.1 );
315 std::unique_ptr<SCHEMATIC> schematic;
356 for(
int style = 1; style <= 3; ++style )
359 pin->SetNumber( wxT(
"1" ) );
360 pin->SetName( wxT(
"SIGNAL" ) );
361 pin->SetBodyStyle( style );
364 pin->SetCustomProperty( wxT(
"Role" ), wxT(
"Signal" ) );
368 for(
bool inLibrary : {
false,
true } )
421 for(
int style = 1; style <= 3; ++style )
435 locked->SetLocked(
true );
439 textbox->
SetText( wxT(
"Hatched text box" ) );
443 aScreen.
Append( textbox );
454 group->AddItem( third );
455 group->AddItem( textbox );
468 bool aDropInsteadOfApproximate )
473 { wxT(
"Selected custom body styles" ), 20250827, DOWNGRADE_BUCKET::LOWER },
474 { wxT(
"Locked items" ), 20260326, DOWNGRADE_BUCKET::LOWER },
475 { wxT(
"Ellipse graphics" ), 20260508, DOWNGRADE_BUCKET::LOWER },
476 { wxT(
"Hatched shape fills" ), 20250222, DOWNGRADE_BUCKET::LOWER },
477 { wxT(
"Pin-to-pad maps" ), 20260629, DOWNGRADE_BUCKET::DROP },
478 { wxT(
"Groups" ), 20250513, DOWNGRADE_BUCKET::LOWER },
479 { wxT(
"Jumper pin groups" ), 20250324, DOWNGRADE_BUCKET::DROP },
480 { wxT(
"Named body styles" ), 20250827, DOWNGRADE_BUCKET::DROP },
481 { wxT(
"Position file exclusions" ), 20260101, DOWNGRADE_BUCKET::DROP },
482 { wxT(
"Rounded rectangles" ), 20250829, DOWNGRADE_BUCKET::LOWER },
483 { wxT(
"Rule area flags" ), 20250610, DOWNGRADE_BUCKET::DROP },
484 { wxT(
"Line endings" ), 20260818, DOWNGRADE_BUCKET::LOWER },
485 { wxT(
"Custom user properties" ), 20260830, DOWNGRADE_BUCKET::DROP },
487 aDropInsteadOfApproximate );
492 const std::string& aTokenFileName )
497 for(
bool drop : {
false,
true } )
502 std::unique_ptr<SCHEMATIC> schematic;
513 const std::string src = ( tmp.
GetPath() /
"source.kicad_sch" ).string();
526 reporter.GetMessages().ToStdString() );
529 const std::string dest = ( tmp.
GetPath() /
"export/source.kicad_sch" ).string();
533 for(
const std::string& token : unsupported )
534 BOOST_ERROR(
"Transformed schematic uses unknown token: " + token );
536 BOOST_CHECK( content.find(
"(version " + std::to_string( aTarget.
m_schVersion ) +
")" )
537 != std::string::npos );
540 std::ifstream outputFile( dest );
570 return child->GetChild( 1 )->GetString();
573 throw std::runtime_error(
"Missing netlist field " + aHead );
580 auto root = parser.
Parse( aText );
594 const std::string netClass =
netlistValue( *net,
"class" );
603 std::array<std::string, 4>{ name, netClass, netlistValue( *node,
"pinfunction" ),
604 netlistValue( *node,
"pintype" ) } )
607 throw std::runtime_error(
"Duplicate reference/pin in golden netlist" );
618 bool aDropInsteadOfApproximate =
false )
629 const std::string output = ( tmp.
GetPath() /
"export/body_styles.kicad_sch" ).string();
641 if( aRelease ==
"v10" )
644 const std::string difference =
646 BOOST_CHECK_MESSAGE( difference.empty(), difference );
656 std::ifstream outputFile( output );
658 schematic->RootScreen()->SetFileName( output );
659 SCH_SHEET_LIST sheets = schematic->BuildSheetListSortedByPageNumbers();
660 schematic->ConnectionGraph()->Recalculate( sheets,
true );
671 if( aRelease ==
"v9" )
673 for(
auto& [key, connection] : expectedConnections )
675 if( !connection[2].
empty() )
676 connection[2] +=
"_" + key.second;
680 if( aRelease ==
"v9" && aDropInsteadOfApproximate )
683 expectedConnections.erase( {
"U1",
"1" } );
684 expectedConnections.erase( {
"U1",
"2" } );
687 BOOST_REQUIRE_EQUAL( expectedConnections.size(), aRelease ==
"v9" && aDropInsteadOfApproximate ? 3 : 5 );
688 BOOST_CHECK( actualConnections == expectedConnections );
693 std::unique_ptr<SCHEMATIC> reference;
695 std::map<KIID, SCH_SYMBOL*> expectedSymbols;
697 expectedSymbols.emplace( item->m_Uuid,
static_cast<SCH_SYMBOL*
>( item ) );
713 BOOST_CHECK(
pin->m_Uuid == expectedPin->
m_Uuid );
720 std::vector<const SCH_SHAPE*> shapes;
721 for(
const SCH_ITEM& drawing : aSymbol->GetLibSymbolRef()->GetDrawItems() )
724 && ( !drawing.GetBodyStyle() || drawing.GetBodyStyle() == aSymbol->GetBodyStyle() ) )
726 shapes.push_back(
static_cast<const SCH_SHAPE*
>( &drawing ) );
732 const auto shapes = activeShapes( symbol );
733 const auto expectedShapes = activeShapes(
expected );
734 BOOST_REQUIRE_EQUAL( shapes.size(), expectedShapes.size() );
735 for(
size_t i = 0; i < shapes.size(); ++i )
737 BOOST_CHECK( shapes[i]->GetShape() == expectedShapes[i]->GetShape() );
738 BOOST_CHECK( shapes[i]->GetStart() == expectedShapes[i]->GetStart() );
739 BOOST_CHECK( shapes[i]->GetEnd() == expectedShapes[i]->GetEnd() );
740 BOOST_CHECK_EQUAL( shapes[i]->GetStroke().GetWidth(), expectedShapes[i]->GetStroke().GetWidth() );
741 BOOST_CHECK( shapes[i]->GetStroke().GetLineStyle() == expectedShapes[i]->GetStroke().GetLineStyle() );
742 BOOST_CHECK( shapes[i]->GetStroke().GetColor() == expectedShapes[i]->GetStroke().GetColor() );
743 BOOST_CHECK( shapes[i]->GetFillMode() == expectedShapes[i]->GetFillMode() );
747 BOOST_CHECK_EQUAL( checked, aRelease ==
"v9" && aDropInsteadOfApproximate ? 2 : 3 );
757 const wxString dest = ( tmp.
GetPath() /
"metadata.kicad_sym" ).wstring();
758 const wxString src = wxString::FromUTF8(
downgradeDataPath() +
"golden/current/metadata.kicad_sym" );
761 std::vector<LIB_SYMBOL*> symbols;
763 BOOST_REQUIRE_EQUAL( symbols.size(), 3 );
765 std::stable_sort( symbols.begin(), symbols.end(),
768 return a->GetInheritanceDepth() < b->GetInheritanceDepth();
777 downgradeDataPath() +
"golden/" + aRelease +
"/metadata.kicad_sym", dest.ToStdString() );
778 BOOST_CHECK_MESSAGE( difference.empty(), difference );
821 const std::string fixture =
downgradeDataPath() +
"regressions/bus_alias_connectivity/";
822 const std::string
source = fixture +
"prefix_bus_alias.kicad_sch";
831 reporter.GetMessages().ToStdString() );
833 const std::string
project = ( tmp.
GetPath() /
"export/prefix_bus_alias.kicad_pro" ).string();
836 BOOST_CHECK( document.at(
"schematic" ).at(
"bus_aliases" ).at(
"Bus1" )
837 == nlohmann::json( {
"D[0..7]",
"CTL1",
"CTL2" } ) );
839 wxFileName output( ( tmp.
GetPath() /
"export/prefix_bus_alias.kicad_sch" ).string() );
842 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
843 std::map<std::pair<std::string, std::string>, wxString> connections;
850 const std::string reference = symbol->
GetRef( &sheet ).ToStdString();
857 BOOST_CHECK( !connection->
Name().IsEmpty() );
859 .emplace( std::make_pair( reference,
pin->GetNumber().ToStdString() ),
866 BOOST_REQUIRE_EQUAL( connections.size(), 20 );
867 std::set<wxString> netNames;
871 const std::string number = std::to_string(
pin );
872 const auto& first = connections.at( {
"J1", number } );
873 const auto& second = connections.at( {
"J2", number } );
874 BOOST_CHECK( first == second );
875 netNames.insert( first );
889 for(
bool baseExcluded : {
false,
true } )
894 const std::string
source = ( tmp.
GetPath() /
"variant.kicad_sch" ).string();
898 BOOST_REQUIRE_EQUAL( paths.size(), 1 );
899 auto symbols = paths[0].LastScreen()->Items().OfType(
SCH_SYMBOL_T );
900 BOOST_REQUIRE_EQUAL( std::distance( symbols.begin(), symbols.end() ), 1 );
908 m_schematic->AddVariant( variant.
m_Name );
912 BOOST_REQUIRE( original.find(
"(variant" ) != std::string::npos );
922 BOOST_CHECK( !std::filesystem::exists( tmp.
GetPath() /
"base-preview" ) );
931 const int selectedDrops = baseExcluded ? 1 : 2;
936 BOOST_CHECK( !std::filesystem::exists( tmp.
GetPath() /
"selected" ) );
941 reporter.GetMessages().ToStdString() );
943 BOOST_CHECK( std::filesystem::exists( tmp.
GetPath() /
"selected/variant.kicad_sch" ) );
945 BOOST_CHECK( !std::filesystem::exists( tmp.
GetPath() /
"variant.kicad_pro" ) );
959 const std::string
source = ( tmp.
GetPath() /
"variant.kicad_sch" ).string();
960 const std::string childSource = ( tmp.
GetPath() /
"shared.kicad_sch" ).string();
963 SCH_SHEET* root = m_schematic->GetTopLevelSheet( 0 );
966 BOOST_REQUIRE_EQUAL( std::distance( symbols.begin(), symbols.end() ), 1 );
968 SCH_SHEET_PATH rootPath = m_schematic->BuildUnorderedSheetList()[0];
974 first->
SetName( wxT(
"First" ) );
975 second->
SetName( wxT(
"Second" ) );
984 m_schematic->RefreshHierarchy();
986 BOOST_REQUIRE_EQUAL( paths.size(), 3 );
991 if(
path.LastScreen() != sharedScreen )
994 path.SetPageNumber( wxString::Format( wxT(
"%d" ), reference + 1 ) );
997 instance.
m_Reference = wxString::Format( wxT(
"TP%d" ), reference++ );
1000 if(
path.Last() == first )
1004 variant.
m_DNP =
true;
1009 BOOST_REQUIRE_EQUAL( reference, 3 );
1010 m_schematic->AddVariant( wxT(
"V1" ) );
1020 for(
bool dryRun : {
true,
false } )
1032 BOOST_CHECK( !std::filesystem::exists( tmp.
GetPath() /
"out" ) );
1035 BOOST_CHECK( !std::filesystem::exists( tmp.
GetPath() /
"variant.kicad_pro" ) );
1057 BOOST_CHECK( std::filesystem::is_empty( tmp.
GetPath() ) );
1060 BOOST_CHECK( std::filesystem::is_empty( tmp.
GetPath() ) );
1069 const auto existing = tmp.
GetPath() /
"existing";
1071 std::filesystem::copy_file( fixture,
source );
1072 std::filesystem::create_directory( existing );
1073 std::filesystem::copy_file( fixture, existing /
source.filename() );
1078 for(
bool drop : {
false,
true } )
1093 BOOST_CHECK_EQUAL( std::distance( std::filesystem::directory_iterator( existing ),
1094 std::filesystem::directory_iterator() ),
1113 BOOST_CHECK( std::filesystem::is_empty( tmp.
GetPath() ) );
1117 const std::string output = ( tmp.
GetPath() /
"export/position_exclusion.kicad_sch" ).string();
1125 const std::string fixture =
downgradeDataPath() +
"regressions/incomplete_hierarchy/";
1126 for(
int failure = 0; failure < 3; ++failure )
1129 for(
const std::string&
name :
1130 {
"project.kicad_pro",
"project.kicad_sch",
"sibling.kicad_sch",
"broken.kicad_sch" } )
1133 if( ( failure >= 1 &&
name ==
"broken.kicad_sch" ) || ( failure == 2 &&
name ==
"sibling.kicad_sch" ) )
1140 for(
bool dryRun : {
false,
true } )
1151 BOOST_CHECK( !std::filesystem::exists( tmp.
GetPath() /
"out" ) );
1161 std::vector<const SEXPR::SEXPR*> nodes;
1164 if( !node.IsList() )
1167 nodes.push_back( &node );
1188 std::unique_ptr<SCHEMATIC> schematic;
1195 schematic->RootScreen()->Append(
new SCH_SHAPE( polygon ) );
1198 schematic->RootScreen()->AddLibSymbol( lib );
1199 const std::string libraryPath = ( tmp.
GetPath() /
"polygon.kicad_sym" ).string();
1200 const std::string schematicPath = ( tmp.
GetPath() /
"polygon.kicad_sch" ).string();
1203 for(
const auto&
path : { libraryPath, schematicPath } )
1207 const auto polylines =
rawNodes( *root,
"polyline" );
1209 size_t closedCount = 0;
1210 for(
const auto* polyline : polylines )
1213 if( !points || points->GetNumberOfChildren() < 4 )
1215 BOOST_REQUIRE_EQUAL( points->GetNumberOfChildren(), 5 );
1216 const auto* first = points->GetChild( 1 );
1217 const auto* last = points->GetChild( 4 );
1237 const std::string
path = ( tmp.
GetPath() /
"bold.kicad_sym" ).string();
1241 auto widths =
rawNodes( *root,
"thickness" );
1242 BOOST_REQUIRE_EQUAL( widths.size(), 1 );
1243 BOOST_CHECK_CLOSE(
rawNumber( *widths.front()->GetChild( 1 ) ), 160000.0 /
schIUScale.IU_PER_MM, 0.00001 );
1257 auto outlineWidths =
rawNodes( *outlined,
"thickness" );
1258 BOOST_REQUIRE_EQUAL( outlineWidths.size(), 1 );
1259 BOOST_CHECK_CLOSE(
rawNumber( *outlineWidths.front()->GetChild( 1 ) ), 100000.0 /
schIUScale.IU_PER_MM,
1273 parent.
SetKeyWords( wxT(
"parent inherited keywords" ) );
1275 empty.SetParent( &parent );
1276 LIB_SYMBOL explicitKeywords( wxT(
"explicit_derived" ) );
1278 explicitKeywords.
SetKeyWords( wxT(
"child raw keywords" ) );
1281 const std::string
path = ( tmp.
GetPath() /
"derived.kicad_sym" ).string();
1289 BOOST_CHECK( reloadedExplicit->
GetRawKeyWords() == wxT(
"child raw keywords" ) );
1298 for(
size_t payloadSize : { size_t( 13 ), size_t( 4099 ) } )
1300 BOOST_TEST_CONTEXT(
"target=" << target.m_id.ToStdString() <<
" payload_size=" << payloadSize )
1304 std::unique_ptr<SCHEMATIC> schematic;
1308 auto attachment = std::make_shared<EMBEDDED_FILES::EMBEDDED_FILE>();
1309 attachment->name = wxT(
"nonaligned.bin" );
1311 for(
size_t i = 0; i < payloadSize; ++i )
1312 attachment->decompressedData.push_back(
static_cast<char>( ( i * 131 + i / 251 ) % 256 ) );
1316 const auto originalPayload = attachment->decompressedData;
1317 const std::string originalEncoded = attachment->compressedEncodedData;
1318 const std::string originalHash = attachment->data_hash;
1320 legacyHash.
addDataV1(
reinterpret_cast<const uint8_t*
>( originalPayload.data() ),
1321 originalPayload.size() );
1323 BOOST_REQUIRE_NE( expectedHash, originalHash );
1325 schematic->GetEmbeddedFiles()->AddFile( attachment );
1329 schematic->RootScreen()->AddLibSymbol( lib );
1331 auto checkSourceUnchanged = [&]()
1333 BOOST_CHECK( attachment->decompressedData == originalPayload );
1336 BOOST_CHECK( attachment->is_valid );
1339 auto checkSerializedChecksum = [&](
const std::string&
path,
size_t expectedCount )
1342 const std::string checksum =
"(checksum \"" + expectedHash +
"\")";
1345 for(
size_t pos = content.find( checksum ); pos != std::string::npos;
1346 pos = content.find( checksum, pos + checksum.size() ) )
1352 BOOST_CHECK( content.find(
"(checksum \"" + originalHash +
"\")" ) == std::string::npos );
1355 auto checkReloadedAttachment = [&](
const EMBEDDED_FILES& files )
1357 auto* reloaded = files.GetEmbeddedFile( attachment->name );
1359 BOOST_CHECK( reloaded->Validate() );
1360 BOOST_CHECK( reloaded->decompressedData == originalPayload );
1365 const std::string libraryPath = ( tmp.
GetPath() /
"attached_symbol.kicad_sym" ).string();
1366 const std::string schematicPath = ( tmp.
GetPath() /
"attached_schematic.kicad_sch" ).string();
1368 checkSourceUnchanged();
1369 checkSerializedChecksum( libraryPath, 1 );
1376 checkSourceUnchanged();
1377 checkSerializedChecksum( schematicPath, 2 );
1378 std::ifstream outputFile( schematicPath );
1381 checkReloadedAttachment( *reloadedSchematic->GetEmbeddedFiles() );
1382 const auto& reloadedCache = reloadedSchematic->RootScreen()->GetLibSymbols();
1383 const auto cachedSymbol = reloadedCache.find( cacheKey );
1385 checkReloadedAttachment( *cachedSymbol->second->GetEmbeddedFiles() );
1386 checkSourceUnchanged();
constexpr EDA_IU_SCALE schIUScale
int GetLegacyPPI() const
Recompute the PPI the way it was computed before the pixels/cm truncation fix.
What an export to a given target will keep, approximate, drop, or block.
bool IsLossy() const
True if anything is approximated or dropped. This is what triggers the lossy warning.
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
int Count(DOWNGRADE_BUCKET aBucket) const
void SetCustomProperty(const wxString &aKey, const wxString &aValue)
virtual void SetEnd(const VECTOR2I &aEnd)
void SetEndEnding(const LINE_ENDING &aEnding)
virtual void SetCornerRadius(int aRadius)
SHAPE_POLY_SET & GetPolyShape()
virtual void SetEllipseEndAngle(const EDA_ANGLE &aA)
virtual void SetEllipseCenter(const VECTOR2I &aPt)
virtual void SetEllipseMinorRadius(int aR)
virtual void SetEllipseMajorRadius(int aR)
virtual void SetEllipseStartAngle(const EDA_ANGLE &aA)
void SetPolyPoints(const std::vector< VECTOR2I > &aPoints)
void SetFillMode(FILL_T aFill)
virtual void SetStart(const VECTOR2I &aStart)
virtual void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
virtual int GetTextThickness() const
virtual void SetText(const wxString &aText)
void SetFont(KIFONT::FONT *aFont)
Handle Eeschema job dispatches.
int JobDowngrade(JOB *aJob)
EE_TYPE OfType(KICAD_T aType) const
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
static RETURN_CODE CompressAndEncode(EMBEDDED_FILE &aFile)
Take data from the decompressedData buffer and compresses it using ZSTD into the compressedEncodedDat...
Container for ERC settings.
void SetReporter(REPORTER *aReporter)
std::vector< wxString > m_foundVariants
Variant names found in the schematic when the target drops variants.
wxString m_outputDir
Write downgraded sheets under this fresh folder.
wxString m_variant
Flatten this variant into the export. Empty means the base design.
bool m_inPlace
Internal only: convert the coordinator's already-copied export files.
bool m_dryRun
Only classify and fill m_report, do not write anything.
wxString m_filename
Root schematic file (may be empty to downgrade only libraries)
COMPATIBILITY_REPORT m_report
Filled by the handler so the caller can show it.
wxString m_target
Target release name or id, e.g. "KiCad 10.0" or "10.0". Empty means the newest.
bool m_dropInsteadOfApproximate
Omit features that would otherwise be approximated.
bool m_force
Export even when features must be dropped or approximated.
FONT is an abstract base class for both outline and stroke fonts.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
virtual bool IsStroke() const
std::string AsStdString() const
A generic fixture for loading schematics and associated settings for qa tests.
A temporary directory deleted when it goes out of scope.
const std::filesystem::path & GetPath() const
A logical library item identifier and consists of various portions much like a URI.
Define a library symbol object.
const wxString & GetRawKeyWords() const
Return only this symbol's keywords, without inheriting from its parent.
const LIB_ID & GetLibId() const override
wxString GetKeyWords() const override
void SetDuplicatePinNumbersAreJumpers(bool aEnabled)
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
void SetAssociatedFootprints(std::vector< ASSOCIATED_FOOTPRINT > aList)
void SetBodyStyleNames(const std::vector< wxString > &aBodyStyleNames)
void SetParent(LIB_SYMBOL *aParent=nullptr)
wxString GetName() const override
void SetKeyWords(const wxString &aKeyWords)
EMBEDDED_FILES * GetEmbeddedFiles() override
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Decorative shape (arrowhead, circle, square) at the start or end of a graphic line,...
A streaming C++ equivalent for MurmurHash3_x64_128.
FORCE_INLINE void addDataV1(const uint8_t *data, size_t length)
FORCE_INLINE HASH_128 digest()
Generate the KiCad netlist format supported by Pcbnew.
void Format(OUTPUTFORMATTER *aOutputFormatter, int aCtl)
Output this s-expression netlist into aOutputFormatter.
The backing store for a PROJECT, in JSON format.
ERC_SETTINGS * m_ErcSettings
Eeschema params.
SCHEMATIC_SETTINGS * m_SchematicSettings
Container for project specific data.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
void SetImageScale(double aScale)
Set the image "zoom" value.
A pure virtual class used to derive REPORTER objects from.
These are loaded from Eeschema settings but then overwritten by the project settings.
Object to handle a bitmap image that can be inserted in a schematic.
REFERENCE_IMAGE & GetReferenceImage()
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString Name(bool aIgnoreSheet=false) const
A set of SCH_ITEMs (i.e., without duplicates).
A SCH_IO derivation for loading schematic files using the new s-expression file format.
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Segment description base class to describe items which have 2 end points (track, wire,...
void SetEndEnding(const LINE_ENDING &aEnding)
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
void SetEndPoint(const VECTOR2I &aPosition)
const wxString & GetName() const
VECTOR2I GetPosition() const override
void SetDNP(bool aDNP, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void SetExcludedFromSim(bool aExcludeFromSim, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from simulation flag.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
const KIID & GetUuid() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
void SetStroke(const STROKE_PARAMS &aStroke) override
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetFileName(const wxString &aFilename)
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Variant information for a schematic symbol.
void InitializeAttributes(const SCH_SYMBOL &aSymbol)
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
void RemoveInstance(const SCH_SHEET_PATH &aInstancePath)
std::optional< SCH_SYMBOL_VARIANT > GetVariant(const SCH_SHEET_PATH &aInstance, const wxString &aVariantName) const
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
VECTOR2I GetPosition() const override
void SetExcludedFromPosFiles(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void AddVariant(const SCH_SHEET_PATH &aInstance, const SCH_SYMBOL_VARIANT &aVariant)
int GetOrientation() const override
Get the display symbol orientation.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
std::unique_ptr< SEXPR > Parse(const std::string &aString)
SEXPR_VECTOR const * GetChildren() const
int64_t GetLongInteger() const
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
Simple container to manage line stroke parameters.
void SetExcludedFromPosFiles(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear exclude from position files flag.
bool m_ExcludedFromPosFiles
A wrapper for reporting to a wxString object.
@ LOWER
Approximated down to a simpler equivalent.
@ DROP
No equivalent, left out.
static bool empty(const wxTextEntryBase *aCtrl)
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
static const int ERR_ARGS
static const int ERR_INVALID_INPUT_FILE
static const int ERR_UNKNOWN
Test utilities for timestamps.
std::unique_ptr< SCHEMATIC > ReadSchematicFromStream(std::istream &aStream, PROJECT *aProject)
std::string GoldenNodeHead(const SEXPR::SEXPR &aNode)
std::set< std::string > LoadTokenSet(const std::string &aFileName)
Read a release keyword file from qa/data/downgrade, one token per line.
std::string GoldenFileDifference(const std::string &aExpected, const std::string &aActual)
std::string ReadGoldenText(const std::string &aPath)
void CheckTransformCoverage(const COMPATIBILITY_REPORT &aReport, int aTargetVersion, std::initializer_list< EXPECTED_DOWNGRADE_FEATURE > aFeatures, bool aDropInsteadOfApproximate)
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
const SEXPR::SEXPR * FindGoldenChild(const SEXPR::SEXPR &aNode, const std::string &aHead)
wxMemoryBuffer MakePngWithFractionalPixelsPerCm()
A tiny PNG whose embedded resolution gives a fractional pixels/cm, so the legacy truncating PPI diffe...
double SerializedImageScale(const std::string &aContent, const std::string &aUuid)
std::vector< std::string > UnknownSexprHeads(const std::string &aContent, const std::set< std::string > &aKnown, const std::set< std::string > &aHarmless={})
Every node head in the serialized text that is not in the known or harmless sets.
void DowngradeScreenInPlace(SCH_SCREEN *aScreen, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Approximate or remove, in place, what the target cannot represent.
bool FlattenSchematicVariant(SCHEMATIC &aSchematic, const wxString &aVariantName, wxString *aConflict)
Bake a variant into the base attributes of every symbol and sheet.
void SaveSymbolLibraryForTarget(const std::vector< LIB_SYMBOL * > &aSymbols, const wxString &aPath, const DOWNGRADE_TARGET &aTarget)
Save a .kicad_sym library stamped for the target.
void DowngradeLibSymbolInPlace(LIB_SYMBOL *aSymbol, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Symbol-scoped downgrade for standalone .kicad_sym files the screen pass never sees.
void SaveSchematicForTarget(SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const wxString &aPath, const DOWNGRADE_TARGET &aTarget)
Save a schematic sheet file stamped for the target, using the writer for that version.
COMPATIBILITY_REPORT ClassifyScreenForDowngrade(const SCH_SCREEN *aScreen, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Report what a schematic screen would lose if exported to an older KiCad.
Class to handle a set of SCH_ITEMs.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName)
An older KiCad release we can export a project back to.
int m_schVersion
SEXPR_SCHEMATIC_FILE_VERSION for the target.
wxString m_id
Stable machine key for CLI and jobsets, e.g. "10.0".
std::string ToString() const
A simple container for schematic symbol instance information.
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
VECTOR3I expected(15, 30, 45)
static const DOWNGRADE_TARGET & kicad10
static const DOWNGRADE_TARGET & kicad9
static std::vector< const SEXPR::SEXPR * > rawNodes(const SEXPR::SEXPR &aRoot, const std::string &aHead)
static int runDowngradeJob(JOB_SCH_DOWNGRADE &aJob, REPORTER &aReporter)
static void checkNativeSymbolLibraryGolden(const DOWNGRADE_TARGET &aTarget, const std::string &aRelease)
static GOLDEN_NET_CONNECTIONS netlistConnections(const std::string &aText)
static void checkExportUsesOnlyKnownTokens(const DOWNGRADE_TARGET &aTarget, const std::string &aTokenFileName)
static void checkNativeSchematicGolden(const DOWNGRADE_TARGET &aTarget, const std::string &aRelease, bool aDropInsteadOfApproximate=false)
static SCH_BITMAP * addTransformFeatures(SCH_SCREEN &aScreen)
static void checkSchematicTransformCoverage(const COMPATIBILITY_REPORT &aReport, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
static std::string downgradeDataPath()
BOOST_AUTO_TEST_CASE(SchToKicad9UsesOnlyKnownTokens)
BOOST_FIXTURE_TEST_CASE(StandaloneKicad10ExportKeepsProjectBusAliasConnectivity, KI_TEST::SCHEMATIC_TEST_FIXTURE)
static void checkTransformedSchematicUsesOnlyKnownTokens(const DOWNGRADE_TARGET &aTarget, const std::string &aTokenFileName)
static double rawNumber(const SEXPR::SEXPR &aNode)
static std::string netlistValue(const SEXPR::SEXPR &aNode, const std::string &aHead)
std::map< std::pair< std::string, std::string >, std::array< std::string, 4 > > GOLDEN_NET_CONNECTIONS
BOOST_TEST_CONTEXT("Test Clearance")
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I