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