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 #include <pcb_draw_panel_gal.h>
37 
38 #include <functional>
39 #include <tool/tool_menu.h>
40 
47 class PCB_TOOL;
48 class PCB_EDIT_FRAME;
50 class SELECTION;
51 
53 {
54  virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
55  virtual void SnapItem( BOARD_ITEM *aItem );
56  virtual bool 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_menu( *this ),
74  m_editModules( false ) {};
75 
80  PCB_TOOL( const std::string& aName ) :
81  TOOL_INTERACTIVE ( aName ),
82  m_menu( *this ),
83  m_editModules( false ) {};
84 
85  virtual ~PCB_TOOL() {};
86 
87  virtual bool Init() override;
88  virtual void Reset( RESET_REASON aReason ) override;
89 
97  void SetEditModules( bool aEnabled )
98  {
99  m_editModules = aEnabled;
100  }
101 
102  bool EditingModules() const
103  {
104  return m_editModules;
105  }
106 
107 protected:
108 
111  IPO_FLIP = 2,
115  };
116 
117 
131  const wxString& aCommitMessage,
132  int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
133 
134  virtual void setTransitions() override;
135 
136 
137  KIGFX::PCB_VIEW* view() const { return static_cast<KIGFX::PCB_VIEW*>( getView() ); }
139  PCB_EDIT_FRAME* frame() const { return getEditFrame<PCB_EDIT_FRAME>(); }
140  BOARD* board() const { return getModel<BOARD>(); }
141  MODULE* module() const { return board()->m_Modules; }
143  PCB_DRAW_PANEL_GAL* canvas() const;
144  const SELECTION& selection() const;
145  SELECTION& selection();
146 
149 
151 };
152 
153 #endif
virtual void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
Definition: pcb_tool.cpp:236
KIGFX::VIEW_CONTROLS * controls() const
Definition: pcb_tool.h:138
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
Definition: pcb_tool.cpp:271
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: pcb_tool.h:148
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.
const SELECTION & selection() const
Definition: pcb_tool.cpp:251
KIGFX::PCB_VIEW * view() const
Definition: pcb_tool.h:137
Class TOOL_MENU.
Definition: tool_menu.h:47
PCB_EDIT_FRAME * m_frame
Definition: pcb_tool.h:58
INTERACTIVE_PLACEMENT_OPTIONS
Definition: pcb_tool.h:109
PCB_DRAW_PANEL_GAL * canvas() const
Definition: pcb_tool.cpp:246
virtual void SnapItem(BOARD_ITEM *aItem)
Definition: pcb_tool.cpp:266
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:85
PCB_DISPLAY_OPTIONS * displayOptions() const
Definition: pcb_tool.cpp:241
BOARD * board() const
Definition: pcb_tool.h:140
PCB_TOOL(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool.h:71
virtual void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
Definition: pcb_tool.cpp:231
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
bool m_editModules
Definition: pcb_tool.h:150
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
virtual bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: pcb_tool.cpp:214
DLIST< MODULE > m_Modules
Definition: class_board.h:249
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
bool EditingModules() const
Definition: pcb_tool.h:102
void doInteractiveItemPlacement(INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
Helper function for performing a common interactive idiom: wait for a left click, place an item there...
Definition: pcb_tool.cpp:39
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
MODULE * module() const
Definition: pcb_tool.h:141
PCB_TOOL(const std::string &aName)
Constructor.
Definition: pcb_tool.h:80
void SetEditModules(bool aEnabled)
Function SetEditModules()
Definition: pcb_tool.h:97