KiCad PCB EDA Suite
tool_lib.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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
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, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #include <fctsys.h>
31 #include <hotkeys.h>
32 #include <eeschema_id.h>
33 
34 #include <general.h>
35 #include <lib_edit_frame.h>
36 #include <dialog_helpers.h>
37 #include <bitmaps.h>
38 
39 #include <help_common_strings.h>
40 
41 #ifdef __UNIX__
42 #define LISTBOX_WIDTH 140
43 #else
44 #define LISTBOX_WIDTH 120
45 #endif
46 
47 
49 {
50  if( m_drawToolBar )
51  m_drawToolBar->Clear();
52  else
53  m_drawToolBar = new wxAuiToolBar( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
54  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
55 
56  // Set up toolbar
57  m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiScaledBitmap( cursor_xpm, this ),
58  _( "Deselect current tool" ), wxITEM_CHECK );
59 
60  m_drawToolBar->AddTool( ID_LIBEDIT_PIN_BUTT, wxEmptyString, KiScaledBitmap( pin_xpm, this ),
61  HELP_ADD_PIN, wxITEM_CHECK );
62 
63  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_TEXT_BUTT, wxEmptyString,
64  KiScaledBitmap( text_xpm, this ),
65  HELP_ADD_BODYTEXT, wxITEM_CHECK );
66 
67  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_RECT_BUTT, wxEmptyString,
68  KiScaledBitmap( add_rectangle_xpm, this ),
69  HELP_ADD_BODYRECT, wxITEM_CHECK );
70 
71  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_CIRCLE_BUTT, wxEmptyString,
72  KiScaledBitmap( add_circle_xpm, this ),
73  HELP_ADD_BODYCIRCLE, wxITEM_CHECK );
74 
75  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_ARC_BUTT, wxEmptyString,
76  KiScaledBitmap( add_arc_xpm, this ),
77  HELP_ADD_BODYARC, wxITEM_CHECK );
78 
79  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_LINE_BUTT, wxEmptyString,
80  KiScaledBitmap( add_polygon_xpm, this ),
81  HELP_ADD_BODYPOLYGON, wxITEM_CHECK );
82 
83  m_drawToolBar->AddTool( ID_LIBEDIT_ANCHOR_ITEM_BUTT, wxEmptyString,
84  KiScaledBitmap( anchor_xpm, this ),
85  _( "Move symbol anchor" ), wxITEM_CHECK );
86 
87  m_drawToolBar->AddTool( ID_LIBEDIT_IMPORT_BODY_BUTT, wxEmptyString,
88  KiScaledBitmap( import_xpm, this ),
89  _( "Import existing drawings" ), wxITEM_CHECK );
90 
91  m_drawToolBar->AddTool( ID_LIBEDIT_EXPORT_BODY_BUTT, wxEmptyString,
92  KiScaledBitmap( export_xpm, this ),
93  _( "Export current drawing" ), wxITEM_CHECK );
94 
95  m_drawToolBar->AddTool( ID_LIBEDIT_DELETE_ITEM_BUTT, wxEmptyString,
96  KiScaledBitmap( delete_xpm, this ),
97  HELP_DELETE_ITEMS, wxITEM_CHECK );
98 
99  m_drawToolBar->Realize();
100 }
101 
102 
104 {
105  wxString msg;
106 
107  if( m_mainToolBar )
108  m_mainToolBar->Clear();
109  else
110  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
111  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
112 
113  // Set up toolbar
114  m_mainToolBar->AddTool( ID_LIBEDIT_NEW_LIBRARY, wxEmptyString,
115  KiScaledBitmap( new_library_xpm, this ),
116  _( "Create a new library" ) );
117 
118  m_mainToolBar->AddTool( ID_LIBEDIT_ADD_LIBRARY, wxEmptyString,
119  KiScaledBitmap( add_library_xpm, this ),
120  _( "Add an existing library" ) );
121 
122  m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_LIBRARY, wxEmptyString,
123  KiScaledBitmap( save_library_xpm, this ),
124  _( "Save current library" ) );
125 
127 
128  m_mainToolBar->AddTool( ID_LIBEDIT_NEW_PART, wxEmptyString,
129  KiScaledBitmap( new_component_xpm, this ),
130  _( "Create new symbol" ) );
131 
132  m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_PART, wxEmptyString,
133  KiScaledBitmap( save_part_xpm, this ),
134  _( "Save current symbol" ) );
135 
136  m_mainToolBar->AddTool( ID_LIBEDIT_IMPORT_PART, wxEmptyString,
137  KiScaledBitmap( import_part_xpm, this ),
138  _( "Import symbol" ) );
139 
140  m_mainToolBar->AddTool( ID_LIBEDIT_EXPORT_PART, wxEmptyString,
141  KiScaledBitmap( export_part_xpm, this ),
142  _( "Export symbol" ) );
143 
145 
146  m_mainToolBar->AddTool( wxID_PASTE, wxEmptyString, KiScaledBitmap( paste_xpm, this ),
147  _( "Paste" ) );
148 
150 
152  m_mainToolBar->AddTool( wxID_UNDO, wxEmptyString, KiScaledBitmap( undo_xpm, this ), msg );
153 
155  m_mainToolBar->AddTool( wxID_REDO, wxEmptyString, KiScaledBitmap( redo_xpm, this ), msg );
156 
158 
159  m_mainToolBar->AddTool( ID_LIBEDIT_GET_FRAME_EDIT_PART, wxEmptyString,
160  KiScaledBitmap( part_properties_xpm, this ),
161  _( "Edit symbol properties" ) );
162 
163  m_mainToolBar->AddTool( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, wxEmptyString,
164  KiScaledBitmap( text_xpm, this ),
165  _( "Edit field properties" ) );
166 
168 
169  m_mainToolBar->AddTool( ID_LIBEDIT_CHECK_PART, wxEmptyString, KiScaledBitmap( erc_xpm, this ),
170  _( "Check duplicate and off grid pins" ) );
171 
173 
175  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
176  KiScaledBitmap( zoom_redraw_xpm, this ), msg );
177 
179  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiScaledBitmap( zoom_in_xpm, this ), msg );
180 
182  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiScaledBitmap( zoom_out_xpm, this ), msg );
183 
184  msg = AddHotkeyName( _( "Zoom to fit symbol" ), g_Libedit_Hokeys_Descr,
186  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
187  KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg );
188 
189  m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiScaledBitmap( zoom_area_xpm, this ),
190  _( "Zoom to selection" ), wxITEM_CHECK );
191 
193 
194  m_mainToolBar->AddTool( ID_DE_MORGAN_NORMAL_BUTT, wxEmptyString,
195  KiScaledBitmap( morgan1_xpm, this ),
196  _( "Show as \"De Morgan\" normal symbol" ), wxITEM_CHECK );
197  m_mainToolBar->AddTool( ID_DE_MORGAN_CONVERT_BUTT, wxEmptyString,
198  KiScaledBitmap( morgan2_xpm, this ),
199  _( "Show as \"De Morgan\" convert symbol" ), wxITEM_CHECK );
200 
202 
203  m_mainToolBar->AddTool( ID_LIBEDIT_VIEW_DOC, wxEmptyString,
204  KiScaledBitmap( datasheet_xpm, this ),
205  _( "Show associated datasheet or document" ) );
206 
208 
209  m_partSelectBox = new wxComboBox( m_mainToolBar,
211  wxEmptyString,
212  wxDefaultPosition,
213  wxSize( LISTBOX_WIDTH, -1 ),
214  0, nullptr, wxCB_READONLY );
215  m_mainToolBar->AddControl( m_partSelectBox );
216 
217  m_aliasSelectBox = new wxComboBox( m_mainToolBar,
219  wxEmptyString,
220  wxDefaultPosition,
221  wxSize( LISTBOX_WIDTH, -1 ),
222  0, nullptr, wxCB_READONLY );
223  m_mainToolBar->AddControl( m_aliasSelectBox );
224 
225  m_mainToolBar->AddSeparator();
227  msg = _( "Synchronized pin edit mode\n"
228  "Synchronized pin edit mode propagates to other units all pin changes except pin number modification.\n"
229  "Enabled by default for multiunit parts with interchangeable units." );
230  m_mainToolBar->AddTool( ID_LIBEDIT_SYNC_PIN_EDIT, wxEmptyString,
231  KiScaledBitmap( pin2pin_xpm, this ), msg, wxITEM_CHECK );
232  m_mainToolBar->AddTool( ID_LIBEDIT_EDIT_PIN_BY_TABLE, wxEmptyString,
233  KiScaledBitmap( pin_table_xpm, this ),
234  _( "Show pin table" ) );
235 
236  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
237  m_mainToolBar->Realize();
238 }
239 
240 
242 {
243  if( m_optionsToolBar )
244  m_optionsToolBar->Clear();
245  else
246  m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
247  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
248 
249  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString,
250  KiScaledBitmap( grid_xpm, this ),
251  _( "Turn grid off" ), wxITEM_CHECK );
252 
253  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
254  KiScaledBitmap( unit_inch_xpm, this ), _( "Set units to inches" ),
255  wxITEM_CHECK );
256 
257  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
258  KiScaledBitmap( unit_mm_xpm, this ),
259  _( "Set units to millimeters" ), wxITEM_CHECK );
260 
261 #ifndef __APPLE__
262  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
263  KiScaledBitmap( cursor_shape_xpm, this ),
264  _( "Change cursor shape" ), wxITEM_CHECK );
265 #else
266  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
267  KiScaledBitmap( cursor_shape_xpm, this ),
268  _( "Change cursor shape (not supported in Legacy Toolset)" ),
269  wxITEM_CHECK );
270 #endif
271 
272  m_optionsToolBar->AddTool( ID_LIBEDIT_SHOW_ELECTRICAL_TYPE, wxEmptyString,
273  KiScaledBitmap( pin_show_etype_xpm, this ),
274  _( "Show pins electrical type" ), wxITEM_CHECK );
275 
276  m_optionsToolBar->AddTool( ID_LIBEDIT_SHOW_HIDE_SEARCH_TREE, wxEmptyString,
277  KiScaledBitmap( search_tree_xpm, this ),
278  _( "Toggles the search tree" ), wxITEM_CHECK );
279 
280  m_optionsToolBar->Realize();
281 }
void ReCreateOptToolbar()
Definition: tool_lib.cpp:241
#define HELP_ADD_BODYRECT
#define HELP_ADD_BODYCIRCLE
Definition: id.h:242
struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[]
#define LISTBOX_WIDTH
Definition: tool_lib.cpp:44
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Function KiScaledBitmap Constructs a wxBitmap from a memory record, scaling it if device DPI demands ...
Definition: bitmap.cpp:114
#define HELP_ZOOM_OUT
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
Definition: draw_frame.cpp:123
#define HELP_ZOOM_REDRAW
#define HELP_ADD_BODYPOLYGON
wxAuiToolBar * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:138
strings common to toolbars and menubar
wxComboBox * m_partSelectBox
a Box to select a part to edit (if any)
#define HELP_ADD_BODYTEXT
Helper dialog and control classes.
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:135
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
#define HELP_REDO
#define HELP_ADD_BODYARC
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
void ReCreateHToolbar() override
Definition: tool_lib.cpp:103
#define HELP_ADD_PIN
#define HELP_ZOOM_IN
#define HELP_UNDO
These strings are used in menus and tools, that do the same command But they are internationalized, and therefore must be created at run time, on the fly.
void KiScaledSeparator(wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
Function KiScaledSeparator Adds a separator to the given toolbar scaled the same way as KiScaledBitma...
Definition: bitmap.cpp:146
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
Definition of class LIB_EDIT_FRAME.
static const char * text_xpm[]
#define HELP_DELETE_ITEMS
wxComboBox * m_aliasSelectBox
a box to select the alias to edit (if any)
void ReCreateVToolbar() override
Definition: tool_lib.cpp:48