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  _( "Display Options" ),
143  KiBitmap( read_setup_xpm ) );
144 
145  wxMenu * renderEngineList = new wxMenu;
146  AddMenuItem( prefsMenu, renderEngineList, ID_MENU3D_ENGINE,
147  _( "Render Engine" ), KiBitmap( render_mode_xpm ) );
148 
149  renderEngineList->AppendRadioItem( ID_MENU3D_ENGINE_OPENGL_LEGACY,
150  _( "OpenGL" ),
151  wxEmptyString );
152 
153  renderEngineList->AppendRadioItem( ID_MENU3D_ENGINE_RAYTRACING,
154  _( "Raytracing" ),
155  wxEmptyString );
156 
157  renderEngineList->Check( ID_MENU3D_ENGINE_OPENGL_LEGACY,
159 
160  renderEngineList->Check( ID_MENU3D_ENGINE_RAYTRACING,
162 
163  wxMenu * renderOptionsMenu = new wxMenu;
164  AddMenuItem( prefsMenu, renderOptionsMenu, ID_MENU3D_FL,
165  _( "Render Options" ), KiBitmap( options_3drender_xpm ) );
166 
167  wxMenu * materialsList = new wxMenu;
168  AddMenuItem( renderOptionsMenu, materialsList, ID_MENU3D_FL_RENDER_MATERIAL,
169  _( "Material Properties" ), KiBitmap( color_materials_xpm ) );
170 
171  materialsList->AppendRadioItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL,
172  _( "Use All Properties" ),
173  _( "Use all material properties from each 3D model file" ) );
174 
175  materialsList->AppendRadioItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_DIFFUSE_ONLY,
176  _( "Use Diffuse Only" ),
177  _( "Use only the diffuse color property from model 3D model file " ) );
178 
179  materialsList->AppendRadioItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE,
180  _( "CAD Color Style" ),
181  _( "Use a CAD color style based on the diffuse color of the material" ) );
182 
183  // Add specific preferences for OpenGL
184  // /////////////////////////////////////////////////////////////////////////
185  wxMenu * renderOptionsMenu_OPENGL = new wxMenu;
186 
187  AddMenuItem( renderOptionsMenu, renderOptionsMenu_OPENGL, ID_MENU3D_FL_OPENGL,
188  _( "OpenGL Options" ), KiBitmap( tools_xpm ) );
189 
190  AddMenuItem( renderOptionsMenu_OPENGL, ID_MENU3D_FL_OPENGL_RENDER_COPPER_THICKNESS,
191  _( "Show Copper Thickness" ),
192  _( "Shows the copper thickness on copper layers (slower loading)"),
193  KiBitmap( use_3D_copper_thickness_xpm ), wxITEM_CHECK );
194 
195  AddMenuItem( renderOptionsMenu_OPENGL, ID_MENU3D_FL_OPENGL_RENDER_SHOW_MODEL_BBOX,
196  _( "Show Model Bounding Boxes" ),
197  KiBitmap( ortho_xpm ), wxITEM_CHECK );
198 
199 
200  // Add specific preferences for Raytracing
201  // /////////////////////////////////////////////////////////////////////////
202  wxMenu * renderOptionsMenu_RAYTRACING = new wxMenu;
203  AddMenuItem( renderOptionsMenu, renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING,
204  _( "Raytracing Options" ), KiBitmap( tools_xpm ) );
205 
206  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_RENDER_SHADOWS,
207  _( "Render Shadows" ),
208  KiBitmap( green_xpm ), wxITEM_CHECK );
209 
210  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_PROCEDURAL_TEXTURES,
211  _( "Procedural Textures" ),
212  _( "Apply procedural textures to materials (slow)"),
213  KiBitmap( green_xpm ), wxITEM_CHECK );
214 
215  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_BACKFLOOR,
216  _( "Add Floor" ),
217  _( "Adds a floor plane below the board (slow)"),
218  KiBitmap( green_xpm ), wxITEM_CHECK );
219 
220  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_REFRACTIONS,
221  _( "Refractions" ),
222  _( "Render materials with refractions properties on final render (slow)"),
223  KiBitmap( green_xpm ), wxITEM_CHECK );
224 
225  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_REFLECTIONS,
226  _( "Reflections" ),
227  _( "Render materials with reflections properties on final render (slow)"),
228  KiBitmap( green_xpm ), wxITEM_CHECK );
229 
230  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_ANTI_ALIASING,
231  _( "Anti-aliasing" ),
232  _( "Render with improved quality on final render (slow)"),
233  KiBitmap( green_xpm ), wxITEM_CHECK );
234 
235  AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_POST_PROCESSING,
236  _( "Post-processing" ),
237  _( "Apply Screen Space Ambient Occlusion and Global Illumination reflections on final render (slow)"),
238  KiBitmap( green_xpm ), wxITEM_CHECK );
239 
240  prefsMenu->AppendSeparator();
241 
242 
243  // Colors, axis and grid elements
244  // /////////////////////////////////////////////////////////////////////////
245 
246  // Add submenu set Colors
247  wxMenu * setColorMenu = new wxMenu;
248  AddMenuItem( prefsMenu, setColorMenu, ID_MENU3D_COLOR,
249  _( "Choose Colors" ), KiBitmap( palette_xpm ) );
250 
251  wxMenu * setBgColorMenu = new wxMenu;
252  AddMenuItem( setColorMenu, setBgColorMenu, ID_MENU3D_BGCOLOR,
253  _( "Background Color" ), KiBitmap( palette_xpm ) );
254 
256  _( "Background Top Color..." ), KiBitmap( setcolor_3d_bg_xpm ) );
257 
259  _( "Background Bottom Color..." ), KiBitmap( setcolor_3d_bg_xpm ) );
260 
262  _( "Silkscreen Color..." ), KiBitmap( setcolor_silkscreen_xpm ) );
263 
265  _( "Solder Mask Color..." ), KiBitmap( setcolor_soldermask_xpm ) );
266 
268  _( "Solder Paste Color..." ), KiBitmap( setcolor_solderpaste_xpm ) );
269 
271  _( "Copper/Surface Finish Color..." ), KiBitmap( setcolor_copper_xpm ) );
272 
274  _( "Board Body Color..." ), KiBitmap( setcolor_board_body_xpm ) );
275 
276  AddMenuItem( prefsMenu, ID_MENU3D_AXIS_ONOFF,
277  _( "Show 3D &Axis" ), KiBitmap( axis3d_front_xpm ), wxITEM_CHECK );
278 
279 
280  // Creates grid menu
281  // /////////////////////////////////////////////////////////////////////////
282 
283  wxMenu * gridlistMenu = new wxMenu;
284  AddMenuItem( prefsMenu, gridlistMenu, ID_MENU3D_GRID,
285  _( "3D Grid" ), KiBitmap( grid_xpm ) );
286  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_NOGRID, _( "No 3D Grid" ), wxEmptyString );
287  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_10_MM, _( "3D Grid 10 mm" ), wxEmptyString );
288  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_5_MM, _( "3D Grid 5 mm" ), wxEmptyString );
289  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_2P5_MM, _( "3D Grid 2.5 mm" ), wxEmptyString );
290  gridlistMenu->AppendRadioItem( ID_MENU3D_GRID_1_MM, _( "3D Grid 1 mm" ), wxEmptyString );
291 
292  // If the grid is on, check the corresponding menuitem showing the grid size
293  if( m_settings.GridGet() != GRID3D_NONE )
294  {
295  gridlistMenu->Check( ID_MENU3D_GRID_10_MM, m_settings.GridGet() == GRID3D_10MM );
296  gridlistMenu->Check( ID_MENU3D_GRID_5_MM, m_settings.GridGet() == GRID3D_5MM );
297  gridlistMenu->Check( ID_MENU3D_GRID_2P5_MM, m_settings.GridGet() == GRID3D_2P5MM );
298  gridlistMenu->Check( ID_MENU3D_GRID_1_MM, m_settings.GridGet() == GRID3D_1MM );
299  }
300  else
301  gridlistMenu->Check( ID_MENU3D_GRID_NOGRID, true );
302 
303  // Reset options
304  // /////////////////////////////////////////////////////////////////////////
305  prefsMenu->AppendSeparator();
306 
308  _( "Reset to Default Settings" ),
309  KiBitmap( tools_xpm ) );
310 
311  // Help menu
312  // /////////////////////////////////////////////////////////////////////////
313  menuBar->Append( helpMenu, _( "&Help" ) );
314 
315  AddMenuItem( helpMenu, wxID_HELP,
316  _( "Pcbnew &Manual" ),
317  _( "Open Pcbnew Manual" ),
318  KiBitmap( online_help_xpm ) );
319 
320  AddMenuItem( helpMenu, wxID_INDEX,
321  _( "&Getting Started in KiCad" ),
322  _( "Open \"Getting Started in KiCad\" guide for beginners" ),
323  KiBitmap( help_xpm ) );
324 
325  wxString text = AddHotkeyName( _( "&List Hotkeys..." ), g_3DViewer_Hokeys_Descr, HK_HELP );
327  text,
328  _( "Displays the current hotkeys list and corresponding commands" ),
329  KiBitmap( hotkeys_xpm ) );
330 
331  helpMenu->AppendSeparator();
332 
334  _( "Get &Involved" ),
335  _( "Contribute to KiCad (opens a web browser)" ),
336  KiBitmap( info_xpm ) );
337 
338  helpMenu->AppendSeparator();
339 
340  AddMenuItem( helpMenu, wxID_ABOUT,
341  _( "&About KiCad" ),
342  _( "Display KiCad About dialog" ),
343  KiBitmap( about_xpm ) );
344 
345  SetMenuBar( menuBar );
347 }
348 
349 
351 {
352  wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::SetMenuBarOptionsState" ) );
353 
354  wxMenuBar* menuBar = GetMenuBar();
355 
356  if( menuBar == NULL )
357  {
358  wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER::SetMenuBarOptionsState menuBar == NULL" ) );
359 
360  return;
361  }
362 
363  wxMenuItem* item;
364  // Set the state of toggle menus according to the current display options
365  item = menuBar->FindItem( ID_MENU3D_ENGINE_OPENGL_LEGACY );
367 
368  item = menuBar->FindItem( ID_MENU3D_ENGINE_RAYTRACING );
370 
371  item = menuBar->FindItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL );
372  item->Check( m_settings.MaterialModeGet() == MATERIAL_MODE_NORMAL );
373 
374  item = menuBar->FindItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_DIFFUSE_ONLY );
376 
377  item = menuBar->FindItem( ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE );
379 
380  // OpenGL
381  item = menuBar->FindItem( ID_MENU3D_FL_OPENGL_RENDER_COPPER_THICKNESS );
383 
384  item = menuBar->FindItem( ID_MENU3D_FL_OPENGL_RENDER_SHOW_MODEL_BBOX );
386 
387  // Raytracing
388  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_RENDER_SHADOWS );
390 
391  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_BACKFLOOR );
393 
394  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_REFRACTIONS );
396 
397  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_REFLECTIONS );
399 
400  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_POST_PROCESSING );
402 
403  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_ANTI_ALIASING );
405 
406  item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_PROCEDURAL_TEXTURES );
408 
409 
410  item = menuBar->FindItem( ID_MENU3D_AXIS_ONOFF );
411  item->Check( m_settings.GetFlag( FL_AXIS ) );
412 
413 }
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:94
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:223
#define HELP_ZOOM_FIT
void SetMenuBarOptionsState()
Set the state of toggle menus according to the current display options.
Definition: 3d_menubar.cpp:350
Definition: id.h:241
Handles data related with the board to be visualized.
#define HELP_ZOOM_OUT
#define HELP_ZOOM_REDRAW
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
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