Consolidate some UI conditions from context menu enabling
These conditions are for enabling/disabling a control, so place them inside the new UI conditions framework instead of the separate update routine.
This commit is contained in:
parent
aceed2b0a4
commit
e825a99b9a
|
@ -630,6 +630,47 @@ void PCB_EDIT_FRAME::setupUIConditions()
|
|||
mgr->SetConditions( PCB_ACTIONS::routerShoveMode, CHECK( isShoveMode ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::routerWalkaroundMode, CHECK( isWalkaroundMode ) );
|
||||
|
||||
auto haveNetCond =
|
||||
[] ( const SELECTION& aSel )
|
||||
{
|
||||
for( EDA_ITEM* item : aSel )
|
||||
{
|
||||
if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
|
||||
{
|
||||
if( bci->GetNetCode() > 0 )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
mgr->SetConditions( PCB_ACTIONS::showNet, ENABLE( haveNetCond ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::hideNet, ENABLE( haveNetCond ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::highlightNet, ENABLE( haveNetCond ) );
|
||||
|
||||
mgr->SetConditions( PCB_ACTIONS::selectNet,
|
||||
ENABLE( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::selectConnection,
|
||||
ENABLE( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::selectSameSheet,
|
||||
ENABLE( SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) ) );
|
||||
|
||||
|
||||
SELECTION_CONDITION singleZoneCond = SELECTION_CONDITIONS::Count( 1 ) &&
|
||||
SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Zones );
|
||||
|
||||
SELECTION_CONDITION zoneMergeCond = SELECTION_CONDITIONS::MoreThan( 1 ) &&
|
||||
PCB_SELECTION_CONDITIONS::SameNet( true ) &&
|
||||
PCB_SELECTION_CONDITIONS::SameLayer();
|
||||
|
||||
mgr->SetConditions( PCB_ACTIONS::zoneDuplicate, ENABLE( singleZoneCond ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::drawSimilarZone, ENABLE( singleZoneCond ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::zoneMerge, ENABLE( zoneMergeCond ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::zoneFill, ENABLE( SELECTION_CONDITIONS::MoreThan( 0 ) ) );
|
||||
mgr->SetConditions( PCB_ACTIONS::zoneUnfill, ENABLE( SELECTION_CONDITIONS::MoreThan( 0 ) ) );
|
||||
|
||||
// The layer indicator is special, so we register a callback directly that will regenerate the
|
||||
// bitmap instead of using the conditions system
|
||||
auto layerIndicatorUpdate =
|
||||
|
|
|
@ -94,35 +94,6 @@ protected:
|
|||
{
|
||||
return new ZONE_CONTEXT_MENU();
|
||||
}
|
||||
|
||||
private:
|
||||
void update() override
|
||||
{
|
||||
SELECTION_TOOL* selTool = getToolManager()->GetTool<SELECTION_TOOL>();
|
||||
|
||||
// enable zone actions that act on a single zone
|
||||
bool singleZoneActionsEnabled = ( SELECTION_CONDITIONS::Count( 1 ) &&
|
||||
SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Zones )
|
||||
)( selTool->GetSelection() );
|
||||
|
||||
Enable( PCB_ACTIONS::zoneDuplicate.GetUIId(), singleZoneActionsEnabled );
|
||||
Enable( PCB_ACTIONS::drawZoneCutout.GetUIId(), singleZoneActionsEnabled );
|
||||
Enable( PCB_ACTIONS::drawSimilarZone.GetUIId(), singleZoneActionsEnabled );
|
||||
|
||||
// enable zone actions that ably to a specific set of zones (as opposed to all of them)
|
||||
bool nonGlobalActionsEnabled = ( SELECTION_CONDITIONS::MoreThan( 0 ) )( selTool->GetSelection() );
|
||||
|
||||
Enable( PCB_ACTIONS::zoneFill.GetUIId(), nonGlobalActionsEnabled );
|
||||
Enable( PCB_ACTIONS::zoneUnfill.GetUIId(), nonGlobalActionsEnabled );
|
||||
|
||||
// lines like this make me really think about a better name for SELECTION_CONDITIONS class
|
||||
bool mergeEnabled = ( SELECTION_CONDITIONS::MoreThan( 1 ) &&
|
||||
/*SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) &&*/
|
||||
PCB_SELECTION_CONDITIONS::SameNet( true ) &&
|
||||
PCB_SELECTION_CONDITIONS::SameLayer() )( selTool->GetSelection() );
|
||||
|
||||
Enable( PCB_ACTIONS::zoneMerge.GetUIId(), mergeEnabled );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -57,30 +57,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
void update() override
|
||||
{
|
||||
const auto& selection = getToolManager()->GetTool<SELECTION_TOOL>()->GetSelection();
|
||||
|
||||
bool haveNetCode = false;
|
||||
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
|
||||
{
|
||||
if( bci->GetNetCode() > 0 )
|
||||
{
|
||||
haveNetCode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Enable( PCB_ACTIONS::showNet.GetUIId(), haveNetCode );
|
||||
Enable( PCB_ACTIONS::hideNet.GetUIId(), haveNetCode );
|
||||
// Enable( PCB_ACTIONS::highlightNet.GetUIId(), haveNetCode );
|
||||
}
|
||||
|
||||
ACTION_MENU* create() const override
|
||||
{
|
||||
return new NET_CONTEXT_MENU();
|
||||
|
|
|
@ -77,21 +77,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
void update() override
|
||||
{
|
||||
using S_C = SELECTION_CONDITIONS;
|
||||
|
||||
const auto& selection = getToolManager()->GetTool<SELECTION_TOOL>()->GetSelection();
|
||||
|
||||
bool connItem = S_C::OnlyTypes( GENERAL_COLLECTOR::Tracks )( selection );
|
||||
bool sheetSelEnabled = ( S_C::OnlyType( PCB_MODULE_T ) )( selection );
|
||||
|
||||
Enable( PCB_ACTIONS::selectNet.GetUIId(), connItem );
|
||||
Enable( PCB_ACTIONS::selectConnection.GetUIId(), connItem );
|
||||
Enable( PCB_ACTIONS::selectSameSheet.GetUIId(), sheetSelEnabled );
|
||||
}
|
||||
|
||||
ACTION_MENU* create() const override
|
||||
{
|
||||
return new SELECT_MENU();
|
||||
|
|
Loading…
Reference in New Issue