KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_3d_viewer_frame.h
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) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
6 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
7 * Copyright (C) 2023 CERN
8 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
28
29#ifndef EDA_3D_VIEWER_H
30#define EDA_3D_VIEWER_H
31
35#include <kiway_player.h>
36#include <wx/colourdata.h>
37#include <dialogs/dialog_color_picker.h> // for CUSTOM_COLORS_LIST definition
38
39
40#define KICAD_DEFAULT_3D_DRAWFRAME_STYLE (wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS)
41
42// Forward declarations
43#if defined(__linux__) || defined(__FreeBSD__)
45#else
47#endif
49
50
60
68
73{
74public:
75 EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent, const wxString& aTitle,
77
79
80 PCB_BASE_FRAME* Parent() const { return (PCB_BASE_FRAME*)GetParent(); }
81
82 BOARD* GetBoard() { return Parent()->GetBoard(); }
83
84 wxWindow* GetToolCanvas() const override { return m_canvas; }
85
94 void ReloadRequest();
95
98
99 // !TODO: review this function: it need a way to tell what changed,
100 // to only reload/rebuild things that have really changed
111 void NewDisplay( bool aForceImmediateRedraw = false );
112
113 void Redraw();
114
117
119
120 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
121 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
122
129 void CommonSettingsChanged( int aFlags ) override;
130 void ShowChangedLanguage() override;
131
133
135
136 void OnDarkModeToggle();
137
143
149 void ExportImage( EDA_3D_VIEWER_EXPORT_FORMAT aFormat, const wxSize& aSize );
150
151protected:
152 APP_SETTINGS_BASE* config() const override;
153
154 void setupUIConditions() override;
155
156 void handleIconizeEvent( wxIconizeEvent& aEvent ) override;
157
158private:
160 void Exit3DFrame( wxCommandEvent& event );
161
162 void OnCloseWindow( wxCloseEvent& event );
163
164 bool TryBefore( wxEvent& aEvent ) override;
165
166 void Process_Special_Functions( wxCommandEvent& event );
167
168 void onDisableRayTracing( wxCommandEvent& aEvent );
169
170 void OnActivate( wxActivateEvent& event );
171 void OnSetFocus( wxFocusEvent& event );
172
173 void doReCreateMenuBar() override;
174
178 void RenderEngineChanged();
179
180 void refreshRender();
181
182 DECLARE_EVENT_TABLE()
183
184
187 void loadCommonSettings();
188
189 void applySettings( EDA_3D_VIEWER_SETTINGS* aSettings );
190
198 bool getExportFileName( EDA_3D_VIEWER_EXPORT_FORMAT& aFormat, wxString& fullFileName );
199
205 wxImage captureScreenshot( const wxSize& aSize );
206
211 void setupRenderingConfig( BOARD_ADAPTER& adapter );
212
219
227 wxImage captureRaytracingScreenshot( BOARD_ADAPTER& adapter, TRACK_BALL& camera, const wxSize& aSize );
228
235 wxImage convertRGBAToImage( uint8_t* rgbaBuffer, const wxSize& realSize );
236
244 wxImage captureOpenGLScreenshot( BOARD_ADAPTER& adapter, TRACK_BALL& camera, const wxSize& aSize );
245
252
259 void saveOrCopyImage( const wxImage& screenshotImage, EDA_3D_VIEWER_EXPORT_FORMAT aFormat, const wxString& fullFileName );
260
265 void copyImageToClipboard( const wxImage& screenshotImage );
266
273 void saveImageToFile( const wxImage& screenshotImage, EDA_3D_VIEWER_EXPORT_FORMAT aFormat, const wxString& fullFileName );
274
275private:
277
283
285
286#if defined(__linux__) || defined(__FreeBSD__)
287 std::unique_ptr<SPNAV_VIEWER_PLUGIN> m_spaceMouse;
288#else
289 std::unique_ptr<NL_3D_VIEWER_PLUGIN> m_spaceMouse;
290#endif
291
298 static const wxChar *m_logTrace;
299
300};
301
302#endif // EDA_3D_VIEWER_H
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Helper class to handle information needed to display 3D board.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
A class used to derive camera objects from.
Definition camera.h:94
Implement a canvas based on a wxGLCanvas.
void saveOrCopyImage(const wxImage &screenshotImage, EDA_3D_VIEWER_EXPORT_FORMAT aFormat, const wxString &fullFileName)
Save image to file or copy to clipboard based on format.
wxWindow * GetToolCanvas() const override
Canvas access.
void OnSetFocus(wxFocusEvent &event)
void onDisableRayTracing(wxCommandEvent &aEvent)
void CommonSettingsChanged(int aFlags) override
Notification that common settings are updated.
void applySettings(EDA_3D_VIEWER_SETTINGS *aSettings)
PCB_BASE_FRAME * Parent() const
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
void configureCanvas(std::unique_ptr< EDA_3D_CANVAS > &canvas, EDA_3D_VIEWER_SETTINGS *cfg)
Configure canvas settings for screenshot capture.
wxImage captureOpenGLScreenshot(BOARD_ADAPTER &adapter, TRACK_BALL &camera, const wxSize &aSize)
Capture screenshot using OpenGL renderer.
bool getExportFileName(EDA_3D_VIEWER_EXPORT_FORMAT &aFormat, wxString &fullFileName)
Get export filename through file dialog.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void OnActivate(wxActivateEvent &event)
bool TryBefore(wxEvent &aEvent) override
void Exit3DFrame(wxCommandEvent &event)
Called when user press the File->Exit.
std::unique_ptr< NL_3D_VIEWER_PLUGIN > m_spaceMouse
void RenderEngineChanged()
RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged.
void Process_Special_Functions(wxCommandEvent &event)
wxImage captureCurrentViewScreenshot()
Capture screenshot of the current view using the configured renderer.
void OnCloseWindow(wxCloseEvent &event)
void doReCreateMenuBar() override
void ShowChangedLanguage() override
EDA_3D_VIEWER_FRAME(KIWAY *aKiway, PCB_BASE_FRAME *aParent, const wxString &aTitle, long style=KICAD_DEFAULT_3D_DRAWFRAME_STYLE)
wxImage captureScreenshot(const wxSize &aSize)
Capture screenshot using appropriate rendering method.
void setupRenderingConfig(BOARD_ADAPTER &adapter)
Setup rendering configuration for screenshot capture.
void ApplyProjectFileSettings()
Take the saved 3D viewports from the project file, as at startup and after it was reread.
void ReloadRequest()
Request reloading the 3D view.
wxFileName m_defaultSaveScreenshotFileName
wxImage convertRGBAToImage(uint8_t *rgbaBuffer, const wxSize &realSize)
Convert RGBA buffer to wxImage format.
APP_SETTINGS_BASE * config() const override
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
EDA_3D_CANVAS * GetCanvas()
BOARD_ADAPTER & GetAdapter()
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void saveImageToFile(const wxImage &screenshotImage, EDA_3D_VIEWER_EXPORT_FORMAT aFormat, const wxString &fullFileName)
Save image to file.
void copyImageToClipboard(const wxImage &screenshotImage)
Copy image to system clipboard.
void loadCommonSettings()
Load configuration from common settings.
APPEARANCE_CONTROLS_3D * GetAppearanceManager()
void ExportImage(EDA_3D_VIEWER_EXPORT_FORMAT aFormat, const wxSize &aSize)
Export 3D viewer image to file or clipboard.
wxImage captureRaytracingScreenshot(BOARD_ADAPTER &adapter, TRACK_BALL &camera, const wxSize &aSize)
Capture screenshot using raytracing renderer.
void TakeScreenshot(EDA_3D_VIEWER_EXPORT_FORMAT aFormat)
Create a Screenshot of the current 3D view.
void handleIconizeEvent(wxIconizeEvent &aEvent) override
Handle a window iconize event.
APPEARANCE_CONTROLS_3D * m_appearancePanel
Manage an 8-bit channel image.
Definition image.h:86
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
The class that implements the public interface to the SpaceMouse plug-in.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
STL class.
EDA_3D_VIEWER_EXPORT_FORMAT
#define KICAD_DEFAULT_3D_DRAWFRAME_STYLE
EDA_3D_VIEWER_STATUSBAR
@ ZOOM_LEVEL
@ HOVERED_ITEM
@ RENDER_TIME
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
STL namespace.
Declaration for a track ball camera.