KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pcb_control_rehatch.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
// rehatchBoardItem() runs on every board item on every edit (BOARD_COMMIT::Push posts
21
// rehatchShapes), so re-caching anything but hatch-filled shapes stalls commits on dense boards.
22
23
#include <
qa_utils/wx_utils/unit_test_utils.h
>
24
25
#include <
board.h
>
26
#include <
pcb_shape.h
>
27
#include <
pcb_track.h
>
28
#include <
tools/pcb_control.h
>
29
#include <
view/view.h
>
30
31
namespace
32
{
33
34
// Records which items get queued for redraw without needing a GAL backend.
35
class
RECORDING_VIEW :
public
KIGFX::VIEW
36
{
37
public
:
38
void
Update(
const
KIGFX::VIEW_ITEM* aItem,
int
aUpdateFlags )
const override
39
{
40
m_updated.push_back( aItem );
41
}
42
43
void
Update(
const
KIGFX::VIEW_ITEM* aItem )
const override
{ m_updated.push_back( aItem ); }
44
45
bool
WasUpdated(
const
KIGFX::VIEW_ITEM* aItem )
const
46
{
47
return
std::find( m_updated.begin(), m_updated.end(), aItem ) != m_updated.end();
48
}
49
50
mutable
std::vector<const KIGFX::VIEW_ITEM*> m_updated;
51
};
52
53
}
// namespace
54
55
56
BOOST_AUTO_TEST_SUITE
( PcbControlRehatch )
57
58
59
BOOST_AUTO_TEST_CASE
( RehatchOnlyTouchesHatchedShapes )
60
{
61
BOARD
board;
62
63
PCB_SHAPE
solidRect( &board,
SHAPE_T::RECTANGLE
);
64
solidRect.
SetFillMode
(
FILL_T::NO_FILL
);
65
66
PCB_SHAPE
filledRect( &board,
SHAPE_T::RECTANGLE
);
67
filledRect.
SetFillMode
(
FILL_T::FILLED_SHAPE
);
68
69
PCB_SHAPE
hatchedRect( &board,
SHAPE_T::RECTANGLE
);
70
hatchedRect.
SetFillMode
(
FILL_T::HATCH
);
71
72
PCB_TRACK
track( &board );
73
74
BOOST_REQUIRE
( !solidRect.
IsHatchedFill
() );
75
BOOST_REQUIRE
( !filledRect.
IsHatchedFill
() );
76
BOOST_REQUIRE
( hatchedRect.
IsHatchedFill
() );
77
78
RECORDING_VIEW view;
79
80
PCB_CONTROL::rehatchBoardItem
( &view, &solidRect );
81
PCB_CONTROL::rehatchBoardItem
( &view, &filledRect );
82
PCB_CONTROL::rehatchBoardItem
( &view, &track );
83
PCB_CONTROL::rehatchBoardItem
( &view, &hatchedRect );
84
85
BOOST_CHECK( view.WasUpdated( &hatchedRect ) );
86
BOOST_CHECK( !view.WasUpdated( &solidRect ) );
87
BOOST_CHECK( !view.WasUpdated( &filledRect ) );
88
BOOST_CHECK( !view.WasUpdated( &track ) );
89
BOOST_CHECK_EQUAL
( view.m_updated.size(), 1u );
90
}
91
92
93
BOOST_AUTO_TEST_SUITE_END
()
board.h
BOARD
Information pertinent to a Pcbnew printed circuit board.
Definition
board.h:372
EDA_SHAPE::IsHatchedFill
bool IsHatchedFill() const
Definition
eda_shape.h:140
EDA_SHAPE::SetFillMode
void SetFillMode(FILL_T aFill)
Definition
eda_shape.cpp:674
KIGFX::VIEW
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition
view.h:63
PCB_CONTROL::rehatchBoardItem
static void rehatchBoardItem(KIGFX::VIEW *aView, BOARD_ITEM *aItem)
Regenerate and redraw an item's hatching, skipping non-hatched shapes. Static for testing.
Definition
pcb_control.cpp:2948
PCB_SHAPE
Definition
pcb_shape.h:35
PCB_TRACK
Definition
pcb_track.h:57
SHAPE_T::RECTANGLE
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition
eda_shape.h:47
FILL_T::NO_FILL
@ NO_FILL
Definition
eda_shape.h:60
FILL_T::HATCH
@ HATCH
Definition
eda_shape.h:64
FILL_T::FILLED_SHAPE
@ FILLED_SHAPE
Fill with object color.
Definition
eda_shape.h:61
pcb_control.h
pcb_shape.h
pcb_track.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_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")
unit_test_utils.h
view.h
src
qa
tests
pcbnew
test_pcb_control_rehatch.cpp
Generated on Fri Jun 26 2026 00:05:45 for KiCad PCB EDA Suite by
1.13.2