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
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
36BOOST_AUTO_TEST_SUITE( GroupMirror )
37
38
39BOOST_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
70BOOST_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
91BOOST_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
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:240
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:190
void SetPosition(const VECTOR2I &aPos) override
VECTOR2I GetPosition() const override
Definition footprint.h:403
virtual void SetEnd(const VECTOR2I &aPoint)
virtual void SetStart(const VECTOR2I &aPoint)
virtual VECTOR2I GetEnd() const
virtual VECTOR2I GetStart() const
The dimension's origin is the first feature point for the dimension.
For better understanding of the points that make a dimension:
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:49
void SetEnd(const VECTOR2I &aEnd) override
void SetStart(const VECTOR2I &aStart) override
@ SEGMENT
Definition eda_shape.h:46
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:24
Class to handle a set of BOARD_ITEMs.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(GroupWithFootprintIsLeftIntact)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:95
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683