KiCad PCB EDA Suite
Loading...
Searching...
No Matches
toolbars_sch_editor.cpp
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 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 * Copyright (C) 2019 CERN
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, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <advanced_config.h>
29#include <sch_draw_panel.h>
30#include <sch_edit_frame.h>
31#include <kiface_base.h>
32#include <bitmaps.h>
33#include <eeschema_id.h>
34#include <pgm_base.h>
35#include <python_scripting.h>
36#include <tool/tool_manager.h>
37#include <tool/action_toolbar.h>
38#include <tools/sch_actions.h>
45#include <toolbars_sch_editor.h>
46#include <wx/choice.h>
47
48
50 "control.currentVariant",
51 _( "Current Variant" ),
52 _( "Control to select the current schematic variant" ) );
53
54
55std::optional<TOOLBAR_CONFIGURATION> SCH_EDIT_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
56{
58
59 // clang-format off
60 switch( aToolbar )
61 {
63 return std::nullopt;
64
66 config.AppendAction( ACTIONS::toggleGrid )
67 .AppendAction( ACTIONS::toggleGridOverrides )
68 .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) )
69 .AddAction( ACTIONS::inchesUnits )
70 .AddAction( ACTIONS::milsUnits )
71 .AddAction( ACTIONS::millimetersUnits ) )
72 .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Crosshair modes" ) )
75 .AddAction( ACTIONS::cursor45Crosshairs ) );
76
77 config.AppendSeparator()
78 .AppendAction( SCH_ACTIONS::toggleHiddenPins );
79
80 config.AppendSeparator()
81 .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Line modes" ) )
82 .AddAction( SCH_ACTIONS::lineModeFree )
83 .AddAction( SCH_ACTIONS::lineMode90 )
84 .AddAction( SCH_ACTIONS::lineMode45 ) );
85
86 config.AppendSeparator()
87 .AppendAction( SCH_ACTIONS::toggleAnnotateAuto );
88
89 config.AppendSeparator()
90 .AppendAction( SCH_ACTIONS::showHierarchy )
91 .AppendAction( ACTIONS::showProperties );
92
93 if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
95
96 /* TODO (ISM): Handle context menus
97 EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
98 std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
99 gridMenu->Add( ACTIONS::gridProperties );
100 m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
101 */
102 break;
103
105 config.AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Selection modes" ) )
106 .AddAction( ACTIONS::selectSetRect )
107 .AddAction( ACTIONS::selectSetLasso ) )
108 .AppendAction( SCH_ACTIONS::highlightNetTool );
109
110 config.AppendSeparator()
111 .AppendAction( SCH_ACTIONS::placeSymbol )
112 .AppendAction( SCH_ACTIONS::placePower )
113 .AppendAction( SCH_ACTIONS::drawWire )
114 .AppendAction( SCH_ACTIONS::drawBus )
115 .AppendAction( SCH_ACTIONS::placeBusWireEntry )
116 .AppendAction( SCH_ACTIONS::placeNoConnect )
117 .AppendAction( SCH_ACTIONS::placeJunction )
118 .AppendAction( SCH_ACTIONS::placeLabel )
119 .AppendAction( SCH_ACTIONS::placeClassLabel )
120 .AppendAction( SCH_ACTIONS::drawRuleArea )
121 .AppendAction( SCH_ACTIONS::placeGlobalLabel )
122 .AppendAction( SCH_ACTIONS::placeHierLabel )
123 .AppendAction( SCH_ACTIONS::drawSheet )
124 .AppendAction( SCH_ACTIONS::placeSheetPin )
125 .AppendAction( SCH_ACTIONS::syncAllSheetsPins );
126
127 config.AppendSeparator()
128 .AppendAction( SCH_ACTIONS::placeSchematicText )
129 .AppendAction( SCH_ACTIONS::drawTextBox )
130 .AppendAction( SCH_ACTIONS::drawTable )
131 .AppendAction( SCH_ACTIONS::drawRectangle )
132 .AppendAction( SCH_ACTIONS::drawCircle )
133 .AppendAction( SCH_ACTIONS::drawArc )
134 .AppendAction( SCH_ACTIONS::drawBezier )
135 .AppendAction( SCH_ACTIONS::drawLines )
136 .AppendAction( SCH_ACTIONS::placeImage )
137 .AppendAction( ACTIONS::deleteTool );
138
139 break;
140
142 if( Kiface().IsSingle() ) // not when under a project mgr
143 {
144 config.AppendAction( ACTIONS::doNew );
145 config.AppendAction( ACTIONS::open );
146 }
147
148 config.AppendAction( ACTIONS::save );
149
150 config.AppendSeparator()
151 .AppendAction( SCH_ACTIONS::schematicSetup );
152
153 config.AppendSeparator()
154 .AppendAction( ACTIONS::pageSettings )
155 .AppendAction( ACTIONS::print )
156 .AppendAction( ACTIONS::plot );
157
158 config.AppendSeparator()
159 .AppendAction( ACTIONS::paste );
160
161 config.AppendSeparator()
162 .AppendAction( ACTIONS::undo )
163 .AppendAction( ACTIONS::redo );
164
165 config.AppendSeparator()
166 .AppendAction( ACTIONS::find )
167 .AppendAction( ACTIONS::findAndReplace );
168
169 config.AppendSeparator()
170 .AppendAction( ACTIONS::zoomRedraw )
171 .AppendAction( ACTIONS::zoomInCenter )
172 .AppendAction( ACTIONS::zoomOutCenter )
173 .AppendAction( ACTIONS::zoomFitScreen )
174 .AppendAction( ACTIONS::zoomFitObjects )
175 .AppendAction( ACTIONS::zoomTool );
176
177 config.AppendSeparator()
178 .AppendAction( SCH_ACTIONS::navigateBack )
179 .AppendAction( SCH_ACTIONS::navigateUp )
180 .AppendAction( SCH_ACTIONS::navigateForward );
181
182 config.AppendSeparator()
183 .AppendAction( SCH_ACTIONS::rotateCCW )
184 .AppendAction( SCH_ACTIONS::rotateCW )
185 .AppendAction( SCH_ACTIONS::mirrorV )
186 .AppendAction( SCH_ACTIONS::mirrorH )
187 .AppendAction( ACTIONS::group )
188 .AppendAction( ACTIONS::ungroup );
189
190 config.AppendSeparator()
191 .AppendAction( ACTIONS::showSymbolEditor )
192 .AppendAction( ACTIONS::showSymbolBrowser )
193 .AppendAction( ACTIONS::showFootprintEditor );
194
195 config.AppendSeparator()
196 .AppendAction( SCH_ACTIONS::annotate )
197 .AppendAction( SCH_ACTIONS::runERC )
198 .AppendAction( SCH_ACTIONS::showSimulator )
199 .AppendAction( SCH_ACTIONS::assignFootprints )
200 .AppendAction( SCH_ACTIONS::editSymbolFields )
201 .AppendAction( SCH_ACTIONS::generateBOM );
202
203 config.AppendSeparator()
204 .AppendAction( SCH_ACTIONS::showPcbNew );
205
206 if( ADVANCED_CFG::GetCfg().m_EnableVariantsUI )
208
209 // Insert all the IPC plugins here on the toolbar
210 // TODO (ISM): Move this to individual actions for each script
212
213 break;
214 }
215
216 // clang-format on
217 return config;
218}
219
220
222{
224
225 if( ADVANCED_CFG::GetCfg().m_EnableVariantsUI )
226 {
227 // Variant selection drop down control on main tool bar.
228 auto variantSelectionCtrlFactory =
229 [this]( ACTION_TOOLBAR* aToolbar )
230 {
231 std::optional<wxString> currentVariantName = Schematic().GetCurrentVariant();
232 wxString tmp = currentVariantName ? *currentVariantName : GetDefaultVariantName();
233
234 m_currentVariantCtrl = new wxChoice( aToolbar, ID_TOOLBAR_SCH_SELECT_VARAIANT, wxDefaultPosition,
235 wxDefaultSize, Schematic().GetVariantNamesForUI(), 0,
236 wxDefaultValidator, tmp );
237
238 m_currentVariantCtrl->SetToolTip( _( "Select the current variant to display and edit." ) );
239 aToolbar->Add( m_currentVariantCtrl );
240 UpdateVariantSelectionCtrl( Schematic().GetVariantNamesForUI() );
241 };
242
244 }
245
246 // IPC/Scripting plugin control
247 // TODO (ISM): Clean this up to make IPC actions just normal tool actions to get rid of this entire
248 // control
249 auto pluginControlFactory =
250 [this]( ACTION_TOOLBAR* aToolbar )
251 {
252 // Add scripting console and API plugins
253 bool scriptingAvailable = SCRIPTING::IsWxAvailable();
254
255 #ifdef KICAD_IPC_API
256 bool haveApiPlugins = Pgm().GetCommonSettings()->m_Api.enable_server &&
257 !Pgm().GetPluginManager().GetActionsForScope( PluginActionScope() ).empty();
258 #else
259 bool haveApiPlugins = false;
260 #endif
261
262 if( scriptingAvailable || haveApiPlugins )
263 {
264 aToolbar->AddScaledSeparator( aToolbar->GetParent() );
265
266 if( haveApiPlugins )
267 AddApiPluginTools( aToolbar );
268 }
269 };
270
272}
273
274
275void SCH_EDIT_FRAME::UpdateVariantSelectionCtrl( const wxArrayString& aVariantNames )
276{
278 return;
279
280 // Fall back to the default if nothing is currently selected.
281 wxString currentSelection = GetDefaultVariantName();
282 int selectionIndex = m_currentVariantCtrl->GetSelection();
283
284 if( selectionIndex != wxNOT_FOUND )
285 currentSelection = m_currentVariantCtrl->GetString( selectionIndex );
286
287 m_currentVariantCtrl->Set( aVariantNames );
288
289 selectionIndex = m_currentVariantCtrl->FindString( currentSelection );
290
291 if( ( selectionIndex == wxNOT_FOUND ) && ( m_currentVariantCtrl->GetCount() != 0 ) )
292 selectionIndex = 0;
293
294 m_currentVariantCtrl->SetSelection( selectionIndex );
295}
296
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION toggleGrid
Definition actions.h:197
static TOOL_ACTION paste
Definition actions.h:80
static TOOL_ACTION zoomRedraw
Definition actions.h:131
static TOOL_ACTION millimetersUnits
Definition actions.h:205
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:151
static TOOL_ACTION zoomOutCenter
Definition actions.h:135
static TOOL_ACTION selectSetLasso
Definition actions.h:220
static TOOL_ACTION selectSetRect
Set lasso selection mode.
Definition actions.h:219
static TOOL_ACTION group
Definition actions.h:238
static TOOL_ACTION showSymbolEditor
Definition actions.h:259
static TOOL_ACTION showSymbolBrowser
Definition actions.h:258
static TOOL_ACTION findAndReplace
Definition actions.h:117
static TOOL_ACTION milsUnits
Definition actions.h:204
static TOOL_ACTION ungroup
Definition actions.h:239
static TOOL_ACTION toggleBoundingBoxes
Definition actions.h:156
static TOOL_ACTION plot
Definition actions.h:65
static TOOL_ACTION open
Definition actions.h:57
static TOOL_ACTION pageSettings
Definition actions.h:63
static TOOL_ACTION undo
Definition actions.h:75
static TOOL_ACTION inchesUnits
Definition actions.h:203
static TOOL_ACTION save
Definition actions.h:58
static TOOL_ACTION zoomFitScreen
Definition actions.h:141
static TOOL_ACTION redo
Definition actions.h:76
static TOOL_ACTION deleteTool
Definition actions.h:86
static TOOL_ACTION zoomTool
Definition actions.h:145
static TOOL_ACTION cursor45Crosshairs
Definition actions.h:153
static TOOL_ACTION showFootprintEditor
Definition actions.h:261
static TOOL_ACTION print
Definition actions.h:64
static TOOL_ACTION showProperties
Definition actions.h:265
static TOOL_ACTION doNew
Definition actions.h:54
static TOOL_ACTION zoomFitObjects
Definition actions.h:142
static TOOL_ACTION zoomInCenter
Definition actions.h:134
static TOOL_ACTION toggleGridOverrides
Definition actions.h:198
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:152
static TOOL_ACTION find
Definition actions.h:116
static ACTION_TOOLBAR_CONTROL ipcScripting
Class to hold basic information about controls that can be added to the toolbars.
Define the structure of a toolbar with buttons that invoke ACTIONs.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void RegisterCustomToolbarControlFactory(const ACTION_TOOLBAR_CONTROL &aControlDesc, const ACTION_TOOLBAR_CONTROL_FACTORY &aControlFactory)
Register a creation factory for toolbar controls that are present in this frame.
virtual void configureToolbars()
virtual void AddApiPluginTools(ACTION_TOOLBAR *aToolbar)
Append actions from API plugins to the given toolbar.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:576
wxString GetCurrentVariant() const
Return the current variant being edited.
static TOOL_ACTION showPcbNew
static TOOL_ACTION rotateCCW
static TOOL_ACTION placeClassLabel
Definition sch_actions.h:79
static TOOL_ACTION placeSheetPin
Definition sch_actions.h:85
static TOOL_ACTION assignFootprints
static TOOL_ACTION mirrorV
static TOOL_ACTION placeGlobalLabel
Definition sch_actions.h:80
static TOOL_ACTION editSymbolFields
static TOOL_ACTION drawTextBox
Definition sch_actions.h:93
static TOOL_ACTION toggleAnnotateAuto
static TOOL_ACTION syncAllSheetsPins
Definition sch_actions.h:91
static TOOL_ACTION drawArc
Definition sch_actions.h:97
static TOOL_ACTION drawSheet
Definition sch_actions.h:82
static TOOL_ACTION navigateBack
static TOOL_ACTION schematicSetup
static TOOL_ACTION highlightNetTool
static TOOL_ACTION drawRectangle
Definition sch_actions.h:95
static TOOL_ACTION drawLines
Definition sch_actions.h:99
static TOOL_ACTION placeHierLabel
Definition sch_actions.h:81
static TOOL_ACTION placeLabel
Definition sch_actions.h:78
static TOOL_ACTION drawCircle
Definition sch_actions.h:96
static TOOL_ACTION placeBusWireEntry
Definition sch_actions.h:77
static TOOL_ACTION drawBezier
Definition sch_actions.h:98
static TOOL_ACTION drawWire
Definition sch_actions.h:72
static TOOL_ACTION lineMode45
static TOOL_ACTION rotateCW
static TOOL_ACTION generateBOM
static TOOL_ACTION showHierarchy
static TOOL_ACTION placeJunction
Definition sch_actions.h:76
static TOOL_ACTION drawRuleArea
static TOOL_ACTION placeSymbol
Definition sch_actions.h:66
static TOOL_ACTION placeImage
static TOOL_ACTION navigateForward
static TOOL_ACTION mirrorH
static TOOL_ACTION showSimulator
static TOOL_ACTION drawBus
Definition sch_actions.h:73
static TOOL_ACTION runERC
Inspection and Editing.
static TOOL_ACTION drawTable
Definition sch_actions.h:94
static TOOL_ACTION lineMode90
static TOOL_ACTION placeSchematicText
Definition sch_actions.h:92
static TOOL_ACTION lineModeFree
static TOOL_ACTION annotate
static TOOL_ACTION placeNoConnect
Definition sch_actions.h:75
static TOOL_ACTION toggleHiddenPins
static TOOL_ACTION placePower
Definition sch_actions.h:68
static TOOL_ACTION navigateUp
static ACTION_TOOLBAR_CONTROL currentVariant
wxChoice * m_currentVariantCtrl
void UpdateVariantSelectionCtrl(const wxArrayString &aVariantNames)
Update the variant name control on the main toolbar.
void configureToolbars() override
PLUGIN_ACTION_SCOPE PluginActionScope() const override
SCHEMATIC & Schematic() const
std::optional< TOOLBAR_CONFIGURATION > DefaultToolbarConfig(TOOLBAR_LOC aToolbar) override
Get the default tools to show on the specified canvas toolbar.
#define _(s)
@ ID_TOOLBAR_SCH_SELECT_VARAIANT
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:913
see class PGM_BASE
wxString GetDefaultVariantName()
@ RIGHT
Toolbar on the right side of the canvas.
@ LEFT
Toolbar on the left side of the canvas.
@ TOP_AUX
Toolbar on the top of the canvas.
@ TOP_MAIN
Toolbar on the top of the canvas.