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-2018 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 
31 #include <fctsys.h>
32 
33 #include <eda_3d_viewer.h>
34 #include <3d_canvas/cinfo3d_visu.h>
35 #include <menus_helpers.h>
36 #include <3d_viewer_id.h>
37 #include "help_common_strings.h"
38 
40 
42 {
43  wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::CreateMenuBar" ) );
44 
45  wxMenuBar* menuBar = new wxMenuBar;
46  wxMenu* fileMenu = new wxMenu;
47  wxMenu* editMenu = new wxMenu;
48  wxMenu* viewMenu = new wxMenu;
49  wxMenu* prefsMenu = new wxMenu;
50  wxMenu* helpMenu = new wxMenu;
51 
52  menuBar->Append( fileMenu, _( "&File" ) );
53 
55  _( "Export Current View as PNG..." ),
56  KiBitmap( export_xpm ) );
57 
59  _( "Export Current View as JPEG..." ),
60  KiBitmap( export_xpm ) );
61 
62  fileMenu->AppendSeparator();
63  AddMenuItem( fileMenu, wxID_EXIT,
64  _( "&Exit" ),
65  KiBitmap( exit_xpm ) );
66 
67  menuBar->Append( editMenu, _( "&Edit" ) );
68 
70  _( "Copy 3D Image" ),
71  KiBitmap( copy_xpm ) );
72 
73  menuBar->Append( viewMenu, _( "&View" ) );
74 
75  AddMenuItem( viewMenu, ID_ZOOM_IN,
76  _( "Zoom &In" ), HELP_ZOOM_IN,
77  KiBitmap( zoom_in_xpm ) );
78 
79  AddMenuItem( viewMenu, ID_ZOOM_OUT,
80  _( "Zoom &Out" ), HELP_ZOOM_OUT,
81  KiBitmap( zoom_out_xpm ) );
82 
83  AddMenuItem( viewMenu, ID_ZOOM_PAGE,
84  _( "Zoom to &Fit" ), HELP_ZOOM_FIT,
85  KiBitmap( zoom_fit_in_page_xpm ) );
86 
87  AddMenuItem( viewMenu, ID_ZOOM_REDRAW,
88  _( "&Redraw" ), HELP_ZOOM_REDRAW,
89  KiBitmap( zoom_redraw_xpm ) );
90 
91  viewMenu->AppendSeparator();
92 
93  AddMenuItem( viewMenu, ID_ROTATE3D_X_NEG,
94  _( "Rotate X Clockwise" ),
95  KiBitmap( rotate_neg_x_xpm ) );
96 
97  AddMenuItem( viewMenu, ID_ROTATE3D_X_POS,
98  _( "Rotate X Counterclockwise" ),
99  KiBitmap( rotate_pos_x_xpm ) );
100 
101  viewMenu->AppendSeparator();
102 
103  AddMenuItem( viewMenu, ID_ROTATE3D_Y_NEG,
104  _( "Rotate Y Clockwise" ),
105  KiBitmap( rotate_neg_y_xpm ) );
106 
107  AddMenuItem( viewMenu, ID_ROTATE3D_Y_POS,
108  _( "Rotate Y Counterclockwise" ),
109  KiBitmap( rotate_pos_y_xpm ) );
110 
111  viewMenu->AppendSeparator();
112 
113  AddMenuItem( viewMenu, ID_ROTATE3D_Z_NEG,
114  _( "Rotate Z Clockwise" ),
115  KiBitmap( rotate_neg_z_xpm ) );
116 
117  AddMenuItem( viewMenu, ID_ROTATE3D_Z_POS,
118  _( "Rotate Z Counterclockwise" ),
119  KiBitmap( rotate_pos_z_xpm ) );
120 
121  viewMenu->AppendSeparator();
122 
123  AddMenuItem( viewMenu, ID_MOVE3D_LEFT,
124  _( "Move left" ),
125  KiBitmap( left_xpm ) );
126 
127  AddMenuItem( viewMenu, ID_MOVE3D_RIGHT,
128  _( "Move right" ),
129  KiBitmap( right_xpm ) );
130 
131  AddMenuItem( viewMenu, ID_MOVE3D_UP,
132  _( "Move up" ),
133  KiBitmap( up_xpm ) );
134 
135  AddMenuItem( viewMenu, ID_MOVE3D_DOWN,
136  _( "Move down" ),
137  KiBitmap( down_xpm ) );
138 
139  menuBar->Append( prefsMenu, _( "&Preferences" ) );
140 
142  _( "Use Touchpad to Pan" ),
143  KiBitmap( tools_xpm ), wxITEM_CHECK );
144 
145  prefsMenu->AppendSeparator();
146 
148  _( "Display Options" ),
149  KiBitmap( read_setup_xpm ) );
150 
151  wxMenu * renderEngineList = new wxMenu;
152  AddMenuItem( prefsMenu, renderEngineList, ID_MENU3D_ENGINE,
153  _( "Render Engine" ), KiBitmap( render_mode_xpm ) );
154 
155  renderEngineList->AppendRadioItem( ID_MENU3D_ENGINE_OPENGL_LEGACY,
156  _( "OpenGL" ),
157  wxEmptyString );
158 
159  renderEngineList->AppendRadioItem( ID_MENU3D_ENGINE_RAYTRACING,
160  _( "Raytracing" ),
161  wxEmptyString );
162 
163  renderEngineList->Check( ID_MENU3D_ENGINE_OPENGL_LEGACY,
165 
166  renderEngineList->Check( ID_MENU3D_ENGINE_RAYTRACING,
168 
169  wxMenu * renderOptionsMenu = new wxMenu;
170  AddMenuItem( prefsMenu, renderOptionsMenu, ID_MENU3D_FL,
171  _( "Render Options" ), KiBitmap( options_3drender_xpm ) );
172 
173  wxMenu * materialsList = new wxMenu;
174  AddMenuItem( renderOptionsMenu, materialsList, ID_MENU3D_FL_RENDER_MATERIAL,
175  _( "Material Properties" ), KiBitmap( color_materials_xpm ) );
176 
177  materialsList->AppendRadioItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL,
178  _( "Use All Properties" ),
179  _( "Use all material properties from each 3D model file" ) );
180 
181  materialsList->AppendRadioItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_DIFFUSE_ONLY,
182  _( "Use Diffuse Only" ),
183  _( "Use only the diffuse color property from model 3D model file " ) );
184 
185  materialsList->AppendRadioItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE,
186  _( "CAD Color Style" ),
187  _( "Use a CAD color style based on the diffuse color of the material" ) );
188 
189  // Add specific preferences for OpenGL
190  // /////////////////////////////////////////////////////////////////////////
191  wxMenu * renderOptionsMenu_OPENGL = new wxMenu;
192 
193  AddMenuItem( renderOptionsMenu, renderOptionsMenu_OPENGL, ID_MENU3D_FL_OPENGL,
194  _( "OpenGL Options" ), KiBitmap( tools_xpm ) );
195 
196  AddMenuItem( renderOptionsMenu_OPENGL, ID_MENU3D_FL_OPENGL_RENDER_COPPER_THICKNESS,
197  _( "Show Copper Thickness" ),
198  _( "Shows the copper thickness on copper layers (slower loading)"),
199  KiBitmap( use_3D_copper_thickness_xpm ), wxITEM_CHECK );
200 
201  AddMenuItem( renderOptionsMenu_OPENGL, ID_MENU3D_FL_OPENGL_RENDER_SHOW_MODEL_BBOX,
202  _( "Show Model Bounding Boxes" ),
203  KiBitmap( ortho_xpm ), wxITEM_CHECK );
204 
205 
206  // Add specific preferences for Raytracing
207  // /////////////////////////////////////////////////////////////////////////
208  wxMenu * renderOptionsMenu_RAYTRACING = new wxMenu;
209  AddMenuItem( renderOptionsMenu, renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING,
210  _( "Raytracing Options" ), KiBitmap( tools_xpm ) );
211 
212  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_RENDER_SHADOWS,
213  _( "Render Shadows" ),
214  KiBitmap( green_xpm ), wxITEM_CHECK );
215 
216  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_PROCEDURAL_TEXTURES,
217  _( "Procedural Textures" ),
218  _( "Apply procedural textures to materials (slow)"),
219  KiBitmap( green_xpm ), wxITEM_CHECK );
220 
221  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_BACKFLOOR,
222  _( "Add Floor" ),
223  _( "Adds a floor plane below the board (slow)"),
224  KiBitmap( green_xpm ), wxITEM_CHECK );
225 
226  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_REFRACTIONS,
227  _( "Refractions" ),
228  _( "Render materials with refractions properties on final render (slow)"),
229  KiBitmap( green_xpm ), wxITEM_CHECK );
230 
231  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_REFLECTIONS,
232  _( "Reflections" ),
233  _( "Render materials with reflections properties on final render (slow)"),
234  KiBitmap( green_xpm ), wxITEM_CHECK );
235 
236  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_ANTI_ALIASING,
237  _( "Anti-aliasing" ),
238  _( "Render with improved quality on final render (slow)"),
239  KiBitmap( green_xpm ), wxITEM_CHECK );
240 
241  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_POST_PROCESSING,
242  _( "Post-processing" ),
243  _( "Apply Screen Space Ambient Occlusion and Global Illumination reflections on final render (slow)"),
244  KiBitmap( green_xpm ), wxITEM_CHECK );
245 
246  prefsMenu->AppendSeparator();
247 
248 
249  // Colors, axis and grid elements
250  // /////////////////////////////////////////////////////////////////////////
251 
252  // Add submenu set Colors
253  wxMenu * setColorMenu = new wxMenu;
254  AddMenuItem( prefsMenu, setColorMenu, ID_MENU3D_COLOR,
255  _( "Choose Colors" ), KiBitmap( palette_xpm ) );
256 
257  wxMenu * setBgColorMenu = new wxMenu;
258  AddMenuItem( setColorMenu, setBgColorMenu, ID_MENU3D_BGCOLOR,
259  _( "Background Color" ), KiBitmap( palette_xpm ) );
260 
262  _( "Background Top Color..." ), KiBitmap( setcolor_3d_bg_xpm ) );
263 
265  _( "Background Bottom Color..." ), KiBitmap( setcolor_3d_bg_xpm ) );
266 
268  _( "Silkscreen Color..." ), KiBitmap( setcolor_silkscreen_xpm ) );
269 
271  _( "Solder Mask Color..." ), KiBitmap( setcolor_soldermask_xpm ) );
272 
274  _( "Solder Paste Color..." ), KiBitmap( setcolor_solderpaste_xpm ) );
275 
277  _( "Copper/Surface Finish Color..." ), KiBitmap( setcolor_copper_xpm ) );
278 
280  _( "Board Body Color..." ), KiBitmap( setcolor_board_body_xpm ) );
281 
282  AddMenuItem( prefsMenu, ID_MENU3D_AXIS_ONOFF,
283  _( "Show 3D &Axis" ), KiBitmap( axis3d_front_xpm ), wxITEM_CHECK );
284 
285 
286  // Creates grid menu
287  // /////////////////////////////////////////////////////////////////////////
288 
289  wxMenu * gridlistMenu = new wxMenu;
290  AddMenuItem( prefsMenu, gridlistMenu, ID_MENU3D_GRID,
291  _( "3D Grid" ), KiBitmap( grid_xpm ) );
292  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_NOGRID, _( "No 3D Grid" ), wxEmptyString );
293  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_10_MM, _( "3D Grid 10 mm" ), wxEmptyString );
294  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_5_MM, _( "3D Grid 5 mm" ), wxEmptyString );
295  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_2P5_MM, _( "3D Grid 2.5 mm" ), wxEmptyString );
296  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_1_MM, _( "3D Grid 1 mm" ), wxEmptyString );
297 
298  // If the grid is on, check the corresponding menuitem showing the grid size
299  if( m_settings.GridGet() != GRID3D_NONE )
300  {
301  gridlistMenu->Check( ID_MENU3D_GRID_10_MM, m_settings.GridGet() == GRID3D_10MM );
302  gridlistMenu->Check( ID_MENU3D_GRID_5_MM, m_settings.GridGet() == GRID3D_5MM );
303  gridlistMenu->Check( ID_MENU3D_GRID_2P5_MM, m_settings.GridGet() == GRID3D_2P5MM );
304  gridlistMenu->Check( ID_MENU3D_GRID_1_MM, m_settings.GridGet() == GRID3D_1MM );
305  }
306  else
307  gridlistMenu->Check( ID_MENU3D_GRID_NOGRID, true );
308 
309  // Reset options
310  // /////////////////////////////////////////////////////////////////////////
311  prefsMenu->AppendSeparator();
312 
314  _( "Reset to Default Settings" ),
315  KiBitmap( tools_xpm ) );
316 
317  // Help menu
318  // /////////////////////////////////////////////////////////////////////////
319  menuBar->Append( helpMenu, _( "&Help" ) );
320 
321  AddMenuItem( helpMenu, wxID_HELP,
322  _( "Pcbnew &Manual" ),
323  _( "Open Pcbnew Manual" ),
324  KiBitmap( online_help_xpm ) );
325 
326  AddMenuItem( helpMenu, wxID_INDEX,
327  _( "&Getting Started in KiCad" ),
328  _( "Open \"Getting Started in KiCad\" guide for beginners" ),
329  KiBitmap( help_xpm ) );
330 
331  wxString text = AddHotkeyName( _( "&List Hotkeys..." ), g_3DViewer_Hokeys_Descr, HK_HELP );
333  text,
334  _( "Displays the current hotkeys list and corresponding commands" ),
335  KiBitmap( hotkeys_xpm ) );
336 
337  helpMenu->AppendSeparator();
338 
340  _( "Get &Involved" ),
341  _( "Contribute to KiCad (opens a web browser)" ),
342  KiBitmap( info_xpm ) );
343 
344  helpMenu->AppendSeparator();
345 
346  AddMenuItem( helpMenu, wxID_ABOUT,
347  _( "&About KiCad" ),
348  _( "Display KiCad About dialog" ),
349  KiBitmap( about_xpm ) );
350 
351  SetMenuBar( menuBar );
353 }
354 
355 
357 {
358  wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::SetMenuBarOptionsState" ) );
359 
360  wxMenuBar* menuBar = GetMenuBar();
361 
362  if( menuBar == NULL )
363  {
364  wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::SetMenuBarOptionsState menuBar == NULL" ) );
365 
366  return;
367  }
368 
369  wxMenuItem* item;
370  // Set the state of toggle menus according to the current display options
371  item = menuBar->FindItem( ID_MENU3D_MOUSEWHEEL_PANNING );
372  item->Check( m_settings.GetFlag( FL_MOUSEWHEEL_PANNING ) );
373 
374 
375  item = menuBar->FindItem( ID_MENU3D_ENGINE_OPENGL_LEGACY );
377 
378  item = menuBar->FindItem( ID_MENU3D_ENGINE_RAYTRACING );
380 
381  item = menuBar->FindItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL );
382  item->Check( m_settings.MaterialModeGet() == MATERIAL_MODE_NORMAL );
383 
384  item = menuBar->FindItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_DIFFUSE_ONLY );
386 
387  item = menuBar->FindItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE );
389 
390  // OpenGL
391  item = menuBar->FindItem( ID_MENU3D_FL_OPENGL_RENDER_COPPER_THICKNESS );
393 
394  item = menuBar->FindItem( ID_MENU3D_FL_OPENGL_RENDER_SHOW_MODEL_BBOX );
396 
397  // Raytracing
398  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_RENDER_SHADOWS );
400 
401  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_BACKFLOOR );
403 
404  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_REFRACTIONS );
406 
407  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_REFLECTIONS );
409 
410  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_POST_PROCESSING );
412 
413  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_ANTI_ALIASING );
415 
416  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_PROCEDURAL_TEXTURES );
418 
419 
420  item = menuBar->FindItem( ID_MENU3D_AXIS_ONOFF );
421  item->Check( m_settings.GetFlag( FL_AXIS ) );
422 
423 }
GRID3D_TYPE GridGet() const
GridGet - get the current grid.
Definition: cinfo3d_visu.h:216
Use only diffuse material properties.
Definition: 3d_enums.h:93
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:89
CINFO3D_VISU m_settings
Store all the settings and options to be used by the renders.
MATERIAL_MODE MaterialModeGet() const
MaterialModeGet.
Definition: cinfo3d_visu.h:246
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:194
#define HELP_ZOOM_FIT
void SetMenuBarOptionsState()
Set the state of toggle menus according to the current display options.
Definition: 3d_menubar.cpp:356
Definition: id.h:240
Handles data related with the board to be visualized.
#define HELP_ZOOM_OUT
#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:78
Use a gray shading based on diffuse material.
Definition: 3d_enums.h:94
RENDER_ENGINE RenderEngineGet() const
RenderEngineGet.
Definition: cinfo3d_visu.h:234
Use all material properties from model file.
Definition: 3d_enums.h:92
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
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) ...
Declaration of the eda_3d_viewer class.
struct EDA_HOTKEY_CONFIG g_3DViewer_Hokeys_Descr[]
#define HELP_ZOOM_IN
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void CreateMenuBar()
Definition: 3d_menubar.cpp:41
strings common to toolbars and menubar