KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
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
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#include <pcbnew_settings.h>
38#include <functional>
39#include <tool/tool_menu.h>
40
47class PCB_TOOL_BASE;
48class PCB_EDIT_FRAME;
50class 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{
72public:
77 PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
78 TOOL_INTERACTIVE ( aId, aName ),
79 m_isFootprintEditor( false ),
80 m_isBoardEditor( false )
81 {};
82
87 PCB_TOOL_BASE( const std::string& aName ) :
88 TOOL_INTERACTIVE ( aName ),
89 m_isFootprintEditor( false ),
90 m_isBoardEditor( false )
91 {};
92
93 virtual ~PCB_TOOL_BASE() {};
94
95 virtual bool Init() override;
96 virtual void Reset( RESET_REASON aReason ) override;
97
105 void SetIsFootprintEditor( bool aEnabled ) { m_isFootprintEditor = aEnabled; }
106 bool IsFootprintEditor() const { return m_isFootprintEditor; }
107
108 void SetIsBoardEditor( bool aEnabled ) { m_isBoardEditor = aEnabled; }
109 bool IsBoardEditor() const { return m_isBoardEditor; }
110
115 virtual bool Is45Limited() const;
116
117protected:
124
126 IPO_FLIP = 0x02,
127
131
133 IPO_REPEAT = 0x08
134 };
135
149 const wxString& aCommitMessage,
150 int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
151
152 virtual void setTransitions() override;
153
154
156 {
157 return static_cast<KIGFX::PCB_VIEW*>( getView() );
158 }
159
161 {
162 return getViewControls();
163 }
164
166 {
167 return getEditFrame<PCB_BASE_EDIT_FRAME>();
168 }
169
170 BOARD* board() const { return getModel<BOARD>(); }
171
173 {
174 return board()->GetFirstFootprint();
175 }
176
178
179 PCB_DRAW_PANEL_GAL* canvas() const;
180
181 const PCB_SELECTION& selection() const;
182
184
185protected:
188};
189
190#endif
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:433
An interface for classes handling user events controlling the view behavior such as zooming,...
Common, abstract interface for edit frames.
The main frame for Pcbnew.
void SetIsFootprintEditor(bool aEnabled)
Function SetIsFootprintEditor()
KIGFX::PCB_VIEW * view() const
virtual bool Is45Limited() const
Should the tool use its 45° mode option?
bool IsFootprintEditor() const
bool IsBoardEditor() const
PCB_BASE_EDIT_FRAME * frame() const
KIGFX::VIEW_CONTROLS * controls() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:77
void SetIsBoardEditor(bool aEnabled)
BOARD * board() const
PCB_DRAW_PANEL_GAL * canvas() const
PCBNEW_SETTINGS::DISPLAY_OPTIONS & displayOptions() const
virtual void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
INTERACTIVE_PLACEMENT_OPTIONS
Options for placing items interactively.
@ IPO_FLIP
Handle flip action in the loop by calling the item's flip method.
@ IPO_ROTATE
Handle the rotate action in the loop by calling the item's rotate method.
@ IPO_SINGLE_CLICK
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
@ IPO_REPEAT
Allow repeat placement of the item.
virtual ~PCB_TOOL_BASE()
Definition: pcb_tool_base.h:93
virtual bool Init() override
Init() is called once upon a registration of the tool.
bool m_isFootprintEditor
void doInteractiveItemPlacement(const TOOL_EVENT &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...
PCB_TOOL_BASE(const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:87
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
void Reset() override
virtual void SnapItem(BOARD_ITEM *aItem)
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:64
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
virtual ~INTERACTIVE_PLACER_BASE()
Definition: pcb_tool_base.h:54
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56