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 {
55  {
56  }
57 
58  virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
59  virtual void SnapItem( BOARD_ITEM *aItem );
60  virtual bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit );
61 
65 };
66 
67 
69 {
70 public:
75  PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
76  TOOL_INTERACTIVE ( aId, aName ),
77  m_editModules( false )
78  {};
79 
84  PCB_TOOL_BASE( const std::string& aName ) :
85  TOOL_INTERACTIVE ( aName ),
86  m_editModules( false )
87  {};
88 
89  virtual ~PCB_TOOL_BASE() {};
90 
91  virtual bool Init() override;
92  virtual void Reset( RESET_REASON aReason ) override;
93 
101  void SetEditModules( bool aEnabled )
102  {
103  m_editModules = aEnabled;
104  }
105 
106  bool EditingModules() const
107  {
108  return m_editModules;
109  }
110 
111 protected:
112 
118  IPO_ROTATE = 0x01,
119 
121  IPO_FLIP = 0x02,
122 
126 
128  IPO_REPEAT = 0x08
129  };
130 
131 
144  void doInteractiveItemPlacement( const std::string& aTool, INTERACTIVE_PLACER_BASE *aPlacer,
145  const wxString& aCommitMessage,
146  int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
147 
148  virtual void setTransitions() override;
149 
150 
152  {
153  return static_cast<KIGFX::PCB_VIEW*>( getView() );
154  }
155 
157  {
158  return getViewControls();
159  }
160 
162  {
163  return getEditFrame<PCB_BASE_EDIT_FRAME>();
164  }
165 
166  BOARD* board() const { return getModel<BOARD>(); }
167 
168  MODULE* module() const
169  {
170  return board()->GetFirstModule();
171  }
172 
173  const PCB_DISPLAY_OPTIONS& displayOptions() const;
174  PCB_DRAW_PANEL_GAL* canvas() const;
175  const PCBNEW_SELECTION& selection() const;
177 
179 };
180 
181 #endif
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,...
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:84
virtual void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
Allow repeat placement of the item.
void SetEditModules(bool aEnabled)
Function SetEditModules()
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:310
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 ...
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:75
bool EditingModules() const
Handle the rotate action in the loop by calling the item's rotate method.
virtual ~PCB_TOOL_BASE()
Definition: pcb_tool_base.h:89
KIGFX::VIEW_CONTROLS * controls() const
Common, abstract interface for edit frames.
virtual ~INTERACTIVE_PLACER_BASE()
Definition: pcb_tool_base.h:54
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
MODULE * module() const
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.
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:62
PCB_DRAW_PANEL_GAL * canvas() const