2014-07-09 12:23:13 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-06-21 15:06:28 +00:00
|
|
|
* Copyright (C) 2014-2016 CERN
|
2022-08-30 14:13:51 +00:00
|
|
|
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-07-09 12:23:13 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2018-01-31 21:24:32 +00:00
|
|
|
#include "tool/selection.h"
|
2014-07-09 12:23:13 +00:00
|
|
|
#include "placement_tool.h"
|
2017-02-21 12:42:08 +00:00
|
|
|
#include "pcb_actions.h"
|
2020-12-16 13:31:32 +00:00
|
|
|
#include "pcb_selection_tool.h"
|
2020-06-16 18:15:14 +00:00
|
|
|
|
|
|
|
#include <ratsnest/ratsnest_data.h>
|
2015-05-05 18:39:41 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <bitmaps.h>
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <geometry/distribute.h>
|
2024-04-27 19:57:24 +00:00
|
|
|
#include <view/view_controls.h>
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
ALIGN_DISTRIBUTE_TOOL::ALIGN_DISTRIBUTE_TOOL() :
|
2021-07-19 23:56:05 +00:00
|
|
|
TOOL_INTERACTIVE( "pcbnew.Placement" ),
|
|
|
|
m_selectionTool( nullptr ),
|
|
|
|
m_placementMenu( nullptr ),
|
|
|
|
m_frame( nullptr )
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
ALIGN_DISTRIBUTE_TOOL::~ALIGN_DISTRIBUTE_TOOL()
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
2015-07-24 07:42:46 +00:00
|
|
|
delete m_placementMenu;
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
bool ALIGN_DISTRIBUTE_TOOL::Init()
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
|
|
|
// Find the selection tool, so they can cooperate
|
2020-12-16 13:31:32 +00:00
|
|
|
m_selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
2018-10-10 05:00:07 +00:00
|
|
|
m_frame = getEditFrame<PCB_BASE_FRAME>();
|
|
|
|
|
2014-07-09 12:23:13 +00:00
|
|
|
// Create a context menu and make it available through selection tool
|
2024-05-04 19:28:47 +00:00
|
|
|
m_placementMenu = new CONDITIONAL_MENU( this );
|
2021-03-08 02:59:07 +00:00
|
|
|
m_placementMenu->SetIcon( BITMAPS::align_items );
|
2018-02-09 16:28:33 +00:00
|
|
|
m_placementMenu->SetTitle( _( "Align/Distribute" ) );
|
2016-12-20 16:50:29 +00:00
|
|
|
|
2024-05-04 19:28:47 +00:00
|
|
|
const auto canAlign = SELECTION_CONDITIONS::MoreThan( 1 );
|
|
|
|
const auto canDistribute = SELECTION_CONDITIONS::MoreThan( 2 );
|
|
|
|
|
2017-01-23 09:59:56 +00:00
|
|
|
// Add all align/distribute commands
|
2024-05-04 19:28:47 +00:00
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::alignLeft, canAlign );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::alignCenterX, canAlign );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::alignRight, canAlign );
|
|
|
|
|
|
|
|
m_placementMenu->AddSeparator( canAlign );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::alignTop, canAlign );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::alignCenterY, canAlign );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::alignBottom, canAlign );
|
|
|
|
|
|
|
|
m_placementMenu->AddSeparator( canDistribute );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::distributeHorizontallyCenters, canDistribute );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::distributeHorizontallyGaps, canDistribute );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::distributeVerticallyCenters, canDistribute );
|
|
|
|
m_placementMenu->AddItem( PCB_ACTIONS::distributeVerticallyGaps, canDistribute );
|
2016-12-20 16:50:29 +00:00
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
2022-09-03 18:29:02 +00:00
|
|
|
selToolMenu.AddMenu( m_placementMenu, SELECTION_CONDITIONS::MoreThan( 1 ), 100 );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-14 12:22:00 +00:00
|
|
|
template <class T>
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> GetBoundingBoxes( const T& aItems )
|
2018-01-31 21:24:32 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> rects;
|
2018-01-31 21:24:32 +00:00
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
for( EDA_ITEM* item : aItems )
|
2018-12-14 12:22:00 +00:00
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
|
|
|
|
|
|
|
|
wxCHECK2( boardItem, continue );
|
2018-02-17 10:36:41 +00:00
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
if( item->Type() == PCB_FOOTPRINT_T )
|
2020-12-27 14:11:41 +00:00
|
|
|
{
|
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
|
2022-08-30 14:13:51 +00:00
|
|
|
rects.emplace_back( std::make_pair( footprint,
|
2021-02-26 13:49:40 +00:00
|
|
|
footprint->GetBoundingBox( false, false ) ) );
|
2020-12-27 14:11:41 +00:00
|
|
|
}
|
2018-12-14 12:22:00 +00:00
|
|
|
else
|
2020-12-27 14:11:41 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
rects.emplace_back( std::make_pair( boardItem, boardItem->GetBoundingBox() ) );
|
2020-12-27 14:11:41 +00:00
|
|
|
}
|
2018-12-14 12:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rects;
|
2018-01-31 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 10:36:41 +00:00
|
|
|
|
2018-12-14 12:22:00 +00:00
|
|
|
template< typename T >
|
2022-08-30 14:13:51 +00:00
|
|
|
int ALIGN_DISTRIBUTE_TOOL::selectTarget( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aLocked,
|
2020-12-27 14:11:41 +00:00
|
|
|
T aGetValue )
|
2018-01-31 21:24:32 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
VECTOR2I curPos = getViewControls()->GetCursorPosition();
|
2018-01-31 21:24:32 +00:00
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
// Prefer locked items to unlocked items.
|
|
|
|
// Secondly, prefer items under the cursor to other items.
|
2018-02-17 10:36:41 +00:00
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
if( aLocked.size() >= 1 )
|
2018-12-14 12:22:00 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
for( const std::pair<BOARD_ITEM*, BOX2I>& item : aLocked )
|
2018-12-14 12:22:00 +00:00
|
|
|
{
|
2020-01-07 04:01:21 +00:00
|
|
|
if( item.second.Contains( curPos ) )
|
|
|
|
return aGetValue( item );
|
2018-12-14 12:22:00 +00:00
|
|
|
}
|
2020-12-27 15:00:47 +00:00
|
|
|
|
|
|
|
return aGetValue( aLocked.front() );
|
|
|
|
}
|
|
|
|
|
2022-08-30 14:13:51 +00:00
|
|
|
for( const std::pair<BOARD_ITEM*, BOX2I>& item : aItems )
|
2020-12-27 15:00:47 +00:00
|
|
|
{
|
|
|
|
if( item.second.Contains( curPos ) )
|
|
|
|
return aGetValue( item );
|
2018-12-14 12:22:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
return aGetValue( aItems.front() );
|
2018-02-08 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 10:36:41 +00:00
|
|
|
|
2018-12-14 12:22:00 +00:00
|
|
|
template< typename T >
|
2022-08-30 14:13:51 +00:00
|
|
|
size_t ALIGN_DISTRIBUTE_TOOL::GetSelections( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItemsToAlign,
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aLockedItems,
|
|
|
|
T aCompare )
|
2018-01-31 21:24:32 +00:00
|
|
|
{
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
|
2020-12-10 01:33:24 +00:00
|
|
|
{
|
2020-12-15 22:32:02 +00:00
|
|
|
// Iterate from the back so we don't have to worry about removals.
|
|
|
|
for( int i = aCollector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = aCollector[i];
|
|
|
|
|
|
|
|
if( item->Type() == PCB_MARKER_T )
|
|
|
|
aCollector.Remove( item );
|
|
|
|
}
|
2020-12-10 01:33:24 +00:00
|
|
|
} );
|
2018-02-17 10:36:41 +00:00
|
|
|
|
2018-12-14 12:22:00 +00:00
|
|
|
std::vector<BOARD_ITEM*> lockedItems;
|
2020-12-27 15:00:47 +00:00
|
|
|
std::vector<BOARD_ITEM*> itemsToAlign;
|
2020-12-10 17:34:26 +00:00
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
|
|
|
|
wxCHECK2( boardItem, continue );
|
2020-12-10 17:34:26 +00:00
|
|
|
|
2021-06-29 23:46:25 +00:00
|
|
|
// We do not lock items in the footprint editor
|
|
|
|
if( boardItem->IsLocked() && m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2021-01-08 21:18:52 +00:00
|
|
|
{
|
|
|
|
// Locking a pad but not the footprint means that we align the footprint using
|
|
|
|
// the pad position. So we test for footprint locking here
|
2021-06-29 23:46:25 +00:00
|
|
|
if( boardItem->Type() == PCB_PAD_T && !boardItem->GetParent()->IsLocked() )
|
2021-01-08 21:18:52 +00:00
|
|
|
itemsToAlign.push_back( boardItem );
|
|
|
|
else
|
|
|
|
lockedItems.push_back( boardItem );
|
|
|
|
}
|
2020-12-27 15:00:47 +00:00
|
|
|
else
|
|
|
|
itemsToAlign.push_back( boardItem );
|
2020-12-10 17:34:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
aItemsToAlign = GetBoundingBoxes( itemsToAlign );
|
|
|
|
aLockedItems = GetBoundingBoxes( lockedItems );
|
|
|
|
std::sort( aItemsToAlign.begin(), aItemsToAlign.end(), aCompare );
|
|
|
|
std::sort( aLockedItems.begin(), aLockedItems.end(), aCompare );
|
2018-02-17 10:36:41 +00:00
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
return aItemsToAlign.size();
|
2018-01-31 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
int ALIGN_DISTRIBUTE_TOOL::AlignTop( const TOOL_EVENT& aEvent )
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> itemsToAlign;
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> locked_items;
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2020-12-10 17:34:26 +00:00
|
|
|
if( !GetSelections( itemsToAlign, locked_items,
|
2023-07-15 16:37:17 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& lhs, const std::pair<BOARD_ITEM*, BOX2I>& rhs )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
return ( lhs.second.GetTop() < rhs.second.GetTop() );
|
2020-12-10 17:34:26 +00:00
|
|
|
} ) )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
return 0;
|
2020-12-10 17:34:26 +00:00
|
|
|
}
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2018-10-10 05:00:07 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2020-12-27 15:00:47 +00:00
|
|
|
|
2020-12-10 17:34:26 +00:00
|
|
|
int targetTop = selectTarget( itemsToAlign, locked_items,
|
2022-08-30 14:13:51 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& aVal )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
|
|
|
return aVal.second.GetTop();
|
|
|
|
} );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
// Move the selected items
|
2022-08-30 14:13:51 +00:00
|
|
|
for( const std::pair<BOARD_ITEM*, BOX2I>& i : itemsToAlign )
|
2016-06-21 15:06:28 +00:00
|
|
|
{
|
2018-02-28 23:13:21 +00:00
|
|
|
BOARD_ITEM* item = i.first;
|
2021-04-02 20:52:06 +00:00
|
|
|
int difference = targetTop - i.second.GetTop();
|
|
|
|
|
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
2018-02-28 23:13:21 +00:00
|
|
|
|
|
|
|
// Don't move a pad by itself unless editing the footprint
|
2019-09-05 22:00:47 +00:00
|
|
|
if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2018-02-28 23:13:21 +00:00
|
|
|
item = item->GetParent();
|
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
commit.Stage( item, CHT_MODIFY );
|
2022-08-30 14:13:51 +00:00
|
|
|
item->Move( VECTOR2I( 0, difference ) );
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Align to Top" ) );
|
2014-07-09 12:23:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
int ALIGN_DISTRIBUTE_TOOL::AlignBottom( const TOOL_EVENT& aEvent )
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> itemsToAlign;
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> locked_items;
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2020-12-10 17:34:26 +00:00
|
|
|
if( !GetSelections( itemsToAlign, locked_items,
|
2023-07-15 16:37:17 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& lhs, const std::pair<BOARD_ITEM*, BOX2I>& rhs)
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
return ( lhs.second.GetBottom() > rhs.second.GetBottom() );
|
2020-12-10 17:34:26 +00:00
|
|
|
} ) )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
return 0;
|
2020-12-10 17:34:26 +00:00
|
|
|
}
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2018-10-10 05:00:07 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2020-12-27 15:00:47 +00:00
|
|
|
|
|
|
|
int targetBottom = selectTarget( itemsToAlign, locked_items,
|
2022-08-30 14:13:51 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& aVal )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
|
|
|
return aVal.second.GetBottom();
|
|
|
|
} );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
// Move the selected items
|
2022-08-30 14:13:51 +00:00
|
|
|
for( const std::pair<BOARD_ITEM*, BOX2I>& i : itemsToAlign )
|
2016-06-21 15:06:28 +00:00
|
|
|
{
|
2018-02-08 14:47:24 +00:00
|
|
|
int difference = targetBottom - i.second.GetBottom();
|
2018-02-28 23:13:21 +00:00
|
|
|
BOARD_ITEM* item = i.first;
|
|
|
|
|
2021-04-02 20:52:06 +00:00
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2018-02-28 23:13:21 +00:00
|
|
|
// Don't move a pad by itself unless editing the footprint
|
2019-09-05 22:00:47 +00:00
|
|
|
if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2018-02-28 23:13:21 +00:00
|
|
|
item = item->GetParent();
|
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
commit.Stage( item, CHT_MODIFY );
|
2022-08-30 14:13:51 +00:00
|
|
|
item->Move( VECTOR2I( 0, difference ) );
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Align to Bottom" ) );
|
2014-07-09 12:23:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
int ALIGN_DISTRIBUTE_TOOL::AlignLeft( const TOOL_EVENT& aEvent )
|
2017-12-09 19:16:27 +00:00
|
|
|
{
|
|
|
|
// Because this tool uses bounding boxes and they aren't mirrored even when
|
|
|
|
// the view is mirrored, we need to call the other one if mirrored.
|
|
|
|
if( getView()->IsMirroredX() )
|
|
|
|
return doAlignRight();
|
|
|
|
else
|
|
|
|
return doAlignLeft();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ALIGN_DISTRIBUTE_TOOL::doAlignLeft()
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> itemsToAlign;
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> locked_items;
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2020-12-10 17:34:26 +00:00
|
|
|
if( !GetSelections( itemsToAlign, locked_items,
|
2023-07-15 16:37:17 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& lhs, const std::pair<BOARD_ITEM*, BOX2I>& rhs )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
return ( lhs.second.GetLeft() < rhs.second.GetLeft() );
|
2020-12-10 17:34:26 +00:00
|
|
|
} ) )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
return 0;
|
2020-12-10 17:34:26 +00:00
|
|
|
}
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2018-10-10 05:00:07 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2020-12-27 15:00:47 +00:00
|
|
|
|
|
|
|
int targetLeft = selectTarget( itemsToAlign, locked_items,
|
2022-08-30 14:13:51 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& aVal )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
|
|
|
return aVal.second.GetLeft();
|
|
|
|
} );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
// Move the selected items
|
2022-08-30 14:13:51 +00:00
|
|
|
for( const std::pair<BOARD_ITEM*, BOX2I>& i : itemsToAlign )
|
2016-06-21 15:06:28 +00:00
|
|
|
{
|
2018-12-14 12:22:00 +00:00
|
|
|
int difference = targetLeft - i.second.GetLeft();
|
2018-02-28 23:13:21 +00:00
|
|
|
BOARD_ITEM* item = i.first;
|
|
|
|
|
2021-04-02 20:52:06 +00:00
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2018-02-28 23:13:21 +00:00
|
|
|
// Don't move a pad by itself unless editing the footprint
|
2019-09-05 22:00:47 +00:00
|
|
|
if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2018-02-28 23:13:21 +00:00
|
|
|
item = item->GetParent();
|
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
commit.Stage( item, CHT_MODIFY );
|
2022-08-30 14:13:51 +00:00
|
|
|
item->Move( VECTOR2I( difference, 0 ) );
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Align to Left" ) );
|
2014-07-09 12:23:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
int ALIGN_DISTRIBUTE_TOOL::AlignRight( const TOOL_EVENT& aEvent )
|
2017-12-09 19:16:27 +00:00
|
|
|
{
|
|
|
|
// Because this tool uses bounding boxes and they aren't mirrored even when
|
|
|
|
// the view is mirrored, we need to call the other one if mirrored.
|
|
|
|
if( getView()->IsMirroredX() )
|
|
|
|
return doAlignLeft();
|
|
|
|
else
|
|
|
|
return doAlignRight();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ALIGN_DISTRIBUTE_TOOL::doAlignRight()
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> itemsToAlign;
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> locked_items;
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2020-12-10 17:34:26 +00:00
|
|
|
if( !GetSelections( itemsToAlign, locked_items,
|
2023-07-15 16:37:17 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& lhs, const std::pair<BOARD_ITEM*, BOX2I>& rhs )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
return ( lhs.second.GetRight() > rhs.second.GetRight() );
|
2020-12-10 17:34:26 +00:00
|
|
|
} ) )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
return 0;
|
2020-12-10 17:34:26 +00:00
|
|
|
}
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2018-10-10 05:00:07 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2020-12-27 15:00:47 +00:00
|
|
|
|
|
|
|
int targetRight = selectTarget( itemsToAlign, locked_items,
|
2022-08-30 14:13:51 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& aVal )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
|
|
|
return aVal.second.GetRight();
|
|
|
|
} );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
// Move the selected items
|
2022-08-30 14:13:51 +00:00
|
|
|
for( const std::pair<BOARD_ITEM*, BOX2I>& i : itemsToAlign )
|
2016-06-21 15:06:28 +00:00
|
|
|
{
|
2018-02-08 14:47:24 +00:00
|
|
|
int difference = targetRight - i.second.GetRight();
|
2018-02-28 23:13:21 +00:00
|
|
|
BOARD_ITEM* item = i.first;
|
|
|
|
|
2021-04-02 20:52:06 +00:00
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2018-02-28 23:13:21 +00:00
|
|
|
// Don't move a pad by itself unless editing the footprint
|
2019-09-05 22:00:47 +00:00
|
|
|
if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2018-02-28 23:13:21 +00:00
|
|
|
item = item->GetParent();
|
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
commit.Stage( item, CHT_MODIFY );
|
2022-08-30 14:13:51 +00:00
|
|
|
item->Move( VECTOR2I( difference, 0 ) );
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Align to Right" ) );
|
2014-07-09 12:23:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 16:01:36 +00:00
|
|
|
int ALIGN_DISTRIBUTE_TOOL::AlignCenterX( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> itemsToAlign;
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> locked_items;
|
2018-02-08 16:01:36 +00:00
|
|
|
|
2020-12-10 17:34:26 +00:00
|
|
|
if( !GetSelections( itemsToAlign, locked_items,
|
2023-07-15 16:37:17 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& lhs, const std::pair<BOARD_ITEM*, BOX2I>& rhs )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
return ( lhs.second.Centre().x < rhs.second.Centre().x );
|
2020-12-10 17:34:26 +00:00
|
|
|
} ) )
|
|
|
|
{
|
2018-02-08 16:01:36 +00:00
|
|
|
return 0;
|
2020-12-10 17:34:26 +00:00
|
|
|
}
|
2018-02-08 16:01:36 +00:00
|
|
|
|
2018-10-10 05:00:07 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2020-12-27 15:00:47 +00:00
|
|
|
|
|
|
|
int targetX = selectTarget( itemsToAlign, locked_items,
|
2022-08-30 14:13:51 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& aVal )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
return aVal.second.Centre().x;
|
2020-12-10 17:34:26 +00:00
|
|
|
} );
|
2018-02-08 16:01:36 +00:00
|
|
|
|
|
|
|
// Move the selected items
|
2022-08-30 14:13:51 +00:00
|
|
|
for( const std::pair<BOARD_ITEM*, BOX2I>& i : itemsToAlign )
|
2018-02-08 16:01:36 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
int difference = targetX - i.second.Centre().x;
|
2018-02-28 23:13:21 +00:00
|
|
|
BOARD_ITEM* item = i.first;
|
|
|
|
|
2021-04-02 20:52:06 +00:00
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2018-02-28 23:13:21 +00:00
|
|
|
// Don't move a pad by itself unless editing the footprint
|
2019-09-05 22:00:47 +00:00
|
|
|
if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2018-02-28 23:13:21 +00:00
|
|
|
item = item->GetParent();
|
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
commit.Stage( item, CHT_MODIFY );
|
2022-08-30 14:13:51 +00:00
|
|
|
item->Move( VECTOR2I( difference, 0 ) );
|
2018-02-08 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Align to Middle" ) );
|
2018-02-08 16:01:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ALIGN_DISTRIBUTE_TOOL::AlignCenterY( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> itemsToAlign;
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> locked_items;
|
2018-02-08 16:01:36 +00:00
|
|
|
|
2020-12-10 17:34:26 +00:00
|
|
|
if( !GetSelections( itemsToAlign, locked_items,
|
2023-07-15 16:37:17 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& lhs, const std::pair<BOARD_ITEM*, BOX2I>& rhs )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
return ( lhs.second.Centre().y < rhs.second.Centre().y );
|
2020-12-10 17:34:26 +00:00
|
|
|
} ) )
|
|
|
|
{
|
2018-02-08 16:01:36 +00:00
|
|
|
return 0;
|
2020-12-10 17:34:26 +00:00
|
|
|
}
|
2018-02-08 16:01:36 +00:00
|
|
|
|
2018-10-10 05:00:07 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2020-12-27 15:00:47 +00:00
|
|
|
|
|
|
|
int targetY = selectTarget( itemsToAlign, locked_items,
|
2022-08-30 14:13:51 +00:00
|
|
|
[]( const std::pair<BOARD_ITEM*, BOX2I>& aVal )
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
return aVal.second.Centre().y;
|
2020-12-10 17:34:26 +00:00
|
|
|
} );
|
2018-02-08 16:01:36 +00:00
|
|
|
|
|
|
|
// Move the selected items
|
2022-08-30 14:13:51 +00:00
|
|
|
for( const std::pair<BOARD_ITEM*, BOX2I>& i : itemsToAlign )
|
2018-02-08 16:01:36 +00:00
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
int difference = targetY - i.second.Centre().y;
|
2018-02-28 23:13:21 +00:00
|
|
|
BOARD_ITEM* item = i.first;
|
|
|
|
|
2021-04-02 20:52:06 +00:00
|
|
|
if( item->GetParent() && item->GetParent()->IsSelected() )
|
|
|
|
continue;
|
|
|
|
|
2018-02-28 23:13:21 +00:00
|
|
|
// Don't move a pad by itself unless editing the footprint
|
2019-09-05 22:00:47 +00:00
|
|
|
if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2018-02-28 23:13:21 +00:00
|
|
|
item = item->GetParent();
|
|
|
|
|
2020-12-27 15:00:47 +00:00
|
|
|
commit.Stage( item, CHT_MODIFY );
|
2022-08-30 14:13:51 +00:00
|
|
|
item->Move( VECTOR2I( 0, difference ) );
|
2018-02-08 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Align to Center" ) );
|
2018-02-08 16:01:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
int ALIGN_DISTRIBUTE_TOOL::DistributeItems( const TOOL_EVENT& aEvent )
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION& selection = m_selectionTool->RequestSelection(
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector,
|
|
|
|
PCB_SELECTION_TOOL* sTool )
|
2020-12-10 01:33:24 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
sTool->FilterCollectorForMarkers( aCollector );
|
|
|
|
sTool->FilterCollectorForHierarchy( aCollector, true );
|
|
|
|
sTool->FilterCollectorForFreePads( aCollector );
|
2020-12-10 01:33:24 +00:00
|
|
|
},
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
m_frame->IsType( FRAME_PCB_EDITOR ) /* prompt user regarding locked items */
|
|
|
|
);
|
2014-07-09 12:23:13 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
// Need at least 3 items to distribute - one at each end and at least on in the middle
|
|
|
|
if( selection.Size() < 3 )
|
2016-06-21 15:06:28 +00:00
|
|
|
return 0;
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2022-08-30 14:13:51 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
wxString commitMsg;
|
2022-08-30 14:13:51 +00:00
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>> itemsToDistribute = GetBoundingBoxes( selection );
|
2016-12-09 11:04:32 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
if( aEvent.Matches( PCB_ACTIONS::distributeHorizontallyCenters.MakeEvent() ) )
|
|
|
|
{
|
|
|
|
doDistributeCenters( true, itemsToDistribute, commit );
|
|
|
|
commitMsg = PCB_ACTIONS::distributeHorizontallyCenters.GetFriendlyName();
|
|
|
|
}
|
|
|
|
else if( aEvent.Matches( PCB_ACTIONS::distributeHorizontallyGaps.MakeEvent() ) )
|
|
|
|
{
|
|
|
|
doDistributeGaps( true, itemsToDistribute, commit );
|
|
|
|
commitMsg = PCB_ACTIONS::distributeHorizontallyGaps.GetFriendlyName();
|
|
|
|
}
|
|
|
|
else if( aEvent.Matches( PCB_ACTIONS::distributeVerticallyCenters.MakeEvent() ) )
|
2018-02-26 20:54:33 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
doDistributeCenters( false, itemsToDistribute, commit );
|
|
|
|
commitMsg = PCB_ACTIONS::distributeVerticallyCenters.GetFriendlyName();
|
2018-02-26 20:54:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
doDistributeGaps( false, itemsToDistribute, commit );
|
|
|
|
commitMsg = PCB_ACTIONS::distributeVerticallyGaps.GetFriendlyName();
|
2018-02-26 20:54:33 +00:00
|
|
|
}
|
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
commit.Push( commitMsg );
|
2018-02-26 20:54:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-09 12:23:13 +00:00
|
|
|
|
2018-02-26 20:54:33 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
void ALIGN_DISTRIBUTE_TOOL::doDistributeGaps( bool aIsXAxis,
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
|
|
|
|
BOARD_COMMIT& aCommit ) const
|
2018-02-26 20:54:33 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
// Sort by start position.
|
|
|
|
// This is a simple way to get the items in a sensible order but it's not perfect.
|
|
|
|
// It will fail if, say, there's a huge items that's bigger than the total span of
|
|
|
|
// all the other items, but at that point a gap-equalising algorithm probably isn't
|
|
|
|
// well-defined anyway.
|
|
|
|
std::sort( aItems.begin(), aItems.end(),
|
|
|
|
[&]( const std::pair<BOARD_ITEM*, BOX2I>& a, const std::pair<BOARD_ITEM*, BOX2I>& b )
|
|
|
|
{
|
|
|
|
return aIsXAxis ? a.second.GetLeft() < b.second.GetLeft()
|
|
|
|
: a.second.GetTop() < b.second.GetTop();
|
|
|
|
} );
|
2021-04-02 20:52:06 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
// Consruct list of item spans in the relevant axis
|
|
|
|
std::vector<std::pair<int, int>> itemSpans;
|
|
|
|
itemSpans.reserve( aItems.size() );
|
2018-10-10 05:00:07 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
for( const auto& [item, box] : aItems )
|
|
|
|
{
|
|
|
|
const int start = aIsXAxis ? box.GetLeft() : box.GetTop();
|
|
|
|
const int end = aIsXAxis ? box.GetRight() : box.GetBottom();
|
|
|
|
itemSpans.emplace_back( start, end );
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|
2020-12-27 15:00:47 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
// Get the deltas needed to distribute the items evenly
|
|
|
|
const std::vector<int> deltas = GetDeltasForDistributeByGaps( itemSpans );
|
2018-02-26 20:54:33 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
// Apply the deltas to the items
|
|
|
|
for( size_t i = 1; i < aItems.size() - 1; ++i )
|
2018-10-10 05:00:07 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
const auto& [item, box] = aItems[i];
|
|
|
|
const int delta = deltas[i];
|
2021-04-02 20:52:06 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
if( delta != 0 )
|
|
|
|
{
|
|
|
|
const VECTOR2I deltaVec = aIsXAxis ? VECTOR2I( delta, 0 ) : VECTOR2I( 0, delta );
|
2018-10-10 05:00:07 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
aCommit.Stage( item, CHT_MODIFY );
|
|
|
|
item->Move( deltaVec );
|
|
|
|
}
|
2018-10-10 05:00:07 +00:00
|
|
|
}
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
void ALIGN_DISTRIBUTE_TOOL::doDistributeCenters( bool aIsXAxis,
|
|
|
|
std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
|
|
|
|
BOARD_COMMIT& aCommit ) const
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
std::sort(
|
|
|
|
aItems.begin(), aItems.end(),
|
|
|
|
[&]( const std::pair<BOARD_ITEM*, BOX2I>& lhs, const std::pair<BOARD_ITEM*, BOX2I>& rhs )
|
2020-12-10 01:33:24 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
const int lhsPos = aIsXAxis ? lhs.second.Centre().x : lhs.second.Centre().y;
|
|
|
|
const int rhsPos = aIsXAxis ? rhs.second.Centre().x : rhs.second.Centre().y;
|
|
|
|
return lhsPos < rhsPos;
|
2023-07-15 16:37:17 +00:00
|
|
|
} );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
std::vector<int> itemCenters;
|
|
|
|
itemCenters.reserve( aItems.size() );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
for( const auto& [item, box] : aItems )
|
2018-02-26 20:54:33 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
itemCenters.push_back( aIsXAxis ? box.Centre().x : box.Centre().y );
|
2018-02-26 20:54:33 +00:00
|
|
|
}
|
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
const std::vector<int> deltas = GetDeltasForDistributeByPoints( itemCenters );
|
2014-07-09 12:23:13 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
// Apply the deltas to the items
|
|
|
|
for( size_t i = 1; i < aItems.size() - 1; ++i )
|
2016-06-21 15:06:28 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
const auto& [item, box] = aItems[i];
|
|
|
|
const int delta = deltas[i];
|
2014-07-09 12:23:13 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
if ( delta != 0)
|
2020-12-10 17:34:26 +00:00
|
|
|
{
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
const VECTOR2I deltaVec = aIsXAxis ? VECTOR2I( delta, 0 ) : VECTOR2I( 0, delta );
|
2021-04-02 20:52:06 +00:00
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
aCommit.Stage( item, CHT_MODIFY );
|
|
|
|
item->Move( deltaVec );
|
|
|
|
}
|
2018-02-26 20:54:33 +00:00
|
|
|
}
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void ALIGN_DISTRIBUTE_TOOL::setTransitions()
|
2014-07-09 12:23:13 +00:00
|
|
|
{
|
2019-06-09 22:32:08 +00:00
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::AlignTop, PCB_ACTIONS::alignTop.MakeEvent() );
|
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::AlignBottom, PCB_ACTIONS::alignBottom.MakeEvent() );
|
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::AlignLeft, PCB_ACTIONS::alignLeft.MakeEvent() );
|
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::AlignRight, PCB_ACTIONS::alignRight.MakeEvent() );
|
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::AlignCenterX, PCB_ACTIONS::alignCenterX.MakeEvent() );
|
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::AlignCenterY, PCB_ACTIONS::alignCenterY.MakeEvent() );
|
|
|
|
|
Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.
The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.
The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.
This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.
Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-04 07:41:21 +00:00
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::DistributeItems,
|
|
|
|
PCB_ACTIONS::distributeHorizontallyCenters.MakeEvent() );
|
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::DistributeItems,
|
|
|
|
PCB_ACTIONS::distributeHorizontallyGaps.MakeEvent() );
|
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::DistributeItems,
|
|
|
|
PCB_ACTIONS::distributeVerticallyCenters.MakeEvent() );
|
|
|
|
Go( &ALIGN_DISTRIBUTE_TOOL::DistributeItems,
|
|
|
|
PCB_ACTIONS::distributeVerticallyGaps.MakeEvent() );
|
2014-07-09 12:23:13 +00:00
|
|
|
}
|