KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_group_mirror.cpp
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18
*/
19
20
#include <
qa_utils/wx_utils/unit_test_utils.h
>
21
22
#include <
board.h
>
23
#include <
board_item.h
>
24
#include <
footprint.h
>
25
#include <
pcb_dimension.h
>
26
#include <
pcb_group.h
>
27
#include <
pcb_shape.h
>
28
29
// Regression test for https://gitlab.com/kicad/code/kicad/-/work_items/23731
30
//
31
// A footprint has no mirror (only flip). Mirroring a group that contains one used to call
32
// BOARD_ITEM::Mirror on the footprint, spawning a warning dialog per footprint and mirroring
33
// the other members while the footprint stayed put, tearing the group apart. A group is now
34
// left untouched unless every member can be mirrored.
35
36
BOOST_AUTO_TEST_SUITE
( GroupMirror )
37
38
39
BOOST_AUTO_TEST_CASE
( GroupWithFootprintIsLeftIntact )
40
{
41
std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
42
43
PCB_SHAPE
* shape =
new
PCB_SHAPE
( board.get(),
SHAPE_T::SEGMENT
);
44
shape->
SetStart
(
VECTOR2I
( 1000000, 2000000 ) );
45
shape->
SetEnd
(
VECTOR2I
( 3000000, 4000000 ) );
46
board->Add( shape );
47
48
FOOTPRINT
* footprint =
new
FOOTPRINT
( board.get() );
49
footprint->
SetPosition
(
VECTOR2I
( 5000000, 6000000 ) );
50
board->Add( footprint );
51
52
PCB_GROUP
*
group
=
new
PCB_GROUP
( board.get() );
53
group
->AddItem( shape );
54
group
->AddItem( footprint );
55
board->Add(
group
);
56
57
const
VECTOR2I
shapeStart = shape->
GetStart
();
58
const
VECTOR2I
shapeEnd = shape->
GetEnd
();
59
const
VECTOR2I
fpPos = footprint->
GetPosition
();
60
61
group
->Mirror(
VECTOR2I
( 0, 0 ),
FLIP_DIRECTION::LEFT_RIGHT
);
62
63
// Nothing moved: the group is untouchable because it holds a footprint.
64
BOOST_CHECK_EQUAL
( shape->
GetStart
(), shapeStart );
65
BOOST_CHECK_EQUAL
( shape->
GetEnd
(), shapeEnd );
66
BOOST_CHECK_EQUAL
( footprint->
GetPosition
(), fpPos );
67
}
68
69
70
BOOST_AUTO_TEST_CASE
( GroupWithoutFootprintStillMirrors )
71
{
72
std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
73
74
PCB_SHAPE
* shape =
new
PCB_SHAPE
( board.get(),
SHAPE_T::SEGMENT
);
75
shape->
SetStart
(
VECTOR2I
( 1000000, 2000000 ) );
76
shape->
SetEnd
(
VECTOR2I
( 3000000, 4000000 ) );
77
board->Add( shape );
78
79
PCB_GROUP
*
group
=
new
PCB_GROUP
( board.get() );
80
group
->AddItem( shape );
81
board->Add(
group
);
82
83
group
->Mirror(
VECTOR2I
( 0, 0 ),
FLIP_DIRECTION::LEFT_RIGHT
);
84
85
// Mirror across x = 0 flips the x coordinate, y is unchanged.
86
BOOST_CHECK_EQUAL
( shape->
GetStart
(),
VECTOR2I
( -1000000, 2000000 ) );
87
BOOST_CHECK_EQUAL
( shape->
GetEnd
(),
VECTOR2I
( -3000000, 4000000 ) );
88
}
89
90
91
BOOST_AUTO_TEST_CASE
( GroupWithDimensionStillMirrors )
92
{
93
// A dimension has a Mirror(), so a group holding one must stay mirrorable.
94
std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
95
96
PCB_SHAPE
* shape =
new
PCB_SHAPE
( board.get(),
SHAPE_T::SEGMENT
);
97
shape->
SetStart
(
VECTOR2I
( 1000000, 2000000 ) );
98
shape->
SetEnd
(
VECTOR2I
( 3000000, 4000000 ) );
99
board->Add( shape );
100
101
PCB_DIM_ALIGNED
* dim =
new
PCB_DIM_ALIGNED
( board.get(),
PCB_DIM_ALIGNED_T
);
102
dim->
SetStart
(
VECTOR2I
( 1000000, 0 ) );
103
dim->
SetEnd
(
VECTOR2I
( 5000000, 0 ) );
104
board->Add( dim );
105
106
PCB_GROUP
*
group
=
new
PCB_GROUP
( board.get() );
107
group
->AddItem( shape );
108
group
->AddItem( dim );
109
board->Add(
group
);
110
111
group
->Mirror(
VECTOR2I
( 0, 0 ),
FLIP_DIRECTION::LEFT_RIGHT
);
112
113
// The group was mirrored, both members flipped across x = 0.
114
BOOST_CHECK_EQUAL
( shape->
GetStart
(),
VECTOR2I
( -1000000, 2000000 ) );
115
BOOST_CHECK_EQUAL
( dim->
GetStart
(),
VECTOR2I
( -1000000, 0 ) );
116
BOOST_CHECK_EQUAL
( dim->
GetEnd
(),
VECTOR2I
( -5000000, 0 ) );
117
}
118
119
120
BOOST_AUTO_TEST_SUITE_END
()
BITMAPS::group
@ group
Definition
bitmaps_list.h:246
board.h
board_item.h
EDA_SHAPE::GetEnd
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition
eda_shape.h:240
EDA_SHAPE::GetStart
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition
eda_shape.h:190
FOOTPRINT
Definition
footprint.h:288
FOOTPRINT::SetPosition
void SetPosition(const VECTOR2I &aPos) override
Definition
footprint.cpp:3132
FOOTPRINT::GetPosition
VECTOR2I GetPosition() const override
Definition
footprint.h:403
PCB_DIMENSION_BASE::SetEnd
virtual void SetEnd(const VECTOR2I &aPoint)
Definition
pcb_dimension.cpp:200
PCB_DIMENSION_BASE::SetStart
virtual void SetStart(const VECTOR2I &aPoint)
Definition
pcb_dimension.cpp:191
PCB_DIMENSION_BASE::GetEnd
virtual VECTOR2I GetEnd() const
Definition
pcb_dimension.cpp:182
PCB_DIMENSION_BASE::GetStart
virtual VECTOR2I GetStart() const
The dimension's origin is the first feature point for the dimension.
Definition
pcb_dimension.cpp:173
PCB_DIM_ALIGNED
For better understanding of the points that make a dimension:
Definition
pcb_dimension.h:421
PCB_GROUP
A set of BOARD_ITEMs (i.e., without duplicates).
Definition
pcb_group.h:49
PCB_SHAPE
Definition
pcb_shape.h:35
PCB_SHAPE::SetEnd
void SetEnd(const VECTOR2I &aEnd) override
Definition
pcb_shape.cpp:882
PCB_SHAPE::SetStart
void SetStart(const VECTOR2I &aStart) override
Definition
pcb_shape.cpp:875
SHAPE_T::SEGMENT
@ SEGMENT
Definition
eda_shape.h:46
footprint.h
FLIP_DIRECTION::LEFT_RIGHT
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition
mirror.h:24
pcb_dimension.h
pcb_group.h
Class to handle a set of BOARD_ITEMs.
pcb_shape.h
PLUGIN_ACTION_SCOPE::FOOTPRINT
@ FOOTPRINT
Definition
plugin_action_scope.h:30
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(GroupWithFootprintIsLeftIntact)
Definition
test_group_mirror.cpp:39
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
PCB_DIM_ALIGNED_T
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition
typeinfo.h:95
unit_test_utils.h
VECTOR2I
VECTOR2< int32_t > VECTOR2I
Definition
vector2d.h:683
src
qa
tests
pcbnew
test_group_mirror.cpp
Generated on Tue Jul 7 2026 00:07:30 for KiCad PCB EDA Suite by
1.13.2