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
37class BOARD_COMMIT;
38
40{
41public:
43 virtual ~ALIGN_DISTRIBUTE_TOOL();
44
46 void Reset( RESET_REASON aReason ) override {}
47
49 bool Init() override;
50
55 int AlignTop( const TOOL_EVENT& aEvent );
56
61 int AlignBottom( const TOOL_EVENT& aEvent );
62
67 int AlignLeft( const TOOL_EVENT& aEvent );
68
73 int AlignRight( const TOOL_EVENT& aEvent );
74
79 int AlignCenterX( const TOOL_EVENT& aEvent );
80
85 int AlignCenterY( const TOOL_EVENT& aEvent );
86
90 int DistributeItems( const TOOL_EVENT& aEvent );
91
93 void setTransitions() override;
94
95private:
101 template< typename T >
102 size_t GetSelections( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItemsToAlign,
103 std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aLockedItems,
104 T aCompare );
105
106 template< typename T >
107 int selectTarget( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
108 std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aLocked, T aGetValue );
109
117 int doAlignLeft();
118
125 int doAlignRight();
126
135 void doDistributeCenters( bool aIsXAxis, std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
136 BOARD_COMMIT& aCommit ) const;
137
145 void doDistributeGaps( bool aIsXAxis, std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
146 BOARD_COMMIT& aCommit ) const;
147
148private:
152};
153
154#endif /* ALIGN_DISTRIBUTE_TOOL_H_ */
int AlignBottom(const TOOL_EVENT &aEvent)
Sets Y coordinate of the selected items to the value of the bottom-most selected item Y coordinate.
int DistributeItems(const TOOL_EVENT &aEvent)
Distribute the selected items in some way.
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
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.
CONDITIONAL_MENU * m_placementMenu
void doDistributeCenters(bool aIsXAxis, 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 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.
void doDistributeGaps(bool aIsXAxis, std::vector< std::pair< BOARD_ITEM *, BOX2I > > &aItems, BOARD_COMMIT &aCommit) const
Distributes selected items using an even spacing between their bounding boxe in the x or y axis.
virtual ~ALIGN_DISTRIBUTE_TOOL()
bool Init() override
Init() is called once upon a registration of the tool.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
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.
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