KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 * @author Maciej Suminski <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#include <tool/selection.h>
24
25#include <functional>
26#include <eda_item.h>
27
28using namespace std::placeholders;
29
30
32{
33 return !aSelection.Empty();
34}
35
36
37bool SELECTION_CONDITIONS::Empty( const SELECTION& aSelection )
38{
39 return aSelection.Empty();
40}
41
42
43bool SELECTION_CONDITIONS::Idle( const SELECTION& aSelection )
44{
45 constexpr int busyMask = ( IS_NEW | IS_PASTED | IS_MOVING );
46
47 return !aSelection.Front() || ( aSelection.Front()->GetEditFlags() & busyMask ) == 0;
48}
49
50
52{
53 return ( aSelection.Front() && aSelection.Front()->GetEditFlags() == 0 );
54}
55
56
61
62
64{
65 return std::bind( &SELECTION_CONDITIONS::hasTypesFunc, _1, aTypes );
66}
67
68
70{
71 return std::bind( &SELECTION_CONDITIONS::onlyTypesFunc, _1, aTypes );
72}
73
74
76{
77 return std::bind( &SELECTION_CONDITIONS::countFunc, _1, aNumber );
78}
79
80
82{
83 return std::bind( &SELECTION_CONDITIONS::moreThanFunc, _1, aNumber );
84}
85
86
88{
89 return std::bind( &SELECTION_CONDITIONS::lessThanFunc, _1, aNumber );
90}
91
92
93bool SELECTION_CONDITIONS::hasTypeFunc( const SELECTION& aSelection, KICAD_T aType )
94{
95 if( aSelection.Empty() )
96 return false;
97
98 for( const EDA_ITEM* item : aSelection )
99 {
100 if( item->Type() == aType )
101 return true;
102 }
103
104 return false;
105}
106
107
108bool SELECTION_CONDITIONS::hasTypesFunc( const SELECTION& aSelection, std::vector<KICAD_T> aTypes )
109{
110 if( aSelection.Empty() )
111 return false;
112
113 for( const EDA_ITEM* item : aSelection )
114 {
115 if( item->IsType( aTypes ) )
116 return true;
117 }
118
119 return false;
120}
121
122
123bool SELECTION_CONDITIONS::onlyTypesFunc( const SELECTION& aSelection, std::vector<KICAD_T> aTypes )
124{
125 if( aSelection.Empty() )
126 return false;
127
128 for( const EDA_ITEM* item : aSelection )
129 {
130 if( !item->IsType( aTypes ) )
131 return false;
132 }
133
134 return true;
135}
136
137
138bool SELECTION_CONDITIONS::countFunc( const SELECTION& aSelection, int aNumber )
139{
140 return aSelection.Size() == aNumber;
141}
142
143
144bool SELECTION_CONDITIONS::moreThanFunc( const SELECTION& aSelection, int aNumber )
145{
146 return aSelection.Size() > aNumber;
147}
148
149
150bool SELECTION_CONDITIONS::lessThanFunc( const SELECTION& aSelection, int aNumber )
151{
152 return aSelection.Size() < aNumber;
153}
154
155
157 const SELECTION_CONDITION& aConditionB )
158{
159 return std::bind( &SELECTION_CONDITIONS::orFunc, aConditionA, aConditionB, _1 );
160}
161
162
164 const SELECTION_CONDITION& aConditionB )
165{
166 return std::bind( &SELECTION_CONDITIONS::andFunc, aConditionA, aConditionB, _1 );
167}
168
169
171{
172 return std::bind( &SELECTION_CONDITIONS::notFunc, aCondition, _1 );
173}
174
175
177 SELECTION_BOOL aConditionB )
178{
179 return std::bind( &SELECTION_CONDITIONS::orBoolFunc, aConditionA, std::ref( aConditionB ), _1 );
180}
181
182
184 const SELECTION_CONDITION& aConditionB )
185{
186 return aConditionB || aConditionA;
187}
188
189
191 SELECTION_BOOL aConditionB )
192{
193 return std::bind( &SELECTION_CONDITIONS::andBoolFunc, aConditionA,
194 std::ref( aConditionB ), _1 );
195}
196
197
199 const SELECTION_CONDITION& aConditionB )
200{
201 return aConditionB && aConditionA;
202}
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:158
static bool hasTypesFunc(const SELECTION &aSelection, std::vector< KICAD_T > aTypes)
Helper function used by HasTypes().
static SELECTION_CONDITION HasTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if among the selected items there is at least one of a given types.
static SELECTION_CONDITION HasType(KICAD_T aType)
Create a functor that tests if among the selected items there is at least one of a given type.
static bool Empty(const SELECTION &aSelection)
Test if there are no items selected.
static bool moreThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by MoreThan().
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static bool countFunc(const SELECTION &aSelection, int aNumber)
Helper function used by Count().
static bool orFunc(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
Helper function used by operator ||.
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
static bool orBoolFunc(const SELECTION_CONDITION &aConditionA, SELECTION_BOOL &aConditionB, const SELECTION &aSelection)
Helper function used by operator ||.
static bool lessThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by LessThan().
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
static bool IdleSelection(const SELECTION &aSelection)
Test if all selected items are not being edited.
static bool andBoolFunc(const SELECTION_CONDITION &aConditionA, SELECTION_BOOL &aConditionB, const SELECTION &aSelection)
Helper function used by operator &&.
static SELECTION_CONDITION LessThan(int aNumber)
Create a functor that tests if the number of selected items is smaller than the value given as parame...
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
static bool onlyTypesFunc(const SELECTION &aSelection, std::vector< KICAD_T > aTypes)
Helper function used by OnlyTypes().
static bool andFunc(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
Helper function used by operator &&.
static bool notFunc(const SELECTION_CONDITION &aCondition, const SELECTION &aSelection)
Helper function used by operator !.
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
static bool hasTypeFunc(const SELECTION &aSelection, KICAD_T aType)
Helper function used by HasType().
EDA_ITEM * Front() const
Definition selection.h:173
int Size() const
Returns the number of selected parts.
Definition selection.h:117
bool Empty() const
Checks if there is anything selected.
Definition selection.h:111
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
#define IS_NEW
New item, just created.
#define IS_MOVING
Item being moved.
SELECTION_CONDITION operator||(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
SELECTION_CONDITION operator&&(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
SELECTION_CONDITION operator!(const SELECTION_CONDITION &aCondition)
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
bool(& SELECTION_BOOL)(const SELECTION &)
Signature for a reference to a function that takes a SELECTION and returns a boolean.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71