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 The 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>
39#include <functional>
40#include <tool/tool_menu.h>
41
47
48class PCB_TOOL_BASE;
49class PCB_EDIT_FRAME;
51class PCB_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{
73public:
78 PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
79 TOOL_INTERACTIVE ( aId, aName ),
80 m_isFootprintEditor( false ),
81 m_isBoardEditor( false )
82 {};
83
88 PCB_TOOL_BASE( const std::string& aName ) :
89 TOOL_INTERACTIVE ( aName ),
90 m_isFootprintEditor( false ),
91 m_isBoardEditor( false )
92 {};
93
94 virtual ~PCB_TOOL_BASE() {};
95
96 virtual bool Init() override;
97 virtual void Reset( RESET_REASON aReason ) override;
98
106 void SetIsFootprintEditor( bool aEnabled ) { m_isFootprintEditor = aEnabled; }
107 bool IsFootprintEditor() const { return m_isFootprintEditor; }
108
109 void SetIsBoardEditor( bool aEnabled ) { m_isBoardEditor = aEnabled; }
110 bool IsBoardEditor() const { return m_isBoardEditor; }
111
116 virtual bool Is45Limited() const;
117
121 virtual bool Is90Limited() const;
122
127
128protected:
135
137 IPO_FLIP = 0x02,
138
142
145 };
146
160 const wxString& aCommitMessage,
161 int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
162
163 virtual void setTransitions() override;
164
165
167 {
168 return static_cast<KIGFX::PCB_VIEW*>( getView() );
169 }
170
172 {
173 return getViewControls();
174 }
175
176 template<class T = PCB_BASE_EDIT_FRAME>
177 T* frame() const
178 {
179 return getEditFrame<T>();
180 }
181
182 BOARD* board() const { return getModel<BOARD>(); }
183
185 {
186 return board()->GetFirstFootprint();
187 }
188
190
191 PCB_DRAW_PANEL_GAL* canvas() const;
192
193 const PCB_SELECTION& selection() const;
194
196
197protected:
200};
201
202#endif
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:79
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:317
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:488
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()
T * frame() const
KIGFX::PCB_VIEW * view() const
virtual bool Is45Limited() const
Should the tool use its 45° mode option?
bool IsFootprintEditor() const
bool IsBoardEditor() const
LEADER_MODE GetAngleSnapMode() const
Get the current angle snapping mode.
KIGFX::VIEW_CONTROLS * controls() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
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()
virtual bool Init() override
Init() is called once upon a registration of the tool.
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.
virtual bool Is90Limited() const
Should the tool limit drawing to horizontal and vertical only?
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:186
T * getModel() const
Return the model object if it matches the requested type.
Definition tool_base.h:198
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:44
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition tool_base.cpp:38
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:78
Generic, UI-independent tool event.
Definition tool_event.h:171
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
void Reset() override
LEADER_MODE
The kind of the leader line.
virtual void SnapItem(BOARD_ITEM *aItem)
PCB_BASE_EDIT_FRAME * m_frame
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
virtual ~INTERACTIVE_PLACER_BASE()
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
int TOOL_ID
Unique identifier for tools.
Definition tool_base.h:56