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 <advanced_config.h>
28 #include <kiface_i.h>
29 #include <pgm_base.h>
30 #include "gerbview_id.h"
31 #include <menus_helpers.h>
32 #include <tool/actions.h>
33 #include <tool/tool_manager.h>
34 #include <tool/conditional_menu.h>
36 #include <tools/gerbview_actions.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  wxMenuBar* menuBar = new wxMenuBar();
46 
47  //-- File menu -------------------------------------------------------
48  //
49  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
50  static FILE_HISTORY_MENU* openRecentGbrMenu;
51  static FILE_HISTORY_MENU* openRecentDrlMenu;
52  static FILE_HISTORY_MENU* openRecentJobMenu;
53  static FILE_HISTORY_MENU* openRecentZipMenu;
54  FILE_HISTORY& recentGbrFiles = Kiface().GetFileHistory();
55 
56 
57  // Create the gerber file menu if it does not exist. Adding a file to/from the history
58  // will automatically refresh the menu.
59  if( !openRecentGbrMenu )
60  {
61  openRecentGbrMenu =
62  new FILE_HISTORY_MENU( recentGbrFiles, _( "Clear Recent Gerber Files" ) );
63  openRecentGbrMenu->SetTool( selTool );
64  openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
65  openRecentGbrMenu->SetIcon( recent_xpm );
66  }
67 
68  // Create the drill file menu if it does not exist. Adding a file to/from the history
69  // will automatically refresh the menu.
70  if( !openRecentDrlMenu )
71  {
72  openRecentDrlMenu =
73  new FILE_HISTORY_MENU( m_drillFileHistory, _( "Clear Recent Drill Files" ) );
74  openRecentDrlMenu->SetTool( selTool );
75  openRecentDrlMenu->SetTitle( _( "Open Recent Drill File" ) );
76  openRecentDrlMenu->SetIcon( recent_xpm );
77  }
78 
79  // Create the job file menu if it does not exist. Adding a file to/from the history
80  // will automatically refresh the menu.
81  if( !openRecentJobMenu )
82  {
83  openRecentJobMenu =
84  new FILE_HISTORY_MENU( m_jobFileHistory, _( "Clear Recent Job Files" ) );
85  openRecentJobMenu->SetTool( selTool );
86  openRecentJobMenu->SetTitle( _( "Open Recent Job File" ) );
87  openRecentJobMenu->SetIcon( recent_xpm );
88  }
89 
90  // Create the zip file menu if it does not exist. Adding a file to/from the history
91  // will automatically refresh the menu.
92  if( !openRecentZipMenu )
93  {
94  openRecentZipMenu =
95  new FILE_HISTORY_MENU( m_zipFileHistory, _( "Clear Recent Zip Files" ) );
96  openRecentZipMenu->SetTool( selTool );
97  openRecentZipMenu->SetTitle( _( "Open Recent Zip File" ) );
98  openRecentZipMenu->SetIcon( recent_xpm );
99  }
100 
101  fileMenu->AddItem( wxID_FILE, _( "Open &Gerber File(s)..." ),
102  _( "Open Gerber file(s) on the current layer. Previous data will be deleted" ),
104  fileMenu->AddMenu( openRecentGbrMenu, FILE_HISTORY::FileHistoryNotEmpty( recentGbrFiles ) );
105 
106  fileMenu->AddItem( ID_GERBVIEW_LOAD_DRILL_FILE, _( "Open &Excellon Drill File(s)..." ),
107  _( "Open Excellon drill file(s) on the current layer. Previous data will be deleted" ),
109  fileMenu->AddMenu( openRecentDrlMenu, FILE_HISTORY::FileHistoryNotEmpty( m_drillFileHistory ) );
110 
111  fileMenu->AddItem( ID_GERBVIEW_LOAD_JOB_FILE, _( "Open Gerber &Job File..." ),
112  _( "Open a Gerber job file and its associated gerber files" ),
114  fileMenu->AddMenu( openRecentJobMenu, FILE_HISTORY::FileHistoryNotEmpty( m_jobFileHistory ) );
115 
116  fileMenu->AddItem( ID_GERBVIEW_LOAD_ZIP_ARCHIVE_FILE, _( "Open &Zip Archive File..." ),
117  _( "Open a zipped archive (Gerber and Drill) file" ),
119  fileMenu->AddMenu( openRecentZipMenu, FILE_HISTORY::FileHistoryNotEmpty( m_zipFileHistory ) );
120 
121  fileMenu->AddSeparator();
122  fileMenu->AddItem( ID_GERBVIEW_ERASE_ALL, _( "Clear &All Layers" ),
123  _( "Clear all layers. All data will be deleted" ),
125 
126  fileMenu->AddItem( ID_GERBVIEW_RELOAD_ALL, _( "Reload All Layers" ),
127  _( "Reload all layers. All data will be reloaded" ),
129 
130  fileMenu->AddSeparator();
131  fileMenu->AddItem( ID_GERBVIEW_EXPORT_TO_PCBNEW, _( "Export to Pcbnew..." ),
132  _( "Export data in Pcbnew format" ),
134 
135  fileMenu->AddSeparator();
137 
138  fileMenu->AddSeparator();
139  fileMenu->AddQuitOrClose( &Kiface(), _( "GerbView" ) );
140 
141  fileMenu->Resolve();
142 
143  //-- View menu -------------------------------------------------------
144  //
145  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
146 
147  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
148  return IsGridVisible();
149  };
150  auto polarCoordsCondition = [ this ] ( const SELECTION& aSel ) {
151  return GetShowPolarCoords();
152  };
153  auto layersManagerShownCondition = [ this ] ( const SELECTION& aSel ) {
155  };
156  auto imperialUnitsCondition = [this]( const SELECTION& aSel ) {
157  return GetUserUnits() == EDA_UNITS::INCHES;
158  };
159  auto metricUnitsCondition = [this]( const SELECTION& aSel ) {
161  };
162  auto sketchFlashedCondition = [ this ] ( const SELECTION& aSel ) {
164  };
165  auto sketchLinesCondition = [ this ] ( const SELECTION& aSel ) {
167  };
168  auto sketchPolygonsCondition = [ this ] ( const SELECTION& aSel ) {
170  };
171  auto showDcodes = [ this ] ( const SELECTION& aSel ) {
172  return IsElementVisible( LAYER_DCODES );
173  };
174  auto showNegativeObjects = [ this ] ( const SELECTION& aSel ) {
176  };
177  auto diffModeCondition = [ this ] ( const SELECTION& aSel ) {
179  };
180  auto contrastModeCondition = [ this ] ( const SELECTION& aSel ) {
182  };
183 
184  // Hide layer manager
186  _( "Show &Layers Manager" ), _( "Show or hide the layer manager" ),
187  layers_manager_xpm, layersManagerShownCondition );
188 
189  viewMenu->AddSeparator();
195 
196  viewMenu->AddSeparator();
197  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
198  viewMenu->AddCheckItem( ACTIONS::togglePolarCoords, polarCoordsCondition );
199 
200  // Units submenu
201  CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool );
202  unitsSubMenu->SetTitle( _( "&Units" ) );
203  unitsSubMenu->SetIcon( unit_mm_xpm );
204  unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition );
205  unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition );
206  viewMenu->AddMenu( unitsSubMenu );
207 
208  viewMenu->AddSeparator();
209  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::flashedDisplayOutlines, sketchFlashedCondition );
210  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::linesDisplayOutlines, sketchLinesCondition );
211  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::polygonsDisplayOutlines, sketchPolygonsCondition );
212  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::dcodeDisplay, showDcodes );
213  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::negativeObjectDisplay, showNegativeObjects );
214  viewMenu->AddCheckItem( GERBVIEW_ACTIONS::toggleDiffMode, diffModeCondition );
215  viewMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition );
216 
217  viewMenu->Resolve();
218 
219  //-- Tools menu -------------------------------------------------------
220  //
221  ACTION_MENU* toolsMenu = new ACTION_MENU( false );
222 
223  toolsMenu->Add( _( "&List DCodes..." ), _( "List D-codes defined in Gerber files" ),
225 
226  toolsMenu->Add( _( "&Show Source..." ), _( "Show source file for the current layer" ),
228 
229  toolsMenu->Add( ACTIONS::measureTool );
230 
231  toolsMenu->AppendSeparator();
232  toolsMenu->Add( _( "Clear Current Layer..." ), _( "Clear the selected graphic layer" ),
234 
235  //-- Preferences menu -----------------------------------------------
236  //
237  auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
239  };
240  auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
242  };
243 
244  CONDITIONAL_MENU* preferencesMenu = new CONDITIONAL_MENU( false, selTool );
245 
246  preferencesMenu->AddItem( wxID_PREFERENCES,
247  _( "Preferences...\tCTRL+," ),
248  _( "Show preferences for all open tools" ),
250 
251  preferencesMenu->AddSeparator();
252  AddMenuLanguageList( preferencesMenu, selTool );
253 
254  preferencesMenu->AddSeparator();
255  preferencesMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
256  preferencesMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
257 
258  preferencesMenu->Resolve();
259 
260  //-- Menubar -------------------------------------------------------------
261  //
262  menuBar->Append( fileMenu, _( "&File" ) );
263  menuBar->Append( viewMenu, _( "&View" ) );
264  menuBar->Append( toolsMenu, _( "&Tools" ) );
265  menuBar->Append( preferencesMenu, _( "&Preferences" ) );
266  AddStandardHelpMenu( menuBar );
267 
268  // Associate the menu bar with the frame, if no previous menubar
269  SetMenuBar( menuBar );
270  delete oldMenuBar;
271 }
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 zoomInCenter
Definition: actions.h:90
ACTION_MENU.
Definition: action_menu.h:43
static TOOL_ACTION zoomTool
Definition: actions.h:95
FILE_HISTORY m_jobFileHistory
virtual bool IsGridVisible() const
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
const BITMAP_OPAQUE zip_xpm[1]
Definition: zip.cpp:60
static TOOL_ACTION standardGraphics
Definition: actions.h:155
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
const BITMAP_OPAQUE gerber_job_file_xpm[1]
This class implements a menu container for a file history.
Definition: filehistory.h:86
bool m_HighContrastMode
High contrast mode (dim un-highlighted objects)
static TOOL_ACTION print
Definition: actions.h:60
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:40
static TOOL_ACTION imperialUnits
Definition: actions.h:136
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:144
bool m_DiffMode
Display layers in diff mode.
static TOOL_ACTION toggleGrid
Definition: actions.h:132
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:68
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:139
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:137
GERBVIEW_SELECTION_TOOL.
const BITMAP_OPAQUE layers_manager_xpm[1]
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:86
see class PGM_BASE
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...
Definition: filehistory.cpp:73
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:31
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
const BITMAP_OPAQUE load_gerber_xpm[1]
Definition: load_gerber.cpp:80
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:123
static TOOL_ACTION polygonsDisplayOutlines
const BITMAP_OPAQUE gerbview_drill_file_xpm[1]
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:154
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.
TOOL_MANAGER * m_toolManager
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.