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-2020 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>
33 #include <tool/tool_manager.h>
34 #include <tool/common_control.h>
35 #include <widgets/wx_menubar.h>
36 
37 
39 {
40  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::CreateMenuBar" );
41 
43  WX_MENUBAR* menuBar = new WX_MENUBAR();
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 
79 
80  viewMenu->AddSeparator();
83 
84  viewMenu->AddSeparator();
87 
88  viewMenu->AddSeparator();
91 
92  viewMenu->AddSeparator();
97 
98  viewMenu->Resolve();
99 
100  //-- Preferences menu -----------------------------------------------
101  //
102  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, tool );
103 
104  //clang-format off
105  auto raytracingCondition = [this]( const SELECTION& aSel )
106  {
108  };
109 
110  auto NormalModeCondition = [this]( const SELECTION& aSel )
111  {
113  };
114 
115  auto DiffuseModeCondition = [this]( const SELECTION& aSel )
116  {
118  };
119 
120  auto CADModeCondition = [this]( const SELECTION& aSel )
121  {
123  };
124 
125  auto boundingBoxesCondition = [this]( const SELECTION& aSel )
126  {
128  };
129 
130  auto renderShadowsCondition = [this]( const SELECTION& aSel )
131  {
133  };
134 
135  auto proceduralTexturesCondition = [this]( const SELECTION& aSel )
136  {
138  };
139 
140  auto showFloorCondition = [this]( const SELECTION& aSel )
141  {
143  };
144 
145  auto useRefractionsCondition = [this]( const SELECTION& aSel )
146  {
148  };
149 
150  auto useReflectionsCondition = [this]( const SELECTION& aSel )
151  {
153  };
154 
155  auto antiAliasingCondition = [this]( const SELECTION& aSel )
156  {
158  };
159 
160  auto postProcessCondition = [this]( const SELECTION& aSel )
161  {
163  };
164 
165  auto showAxesCondition = [this]( const SELECTION& aSel )
166  {
167  return m_boardAdapter.GetFlag( FL_AXIS );
168  };
169  //clang-format on
170 
171  prefsMenu->AddItem( ID_TOOL_SET_VISIBLE_ITEMS, _( "Display Options" ), "",
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 
204  optsSubmenu->AddCheckItem( EDA_3D_ACTIONS::showBoundingBoxes, boundingBoxesCondition );
205 
206  // Raytracing submenu
207  CONDITIONAL_MENU* raySubmenu = new CONDITIONAL_MENU( false, tool );
208  raySubmenu->SetTitle( _( "Raytracing Options" ) );
209  raySubmenu->SetIcon( tools_xpm );
210 
211  raySubmenu->AddCheckItem( EDA_3D_ACTIONS::renderShadows, renderShadowsCondition );
212  raySubmenu->AddCheckItem( EDA_3D_ACTIONS::proceduralTextures, proceduralTexturesCondition );
213  raySubmenu->AddCheckItem( EDA_3D_ACTIONS::addFloor, showFloorCondition );
214  raySubmenu->AddCheckItem( EDA_3D_ACTIONS::showRefractions, useRefractionsCondition );
215  raySubmenu->AddCheckItem( EDA_3D_ACTIONS::showReflections, useReflectionsCondition );
216  raySubmenu->AddCheckItem( EDA_3D_ACTIONS::antiAliasing, antiAliasingCondition );
217 
218  raySubmenu->AddCheckItem( EDA_3D_ACTIONS::postProcessing, postProcessCondition );
219 
220  optsSubmenu->AddMenu( raySubmenu, SELECTION_CONDITIONS::ShowAlways );
221  prefsMenu->AddMenu( optsSubmenu, SELECTION_CONDITIONS::ShowAlways );
222 
223  prefsMenu->AddSeparator();
224 
225  // Color submenu
226  CONDITIONAL_MENU* colorSubmenu = new CONDITIONAL_MENU( false, tool );
227  colorSubmenu->SetTitle( _( "Choose Colors" ) );
228  colorSubmenu->SetIcon( palette_xpm );
229 
230  colorSubmenu->AddItem( ID_MENU3D_BGCOLOR_TOP, _( "Background Top Color..." ), "",
232 
233  colorSubmenu->AddItem( ID_MENU3D_BGCOLOR_BOTTOM, _( "Background Bottom Color..." ), "",
235 
236  colorSubmenu->AddItem( ID_MENU3D_SILKSCREEN_COLOR, _( "Silkscreen Color..." ), "",
238 
239  colorSubmenu->AddItem( ID_MENU3D_SOLDERMASK_COLOR, _( "Solder Mask Color..." ), "",
241 
242  colorSubmenu->AddItem( ID_MENU3D_SOLDERPASTE_COLOR, _( "Solder Paste Color..." ), "",
244 
245  colorSubmenu->AddItem( ID_MENU3D_COPPER_COLOR, _( "Copper/Surface Finish Color..." ), "",
247 
248  colorSubmenu->AddItem( ID_MENU3D_PCB_BODY_COLOR, _( "Board Body Color..." ), "",
250 
251  // Only allow the stackup to be used in the PCB editor, since it isn't editable in the other frames
252  if( Parent()->IsType( FRAME_PCB_EDITOR ) )
253  {
254  colorSubmenu->AddItem( ID_MENU3D_STACKUP_COLORS, _( "Get colors from physical stackup" ), "",
256  }
257 
258  prefsMenu->AddMenu( colorSubmenu );
259 
260  prefsMenu->AddCheckItem( EDA_3D_ACTIONS::showAxis, showAxesCondition );
261 
262  // Grid submenu
263  CONDITIONAL_MENU* gridSubmenu = new CONDITIONAL_MENU( false, tool );
264  gridSubmenu->SetTitle( _( "3D Grid" ) );
265  gridSubmenu->SetIcon( grid_xpm );
266 
267  //clang-format off
268  auto noGridCondition = [this]( const SELECTION& aSel )
269  {
271  };
272 
273  auto grid10mmCondition = [this]( const SELECTION& aSel )
274  {
276  };
277 
278  auto grid5mmCondition = [this]( const SELECTION& aSel )
279  {
281  };
282 
283  auto grid2p5mmCondition = [this]( const SELECTION& aSel )
284  {
286  };
287 
288  auto grid_1mmCondition = [this]( const SELECTION& aSel )
289  {
291  };
292  //clang-format on
293 
294  gridSubmenu->AddCheckItem( EDA_3D_ACTIONS::noGrid, noGridCondition );
295  gridSubmenu->AddCheckItem( EDA_3D_ACTIONS::show10mmGrid, grid10mmCondition );
296  gridSubmenu->AddCheckItem( EDA_3D_ACTIONS::show5mmGrid, grid5mmCondition );
297  gridSubmenu->AddCheckItem( EDA_3D_ACTIONS::show2_5mmGrid, grid2p5mmCondition );
298  gridSubmenu->AddCheckItem( EDA_3D_ACTIONS::show1mmGrid, grid_1mmCondition );
299 
300  prefsMenu->AddMenu( gridSubmenu, SELECTION_CONDITIONS::ShowAlways );
301 
302  prefsMenu->AddSeparator();
303  prefsMenu->AddItem( ID_MENU3D_RESET_DEFAULTS, _( "Reset to Default Settings" ), "",
305 
306 #ifdef __APPLE__ // Note: will get moved to Apple menu by wxWidgets
307  prefsMenu->AddItem( wxID_PREFERENCES,
308  _( "Preferences...\tCTRL+," ),
309  _( "Show preferences for all open tools" ),
311 #endif
312 
313  prefsMenu->Resolve();
314 
315  //-- Menubar -------------------------------------------------------------
316  //
317  menuBar->Append( fileMenu, _( "&File" ) );
318  menuBar->Append( editMenu, _( "&Edit" ) );
319  menuBar->Append( viewMenu, _( "&View" ) );
320  menuBar->Append( prefsMenu, _( "&Preferences" ) );
321  AddStandardHelpMenu( menuBar );
322 
323  SetMenuBar( menuBar );
324 }
static TOOL_ACTION rotateXCW
Definition: 3d_actions.h:47
Use a gray shading based on diffuse material.
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
const BITMAP_OPAQUE options_3drender_xpm[1]
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
const BITMAP_OPAQUE setcolor_soldermask_xpm[1]
const BITMAP_OPAQUE setcolor_solderpaste_xpm[1]
static TOOL_ACTION show10mmGrid
Definition: 3d_actions.h:70
static TOOL_ACTION showBoundingBoxes
Definition: 3d_actions.h:79
const BITMAP_OPAQUE palette_xpm[1]
Definition: palette.cpp:89
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
static TOOL_ACTION showRefractions
Definition: 3d_actions.h:83
const BITMAP_OPAQUE setcolor_board_body_xpm[1]
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:45
Use only diffuse material properties.
ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE
static TOOL_ACTION antiAliasing
Definition: 3d_actions.h:85
BOARD_ADAPTER m_boardAdapter
const BITMAP_OPAQUE setcolor_copper_xpm[1]
const BITMAP_OPAQUE read_setup_xpm[1]
Definition: read_setup.cpp:99
static TOOL_ACTION moveLeft
Definition: 3d_actions.h:53
static TOOL_ACTION show5mmGrid
Definition: 3d_actions.h:71
Use all material properties from model file.
static TOOL_ACTION rotateYCW
Definition: 3d_actions.h:49
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
const BITMAP_OPAQUE grid_xpm[1]
Definition: grid.cpp:21
const BITMAP_OPAQUE export_xpm[1]
Definition: export.cpp:75
static TOOL_ACTION rotateXCCW
Definition: 3d_actions.h:48
RENDER_ENGINE RenderEngineGet() const noexcept
RenderEngineGet.
const BITMAP_OPAQUE setcolor_silkscreen_xpm[1]
const BITMAP_OPAQUE copy_xpm[1]
Definition: copy.cpp:67
static TOOL_ACTION rotateZCCW
Definition: 3d_actions.h:52
static TOOL_ACTION addFloor
Definition: 3d_actions.h:82
static TOOL_ACTION showAxis
Definition: 3d_actions.h:89
COMMON_CONTROL.
static TOOL_ACTION rotateZCW
Definition: 3d_actions.h:51
void Resolve()
Function Resolve()
const BITMAP_OPAQUE tools_xpm[1]
Definition: tools.cpp:113
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION moveDown
Definition: 3d_actions.h:56
void AddClose(wxString aAppname="")
Function AddClose()
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
static TOOL_ACTION proceduralTextures
Definition: 3d_actions.h:81
const BITMAP_OPAQUE setcolor_3d_bg_xpm[1]
static TOOL_ACTION show2_5mmGrid
Definition: 3d_actions.h:72
static TOOL_ACTION show1mmGrid
Definition: 3d_actions.h:73
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
Declaration of the eda_3d_viewer class.
bool IsType(FRAME_T aType) const
static TOOL_ACTION rotateYCCW
Definition: 3d_actions.h:50
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
static TOOL_ACTION postProcessing
Definition: 3d_actions.h:86
PCB_BASE_FRAME * Parent() const
Definition: eda_3d_viewer.h:76
void CreateMenuBar()
Definition: 3d_menubar.cpp:38
static TOOL_ACTION moveUp
Definition: 3d_actions.h:55
static TOOL_ACTION noGrid
Definition: 3d_actions.h:69
static TOOL_ACTION zoomIn
Definition: actions.h:88
static TOOL_ACTION zoomOut
Definition: actions.h:89
static TOOL_ACTION showReflections
Definition: 3d_actions.h:84
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:66
GRID3D_TYPE GridGet() const noexcept
GridGet - get the current grid.
MATERIAL_MODE MaterialModeGet() const noexcept
MaterialModeGet.
static TOOL_ACTION renderShadows
Definition: 3d_actions.h:80
static TOOL_ACTION moveRight
Definition: 3d_actions.h:54
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
const BITMAP_OPAQUE color_materials_xpm[1]