KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_align_tool.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html,
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25
26#include <vector>
27
28#include <math/box2.h>
29#include <tools/sch_tool_base.h>
30
32class SCH_ITEM;
33class SCH_COMMIT;
34
35
36class SCH_ALIGN_TOOL : public SCH_TOOL_BASE<SCH_EDIT_FRAME>
37{
38public:
40 ~SCH_ALIGN_TOOL() override;
41
42 bool Init() override;
43
44 int AlignTop( const TOOL_EVENT& aEvent );
45 int AlignBottom( const TOOL_EVENT& aEvent );
46 int AlignLeft( const TOOL_EVENT& aEvent );
47 int AlignRight( const TOOL_EVENT& aEvent );
48 int AlignCenterX( const TOOL_EVENT& aEvent );
49 int AlignCenterY( const TOOL_EVENT& aEvent );
50
51private:
52 using ITEM_BOX = std::pair<SCH_ITEM*, BOX2I>;
53
54 template< typename T >
55 int selectTarget( const std::vector<ITEM_BOX>& aItems, const std::vector<ITEM_BOX>& aLocked,
56 T aGetValue );
57
58 template< typename T >
59 size_t GetSelections( std::vector<ITEM_BOX>& aItemsToAlign, std::vector<ITEM_BOX>& aLockedItems,
60 T aCompare );
61
62 void moveItem( SCH_ITEM* aItem, const VECTOR2I& aDelta, SCH_COMMIT& aCommit );
63 VECTOR2I adjustDeltaForGrid( SCH_ITEM* aItem, const VECTOR2I& aDelta );
64 void setTransitions() override;
65
66private:
68};
69
int AlignTop(const TOOL_EVENT &aEvent)
int AlignLeft(const TOOL_EVENT &aEvent)
int selectTarget(const std::vector< ITEM_BOX > &aItems, const std::vector< ITEM_BOX > &aLocked, T aGetValue)
~SCH_ALIGN_TOOL() override
size_t GetSelections(std::vector< ITEM_BOX > &aItemsToAlign, std::vector< ITEM_BOX > &aLockedItems, T aCompare)
bool Init() override
Init() is called once upon a registration of the tool.
int AlignBottom(const TOOL_EVENT &aEvent)
VECTOR2I adjustDeltaForGrid(SCH_ITEM *aItem, const VECTOR2I &aDelta)
CONDITIONAL_MENU * m_alignMenu
int AlignRight(const TOOL_EVENT &aEvent)
std::pair< SCH_ITEM *, BOX2I > ITEM_BOX
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int AlignCenterY(const TOOL_EVENT &aEvent)
int AlignCenterX(const TOOL_EVENT &aEvent)
void moveItem(SCH_ITEM *aItem, const VECTOR2I &aDelta, SCH_COMMIT &aCommit)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
SCH_TOOL_BASE(const std::string &aName)
Generic, UI-independent tool event.
Definition tool_event.h:171
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695