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 typedef std::vector<std::pair<BOARD_ITEM*, EDA_RECT>> ALIGNMENT_RECTS;
33 
34 class SELECTION_TOOL;
35 
37 {
38 public:
40  virtual ~ALIGN_DISTRIBUTE_TOOL();
41 
43  void Reset( RESET_REASON aReason ) override {}
44 
46  bool Init() override;
47 
52  int AlignTop( const TOOL_EVENT& aEvent );
53 
58  int AlignBottom( const TOOL_EVENT& aEvent );
59 
64  int AlignLeft( const TOOL_EVENT& aEvent );
65 
70  int AlignRight( const TOOL_EVENT& aEvent );
71 
77  int AlignCenterX( const TOOL_EVENT& aEvent );
78 
84  int AlignCenterY( const TOOL_EVENT& aEvent );
85 
90  int DistributeHorizontally( const TOOL_EVENT& aEvent );
91 
96  int DistributeVertically( const TOOL_EVENT& aEvent );
97 
99  void setTransitions() override;
100 
101 private:
102 
109  int doAlignLeft();
110 
117  int doAlignRight();
118 
120 
122 
124 
133  int checkLockedStatus( const SELECTION &selection ) const;
134 
141  void doDistributeCentersHorizontally( ALIGNMENT_RECTS &itemsToDistribute ) const;
142 
149  void doDistributeCentersVertically( ALIGNMENT_RECTS &itemsToDistribute ) const;
150 
157  void doDistributeGapsHorizontally( ALIGNMENT_RECTS &itemsToDistribute,
158  const BOARD_ITEM *lastItem,
159  int totalGap ) const;
160 
167  void doDistributeGapsVertically( ALIGNMENT_RECTS &itemsToDistribute,
168  const BOARD_ITEM *lastItem,
169  int totalGap ) const;
170 };
171 
172 #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 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...
std::vector< std::pair< BOARD_ITEM *, EDA_RECT > > ALIGNMENT_RECTS
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...
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.
PCB_BASE_FRAME * m_frame
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...