KiCad PCB EDA Suite
pcb_tool_base.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_BASE_H
26 #define PCB_TOOL_BASE_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_BASE;
48 class PCB_EDIT_FRAME;
50 class PCBNEW_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 
65 {
66 public:
71  PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
72  TOOL_INTERACTIVE ( aId, aName ),
73  m_editModules( false )
74  {};
75 
80  PCB_TOOL_BASE( const std::string& aName ) :
81  TOOL_INTERACTIVE ( aName ),
82  m_editModules( false )
83  {};
84 
85  virtual ~PCB_TOOL_BASE() {};
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,
114  };
115 
116 
129  void doInteractiveItemPlacement( const std::string& aTool, INTERACTIVE_PLACER_BASE *aPlacer,
130  const wxString& aCommitMessage,
131  int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
132 
133  virtual void setTransitions() override;
134 
135 
137  {
138  return static_cast<KIGFX::PCB_VIEW*>( getView() );
139  }
140 
142  {
143  return getViewControls();
144  }
145 
147  {
148  return getEditFrame<PCB_BASE_EDIT_FRAME>();
149  }
150 
151  BOARD* board() const { return getModel<BOARD>(); }
152 
153  MODULE* module() const
154  {
155  return board()->GetFirstModule();
156  }
157 
159  PCB_DRAW_PANEL_GAL* canvas() const;
160  const PCBNEW_SELECTION& selection() const;
162 
164 };
165 
166 #endif
PCB_DISPLAY_OPTIONS * displayOptions() const
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
BOARD * board() const
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
virtual void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
PCB_BASE_EDIT_FRAME * frame() const
virtual void SnapItem(BOARD_ITEM *aItem)
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
const PCBNEW_SELECTION & selection() const
PCB_TOOL_BASE(const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:80
virtual void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void SetEditModules(bool aEnabled)
Function SetEditModules()
Definition: pcb_tool_base.h:97
KIGFX::PCB_VIEW * view() const
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:285
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:36
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:71
bool EditingModules() const
virtual ~PCB_TOOL_BASE()
Definition: pcb_tool_base.h:85
KIGFX::VIEW_CONTROLS * controls() const
Common, abstract interface for edit frames.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
MODULE * module() const
virtual bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
void doInteractiveItemPlacement(const std::string &aTool, 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...
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:58
PCB_DRAW_PANEL_GAL * canvas() const