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 <wxPcbStruct.h>
33 #include <class_board.h>
34 #include <view/view_group.h>
35 
36 #include <functional>
37 
38 
45 class PCB_TOOL : public TOOL_INTERACTIVE
46 {
47 public:
52  PCB_TOOL( TOOL_ID aId, const std::string& aName ) :
53  TOOL_INTERACTIVE ( aId, aName ),
54  m_editModules( false ) {};
55 
60  PCB_TOOL( const std::string& aName ) :
61  TOOL_INTERACTIVE ( aName ),
62  m_editModules( false ) {};
63 
64  virtual ~PCB_TOOL() {};
65 
73  void SetEditModules( bool aEnabled )
74  {
75  m_editModules = aEnabled;
76  }
77 
78  bool EditingModules() const
79  {
80  return m_editModules;
81  }
82 
83 protected:
84 
91  using ITEM_CREATOR = std::function< std::unique_ptr< BOARD_ITEM >( const TOOL_EVENT& aEvt ) >;
92 
105  void doInteractiveItemPlacement( ITEM_CREATOR aItemCreator,
106  const wxString& aCommitMessage );
107 
108  KIGFX::VIEW* view() const { return getView(); }
109  PCB_EDIT_FRAME* frame() const { return getEditFrame<PCB_EDIT_FRAME>(); }
110  BOARD* board() const { return getModel<BOARD>(); }
111 
113 };
114 
115 #endif
KIGFX::VIEW * view() const
Definition: pcb_tool.h:108
Class BOARD to handle a board.
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:57
virtual ~PCB_TOOL()
Definition: pcb_tool.h:64
PCB_TOOL(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool.h:52
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:109
Class TOOL_EVENT.
Definition: tool_event.h:162
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
Class PCB_TOOL.
Definition: pcb_tool.h:45
bool m_editModules
Definition: pcb_tool.h:112
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
bool EditingModules() const
Definition: pcb_tool.h:78
void doInteractiveItemPlacement(ITEM_CREATOR aItemCreator, const wxString &aCommitMessage)
Helper function for performing a common interactive idiom: wait for a left click, place an item there...
Definition: pcb_tool.cpp:39
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
Class VIEW.
Definition: view.h:58
std::function< std::unique_ptr< BOARD_ITEM >(const TOOL_EVENT &aEvt) > ITEM_CREATOR
Callable that returns a new board item.
Definition: pcb_tool.h:91
PCB_TOOL(const std::string &aName)
Constructor.
Definition: pcb_tool.h:60
void SetEditModules(bool aEnabled)
Function SetEditModules()
Definition: pcb_tool.h:73
BOARD * board() const
Definition: pcb_tool.h:110