89 const std::vector<ITEM_BOX>& aLocked,
T aGetValue )
93 if( !aLocked.empty() )
95 for(
const ITEM_BOX& item : aLocked )
97 if( item.second.Contains( cursorPos ) )
98 return aGetValue( item );
101 return aGetValue( aLocked.front() );
104 for(
const ITEM_BOX& item : aItems )
106 if( item.second.Contains( cursorPos ) )
107 return aGetValue( item );
110 return aGetValue( aItems.front() );
114template<
typename T >
116 std::vector<ITEM_BOX>& aLockedItems,
T aCompare )
122 if( !item->IsSCH_ITEM() )
133 aLockedItems.emplace_back( schItem, bbox );
135 aItemsToAlign.emplace_back( schItem, bbox );
138 std::sort( aItemsToAlign.begin(), aItemsToAlign.end(), aCompare );
139 std::sort( aLockedItems.begin(), aLockedItems.end(), aCompare );
141 return aItemsToAlign.size();
174 VECTOR2I snappedPos =
grid.AlignGrid( desiredPos, gridType );
193 std::vector<ITEM_BOX> itemsToAlign;
194 std::vector<ITEM_BOX> lockedItems;
199 return lhs.second.GetTop() < rhs.second.GetTop();
207 int targetTop =
selectTarget( itemsToAlign, lockedItems,
210 return item.second.GetTop();
213 for(
const ITEM_BOX& item : itemsToAlign )
215 int difference = targetTop - item.second.GetTop();
221 commit.
Push(
_(
"Align to Top" ) );
228 std::vector<ITEM_BOX> itemsToAlign;
229 std::vector<ITEM_BOX> lockedItems;
234 return lhs.second.GetBottom() > rhs.second.GetBottom();
242 int targetBottom =
selectTarget( itemsToAlign, lockedItems,
245 return item.second.GetBottom();
248 for(
const ITEM_BOX& item : itemsToAlign )
250 int difference = targetBottom - item.second.GetBottom();
256 commit.
Push(
_(
"Align to Bottom" ) );
263 std::vector<ITEM_BOX> itemsToAlign;
264 std::vector<ITEM_BOX> lockedItems;
269 return lhs.second.GetLeft() < rhs.second.GetLeft();
277 int targetLeft =
selectTarget( itemsToAlign, lockedItems,
280 return item.second.GetLeft();
283 for(
const ITEM_BOX& item : itemsToAlign )
285 int difference = targetLeft - item.second.GetLeft();
291 commit.
Push(
_(
"Align to Left" ) );
298 std::vector<ITEM_BOX> itemsToAlign;
299 std::vector<ITEM_BOX> lockedItems;
304 return lhs.second.GetRight() > rhs.second.GetRight();
312 int targetRight =
selectTarget( itemsToAlign, lockedItems,
315 return item.second.GetRight();
318 for(
const ITEM_BOX& item : itemsToAlign )
320 int difference = targetRight - item.second.GetRight();
326 commit.
Push(
_(
"Align to Right" ) );
333 std::vector<ITEM_BOX> itemsToAlign;
334 std::vector<ITEM_BOX> lockedItems;
339 return lhs.second.Centre().x < rhs.second.Centre().x;
350 return item.second.Centre().x;
353 for(
const ITEM_BOX& item : itemsToAlign )
355 int difference = targetX - item.second.Centre().x;
361 commit.
Push(
_(
"Align to Middle" ) );
368 std::vector<ITEM_BOX> itemsToAlign;
369 std::vector<ITEM_BOX> lockedItems;
374 return lhs.second.Centre().y < rhs.second.Centre().y;
385 return item.second.Centre().y;
388 for(
const ITEM_BOX& item : itemsToAlign )
390 int difference = targetY - item.second.Centre().y;
396 commit.
Push(
_(
"Align to Center" ) );
407 for(
const ITEM_BOX& item : aItems )
408 alignedItems.
Add( item.first );
414 item->ClearTempFlags();
416 m_frame->Schematic().CleanUp( &aCommit );
419 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
virtual bool IsLocked() 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,...
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