KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_constraint_exclusions.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 <algorithm>
21
23
24#include <board.h>
25#include <collectors.h>
27
28
29BOOST_AUTO_TEST_SUITE( ConstraintSolverExclusions )
30
31
32static bool listContains( const std::vector<KICAD_T>& aList, KICAD_T aType )
33{
34 return std::find( aList.begin(), aList.end(), aType ) != aList.end();
35}
36
37
38BOOST_AUTO_TEST_CASE( NotGroupable )
39{
41
42 // A constraint references items but is not itself a groupable element.
43 BOOST_CHECK( !c.IsGroupableType() );
44}
45
46
47BOOST_AUTO_TEST_CASE( NotInCollectorScanLists )
48{
49 // Selection and editing flow through these scan lists. A constraint must appear in
50 // none of them, otherwise it would become selectable/editable.
54}
55
56
57BOOST_AUTO_TEST_CASE( VisitWithCollectorListsSkipsConstraint )
58{
59 BOARD board;
60
62 board.Add( c );
63
64 auto countConstraintHits =
65 [&]( const std::vector<KICAD_T>& aTypes )
66 {
67 int hits = 0;
68
69 board.Visit(
70 [&]( EDA_ITEM* aItem, void* ) -> INSPECT_RESULT
71 {
72 if( aItem == c )
73 hits++;
74
76 },
77 nullptr, aTypes );
78
79 return hits;
80 };
81
82 // The production collector scan list never visits the constraint...
83 BOOST_CHECK_EQUAL( countConstraintHits( GENERAL_COLLECTOR::AllBoardItems ), 0 );
84
85 // ...but it is genuinely owned and reachable when explicitly scanned for.
86 BOOST_CHECK_EQUAL( countConstraintHits( { PCB_CONSTRAINT_T } ), 1 );
87}
88
89
bool IsGroupableType() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition board.cpp:2599
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1355
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
static const std::vector< KICAD_T > BoardLevelItems
A scan list for all primary board items, omitting items which are subordinate to a FOOTPRINT,...
Definition collectors.h:65
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition collectors.h:37
static const std::vector< KICAD_T > FootprintItems
A scan list for primary footprint items.
Definition collectors.h:103
A geometric constraint between board items (issue #2329).
INSPECT_RESULT
Definition eda_item.h:42
STL namespace.
@ PARALLEL
Two segments are parallel.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static bool listContains(const std::vector< KICAD_T > &aList, KICAD_T aType)
BOOST_AUTO_TEST_CASE(NotGroupable)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ PCB_CONSTRAINT_T
class PCB_CONSTRAINT, a geometric constraint between board items
Definition typeinfo.h:238