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:
74 PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
75 TOOL_INTERACTIVE ( aId, aName ),
76 m_isFootprintEditor( false ),
77 m_isBoardEditor( false )
78 {};
79
84 PCB_TOOL_BASE( const std::string& aName ) :
85 TOOL_INTERACTIVE ( aName ),
86 m_isFootprintEditor( false ),
87 m_isBoardEditor( false )
88 {};
89
90 virtual ~PCB_TOOL_BASE() {};
91
92 virtual bool Init() override;
93 virtual void Reset( RESET_REASON aReason ) override;
94
102 void SetIsFootprintEditor( bool aEnabled ) { m_isFootprintEditor = aEnabled; }
103 bool IsFootprintEditor() const { return m_isFootprintEditor; }
104
105 void SetIsBoardEditor( bool aEnabled ) { m_isBoardEditor = aEnabled; }
106 bool IsBoardEditor() const { return m_isBoardEditor; }
107
112 virtual bool Is45Limited() const;
113
117 virtual bool Is90Limited() const;
118
123
127 bool GetAutoConstraints() const;
128
129protected:
136
138 IPO_FLIP = 0x02,
139
143
146 };
147
161 const wxString& aCommitMessage,
162 int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
163
164 virtual void setTransitions() override;
165
166
168 {
169 return static_cast<KIGFX::PCB_VIEW*>( getView() );
170 }
171
173 {
174 return getViewControls();
175 }
176
177 template<class T = PCB_BASE_EDIT_FRAME>
178 T* frame() const
179 {
180 return getEditFrame<T>();
181 }
182
183 BOARD* board() const { return getModel<BOARD>(); }
184
186 {
187 return board()->GetFirstFootprint();
188 }
189
191
192 PCB_DRAW_PANEL_GAL* canvas() const;
193
194 const PCB_SELECTION& selection() const;
195
197
198protected:
201};
202
203#endif
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:599
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.
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
Returns the instance of #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