KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_extruded_body_load_save.cpp
Go to the documentation of this file.
1
#include <
qa_utils/file_utils.h
>
2
#include <boost/test/unit_test.hpp>
3
#include <
footprint.h
>
4
#include <
pcb_3d_body.h
>
5
#include <
pcbnew_utils/board_file_utils.h
>
6
#include <
pcbnew_utils/board_test_utils.h
>
7
#include <
settings/settings_manager.h
>
8
#include <filesystem>
9
10
BOOST_AUTO_TEST_SUITE
( ExtrudedBodyLoadSave )
11
12
BOOST_AUTO_TEST_CASE
( FullRoundTrip )
13
{
14
SETTINGS_MANAGER
settingsManager;
15
16
FOOTPRINT
footprint(
nullptr
);
17
EXTRUDED_3D_BODY
& body = *footprint.
EnsureBody
().
MutableExtruded
();
18
body.
m_height
=
pcbIUScale
.mmToIU( 2.5 );
19
body.
m_standoff
=
pcbIUScale
.mmToIU( 0.1 );
20
body.
m_layer
=
F_CrtYd
;
21
body.
m_material
=
EXTRUSION_MATERIAL::METAL
;
22
body.
m_color
=
KIGFX::COLOR4D
( 0.8, 0.4, 0.0, 0.9 );
23
body.
m_offset
=
VECTOR3D
( 1.0, -0.5, 0.2 );
24
body.
m_scale
=
VECTOR3D
( 1.5, 0.8, 2.0 );
25
body.
m_rotation
=
VECTOR3D
( 10.0, 20.0, 45.0 );
26
body.
m_show
=
false
;
27
28
KI_TEST::SCOPED_TEMP_DIR
tempLib(
"kicad_qa_extruded_body_roundtrip"
);
29
const
auto
libPath = tempLib.
CreateChildDir
(
"extruded_body_roundtrip.pretty"
);
30
const
auto
savePath = libPath /
"extruded_body_roundtrip.kicad_mod"
;
31
KI_TEST::DumpFootprintToFile
( footprint, savePath );
32
33
std::unique_ptr<FOOTPRINT> loaded =
KI_TEST::ReadFootprintFromFile
( savePath );
34
BOOST_REQUIRE
( loaded !=
nullptr
);
35
36
BOOST_REQUIRE
( loaded->HasBody() );
37
const
EXTRUDED_3D_BODY
* lb = loaded->GetBody()->GetExtruded();
38
39
BOOST_CHECK_EQUAL
( lb->
m_height
, body.
m_height
);
40
BOOST_CHECK_EQUAL
( lb->
m_standoff
, body.
m_standoff
);
41
BOOST_CHECK_EQUAL
( lb->
m_layer
, body.
m_layer
);
42
BOOST_CHECK_EQUAL
(
static_cast<
int
>
( lb->
m_material
),
static_cast<
int
>
( body.
m_material
) );
43
BOOST_CHECK_CLOSE( lb->
m_color
.
r
, body.
m_color
.
r
, 0.01 );
44
BOOST_CHECK_CLOSE( lb->
m_color
.
g
, body.
m_color
.
g
, 0.01 );
45
BOOST_CHECK_CLOSE( lb->
m_color
.
b
, body.
m_color
.
b
, 0.01 );
46
BOOST_CHECK_CLOSE( lb->
m_color
.
a
, body.
m_color
.
a
, 0.01 );
47
48
BOOST_CHECK_CLOSE( lb->
m_offset
.
x
, body.
m_offset
.
x
, 0.01 );
49
BOOST_CHECK_CLOSE( lb->
m_offset
.
y
, body.
m_offset
.
y
, 0.01 );
50
BOOST_CHECK_CLOSE( lb->
m_offset
.
z
, body.
m_offset
.
z
, 0.01 );
51
BOOST_CHECK_CLOSE( lb->
m_scale
.
x
, body.
m_scale
.
x
, 0.01 );
52
BOOST_CHECK_CLOSE( lb->
m_scale
.
y
, body.
m_scale
.
y
, 0.01 );
53
BOOST_CHECK_CLOSE( lb->
m_scale
.
z
, body.
m_scale
.
z
, 0.01 );
54
BOOST_CHECK_CLOSE( lb->
m_rotation
.
x
, body.
m_rotation
.
x
, 0.01 );
55
BOOST_CHECK_CLOSE( lb->
m_rotation
.
y
, body.
m_rotation
.
y
, 0.01 );
56
BOOST_CHECK_CLOSE( lb->
m_rotation
.
z
, body.
m_rotation
.
z
, 0.01 );
57
58
BOOST_CHECK_EQUAL
( lb->
m_show
, body.
m_show
);
59
}
60
61
BOOST_AUTO_TEST_CASE
( DefaultsRoundTrip )
62
{
63
SETTINGS_MANAGER
settingsManager;
64
65
FOOTPRINT
footprint(
nullptr
);
66
EXTRUDED_3D_BODY
& body = *footprint.
EnsureBody
().
MutableExtruded
();
67
body.
m_height
=
pcbIUScale
.mmToIU( 5.0 );
68
// Leave everything else at defaults
69
70
KI_TEST::SCOPED_TEMP_DIR
tempLib(
"kicad_qa_extruded_body_defaults_roundtrip"
);
71
const
auto
libPath = tempLib.
CreateChildDir
(
"extruded_body_defaults_roundtrip.pretty"
);
72
const
auto
savePath = libPath /
"extruded_body_defaults_roundtrip.kicad_mod"
;
73
KI_TEST::DumpFootprintToFile
( footprint, savePath );
74
75
std::unique_ptr<FOOTPRINT> loaded =
KI_TEST::ReadFootprintFromFile
( savePath );
76
BOOST_REQUIRE
( loaded !=
nullptr
);
77
BOOST_REQUIRE
( loaded->HasBody() );
78
79
const
EXTRUDED_3D_BODY
* lb = loaded->GetBody()->GetExtruded();
80
BOOST_CHECK_EQUAL
( lb->
m_height
, body.
m_height
);
81
BOOST_CHECK_EQUAL
( lb->
m_standoff
, 0 );
82
BOOST_CHECK_EQUAL
( lb->
m_layer
,
UNDEFINED_LAYER
);
83
BOOST_CHECK_EQUAL
(
static_cast<
int
>
( lb->
m_material
),
static_cast<
int
>
(
EXTRUSION_MATERIAL::PLASTIC
) );
84
BOOST_CHECK( lb->
m_color
==
KIGFX::COLOR4D::UNSPECIFIED
);
85
86
BOOST_CHECK_CLOSE( lb->
m_offset
.
x
, 0.0, 0.01 );
87
BOOST_CHECK_CLOSE( lb->
m_offset
.
y
, 0.0, 0.01 );
88
BOOST_CHECK_CLOSE( lb->
m_offset
.
z
, 0.0, 0.01 );
89
BOOST_CHECK_CLOSE( lb->
m_scale
.
x
, 1.0, 0.01 );
90
BOOST_CHECK_CLOSE( lb->
m_scale
.
y
, 1.0, 0.01 );
91
BOOST_CHECK_CLOSE( lb->
m_scale
.
z
, 1.0, 0.01 );
92
BOOST_CHECK_CLOSE( lb->
m_rotation
.
x
, 0.0, 0.01 );
93
BOOST_CHECK_CLOSE( lb->
m_rotation
.
y
, 0.0, 0.01 );
94
BOOST_CHECK_CLOSE( lb->
m_rotation
.
z
, 0.0, 0.01 );
95
96
BOOST_CHECK_EQUAL
( lb->
m_show
,
true
);
97
}
98
99
BOOST_AUTO_TEST_CASE
( NoExtrudedBodyRoundTrip )
100
{
101
SETTINGS_MANAGER
settingsManager;
102
103
FOOTPRINT
footprint(
nullptr
);
104
105
KI_TEST::SCOPED_TEMP_DIR
tempLib(
"kicad_qa_extruded_body_none_roundtrip"
);
106
const
auto
libPath = tempLib.
CreateChildDir
(
"extruded_body_none_roundtrip.pretty"
);
107
const
auto
savePath = libPath /
"extruded_body_none_roundtrip.kicad_mod"
;
108
KI_TEST::DumpFootprintToFile
( footprint, savePath );
109
110
std::unique_ptr<FOOTPRINT> loaded =
KI_TEST::ReadFootprintFromFile
( savePath );
111
BOOST_REQUIRE
( loaded !=
nullptr
);
112
BOOST_CHECK( !loaded->HasBody() );
113
}
114
115
BOOST_AUTO_TEST_SUITE_END
()
pcbIUScale
constexpr EDA_IU_SCALE pcbIUScale
Definition
base_units.h:128
board_file_utils.h
General utilities for PCB file IO for QA programs.
board_test_utils.h
EXTRUDED_3D_BODY
Definition
pcb_3d_body.h:39
EXTRUDED_3D_BODY::m_color
KIGFX::COLOR4D m_color
Definition
pcb_3d_body.h:46
EXTRUDED_3D_BODY::m_offset
VECTOR3D m_offset
Definition
pcb_3d_body.h:52
EXTRUDED_3D_BODY::m_layer
PCB_LAYER_ID m_layer
Definition
pcb_3d_body.h:45
EXTRUDED_3D_BODY::m_standoff
int m_standoff
Definition
pcb_3d_body.h:44
EXTRUDED_3D_BODY::m_rotation
VECTOR3D m_rotation
Definition
pcb_3d_body.h:51
EXTRUDED_3D_BODY::m_scale
VECTOR3D m_scale
Definition
pcb_3d_body.h:50
EXTRUDED_3D_BODY::m_height
int m_height
Definition
pcb_3d_body.h:43
EXTRUDED_3D_BODY::m_material
EXTRUSION_MATERIAL m_material
Definition
pcb_3d_body.h:47
EXTRUDED_3D_BODY::m_show
bool m_show
Definition
pcb_3d_body.h:48
FOOTPRINT
Definition
footprint.h:265
FOOTPRINT::EnsureBody
PCB_3D_BODY & EnsureBody()
Definition
footprint.cpp:3151
KIGFX::COLOR4D
A color representation with 4 components: red, green, blue, alpha.
Definition
color4d.h:101
KIGFX::COLOR4D::r
double r
Red component.
Definition
color4d.h:391
KIGFX::COLOR4D::g
double g
Green component.
Definition
color4d.h:392
KIGFX::COLOR4D::a
double a
Alpha component.
Definition
color4d.h:394
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:400
KIGFX::COLOR4D::b
double b
Blue component.
Definition
color4d.h:393
KI_TEST::SCOPED_TEMP_DIR
Definition
file_utils.h:38
KI_TEST::SCOPED_TEMP_DIR::CreateChildDir
std::filesystem::path CreateChildDir(const wxString &aName) const
Create and return the path to a direct child directory.
Definition
file_utils.cpp:233
PCB_3D_BODY::MutableExtruded
EXTRUDED_3D_BODY * MutableExtruded()
Definition
pcb_3d_body.h:115
SETTINGS_MANAGER
Definition
settings_manager.h:48
VECTOR3::y
T y
Definition
vector3.h:64
VECTOR3::z
T z
Definition
vector3.h:65
VECTOR3::x
T x
Definition
vector3.h:63
file_utils.h
footprint.h
F_CrtYd
@ F_CrtYd
Definition
layer_ids.h:112
UNDEFINED_LAYER
@ UNDEFINED_LAYER
Definition
layer_ids.h:57
KI_TEST::DumpFootprintToFile
void DumpFootprintToFile(const FOOTPRINT &aFootprint, const std::filesystem::path &aLibraryPath)
Same as DumpBoardToFile, but for footprints.
Definition
board_file_utils.cpp:177
KI_TEST::ReadFootprintFromFile
std::unique_ptr< FOOTPRINT > ReadFootprintFromFile(const std::filesystem::path &aFilename)
Definition
board_file_utils.cpp:171
pcb_3d_body.h
EXTRUSION_MATERIAL::METAL
@ METAL
Definition
pcb_3d_body.h:34
EXTRUSION_MATERIAL::PLASTIC
@ PLASTIC
Definition
pcb_3d_body.h:32
settings_manager.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:80
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:12
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 Tue Oct 27 2026 00:06:46 for KiCad PCB EDA Suite by
1.13.2