KiCad PCB EDA Suite
pcb_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) 2016 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@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 __PCB_TOOL_H
26 #define __PCB_TOOL_H
27 
28 #include <string>
29 
30 #include <tool/tool_event.h>
31 #include <tool/tool_interactive.h>
32 #include <pcb_edit_frame.h>
33 #include <class_board.h>
34 #include <view/view_group.h>
35 #include <pcb_view.h>
36 
37 #include <functional>
38 
39 
46 class PCB_TOOL;
47 class PCB_EDIT_FRAME;
49 class PCB_DRAW_PANEL_GAL;
50 class SELECTION;
51 
53 {
54  virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
55  virtual void SnapItem( BOARD_ITEM *aItem );
56  virtual void PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit );
57 
61 };
62 
63 
64 class PCB_TOOL : public TOOL_INTERACTIVE
65 {
66 public:
71  PCB_TOOL( TOOL_ID aId, const std::string& aName ) :
72  TOOL_INTERACTIVE ( aId, aName ),
73  m_editModules( false ) {};
74 
79  PCB_TOOL( const std::string& aName ) :
80  TOOL_INTERACTIVE ( aName ),
81  m_editModules( false ) {};
82 
83  virtual ~PCB_TOOL() {};
84 
85  virtual void Reset( RESET_REASON aReason ) override;
86 
94  void SetEditModules( bool aEnabled )
95  {
96  m_editModules = aEnabled;
97  }
98 
99  bool EditingModules() const
100  {
101  return m_editModules;
102  }
103 
104 protected:
105 
107  IPO_ROTATE = 1,
108  IPO_FLIP = 2,
109  IPO_PROPERTIES = 4,
110  IPO_SINGLE_CLICK = 8,
111  IPO_REPEAT = 16
112  };
113 
114 
127  void doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE *aPlacer,
128  const wxString& aCommitMessage,
129  int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
130 
131  virtual void setTransitions() override;
132 
133 
134  KIGFX::PCB_VIEW* view() const { return static_cast<KIGFX::PCB_VIEW*>( getView() ); }
135  KIGFX::VIEW_CONTROLS* controls() const { return getViewControls(); }
136  PCB_EDIT_FRAME* frame() const { return getEditFrame<PCB_EDIT_FRAME>(); }
137  BOARD* board() const { return getModel<BOARD>(); }
138  MODULE* module() const { return board()->m_Modules; }
139  PCB_DISPLAY_OPTIONS* displayOptions() const;
140  PCB_DRAW_PANEL_GAL* canvas() const;
141  const SELECTION& selection() const;
142  SELECTION& selection();
143 
145 };
146 
147 #endif
virtual void PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
Definition: pcb_tool.cpp:241
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
Class BOARD to handle a board.
PCB_EDIT_FRAME * m_frame
Definition: pcb_tool.h:58
INTERACTIVE_PLACEMENT_OPTIONS
Definition: pcb_tool.h:106
virtual void SnapItem(BOARD_ITEM *aItem)
Definition: pcb_tool.cpp:236
KIGFX::VIEW_CONTROLS * controls() const
Definition: pcb_tool.h:135
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:57
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
virtual ~PCB_TOOL()
Definition: pcb_tool.h:83
PCB_TOOL(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool.h:71
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:136
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
MODULE * module() const
Definition: pcb_tool.h:138
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
bool m_editModules
Definition: pcb_tool.h:144
bool EditingModules() const
Definition: pcb_tool.h:99
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
KIGFX::PCB_VIEW * view() const
Definition: pcb_tool.h:134
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
PCB_TOOL(const std::string &aName)
Constructor.
Definition: pcb_tool.h:79
void SetEditModules(bool aEnabled)
Function SetEditModules()
Definition: pcb_tool.h:94
BOARD * board() const
Definition: pcb_tool.h:137