Added SELECTION_CONDITIONS::OnlyTypes() variant that takes KICAD_T[]4
This commit is contained in:
parent
dfa963f31a
commit
dd10c577ec
|
@ -29,6 +29,7 @@
|
|||
#include <class_module.h>
|
||||
#include <class_edge_mod.h>
|
||||
#include <class_zone.h>
|
||||
#include <collectors.h>
|
||||
#include <wxPcbStruct.h>
|
||||
#include <kiway.h>
|
||||
#include <class_draw_panel_gal.h>
|
||||
|
@ -81,23 +82,20 @@ bool EDIT_TOOL::Init()
|
|||
return false;
|
||||
}
|
||||
|
||||
// Vector storing track & via types, used for specifying 'Properties' menu entry condition
|
||||
m_tracksViasType.push_back( PCB_TRACE_T );
|
||||
m_tracksViasType.push_back( PCB_VIA_T );
|
||||
|
||||
// Add context menu entries that are displayed when selection tool is active
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty );
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty );
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 )
|
||||
|| SELECTION_CONDITIONS::OnlyTypes( m_tracksViasType ) );
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
|
||||
CONDITIONAL_MENU& menu = m_selectionTool->GetMenu();
|
||||
menu.AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
|
||||
menu.AddItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty );
|
||||
menu.AddItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
|
||||
menu.AddItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty );
|
||||
menu.AddItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 )
|
||||
|| SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
|
||||
menu.AddItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
|
||||
menu.AddItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
|
||||
menu.AddItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
|
||||
|
||||
// Footprint actions
|
||||
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editFootprintInFpEditor,
|
||||
menu.AddItem( COMMON_ACTIONS::editFootprintInFpEditor,
|
||||
SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) &&
|
||||
SELECTION_CONDITIONS::Count( 1 ) );
|
||||
|
||||
|
@ -360,7 +358,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
|
|||
return 0;
|
||||
|
||||
// Tracks & vias are treated in a special way:
|
||||
if( ( SELECTION_CONDITIONS::OnlyTypes( m_tracksViasType ) )( selection ) )
|
||||
if( ( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) )( selection ) )
|
||||
{
|
||||
DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection );
|
||||
|
||||
|
|
|
@ -149,9 +149,6 @@ private:
|
|||
/// Counter of undo inhibitions. When zero, undo is not inhibited.
|
||||
int m_undoInhibit;
|
||||
|
||||
// Vector storing track & via types, used for specifying 'Properties' menu entry condition
|
||||
std::vector<KICAD_T> m_tracksViasType;
|
||||
|
||||
///> Removes and frees a single BOARD_ITEM.
|
||||
void remove( BOARD_ITEM* aItem );
|
||||
|
||||
|
|
|
@ -82,6 +82,12 @@ SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes( const std::vector<KICAD_T>&
|
|||
}
|
||||
|
||||
|
||||
SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes( const KICAD_T aTypes[] )
|
||||
{
|
||||
return boost::bind( &SELECTION_CONDITIONS::onlyTypesFuncArr, _1, aTypes );
|
||||
}
|
||||
|
||||
|
||||
SELECTION_CONDITION SELECTION_CONDITIONS::Count( int aNumber )
|
||||
{
|
||||
return boost::bind( &SELECTION_CONDITIONS::countFunc, _1, aNumber );
|
||||
|
@ -224,6 +230,35 @@ bool SELECTION_CONDITIONS::onlyTypesFunc( const SELECTION& aSelection, const std
|
|||
}
|
||||
|
||||
|
||||
bool SELECTION_CONDITIONS::onlyTypesFuncArr( const SELECTION& aSelection, const KICAD_T aTypes[] )
|
||||
{
|
||||
if( aSelection.Empty() )
|
||||
return false;
|
||||
|
||||
for( int i = 0; i < aSelection.Size(); ++i )
|
||||
{
|
||||
bool valid = false;
|
||||
const KICAD_T* type = aTypes;
|
||||
|
||||
while( *type != EOT )
|
||||
{
|
||||
if( aSelection.Item<EDA_ITEM>( i )->Type() == *type )
|
||||
{
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++type;
|
||||
}
|
||||
|
||||
if( !valid )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SELECTION_CONDITIONS::countFunc( const SELECTION& aSelection, int aNumber )
|
||||
{
|
||||
return aSelection.Size() == aNumber;
|
||||
|
|
|
@ -117,6 +117,15 @@ public:
|
|||
*/
|
||||
static SELECTION_CONDITION OnlyTypes( const std::vector<KICAD_T>& aTypes );
|
||||
|
||||
/**
|
||||
* Function OnlyTypes
|
||||
* Creates a functor that tests if the selected items are *only* of given types.
|
||||
* @param aType is an array containing types that are searched. It has to be ended with
|
||||
* KICAD_T::EOT as end marker.
|
||||
* @return Functor testing if selected items are exclusively of the requested types.
|
||||
*/
|
||||
static SELECTION_CONDITION OnlyTypes( const KICAD_T aTypes[] );
|
||||
|
||||
/**
|
||||
* Function Count
|
||||
* Creates a functor that tests if the number of selected items is equal to the value given as
|
||||
|
@ -159,6 +168,7 @@ private:
|
|||
|
||||
///> Helper function used by OnlyTypes()
|
||||
static bool onlyTypesFunc( const SELECTION& aSelection, const std::vector<KICAD_T>& aTypes );
|
||||
static bool onlyTypesFuncArr( const SELECTION& aSelection, const KICAD_T aTypes[] );
|
||||
|
||||
///> Helper function used by Count()
|
||||
static bool countFunc( const SELECTION& aSelection, int aNumber );
|
||||
|
|
Loading…
Reference in New Issue