KiCad PCB EDA Suite
gerbview/menubar.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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2009 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2019 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 #include "gerbview_frame.h"
26 
27 #include "gerbview_id.h"
28 #include <kiface_i.h>
29 #include <menus_helpers.h>
30 #include <pgm_base.h>
31 #include <tool/actions.h>
32 #include <tool/conditional_menu.h>
33 #include <tool/tool_manager.h>
34 #include <tools/gerbview_actions.h>
36 #include <widgets/wx_menubar.h>
37 
38 
40 {
42  // wxWidgets handles the Mac Application menu behind the scenes, but that means
43  // we always have to start from scratch with a new wxMenuBar.
44  wxMenuBar* oldMenuBar = GetMenuBar();
45  WX_MENUBAR* menuBar = new WX_MENUBAR();
46 
47  //-- File menu -------------------------------------------------------
48  //
49  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
50  static ACTION_MENU* openRecentGbrMenu;
51  static ACTION_MENU* openRecentDrlMenu;
52  static ACTION_MENU* openRecentJobMenu;
53  static ACTION_MENU* openRecentZipMenu;
54 
55  FILE_HISTORY& recentGbrFiles = GetFileHistory();
56  recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );
57 
58 
59  // Create the gerber file menu if it does not exist. Adding a file to/from the history
60  // will automatically refresh the menu.
61  if( !openRecentGbrMenu )
62  {
63  openRecentGbrMenu = new ACTION_MENU( false );
64  openRecentGbrMenu->SetTool( selTool );
65  openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
66  openRecentGbrMenu->SetIcon( recent_xpm );
67 
68  recentGbrFiles.UseMenu( openRecentGbrMenu );
69  recentGbrFiles.AddFilesToMenu();
70  }
71 
72  // Create the drill file menu if it does not exist. Adding a file to/from the history
73  // will automatically refresh the menu.
74  if( !openRecentDrlMenu )
75  {
76  openRecentDrlMenu = new ACTION_MENU( false );
77  openRecentDrlMenu->SetTool( selTool );
78  openRecentDrlMenu->SetTitle( _( "Open Recent Drill File" ) );
79  openRecentDrlMenu->SetIcon( recent_xpm );
80 
81  m_drillFileHistory.UseMenu( openRecentDrlMenu );
83  }
84 
85  // Create the job file menu if it does not exist. Adding a file to/from the history
86  // will automatically refresh the menu.
87  if( !openRecentJobMenu )
88  {
89  openRecentJobMenu = new ACTION_MENU( false );
90  openRecentJobMenu->SetTool( selTool );
91  openRecentJobMenu->SetTitle( _( "Open Recent Job File" ) );
92  openRecentJobMenu->SetIcon( recent_xpm );
93 
94  m_jobFileHistory.UseMenu( openRecentJobMenu );
96  }
97 
98  // Create the zip file menu if it does not exist. Adding a file to/from the history
99  // will automatically refresh the menu.
100  if( !openRecentZipMenu )
101  {
102  openRecentZipMenu = new ACTION_MENU( false );
103  openRecentZipMenu->SetTool( selTool );
104  openRecentZipMenu->SetTitle( _( "Open Recent Zip File" ) );
105  openRecentZipMenu->SetIcon( recent_xpm );
106 
107  m_zipFileHistory.UseMenu( openRecentZipMenu );
109  }
110 
112  fileMenu->AddMenu( openRecentGbrMenu, FILE_HISTORY::FileHistoryNotEmpty( recentGbrFiles ) );
113 
115  fileMenu->AddMenu( openRecentDrlMenu, FILE_HISTORY::FileHistoryNotEmpty( m_drillFileHistory ) );
116 
118  fileMenu->AddMenu( openRecentJobMenu, FILE_HISTORY::FileHistoryNotEmpty( m_jobFileHistory ) );
119 
121  fileMenu->AddMenu( openRecentZipMenu, FILE_HISTORY::FileHistoryNotEmpty( m_zipFileHistory ) );
122 
123  fileMenu->AddSeparator();
124  fileMenu->AddItem( ID_GERBVIEW_ERASE_ALL, _( "Clear &All Layers" ),
125  _( "Clear all layers. All data will be deleted" ),
127 
128  fileMenu->AddItem( ID_GERBVIEW_RELOAD_ALL, _( "Reload All Layers" ),
129  _( "Reload all layers. All data will be reloaded" ),
131 
132  fileMenu->AddSeparator();
133  fileMenu->AddItem( ID_GERBVIEW_EXPORT_TO_PCBNEW, _( "Export to Pcbnew..." ),
134  _( "Export data in Pcbnew format" ),
136 
137  fileMenu->AddSeparator();
139 
140  fileMenu->AddSeparator();
141  fileMenu->AddQuitOrClose( &Kiface(), _( "GerbView" ) );
142 
143  fileMenu->Resolve();
144 
145  //-- View menu -------------------------------------------------------
146  //
147  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
148 
149  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
150  return IsGridVisible();
151  };
152  auto polarCoordsCondition = [ this ] ( const SELECTION& aSel ) {
153  return GetShowPolarCoords();
154  };
155  auto layersManagerShownCondition = [ this ] ( const SELECTION& aSel ) {
157  };
158  auto imperialUnitsCondition = [this]( const SELECTION& aSel ) {
159  return GetUserUnits() == EDA_UNITS::INCHES;
160  };
161  auto metricUnitsCondition = [this]( const SELECTION& aSel ) {
163  };
164  auto sketchFlashedCondition = [ this ] ( const SELECTION& aSel ) {
166  };
167  auto sketchLinesCondition = [ this ] ( const SELECTION& aSel ) {
169  };
170  auto sketchPolygonsCondition = [ this ] ( const SELECTION& aSel ) {
172  };
173  auto showDcodes = [ this ] ( const SELECTION& aSel ) {
174  return IsElementVisible( LAYER_DCODES );
175  };
176  auto showNegativeObjects = [ this ] ( const SELECTION& aSel ) {
178  };
179  auto diffModeCondition = [ this ] ( const SELECTION& aSel ) {
181  };
182  auto contrastModeCondition = [ this ] ( const SELECTION& aSel ) {
184  };
185 
186  // Hide layer manager
188  _( "Show &Layers Manager" ), _( "Show or hide the layer manager" ),
189  layers_manager_xpm, layersManagerShownCondition );
190 
191  viewMenu->AddSeparator();
197 
198  viewMenu->AddSeparator();
199  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
200  viewMenu->AddCheckItem( ACTIONS::togglePolarCoords, polarCoordsCondition );
201 
202  // Units submenu
203  CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool );
204  unitsSubMenu->SetTitle( _( "&Units" ) );
205  unitsSubMenu->SetIcon( unit_mm_xpm );
206  unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition );
207  unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition );
208  viewMenu->AddMenu( unitsSubMenu );
209 
210  viewMenu->AddSeparator();
211  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::flashedDisplayOutlines, sketchFlashedCondition );
212  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::linesDisplayOutlines, sketchLinesCondition );
213  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::polygonsDisplayOutlines, sketchPolygonsCondition );
214  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::dcodeDisplay, showDcodes );
215  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::negativeObjectDisplay, showNegativeObjects );
216  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::toggleDiffMode, diffModeCondition );
217  viewMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition );
218 
219  viewMenu->Resolve();
220 
221  //-- Tools menu -------------------------------------------------------
222  //
223  ACTION_MENU* toolsMenu = new ACTION_MENU( false );
224 
225  toolsMenu->Add( _( "&List DCodes..." ), _( "List D-codes defined in Gerber files" ),
227 
228  toolsMenu->Add( _( "&Show Source..." ), _( "Show source file for the current layer" ),
230 
231  toolsMenu->Add( ACTIONS::measureTool );
232 
233  toolsMenu->AppendSeparator();
234  toolsMenu->Add( _( "Clear Current Layer..." ), _( "Clear the selected graphic layer" ),
236 
237  //-- Preferences menu -----------------------------------------------
238  //
239  auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
241  };
242  auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
244  };
245 
246  CONDITIONAL_MENU* preferencesMenu = new CONDITIONAL_MENU( false, selTool );
247 
248  preferencesMenu->AddItem( wxID_PREFERENCES,
249  _( "Preferences...\tCTRL+," ),
250  _( "Show preferences for all open tools" ),
252 
253  preferencesMenu->AddSeparator();
254  AddMenuLanguageList( preferencesMenu, selTool );
255 
256  preferencesMenu->AddSeparator();
257  preferencesMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
258  preferencesMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
259 
260  preferencesMenu->Resolve();
261 
262  //-- Menubar -------------------------------------------------------------
263  //
264  menuBar->Append( fileMenu, _( "&File" ) );
265  menuBar->Append( viewMenu, _( "&View" ) );
266  menuBar->Append( toolsMenu, _( "&Tools" ) );
267  menuBar->Append( preferencesMenu, _( "&Preferences" ) );
268  AddStandardHelpMenu( menuBar );
269 
270  // Associate the menu bar with the frame, if no previous menubar
271  SetMenuBar( menuBar );
272  delete oldMenuBar;
273 }
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
bool m_DisplayPolygonsFill
Option to draw polygons (filled/sketch)
static TOOL_ACTION openDrillFile
static TOOL_ACTION zoomInCenter
Definition: actions.h:90
static TOOL_ACTION openGerber
ACTION_MENU.
Definition: action_menu.h:44
static TOOL_ACTION zoomTool
Definition: actions.h:95
FILE_HISTORY m_jobFileHistory
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
Definition: filehistory.h:123
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
static TOOL_ACTION standardGraphics
Definition: actions.h:159
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
bool m_HighContrastMode
High contrast mode (dim un-highlighted objects)
static TOOL_ACTION print
Definition: actions.h:60
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:45
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:42
static TOOL_ACTION imperialUnits
Definition: actions.h:139
static TOOL_ACTION dcodeDisplay
static TOOL_ACTION negativeObjectDisplay
static TOOL_ACTION zoomOutCenter
Definition: actions.h:91
const BITMAP_OPAQUE recent_xpm[1]
Definition: recent.cpp:68
bool m_DisplayLinesFill
Option to draw line items (filled/sketch)
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
static TOOL_ACTION toggleDiffMode
FILE_HISTORY m_zipFileHistory
static TOOL_ACTION measureTool
Definition: actions.h:147
bool m_DiffMode
Display layers in diff mode.
bool IsGridVisible() const
static TOOL_ACTION toggleGrid
Definition: actions.h:135
static TOOL_ACTION linesDisplayOutlines
const BITMAP_OPAQUE delete_sheet_xpm[1]
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
GBR_DISPLAY_OPTIONS m_DisplayOptions
bool m_DisplayFlashedItemsFill
Option to draw flashed items (filled/sketch)
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
const BITMAP_OPAQUE export_xpm[1]
Definition: export.cpp:75
static TOOL_ACTION togglePolarCoords
Definition: actions.h:142
static TOOL_ACTION openJobFile
bool IsElementVisible(int aLayerID) const
Function IsElementVisible tests whether a given element category is visible.
FILE_HISTORY m_drillFileHistory
void Resolve()
Function Resolve()
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:28
const BITMAP_OPAQUE tools_xpm[1]
Definition: tools.cpp:113
static TOOL_ACTION flashedDisplayOutlines
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Functions AddQuitOrClose()
const BITMAP_OPAQUE show_dcodenumber_xpm[1]
static TOOL_ACTION metricUnits
Definition: actions.h:140
GERBVIEW_SELECTION_TOOL.
const BITMAP_OPAQUE layers_manager_xpm[1]
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
see class PGM_BASE
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
static SELECTION_CONDITION FileHistoryNotEmpty(const FILE_HISTORY &aHistory)
Create a SELECTION_CONDITION that can be used to enable a menu item when the file history has items i...
void AddMenuLanguageList(CONDITIONAL_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
static TOOL_ACTION polygonsDisplayOutlines
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:158
const BITMAP_OPAQUE delete_gerber_xpm[1]
const BITMAP_OPAQUE reload2_xpm[1]
Definition: reload2.cpp:68
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
bool m_show_layer_manager_tools
void ReCreateMenuBar() override
Recreates the menu bar.
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:66
static TOOL_ACTION highContrastMode
Definition: actions.h:99
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION openZipFile