KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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) 2013 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef TOOL_BASE_H
24#define TOOL_BASE_H
25
26#include <cassert>
27#include <functional>
28#include <string>
29#include <wx/debug.h>
30
31class EDA_ITEM;
32class TOOL_EVENT;
33class TOOL_MANAGER;
34class TOOLS_HOLDER;
35
36namespace KIGFX
37{
38class VIEW;
39class VIEW_CONTROLS;
40}
41
43{
46
48 BATCH = 0x02
49};
50
52typedef int TOOL_ID;
53
54using TOOL_STATE_FUNC = std::function<int(const TOOL_EVENT&)>;
55
56
60
62{
63public:
64 TOOL_BASE( TOOL_TYPE aType, TOOL_ID aId, const std::string& aName = std::string( "" ) ) :
65 m_type( aType ),
66 m_toolId( aId ),
67 m_toolName( aName ),
68 m_toolMgr( nullptr ) {};
69
70 virtual ~TOOL_BASE() {};
71
82
88 virtual bool Init()
89 {
90 return true;
91 }
92
100 virtual void Reset( RESET_REASON aReason ) = 0;
101
108 {
109 return m_type;
110 }
111
120 {
121 return m_toolId;
122 }
123
132 const std::string& GetName() const
133 {
134 return m_toolName;
135 }
136
143 {
144 return m_toolMgr;
145 }
146
147 //TOOL_SETTINGS& GetAdapter();
148
149 bool IsToolActive() const;
150
151protected:
152 friend class TOOL_MANAGER;
153
159 void attachManager( TOOL_MANAGER* aManager );
160
166 KIGFX::VIEW* getView() const;
167
177
181 template <typename T>
183 {
184#if !defined( QA_TEST ) // Dynamic casts give the linker a seizure in the test framework
185 wxASSERT( dynamic_cast<T*>( getToolHolderInternal() ) );
186#endif
187
188 return static_cast<T*>( getToolHolderInternal() );
189 }
190
194 template <typename T>
195 T* getModel() const
196 {
198
199#if !defined( QA_TEST ) // Dynamic casts give the linker a seizure in the test framework
200 if( m )
201 wxASSERT( dynamic_cast<T*>( m ) );
202#endif
203
204 return static_cast<T*>( m );
205 }
206
207private:
208 // hide the implementation to avoid spreading half of kicad and wxWidgets headers to the tools
209 // that may not need them at all!
210 EDA_ITEM* getModelInternal() const;
212
213protected:
216
219 std::string m_toolName;
221};
222
223#endif // TOOL_BASE_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
An interface for classes handling user events controlling the view behavior such as zooming,...
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition tool_base.h:142
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
virtual void Reset(RESET_REASON aReason)=0
Bring the tool to a known, initial state.
virtual bool Init()
Init() is called once upon a registration of the tool.
Definition tool_base.h:88
TOOL_TYPE m_type
Definition tool_base.h:214
TOOLS_HOLDER * getToolHolderInternal() const
Definition tool_base.cpp:46
const std::string & GetName() const
Return the name of the tool.
Definition tool_base.h:132
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
friend class TOOL_MANAGER
Definition tool_base.h:152
EDA_ITEM * getModelInternal() const
Definition tool_base.cpp:52
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition tool_base.cpp:34
TOOL_TYPE GetType() const
Return the type of the tool.
Definition tool_base.h:107
bool IsToolActive() const
Definition tool_base.cpp:28
TOOL_ID m_toolId
Unique id, assigned by a TOOL_MANAGER instance.
Definition tool_base.h:215
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
@ REDRAW
Full drawing refresh.
Definition tool_base.h:79
@ SHUTDOWN
Tool is being shut down.
Definition tool_base.h:80
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:76
@ GAL_SWITCH
Rendering engine changes.
Definition tool_base.h:78
@ SUPERMODEL_RELOAD
For schematics, the entire schematic changed, not just the sheet.
Definition tool_base.h:77
@ RUN
Tool is invoked after being inactive.
Definition tool_base.h:75
virtual ~TOOL_BASE()
Definition tool_base.h:70
TOOL_ID GetId() const
Return the unique identifier of the tool.
Definition tool_base.h:119
void attachManager(TOOL_MANAGER *aManager)
Set the TOOL_MANAGER the tool will belong to.
Definition tool_base.cpp:58
std::string m_toolName
Names are expected to obey the format application.ToolName (eg.
Definition tool_base.h:219
TOOL_BASE(TOOL_TYPE aType, TOOL_ID aId, const std::string &aName=std::string(""))
Definition tool_base.h:64
Generic, UI-independent tool event.
Definition tool_event.h:167
Master controller class:
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition tool_base.h:54
int TOOL_ID
Unique identifier for tools.
Definition tool_base.h:52
TOOL_TYPE
Definition tool_base.h:43
@ INTERACTIVE
Tool that interacts with the user.
Definition tool_base.h:45
@ BATCH
Tool that runs in the background without any user intervention.
Definition tool_base.h:48