85 const std::vector<ITEM_BOX>& aLocked,
T aGetValue )
89 if( !aLocked.empty() )
91 for(
const ITEM_BOX& item : aLocked )
93 if( item.second.Contains( cursorPos ) )
94 return aGetValue( item );
97 return aGetValue( aLocked.front() );
100 for(
const ITEM_BOX& item : aItems )
102 if( item.second.Contains( cursorPos ) )
103 return aGetValue( item );
106 return aGetValue( aItems.front() );
110template<
typename T >
112 std::vector<ITEM_BOX>& aLockedItems,
T aCompare )
118 if( !item->IsSCH_ITEM() )
129 aLockedItems.emplace_back( schItem, bbox );
131 aItemsToAlign.emplace_back( schItem, bbox );
134 std::sort( aItemsToAlign.begin(), aItemsToAlign.end(), aCompare );
135 std::sort( aLockedItems.begin(), aLockedItems.end(), aCompare );
137 return aItemsToAlign.size();
170 VECTOR2I snappedPos =
grid.AlignGrid( desiredPos, gridType );
189 std::vector<ITEM_BOX> itemsToAlign;
190 std::vector<ITEM_BOX> lockedItems;
195 return lhs.second.GetTop() < rhs.second.GetTop();
203 int targetTop =
selectTarget( itemsToAlign, lockedItems,
206 return item.second.GetTop();
209 for(
const ITEM_BOX& item : itemsToAlign )
211 int difference = targetTop - item.second.GetTop();
217 commit.
Push(
_(
"Align to Top" ) );
224 std::vector<ITEM_BOX> itemsToAlign;
225 std::vector<ITEM_BOX> lockedItems;
230 return lhs.second.GetBottom() > rhs.second.GetBottom();
238 int targetBottom =
selectTarget( itemsToAlign, lockedItems,
241 return item.second.GetBottom();
244 for(
const ITEM_BOX& item : itemsToAlign )
246 int difference = targetBottom - item.second.GetBottom();
252 commit.
Push(
_(
"Align to Bottom" ) );
259 std::vector<ITEM_BOX> itemsToAlign;
260 std::vector<ITEM_BOX> lockedItems;
265 return lhs.second.GetLeft() < rhs.second.GetLeft();
273 int targetLeft =
selectTarget( itemsToAlign, lockedItems,
276 return item.second.GetLeft();
279 for(
const ITEM_BOX& item : itemsToAlign )
281 int difference = targetLeft - item.second.GetLeft();
287 commit.
Push(
_(
"Align to Left" ) );
294 std::vector<ITEM_BOX> itemsToAlign;
295 std::vector<ITEM_BOX> lockedItems;
300 return lhs.second.GetRight() > rhs.second.GetRight();
308 int targetRight =
selectTarget( itemsToAlign, lockedItems,
311 return item.second.GetRight();
314 for(
const ITEM_BOX& item : itemsToAlign )
316 int difference = targetRight - item.second.GetRight();
322 commit.
Push(
_(
"Align to Right" ) );
329 std::vector<ITEM_BOX> itemsToAlign;
330 std::vector<ITEM_BOX> lockedItems;
335 return lhs.second.Centre().x < rhs.second.Centre().x;
346 return item.second.Centre().x;
349 for(
const ITEM_BOX& item : itemsToAlign )
351 int difference = targetX - item.second.Centre().x;
357 commit.
Push(
_(
"Align to Middle" ) );
364 std::vector<ITEM_BOX> itemsToAlign;
365 std::vector<ITEM_BOX> lockedItems;
370 return lhs.second.Centre().y < rhs.second.Centre().y;
381 return item.second.Centre().y;
384 for(
const ITEM_BOX& item : itemsToAlign )
386 int difference = targetY - item.second.Centre().y;
392 commit.
Push(
_(
"Align to Center" ) );
403 for(
const ITEM_BOX& item : aItems )
404 alignedItems.
Add( item.first );
410 item->ClearTempFlags();
412 m_frame->Schematic().CleanUp( &aCommit );
415 item->ClearEditFlags();
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
A base class for most all the KiCad significant classes used in schematics and boards.
virtual VECTOR2I GetPosition() const
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
EDA_ITEM * GetParent() const
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
static TOOL_ACTION alignTop
static TOOL_ACTION alignRight
static TOOL_ACTION alignBottom
static TOOL_ACTION alignLeft
static TOOL_ACTION alignCenterX
static TOOL_ACTION alignCenterY
static const std::vector< KICAD_T > MovableItems
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
bool IsLocked() const override
virtual void Move(const VECTOR2I &aMoveVector)
Move the item by aMoveVector to a new position.
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...
virtual void Add(EDA_ITEM *aItem)
#define IS_MOVING
Item being moved.
VECTOR2< int32_t > VECTOR2I