KiCad PCB EDA Suite
Loading...
Searching...
No Matches
placement_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 (C) 2014 CERN
5 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#ifndef ALIGN_DISTRIBUTE_TOOL_H_
28#define ALIGN_DISTRIBUTE_TOOL_H_
29
31#include <tools/pcb_selection.h>
32#include <board_item.h>
33#include <pcb_base_frame.h>
34
35
37
39{
40public:
42 virtual ~ALIGN_DISTRIBUTE_TOOL();
43
45 void Reset( RESET_REASON aReason ) override {}
46
48 bool Init() override;
49
54 int AlignTop( const TOOL_EVENT& aEvent );
55
60 int AlignBottom( const TOOL_EVENT& aEvent );
61
66 int AlignLeft( const TOOL_EVENT& aEvent );
67
72 int AlignRight( const TOOL_EVENT& aEvent );
73
78 int AlignCenterX( const TOOL_EVENT& aEvent );
79
84 int AlignCenterY( const TOOL_EVENT& aEvent );
85
89 int DistributeHorizontally( const TOOL_EVENT& aEvent );
90
94 int DistributeVertically( const TOOL_EVENT& aEvent );
95
97 void setTransitions() override;
98
99private:
105 template< typename T >
106 size_t GetSelections( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItemsToAlign,
107 std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aLockedItems,
108 T aCompare );
109
110 template< typename T >
111 int selectTarget( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
112 std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aLocked, T aGetValue );
113
121 int doAlignLeft();
122
129 int doAlignRight();
130
139 void doDistributeCentersHorizontally( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
140 BOARD_COMMIT& aCommit ) const;
141
150 void doDistributeCentersVertically( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
151 BOARD_COMMIT& aCommit ) const;
152
159 void doDistributeGapsHorizontally( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
160 BOARD_COMMIT& aCommit, const BOARD_ITEM* lastItem,
161 int totalGap ) const;
162
169 void doDistributeGapsVertically( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
170 BOARD_COMMIT& aCommit, const BOARD_ITEM* lastItem,
171 int totalGap ) const;
172
173private:
177};
178
179#endif /* ALIGN_DISTRIBUTE_TOOL_H_ */
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void doDistributeGapsVertically(std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aItems, BOARD_COMMIT &aCommit, const BOARD_ITEM *lastItem, int totalGap) const
Distributes selected items using an even spacing between their bounding boxes.
int AlignBottom(const TOOL_EVENT &aEvent)
Sets Y coordinate of the selected items to the value of the bottom-most selected item Y coordinate.
PCB_SELECTION_TOOL * m_selectionTool
size_t GetSelections(std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aItemsToAlign, std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aLockedItems, T aCompare)
Populate two vectors with the sorted selection and sorted locked items.
int AlignCenterX(const TOOL_EVENT &aEvent)
Set the x coordinate of the midpoint of each of the selected items to the value of the x coordinate o...
PCB_BASE_FRAME * m_frame
void doDistributeGapsHorizontally(std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aItems, BOARD_COMMIT &aCommit, const BOARD_ITEM *lastItem, int totalGap) const
Distributes selected items using an even spacing between their bounding boxes.
int AlignTop(const TOOL_EVENT &aEvent)
Set Y coordinate of the selected items to the value of the top-most selected item Y coordinate.
int doAlignLeft()
Sets X coordinate of the selected items to the value of the left-most selected item X coordinate.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int selectTarget(std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aItems, std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aLocked, T aGetValue)
int AlignCenterY(const TOOL_EVENT &aEvent)
Set the y coordinate of the midpoint of each of the selected items to the value of the y coordinate o...
int AlignRight(const TOOL_EVENT &aEvent)
Sets X coordinate of the selected items to the value of the right-most selected item X coordinate.
virtual ~ALIGN_DISTRIBUTE_TOOL()
void doDistributeCentersHorizontally(std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aItems, BOARD_COMMIT &aCommit) const
Distribute selected items using an even spacing between the centers of their bounding boxes.
int DistributeVertically(const TOOL_EVENT &aEvent)
Distribute the selected items along the Y axis.
bool Init() override
Init() is called once upon a registration of the tool.
int DistributeHorizontally(const TOOL_EVENT &aEvent)
Distribute the selected items along the X axis.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void doDistributeCentersVertically(std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aItems, BOARD_COMMIT &aCommit) const
Distribute selected items using an even spacing between the centers of their bounding boxes.
int doAlignRight()
Align selected items using the right edge of their bounding boxes to the right-most item.
int AlignLeft(const TOOL_EVENT &aEvent)
Sets X coordinate of the selected items to the value of the left-most selected item X coordinate.
ACTION_MENU * m_placementMenu
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
The selection tool: currently supports:
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167