20#include <boost/test/data/test_case.hpp>
45struct REFERENCE_IMAGE_LOAD_TEST_FIXTURE
47 REFERENCE_IMAGE_LOAD_TEST_FIXTURE() {}
51struct REFERENCE_IMAGE_LOAD_TEST_CASE
56 bool m_expectedLocked;
58 double m_expectedScale;
67 std::vector<REFERENCE_IMAGE_LOAD_TEST_CASE> m_imageCases;
70const std::vector<REFERENCE_IMAGE_LOAD_BOARD_TEST_CASE> ReferenceImageLoading_testCases{
72 "reference_images_load_save",
77 "7dde345e-020a-4fdd-af77-588b452be5e0",
84 "e4fd52dd-1d89-4c43-b621-aebfc9788d5c",
91 "d402397e-bce0-4cae-a398-b5aeef397e87",
104const std::vector<unsigned char> png_3780_ppm = {
105 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
106 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53,
107 0xDE, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0E, 0xC4, 0x00, 0x00, 0x0E,
108 0xC4, 0x01, 0x95, 0x2B, 0x0E, 0x1B, 0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41, 0x54, 0x78, 0xDA,
109 0x63, 0xF8, 0xCF, 0xC0, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0xF7, 0x03, 0x41, 0x43, 0x00, 0x00,
110 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82
114std::unique_ptr<BOARD> parseBoardString(
const std::string& aData )
119 return std::unique_ptr<BOARD>(
dynamic_cast<BOARD*
>( parser.Parse() ) );
123double firstImageScale(
const BOARD& aBoard )
138 boost::unit_test::data::make( ReferenceImageLoading_testCases ), testCase )
140 const auto doBoardTest = [&](
const BOARD& aBoard )
142 for(
const REFERENCE_IMAGE_LOAD_TEST_CASE& imageTestCase : testCase.m_imageCases )
145 "Checking for image with UUID: " << imageTestCase.m_imageUuid.
AsString() );
154 BOOST_CHECK_CLOSE( refImage.
GetImageScale(), imageTestCase.m_expectedScale, 1e-6 );
163 testCase.m_ExpectedBoardVersion );
173 const auto doBoardTest = [&](
const BOARD& aBoard )
175 KIID targetUuid(
"7dde345e-020a-4fdd-af77-588b452be5e0" );
222 m_board = std::make_unique<BOARD>();
230 template <
typename T>
233 wxMemoryBuffer buffer;
234 buffer.AppendData( aData.data(), aData.size() );
251 BOARD& board = GetBoard();
254 SetImageData( png_3780_ppm );
264 const std::string
path = ( std::filesystem::temp_directory_path()
265 /
"issue23575_ppi_migration.kicad_pcb" ).
string();
268 std::ifstream in(
path );
269 std::stringstream ss;
271 const std::string current = ss.str();
274 std::unique_ptr<BOARD> reloaded = parseBoardString( current );
276 BOOST_CHECK_CLOSE( firstImageScale( *reloaded ), 2.0, 1e-6 );
280 std::string legacy = current;
282 const size_t pos = legacy.find( version );
284 legacy.replace( pos, version.size(),
"20260512" );
286 std::unique_ptr<BOARD> migrated = parseBoardString( legacy );
288 BOOST_CHECK_CLOSE( firstImageScale( *migrated ), 2.0 * 96.0 / 94.0, 1e-3 );
298 BOARD& board = GetBoard();
301 SetImageData( png_3780_ppm );
330 BOARD& board = GetBoard();
335 wxImage raster( 42, 24 );
336 raster.SetRGB( wxRect( 0, 0, 42, 24 ), 0, 0, 0 );
General utilities for PCB file IO for QA programs.
This class handle bitmap images in KiCad.
VECTOR2I GetSizePixels() const
int GetLegacyPPI() const
Recompute the PPI the way it was computed before the pixels/cm truncation fix.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayer) const
const DRAWINGS & Drawings() const
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
constexpr const SizeVec & GetSize() const
wxString AsString() const
Read a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD_ITEM object...
Object to handle a bitmap image that can be inserted in a PCB.
double GetImageScale() const
std::unique_ptr< BOARD > m_board
REFERENCE_IMAGE_BOARD_FIXTURE()
PCB_REFERENCE_IMAGE & GetImage()
PCB_REFERENCE_IMAGE * m_image
void SetImageData(const T &aData)
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
EDA_ANGLE GetOrientation() const
bool Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
void Rotate(const VECTOR2I &aCenter, const EDA_ANGLE &aAngle)
Rotate the image about aCenter.
void SetTransformOriginOffset(const VECTOR2I &aCenter)
VECTOR2I GetTransformOriginOffset() const
Get the center of scaling, etc, relative to the image center (GetPosition()).
VECTOR2I GetPosition() const
bool SetImage(const wxImage &aImage)
Set the image from an existing wxImage.
void SetPosition(const VECTOR2I &aPos)
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
void SetImageScale(double aScale)
Set the image "zoom" value.
BOX2I GetBoundingBox() const
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_45
static constexpr EDA_ANGLE ANGLE_270
PCB_LAYER_ID
A quick note on layer IDs:
@ LEFT_RIGHT
Flip left to right (around the Y axis)
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
void LoadAndTestBoardFile(const wxString aRelativePath, bool aRoundtrip, std::function< void(BOARD &)> aBoardTestFunction, std::optional< int > aExpectedBoardVersion)
Perform "some test" on a board file loaded from the path, then optionally save and reload and run the...
void DumpBoardToFile(BOARD &board, const std::filesystem::path &aFilename)
Utility function to simply write a Board out to a file.
BOARD_ITEM & RequireBoardItemWithTypeAndId(const BOARD &aBoard, KICAD_T aItemType, const KIID &aID)
Get an item from the given board with a certain type and UUID.
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
Pcbnew s-expression file format parser definition.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(ReferenceImageFlipLayer, REFERENCE_IMAGE_LOAD_TEST_FIXTURE)
Test that flipping a reference image changes its associated layer, matching the behavior of all other...
BOOST_DATA_TEST_CASE_F(REFERENCE_IMAGE_LOAD_TEST_FIXTURE, ReferenceImageLoading, boost::unit_test::data::make(ReferenceImageLoading_testCases), testCase)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
VECTOR2< int32_t > VECTOR2I