KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_extruded_body_load_save.cpp
Go to the documentation of this file.
2#include <boost/test/unit_test.hpp>
3#include <footprint.h>
7#include <filesystem>
8
9BOOST_AUTO_TEST_SUITE( ExtrudedBodyLoadSave )
10
11BOOST_AUTO_TEST_CASE( FullRoundTrip )
12{
13 SETTINGS_MANAGER settingsManager;
14
15 FOOTPRINT footprint( nullptr );
16 EXTRUDED_3D_BODY& body = footprint.EnsureExtrudedBody();
17 body.m_height = pcbIUScale.mmToIU( 2.5 );
18 body.m_standoff = pcbIUScale.mmToIU( 0.1 );
19 body.m_layer = F_CrtYd;
21 body.m_color = KIGFX::COLOR4D( 0.8, 0.4, 0.0, 0.9 );
22 body.m_offset = VECTOR3D( 1.0, -0.5, 0.2 );
23 body.m_scale = VECTOR3D( 1.5, 0.8, 2.0 );
24 body.m_rotation = VECTOR3D( 10.0, 20.0, 45.0 );
25 body.m_show = false;
26
27 KI_TEST::SCOPED_TEMP_DIR tempLib( "kicad_qa_extruded_body_roundtrip" );
28 const auto libPath = tempLib.CreateChildDir( "extruded_body_roundtrip.pretty" );
29 const auto savePath = libPath / "extruded_body_roundtrip.kicad_mod";
30 KI_TEST::DumpFootprintToFile( footprint, savePath.string() );
31
32 std::unique_ptr<FOOTPRINT> loaded = KI_TEST::ReadFootprintFromFileOrStream( savePath.string() );
33 BOOST_REQUIRE( loaded != nullptr );
34
35 BOOST_REQUIRE( loaded->HasExtrudedBody() );
36 const EXTRUDED_3D_BODY* lb = loaded->GetExtrudedBody();
37
41 BOOST_CHECK_EQUAL( static_cast<int>( lb->m_material ), static_cast<int>( body.m_material ) );
42 BOOST_CHECK_CLOSE( lb->m_color.r, body.m_color.r, 0.01 );
43 BOOST_CHECK_CLOSE( lb->m_color.g, body.m_color.g, 0.01 );
44 BOOST_CHECK_CLOSE( lb->m_color.b, body.m_color.b, 0.01 );
45 BOOST_CHECK_CLOSE( lb->m_color.a, body.m_color.a, 0.01 );
46
47 BOOST_CHECK_CLOSE( lb->m_offset.x, body.m_offset.x, 0.01 );
48 BOOST_CHECK_CLOSE( lb->m_offset.y, body.m_offset.y, 0.01 );
49 BOOST_CHECK_CLOSE( lb->m_offset.z, body.m_offset.z, 0.01 );
50 BOOST_CHECK_CLOSE( lb->m_scale.x, body.m_scale.x, 0.01 );
51 BOOST_CHECK_CLOSE( lb->m_scale.y, body.m_scale.y, 0.01 );
52 BOOST_CHECK_CLOSE( lb->m_scale.z, body.m_scale.z, 0.01 );
53 BOOST_CHECK_CLOSE( lb->m_rotation.x, body.m_rotation.x, 0.01 );
54 BOOST_CHECK_CLOSE( lb->m_rotation.y, body.m_rotation.y, 0.01 );
55 BOOST_CHECK_CLOSE( lb->m_rotation.z, body.m_rotation.z, 0.01 );
56
57 BOOST_CHECK_EQUAL( lb->m_show, body.m_show );
58}
59
60BOOST_AUTO_TEST_CASE( DefaultsRoundTrip )
61{
62 SETTINGS_MANAGER settingsManager;
63
64 FOOTPRINT footprint( nullptr );
65 EXTRUDED_3D_BODY& body = footprint.EnsureExtrudedBody();
66 body.m_height = pcbIUScale.mmToIU( 5.0 );
67 // Leave everything else at defaults
68
69 KI_TEST::SCOPED_TEMP_DIR tempLib( "kicad_qa_extruded_body_defaults_roundtrip" );
70 const auto libPath = tempLib.CreateChildDir( "extruded_body_defaults_roundtrip.pretty" );
71 const auto savePath = libPath / "extruded_body_defaults_roundtrip.kicad_mod";
72 KI_TEST::DumpFootprintToFile( footprint, savePath.string() );
73
74 std::unique_ptr<FOOTPRINT> loaded = KI_TEST::ReadFootprintFromFileOrStream( savePath.string() );
75 BOOST_REQUIRE( loaded != nullptr );
76 BOOST_REQUIRE( loaded->HasExtrudedBody() );
77
78 const EXTRUDED_3D_BODY* lb = loaded->GetExtrudedBody();
82 BOOST_CHECK_EQUAL( static_cast<int>( lb->m_material ), static_cast<int>( EXTRUSION_MATERIAL::PLASTIC ) );
83 BOOST_CHECK( lb->m_color == KIGFX::COLOR4D::UNSPECIFIED );
84
85 BOOST_CHECK_CLOSE( lb->m_offset.x, 0.0, 0.01 );
86 BOOST_CHECK_CLOSE( lb->m_offset.y, 0.0, 0.01 );
87 BOOST_CHECK_CLOSE( lb->m_offset.z, 0.0, 0.01 );
88 BOOST_CHECK_CLOSE( lb->m_scale.x, 1.0, 0.01 );
89 BOOST_CHECK_CLOSE( lb->m_scale.y, 1.0, 0.01 );
90 BOOST_CHECK_CLOSE( lb->m_scale.z, 1.0, 0.01 );
91 BOOST_CHECK_CLOSE( lb->m_rotation.x, 0.0, 0.01 );
92 BOOST_CHECK_CLOSE( lb->m_rotation.y, 0.0, 0.01 );
93 BOOST_CHECK_CLOSE( lb->m_rotation.z, 0.0, 0.01 );
94
95 BOOST_CHECK_EQUAL( lb->m_show, true );
96}
97
98BOOST_AUTO_TEST_CASE( NoExtrudedBodyRoundTrip )
99{
100 SETTINGS_MANAGER settingsManager;
101
102 FOOTPRINT footprint( nullptr );
103
104 KI_TEST::SCOPED_TEMP_DIR tempLib( "kicad_qa_extruded_body_none_roundtrip" );
105 const auto libPath = tempLib.CreateChildDir( "extruded_body_none_roundtrip.pretty" );
106 const auto savePath = libPath / "extruded_body_none_roundtrip.kicad_mod";
107 KI_TEST::DumpFootprintToFile( footprint, savePath.string() );
108
109 std::unique_ptr<FOOTPRINT> loaded = KI_TEST::ReadFootprintFromFileOrStream( savePath.string() );
110 BOOST_REQUIRE( loaded != nullptr );
111 BOOST_CHECK( !loaded->HasExtrudedBody() );
112}
113
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
General utilities for PCB file IO for QA programs.
KIGFX::COLOR4D m_color
Definition footprint.h:120
VECTOR3D m_offset
Definition footprint.h:126
PCB_LAYER_ID m_layer
Definition footprint.h:119
VECTOR3D m_rotation
Definition footprint.h:125
VECTOR3D m_scale
Definition footprint.h:124
EXTRUSION_MATERIAL m_material
Definition footprint.h:121
EXTRUDED_3D_BODY & EnsureExtrudedBody()
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double r
Red component.
Definition color4d.h:390
double g
Green component.
Definition color4d.h:391
double a
Alpha component.
Definition color4d.h:393
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:399
double b
Blue component.
Definition color4d.h:392
std::filesystem::path CreateChildDir(const wxString &aName) const
Create and return the path to a direct child directory.
@ F_CrtYd
Definition layer_ids.h:112
@ UNDEFINED_LAYER
Definition layer_ids.h:57
void DumpFootprintToFile(const FOOTPRINT &aFootprint, const std::filesystem::path &aLibraryPath)
Same as DumpBoardToFile, but for footprints.
std::unique_ptr< FOOTPRINT > ReadFootprintFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(FullRoundTrip)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR3< double > VECTOR3D
Definition vector3.h:230