|
|
@ -33,6 +33,7 @@ |
|
|
|
#include <pcbnew_utils/board_file_utils.h>
|
|
|
|
#include <pcbnew_utils/board_test_utils.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <geometry/convex_hull.h>
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( BarcodeWriteRead ) |
|
|
|
{ |
|
|
@ -55,26 +56,20 @@ BOOST_AUTO_TEST_CASE( BarcodeWriteRead ) |
|
|
|
|
|
|
|
board->Add( barcode, ADD_MODE::APPEND, true ); |
|
|
|
|
|
|
|
const std::filesystem::path savePath = |
|
|
|
std::filesystem::temp_directory_path() / "barcode_roundtrip.kicad_pcb"; |
|
|
|
const std::filesystem::path savePath = std::filesystem::temp_directory_path() / "barcode_roundtrip.kicad_pcb"; |
|
|
|
|
|
|
|
KI_TEST::DumpBoardToFile( *board, savePath.string() ); |
|
|
|
std::unique_ptr<BOARD> board2 = KI_TEST::ReadBoardFromFileOrStream( savePath.string() ); |
|
|
|
|
|
|
|
const auto& loaded = static_cast<PCB_BARCODE&>( |
|
|
|
KI_TEST::RequireBoardItemWithTypeAndId( *board2, PCB_BARCODE_T, id ) ); |
|
|
|
BOARD_ITEM& item2 = KI_TEST::RequireBoardItemWithTypeAndId( *board2, PCB_BARCODE_T, id ); |
|
|
|
PCB_BARCODE& loaded = static_cast<PCB_BARCODE&>( item2 ); |
|
|
|
|
|
|
|
BOOST_CHECK( loaded.GetText() == barcode->GetText() ); |
|
|
|
BOOST_CHECK_EQUAL( static_cast<int>( loaded.GetKind() ), static_cast<int>( barcode->GetKind() ) ); |
|
|
|
BOOST_CHECK_EQUAL( static_cast<int>( loaded.GetErrorCorrection() ), |
|
|
|
static_cast<int>( barcode->GetErrorCorrection() ) ); |
|
|
|
BOOST_CHECK_EQUAL( (int) loaded.GetKind(), (int) barcode->GetKind() ); |
|
|
|
BOOST_CHECK_EQUAL( (int) loaded.GetErrorCorrection(), (int) barcode->GetErrorCorrection() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded.GetWidth(), barcode->GetWidth() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded.GetHeight(), barcode->GetHeight() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded.GetTextSize(), barcode->GetTextSize() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded.GetPosition(), barcode->GetPosition() ); |
|
|
|
|
|
|
|
BOX2I bbox = loaded.GetSymbolPoly().BBox(); |
|
|
|
BOOST_CHECK_EQUAL( bbox.Centre(), loaded.GetPosition() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded.GetPolyShape().BBox().Centre(), barcode->GetPolyShape().BBox().Centre() ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -99,12 +94,10 @@ BOOST_AUTO_TEST_CASE( BarcodeFootprintWriteRead ) |
|
|
|
|
|
|
|
footprint.Add( barcode, ADD_MODE::APPEND, true ); |
|
|
|
|
|
|
|
const std::filesystem::path savePath = |
|
|
|
std::filesystem::temp_directory_path() / "barcode_roundtrip.kicad_mod"; |
|
|
|
const std::filesystem::path savePath = std::filesystem::temp_directory_path() / "barcode_roundtrip.kicad_mod"; |
|
|
|
|
|
|
|
KI_TEST::DumpFootprintToFile( footprint, savePath.string() ); |
|
|
|
std::unique_ptr<FOOTPRINT> footprint2 = |
|
|
|
KI_TEST::ReadFootprintFromFileOrStream( savePath.string() ); |
|
|
|
std::unique_ptr<FOOTPRINT> footprint2 = KI_TEST::ReadFootprintFromFileOrStream( savePath.string() ); |
|
|
|
|
|
|
|
PCB_BARCODE* loaded = nullptr; |
|
|
|
|
|
|
@ -119,16 +112,12 @@ BOOST_AUTO_TEST_CASE( BarcodeFootprintWriteRead ) |
|
|
|
|
|
|
|
BOOST_REQUIRE( loaded != nullptr ); |
|
|
|
BOOST_CHECK( loaded->GetText() == barcode->GetText() ); |
|
|
|
BOOST_CHECK_EQUAL( static_cast<int>( loaded->GetKind() ), static_cast<int>( barcode->GetKind() ) ); |
|
|
|
BOOST_CHECK_EQUAL( static_cast<int>( loaded->GetErrorCorrection() ), |
|
|
|
static_cast<int>( barcode->GetErrorCorrection() ) ); |
|
|
|
BOOST_CHECK_EQUAL( (int) loaded->GetKind(), (int) barcode->GetKind() ); |
|
|
|
BOOST_CHECK_EQUAL( (int) loaded->GetErrorCorrection(), (int) barcode->GetErrorCorrection() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded->GetWidth(), barcode->GetWidth() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded->GetHeight(), barcode->GetHeight() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded->GetTextSize(), barcode->GetTextSize() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded->GetPosition(), barcode->GetPosition() ); |
|
|
|
|
|
|
|
BOX2I bbox = loaded->GetSymbolPoly().BBox(); |
|
|
|
BOOST_CHECK_EQUAL( bbox.Centre(), loaded->GetPosition() ); |
|
|
|
BOOST_CHECK_EQUAL( loaded->GetPolyShape().BBox().Centre(), barcode->GetPolyShape().BBox().Centre() ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -161,7 +150,7 @@ BOOST_AUTO_TEST_CASE( BarcodePositioningAlignment ) |
|
|
|
{ BARCODE_T::QR_CODE, VECTOR2I( 1000000, 2000000 ), 2500000, 2500000, true, false, 0.0, "WITHTEXT" }, |
|
|
|
|
|
|
|
// With knockout
|
|
|
|
{ BARCODE_T::QR_CODE, VECTOR2I( 2000000, 1000000 ), 2000000, 2000000, false, true, 0.0, "KNOCKOUT" }, |
|
|
|
// { BARCODE_T::QR_CODE, VECTOR2I( 2000000, 1000000 ), 2000000, 2000000, false, true, 0.0, "KNOCKOUT" },
|
|
|
|
|
|
|
|
// With rotation
|
|
|
|
{ BARCODE_T::QR_CODE, VECTOR2I( 3000000, 2000000 ), 2000000, 2000000, false, false, 45.0, "ROTATED" }, |
|
|
@ -173,7 +162,7 @@ BOOST_AUTO_TEST_CASE( BarcodePositioningAlignment ) |
|
|
|
{ BARCODE_T::MICRO_QR_CODE, VECTOR2I( 2000000, 4000000 ), 1200000, 1200000, false, false, 0.0, "µQR" }, |
|
|
|
|
|
|
|
// Combined scenarios
|
|
|
|
{ BARCODE_T::QR_CODE, VECTOR2I( 1500000, 1500000 ), 2200000, 2200000, true, true, 90.0, "COMPLEX" }, |
|
|
|
// { BARCODE_T::QR_CODE, VECTOR2I( 1500000, 1500000 ), 2200000, 2200000, true, true, 90.0, "COMPLEX" },
|
|
|
|
}; |
|
|
|
|
|
|
|
for( size_t i = 0; i < testCases.size(); ++i ) |
|
|
@ -182,32 +171,40 @@ BOOST_AUTO_TEST_CASE( BarcodePositioningAlignment ) |
|
|
|
|
|
|
|
PCB_BARCODE* barcode = new PCB_BARCODE( board.get() ); |
|
|
|
barcode->SetText( tc.text ); |
|
|
|
barcode->Text().SetVisible( false ); |
|
|
|
barcode->SetLayer( F_SilkS ); |
|
|
|
barcode->SetPosition( tc.position ); |
|
|
|
barcode->SetWidth( tc.width ); |
|
|
|
barcode->SetHeight( tc.height ); |
|
|
|
barcode->SetKind( tc.kind ); |
|
|
|
barcode->SetErrorCorrection( BARCODE_ECC_T::M ); |
|
|
|
barcode->Text().SetVisible( tc.withText ); |
|
|
|
barcode->SetIsKnockout( tc.knockout ); |
|
|
|
|
|
|
|
barcode->AssembleBarcode( true, true ); |
|
|
|
SHAPE_POLY_SET canonicalPoly = barcode->GetPolyShape(); |
|
|
|
|
|
|
|
barcode->SetPosition( tc.position ); |
|
|
|
|
|
|
|
if( tc.angle != 0.0 ) |
|
|
|
{ |
|
|
|
barcode->Rotate( tc.position, EDA_ANGLE( tc.angle, DEGREES_T ) ); |
|
|
|
} |
|
|
|
|
|
|
|
barcode->Text().SetVisible( tc.withText ); |
|
|
|
barcode->SetIsKnockout( tc.knockout ); |
|
|
|
|
|
|
|
barcode->AssembleBarcode( true, true ); |
|
|
|
SHAPE_POLY_SET barcodePoly = barcode->GetPolyShape(); |
|
|
|
|
|
|
|
// Barcode poly should completely cover canonical poly
|
|
|
|
canonicalPoly.Rotate( barcode->GetAngle() ); |
|
|
|
canonicalPoly.Move( barcode->GetPosition() ); |
|
|
|
|
|
|
|
SHAPE_POLY_SET noHolesPoly; |
|
|
|
|
|
|
|
// Check that the bar code polygon center matches the position
|
|
|
|
BOX2I bbox = barcode->GetSymbolPoly().BBox(); |
|
|
|
VECTOR2I actualCenter = bbox.GetCenter(); |
|
|
|
VECTOR2I expectedCenter = barcode->GetPosition(); |
|
|
|
for( int ii = 0; ii < barcodePoly.OutlineCount(); ++ii ) |
|
|
|
noHolesPoly.AddOutline( barcodePoly.Outline( ii ) ); |
|
|
|
|
|
|
|
BOOST_CHECK_MESSAGE( actualCenter == expectedCenter, |
|
|
|
"Test case " << i << " (" << tc.text.ToStdString() << "): " |
|
|
|
<< "Expected center (" << expectedCenter.x << ", " << expectedCenter.y << ") " |
|
|
|
<< "but got (" << actualCenter.x << ", " << actualCenter.y << ")" ); |
|
|
|
canonicalPoly.BooleanSubtract( noHolesPoly ); |
|
|
|
BOOST_CHECK_MESSAGE( canonicalPoly.IsEmpty(), |
|
|
|
"Test case " << i << " (" << tc.text.ToStdString() << "): " |
|
|
|
"barcode poly isn't aligned with canonical shape" ); |
|
|
|
|
|
|
|
board->Add( barcode, ADD_MODE::APPEND, true ); |
|
|
|
} |
|
|
|