Improve logic of Position Relative tool
Fixes https://gitlab.com/kicad/code/kicad/-/issues/12672
(cherry picked from commit 2d2912c23d
)
This commit is contained in:
parent
6c9d8f1ae7
commit
960c92634f
|
@ -37,6 +37,7 @@ using namespace std::placeholders;
|
|||
#include <pad.h>
|
||||
#include <footprint.h>
|
||||
#include <pcb_group.h>
|
||||
#include <pcbnew_settings.h>
|
||||
|
||||
|
||||
POSITION_RELATIVE_TOOL::POSITION_RELATIVE_TOOL() :
|
||||
|
@ -82,29 +83,24 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
|
|||
|
||||
m_selection = selection;
|
||||
|
||||
PCB_TYPE_COLLECTOR collector;
|
||||
collector.Collect( static_cast<BOARD_ITEM*>( m_selection.GetTopLeftItem() ), { PCB_PAD_T } );
|
||||
// We prefer footprints, then pads, then anything else here.
|
||||
EDA_ITEM* preferredItem = m_selection.GetTopLeftItem( true );
|
||||
|
||||
if( collector.GetCount() == 0 )
|
||||
if( !preferredItem && m_selection.HasType( PCB_PAD_T ) )
|
||||
{
|
||||
for( FOOTPRINT* footprint : editFrame->GetBoard()->Footprints() )
|
||||
{
|
||||
for( PAD* pad : footprint->Pads() )
|
||||
{
|
||||
if( pad->IsSelected() )
|
||||
collector.Append( pad );
|
||||
PCB_SELECTION padsOnly = m_selection;
|
||||
std::deque<EDA_ITEM*>& items = padsOnly.Items();
|
||||
items.erase( std::remove_if( items.begin(), items.end(),
|
||||
[]( const EDA_ITEM* aItem )
|
||||
{
|
||||
return aItem->Type() != PCB_PAD_T;
|
||||
} ), items.end() );
|
||||
|
||||
if( collector.GetCount() > 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
if( collector.GetCount() > 0 )
|
||||
break;
|
||||
}
|
||||
preferredItem = padsOnly.GetTopLeftItem();
|
||||
}
|
||||
|
||||
if( collector.GetCount() > 0 )
|
||||
m_selectionAnchor = collector[0]->GetPosition();
|
||||
if( preferredItem )
|
||||
m_selectionAnchor = preferredItem->GetPosition();
|
||||
else
|
||||
m_selectionAnchor = m_selection.GetTopLeftItem()->GetPosition();
|
||||
|
||||
|
@ -134,8 +130,12 @@ int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( const VECTOR2I& aPosAncho
|
|||
for( EDA_ITEM* item : m_selection )
|
||||
{
|
||||
// Don't move a pad by itself unless editing the footprint
|
||||
if( item->Type() == PCB_PAD_T && frame()->IsType( FRAME_PCB_EDITOR ) )
|
||||
if( item->Type() == PCB_PAD_T
|
||||
&& !frame()->GetPcbNewSettings()->m_AllowFreePads
|
||||
&& frame()->IsType( FRAME_PCB_EDITOR ) )
|
||||
{
|
||||
item = item->GetParent();
|
||||
}
|
||||
|
||||
m_commit->Modify( item );
|
||||
|
||||
|
|
Loading…
Reference in New Issue