KiCad PCB EDA Suite
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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef ALIGN_DISTRIBUTE_TOOL_H_
26 #define ALIGN_DISTRIBUTE_TOOL_H_
27 
28 #include <tool/tool_interactive.h>
29 #include <tools/pcbnew_selection.h>
30 #include <class_board_item.h>
31 #include <pcb_base_frame.h>
32 
33 using ALIGNMENT_RECT = std::pair<BOARD_ITEM*, EDA_RECT>;
34 using ALIGNMENT_RECTS = std::vector<ALIGNMENT_RECT>;
35 
36 class SELECTION_TOOL;
37 
39 {
40 public:
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 
79  int AlignCenterX( const TOOL_EVENT& aEvent );
80 
86  int AlignCenterY( const TOOL_EVENT& aEvent );
87 
92  int DistributeHorizontally( const TOOL_EVENT& aEvent );
93 
98  int DistributeVertically( const TOOL_EVENT& aEvent );
99 
101  void setTransitions() override;
102 
103 private:
104 
110  template< typename T >
111  size_t GetSelections( ALIGNMENT_RECTS& aItems, ALIGNMENT_RECTS& aLocked, T aCompare );
112 
113  template< typename T >
114  int selectTarget( ALIGNMENT_RECTS& aItems, ALIGNMENT_RECTS& aLocked, T aGetValue );
115 
122  int doAlignLeft();
123 
130  int doAlignRight();
131 
133 
135 
137 
146  int checkLockedStatus( const PCBNEW_SELECTION &selection ) const;
147 
154  void doDistributeCentersHorizontally( ALIGNMENT_RECTS &itemsToDistribute ) const;
155 
162  void doDistributeCentersVertically( ALIGNMENT_RECTS &itemsToDistribute ) const;
163 
170  void doDistributeGapsHorizontally( ALIGNMENT_RECTS &itemsToDistribute,
171  const BOARD_ITEM *lastItem,
172  int totalGap ) const;
173 
180  void doDistributeGapsVertically( ALIGNMENT_RECTS &itemsToDistribute,
181  const BOARD_ITEM *lastItem,
182  int totalGap ) const;
183 };
184 
185 #endif /* ALIGN_DISTRIBUTE_TOOL_H_ */
int AlignLeft(const TOOL_EVENT &aEvent)
Function AlignLeft() Sets X coordinate of the selected items to the value of the left-most selected i...
void doDistributeGapsHorizontally(ALIGNMENT_RECTS &itemsToDistribute, const BOARD_ITEM *lastItem, int totalGap) const
Distributes selected items using an even spacing between their bounding boxes.
int selectTarget(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aGetValue)
int AlignCenterY(const TOOL_EVENT &aEvent)
Function AlignCenterX() Sets the y coordinate of the midpoint of each of the selected items to the va...
ACTION_MENU.
Definition: action_menu.h:44
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
int AlignCenterX(const TOOL_EVENT &aEvent)
Function AlignCenterX() Sets the x coordinate of the midpoint of each of the selected items to the va...
virtual ~ALIGN_DISTRIBUTE_TOOL()
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
ACTION_MENU * m_placementMenu
SELECTION_TOOL.
void doDistributeCentersVertically(ALIGNMENT_RECTS &itemsToDistribute) const
Distributes selected items using an even spacing between the centers of their bounding boxes.
int AlignBottom(const TOOL_EVENT &aEvent)
Function AlignBottom() Sets Y coordinate of the selected items to the value of the bottom-most select...
T
enum T contains all this lexer's tokens.
Classes used in Pcbnew, CvPcb and GerbView.
int DistributeHorizontally(const TOOL_EVENT &aEvent)
Function DistributeHorizontally() Distributes the selected items along the X axis.
int doAlignRight()
Aligns selected items using the right edge of their bounding boxes to the right-most item.
int doAlignLeft()
Sets X coordinate of the selected items to the value of the left-most selected item X coordinate.
std::vector< ALIGNMENT_RECT > ALIGNMENT_RECTS
int AlignTop(const TOOL_EVENT &aEvent)
Function AlignTop() Sets Y coordinate of the selected items to the value of the top-most selected ite...
TOOL_EVENT.
Definition: tool_event.h:171
int DistributeVertically(const TOOL_EVENT &aEvent)
Function DistributeVertically() Distributes the selected items along the Y axis.
void doDistributeCentersHorizontally(ALIGNMENT_RECTS &itemsToDistribute) const
Distributes selected items using an even spacing between the centers of their bounding boxes.
size_t GetSelections(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aCompare)
Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Retu...
PCB_BASE_FRAME * m_frame
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
void setTransitions() override
Sets up handlers for various events.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
void doDistributeGapsVertically(ALIGNMENT_RECTS &itemsToDistribute, const BOARD_ITEM *lastItem, int totalGap) const
Distributes selected items using an even spacing between their bounding boxes.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
SELECTION_TOOL * m_selectionTool
int AlignRight(const TOOL_EVENT &aEvent)
Function AlignRight() Sets X coordinate of the selected items to the value of the right-most selected...
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
int checkLockedStatus(const PCBNEW_SELECTION &selection) const
Check a selection to ensure locks are valid for alignment.
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.