21#include <boost/test/unit_test.hpp>
30#include <api/board/board_types.pb.h>
31#include <api/common/types/embedded_files.pb.h>
69 int drillChartCount = 0;
70 int drillMapCount = 0;
71 int referenceImageCount = 0;
77 for(
PCB_TRACK* track : m_board->Tracks() )
79 switch( track->Type() )
100 for(
FOOTPRINT* footprint : m_board->Footprints() )
103 for(
ZONE* zone : m_board->Zones() )
108 switch( item->Type() )
137 static_cast<PCB_BARCODE*
>( item ), m_board.get() );
144 ++referenceImageCount;
166 static_cast<PCB_TEXT*
>( item ), m_board.get() );
172 static_cast<PCB_TEXTBOX*
>( item ), m_board.get() );
178 static_cast<PCB_SHAPE*
>( item ), m_board.get() );
186 BOOST_CHECK_GT( barcodeCount, 0 );
187 BOOST_CHECK_GT( drillChartCount, 0 );
188 BOOST_CHECK_GT( drillMapCount, 0 );
189 BOOST_CHECK_GT( referenceImageCount, 0 );
190 BOOST_CHECK_GT( tableCount, 0 );
191 BOOST_CHECK_GT( textCount, 0 );
192 BOOST_CHECK_GT( textBoxCount, 0 );
193 BOOST_CHECK_GT( shapeCount, 0 );
225 google::protobuf::Any
any;
227 kiapi::board::types::DrillChart proto;
229 BOOST_REQUIRE_GT( proto.columns_size(), 0 );
234 proto.mutable_columns( 0 )->mutable_width()->set_value_nm( width );
235 any.PackFrom( proto );
242 std::numeric_limits<int64_t>::max() } )
244 proto.mutable_columns( 0 )->mutable_width()->set_value_nm( width );
245 any.PackFrom( proto );
258 for(
PCB_TRACK* track : m_board->Tracks() )
260 switch( track->Type() )
271 for(
FOOTPRINT* footprint : m_board->Footprints() )
280 for(
const FOOTPRINT* fp : m_board->Footprints() )
282 if( fp->EmbeddedFileMap().empty() )
285 BOOST_TEST_CONTEXT( wxString::Format( wxS(
"Footprint %s embedded files" ), fp->m_Uuid.AsStdString() ) )
287 google::protobuf::Any
any;
288 fp->Serialize(
any );
290 kiapi::board::types::FootprintInstance proto;
291 BOOST_CHECK(
any.UnpackTo( &proto ) );
293 BOOST_CHECK_GT( proto.embedded_files().files_size(), 0 );
295 const kiapi::common::types::EmbeddedFile& file = proto.embedded_files().files( 0 );
296 BOOST_CHECK( !file.data().empty() );
298 std::unique_ptr<FOOTPRINT> roundTripped = std::make_unique<FOOTPRINT>( m_board.get() );
299 BOOST_CHECK( roundTripped->Deserialize(
any ) );
301 for(
const auto& [
name,
expected] : fp->EmbeddedFileMap() )
304 BOOST_CHECK_MESSAGE(
actual, wxString::Format( wxS(
"Embedded file '%s' missing after round-trip" ),
name ).c_str() );
322 m_board = std::make_unique<BOARD>();
324 ZONE* zone =
new ZONE( m_board.get() );
341 m_board->Add( zone );
343 google::protobuf::Any
any;
346 kiapi::board::types::Zone proto;
349 BOOST_REQUIRE( proto.copper_settings().has_thieving_settings() );
351 std::unique_ptr<ZONE> roundTripped = std::make_unique<ZONE>( m_board.get() );
357 BOOST_CHECK_LE( roundTripped->GetNetCode(), 0 );
371 const auto makeGridItem =
374 return std::make_unique<PCB_GRID_ITEM>(
nullptr );
404 google::protobuf::Any
any;
407 std::unique_ptr<PCB_GRID_ITEM> roundTripped = makeGridItem();
424 const auto makeBody =
427 return std::make_unique<PCB_3D_BODY>();
456 google::protobuf::Any
any;
459 kiapi::board::types::Body3D msg;
461 BOOST_CHECK( !msg.extruded().has_color() );
464 msg.set_kind( kiapi::board::types::BDK_MODEL );
467 std::unique_ptr<PCB_3D_BODY> modelBody = makeBody();
468 BOOST_CHECK( !modelBody->Deserialize(
any ) );
474 kiapi::board::types::Footprint definition;
477 msg.set_kind( kiapi::board::types::BDK_EXTRUDED );
478 msg.mutable_id()->set_value(
KIID().AsStdString() );
479 msg.mutable_parent()->set_value(
"00000000-0000-0000-0000-000000000001" );
480 msg.mutable_extruded()->mutable_height()->set_value_nm(
pcbIUScale.mmToIU( 2 ) );
482 *definition.add_items() =
any;
485 BOOST_CHECK( target.
HasBody() );
497 numberBox->SetIsProxyItem();
500 spokeTemplate->SetIsProxyItem();
504 google::protobuf::Any numberBoxAny;
505 numberBox->Serialize( numberBoxAny );
507 kiapi::board::types::BoardGraphicShape numberBoxProto;
509 BOOST_REQUIRE( numberBoxProto.has_pad_custom_shape_options() );
510 BOOST_CHECK( numberBoxProto.pad_custom_shape_options().is_number_box() );
512 google::protobuf::Any spokeAny;
513 spokeTemplate->Serialize( spokeAny );
515 kiapi::board::types::BoardGraphicShape spokeProto;
518 BOOST_CHECK( spokeProto.pad_custom_shape_options().is_thermal_spoke_template() );
520 google::protobuf::Any plainAny;
521 plainShape->Serialize( plainAny );
523 kiapi::board::types::BoardGraphicShape plainProto;
525 BOOST_CHECK( !plainProto.has_pad_custom_shape_options() );
528 google::protobuf::Any mismatchedAny;
529 spokeTemplate->Serialize( mismatchedAny );
531 kiapi::board::types::BoardGraphicShape mismatchedProto;
533 mismatchedProto.clear_shape();
534 mismatchedProto.mutable_shape()->mutable_rectangle()->mutable_top_left()->set_x_nm( 0 );
535 mismatchedProto.mutable_shape()->mutable_rectangle()->mutable_top_left()->set_y_nm( 0 );
536 mismatchedProto.mutable_shape()->mutable_rectangle()->mutable_bottom_right()->set_x_nm( 1 );
537 mismatchedProto.mutable_shape()->mutable_rectangle()->mutable_bottom_right()->set_y_nm( 1 );
538 mismatchedAny.PackFrom( mismatchedProto );
void testProtoFromKiCadObject(KiCadClass *aInput, Factory &&aCreateOutput)
constexpr EDA_IU_SCALE pcbIUScale
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
void SetLocked(bool aLocked) override
FOOTPRINT * GetParentFootprint() const
Information pertinent to a Pcbnew printed circuit board.
EDA_ANGLE GetAngle() const
EXTRUSION_MATERIAL m_material
A color representation with 4 components: red, green, blue, alpha.
A 3D body attached to a footprint (or, later, placed on a board).
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
EXTRUDED_3D_BODY * MutableExtruded()
For better understanding of the points that make a dimension:
Mark the center of a circle or arc with a cross shape.
A leader is a dimension-like object pointing to a specific point.
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
A radial dimension indicates either the radius or diameter of an arc or circle.
A drill chart placed on the board, kept in step with the holes.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Turns on drill symbols at the holes, for one layer.
std::vector< GENERATED_TABLE_COLUMN > & Columns()
void SetRadiusExtent(int aR)
void SetAffectsRouting(bool aOn)
void SetPosition(const VECTOR2I &aPos) override
void SetRadiusSpacing(int aR)
void SetGridItemType(PCB_GRID_TYPE aType)
void SetExtent(const VECTOR2I &aExtent)
void SetTickInterval(unsigned aInterval)
void SetOrientationDegrees(double aDeg)
void SetSpacing(const VECTOR2I &aSpacing)
void SetPhiExtentDegrees(double aDeg)
void SetAffectsPlacement(bool aOn)
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void SetPhiSpacingDegrees(double aDeg)
void SetAssignedPriority(unsigned aPriority)
Priority 0 is reserved for the global background grid; user-assigned 0 is bumped to 1.
void SetAffectsCursor(bool aOn)
Object to handle a bitmap image that can be inserted in a PCB.
bool IsProxyItem() const override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Handle a list of polygons defining a copper zone.
bool AppendCorner(const VECTOR2I &aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void SetFillMode(ZONE_FILL_MODE aFillMode)
void SetThievingSettings(const THIEVING_SETTINGS &aSettings)
A type-safe container of any type.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
constexpr int GENERATED_TABLE_MAX_COLUMN_WIDTH
A column can be no wider than this.
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
BARCODE class definition.
std::unique_ptr< BOARD > m_board
SETTINGS_MANAGER m_settingsManager
Parameters that drive copper-thieving fill generation.
EDA_ORIENTATION orientation
BOOST_FIXTURE_TEST_CASE(BoardTypes, PROTO_TEST_FIXTURE)
BOOST_AUTO_TEST_CASE(FootprintExcludeFromSimulationRoundTrip)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
VECTOR2< int32_t > VECTOR2I
VECTOR3< double > VECTOR3D