57 m_frame = getEditFrame<PCB_BASE_FRAME>();
93 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
97 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
98 rects.emplace_back( std::make_pair( boardItem,
103 rects.emplace_back( std::make_pair( boardItem, item->
GetBoundingBox() ) );
111 template<
typename T >
120 if( aLocked.size() >= 1 )
124 if( item.second.Contains( curPos ) )
125 return aGetValue( item );
128 return aGetValue( aLocked.front() );
133 if( item.second.Contains( curPos ) )
134 return aGetValue( item );
137 return aGetValue( aItems.front() );
141 template<
typename T >
149 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
154 aCollector.
Remove( item );
158 std::vector<BOARD_ITEM*> lockedItems;
159 std::vector<BOARD_ITEM*> itemsToAlign;
163 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
172 itemsToAlign.push_back( boardItem );
176 lockedItems.push_back( boardItem );
180 itemsToAlign.push_back( boardItem );
185 std::sort( aItemsToAlign.begin(), aItemsToAlign.end(), aCompare );
186 std::sort( aLockedItems.begin(), aLockedItems.end(), aCompare );
188 return aItemsToAlign.size();
200 return ( left.second.GetTop() < right.second.GetTop() );
208 int targetTop =
selectTarget( itemsToAlign, locked_items,
211 return aVal.second.GetTop();
215 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToAlign )
217 int difference = targetTop - i.second.GetTop();
225 item->
Move( wxPoint( 0, difference ) );
228 commit.
Push(
_(
"Align to top" ) );
242 return ( left.second.GetBottom() < right.second.GetBottom() );
250 int targetBottom =
selectTarget( itemsToAlign, locked_items,
253 return aVal.second.GetBottom();
257 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToAlign )
259 int difference = targetBottom - i.second.GetBottom();
267 item->
Move( wxPoint( 0, difference ) );
270 commit.
Push(
_(
"Align to bottom" ) );
299 return ( left.second.GetLeft() < right.second.GetLeft() );
307 int targetLeft =
selectTarget( itemsToAlign, locked_items,
310 return aVal.second.GetLeft();
314 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToAlign )
316 int difference = targetLeft - i.second.GetLeft();
324 item->
Move( wxPoint( difference, 0 ) );
327 commit.
Push(
_(
"Align to left" ) );
356 return ( left.second.GetRight() < right.second.GetRight() );
364 int targetRight =
selectTarget( itemsToAlign, locked_items,
367 return aVal.second.GetRight();
371 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToAlign )
373 int difference = targetRight - i.second.GetRight();
381 item->
Move( wxPoint( difference, 0 ) );
384 commit.
Push(
_(
"Align to right" ) );
398 return ( left.second.GetCenter().x < right.second.GetCenter().x );
409 return aVal.second.GetCenter().x;
413 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToAlign )
415 int difference = targetX - i.second.GetCenter().x;
423 item->
Move( wxPoint( difference, 0 ) );
426 commit.
Push(
_(
"Align to middle" ) );
440 return ( left.second.GetCenter().y < right.second.GetCenter().y );
451 return aVal.second.GetCenter().y;
455 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToAlign )
457 int difference = targetY - i.second.GetCenter().y;
465 item->
Move( wxPoint( 0, difference ) );
468 commit.
Push(
_(
"Align to center" ) );
480 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
485 aCollector.
Remove( item );
490 if( selection.
Size() <= 1 )
497 std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
500 return ( left.second.GetRight() > right.second.GetRight() );
503 BOARD_ITEM* lastItem = itemsToDistribute.begin()->first;
504 const int maxRight = itemsToDistribute.begin()->second.GetRight();
507 std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
510 return ( left.second.GetX() < right.second.GetX() );
513 const int minX = itemsToDistribute.begin()->second.
GetX();
514 int totalGap = maxRight - minX;
517 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToDistribute )
518 totalWidth += i.second.GetWidth();
520 if( totalGap < totalWidth )
527 totalGap -= totalWidth;
531 commit.
Push(
_(
"Distribute horizontally" ) );
542 const int itemGap = totalGap / ( itemsToDistribute.size() - 1 );
543 int targetX = itemsToDistribute.begin()->second.GetX();
545 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToDistribute )
550 if( lastItem == item )
557 int difference = targetX - i.second.
GetX();
559 item->
Move( wxPoint( difference, 0 ) );
560 targetX += ( i.second.GetWidth() + itemGap );
568 std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
571 return ( left.second.GetCenter().x < right.second.GetCenter().x );
574 const int totalGap = ( itemsToDistribute.end()-1 )->second.GetCenter().x
575 - itemsToDistribute.begin()->second.GetCenter().x;
576 const int itemGap = totalGap / ( itemsToDistribute.size() - 1 );
577 int targetX = itemsToDistribute.begin()->second.GetCenter().x;
579 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToDistribute )
587 int difference = targetX - i.second.
GetCenter().x;
589 item->
Move( wxPoint( difference, 0 ) );
590 targetX += ( itemGap );
601 for(
int i = aCollector.
GetCount() - 1; i >= 0; --i )
606 aCollector.
Remove( item );
611 if( selection.
Size() <= 1 )
618 std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
621 return ( left.second.GetBottom() > right.second.GetBottom() );
624 BOARD_ITEM* lastItem = itemsToDistribute.begin()->first;
625 const int maxBottom = itemsToDistribute.begin()->second.GetBottom();
628 std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
631 return ( left.second.GetCenter().y < right.second.GetCenter().y );
634 int minY = itemsToDistribute.begin()->second.
GetY();
635 int totalGap = maxBottom - minY;
638 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToDistribute )
639 totalHeight += i.second.GetHeight();
641 if( totalGap < totalHeight )
648 totalGap -= totalHeight;
652 commit.
Push(
_(
"Distribute vertically" ) );
663 const int itemGap = totalGap / ( itemsToDistribute.size() - 1 );
664 int targetY = itemsToDistribute.begin()->second.GetY();
666 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToDistribute )
671 if( lastItem == item )
678 int difference = targetY - i.second.
GetY();
680 item->
Move( wxPoint( 0, difference ) );
681 targetY += ( i.second.GetHeight() + itemGap );
689 std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
692 return ( left.second.GetCenter().y < right.second.GetCenter().y );
695 const int totalGap = ( itemsToDistribute.end()-1 )->second.GetCenter().y
696 - itemsToDistribute.begin()->second.GetCenter().y;
697 const int itemGap = totalGap / ( itemsToDistribute.size() - 1 );
698 int targetY = itemsToDistribute.begin()->second.GetCenter().y;
700 for( std::pair<BOARD_ITEM*, EDA_RECT>& i : itemsToDistribute )
708 int difference = targetY - i.second.
GetCenter().y;
710 item->
Move( wxPoint( 0, difference ) );
711 targetY += ( itemGap );
static TOOL_ACTION alignRight
This file is part of the common library.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
Class that computes missing connections on a PCB.
static TOOL_ACTION alignCenterY
class PAD, a pad in a footprint
static TOOL_ACTION distributeVertically
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
static TOOL_ACTION alignBottom
static TOOL_ACTION distributeHorizontally
int GetCount() const
Return the number of objects in the list.
virtual void Move(const wxPoint &aMoveVector)
Move this object.
const BITMAP_OPAQUE align_items_xpm[1]
static TOOL_ACTION alignLeft
virtual wxPoint GetCenter() const
This defaults to the center of the bounding box if not overridden.
static TOOL_ACTION alignTop
class FOOTPRINT, a footprint
virtual bool IsLocked() const
class MARKER_PCB, a marker used to show something
bool IsType(FRAME_T aType) const
Used when the right click button is pressed, or when the select tool is in effect.
int Size() const
Returns the number of selected parts.
A base class for most all the KiCad significant classes used in schematics and boards.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
BOARD_ITEM_CONTAINER * GetParent() const
static TOOL_ACTION alignCenterX
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType) override
KICAD_T Type() const
Returns the type of object.