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_interactive.h>
32 #include <pcb_edit_frame.h>
33 #include <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 PCB_SELECTION;
51 
53 {
55  {
56  }
57 
58  virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
59 
60  virtual void SnapItem( BOARD_ITEM *aItem );
61 
62  virtual bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit );
63 
67 };
68 
69 
71 {
72 public:
77  PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
78  TOOL_INTERACTIVE ( aId, aName ),
79  m_isFootprintEditor( false )
80  {};
81 
86  PCB_TOOL_BASE( const std::string& aName ) :
87  TOOL_INTERACTIVE ( aName ),
88  m_isFootprintEditor( false )
89  {};
90 
91  virtual ~PCB_TOOL_BASE() {};
92 
93  virtual bool Init() override;
94  virtual void Reset( RESET_REASON aReason ) override;
95 
103  void SetIsFootprintEditor( bool aEnabled ) { m_isFootprintEditor = aEnabled; }
104  bool IsFootprintEditor() const { return m_isFootprintEditor; }
105 
110  bool Is45Limited() const;
111 
112 protected:
118  IPO_ROTATE = 0x01,
119 
121  IPO_FLIP = 0x02,
122 
126 
128  IPO_REPEAT = 0x08
129  };
130 
143  void doInteractiveItemPlacement( const std::string& aTool, INTERACTIVE_PLACER_BASE *aPlacer,
144  const wxString& aCommitMessage,
145  int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
146 
147  virtual void setTransitions() override;
148 
149 
151  {
152  return static_cast<KIGFX::PCB_VIEW*>( getView() );
153  }
154 
156  {
157  return getViewControls();
158  }
159 
161  {
162  return getEditFrame<PCB_BASE_EDIT_FRAME>();
163  }
164 
165  BOARD* board() const { return getModel<BOARD>(); }
166 
168  {
169  return board()->GetFirstFootprint();
170  }
171 
172  const PCB_DISPLAY_OPTIONS& displayOptions() const;
173 
174  PCB_DRAW_PANEL_GAL* canvas() const;
175 
176  const PCB_SELECTION& selection() const;
177 
179 
180 protected:
182 
183 };
184 
185 #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
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
virtual void Reset(RESET_REASON aReason) override
Bring 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
Container for display options like enable/disable some optional drawings.
INTERACTIVE_PLACEMENT_OPTIONS
Options for placing items interactively.
const PCB_SELECTION & selection() const
PCB_TOOL_BASE(const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:86
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:317
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
An interface for classes handling user events controlling the view behavior such as zooming,...
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
bool Is45Limited() const
Should the tool use its 45° mode option?
bool m_isFootprintEditor
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
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:77
Handle the rotate action in the loop by calling the item's rotate method.
virtual ~PCB_TOOL_BASE()
Definition: pcb_tool_base.h:91
KIGFX::VIEW_CONTROLS * controls() const
Common, abstract interface for edit frames.
virtual ~INTERACTIVE_PLACER_BASE()
Definition: pcb_tool_base.h:54
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual bool Init() override
Init() is called once upon a registration of the tool.
The main frame for Pcbnew.
bool IsFootprintEditor() const
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
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
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:64
PCB_DRAW_PANEL_GAL * canvas() const