KiCad PCB EDA Suite
tool_modview.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) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012-2015 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
33 #include <dialog_helpers.h>
34 #include <macros.h>
35 #include <menus_helpers.h>
36 #include <wxPcbStruct.h>
37 
38 #include "help_common_strings.h"
39 #include "hotkeys.h"
40 #include "modview_frame.h"
41 #include "pcbnew.h"
42 #include "pcbnew_id.h"
43 
44 
46 {
47  wxString msg;
48 
49  if( m_mainToolBar == NULL )
50  {
51  m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
52  wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT
53  | wxAUI_TB_OVERFLOW );
54 
55  // Set up toolbar
56  m_mainToolBar->AddTool( ID_MODVIEW_SELECT_LIB, wxEmptyString,
57  KiBitmap( library_xpm ),
58  _( "Select library to browse" ) );
59 
60  m_mainToolBar->AddTool( ID_MODVIEW_SELECT_PART, wxEmptyString,
61  KiBitmap( module_xpm ),
62  _( "Select footprint to browse" ) );
63 
64  m_mainToolBar->AddSeparator();
65  m_mainToolBar->AddTool( ID_MODVIEW_PREVIOUS, wxEmptyString,
66  KiBitmap( lib_previous_xpm ),
67  _( "Display previous footprint" ) );
68 
69  m_mainToolBar->AddTool( ID_MODVIEW_NEXT, wxEmptyString,
70  KiBitmap( lib_next_xpm ),
71  _( "Display next footprint" ) );
72 
73  m_mainToolBar->AddSeparator();
74  m_mainToolBar->AddTool( ID_MODVIEW_SHOW_3D_VIEW, wxEmptyString,
75  KiBitmap( three_d_xpm ),
76  _( "Show footprint in 3D viewer" ) );
77 
78  m_mainToolBar->AddSeparator();
79  msg = AddHotkeyName( _( "Zoom in" ), g_Module_Viewer_Hokeys_Descr,
81  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_IN, wxEmptyString,
82  KiBitmap( zoom_in_xpm ), msg );
83 
84  msg = AddHotkeyName( _( "Zoom out" ), g_Module_Viewer_Hokeys_Descr,
86  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_OUT, wxEmptyString,
87  KiBitmap( zoom_out_xpm ), msg );
88 
89  msg = AddHotkeyName( _( "Redraw view" ), g_Module_Viewer_Hokeys_Descr,
91  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_REDRAW, wxEmptyString,
92  KiBitmap( zoom_redraw_xpm ), msg );
93 
94  msg = AddHotkeyName( _( "Zoom auto" ), g_Module_Viewer_Hokeys_Descr,
95  HK_ZOOM_AUTO );
96  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_PAGE, wxEmptyString,
97  KiBitmap( zoom_fit_in_page_xpm ), msg );
98 
99  if( IsModal() )
100  {
101  m_mainToolBar->AddSeparator();
102  m_mainToolBar->AddTool( ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, wxEmptyString,
103  KiBitmap( export_footprint_names_xpm ),
104  _( "Insert footprint in board" ) );
105  }
106 
107  // after adding the buttons to the toolbar, must call Realize() to
108  // reflect the changes
109  m_mainToolBar->Realize();
110  }
111 
112  m_mainToolBar->Refresh();
113 }
114 
115 
117 {
118 }
119 
120 
121 // Virtual function
123 {
124  // Create and try to get the current menubar
125  wxMenuBar* menuBar = GetMenuBar();
126 
127  if( !menuBar )
128  menuBar = new wxMenuBar();
129 
130  // Delete all existing menus so they can be rebuilt.
131  // This allows language changes of the menu text on the fly.
132  menuBar->Freeze();
133 
134  while( menuBar->GetMenuCount() )
135  delete menuBar->Remove( 0 );
136 
137  // Recreate all menus:
138  wxString text;
139 
140  // Menu File:
141  wxMenu* fileMenu = new wxMenu;
142 
143  // Active library selection
144  AddMenuItem( fileMenu, ID_MODVIEW_SELECT_LIB, _("Set Current Library"),
145  _( "Select library to be displayed" ), KiBitmap( open_library_xpm ) );
146  fileMenu->AppendSeparator();
147 
148  // Close viewer
149  AddMenuItem( fileMenu, wxID_EXIT,
150  _( "Cl&ose" ),
151  _( "Close footprint viewer" ),
152  KiBitmap( exit_xpm ) );
153 
154  // View menu
155  wxMenu* viewMenu = new wxMenu;
156 
157  text = AddHotkeyName( _( "Zoom &In" ), g_Module_Viewer_Hokeys_Descr,
159  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
160 
161  text = AddHotkeyName( _( "Zoom &Out" ), g_Module_Viewer_Hokeys_Descr,
163  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
164 
165  text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hokeys_Descr,
166  HK_ZOOM_AUTO );
168  KiBitmap( zoom_fit_in_page_xpm ) );
169 
170  text = AddHotkeyName( _( "&Redraw" ), g_Module_Viewer_Hokeys_Descr, HK_ZOOM_REDRAW );
171  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_REDRAW, text,
172  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
173 
174  viewMenu->AppendSeparator();
175 
176  // 3D view
177  text = AddHotkeyName( _( "3&D Viewer" ), g_Module_Viewer_Hokeys_Descr, HK_3D_VIEWER );
178  AddMenuItem( viewMenu, ID_MODVIEW_SHOW_3D_VIEW, text, _( "Show footprint in 3D viewer" ),
179  KiBitmap( three_d_xpm ) );
180 
181  // Menu Help:
182  wxMenu* helpMenu = new wxMenu;
183 
184  // Contents
185  AddMenuItem( helpMenu, wxID_HELP,
186  _( "Pcbnew &Manual" ),
187  _( "Open the Pcbnew manual" ),
188  KiBitmap( online_help_xpm ) );
189 
190  AddMenuItem( helpMenu, wxID_INDEX,
191  _( "&Getting Started in KiCad" ),
192  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
193  KiBitmap( help_xpm ) );
194 
195  // About Pcbnew
196  helpMenu->AppendSeparator();
197  AddMenuItem( helpMenu, wxID_ABOUT,
198  _( "&About Pcbnew" ),
199  _( "About Pcbnew PCB designer" ),
200  KiBitmap( info_xpm ) );
201 
202  // Append menus to the menubar
203  menuBar->Append( fileMenu, _( "&File" ) );
204 
205  menuBar->Append( viewMenu, _( "&View" ) );
206  menuBar->Append( helpMenu, _( "&Help" ) );
207 
208  menuBar->Thaw();
209 
210  // Associate the menu bar with the frame, if no previous menubar
211  if( GetMenuBar() == NULL )
212  SetMenuBar( menuBar );
213  else
214  menuBar->Refresh();
215 }
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:55
#define HELP_ZOOM_FIT
void ReCreateVToolbar() override
#define HELP_ZOOM_OUT
Pcbnew hotkeys.
This file contains miscellaneous commonly used macros and functions.
#define HELP_ZOOM_REDRAW
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
Helper dialog and control classes.
bool IsModal()
Definition: kiway_player.h:216
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:140
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 ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
#define HELP_ZOOM_IN
void ReCreateHToolbar() override
strings common to toolbars and menubar
struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hokeys_Descr[]