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 <
pcbnew_utils/board_file_utils.h
>
5
#include <
pcbnew_utils/board_test_utils.h
>
6
#include <
settings/settings_manager.h
>
7
#include <filesystem>
8
9
BOOST_AUTO_TEST_SUITE
( ExtrudedBodyLoadSave )
10
11
BOOST_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
;
20
body.
m_material
=
EXTRUSION_MATERIAL::METAL
;
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
38
BOOST_CHECK_EQUAL
( lb->
m_height
, body.
m_height
);
39
BOOST_CHECK_EQUAL
( lb->
m_standoff
, body.
m_standoff
);
40
BOOST_CHECK_EQUAL
( lb->
m_layer
, body.
m_layer
);
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
60
BOOST_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();
79
BOOST_CHECK_EQUAL
( lb->
m_height
, body.
m_height
);
80
BOOST_CHECK_EQUAL
( lb->
m_standoff
, 0 );
81
BOOST_CHECK_EQUAL
( lb->
m_layer
,
UNDEFINED_LAYER
);
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
98
BOOST_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
114
BOOST_AUTO_TEST_SUITE_END
()
pcbIUScale
constexpr EDA_IU_SCALE pcbIUScale
Definition
base_units.h:121
board_file_utils.h
General utilities for PCB file IO for QA programs.
board_test_utils.h
EXTRUDED_3D_BODY
Definition
footprint.h:113
EXTRUDED_3D_BODY::m_color
KIGFX::COLOR4D m_color
Definition
footprint.h:120
EXTRUDED_3D_BODY::m_offset
VECTOR3D m_offset
Definition
footprint.h:126
EXTRUDED_3D_BODY::m_layer
PCB_LAYER_ID m_layer
Definition
footprint.h:119
EXTRUDED_3D_BODY::m_standoff
int m_standoff
Definition
footprint.h:118
EXTRUDED_3D_BODY::m_rotation
VECTOR3D m_rotation
Definition
footprint.h:125
EXTRUDED_3D_BODY::m_scale
VECTOR3D m_scale
Definition
footprint.h:124
EXTRUDED_3D_BODY::m_height
int m_height
Definition
footprint.h:117
EXTRUDED_3D_BODY::m_material
EXTRUSION_MATERIAL m_material
Definition
footprint.h:121
EXTRUDED_3D_BODY::m_show
bool m_show
Definition
footprint.h:122
FOOTPRINT
Definition
footprint.h:314
FOOTPRINT::EnsureExtrudedBody
EXTRUDED_3D_BODY & EnsureExtrudedBody()
Definition
footprint.cpp:3103
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:390
KIGFX::COLOR4D::g
double g
Green component.
Definition
color4d.h:391
KIGFX::COLOR4D::a
double a
Alpha component.
Definition
color4d.h:393
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:399
KIGFX::COLOR4D::b
double b
Blue component.
Definition
color4d.h:392
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:145
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
EXTRUSION_MATERIAL::METAL
@ METAL
Definition
footprint.h:108
EXTRUSION_MATERIAL::PLASTIC
@ PLASTIC
Definition
footprint.h:106
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:144
KI_TEST::ReadFootprintFromFileOrStream
std::unique_ptr< FOOTPRINT > ReadFootprintFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Definition
board_file_utils.cpp:117
settings_manager.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:79
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:11
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 Thu Sep 17 2026 00:06:29 for KiCad PCB EDA Suite by
1.13.2