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
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
31namespace
32{
33
34// Records which items get queued for redraw without needing a GAL backend.
35class RECORDING_VIEW : public KIGFX::VIEW
36{
37public:
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
56BOOST_AUTO_TEST_SUITE( PcbControlRehatch )
57
58
59BOOST_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 );
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
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
bool IsHatchedFill() const
Definition eda_shape.h:140
void SetFillMode(FILL_T aFill)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
static void rehatchBoardItem(KIGFX::VIEW *aView, BOARD_ITEM *aItem)
Regenerate and redraw an item's hatching, skipping non-hatched shapes. Static for testing.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:47
@ NO_FILL
Definition eda_shape.h:60
@ HATCH
Definition eda_shape.h:64
@ FILLED_SHAPE
Fill with object color.
Definition eda_shape.h:61
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")