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  * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef PCB_TOOL_BASE_H
27 #define PCB_TOOL_BASE_H
28 
29 #include <string>
30 
31 #include <tool/tool_event.h>
32 #include <tool/tool_interactive.h>
33 #include <pcb_edit_frame.h>
34 #include <board.h>
35 #include <view/view_group.h>
36 #include <pcb_view.h>
37 #include <pcb_draw_panel_gal.h>
38 
39 #include <functional>
40 #include <tool/tool_menu.h>
41 
48 class PCB_TOOL_BASE;
49 class PCB_EDIT_FRAME;
51 class PCBNEW_SELECTION;
52 
54 {
56  {
57  }
58 
59  virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
60 
61  virtual void SnapItem( BOARD_ITEM *aItem );
62 
63  virtual bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit );
64 
68 };
69 
70 
72 {
73 public:
78  PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
79  TOOL_INTERACTIVE ( aId, aName ),
80  m_isFootprintEditor( false )
81  {};
82 
87  PCB_TOOL_BASE( const std::string& aName ) :
88  TOOL_INTERACTIVE ( aName ),
89  m_isFootprintEditor( false )
90  {};
91 
92  virtual ~PCB_TOOL_BASE() {};
93 
94  virtual bool Init() override;
95  virtual void Reset( RESET_REASON aReason ) override;
96 
104  void SetIsFootprintEditor( bool aEnabled ) { m_isFootprintEditor = aEnabled; }
105  bool IsFootprintEditor() const { return m_isFootprintEditor; }
106 
107 protected:
113  IPO_ROTATE = 0x01,
114 
116  IPO_FLIP = 0x02,
117 
121 
123  IPO_REPEAT = 0x08
124  };
125 
138  void doInteractiveItemPlacement( const std::string& aTool, INTERACTIVE_PLACER_BASE *aPlacer,
139  const wxString& aCommitMessage,
140  int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
141 
142  virtual void setTransitions() override;
143 
144 
146  {
147  return static_cast<KIGFX::PCB_VIEW*>( getView() );
148  }
149 
151  {
152  return getViewControls();
153  }
154 
156  {
157  return getEditFrame<PCB_BASE_EDIT_FRAME>();
158  }
159 
160  BOARD* board() const { return getModel<BOARD>(); }
161 
163  {
164  return board()->GetFirstFootprint();
165  }
166 
167  const PCB_DISPLAY_OPTIONS& displayOptions() const;
168 
169  PCB_DRAW_PANEL_GAL* canvas() const;
170 
171  const PCBNEW_SELECTION& selection() const;
172 
174 
175 protected:
177 };
178 
179 #endif
void SetIsFootprintEditor(bool aEnabled)
Function SetIsFootprintEditor()
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
Handle flip action in the loop by calling the item's flip method.
BOARD * board() const
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
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
PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
INTERACTIVE_PLACEMENT_OPTIONS
Options for placing items interactively.
const PCBNEW_SELECTION & selection() const
PCB_TOOL_BASE(const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:87
FOOTPRINT * GetFirstFootprint() const
Gets the first footprint on the board or nullptr.
Definition: board.h:348
virtual void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
Allow repeat placement of the item.
FOOTPRINT * footprint() const
KIGFX::PCB_VIEW * view() const
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
bool m_isFootprintEditor
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
const PCB_DISPLAY_OPTIONS & displayOptions() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:78
Handle the rotate action in the loop by calling the item's rotate method.
virtual ~PCB_TOOL_BASE()
Definition: pcb_tool_base.h:92
KIGFX::VIEW_CONTROLS * controls() const
Common, abstract interface for edit frames.
virtual ~INTERACTIVE_PLACER_BASE()
Definition: pcb_tool_base.h:55
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
virtual bool Init() override
Function Init() Init() is called once upon a registration of the tool.
PCB_EDIT_FRAME is the main frame for Pcbnew.
bool IsFootprintEditor() const
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:65
PCB_DRAW_PANEL_GAL * canvas() const