KiCad PCB EDA Suite
Loading...
Searching...
No Matches
toolbars_pl_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 * Copyright (C) 2013-2019 CERN
6 * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <bitmaps.h>
23#include <tool/action_menu.h>
24#include <tool/action_toolbar.h>
25#include <tool/tool_manager.h>
27#include <tools/pl_actions.h>
29#include <wx/choice.h>
30
31#include "pl_editor_id.h"
32#include "pl_editor_frame.h"
33#include <toolbars_pl_editor.h>
34
35
36std::optional<TOOLBAR_CONFIGURATION> PL_EDITOR_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
37{
39
40 // clang-format off
41 switch( aToolbar )
42 {
43 // No aux toolbar
45 return std::nullopt;
46
48 config.AppendAction( ACTIONS::toggleGrid )
49 .WithContextMenu(
50 []( TOOL_MANAGER* aToolMgr )
51 {
52 PL_SELECTION_TOOL* selTool = aToolMgr->GetTool<PL_SELECTION_TOOL>();
53 auto menu = std::make_unique<ACTION_MENU>( false, selTool );
54 menu->Add( ACTIONS::gridProperties );
55 return menu;
56 } )
57 .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) )
58 .AddAction( ACTIONS::millimetersUnits )
59 .AddAction( ACTIONS::inchesUnits )
60 .AddAction( ACTIONS::milsUnits ) );
61 break;
62
64 config.AppendAction( ACTIONS::selectionTool );
65
66 config.AppendSeparator()
67 .AppendAction( PL_ACTIONS::drawLine )
68 .AppendAction( PL_ACTIONS::drawRectangle )
69 .AppendAction( PL_ACTIONS::placeText )
70 .AppendAction( PL_ACTIONS::placeImage )
72
73 config.AppendSeparator()
74 .AppendAction( ACTIONS::deleteTool );
75 break;
76
78 config.AppendAction( ACTIONS::doNew )
79 .AppendAction( ACTIONS::open )
80 .AppendAction( ACTIONS::save );
81
82 config.AppendSeparator()
83 .AppendAction( ACTIONS::print );
84
85 config.AppendSeparator()
86 .AppendAction( ACTIONS::undo )
87 .AppendAction( ACTIONS::redo );
88
89 config.AppendSeparator()
90 .AppendAction( ACTIONS::zoomRedraw )
91 .AppendAction( ACTIONS::zoomInCenter )
92 .AppendAction( ACTIONS::zoomOutCenter )
93 .AppendAction( ACTIONS::zoomFitScreen )
94 .AppendAction( ACTIONS::zoomTool );
95
96 config.AppendSeparator()
97 .AppendAction( PL_ACTIONS::showInspector )
98 .AppendAction( PL_ACTIONS::previewSettings );
99
100 // Display mode switch
101 config.AppendSeparator()
102 .AppendAction( PL_ACTIONS::layoutNormalMode )
103 .AppendAction( PL_ACTIONS::layoutEditMode );
104
105 config.AppendSeparator()
108 break;
109 }
110
111 // clang-format on
112 return config;
113}
114
115
117{
119
120 auto originSelectorFactory =
121 [this]( ACTION_TOOLBAR* aToolbar )
122 {
123 if( !m_originSelectBox )
124 {
125 m_originSelectBox = new wxChoice( aToolbar, ID_SELECT_COORDINATE_ORIGIN,
126 wxDefaultPosition, wxDefaultSize, 5, m_originChoiceList );
127 }
128
129 m_originSelectBox->SetToolTip( _("Origin of coordinates displayed to the status bar") );
131
132 aToolbar->Add( m_originSelectBox );
133 };
134
136
137
138 auto pageSelectorFactory =
139 [this]( ACTION_TOOLBAR* aToolbar )
140 {
141 wxString pageList[5] =
142 {
143 _("Page 1"),
144 _("Other pages")
145 };
146
147 if( !m_pageSelectBox )
148 {
149 m_pageSelectBox = new wxChoice( aToolbar, ID_SELECT_PAGE_NUMBER,
150 wxDefaultPosition, wxDefaultSize, 2, pageList );
151 }
152
153 m_pageSelectBox->SetToolTip( _("Simulate page 1 or other pages to show how items\n"\
154 "which are not on all page are displayed") );
155 m_pageSelectBox->SetSelection( 0 );
156
157 aToolbar->Add( m_pageSelectBox );
158 };
159
161}
162
163
165{
167
168 switch( aId )
169 {
170 case ID_SELECT_COORDINATE_ORIGIN: m_originSelectBox = nullptr; break;
171 case ID_SELECT_PAGE_NUMBER: m_pageSelectBox = nullptr; break;
172 }
173}
174
175
177 _( "Origin selector" ),
178 _( "Select the origin of the status bar coordinates" ),
179 { FRAME_PL_EDITOR } );
181 _( "Page selector" ),
182 _( "Select the page to simulate item displays" ),
183 { FRAME_PL_EDITOR } );
184
185
186
188{
189 // Ensure the origin selector is a minimum size
190 int minwidth = 0;
191
192 for( int ii = 0; ii < 5; ii++ )
193 {
195 minwidth = std::max( minwidth, width );
196 }
197
198 m_originSelectBox->SetMinSize( wxSize( minwidth, -1 ) );
199
200 // Base class actually will go through and update the sizes of the controls
202}
static TOOL_ACTION gridProperties
Definition actions.h:200
static TOOL_ACTION toggleGrid
Definition actions.h:198
static TOOL_ACTION zoomRedraw
Definition actions.h:132
static TOOL_ACTION millimetersUnits
Definition actions.h:206
static TOOL_ACTION zoomOutCenter
Definition actions.h:136
static TOOL_ACTION milsUnits
Definition actions.h:205
static TOOL_ACTION open
Definition actions.h:57
static TOOL_ACTION undo
Definition actions.h:75
static TOOL_ACTION inchesUnits
Definition actions.h:204
static TOOL_ACTION selectionTool
Definition actions.h:251
static TOOL_ACTION save
Definition actions.h:58
static TOOL_ACTION zoomFitScreen
Definition actions.h:142
static TOOL_ACTION redo
Definition actions.h:76
static TOOL_ACTION deleteTool
Definition actions.h:86
static TOOL_ACTION zoomTool
Definition actions.h:146
static TOOL_ACTION print
Definition actions.h:64
static TOOL_ACTION doNew
Definition actions.h:54
static TOOL_ACTION zoomInCenter
Definition actions.h:135
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.
virtual void UpdateToolbarControlSizes()
Update the sizes of any controls in the toolbars of the frame.
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.
void configureToolbars() override
void ClearToolbarControl(int aId) override
static TOOL_ACTION placeImage
Definition pl_actions.h:41
static TOOL_ACTION drawRectangle
Definition pl_actions.h:42
static TOOL_ACTION showInspector
Definition pl_actions.h:54
static TOOL_ACTION previewSettings
Definition pl_actions.h:55
static TOOL_ACTION layoutNormalMode
Definition pl_actions.h:49
static TOOL_ACTION placeText
Definition pl_actions.h:40
static TOOL_ACTION layoutEditMode
Definition pl_actions.h:50
static TOOL_ACTION appendImportedDrawingSheet
Definition pl_actions.h:44
static TOOL_ACTION drawLine
Definition pl_actions.h:43
static ACTION_TOOLBAR_CONTROL pageSelect
static ACTION_TOOLBAR_CONTROL originSelector
void configureToolbars() override
void ClearToolbarControl(int aId) override
void UpdateToolbarControlSizes() override
Update the sizes of any controls in the toolbars of the frame.
wxChoice * m_originSelectBox
wxString m_originChoiceList[5]
wxChoice * m_pageSelectBox
std::optional< TOOLBAR_CONFIGURATION > DefaultToolbarConfig(TOOLBAR_LOC aToolbar) override
Get the default tools to show on the specified canvas toolbar.
Master controller class:
#define _(s)
@ FRAME_PL_EDITOR
Definition frame_type.h:59
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition ui_common.cpp:78
@ ID_SELECT_PAGE_NUMBER
@ ID_SELECT_COORDINATE_ORIGIN
@ 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.