KiCad PCB EDA Suite
tool_sch.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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
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 <sch_draw_panel.h>
32 #include <sch_edit_frame.h>
33 #include <kiface_i.h>
34 #include <bitmaps.h>
35 #include <sch_view.h>
36 #include <sch_painter.h>
37 #include <general.h>
38 #include <hotkeys.h>
39 #include <eeschema_id.h>
40 
41 #include <help_common_strings.h>
42 
43 
44 /* Create the main Horizontal Toolbar for the schematic editor
45  */
47 {
48  if( m_mainToolBar )
49  m_mainToolBar->Clear();
50  else
51  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
52  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
53 
54  wxString msg;
55 
56  // Set up toolbar
57  if( Kiface().IsSingle() ) // not when under a project mgr
58  {
59  // These 2 menus have meaning only outside a project, i.e. not under a project manager:
60  m_mainToolBar->AddTool( ID_NEW_PROJECT, wxEmptyString,
61  KiScaledBitmap( new_document_xpm, this ),
62  _( "New schematic" ) );
63 
64  m_mainToolBar->AddTool( ID_LOAD_PROJECT, wxEmptyString,
65  KiScaledBitmap( open_document_xpm, this ),
66  _( "Open schematic" ) );
67  }
68 
69  m_mainToolBar->AddTool( ID_SAVE_PROJECT, wxEmptyString,
70  KiScaledBitmap( save_xpm, this ),
71  _( "Save (all sheets)" ) );
72 
74 
75  m_mainToolBar->AddTool( ID_SHEET_SET, wxEmptyString, KiScaledBitmap( sheetset_xpm, this ),
76  _( "Edit Page settings" ) );
77 
79 
80  m_mainToolBar->AddTool( wxID_PRINT, wxEmptyString, KiScaledBitmap( print_button_xpm, this ),
81  _( "Print schematic" ) );
82 
83  m_mainToolBar->AddTool( ID_GEN_PLOT_SCHEMATIC, wxEmptyString, KiScaledBitmap( plot_xpm, this ),
84  _( "Plot schematic" ) );
85 
87 
88  m_mainToolBar->AddTool( wxID_PASTE, wxEmptyString, KiScaledBitmap( paste_xpm, this ),
89  _( "Paste" ) );
90 
91 
93 
95  m_mainToolBar->AddTool( wxID_UNDO, wxEmptyString, KiScaledBitmap( undo_xpm, this ), msg );
96 
98  m_mainToolBar->AddTool( wxID_REDO, wxEmptyString, KiScaledBitmap( redo_xpm, this ), msg );
99 
100 
102 
104  m_mainToolBar->AddTool( ID_FIND_ITEMS, wxEmptyString, KiScaledBitmap( find_xpm, this ), msg );
105 
106  m_mainToolBar->AddTool( wxID_REPLACE, wxEmptyString, KiScaledBitmap( find_replace_xpm, this ),
107  wxNullBitmap, wxITEM_NORMAL, _( "Find and replace text" ),
108  HELP_REPLACE, nullptr );
109 
110 
112 
114  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
115  KiScaledBitmap( zoom_redraw_xpm, this ), msg );
116 
118  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiScaledBitmap( zoom_in_xpm, this ), msg );
119 
121  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiScaledBitmap( zoom_out_xpm, this ), msg );
122 
124  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
125  KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg );
126 
127  m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiScaledBitmap( zoom_area_xpm, this ),
128  _( "Zoom to selection" ), wxITEM_CHECK );
129 
130 
132 
133  m_mainToolBar->AddTool( ID_HIERARCHY, wxEmptyString, KiScaledBitmap( hierarchy_nav_xpm, this ),
134  _( "Navigate schematic hierarchy" ) );
135 
136 
137  m_mainToolBar->AddTool( ID_POPUP_SCH_LEAVE_SHEET, wxEmptyString,
138  KiScaledBitmap( leave_sheet_xpm, this ), _( "Leave sheet" ) );
139 
141 
142  m_mainToolBar->AddTool( ID_RUN_LIBRARY, wxEmptyString, KiScaledBitmap( libedit_xpm, this ),
144 
145  m_mainToolBar->AddTool( ID_TO_LIBVIEW, wxEmptyString,
146  KiScaledBitmap( library_browse_xpm, this ), HELP_RUN_LIB_VIEWER );
147 
148  // modedit is with libedit in a "library section" because the user must have footprints before
149  // they can be assigned.
150  m_mainToolBar->AddTool( ID_RUN_PCB_MODULE_EDITOR, wxEmptyString,
151  KiScaledBitmap( module_editor_xpm, this ),
152  _( "Footprint Editor - Create/edit footprints" ) );
153 
155 
156  m_mainToolBar->AddTool( ID_GET_ANNOTATE, wxEmptyString, KiScaledBitmap( annotate_xpm, this ),
157  HELP_ANNOTATE );
158 
159  m_mainToolBar->AddTool( ID_GET_ERC, wxEmptyString, KiScaledBitmap( erc_xpm, this ),
160  _( "Perform electrical rules check" ) );
161 
162  m_mainToolBar->AddTool( ID_RUN_CVPCB, wxEmptyString, KiScaledBitmap( cvpcb_xpm, this ),
163  _( "Assign PCB footprints to schematic symbols" ) );
164 
165  m_mainToolBar->AddTool( ID_GET_NETLIST, wxEmptyString, KiScaledBitmap( netlist_xpm, this ),
166  _( "Generate netlist" ) );
167 
168  m_mainToolBar->AddTool( ID_OPEN_CMP_TABLE, wxEmptyString,
169  KiScaledBitmap( spreadsheet_xpm, this ), _( "Edit symbol fields" ) );
170 
171 
172  m_mainToolBar->AddTool( ID_GET_TOOLS, wxEmptyString, KiScaledBitmap( bom_xpm, this ),
174 
176 
177  m_mainToolBar->AddTool( ID_RUN_PCB, wxEmptyString, KiScaledBitmap( pcbnew_xpm, this ),
178  _( "Run Pcbnew to layout printed circuit board" ) );
179 
180  m_mainToolBar->AddTool( ID_BACKANNO_ITEMS, wxEmptyString,
181  KiScaledBitmap( import_footprint_names_xpm, this ),
183 
184  // after adding the tools to the toolbar, must call Realize() to reflect the changes
185  m_mainToolBar->Realize();
186 }
187 
188 
189 /* Create Vertical Right Toolbar
190  */
192 {
193  if( m_drawToolBar )
194  m_drawToolBar->Clear();
195  else
196  m_drawToolBar = new wxAuiToolBar( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
197  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
198 
199  // Set up toolbar
200  m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiScaledBitmap( cursor_xpm, this ),
201  HELP_SELECT, wxITEM_CHECK );
202 
203  m_drawToolBar->AddTool( ID_HIGHLIGHT, wxEmptyString,
204  KiScaledBitmap( net_highlight_schematic_xpm, this ),
205  HELP_HIGHLIGHT, wxITEM_CHECK );
206 
207  m_drawToolBar->AddTool( ID_SCH_PLACE_COMPONENT, wxEmptyString,
208  KiScaledBitmap( add_component_xpm, this ), HELP_PLACE_COMPONENTS,
209  wxITEM_CHECK );
210 
211  m_drawToolBar->AddTool( ID_PLACE_POWER_BUTT, wxEmptyString,
212  KiScaledBitmap( add_power_xpm, this ),
213  HELP_PLACE_POWERPORT, wxITEM_CHECK );
214 
215  m_drawToolBar->AddTool( ID_WIRE_BUTT, wxEmptyString, KiScaledBitmap( add_line_xpm, this ),
216  HELP_PLACE_WIRE, wxITEM_CHECK );
217 
218  m_drawToolBar->AddTool( ID_BUS_BUTT, wxEmptyString, KiScaledBitmap( add_bus_xpm, this ),
219  HELP_PLACE_BUS, wxITEM_CHECK );
220 
221  m_drawToolBar->AddTool( ID_WIRETOBUS_ENTRY_BUTT, wxEmptyString,
222  KiScaledBitmap( add_line2bus_xpm, this ),
223  HELP_PLACE_WIRE2BUS_ENTRY, wxITEM_CHECK );
224 
225  m_drawToolBar->AddTool( ID_BUSTOBUS_ENTRY_BUTT, wxEmptyString,
226  KiScaledBitmap( add_bus2bus_xpm, this ),
227  HELP_PLACE_BUS2BUS_ENTRY, wxITEM_CHECK );
228 
229  m_drawToolBar->AddTool( ID_NOCONN_BUTT, wxEmptyString, KiScaledBitmap( noconn_xpm, this ),
230  HELP_PLACE_NC_FLAG, wxITEM_CHECK );
231 
232  m_drawToolBar->AddTool( ID_JUNCTION_BUTT, wxEmptyString,
233  KiScaledBitmap( add_junction_xpm, this ),
234  HELP_PLACE_JUNCTION, wxITEM_CHECK );
235 
236  m_drawToolBar->AddTool( ID_LABEL_BUTT, wxEmptyString,
237  KiScaledBitmap( add_line_label_xpm, this ),
238  HELP_PLACE_NETLABEL, wxITEM_CHECK );
239 
240  m_drawToolBar->AddTool( ID_GLABEL_BUTT, wxEmptyString, KiScaledBitmap( add_glabel_xpm, this ),
241  HELP_PLACE_GLOBALLABEL, wxITEM_CHECK );
242 
243  m_drawToolBar->AddTool( ID_HIERLABEL_BUTT, wxEmptyString,
244  KiScaledBitmap( add_hierarchical_label_xpm, this ),
245  HELP_PLACE_HIER_LABEL, wxITEM_CHECK );
246 
247  m_drawToolBar->AddTool( ID_SHEET_SYMBOL_BUTT, wxEmptyString,
248  KiScaledBitmap( add_hierarchical_subsheet_xpm, this ),
249  HELP_PLACE_SHEET, wxITEM_CHECK );
250 
251  m_drawToolBar->AddTool( ID_IMPORT_HLABEL_BUTT, wxEmptyString,
252  KiScaledBitmap( import_hierarchical_label_xpm, this ),
253  HELP_IMPORT_SHEETPIN, wxITEM_CHECK );
254 
255  m_drawToolBar->AddTool( ID_SHEET_PIN_BUTT, wxEmptyString,
256  KiScaledBitmap( add_hierar_pin_xpm, this ),
257  HELP_PLACE_SHEETPIN, wxITEM_CHECK );
258 
259  m_drawToolBar->AddTool( ID_LINE_COMMENT_BUTT, wxEmptyString,
260  KiScaledBitmap( add_dashed_line_xpm, this ),
261  HELP_PLACE_GRAPHICLINES, wxITEM_CHECK );
262 
263  m_drawToolBar->AddTool( ID_TEXT_COMMENT_BUTT, wxEmptyString, KiScaledBitmap( text_xpm, this ),
264  HELP_PLACE_GRAPHICTEXTS, wxITEM_CHECK );
265 
266  m_drawToolBar->AddTool( ID_ADD_IMAGE_BUTT, wxEmptyString, KiScaledBitmap( image_xpm, this ),
267  _("Add bitmap image"), wxITEM_CHECK );
268 
269  m_drawToolBar->AddTool( ID_SCHEMATIC_DELETE_ITEM_BUTT, wxEmptyString,
270  KiScaledBitmap( delete_xpm, this ),
271  HELP_DELETE_ITEMS, wxITEM_CHECK );
272 
273  m_drawToolBar->Realize();
274 }
275 
276 
277 /* Create Vertical Left Toolbar (Option Toolbar)
278  */
280 {
281  if( m_optionsToolBar )
282  m_optionsToolBar->Clear();
283  else
284  m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
285  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
286 
287  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString,
288  KiScaledBitmap( grid_xpm, this ),
289  _( "Turn grid off" ), wxITEM_CHECK );
290 
291  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
292  KiScaledBitmap( unit_inch_xpm, this ),
293  _( "Set unit to inch" ), wxITEM_CHECK );
294 
295  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
296  KiScaledBitmap( unit_mm_xpm, this ),
297  _( "Set unit to mm" ), wxITEM_CHECK );
298 
299  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
300  KiScaledBitmap( cursor_shape_xpm, this ),
301  _( "Change cursor shape" ), wxITEM_CHECK );
302 
303  //KiScaledSeparator( m_optionsToolBar, this );
304  m_optionsToolBar->AddTool( ID_TB_OPTIONS_HIDDEN_PINS, wxEmptyString,
305  KiScaledBitmap( hidden_pin_xpm, this ),
306  _( "Show hidden pins" ), wxITEM_CHECK );
307 
308  //KiScaledSeparator( m_optionsToolBar, this );
309  m_optionsToolBar->AddTool( ID_TB_OPTIONS_BUS_WIRES_ORIENT, wxEmptyString,
310  KiScaledBitmap( lines90_xpm, this ),
311  _( "HV orientation for wires and bus" ),
312  wxITEM_CHECK );
313 
314  m_optionsToolBar->Realize();
315 }
316 
317 
318 void SCH_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
319 {
320  int id = event.GetId();
321 
322  switch( id )
323  {
325  {
327 
328  auto painter = static_cast<KIGFX::SCH_PAINTER*>( GetCanvas()->GetView()->GetPainter() );
329  painter->GetSettings()->m_ShowHiddenPins = m_showAllPins;
330 
332  GetCanvas()->Refresh();
333  }
334  break;
335 
337  SetForceHVLines( m_optionsToolBar->GetToolToggled( id ) );
338  break;
339 
340  default:
341  wxFAIL_MSG( wxT( "Unexpected select option tool bar ID." ) );
342  break;
343  }
344 }
#define HELP_PLACE_POWERPORT
void ReCreateOptToolbar()
Definition: tool_sch.cpp:279
#define HELP_SELECT
#define HELP_PLACE_COMPONENTS
void OnSelectOptionToolbar(wxCommandEvent &event)
Definition: tool_sch.cpp:318
#define HELP_PLACE_SHEETPIN
#define HELP_PLACE_NETLABEL
#define HELP_PLACE_GRAPHICTEXTS
void SetForceHVLines(bool aForceHVdirection)
#define HELP_ZOOM_FIT
Definition: id.h:241
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1443
#define HELP_PLACE_WIRE2BUS_ENTRY
#define HELP_HIGHLIGHT
#define HELP_PLACE_SHEET
#define HELP_PLACE_JUNCTION
Definition: id.h:66
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
#define HELP_PLACE_GLOBALLABEL
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
#define HELP_ZOOM_OUT
#define HELP_PLACE_BUS2BUS_ENTRY
#define HELP_ZOOM_REDRAW
#define HELP_PLACE_GRAPHICLINES
Item is being added to the view.
Definition: view_item.h:60
void ReCreateHToolbar() override
Definition: tool_sch.cpp:46
wxAuiToolBar * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:163
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
strings common to toolbars and menubar
SCH_DRAW_PANEL * GetCanvas() const override
#define HELP_REPLACE
#define HELP_RUN_LIB_VIEWER
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:160
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
#define HELP_IMPORT_FOOTPRINTS
KIGFX::SCH_VIEW * GetView() const
bool m_showAllPins
Flag to indicate show hidden pins.
#define HELP_PLACE_NC_FLAG
#define HELP_REDO
#define HELP_PLACE_BUS
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)
#define HELP_ZOOM_IN
#define HELP_RUN_LIB_EDITOR
#define HELP_IMPORT_SHEETPIN
#define HELP_UNDO
These strings are used in menus and tools, that do the same command But they are internationalized,...
void KiScaledSeparator(wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
Add a separator to the given toolbar scaled the same way as KiScaledBitmap.
Definition: bitmap.cpp:167
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
static const char * text_xpm[]
#define HELP_GENERATE_BOM
#define HELP_FIND
#define HELP_PLACE_HIER_LABEL
#define HELP_DELETE_ITEMS
#define HELP_ANNOTATE
void ReCreateVToolbar() override
Definition: tool_sch.cpp:191
#define HELP_PLACE_WIRE
struct EDA_HOTKEY_CONFIG g_Schematic_Hokeys_Descr[]