48 TEMP_FILE_HOLDER(
const std::string& aPrefix,
const std::string& aSuffix )
50 std::filesystem::path dir = std::filesystem::temp_directory_path() / aPrefix;
51 std::filesystem::create_directories( dir );
52 m_path = dir / (
"board" + aSuffix );
58 std::filesystem::remove( m_path, ec );
59 std::filesystem::remove( m_path.parent_path(), ec );
62 const std::filesystem::path& Path()
const {
return m_path; }
65 std::filesystem::path m_path;
69int mm(
double aMillimetres )
79 if( prim->GetShape() == aShape )
96 for(
int ii = 0; ii < expOutline.
PointCount(); ++ii )
115 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
116 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( board.get() );
118 fp->SetReference(
"U1" );
122 fp->SetPosition(
VECTOR2I( mm( 50.0 ), mm( 25.0 ) ) );
124 fp->SetTransformScale( 2.0, 1.5 );
126 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( fp.get() );
128 pad->SetNumber(
"1" );
151 chain.SetClosed(
true );
167 const int expBezierWidth = bezier->
GetWidth();
169 const int expPolyWidth = poly->
GetWidth();
174 TEMP_FILE_HOLDER tmp(
"kicad_qa_custom_pad_primitive_roundtrip",
".kicad_pcb" );
180 FOOTPRINT* fpFound = reloaded->Footprints().empty() ? nullptr : reloaded->Footprints().front();
181 BOOST_REQUIRE_MESSAGE( fpFound,
"Footprint not found in reloaded board" );
182 BOOST_REQUIRE_MESSAGE( !fpFound->
Pads().empty(),
"Pad not found in reloaded footprint" );
184 PAD* padFound = fpFound->
Pads().front();
187 BOOST_REQUIRE_MESSAGE( bezierFound,
"Bezier primitive not found in reloaded pad" );
200 BOOST_REQUIRE_MESSAGE( polyFound,
"Polygon primitive not found in reloaded pad" );
210 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
211 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( board.get() );
213 fp->SetReference(
"U1" );
217 fp->SetPosition(
VECTOR2I( mm( 50.0 ), mm( 25.0 ) ) );
219 fp->SetTransformScale( 2.0, 1.5 );
221 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( fp.get() );
223 pad->SetNumber(
"1" );
241 circle->SetWidth( mm( 0.01 ) );
247 const int expSegWidth = seg->
GetWidth();
254 TEMP_FILE_HOLDER tmp(
"kicad_qa_custom_pad_primitive_roundtrip2",
".kicad_pcb" );
260 FOOTPRINT* fpFound = reloaded->Footprints().empty() ? nullptr : reloaded->Footprints().front();
261 BOOST_REQUIRE_MESSAGE( fpFound,
"Footprint not found in reloaded board" );
262 BOOST_REQUIRE_MESSAGE( !fpFound->
Pads().empty(),
"Pad not found in reloaded footprint" );
264 PAD* padFound = fpFound->
Pads().front();
267 BOOST_REQUIRE_MESSAGE( segFound,
"Segment primitive not found in reloaded pad" );
276 BOOST_REQUIRE_MESSAGE( circleFound,
"Elipse primitive not found in reloaded pad" );
287 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
288 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( board.get() );
289 fp->SetReference(
"U1" );
290 fp->SetPosition(
VECTOR2I( mm( 50.0 ), mm( 50.0 ) ) );
291 fp->SetTransformScale( 2.0, 1.5 );
293 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( fp.get() );
295 pad->SetNumber(
"1" );
302 TEMP_FILE_HOLDER tmp(
"kicad_qa_scaled_fp_roundtrip",
".kicad_pcb" );
307 FOOTPRINT* r = reloaded->Footprints().front();
308 BOOST_CHECK_CLOSE( r->
GetScaleX(), 2.0, 1e-6 );
309 BOOST_CHECK_CLOSE( r->
GetScaleY(), 1.5, 1e-6 );
315 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
316 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( board.get() );
317 fp->SetReference(
"U1" );
318 fp->SetPosition(
VECTOR2I( mm( 50.0 ), mm( 50.0 ) ) );
320 fp->SetTransformScale( 2.0, 1.5 );
322 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( fp.get() );
323 pad->SetNumber(
"1" );
328 pad->SetPosition(
VECTOR2I( mm( 53.0 ), mm( 51.0 ) ) );
337 TEMP_FILE_HOLDER tmp(
"kicad_qa_pad_pos_orient_roundtrip",
".kicad_pcb" );
342 PAD* r = reloaded->Footprints().front()->Pads().front();
351 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
352 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( board.get() );
353 fp->SetReference(
"U1" );
354 fp->SetPosition(
VECTOR2I( mm( 50.0 ), mm( 50.0 ) ) );
355 fp->SetTransformScale( 2.0, 1.5 );
357 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( fp.get() );
358 pad->SetNumber(
"1" );
370 TEMP_FILE_HOLDER tmp(
"kicad_qa_pad_delta_roundtrip",
".kicad_pcb" );
375 PAD* r = reloaded->Footprints().front()->Pads().front();
386 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
387 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( board.get() );
388 fp->SetReference(
"U1" );
389 fp->SetPosition(
VECTOR2I( mm( 50.0 ), mm( 50.0 ) ) );
390 fp->SetTransformScale( 2.0, 1.5 );
392 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( fp.get() );
394 pad->SetNumber(
"1" );
406 TEMP_FILE_HOLDER tmp(
"kicad_qa_pad_offset_roundtrip",
".kicad_pcb" );
411 PAD* r = reloaded->Footprints().front()->Pads().front();
422 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
423 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( board.get() );
424 fp->SetReference(
"U1" );
425 fp->SetPosition(
VECTOR2I( mm( 50.0 ), mm( 50.0 ) ) );
427 fp->SetTransformScale( 2.0, 1.5 );
429 std::unique_ptr<PCB_POINT> pt = std::make_unique<PCB_POINT>( fp.get() );
430 pt->SetLayer(
F_Cu );
431 pt->SetPosition(
VECTOR2I( mm( 55.0 ), mm( 52.0 ) ) );
438 TEMP_FILE_HOLDER tmp(
"kicad_qa_fp_point_roundtrip",
".kicad_pcb" );
443 FOOTPRINT* r = reloaded->Footprints().front();
455 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
456 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( board.get() );
457 fp->SetReference(
"U1" );
458 fp->SetPosition(
VECTOR2I( mm( 50.0 ), mm( 50.0 ) ) );
459 fp->SetTransformScale( 2.0, 1.5 );
461 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( fp.get() );
463 pad->SetNumber(
"1" );
475 TEMP_FILE_HOLDER tmp(
"kicad_qa_rotated_pad_roundtrip",
".kicad_pcb" );
480 PAD* r = reloaded->Footprints().front()->Pads().front();
505 pad->SetOrientation( aRelOrient );
constexpr EDA_IU_SCALE pcbIUScale
General utilities for PCB file IO for QA programs.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
constexpr size_type GetWidth() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
bool IsPolyShapeValid() const
LSET is a set of PCB_LAYER_IDs.
@ NORMAL
Shape is the same on all layers.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives(PCB_LAYER_ID aLayer) const
Accessor to the basic shape list for custom-shaped pads.
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
const VECTOR2I & GetDelta(PCB_LAYER_ID aLayer) const
VECTOR2I GetPosition() const override
VECTOR2I GetOffset(PCB_LAYER_ID aLayer) const
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
VECTOR2I GetPosition() const override
void SetBezierC1(const VECTOR2I &aPt) override
VECTOR2I GetLibraryBezierC1() const
void SetWidth(int aWidth) override
int GetWidth() const override
void SetShape(SHAPE_T aShape) override
void SetEnd(const VECTOR2I &aEnd) override
VECTOR2I GetLibraryEnd() const
void SetPolyShape(const SHAPE_POLY_SET &aShape) override
VECTOR2I GetLibraryStart() const
void SetStart(const VECTOR2I &aStart) override
void SetBezierC2(const VECTOR2I &aPt) override
SHAPE_POLY_SET GetLibraryPolyShape() const
VECTOR2I GetLibraryBezierC2() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
static constexpr EDA_ANGLE ANGLE_0
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
void DumpBoardToFile(BOARD &board, const std::filesystem::path &aFilename)
Utility function to simply write a Board out to a file.
@ SMD
Smd pad, appears on the solder paste layer (default)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(BezierAndPolyOnTransformedFootprint)
A custom pad's bezier and polygon primitives must survive a save/reload unchanged,...
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
const SHAPE_LINE_CHAIN chain
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I