KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_3d_canvas.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 The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef EDA_3D_CANVAS_H
22#define EDA_3D_CANVAS_H
23
24#include <atomic>
25#include "board_adapter.h"
28#include "3d_cache/3d_cache.h"
30#include <wx/image.h>
31#include <wx/timer.h>
32#include <memory>
33#include <stop_token>
34
35
36class WX_INFOBAR;
37class wxStatusBar;
40class SYNC_REPORTER;
41class BOARD;
44
45
46// A custom event, used to call DoRePaint during an idle time
47wxDECLARE_EVENT( wxEVT_REFRESH_CUSTOM_COMMAND, wxCommandEvent );
48
49
50#define EDA_3D_CANVAS_ID (wxID_HIGHEST + 1321)
51
56{
57public:
66 EDA_3D_CANVAS( wxWindow* aParent, const wxGLAttributes& aGLAttribs, BOARD_ADAPTER& aSettings,
67 CAMERA& aCamera, S3D_CACHE* a3DCachePointer );
68
69 ~EDA_3D_CANVAS() override;
70
79 void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
80
81 void SetStatusBar( wxStatusBar* aStatusBar )
82 {
83 m_parentStatusBar = aStatusBar;
84 }
85
86 void SetInfoBar( WX_INFOBAR* aInfoBar )
87 {
88 m_parentInfoBar = aInfoBar;
89 }
90
91 void ReloadRequest( BOARD* aBoard = nullptr, S3D_CACHE* aCachePointer = nullptr );
92
98 void ReloadRaytracingForHitTesting( std::stop_token aStop );
99
104
111 {
112 if( m_3d_render )
113 return m_3d_render->IsReloadRequestPending();
114 else
115 return false;
116 }
117
122
127
133 void GetScreenshot( wxImage& aDstImage );
134
138 void JoinBgWorker();
139
146 bool SetView3D( VIEW3D_TYPE aRequestedView );
147
151 void SetAnimationEnabled( bool aEnable ) { m_animation_enabled = aEnable; }
153
159 void SetMovingSpeedMultiplier( int aMultiplier ) { m_moving_speed_multiplier = aMultiplier; }
161
162 int GetProjectionMode() const { return (int) m_camera.GetProjection(); };
163 void SetProjectionMode( int aMode ) { m_camera.SetProjection( (PROJECTION_TYPE) aMode ); }
164
168 void RenderEngineChanged();
169
173 void DisplayStatus();
174
181 void Request_refresh( bool aRedrawImmediately = true );
182
186 void OnEvent( wxEvent& aEvent );
187
192
197
203 void SetRenderPivot( bool aValue ) { m_render_pivot = aValue; }
204
209 {
211 }
212
213
219 void SetRender3dmousePivot( bool aValue )
220 {
221 m_render3dmousePivot = aValue;
222 }
223
224
230 void Set3dmousePivotPos( const SFVEC3F& aPos )
231 {
232 m_3dmousePivotPos = aPos;
233 }
234
241 void DoRePaint();
242
243 void RenderToFrameBuffer( unsigned char* aBuffer, int aWidth, int aHeight );
244
245 void OnCloseWindow( wxCloseEvent& event );
246
247private:
248 // The wxPaintEvent event. mainly calls DoRePaint()
249 void OnPaint( wxPaintEvent& aEvent );
250
251 void OnEraseBackground( wxEraseEvent& event );
252
253 void OnRefreshRequest( wxEvent& aEvent );
254
255 void OnMouseWheel( wxMouseEvent& event );
256
257 void OnMagnify( wxMouseEvent& event );
258 void OnMouseMove( wxMouseEvent& event );
259 void OnLeftDown( wxMouseEvent& event );
260 void OnLeftUp( wxMouseEvent& event );
261 void OnMiddleUp( wxMouseEvent& event );
262 void OnMiddleDown( wxMouseEvent& event );
263 void OnRightUp( wxMouseEvent& event );
264 void OnRightDown( wxMouseEvent& event );
265
266 void OnTimerTimeout_Editing( wxTimerEvent& event );
267 void OnResize( wxSizeEvent& event );
268 void OnTimerTimeout_Redraw( wxTimerEvent& event );
269
270 void OnZoomGesture( wxZoomGestureEvent& event );
271 void OnPanGesture( wxPanGestureEvent& event );
272 void OnRotateGesture( wxRotateGestureEvent& event );
273
274 DECLARE_EVENT_TABLE()
275
276
280
285
292 void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true );
293
298
305 void render_pivot( float t, float aScale );
306
312 void render3dmousePivot( float aScale );
313
317 bool initializeOpenGL();
318
322 void releaseOpenGL();
323
325
326private:
328 wxStatusBar* m_parentStatusBar = nullptr; // Parent statusbar to report progress
330
333
336
337 wxGLContext* m_glRC = nullptr; // Current OpenGL context
340
341 wxTimer m_editing_timeout_timer; // Expires after some time signaling that
342 // the mouse / keyboard movements are over
343 wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
344 std::atomic_flag m_is_currently_painting = ATOMIC_FLAG_INIT; // Avoid drawing twice at the same time
345
346 bool m_render_pivot = false; // Render the pivot while camera moving
347 float m_camera_moving_speed = 1.0f; // 1.0f will be 1:1
348 int64_t m_strtime_camera_movement = 0; // Ticktime of camera movement start
349 bool m_animation_enabled = true; // Camera animation enabled
350 int m_moving_speed_multiplier = 3; // Camera animation speed multiplier option
351
352 BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
353
358
361
362 ACCELERATOR_3D* m_accelerator3DShapes = nullptr; // used for mouse over searching
363
365
366 bool m_render3dmousePivot = false; // Render the 3dmouse pivot
367 SFVEC3F m_3dmousePivotPos; // The position of the 3dmouse pivot
368
371 double m_gestureLastAngle = 0.0;
372
379 static const wxChar* m_logTrace;
380};
381
382
383#endif // EDA_3D_CANVAS_H
VIEW3D_TYPE
Definition 3d_enums.h:74
PROJECTION_TYPE
Definition camera.h:36
Helper class to handle information needed to display 3D board.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
A class used to derive camera objects from.
Definition camera.h:99
int GetMovingSpeedMultiplier() const
TOOL_DISPATCHER * m_eventDispatcher
void SetProjectionMode(int aMode)
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
void OnMagnify(wxMouseEvent &event)
void SetInfoBar(WX_INFOBAR *aInfoBar)
void restart_editingTimeOut_Timer()
Reset the editing timer.
void RenderToFrameBuffer(unsigned char *aBuffer, int aWidth, int aHeight)
void Set3dmousePivotPos(const SFVEC3F &aPos)
Set the position of the the 3dmouse pivot.
BOARD_ITEM * m_currentRollOverItem
RENDER_3D_BASE * m_3d_render
Non-owning pointer to the active renderer (one of the two below).
void SetAnimationEnabled(bool aEnable)
Enable or disable camera animation when switching to a pre-defined view.
bool m_is_opengl_initialized
void OnResize(wxSizeEvent &event)
bool m_render3dmousePivot
void OnMouseWheel(wxMouseEvent &event)
WX_INFOBAR * m_parentInfoBar
wxTimer m_editing_timeout_timer
int64_t m_strtime_camera_movement
RENDER_3D_BASE * GetCurrentRender() const
void OnLeftDown(wxMouseEvent &event)
int GetProjectionMode() const
void OnPanGesture(wxPanGestureEvent &event)
void OnRightUp(wxMouseEvent &event)
wxGLContext * m_glRC
ACCELERATOR_3D * m_accelerator3DShapes
void OnTimerTimeout_Redraw(wxTimerEvent &event)
wxStatusBar * m_parentStatusBar
void DoRePaint()
The actual function to repaint the canvas.
std::shared_ptr< SYNC_REPORTER > m_warningReporterSync
void OnRightDown(wxMouseEvent &event)
void InvalidateRaytracingHitTesting()
Invalidate the hover hit-test BVH before board layers are rebuilt.
int m_moving_speed_multiplier
void JoinBgWorker()
Block until any in-progress OpenGL background loading has finished.
SFVEC3F m_3dmousePivotPos
bool m_is_opengl_version_supported
wxTimer m_redraw_trigger_timer
BOARD_ADAPTER & m_boardAdapter
void DisplayStatus()
Update the status bar with the position information.
void render3dmousePivot(float aScale)
Render the 3dmouse pivot cursor.
void OnPaint(wxPaintEvent &aEvent)
void SetStatusBar(wxStatusBar *aStatusBar)
void RenderRaytracingRequest()
Request to render the current view in Raytracing mode.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
bool GetRenderPivot()
Get a value indicating whether to render the pivot.
bool m_render_raytracing_was_requested
float m_camera_moving_speed
bool IsReloadRequestPending() const
Query if there is a pending reload request.
bool GetRender3dmousePivot()
Get a value indicating whether to render the 3dmouse pivot.
void ReloadRaytracingForHitTesting(std::stop_token aStop)
Rebuild the auxiliary raytracing BVH used for hover hit-testing in OpenGL mode.
void OnLeftUp(wxMouseEvent &event)
bool GetAnimationEnabled() const
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
RAY getRayAtCurrentMousePosition()
double m_gestureLastZoomFactor
Used to track gesture events.
void OnCloseWindow(wxCloseEvent &event)
bool SetView3D(VIEW3D_TYPE aRequestedView)
Select a specific 3D view or operation.
void OnMiddleDown(wxMouseEvent &event)
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
std::unique_ptr< INFOBAR_REPORTER > m_infoBarReporter
void OnZoomGesture(wxZoomGestureEvent &event)
std::unique_ptr< STATUSBAR_REPORTER > m_statusBarReporter
void SetMovingSpeedMultiplier(int aMultiplier)
Set the camera animation moving speed multiplier option.
std::unique_ptr< RENDER_3D_OPENGL > m_3d_render_opengl
void OnMiddleUp(wxMouseEvent &event)
void render_pivot(float t, float aScale)
Render the pivot cursor.
void request_start_moving_camera(float aMovingSpeed=2.0f, bool aRenderPivot=true)
Start a camera movement.
void RenderEngineChanged()
Notify that the render engine was changed.
std::shared_ptr< SYNC_REPORTER > m_activityReporterSync
std::atomic_flag m_is_currently_painting
void SetRender3dmousePivot(bool aValue)
Set aValue indicating whether to render the 3dmouse pivot.
void OnRefreshRequest(wxEvent &aEvent)
void OnEraseBackground(wxEraseEvent &event)
void releaseOpenGL()
Free created targets and openGL context.
std::unique_ptr< RENDER_3D_RAYTRACE_GL > m_3d_render_raytracing
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
bool m_opengl_supports_raytracing
const BOARD_ADAPTER & GetBoardAdapter() const
Get information used to display 3D board.
~EDA_3D_CANVAS() override
void OnMouseMove(wxMouseEvent &event)
void SetRenderPivot(bool aValue)
Set aValue indicating whether to render the pivot.
void OnRotateGesture(wxRotateGestureEvent &event)
EDA_3D_CANVAS(wxWindow *aParent, const wxGLAttributes &aGLAttribs, BOARD_ADAPTER &aSettings, CAMERA &aCamera, S3D_CACHE *a3DCachePointer)
Create a new 3D Canvas with an attribute list.
void move_pivot_based_on_cur_mouse_position()
This function hits a ray to the board and start a movement.
double m_gestureLastAngle
void OnTimerTimeout_Editing(wxTimerEvent &event)
void stop_editingTimeOut_Timer()
Stop the editing time so it will not timeout.
HIDPI_GL_3D_CANVAS(const KIGFX::VC_SETTINGS &aVcSettings, CAMERA &aCamera, wxWindow *parent, const wxGLAttributes &aGLAttribs, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxGLCanvasName, const wxPalette &palette=wxNullPalette)
A wrapper for reporting to a WX_INFOBAR UI element.
Definition wx_infobar.h:324
This is a base class to hold data and functions for render targets.
Object to render the board using openGL.
Cache for storing the 3D shapes.
Definition 3d_cache.h:53
A wrapper for reporting to a specific text location in a statusbar.
Definition reporter.h:410
A thread-safe REPORTER wrapper that serializes forwarding to an underlying reporter.
Definition reporter.h:184
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:76
STL class.
wxDECLARE_EVENT(wxEVT_REFRESH_CUSTOM_COMMAND, wxCommandEvent)
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
STL namespace.
Definition ray.h:59
glm::vec3 SFVEC3F
Definition xv3d_types.h:40