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 <3d_canvas/cinfo3d_visu.h>
31 #include <menus_helpers.h>
32 #include <3d_viewer_id.h>
33 #include <3d_actions.h>
34 #include <tool/tool_manager.h>
35 #include <tool/conditional_menu.h>
36 #include <tool/common_control.h>
37 #include "help_common_strings.h"
38 
39 
41 {
42  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::CreateMenuBar" );
43 
45  wxMenuBar* menuBar = new wxMenuBar;
46 
47 
48  //-- File menu -----------------------------------------------------------
49  //
50  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, tool );
51 
52  fileMenu->AddItem( ID_MENU_SCREENCOPY_PNG, _( "Export Current View as PNG..." ), "",
54 
55  fileMenu->AddItem( ID_MENU_SCREENCOPY_JPEG, _( "Export Current View as JPEG..." ), "",
57 
58  fileMenu->AddSeparator();
59  fileMenu->AddItem( wxID_CLOSE, _( "Close" ), "", exit_xpm, SELECTION_CONDITIONS::ShowAlways );
60 
61  fileMenu->Resolve();
62 
63  //-- Edit menu -------------------------------------------------------
64  //
65  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, tool );
66 
67  editMenu->AddItem( ID_TOOL_SCREENCOPY_TOCLIBBOARD, _( "Copy 3D Image" ), "",
69 
70  editMenu->Resolve();
71 
72  //-- View menu -------------------------------------------------------
73  //
74  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, tool );
75 
76  viewMenu->AddItem( ID_ZOOM_IN, _( "Zoom In\tF1" ), HELP_ZOOM_IN,
77  zoom_in_xpm, SELECTION_CONDITIONS::ShowAlways );
78 
79  viewMenu->AddItem( ID_ZOOM_OUT, _( "Zoom Out\tF2" ), HELP_ZOOM_OUT,
80  zoom_out_xpm, SELECTION_CONDITIONS::ShowAlways );
81 
82  viewMenu->AddItem( ID_ZOOM_PAGE, _( "Zoom to Fit" ), HELP_ZOOM_FIT,
83  zoom_fit_in_page_xpm, SELECTION_CONDITIONS::ShowAlways );
84 
85  viewMenu->AddItem( ID_ZOOM_REDRAW, _( "Redraw\tR" ), HELP_ZOOM_REDRAW,
86  zoom_redraw_xpm, SELECTION_CONDITIONS::ShowAlways );
87 
88  viewMenu->AddSeparator();
89  viewMenu->AddItem( ID_ROTATE3D_X_NEG, _( "Rotate X Clockwise\tShift+X" ), "",
90  rotate_neg_x_xpm, SELECTION_CONDITIONS::ShowAlways );
91 
92  viewMenu->AddItem( ID_ROTATE3D_X_POS, _( "Rotate X Counterclockwise\tX" ), "",
93  rotate_pos_x_xpm, SELECTION_CONDITIONS::ShowAlways );
94 
95  viewMenu->AddSeparator();
96  viewMenu->AddItem( ID_ROTATE3D_Y_NEG, _( "Rotate Y Clockwise\tShift+Y" ), "",
97  rotate_neg_y_xpm, SELECTION_CONDITIONS::ShowAlways );
98 
99  viewMenu->AddItem( ID_ROTATE3D_Y_POS, _( "Rotate Y Counterclockwise\tY" ), "",
100  rotate_pos_y_xpm, SELECTION_CONDITIONS::ShowAlways );
101 
102  viewMenu->AddSeparator();
103  viewMenu->AddItem( ID_ROTATE3D_Z_NEG, _( "Rotate Z Clockwise\tShift+Z" ), "",
104  rotate_neg_z_xpm, SELECTION_CONDITIONS::ShowAlways );;
105 
106  viewMenu->AddItem( ID_ROTATE3D_Z_POS, _( "Rotate Z Counterclockwise\tZ" ), "",
107  rotate_pos_z_xpm, SELECTION_CONDITIONS::ShowAlways );
108 
109  viewMenu->AppendSeparator();
110  viewMenu->AddItem( ID_MOVE3D_LEFT, _( "Move Left\tLeft" ), "",
112 
113  viewMenu->AddItem( ID_MOVE3D_RIGHT, _( "Move Right\tRight" ), "",
115 
116  viewMenu->AddItem( ID_MOVE3D_UP, _( "Move Up\tUp" ), "",
118 
119  viewMenu->AddItem( ID_MOVE3D_DOWN, _( "Move Down\tDown" ), "",
121 
122  viewMenu->Resolve();
123 
124  //-- Preferences menu -----------------------------------------------
125  //
126  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, tool );
127 
128  auto raytracingCondition = [ this ] ( const SELECTION& aSel ) {
130  };
131  auto NormalModeCondition = [ this ] ( const SELECTION& aSel ) {
133  };
134  auto DiffuseModeCondition = [ this ] ( const SELECTION& aSel ) {
136  };
137  auto CADModeCondition = [ this ] ( const SELECTION& aSel ) {
139  };
140  auto copperThicknessCondition = [ this ] ( const SELECTION& aSel ) {
142  };
143  auto boundingBoxesCondition = [ this ] ( const SELECTION& aSel ) {
145  };
146  auto renderShadowsCondition = [ this ] ( const SELECTION& aSel ) {
148  };
149  auto proceduralTexturesCondition = [ this ] ( const SELECTION& aSel ) {
151  };
152  auto showFloorCondition = [ this ] ( const SELECTION& aSel ) {
154  };
155  auto useRefractionsCondition = [ this ] ( const SELECTION& aSel ) {
157  };
158  auto useReflectionsCondition = [ this ] ( const SELECTION& aSel ) {
160  };
161  auto antiAliasingCondition = [ this ] ( const SELECTION& aSel ) {
163  };
164  auto postProcessCondition = [ this ] ( const SELECTION& aSel ) {
166  };
167  auto showAxesCondition = [ this ] ( const SELECTION& aSel ) {
168  return m_settings.GetFlag( FL_AXIS );
169  };
170 
171  prefsMenu->AddItem( ID_TOOL_SET_VISIBLE_ITEMS, _( "Display Options" ), "",
172  read_setup_xpm, SELECTION_CONDITIONS::ShowAlways );
173 
174  prefsMenu->AddCheckItem( ID_RENDER_CURRENT_VIEW, _( "Raytracing" ), "",
175  tools_xpm, raytracingCondition );
176 
177  // Render options submenu
178  CONDITIONAL_MENU* optsSubmenu = new CONDITIONAL_MENU( false, tool );
179  optsSubmenu->SetTitle( _( "Render Options" ) );
180  optsSubmenu->SetIcon( options_3drender_xpm );
181 
182  // Material properties submenu
183  CONDITIONAL_MENU* propsSubmenu = new CONDITIONAL_MENU( false, tool );
184  propsSubmenu->SetTitle( _( "Material Properties" ) );
185  propsSubmenu->SetIcon( color_materials_xpm );
186 
188  _( "Use All Properties" ),
189  _( "Use all material properties from each 3D model file" ),
190  nullptr, NormalModeCondition );
191 
193  _( "Use Diffuse Only" ),
194  _( "Use only the diffuse color property from model 3D model file" ),
195  nullptr, DiffuseModeCondition );
196 
198  _( "CAD Color Style" ),
199  _( "Use a CAD color style based on the diffuse color of the material" ),
200  nullptr, CADModeCondition );
201 
202  optsSubmenu->AddMenu( propsSubmenu, SELECTION_CONDITIONS::ShowAlways );
203 
205  _( "Show Copper Thickness" ),
206  _( "Shows the copper thickness on copper layers (slower loading)" ),
207  use_3D_copper_thickness_xpm, copperThicknessCondition );
208 
210  _( "Show Model Bounding Boxes" ), "",
211  ortho_xpm, boundingBoxesCondition );
212 
213  // Raytracing submenu
214  CONDITIONAL_MENU* raySubmenu = new CONDITIONAL_MENU( false, tool );
215  raySubmenu->SetTitle( _( "Raytracing Options" ) );
216  raySubmenu->SetIcon( tools_xpm );
217 
219  _( "Render Shadows" ), "",
220  green_xpm, renderShadowsCondition );
221 
223  _( "Procedural Textures" ),
224  _( "Apply procedural textures to materials (slow)"),
225  green_xpm, proceduralTexturesCondition );
226 
228  _( "Add Floor" ),
229  _( "Adds a floor plane below the board (slow)"),
230  green_xpm, showFloorCondition );
231 
233  _( "Refractions" ),
234  _( "Render materials with refractions properties on final render (slow)"),
235  green_xpm, useRefractionsCondition );
236 
238  _( "Reflections" ),
239  _( "Render materials with reflections properties on final render (slow)"),
240  green_xpm, useReflectionsCondition );
241 
243  _( "Anti-aliasing" ),
244  _( "Render with improved quality on final render (slow)"),
245  green_xpm, antiAliasingCondition );
246 
248  _( "Post-processing" ),
249  _( "Apply Screen Space Ambient Occlusion and Global Illumination reflections on final render (slow)"),
250  green_xpm, postProcessCondition );
251 
252  optsSubmenu->AddMenu( raySubmenu, SELECTION_CONDITIONS::ShowAlways );
253  prefsMenu->AddMenu( optsSubmenu, SELECTION_CONDITIONS::ShowAlways );
254 
255  prefsMenu->AddSeparator();
256 
257  // Color submenu
258  CONDITIONAL_MENU* colorSubmenu = new CONDITIONAL_MENU( false, tool );
259  colorSubmenu->SetTitle( _( "Choose Colors" ) );
260  colorSubmenu->SetIcon( palette_xpm );
261 
262  colorSubmenu->AddItem( ID_MENU3D_BGCOLOR_TOP, _( "Background Top Color..." ), "",
263  setcolor_3d_bg_xpm, SELECTION_CONDITIONS::ShowAlways );
264 
265  colorSubmenu->AddItem( ID_MENU3D_BGCOLOR_BOTTOM, _( "Background Bottom Color..." ), "",
266  setcolor_3d_bg_xpm, SELECTION_CONDITIONS::ShowAlways );
267 
268  colorSubmenu->AddItem( ID_MENU3D_SILKSCREEN_COLOR, _( "Silkscreen Color..." ), "",
269  setcolor_silkscreen_xpm, SELECTION_CONDITIONS::ShowAlways );
270 
271  colorSubmenu->AddItem( ID_MENU3D_SOLDERMASK_COLOR, _( "Solder Mask Color..." ), "",
272  setcolor_soldermask_xpm, SELECTION_CONDITIONS::ShowAlways );
273 
274  colorSubmenu->AddItem( ID_MENU3D_SOLDERPASTE_COLOR, _( "Solder Paste Color..." ), "",
275  setcolor_solderpaste_xpm, SELECTION_CONDITIONS::ShowAlways );
276 
277  colorSubmenu->AddItem( ID_MENU3D_COPPER_COLOR, _( "Copper/Surface Finish Color..." ), "",
278  setcolor_copper_xpm, SELECTION_CONDITIONS::ShowAlways );
279 
280  colorSubmenu->AddItem( ID_MENU3D_PCB_BODY_COLOR, _( "Board Body Color..." ), "",
281  setcolor_board_body_xpm, SELECTION_CONDITIONS::ShowAlways );
282 
283  prefsMenu->AddMenu( colorSubmenu );
284 
285  prefsMenu->AddCheckItem( ID_MENU3D_AXIS_ONOFF, _( "Show 3D &Axis" ), "",
286  axis3d_front_xpm, showAxesCondition );
287 
288  // Grid submenu
289  CONDITIONAL_MENU* gridSubmenu = new CONDITIONAL_MENU( false, tool );
290  gridSubmenu->SetTitle( _( "3D Grid" ) );
291  gridSubmenu->SetIcon( grid_xpm );
292 
293  auto noGridCondition = [ this ] ( const SELECTION& aSel ) {
294  return m_settings.GridGet() == GRID3D_NONE;
295  };
296  auto grid10mmCondition = [ this ] ( const SELECTION& aSel ) {
297  return m_settings.GridGet() == GRID3D_10MM;
298  };
299  auto grid5mmCondition = [ this ] ( const SELECTION& aSel ) {
300  return m_settings.GridGet() == GRID3D_5MM;
301  };
302  auto grid2p5mmCondition = [ this ] ( const SELECTION& aSel ) {
303  return m_settings.GridGet() == GRID3D_2P5MM;
304  };
305  auto grid_1mmCondition = [ this ] ( const SELECTION& aSel ) {
306  return m_settings.GridGet() == GRID3D_1MM;
307  };
308 
309  gridSubmenu->AddItem( ID_MENU3D_GRID_NOGRID, _( "No 3D Grid" ), "",
310  nullptr, noGridCondition );
311  gridSubmenu->AddItem( ID_MENU3D_GRID_10_MM, _( "3D Grid 10mm" ), "",
312  nullptr, grid10mmCondition );
313  gridSubmenu->AddItem( ID_MENU3D_GRID_5_MM, _( "3D Grid 5mm" ), "",
314  nullptr, grid5mmCondition );
315  gridSubmenu->AddItem( ID_MENU3D_GRID_2P5_MM, _( "3D Grid 2.5mm" ), "",
316  nullptr, grid2p5mmCondition );
317  gridSubmenu->AddItem( ID_MENU3D_GRID_1_MM, _( "3D Grid 1mm" ), "",
318  nullptr, grid_1mmCondition );
319 
320  prefsMenu->AddMenu( gridSubmenu, SELECTION_CONDITIONS::ShowAlways );
321 
322  prefsMenu->AppendSeparator();
323  prefsMenu->AddItem( ID_MENU3D_RESET_DEFAULTS, _( "Reset to Default Settings" ), "",
325 
326  prefsMenu->Resolve();
327 
328  //-- Menubar -------------------------------------------------------------
329  //
330  menuBar->Append( fileMenu, _( "&File" ) );
331  menuBar->Append( editMenu, _( "&Edit" ) );
332  menuBar->Append( viewMenu, _( "&View" ) );
333  menuBar->Append( prefsMenu, _( "&Preferences" ) );
334  AddStandardHelpMenu( menuBar );
335 
336  SetMenuBar( menuBar );
337 }
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
Handles data related with the board to be visualized.
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.
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:66
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
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:84
Declaration of the eda_3d_viewer class.
void CreateMenuBar()
Definition: 3d_menubar.cpp:40
TOOL_MANAGER * m_toolManager
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()