Two new selection conditions: same net & same layer.
This commit is contained in:
parent
e91fdd0079
commit
39ddb3e9ae
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "selection_conditions.h"
|
||||
#include "selection_tool.h"
|
||||
#include <class_board_connected_item.h>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
@ -51,6 +52,18 @@ bool SELECTION_CONDITIONS::OnlyConnectedItems( const SELECTION& aSelection )
|
|||
}
|
||||
|
||||
|
||||
SELECTION_CONDITION SELECTION_CONDITIONS::SameNet()
|
||||
{
|
||||
return boost::bind( &SELECTION_CONDITIONS::sameNetFunc, _1 );
|
||||
}
|
||||
|
||||
|
||||
SELECTION_CONDITION SELECTION_CONDITIONS::SameLayer()
|
||||
{
|
||||
return boost::bind( &SELECTION_CONDITIONS::sameLayerFunc, _1 );
|
||||
}
|
||||
|
||||
|
||||
SELECTION_CONDITION SELECTION_CONDITIONS::HasType( KICAD_T aType )
|
||||
{
|
||||
return boost::bind( &SELECTION_CONDITIONS::hasTypeFunc, _1, aType );
|
||||
|
@ -81,6 +94,63 @@ SELECTION_CONDITION SELECTION_CONDITIONS::LessThan( int aNumber )
|
|||
}
|
||||
|
||||
|
||||
bool SELECTION_CONDITIONS::sameNetFunc( const SELECTION& aSelection )
|
||||
{
|
||||
if( aSelection.Empty() )
|
||||
return false;
|
||||
|
||||
int netcode = -1;
|
||||
|
||||
for( int i = 0; i < aSelection.Size(); ++i )
|
||||
{
|
||||
const BOARD_CONNECTED_ITEM* item =
|
||||
dynamic_cast<const BOARD_CONNECTED_ITEM*>( aSelection.Item<EDA_ITEM>( i ) );
|
||||
|
||||
if( !item )
|
||||
return false;
|
||||
|
||||
if( netcode < 0 )
|
||||
{
|
||||
netcode = item->GetNetCode();
|
||||
|
||||
if( netcode == NETINFO_LIST::UNCONNECTED )
|
||||
return false;
|
||||
}
|
||||
else if( netcode != item->GetNetCode() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SELECTION_CONDITIONS::sameLayerFunc( const SELECTION& aSelection )
|
||||
{
|
||||
if( aSelection.Empty() )
|
||||
return false;
|
||||
|
||||
LSET layerSet;
|
||||
layerSet.set();
|
||||
|
||||
for( int i = 0; i < aSelection.Size(); ++i )
|
||||
{
|
||||
const BOARD_ITEM* item = dynamic_cast<const BOARD_ITEM*>( aSelection.Item<EDA_ITEM>( i ) );
|
||||
|
||||
if( !item )
|
||||
return false;
|
||||
|
||||
layerSet &= item->GetLayerSet();
|
||||
|
||||
if( !layerSet.any() ) // there are no common layers left
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SELECTION_CONDITIONS::hasTypeFunc( const SELECTION& aSelection, KICAD_T aType )
|
||||
{
|
||||
for( int i = 0; i < aSelection.Size(); ++i )
|
||||
|
|
|
@ -73,9 +73,29 @@ public:
|
|||
*/
|
||||
static bool OnlyConnectedItems( const SELECTION& aSelection );
|
||||
|
||||
/**
|
||||
* Function SameNet
|
||||
* Creates a functor that tests if selection contains items belonging to the same net. If there
|
||||
* are items which are not of BOARD_CONNECTED_ITEM type, the result is false. If all items do
|
||||
* not have any net assigned, the result is negative (technically they have the same netcode,
|
||||
* but in most cases they should not be connected together).
|
||||
* @return Functor testing if selected items are exclusively connected items belonging to
|
||||
* the same net (and netcode > 0).
|
||||
*/
|
||||
static SELECTION_CONDITION SameNet();
|
||||
|
||||
/**
|
||||
* Function SameLayer
|
||||
* Creates a functor that tests if selection contains items that belong exclusively to the same
|
||||
* layer. In case of items belonging to multiple layers, it is enough to have a single common
|
||||
* layer with other items.
|
||||
* @return Functor testing if selected items share at least one common layer.
|
||||
*/
|
||||
static SELECTION_CONDITION SameLayer();
|
||||
|
||||
/**
|
||||
* Function HasType
|
||||
* Creates functor that tests if among the selected items there is at least one of a given type.
|
||||
* Creates a functor that tests if among the selected items there is at least one of a given type.
|
||||
* @param aType is the type that is searched.
|
||||
* @return Functor testing for presence of items of a given type.
|
||||
*/
|
||||
|
@ -83,7 +103,7 @@ public:
|
|||
|
||||
/**
|
||||
* Function OnlyType
|
||||
* Creates functor that tests if the selected items are *only* of given type.
|
||||
* 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..
|
||||
*/
|
||||
|
@ -91,7 +111,7 @@ public:
|
|||
|
||||
/**
|
||||
* Function Count
|
||||
* Creates functor that tests if the number of selected items is equal to the value given as
|
||||
* Creates a functor that tests if the number of selected items is equal to the value given as
|
||||
* parameter.
|
||||
* @param aNumber is the number of expected items.
|
||||
* @return Functor testing if the number of selected items is equal aNumber.
|
||||
|
@ -100,7 +120,7 @@ public:
|
|||
|
||||
/**
|
||||
* Function MoreThan
|
||||
* Creates functor that tests if the number of selected items is greater than the value given
|
||||
* Creates a functor that tests if the number of selected items is greater than the value given
|
||||
* as parameter.
|
||||
* @param aNumber is the number used for comparison.
|
||||
* @return Functor testing if the number of selected items is greater than aNumber.
|
||||
|
@ -109,7 +129,7 @@ public:
|
|||
|
||||
/**
|
||||
* Function LessThan
|
||||
* Creates functor that tests if the number of selected items is smaller than the value given
|
||||
* Creates a functor that tests if the number of selected items is smaller than the value given
|
||||
* as parameter.
|
||||
* @param aNumber is the number used for comparison.
|
||||
* @return Functor testing if the number of selected items is smaller than aNumber.
|
||||
|
@ -117,6 +137,9 @@ public:
|
|||
static SELECTION_CONDITION LessThan( int aNumber );
|
||||
|
||||
private:
|
||||
static bool sameNetFunc( const SELECTION& aSelection );
|
||||
static bool sameLayerFunc( const SELECTION& aSelection );
|
||||
|
||||
///> Helper function used by HasType()
|
||||
static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType );
|
||||
|
||||
|
|
Loading…
Reference in New Issue