KiCad PCB EDA Suite
3d_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) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2019 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 
27 #include <fctsys.h>
28 #include <tool/conditional_menu.h>
29 #include <eda_3d_viewer.h>
30 #include <menus_helpers.h>
31 #include <3d_viewer_id.h>
32 #include <3d_actions.h>
33 #include <tool/tool_manager.h>
34 #include <tool/common_control.h>
35 #include "help_common_strings.h"
36 
37 
39 {
40  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::CreateMenuBar" );
41 
43  wxMenuBar* menuBar = new wxMenuBar;
44 
45 
46  //-- File menu -----------------------------------------------------------
47  //
48  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, tool );
49 
50  fileMenu->AddItem( ID_MENU_SCREENCOPY_PNG, _( "Export Current View as PNG..." ), "",
52 
53  fileMenu->AddItem( ID_MENU_SCREENCOPY_JPEG, _( "Export Current View as JPEG..." ), "",
55 
56  fileMenu->AddSeparator();
57  fileMenu->AddClose( _( "3D Viewer" ) );
58 
59  fileMenu->Resolve();
60 
61  //-- Edit menu -------------------------------------------------------
62  // Avoid to translate hotkey modifiers like Ctrl and Shift.
63  // The translated modifiers do not always work
64  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, tool );
65 
66  editMenu->AddItem( ID_TOOL_SCREENCOPY_TOCLIBBOARD, _( "Copy 3D Image" ), "",
68 
69  editMenu->Resolve();
70 
71  //-- View menu -------------------------------------------------------
72  //
73  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, tool );
74 
75  viewMenu->AddItem( ID_ZOOM_IN, _( "Zoom In\tF1" ), HELP_ZOOM_IN,
76  zoom_in_xpm, SELECTION_CONDITIONS::ShowAlways );
77 
78  viewMenu->AddItem( ID_ZOOM_OUT, _( "Zoom Out\tF2" ), HELP_ZOOM_OUT,
79  zoom_out_xpm, SELECTION_CONDITIONS::ShowAlways );
80 
81  viewMenu->AddItem( ID_ZOOM_PAGE, _( "Zoom to Fit" ), HELP_ZOOM_FIT,
82  zoom_fit_in_page_xpm, SELECTION_CONDITIONS::ShowAlways );
83 
84  viewMenu->AddItem( ID_ZOOM_REDRAW, _( "Redraw\tR" ), HELP_ZOOM_REDRAW,
85  zoom_redraw_xpm, SELECTION_CONDITIONS::ShowAlways );
86 
87  viewMenu->AddSeparator();
88  viewMenu->AddItem( ID_ROTATE3D_X_NEG, _( "Rotate X Clockwise" ) + "\tCtrl+Shift+X", "",
89  rotate_neg_x_xpm, SELECTION_CONDITIONS::ShowAlways );
90 
91  viewMenu->AddItem( ID_ROTATE3D_X_POS, _( "Rotate X Counterclockwise" ) + "\tCtrl+X", "",
92  rotate_pos_x_xpm, SELECTION_CONDITIONS::ShowAlways );
93 
94  viewMenu->AddSeparator();
95  viewMenu->AddItem( ID_ROTATE3D_Y_NEG, _( "Rotate Y Clockwise" ) + "\tCtrl+Shift+Y", "",
96  rotate_neg_y_xpm, SELECTION_CONDITIONS::ShowAlways );
97 
98  viewMenu->AddItem( ID_ROTATE3D_Y_POS, _( "Rotate Y Counterclockwise" ) + "\tCtrl+Y", "",
99  rotate_pos_y_xpm, SELECTION_CONDITIONS::ShowAlways );
100 
101  viewMenu->AddSeparator();
102  viewMenu->AddItem( ID_ROTATE3D_Z_NEG, _( "Rotate Z Clockwise" ) + "\tCtrl+Shift+Z", "",
103  rotate_neg_z_xpm, SELECTION_CONDITIONS::ShowAlways );;
104 
105  viewMenu->AddItem( ID_ROTATE3D_Z_POS, _( "Rotate Z Counterclockwise" ) + "\tCtrl+Z", "",
106  rotate_pos_z_xpm, SELECTION_CONDITIONS::ShowAlways );
107 
108  viewMenu->AddSeparator();
109  viewMenu->AddItem( ID_MOVE3D_LEFT, _( "Move Left\tLeft" ), "",
111 
112  viewMenu->AddItem( ID_MOVE3D_RIGHT, _( "Move Right\tRight" ), "",
114 
115  viewMenu->AddItem( ID_MOVE3D_UP, _( "Move Up\tUp" ), "",
117 
118  viewMenu->AddItem( ID_MOVE3D_DOWN, _( "Move Down\tDown" ), "",
120 
121  viewMenu->Resolve();
122 
123  //-- Preferences menu -----------------------------------------------
124  //
125  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, tool );
126 
127  auto raytracingCondition = [ this ] ( const SELECTION& aSel ) {
129  };
130  auto NormalModeCondition = [ this ] ( const SELECTION& aSel ) {
132  };
133  auto DiffuseModeCondition = [ this ] ( const SELECTION& aSel ) {
135  };
136  auto CADModeCondition = [ this ] ( const SELECTION& aSel ) {
138  };
139  auto copperThicknessCondition = [ this ] ( const SELECTION& aSel ) {
141  };
142  auto boundingBoxesCondition = [ this ] ( const SELECTION& aSel ) {
144  };
145  auto renderShadowsCondition = [ this ] ( const SELECTION& aSel ) {
147  };
148  auto proceduralTexturesCondition = [ this ] ( const SELECTION& aSel ) {
150  };
151  auto showFloorCondition = [ this ] ( const SELECTION& aSel ) {
153  };
154  auto useRefractionsCondition = [ this ] ( const SELECTION& aSel ) {
156  };
157  auto useReflectionsCondition = [ this ] ( const SELECTION& aSel ) {
159  };
160  auto antiAliasingCondition = [ this ] ( const SELECTION& aSel ) {
162  };
163  auto postProcessCondition = [ this ] ( const SELECTION& aSel ) {
165  };
166  auto showAxesCondition = [ this ] ( const SELECTION& aSel ) {
167  return m_settings.GetFlag( FL_AXIS );
168  };
169 
170  prefsMenu->AddItem( ID_TOOL_SET_VISIBLE_ITEMS, _( "Display Options" ), "",
171  read_setup_xpm, SELECTION_CONDITIONS::ShowAlways );
172 
173  prefsMenu->AddCheckItem( ID_RENDER_CURRENT_VIEW, _( "Raytracing" ), "",
174  tools_xpm, raytracingCondition );
175 
176  // Render options submenu
177  CONDITIONAL_MENU* optsSubmenu = new CONDITIONAL_MENU( false, tool );
178  optsSubmenu->SetTitle( _( "Render Options" ) );
179  optsSubmenu->SetIcon( options_3drender_xpm );
180 
181  // Material properties submenu
182  CONDITIONAL_MENU* propsSubmenu = new CONDITIONAL_MENU( false, tool );
183  propsSubmenu->SetTitle( _( "Material Properties" ) );
184  propsSubmenu->SetIcon( color_materials_xpm );
185 
187  _( "Use All Properties" ),
188  _( "Use all material properties from each 3D model file" ),
189  nullptr, NormalModeCondition );
190 
192  _( "Use Diffuse Only" ),
193  _( "Use only the diffuse color property from model 3D model file" ),
194  nullptr, DiffuseModeCondition );
195 
197  _( "CAD Color Style" ),
198  _( "Use a CAD color style based on the diffuse color of the material" ),
199  nullptr, CADModeCondition );
200 
201  optsSubmenu->AddMenu( propsSubmenu, SELECTION_CONDITIONS::ShowAlways );
202 
204  _( "Show Copper Thickness" ),
205  _( "Shows the copper thickness on copper layers (slower loading)" ),
206  use_3D_copper_thickness_xpm, copperThicknessCondition );
207 
209  _( "Show Model Bounding Boxes" ), "",
210  ortho_xpm, boundingBoxesCondition );
211 
212  // Raytracing submenu
213  CONDITIONAL_MENU* raySubmenu = new CONDITIONAL_MENU( false, tool );
214  raySubmenu->SetTitle( _( "Raytracing Options" ) );
215  raySubmenu->SetIcon( tools_xpm );
216 
218  _( "Render Shadows" ), "",
219  green_xpm, renderShadowsCondition );
220 
222  _( "Procedural Textures" ),
223  _( "Apply procedural textures to materials (slow)"),
224  green_xpm, proceduralTexturesCondition );
225 
227  _( "Add Floor" ),
228  _( "Adds a floor plane below the board (slow)"),
229  green_xpm, showFloorCondition );
230 
232  _( "Refractions" ),
233  _( "Render materials with refractions properties on final render (slow)"),
234  green_xpm, useRefractionsCondition );
235 
237  _( "Reflections" ),
238  _( "Render materials with reflections properties on final render (slow)"),
239  green_xpm, useReflectionsCondition );
240 
242  _( "Anti-aliasing" ),
243  _( "Render with improved quality on final render (slow)"),
244  green_xpm, antiAliasingCondition );
245 
247  _( "Post-processing" ),
248  _( "Apply Screen Space Ambient Occlusion and Global Illumination reflections on final render (slow)"),
249  green_xpm, postProcessCondition );
250 
251  optsSubmenu->AddMenu( raySubmenu, SELECTION_CONDITIONS::ShowAlways );
252  prefsMenu->AddMenu( optsSubmenu, SELECTION_CONDITIONS::ShowAlways );
253 
254  prefsMenu->AddSeparator();
255 
256  // Color submenu
257  CONDITIONAL_MENU* colorSubmenu = new CONDITIONAL_MENU( false, tool );
258  colorSubmenu->SetTitle( _( "Choose Colors" ) );
259  colorSubmenu->SetIcon( palette_xpm );
260 
261  colorSubmenu->AddItem( ID_MENU3D_BGCOLOR_TOP, _( "Background Top Color..." ), "",
262  setcolor_3d_bg_xpm, SELECTION_CONDITIONS::ShowAlways );
263 
264  colorSubmenu->AddItem( ID_MENU3D_BGCOLOR_BOTTOM, _( "Background Bottom Color..." ), "",
265  setcolor_3d_bg_xpm, SELECTION_CONDITIONS::ShowAlways );
266 
267  colorSubmenu->AddItem( ID_MENU3D_SILKSCREEN_COLOR, _( "Silkscreen Color..." ), "",
268  setcolor_silkscreen_xpm, SELECTION_CONDITIONS::ShowAlways );
269 
270  colorSubmenu->AddItem( ID_MENU3D_SOLDERMASK_COLOR, _( "Solder Mask Color..." ), "",
271  setcolor_soldermask_xpm, SELECTION_CONDITIONS::ShowAlways );
272 
273  colorSubmenu->AddItem( ID_MENU3D_SOLDERPASTE_COLOR, _( "Solder Paste Color..." ), "",
274  setcolor_solderpaste_xpm, SELECTION_CONDITIONS::ShowAlways );
275 
276  colorSubmenu->AddItem( ID_MENU3D_COPPER_COLOR, _( "Copper/Surface Finish Color..." ), "",
277  setcolor_copper_xpm, SELECTION_CONDITIONS::ShowAlways );
278 
279  colorSubmenu->AddItem( ID_MENU3D_PCB_BODY_COLOR, _( "Board Body Color..." ), "",
280  setcolor_board_body_xpm, SELECTION_CONDITIONS::ShowAlways );
281 
282  prefsMenu->AddMenu( colorSubmenu );
283 
284  prefsMenu->AddCheckItem( ID_MENU3D_AXIS_ONOFF, _( "Show 3D &Axis" ), "",
285  axis3d_front_xpm, showAxesCondition );
286 
287  // Grid submenu
288  CONDITIONAL_MENU* gridSubmenu = new CONDITIONAL_MENU( false, tool );
289  gridSubmenu->SetTitle( _( "3D Grid" ) );
290  gridSubmenu->SetIcon( grid_xpm );
291 
292  auto noGridCondition = [ this ] ( const SELECTION& aSel ) {
293  return m_settings.GridGet() == GRID3D_NONE;
294  };
295  auto grid10mmCondition = [ this ] ( const SELECTION& aSel ) {
296  return m_settings.GridGet() == GRID3D_10MM;
297  };
298  auto grid5mmCondition = [ this ] ( const SELECTION& aSel ) {
299  return m_settings.GridGet() == GRID3D_5MM;
300  };
301  auto grid2p5mmCondition = [ this ] ( const SELECTION& aSel ) {
302  return m_settings.GridGet() == GRID3D_2P5MM;
303  };
304  auto grid_1mmCondition = [ this ] ( const SELECTION& aSel ) {
305  return m_settings.GridGet() == GRID3D_1MM;
306  };
307 
308  gridSubmenu->AddCheckItem( ID_MENU3D_GRID_NOGRID, _( "No 3D Grid" ), "",
309  nullptr, noGridCondition );
310  gridSubmenu->AddCheckItem( ID_MENU3D_GRID_10_MM, _( "3D Grid 10mm" ), "",
311  nullptr, grid10mmCondition );
312  gridSubmenu->AddCheckItem( ID_MENU3D_GRID_5_MM, _( "3D Grid 5mm" ), "",
313  nullptr, grid5mmCondition );
314  gridSubmenu->AddCheckItem( ID_MENU3D_GRID_2P5_MM, _( "3D Grid 2.5mm" ), "",
315  nullptr, grid2p5mmCondition );
316  gridSubmenu->AddCheckItem( ID_MENU3D_GRID_1_MM, _( "3D Grid 1mm" ), "",
317  nullptr, grid_1mmCondition );
318 
319  prefsMenu->AddMenu( gridSubmenu, SELECTION_CONDITIONS::ShowAlways );
320 
321  prefsMenu->AddSeparator();
322  prefsMenu->AddItem( ID_MENU3D_RESET_DEFAULTS, _( "Reset to Default Settings" ), "",
324 
325 #ifdef __APPLE__ // Note: will get moved to Apple menu by wxWidgets
326  prefsMenu->AddItem( wxID_PREFERENCES,
327  _( "Preferences...\tCTRL+," ),
328  _( "Show preferences for all open tools" ),
329  preference_xpm, SELECTION_CONDITIONS::ShowAlways );
330 #endif
331 
332  prefsMenu->Resolve();
333 
334  //-- Menubar -------------------------------------------------------------
335  //
336  menuBar->Append( fileMenu, _( "&File" ) );
337  menuBar->Append( editMenu, _( "&Edit" ) );
338  menuBar->Append( viewMenu, _( "&View" ) );
339  menuBar->Append( prefsMenu, _( "&Preferences" ) );
340  AddStandardHelpMenu( menuBar );
341 
342  SetMenuBar( menuBar );
343 }
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()
Use only diffuse material properties.
Definition: 3d_enums.h:93
CINFO3D_VISU m_settings
#define HELP_ZOOM_OUT
Definition: id.h:215
GRID3D_TYPE GridGet() const
GridGet - get the current grid.
Definition: cinfo3d_visu.h:216
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
#define HELP_ZOOM_IN
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE
MATERIAL_MODE MaterialModeGet() const
MaterialModeGet.
Definition: cinfo3d_visu.h:246
strings common to toolbars and menubar
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:68
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
#define HELP_ZOOM_REDRAW
Use a gray shading based on diffuse material.
Definition: 3d_enums.h:94
Class COMMON_CONTROL.
#define _(s)
void Resolve()
Function Resolve()
RENDER_ENGINE RenderEngineGet() const
RenderEngineGet.
Definition: cinfo3d_visu.h:234
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
Use all material properties from model file.
Definition: 3d_enums.h:92
void AddClose(wxString aAppname="")
Function AddClose()
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
#define HELP_ZOOM_FIT
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:86
Declaration of the eda_3d_viewer class.
void CreateMenuBar()
Definition: 3d_menubar.cpp:38
TOOL_MANAGER * m_toolManager
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()