From 13739217b87bd139d7933f4411c1fe366fdd751d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 9 Jul 2015 13:35:49 +0200 Subject: [PATCH] New SELECTION_CONDITION subclass (OnlyTypes). --- pcbnew/tools/selection_conditions.cpp | 32 +++++++++++++++++++++++++++ pcbnew/tools/selection_conditions.h | 14 +++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/pcbnew/tools/selection_conditions.cpp b/pcbnew/tools/selection_conditions.cpp index d05be088c5..31a8d1a544 100644 --- a/pcbnew/tools/selection_conditions.cpp +++ b/pcbnew/tools/selection_conditions.cpp @@ -76,6 +76,12 @@ SELECTION_CONDITION SELECTION_CONDITIONS::OnlyType( KICAD_T aType ) } +SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes( const std::vector& aTypes ) +{ + return boost::bind( &SELECTION_CONDITIONS::onlyTypesFunc, _1, aTypes ); +} + + SELECTION_CONDITION SELECTION_CONDITIONS::Count( int aNumber ) { return boost::bind( &SELECTION_CONDITIONS::countFunc, _1, aNumber ); @@ -178,6 +184,32 @@ bool SELECTION_CONDITIONS::onlyTypeFunc( const SELECTION& aSelection, KICAD_T aT } +bool SELECTION_CONDITIONS::onlyTypesFunc( const SELECTION& aSelection, const std::vector& aTypes ) +{ + if( aSelection.Empty() ) + return false; + + for( int i = 0; i < aSelection.Size(); ++i ) + { + bool valid = false; + + for( std::vector::const_iterator it = aTypes.begin(); it != aTypes.end(); ++it ) + { + if( aSelection.Item( i )->Type() == *it ) + { + valid = true; + break; + } + } + + if( !valid ) + return false; + } + + return true; +} + + bool SELECTION_CONDITIONS::countFunc( const SELECTION& aSelection, int aNumber ) { return aSelection.Size() == aNumber; diff --git a/pcbnew/tools/selection_conditions.h b/pcbnew/tools/selection_conditions.h index 7f09533bc4..715a4fab08 100644 --- a/pcbnew/tools/selection_conditions.h +++ b/pcbnew/tools/selection_conditions.h @@ -27,6 +27,7 @@ #include #include +#include struct SELECTION; @@ -105,10 +106,18 @@ public: * Function OnlyType * Creates a functor that tests if the selected items are *only* of given type. * @param aType is the type that is searched. - * @return Functor testing if selected items are exclusively of one type.. + * @return Functor testing if selected items are exclusively of one type. */ static SELECTION_CONDITION OnlyType( KICAD_T aType ); + /** + * Function OnlyTypes + * Creates a functor that tests if the selected items are *only* of given types. + * @param aType is a vector containing types that are searched. + * @return Functor testing if selected items are exclusively of the requested types. + */ + static SELECTION_CONDITION OnlyTypes( const std::vector& aTypes ); + /** * Function Count * Creates a functor that tests if the number of selected items is equal to the value given as @@ -146,6 +155,9 @@ private: ///> Helper function used by OnlyType() static bool onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType ); + ///> Helper function used by OnlyTypes() + static bool onlyTypesFunc( const SELECTION& aSelection, const std::vector& aTypes ); + ///> Helper function used by Count() static bool countFunc( const SELECTION& aSelection, int aNumber );