KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_selection_conditions.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 (C) 2014 CERN
5 * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
27#include "pcb_selection_tool.h"
29
30#include <functional>
31using namespace std::placeholders;
32
33
35{
36 return std::bind( &PCB_SELECTION_CONDITIONS::sameNetFunc, _1, aAllowUnconnected );
37}
38
39
41{
42 return std::bind( &PCB_SELECTION_CONDITIONS::sameLayerFunc, _1 );
43}
44
45
47{
48 for( EDA_ITEM* item : aSelection.Items() )
49 {
50 BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
51
52 if( boardItem && boardItem->IsLocked() )
53 return true;
54 }
55
56 return false;
57}
58
59
61{
62 for( EDA_ITEM* item : aSelection.Items() )
63 {
64 BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
65
66 if( boardItem && !boardItem->IsLocked() )
67 return true;
68 }
69
70 return false;
71}
72
73
74bool PCB_SELECTION_CONDITIONS::sameNetFunc( const SELECTION& aSelection, bool aAllowUnconnected )
75{
76 if( aSelection.Empty() )
77 return false;
78
79 int netcode = -1; // -1 stands for 'net code is not yet determined'
80
81 for( const EDA_ITEM* aitem : aSelection )
82 {
83 int current_netcode = -1;
84
85 const BOARD_CONNECTED_ITEM* item = dynamic_cast<const BOARD_CONNECTED_ITEM*>( aitem );
86
87 if( item )
88 {
89 current_netcode = item->GetNetCode();
90 }
91 else
92 {
93 if( !aAllowUnconnected )
94 return false;
95 else
96 // if it is not a BOARD_CONNECTED_ITEM, treat it as if there was no net assigned
97 current_netcode = 0;
98 }
99
100 assert( current_netcode >= 0 );
101
102 if( netcode < 0 )
103 {
104 netcode = current_netcode;
105
106 if( netcode == NETINFO_LIST::UNCONNECTED && !aAllowUnconnected )
107 return false;
108 }
109 else if( netcode != current_netcode )
110 {
111 return false;
112 }
113 }
114
115 return true;
116}
117
118
120{
121 if( aSelection.Empty() )
122 return false;
123
124 LSET layerSet;
125 layerSet.set();
126
127 for( const EDA_ITEM* i : aSelection )
128 {
129 const BOARD_ITEM* item = static_cast<const BOARD_ITEM*>( i );
130 layerSet &= item->GetLayerSet();
131
132 if( !layerSet.any() ) // there are no common layers left
133 return false;
134 }
135
136 return true;
137}
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:231
virtual bool IsLocked() const
Definition: board_item.cpp:74
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:573
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:375
static SELECTION_CONDITION SameLayer()
Creates a functor that tests if selection contains items that belong exclusively to the same layer.
static bool sameLayerFunc(const SELECTION &aSelection)
static bool HasUnlockedItems(const SELECTION &aSelection)
Test if any selected items are unlocked.
static SELECTION_CONDITION SameNet(bool aAllowUnconnected=false)
Create a functor that tests if selection contains items belonging to the same net or are unconnected ...
static bool sameNetFunc(const SELECTION &aSelection, bool aAllowUnconnected)
< Helper function used by SameNet()
static bool HasLockedItems(const SELECTION &aSelection)
Test if any selected items are locked.
std::deque< EDA_ITEM * > & Items()
Definition: selection.h:213
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:109
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.