Added SELECTION_CONDITIONS::OnlyTypes() variant that takes KICAD_T[]4

This commit is contained in:
Maciej Suminski 2016-05-04 18:35:20 +02:00
parent dfa963f31a
commit dd10c577ec
4 changed files with 58 additions and 18 deletions

View File

@ -29,6 +29,7 @@
#include <class_module.h> #include <class_module.h>
#include <class_edge_mod.h> #include <class_edge_mod.h>
#include <class_zone.h> #include <class_zone.h>
#include <collectors.h>
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <kiway.h> #include <kiway.h>
#include <class_draw_panel_gal.h> #include <class_draw_panel_gal.h>
@ -81,23 +82,20 @@ bool EDIT_TOOL::Init()
return false; 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 // Add context menu entries that are displayed when selection tool is active
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty ); CONDITIONAL_MENU& menu = m_selectionTool->GetMenu();
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 ) menu.AddItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty );
|| SELECTION_CONDITIONS::OnlyTypes( m_tracksViasType ) ); menu.AddItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 )
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty ); || SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
// Footprint actions // Footprint actions
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editFootprintInFpEditor, menu.AddItem( COMMON_ACTIONS::editFootprintInFpEditor,
SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) && SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) &&
SELECTION_CONDITIONS::Count( 1 ) ); SELECTION_CONDITIONS::Count( 1 ) );
@ -360,7 +358,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
return 0; return 0;
// Tracks & vias are treated in a special way: // 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 ); DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection );

View File

@ -149,9 +149,6 @@ private:
/// Counter of undo inhibitions. When zero, undo is not inhibited. /// Counter of undo inhibitions. When zero, undo is not inhibited.
int m_undoInhibit; 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. ///> Removes and frees a single BOARD_ITEM.
void remove( BOARD_ITEM* aItem ); void remove( BOARD_ITEM* aItem );

View File

@ -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 ) SELECTION_CONDITION SELECTION_CONDITIONS::Count( int aNumber )
{ {
return boost::bind( &SELECTION_CONDITIONS::countFunc, _1, 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 ) bool SELECTION_CONDITIONS::countFunc( const SELECTION& aSelection, int aNumber )
{ {
return aSelection.Size() == aNumber; return aSelection.Size() == aNumber;

View File

@ -117,6 +117,15 @@ public:
*/ */
static SELECTION_CONDITION OnlyTypes( const std::vector<KICAD_T>& aTypes ); 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 * Function Count
* Creates a 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
@ -159,6 +168,7 @@ private:
///> Helper function used by OnlyTypes() ///> Helper function used by OnlyTypes()
static bool onlyTypesFunc( const SELECTION& aSelection, const std::vector<KICAD_T>& aTypes ); 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() ///> Helper function used by Count()
static bool countFunc( const SELECTION& aSelection, int aNumber ); static bool countFunc( const SELECTION& aSelection, int aNumber );