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 <class_board_item.h>
30 #include <pcb_base_frame.h>
31 
32 using ALIGNMENT_RECT = std::pair<BOARD_ITEM*, EDA_RECT>;
33 using ALIGNMENT_RECTS = std::vector<ALIGNMENT_RECT>;
34 
35 class SELECTION_TOOL;
36 
38 {
39 public:
41  virtual ~ALIGN_DISTRIBUTE_TOOL();
42 
44  void Reset( RESET_REASON aReason ) override {}
45 
47  bool Init() override;
48 
53  int AlignTop( const TOOL_EVENT& aEvent );
54 
59  int AlignBottom( const TOOL_EVENT& aEvent );
60 
65  int AlignLeft( const TOOL_EVENT& aEvent );
66 
71  int AlignRight( const TOOL_EVENT& aEvent );
72 
78  int AlignCenterX( const TOOL_EVENT& aEvent );
79 
85  int AlignCenterY( const TOOL_EVENT& aEvent );
86 
91  int DistributeHorizontally( const TOOL_EVENT& aEvent );
92 
97  int DistributeVertically( const TOOL_EVENT& aEvent );
98 
100  void setTransitions() override;
101 
102 private:
103 
109  template< typename T >
110  size_t GetSelections( ALIGNMENT_RECTS& aItems, ALIGNMENT_RECTS& aLocked, T aCompare );
111 
112  template< typename T >
113  int selectTarget( ALIGNMENT_RECTS& aItems, ALIGNMENT_RECTS& aLocked, T aGetValue );
114 
121  int doAlignLeft();
122 
129  int doAlignRight();
130 
132 
134 
136 
145  int checkLockedStatus( const SELECTION &selection ) const;
146 
153  void doDistributeCentersHorizontally( ALIGNMENT_RECTS &itemsToDistribute ) const;
154 
161  void doDistributeCentersVertically( ALIGNMENT_RECTS &itemsToDistribute ) const;
162 
169  void doDistributeGapsHorizontally( ALIGNMENT_RECTS &itemsToDistribute,
170  const BOARD_ITEM *lastItem,
171  int totalGap ) const;
172 
179  void doDistributeGapsVertically( ALIGNMENT_RECTS &itemsToDistribute,
180  const BOARD_ITEM *lastItem,
181  int totalGap ) const;
182 };
183 
184 #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...
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...
Class 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...
Class CONTEXT_MENU.
Definition: context_menu.h:44
virtual ~ALIGN_DISTRIBUTE_TOOL()
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
Class SELECTION_TOOL.
void doDistributeCentersHorizontally(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...
void doDistributeCentersVertically(ALIGNMENT_RECTS &itemsToDistribute) const
Distributes selected items using an even spacing between the centers of their bounding boxes...
CONTEXT_MENU * m_placementMenu
Classes used in Pcbnew, CvPcb and GerbView.
int DistributeHorizontally(const TOOL_EVENT &aEvent)
Function DistributeHorizontally() Distributes the selected items along the X axis.
void doDistributeGapsVertically(ALIGNMENT_RECTS &itemsToDistribute, const BOARD_ITEM *lastItem, int totalGap) const
Distributes selected items using an even spacing between their bounding boxes.
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...
Class TOOL_EVENT.
Definition: tool_event.h:168
int DistributeVertically(const TOOL_EVENT &aEvent)
Function DistributeVertically() Distributes the selected items along the Y axis.
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 doDistributeGapsHorizontally(ALIGNMENT_RECTS &itemsToDistribute, const BOARD_ITEM *lastItem, int totalGap) const
Distributes selected items using an even spacing between their bounding boxes.
int checkLockedStatus(const SELECTION &selection) const
Check a selection to ensure locks are valid for alignment.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
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.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...