Move lock checks to CLIENT_SELECTION_FILTER.
Also checks render item visibility as well as layer visibility when making selections. Fixes: lp:1066220 * https://bugs.launchpad.net/kicad/+bug/1066220 Fixes: lp:1541756 * https://bugs.launchpad.net/kicad/+bug/1541756
This commit is contained in:
+24
-108
@@ -183,90 +183,18 @@ ALIGNMENT_RECTS GetBoundingBoxes( const SELECTION &sel )
|
||||
}
|
||||
|
||||
|
||||
void ALIGN_DISTRIBUTE_TOOL::filterPadsWithModules( SELECTION &selection )
|
||||
{
|
||||
std::set<BOARD_ITEM*> rejected;
|
||||
for( auto i : selection )
|
||||
{
|
||||
auto item = static_cast<BOARD_ITEM*>( i );
|
||||
if( item->Type() == PCB_PAD_T )
|
||||
{
|
||||
MODULE* mod = static_cast<MODULE*>( item->GetParent() );
|
||||
|
||||
// selection contains both the module and its pads - remove the pads
|
||||
if( mod && selection.Contains( mod ) )
|
||||
rejected.insert( item );
|
||||
}
|
||||
}
|
||||
|
||||
for( BOARD_ITEM* item : rejected )
|
||||
selection.Remove( item );
|
||||
}
|
||||
|
||||
|
||||
int ALIGN_DISTRIBUTE_TOOL::checkLockedStatus( const SELECTION &selection ) const
|
||||
{
|
||||
SELECTION moving_items( selection );
|
||||
|
||||
// Remove the anchor from the list
|
||||
moving_items.Remove( moving_items.Front() );
|
||||
|
||||
bool containsLocked = false;
|
||||
|
||||
// Check if the selection contains locked items
|
||||
for( const auto& item : moving_items )
|
||||
{
|
||||
switch ( item->Type() )
|
||||
{
|
||||
case PCB_MODULE_T:
|
||||
if( static_cast< MODULE* >( item )->IsLocked() )
|
||||
containsLocked = true;
|
||||
break;
|
||||
|
||||
case PCB_PAD_T:
|
||||
case PCB_MODULE_EDGE_T:
|
||||
case PCB_MODULE_TEXT_T:
|
||||
if( static_cast< MODULE* >( item->GetParent() )->IsLocked() )
|
||||
containsLocked = true;
|
||||
break;
|
||||
|
||||
default: // suppress warnings
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( containsLocked )
|
||||
{
|
||||
KIDIALOG dlg( getEditFrame< PCB_EDIT_FRAME >(),
|
||||
_( "Selection contains locked items. Do you want to continue?" ),
|
||||
_( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
||||
dlg.SetOKLabel( _( "Continue" ) );
|
||||
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
||||
|
||||
if( dlg.ShowModal() == wxID_OK )
|
||||
return SELECTION_LOCK_OVERRIDE;
|
||||
else
|
||||
return SELECTION_LOCKED;
|
||||
}
|
||||
|
||||
return SELECTION_UNLOCKED;
|
||||
}
|
||||
|
||||
|
||||
int ALIGN_DISTRIBUTE_TOOL::AlignTop( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
SELECTION& selection = m_selectionTool->RequestSelection( EnsureEditableFilter );
|
||||
SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
||||
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } );
|
||||
|
||||
if( selection.Size() <= 1 )
|
||||
return 0;
|
||||
|
||||
filterPadsWithModules( selection );
|
||||
|
||||
auto itemsToAlign = GetBoundingBoxes( selection );
|
||||
std::sort( itemsToAlign.begin(), itemsToAlign.end(), SortTopmostY );
|
||||
if( checkLockedStatus( selection ) == SELECTION_LOCKED )
|
||||
return 0;
|
||||
|
||||
BOARD_COMMIT commit( frame );
|
||||
commit.StageItems( selection, CHT_MODIFY );
|
||||
@@ -296,17 +224,15 @@ int ALIGN_DISTRIBUTE_TOOL::AlignTop( const TOOL_EVENT& aEvent )
|
||||
int ALIGN_DISTRIBUTE_TOOL::AlignBottom( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
SELECTION& selection = m_selectionTool->RequestSelection( EnsureEditableFilter );
|
||||
SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
||||
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } );
|
||||
|
||||
if( selection.Size() <= 1 )
|
||||
return 0;
|
||||
|
||||
filterPadsWithModules( selection );
|
||||
|
||||
auto itemsToAlign = GetBoundingBoxes( selection );
|
||||
std::sort( itemsToAlign.begin(), itemsToAlign.end(), SortBottommostY );
|
||||
if( checkLockedStatus( selection ) == SELECTION_LOCKED )
|
||||
return 0;
|
||||
|
||||
BOARD_COMMIT commit( frame );
|
||||
commit.StageItems( selection, CHT_MODIFY );
|
||||
@@ -351,17 +277,15 @@ int ALIGN_DISTRIBUTE_TOOL::AlignLeft( const TOOL_EVENT& aEvent )
|
||||
int ALIGN_DISTRIBUTE_TOOL::doAlignLeft()
|
||||
{
|
||||
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
SELECTION& selection = m_selectionTool->RequestSelection( EnsureEditableFilter );
|
||||
SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
||||
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } );
|
||||
|
||||
if( selection.Size() <= 1 )
|
||||
return 0;
|
||||
|
||||
filterPadsWithModules( selection );
|
||||
|
||||
auto itemsToAlign = GetBoundingBoxes( selection );
|
||||
std::sort( itemsToAlign.begin(), itemsToAlign.end(), SortLeftmostX );
|
||||
if( checkLockedStatus( selection ) == SELECTION_LOCKED )
|
||||
return 0;
|
||||
|
||||
BOARD_COMMIT commit( frame );
|
||||
commit.StageItems( selection, CHT_MODIFY );
|
||||
@@ -406,17 +330,15 @@ int ALIGN_DISTRIBUTE_TOOL::AlignRight( const TOOL_EVENT& aEvent )
|
||||
int ALIGN_DISTRIBUTE_TOOL::doAlignRight()
|
||||
{
|
||||
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
SELECTION& selection = m_selectionTool->RequestSelection( EnsureEditableFilter );
|
||||
SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
||||
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } );
|
||||
|
||||
if( selection.Size() <= 1 )
|
||||
return 0;
|
||||
|
||||
filterPadsWithModules( selection );
|
||||
|
||||
auto itemsToAlign = GetBoundingBoxes( selection );
|
||||
std::sort( itemsToAlign.begin(), itemsToAlign.end(), SortRightmostX );
|
||||
if( checkLockedStatus( selection ) == SELECTION_LOCKED )
|
||||
return 0;
|
||||
|
||||
BOARD_COMMIT commit( frame );
|
||||
commit.StageItems( selection, CHT_MODIFY );
|
||||
@@ -446,17 +368,15 @@ int ALIGN_DISTRIBUTE_TOOL::doAlignRight()
|
||||
int ALIGN_DISTRIBUTE_TOOL::AlignCenterX( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
SELECTION& selection = m_selectionTool->RequestSelection( EnsureEditableFilter );
|
||||
SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
||||
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } );
|
||||
|
||||
if( selection.Size() <= 1 )
|
||||
return 0;
|
||||
|
||||
filterPadsWithModules( selection );
|
||||
|
||||
auto itemsToAlign = GetBoundingBoxes( selection );
|
||||
std::sort( itemsToAlign.begin(), itemsToAlign.end(), SortCenterX );
|
||||
if( checkLockedStatus( selection ) == SELECTION_LOCKED )
|
||||
return 0;
|
||||
|
||||
BOARD_COMMIT commit( frame );
|
||||
commit.StageItems( selection, CHT_MODIFY );
|
||||
@@ -487,17 +407,15 @@ int ALIGN_DISTRIBUTE_TOOL::AlignCenterX( const TOOL_EVENT& aEvent )
|
||||
int ALIGN_DISTRIBUTE_TOOL::AlignCenterY( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
SELECTION& selection = m_selectionTool->RequestSelection( EnsureEditableFilter );
|
||||
SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
||||
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } );
|
||||
|
||||
if( selection.Size() <= 1 )
|
||||
return 0;
|
||||
|
||||
filterPadsWithModules( selection );
|
||||
|
||||
auto itemsToAlign = GetBoundingBoxes( selection );
|
||||
std::sort( itemsToAlign.begin(), itemsToAlign.end(), SortCenterY );
|
||||
if( checkLockedStatus( selection ) == SELECTION_LOCKED )
|
||||
return 0;
|
||||
|
||||
BOARD_COMMIT commit( frame );
|
||||
commit.StageItems( selection, CHT_MODIFY );
|
||||
@@ -528,14 +446,13 @@ int ALIGN_DISTRIBUTE_TOOL::AlignCenterY( const TOOL_EVENT& aEvent )
|
||||
int ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
SELECTION& selection = m_selectionTool->RequestSelection( EnsureEditableFilter );
|
||||
SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
||||
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } );
|
||||
|
||||
if( selection.Size() <= 1 )
|
||||
return 0;
|
||||
|
||||
if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
|
||||
return 0;
|
||||
|
||||
BOARD_COMMIT commit( frame );
|
||||
commit.StageItems( selection, CHT_MODIFY );
|
||||
|
||||
@@ -614,14 +531,13 @@ void ALIGN_DISTRIBUTE_TOOL::doDistributeCentersHorizontally( ALIGNMENT_RECTS &it
|
||||
int ALIGN_DISTRIBUTE_TOOL::DistributeVertically( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
auto frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
SELECTION& selection = m_selectionTool->RequestSelection( EnsureEditableFilter );
|
||||
SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
|
||||
{ EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } );
|
||||
|
||||
if( selection.Size() <= 1 )
|
||||
return 0;
|
||||
|
||||
if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
|
||||
return 0;
|
||||
|
||||
BOARD_COMMIT commit( frame );
|
||||
commit.StageItems( selection, CHT_MODIFY );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user