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 
48 extern int ExportPartId;
49 extern int ImportPartId;
50 extern int CreateNewLibAndSavePartId;
51 
52 
54 {
55  if( m_drawToolBar != NULL )
56  return;
57 
58  m_drawToolBar = new wxAuiToolBar( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
59  wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_VERTICAL );
60 
61  // Set up toolbar
62  m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiBitmap( cursor_xpm ),
63  _( "Deselect current tool" ), wxITEM_CHECK );
64 
65  m_drawToolBar->AddTool( ID_LIBEDIT_PIN_BUTT, wxEmptyString, KiBitmap( pin_xpm ),
66  HELP_ADD_PIN, wxITEM_CHECK );
67 
68  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_TEXT_BUTT, wxEmptyString, KiBitmap( text_xpm ),
69  HELP_ADD_BODYTEXT, wxITEM_CHECK );
70 
71  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_RECT_BUTT, wxEmptyString, KiBitmap( add_rectangle_xpm ),
72  HELP_ADD_BODYRECT, wxITEM_CHECK );
73 
74  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_CIRCLE_BUTT, wxEmptyString, KiBitmap( add_circle_xpm ),
75  HELP_ADD_BODYCIRCLE, wxITEM_CHECK );
76 
77  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_ARC_BUTT, wxEmptyString, KiBitmap( add_arc_xpm ),
78  HELP_ADD_BODYARC, wxITEM_CHECK );
79 
80  m_drawToolBar->AddTool( ID_LIBEDIT_BODY_LINE_BUTT, wxEmptyString, KiBitmap( add_polygon_xpm ),
81  HELP_ADD_BODYPOLYGON, wxITEM_CHECK );
82 
83  m_drawToolBar->AddTool( ID_LIBEDIT_ANCHOR_ITEM_BUTT, wxEmptyString, KiBitmap( anchor_xpm ),
84  _( "Move part anchor" ), wxITEM_CHECK );
85 
86  m_drawToolBar->AddTool( ID_LIBEDIT_IMPORT_BODY_BUTT, wxEmptyString, KiBitmap( import_xpm ),
87  _( "Import existing drawings" ), wxITEM_CHECK );
88 
89  m_drawToolBar->AddTool( ID_LIBEDIT_EXPORT_BODY_BUTT, wxEmptyString, KiBitmap( export_xpm ),
90  _( "Export current drawing" ), wxITEM_CHECK );
91 
92  m_drawToolBar->AddTool( ID_LIBEDIT_DELETE_ITEM_BUTT, wxEmptyString, KiBitmap( delete_xpm ),
93  HELP_DELETE_ITEMS, wxITEM_CHECK );
94 
95  m_drawToolBar->Realize();
96 }
97 
98 
100 {
101  wxString msg;
102 
103  // Create the toolbar if not exists
104  if( m_mainToolBar != NULL )
105  return;
106 
107  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
108  wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
109 
110  // Set up toolbar
111  m_mainToolBar->AddTool( ID_LIBEDIT_SELECT_CURRENT_LIB, wxEmptyString, KiBitmap( library_xpm ),
112  _( "Select working library" ) );
113 
114  m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_CURRENT_LIB, wxEmptyString,
115  KiBitmap( save_library_xpm ),
116  _( "Save into current library" ) );
117 
118  m_mainToolBar->AddTool( CreateNewLibAndSavePartId, wxEmptyString, KiBitmap( new_library_xpm ),
119  _( "Save current component to new library" ) );
120 
121  m_mainToolBar->AddTool( ID_TO_LIBVIEW, wxEmptyString, KiBitmap( library_browse_xpm ),
123 
124  m_mainToolBar->AddSeparator();
125  m_mainToolBar->AddTool( ID_LIBEDIT_DELETE_PART, wxEmptyString, KiBitmap( delete_xpm ),
126  _( "Delete component in current library" ) );
127 
128  m_mainToolBar->AddSeparator();
129  m_mainToolBar->AddTool( ID_LIBEDIT_NEW_PART, wxEmptyString, KiBitmap( new_component_xpm ),
130  _( "Create new component" ) );
131 
132  m_mainToolBar->AddTool( ID_LIBEDIT_SELECT_PART, wxEmptyString,
133  KiBitmap( import_cmp_from_lib_xpm ),
134  _( "Load component from current library" ) );
135 
136  m_mainToolBar->AddTool( ID_LIBEDIT_NEW_PART_FROM_EXISTING, wxEmptyString,
137  KiBitmap( copycomponent_xpm ),
138  _( "Create new component from current component" ) );
139 
140  m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_CURRENT_PART, wxEmptyString,
141  KiBitmap( save_part_in_mem_xpm ),
142  _( "Update current component in current library" ) );
143 
144  m_mainToolBar->AddTool( ImportPartId, wxEmptyString, KiBitmap( import_xpm ),
145  _( "Import component" ) );
146 
147  m_mainToolBar->AddTool( ExportPartId, wxEmptyString, KiBitmap( export_xpm ),
148  _( "Export component" ) );
149 
150  m_mainToolBar->AddSeparator();
151  msg = AddHotkeyName( _( "Undo last command" ), g_Libedit_Hokeys_Descr, HK_UNDO, IS_COMMENT );
152  m_mainToolBar->AddTool( wxID_UNDO, wxEmptyString, KiBitmap( undo_xpm ), msg );
153  msg = AddHotkeyName( _( "Redo last command" ), g_Libedit_Hokeys_Descr, HK_REDO,
154  IS_COMMENT );
155  m_mainToolBar->AddTool( wxID_REDO, wxEmptyString, KiBitmap( redo_xpm ), msg );
156 
157  m_mainToolBar->AddSeparator();
158  m_mainToolBar->AddTool( ID_LIBEDIT_GET_FRAME_EDIT_PART, wxEmptyString,
159  KiBitmap( part_properties_xpm ), _( "Edit component properties" ) );
160 
161  m_mainToolBar->AddTool( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, wxEmptyString,
162  KiBitmap( text_xpm ),
163  _( "Edit field properties" ) );
164 
165  m_mainToolBar->AddSeparator();
166  m_mainToolBar->AddTool( ID_LIBEDIT_CHECK_PART, wxEmptyString, KiBitmap( erc_xpm ),
167  _( "Check duplicate and off grid pins" ) );
168 
169  m_mainToolBar->AddSeparator();
171  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString, KiBitmap( zoom_redraw_xpm ), msg );
172 
174  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiBitmap( zoom_in_xpm ), msg );
175 
177  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiBitmap( zoom_out_xpm ), msg );
178 
180  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ), msg );
181 
182  m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiBitmap( zoom_area_xpm ),
183  _( "Zoom to selection" ), wxITEM_CHECK );
184 
185  m_mainToolBar->AddSeparator();
186  m_mainToolBar->AddTool( ID_DE_MORGAN_NORMAL_BUTT, wxEmptyString, KiBitmap( morgan1_xpm ),
187  _( "Show as \"De Morgan\" normal part" ), wxITEM_CHECK );
188  m_mainToolBar->AddTool( ID_DE_MORGAN_CONVERT_BUTT, wxEmptyString, KiBitmap( morgan2_xpm ),
189  _( "Show as \"De Morgan\" convert part" ), wxITEM_CHECK );
190 
191  m_mainToolBar->AddSeparator();
192  m_mainToolBar->AddTool( ID_LIBEDIT_VIEW_DOC, wxEmptyString, KiBitmap( datasheet_xpm ),
193  _( "Show associated datasheet or document" ) );
194 
195  m_mainToolBar->AddSeparator();
196  m_partSelectBox = new wxComboBox( m_mainToolBar,
198  wxEmptyString,
199  wxDefaultPosition,
200  wxSize( LISTBOX_WIDTH, -1 ),
201  0, NULL, wxCB_READONLY );
202  m_mainToolBar->AddControl( m_partSelectBox );
203 
204  m_aliasSelectBox = new wxComboBox( m_mainToolBar,
206  wxEmptyString,
207  wxDefaultPosition,
208  wxSize( LISTBOX_WIDTH, -1 ),
209  0, NULL, wxCB_READONLY );
210  m_mainToolBar->AddControl( m_aliasSelectBox );
211 
212  m_mainToolBar->AddSeparator();
213  msg = _( "Edit pins per part or body style (Use carefully!)" );
214  m_mainToolBar->AddTool( ID_LIBEDIT_EDIT_PIN_BY_PIN, wxEmptyString, KiBitmap( pin2pin_xpm ),
215  msg, wxITEM_CHECK );
216  m_mainToolBar->AddTool( ID_LIBEDIT_EDIT_PIN_BY_TABLE, wxEmptyString, KiBitmap( pin_table_xpm ),
217  _( "Show pin table" ) );
218 
219  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
220  m_mainToolBar->Realize();
221 }
222 
223 
225 {
226  if( m_optionsToolBar )
227  return;
228 
229  m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
230  wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_VERTICAL );
231 
232  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiBitmap( grid_xpm ),
233  _( "Turn grid off" ), wxITEM_CHECK );
234 
235  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
236  KiBitmap( unit_inch_xpm ), _( "Set units to inches" ),
237  wxITEM_CHECK );
238 
239  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
240  KiBitmap( unit_mm_xpm ),
241  _( "Set units to millimeters" ), wxITEM_CHECK );
242 
243 #ifndef __APPLE__
244  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
245  KiBitmap( cursor_shape_xpm ),
246  _( "Change cursor shape" ), wxITEM_CHECK );
247 #endif // !__APPLE__
248 
249  m_optionsToolBar->AddTool( ID_LIBEDIT_SHOW_ELECTRICAL_TYPE, wxEmptyString,
250  KiBitmap( pin_show_etype_xpm ),
251  _( "Show pins electrical type" ), wxITEM_CHECK );
252 
253  m_optionsToolBar->Realize();
254 }
#define HELP_ADD_BODYRECT
#define HELP_ADD_BODYCIRCLE
#define HELP_ZOOM_FIT
int CreateNewLibAndSavePartId
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:121
#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:125
strings common to toolbars and menubar
wxComboBox * m_partSelectBox
a Box to select a part to edit (if any)
Definition: libeditframe.h:56
#define HELP_ADD_BODYTEXT
Helper dialog and control classes.
#define HELP_RUN_LIB_VIEWER
int ExportPartId
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:122
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:136
void CreateOptionToolbar()
Definition: tool_lib.cpp:224
#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:99
#define HELP_ADD_PIN
#define HELP_ZOOM_IN
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:57
int ImportPartId
void ReCreateVToolbar() override
Definition: tool_lib.cpp:53