KiCad PCB EDA Suite
Loading...
Searching...
No Matches
align_distribute_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 The 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef ALIGN_DISTRIBUTE_TOOL_H_
24#define ALIGN_DISTRIBUTE_TOOL_H_
25
27#include <tools/pcb_selection.h>
28#include <board_item.h>
29#include <pcb_base_frame.h>
30
31
33class BOARD_COMMIT;
34
36{
37public:
39 virtual ~ALIGN_DISTRIBUTE_TOOL();
40
42 void Reset( RESET_REASON aReason ) override {}
43
45 bool Init() override;
46
51 int AlignTop( const TOOL_EVENT& aEvent );
52
57 int AlignBottom( const TOOL_EVENT& aEvent );
58
63 int AlignLeft( const TOOL_EVENT& aEvent );
64
69 int AlignRight( const TOOL_EVENT& aEvent );
70
75 int AlignCenterX( const TOOL_EVENT& aEvent );
76
81 int AlignCenterY( const TOOL_EVENT& aEvent );
82
86 int DistributeItems( const TOOL_EVENT& aEvent );
87
89 void setTransitions() override;
90
91private:
97 template< typename T >
98 size_t GetSelections( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItemsToAlign,
99 std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aLockedItems,
100 T aCompare );
101
102 template< typename T >
103 int selectTarget( std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
104 std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aLocked, T aGetValue );
105
113 int doAlignLeft();
114
121 int doAlignRight();
122
131 void doDistributeCenters( bool aIsXAxis, std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
132 BOARD_COMMIT& aCommit ) const;
133
141 void doDistributeGaps( bool aIsXAxis, std::vector<std::pair<BOARD_ITEM*, BOX2I>>& aItems,
142 BOARD_COMMIT& aCommit ) const;
143
144private:
148};
149
150#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...
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.
bool Init() override
Init() is called once upon a registration of the tool.
void setTransitions() override
Set up handlers for various 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:74
Generic, UI-independent tool event.
Definition tool_event.h:167
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.