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-2017 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2004-2017 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 <libeditframe.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 != NULL )
51  return;
52 
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, KiBitmap( cursor_xpm ),
58  _( "Deselect current tool" ), wxITEM_CHECK );
59 
60  m_drawToolBar->AddTool( ID_LIBEDIT_PIN_BUTT, wxEmptyString, KiBitmap( pin_xpm ),
61  HELP_ADD_PIN, wxITEM_CHECK );
62 
63  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_TEXT_BUTT, wxEmptyString, KiBitmap( text_xpm ),
64  HELP_ADD_BODYTEXT, wxITEM_CHECK );
65 
66  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_RECT_BUTT, wxEmptyString, KiBitmap( add_rectangle_xpm ),
67  HELP_ADD_BODYRECT, wxITEM_CHECK );
68 
69  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_CIRCLE_BUTT, wxEmptyString, KiBitmap( add_circle_xpm ),
70  HELP_ADD_BODYCIRCLE, wxITEM_CHECK );
71 
72  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_ARC_BUTT, wxEmptyString, KiBitmap( add_arc_xpm ),
73  HELP_ADD_BODYARC, wxITEM_CHECK );
74 
75  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_LINE_BUTT, wxEmptyString, KiBitmap( add_polygon_xpm ),
76  HELP_ADD_BODYPOLYGON, wxITEM_CHECK );
77 
78  m_drawToolBar->AddTool( ID_LIBEDIT_ANCHOR_ITEM_BUTT, wxEmptyString, KiBitmap( anchor_xpm ),
79  _( "Move part anchor" ), wxITEM_CHECK );
80 
81  m_drawToolBar->AddTool( ID_LIBEDIT_IMPORT_BODY_BUTT, wxEmptyString, KiBitmap( import_xpm ),
82  _( "Import existing drawings" ), wxITEM_CHECK );
83 
84  m_drawToolBar->AddTool( ID_LIBEDIT_EXPORT_BODY_BUTT, wxEmptyString, KiBitmap( export_xpm ),
85  _( "Export current drawing" ), wxITEM_CHECK );
86 
87  m_drawToolBar->AddTool( ID_LIBEDIT_DELETE_ITEM_BUTT, wxEmptyString, KiBitmap( delete_xpm ),
88  HELP_DELETE_ITEMS, wxITEM_CHECK );
89 
90  m_drawToolBar->Realize();
91 }
92 
93 
95 {
96  wxString msg;
97 
98  // Create the toolbar if not exists
99  if( m_mainToolBar != NULL )
100  return;
101 
102  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
103  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
104 
105  // Set up toolbar
106  m_mainToolBar->AddTool( ID_LIBEDIT_NEW_LIBRARY, wxEmptyString,
107  KiBitmap( new_library_xpm ),
108  _( "Create a new library" ) );
109 
110  m_mainToolBar->AddTool( ID_LIBEDIT_ADD_LIBRARY, wxEmptyString,
111  KiBitmap( add_library_xpm ),
112  _( "Add an existing library" ) );
113 
114  m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_LIBRARY, wxEmptyString,
115  KiBitmap( save_library_xpm ),
116  _( "Save current library" ) );
117 
118  m_mainToolBar->AddSeparator();
119  m_mainToolBar->AddTool( ID_LIBEDIT_NEW_PART, wxEmptyString, KiBitmap( new_component_xpm ),
120  _( "Create new part" ) );
121 
122  m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_PART, wxEmptyString,
123  KiBitmap( save_part_xpm ),
124  _( "Save current part" ) );
125 
126  m_mainToolBar->AddTool( ID_LIBEDIT_IMPORT_PART, wxEmptyString, KiBitmap( import_part_xpm ),
127  _( "Import part" ) );
128 
129  m_mainToolBar->AddTool( ID_LIBEDIT_EXPORT_PART, wxEmptyString, KiBitmap( export_part_xpm ),
130  _( "Export part" ) );
131 
132  m_mainToolBar->AddSeparator();
133 
134  m_mainToolBar->AddTool( wxID_PASTE, wxEmptyString, KiBitmap( paste_xpm ),
135  _( "Paste" ) );
136 
137  m_mainToolBar->AddSeparator();
138 
140  m_mainToolBar->AddTool( wxID_UNDO, wxEmptyString, KiBitmap( undo_xpm ), msg );
141 
143  m_mainToolBar->AddTool( wxID_REDO, wxEmptyString, KiBitmap( redo_xpm ), msg );
144 
145  m_mainToolBar->AddSeparator();
146 
147  m_mainToolBar->AddTool( ID_LIBEDIT_GET_FRAME_EDIT_PART, wxEmptyString,
148  KiBitmap( part_properties_xpm ), _( "Edit part properties" ) );
149 
150  m_mainToolBar->AddTool( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, wxEmptyString,
151  KiBitmap( text_xpm ),
152  _( "Edit field properties" ) );
153 
154  m_mainToolBar->AddSeparator();
155  m_mainToolBar->AddTool( ID_LIBEDIT_CHECK_PART, wxEmptyString, KiBitmap( erc_xpm ),
156  _( "Check duplicate and off grid pins" ) );
157 
158  m_mainToolBar->AddSeparator();
160  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString, KiBitmap( zoom_redraw_xpm ), msg );
161 
163  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiBitmap( zoom_in_xpm ), msg );
164 
166  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiBitmap( zoom_out_xpm ), msg );
167 
169  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ), msg );
170 
171  m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiBitmap( zoom_area_xpm ),
172  _( "Zoom to selection" ), wxITEM_CHECK );
173 
174  m_mainToolBar->AddSeparator();
175  m_mainToolBar->AddTool( ID_DE_MORGAN_NORMAL_BUTT, wxEmptyString, KiBitmap( morgan1_xpm ),
176  _( "Show as \"De Morgan\" normal part" ), wxITEM_CHECK );
177  m_mainToolBar->AddTool( ID_DE_MORGAN_CONVERT_BUTT, wxEmptyString, KiBitmap( morgan2_xpm ),
178  _( "Show as \"De Morgan\" convert part" ), wxITEM_CHECK );
179 
180  m_mainToolBar->AddSeparator();
181  m_mainToolBar->AddTool( ID_LIBEDIT_VIEW_DOC, wxEmptyString, KiBitmap( datasheet_xpm ),
182  _( "Show associated datasheet or document" ) );
183 
184  m_mainToolBar->AddSeparator();
185  m_partSelectBox = new wxComboBox( m_mainToolBar,
187  wxEmptyString,
188  wxDefaultPosition,
189  wxSize( LISTBOX_WIDTH, -1 ),
190  0, NULL, wxCB_READONLY );
191  m_mainToolBar->AddControl( m_partSelectBox );
192 
193  m_aliasSelectBox = new wxComboBox( m_mainToolBar,
195  wxEmptyString,
196  wxDefaultPosition,
197  wxSize( LISTBOX_WIDTH, -1 ),
198  0, NULL, wxCB_READONLY );
199  m_mainToolBar->AddControl( m_aliasSelectBox );
200 
201  m_mainToolBar->AddSeparator();
202  msg = _( "Edit pins per part or body style (Use carefully!)" );
203  m_mainToolBar->AddTool( ID_LIBEDIT_EDIT_PIN_BY_PIN, wxEmptyString, KiBitmap( pin2pin_xpm ),
204  msg, wxITEM_CHECK );
205  m_mainToolBar->AddTool( ID_LIBEDIT_EDIT_PIN_BY_TABLE, wxEmptyString, KiBitmap( pin_table_xpm ),
206  _( "Show pin table" ) );
207 
208  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
209  m_mainToolBar->Realize();
210 }
211 
212 
214 {
215  if( m_optionsToolBar )
216  return;
217 
218  m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
219  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
220 
221  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiBitmap( grid_xpm ),
222  _( "Turn grid off" ), wxITEM_CHECK );
223 
224  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
225  KiBitmap( unit_inch_xpm ), _( "Set units to inches" ),
226  wxITEM_CHECK );
227 
228  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
229  KiBitmap( unit_mm_xpm ),
230  _( "Set units to millimeters" ), wxITEM_CHECK );
231 
232 #ifndef __APPLE__
233  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
234  KiBitmap( cursor_shape_xpm ),
235  _( "Change cursor shape" ), wxITEM_CHECK );
236 #endif // !__APPLE__
237 
238  m_optionsToolBar->AddTool( ID_LIBEDIT_SHOW_ELECTRICAL_TYPE, wxEmptyString,
239  KiBitmap( pin_show_etype_xpm ),
240  _( "Show pins electrical type" ), wxITEM_CHECK );
241 
242  m_optionsToolBar->AddTool( ID_LIBEDIT_SHOW_HIDE_SEARCH_TREE, wxEmptyString,
243  KiBitmap( search_tree_xpm ),
244  _( "Toggles the search tree" ), wxITEM_CHECK );
245 
246  m_optionsToolBar->Realize();
247 }
#define HELP_ADD_BODYRECT
#define HELP_ADD_BODYCIRCLE
#define HELP_ZOOM_FIT
Definition: id.h:232
struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[]
#define LISTBOX_WIDTH
Definition: tool_lib.cpp:44
#define HELP_ZOOM_OUT
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
Definition: draw_frame.cpp:124
#define HELP_ZOOM_REDRAW
#define HELP_ADD_BODYPOLYGON
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
wxAuiToolBar * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:126
strings common to toolbars and menubar
wxComboBox * m_partSelectBox
a Box to select a part to edit (if any)
Definition: libeditframe.h:63
#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:123
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:145
void CreateOptionToolbar()
Definition: tool_lib.cpp:213
#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:94
#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.
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
Definition: wxstruct.h:168
static const char * text_xpm[]
#define HELP_DELETE_ITEMS
Definition of class LIB_EDIT_FRAME.
wxComboBox * m_aliasSelectBox
a box to select the alias to edit (if any)
Definition: libeditframe.h:64
void ReCreateVToolbar() override
Definition: tool_lib.cpp:48