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, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef PCB_TOOL_BASE_H
23#define PCB_TOOL_BASE_H
24
25#include <string>
26
28#include <pcb_edit_frame.h>
29#include <board.h>
30#include <view/view_group.h>
31#include <pcb_view.h>
32#include <pcb_draw_panel_gal.h>
33#include <pcbnew_settings.h>
35#include <functional>
36#include <tool/tool_menu.h>
37
43
44class PCB_TOOL_BASE;
45class PCB_EDIT_FRAME;
47class PCB_SELECTION;
48
50{
52 {
53 }
54
55 virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
56
57 virtual void SnapItem( BOARD_ITEM *aItem );
58
59 virtual bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit );
60
64};
65
66
68{
69public:
75 PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
76 TOOL_INTERACTIVE ( aId, aName ),
77 m_isFootprintEditor( false ),
78 m_isBoardEditor( false )
79 {};
80
86 PCB_TOOL_BASE( const std::string& aName ) :
87 TOOL_INTERACTIVE ( aName ),
88 m_isFootprintEditor( false ),
89 m_isBoardEditor( 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 void SetIsBoardEditor( bool aEnabled ) { m_isBoardEditor = aEnabled; }
108 bool IsBoardEditor() const { return m_isBoardEditor; }
109
114 virtual bool Is45Limited() const;
115
119 virtual bool Is90Limited() const;
120
125
129 bool GetAutoConstraints() const;
130
131protected:
138
140 IPO_FLIP = 0x02,
141
145
148 };
149
165 const wxString& aCommitMessage,
166 int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
167
168 virtual void setTransitions() override;
169
170
172 {
173 return static_cast<KIGFX::PCB_VIEW*>( getView() );
174 }
175
177 {
178 return getViewControls();
179 }
180
181 template<class T = PCB_BASE_EDIT_FRAME>
182 T* frame() const
183 {
184 return getEditFrame<T>();
185 }
186
187 BOARD* board() const { return getModel<BOARD>(); }
188
190 {
191 return board()->GetFirstFootprint();
192 }
193
195
196 PCB_DRAW_PANEL_GAL* canvas() const;
197
198 const PCB_SELECTION& selection() const;
199
201
202protected:
205};
206
207#endif
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:712
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)
Toggle edit footprint mode.
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.
bool GetAutoConstraints() const
Should drawing tools author constraints automatically?
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:182
T * getModel() const
Return the model object if it matches the requested type.
Definition tool_base.h:195
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
KIGFX::VIEW * getView() const
Return the instance of KIGFX::VIEW object used in the application.
Definition tool_base.cpp:34
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
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:52