1 /* 2 * This program source code file is part of KiCad, a free EDA CAD application. 3 * 4 * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> 5 * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr 6 * Copyright (C) 2011 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 /** 28 * @file eda_3d_viewer.h 29 * @brief Declaration of the eda_3d_viewer class 30 */ 31 32 #ifndef EDA_3D_VIEWER_H 33 #define EDA_3D_VIEWER_H 34 35 #include "3d_canvas/board_adapter.h" 36 #include "3d_canvas/eda_3d_canvas.h" 37 #include "3d_rendering/track_ball.h" 38 #include <kiway_player.h> 39 #include <wx/colourdata.h> 40 #include <dialogs/dialog_color_picker.h> // for CUSTOM_COLORS_LIST definition 41 42 43 /// A variable name whose value holds the path of 3D shape files. 44 /// Currently an environment variable, eventually a project variable. 45 #define KICAD6_3DMODEL_DIR wxT( "KICAD6_3DMODEL_DIR" ) 46 47 48 #define KICAD_DEFAULT_3D_DRAWFRAME_STYLE (wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS) 49 50 51 enum EDA_3D_VIEWER_STATUSBAR 52 { 53 ACTIVITY = 0, 54 HOVERED_ITEM, 55 X_POS, 56 Y_POS, 57 }; 58 59 /** 60 * Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard 61 */ 62 class EDA_3D_VIEWER_FRAME : public EDA_3D_BOARD_HOLDER, public KIWAY_PLAYER 63 { 64 public: 65 EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent, const wxString& aTitle, 66 long style = KICAD_DEFAULT_3D_DRAWFRAME_STYLE ); 67 68 ~EDA_3D_VIEWER_FRAME(); 69 Parent()70 PCB_BASE_FRAME* Parent() const { return (PCB_BASE_FRAME*)GetParent(); } 71 GetBoard()72 BOARD* GetBoard() { return Parent()->GetBoard(); } 73 GetToolCanvas()74 wxWindow* GetToolCanvas() const override { return m_canvas; } 75 76 void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override; 77 78 /** 79 * Request reloading the 3D view. 80 * 81 * However the request will be executed only when the 3D canvas is refreshed. It allows 82 * one to prepare changes and request for 3D rebuild only when all changes are committed. 83 * This is made because the 3D rebuild can take a long time, and this rebuild cannot 84 * always made after each change, for calculation time reason. 85 */ 86 void ReloadRequest(); 87 88 // !TODO: review this function: it need a way to tell what changed, 89 // to only reload/rebuild things that have really changed 90 /** 91 * Reload and refresh (rebuild) the 3D scene. 92 * 93 * @warning Rebuilding the 3D scene can take a bit of time, so rebuilding the scene can 94 * be immediate, or made later, during the next 3D canvas refresh (on zoom for 95 * instance). 96 * 97 * @param aForceImmediateRedraw true to immediately rebuild the 3D scene or false to wait 98 * refresh later. 99 */ 100 void NewDisplay( bool aForceImmediateRedraw = false ); 101 102 void Redraw(); 103 GetAdapter()104 BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; } GetCurrentCamera()105 CAMERA& GetCurrentCamera() override { return m_currentCamera; } 106 GetCanvas()107 EDA_3D_CANVAS* GetCanvas() { return m_canvas; } 108 109 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override; 110 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override; 111 112 /** 113 * Notification that common settings are updated. 114 * 115 * This would be private (and only called by the Kiway), but we need to do this manually 116 * from the PCB frame because the 3D viewer isn't updated via the #KIWAY. 117 */ 118 void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override; 119 120 protected: 121 void setupUIConditions() override; 122 123 private: 124 /// Called when user press the File->Exit 125 void Exit3DFrame( wxCommandEvent& event ); 126 127 void OnCloseWindow( wxCloseEvent& event ); 128 129 void Process_Special_Functions( wxCommandEvent& event ); 130 131 void OnRenderEngineSelection( wxCommandEvent& event ); 132 void OnDisableRayTracing( wxCommandEvent& aEvent ); 133 134 void OnActivate( wxActivateEvent& event ); 135 136 void OnSetFocus( wxFocusEvent& event ); 137 138 void Install3DViewOptionDialog( wxCommandEvent& event ); 139 140 void CreateMenuBar(); 141 void ReCreateMainToolbar(); 142 143 /** 144 * Create a Screenshot of the current 3D view. 145 * Output file format is png or jpeg, or image is copied to the clipboard 146 */ 147 void takeScreenshot( wxCommandEvent& event ); 148 149 /** 150 * @brief RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged 151 */ 152 void RenderEngineChanged(); 153 154 void refreshRender(); 155 156 DECLARE_EVENT_TABLE() 157 158 /** 159 * Load configuration from common settings. 160 */ 161 void loadCommonSettings(); 162 163 wxFileName m_defaultSaveScreenshotFileName; 164 165 ACTION_TOOLBAR* m_mainToolBar; 166 EDA_3D_CANVAS* m_canvas; 167 BOARD_ADAPTER m_boardAdapter; 168 CAMERA& m_currentCamera; 169 TRACK_BALL m_trackBallCamera; 170 171 bool m_disable_ray_tracing; 172 173 /** 174 * Trace mask used to enable or disable the trace output of this class. 175 * The debug output can be turned on by setting the WXTRACE environment variable to 176 * "KI_TRACE_EDA_3D_VIEWER". See the wxWidgets documentation on wxLogTrace for 177 * more information. 178 */ 179 static const wxChar *m_logTrace; 180 181 }; 182 183 #endif // EDA_3D_VIEWER_H 184