KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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_toolbar.h>
24#include <tool/tool_manager.h>
25#include <tools/pl_actions.h>
27#include <wx/choice.h>
28
29#include "pl_editor_id.h"
30#include "pl_editor_frame.h"
31#include <toolbars_pl_editor.h>
32
33
34std::optional<TOOLBAR_CONFIGURATION> PL_EDITOR_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
35{
37
38 // clang-format off
39 switch( aToolbar )
40 {
41 // No aux toolbar
42 case TOOLBAR_LOC::TOP_AUX:
43 return std::nullopt;
44
45 case TOOLBAR_LOC::LEFT:
46 config.AppendAction( ACTIONS::toggleGrid )
47 .AppendAction( ACTIONS::inchesUnits )
48 .AppendAction( ACTIONS::milsUnits )
49 .AppendAction( ACTIONS::millimetersUnits );
50
51 /* TODO: Implement context menus
52 PL_SELECTION_TOOL* selTool = m_toolManager->GetTool<PL_SELECTION_TOOL>();
53 std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
54 gridMenu->Add( ACTIONS::gridProperties );
55 m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
56 */
57 break;
58
59 case TOOLBAR_LOC::RIGHT:
60 config.AppendAction( ACTIONS::selectionTool );
61
62 config.AppendSeparator()
63 .AppendAction( PL_ACTIONS::drawLine )
64 .AppendAction( PL_ACTIONS::drawRectangle )
65 .AppendAction( PL_ACTIONS::placeText )
66 .AppendAction( PL_ACTIONS::placeImage )
68
69 config.AppendSeparator()
70 .AppendAction( ACTIONS::deleteTool );
71 break;
72
73 case TOOLBAR_LOC::TOP_MAIN:
74 config.AppendAction( ACTIONS::doNew )
75 .AppendAction( ACTIONS::open )
76 .AppendAction( ACTIONS::save );
77
78 config.AppendSeparator()
79 .AppendAction( ACTIONS::print );
80
81 config.AppendSeparator()
82 .AppendAction( ACTIONS::undo )
83 .AppendAction( ACTIONS::redo );
84
85 config.AppendSeparator()
86 .AppendAction( ACTIONS::zoomRedraw )
87 .AppendAction( ACTIONS::zoomInCenter )
88 .AppendAction( ACTIONS::zoomOutCenter )
89 .AppendAction( ACTIONS::zoomFitScreen )
90 .AppendAction( ACTIONS::zoomTool );
91
92 config.AppendSeparator()
93 .AppendAction( PL_ACTIONS::showInspector )
94 .AppendAction( PL_ACTIONS::previewSettings );
95
96 // Display mode switch
97 config.AppendSeparator()
98 .AppendAction( PL_ACTIONS::layoutNormalMode )
99 .AppendAction( PL_ACTIONS::layoutEditMode );
100
101 config.AppendSeparator()
104 break;
105 }
106
107 // clang-format on
108 return config;
109}
110
111
113{
115
116 auto originSelectorFactory =
117 [this]( ACTION_TOOLBAR* aToolbar )
118 {
119 if( !m_originSelectBox )
120 {
121 m_originSelectBox = new wxChoice( aToolbar, ID_SELECT_COORDINATE_ORIGIN,
122 wxDefaultPosition, wxDefaultSize, 5, m_originChoiceList );
123 }
124
125 m_originSelectBox->SetToolTip( _("Origin of coordinates displayed to the status bar") );
127
128 aToolbar->Add( m_originSelectBox );
129 };
130
132
133
134 auto pageSelectorFactory =
135 [this]( ACTION_TOOLBAR* aToolbar )
136 {
137 wxString pageList[5] =
138 {
139 _("Page 1"),
140 _("Other pages")
141 };
142
143 if( !m_pageSelectBox )
144 {
145 m_pageSelectBox = new wxChoice( aToolbar, ID_SELECT_PAGE_NUMBER,
146 wxDefaultPosition, wxDefaultSize, 2, pageList );
147 }
148
149 m_pageSelectBox->SetToolTip( _("Simulate page 1 or other pages to show how items\n"\
150 "which are not on all page are displayed") );
151 m_pageSelectBox->SetSelection( 0 );
152
153 aToolbar->Add( m_pageSelectBox );
154 };
155
157}
158
159
160ACTION_TOOLBAR_CONTROL PL_EDITOR_ACTION_TOOLBAR_CONTROLS::originSelector( "control.OriginSelector", _( "Origin Selector" ),
161 _( "Select the origin of the status bar coordinates" ) );
162ACTION_TOOLBAR_CONTROL PL_EDITOR_ACTION_TOOLBAR_CONTROLS::pageSelect( "control.PageSelect", _( "Page Selector" ),
163 _( "Select the page to simulate item displays" ));
164
165
166
168{
169 // Ensure the origin selector is a minimum size
170 int minwidth = 0;
171
172 for( int ii = 0; ii < 5; ii++ )
173 {
175 minwidth = std::max( minwidth, width );
176 }
177
178 m_originSelectBox->SetMinSize( wxSize( minwidth, -1 ) );
179
180 // Base class actually will go through and update the sizes of the controls
182}
static TOOL_ACTION toggleGrid
Definition: actions.h:191
static TOOL_ACTION zoomRedraw
Definition: actions.h:124
static TOOL_ACTION millimetersUnits
Definition: actions.h:199
static TOOL_ACTION zoomOutCenter
Definition: actions.h:128
static TOOL_ACTION milsUnits
Definition: actions.h:198
static TOOL_ACTION open
Definition: actions.h:50
static TOOL_ACTION undo
Definition: actions.h:68
static TOOL_ACTION inchesUnits
Definition: actions.h:197
static TOOL_ACTION selectionTool
Definition: actions.h:206
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION zoomFitScreen
Definition: actions.h:134
static TOOL_ACTION redo
Definition: actions.h:69
static TOOL_ACTION deleteTool
Definition: actions.h:79
static TOOL_ACTION zoomTool
Definition: actions.h:138
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION doNew
Definition: actions.h:47
static TOOL_ACTION zoomInCenter
Definition: actions.h:127
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
static TOOL_ACTION placeImage
Definition: pl_actions.h:59
static TOOL_ACTION drawRectangle
Definition: pl_actions.h:60
static TOOL_ACTION showInspector
Definition: pl_actions.h:72
static TOOL_ACTION previewSettings
Definition: pl_actions.h:73
static TOOL_ACTION layoutNormalMode
Definition: pl_actions.h:67
static TOOL_ACTION placeText
Definition: pl_actions.h:58
static TOOL_ACTION layoutEditMode
Definition: pl_actions.h:68
static TOOL_ACTION appendImportedDrawingSheet
Definition: pl_actions.h:62
static TOOL_ACTION drawLine
Definition: pl_actions.h:61
static ACTION_TOOLBAR_CONTROL pageSelect
static ACTION_TOOLBAR_CONTROL originSelector
void configureToolbars() 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.
#define _(s)
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
Definition: pl_editor_id.h:40
@ ID_SELECT_COORDINATE_ORIGIN
Definition: pl_editor_id.h:39