KiCad PCB EDA Suite
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 (C) 1992-2021 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef EDA_3D_CANVAS_H
26#define EDA_3D_CANVAS_H
27
28#include <atomic>
29#include "board_adapter.h"
32#include "3d_cache/3d_cache.h"
34#include <wx/image.h>
35#include <wx/timer.h>
36
37
38class WX_INFOBAR;
39class wxStatusBar;
40class BOARD;
43
44
49{
50public:
59 EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList,
60 BOARD_ADAPTER& aSettings, CAMERA& aCamera, S3D_CACHE* a3DCachePointer );
61
63
72 void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
73
74 void SetStatusBar( wxStatusBar* aStatusBar )
75 {
76 m_parentStatusBar = aStatusBar;
77 }
78
79 void SetInfoBar( WX_INFOBAR* aInfoBar )
80 {
81 m_parentInfoBar = aInfoBar;
82 }
83
84 void ReloadRequest( BOARD* aBoard = nullptr, S3D_CACHE* aCachePointer = nullptr );
85
92 {
93 if( m_3d_render )
95 else
96 return false;
97 }
98
103
108
114 void GetScreenshot( wxImage& aDstImage );
115
122 bool SetView3D( int aKeycode );
123
127 void SetAnimationEnabled( bool aEnable ) { m_animation_enabled = aEnable; }
129
135 void SetMovingSpeedMultiplier( int aMultiplier ) { m_moving_speed_multiplier = aMultiplier; }
137
138 int GetProjectionMode() const { return (int) m_camera.GetProjection(); };
139 void SetProjectionMode( int aMode ) { m_camera.SetProjection( (PROJECTION_TYPE) aMode ); }
140
144 void RenderEngineChanged();
145
149 void DisplayStatus();
150
157 void Request_refresh( bool aRedrawImmediately = true );
158
162 void OnEvent( wxEvent& aEvent );
163
168
173
179 void SetRenderPivot( bool aValue ) { m_render_pivot = aValue; }
180
181
182#if defined( KICAD_USE_3DCONNEXION )
186 bool GetRender3dmousePivot()
187 {
188 return m_render3dmousePivot;
189 }
190
191
197 void SetRender3dmousePivot( bool aValue )
198 {
199 m_render3dmousePivot = aValue;
200 }
201
202
208 void Set3dmousePivotPos( const SFVEC3F& aPos )
209 {
210 m_3dmousePivotPos = aPos;
211 }
212#endif
213
214private:
218 void OnPaint( wxPaintEvent& aEvent );
219
226 void DoRePaint();
227
228 void OnEraseBackground( wxEraseEvent& event );
229
230 void OnRefreshRequest( wxEvent& aEvent );
231
232 void OnMouseWheel( wxMouseEvent& event );
233
234#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
235 void OnMagnify( wxMouseEvent& event );
236#endif
237
238 void OnMouseMove( wxMouseEvent& event );
239 void OnLeftDown( wxMouseEvent& event );
240 void OnLeftUp( wxMouseEvent& event );
241 void OnMiddleUp( wxMouseEvent& event );
242 void OnMiddleDown( wxMouseEvent& event );
243 void OnTimerTimeout_Editing( wxTimerEvent& event );
244 void OnCloseWindow( wxCloseEvent& event );
245 void OnResize( wxSizeEvent& event );
246 void OnTimerTimeout_Redraw( wxTimerEvent& event );
247
248 DECLARE_EVENT_TABLE()
249
250
254
259
266 void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true );
267
272
279 void render_pivot( float t, float aScale );
280
281#if defined( KICAD_USE_3DCONNEXION )
287 void render3dmousePivot( float aScale );
288#endif
289
293 bool initializeOpenGL();
294
298 void releaseOpenGL();
299
301
302private:
304 wxStatusBar* m_parentStatusBar; // Parent statusbar to report progress
306
307 wxGLContext* m_glRC; // Current OpenGL context
310
311 wxTimer m_editing_timeout_timer; // Expires after some time signaling that
312 // the mouse / keyboard movements are over
313 wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
314 std::atomic_flag m_is_currently_painting; // Avoid drawing twice at the same time
315
316 bool m_render_pivot; // Render the pivot while camera moving
317 float m_camera_moving_speed; // 1.0f will be 1:1
318 unsigned m_strtime_camera_movement; // Ticktime of camera movement start
319 bool m_animation_enabled; // Camera animation enabled
320 int m_moving_speed_multiplier; // Camera animation speed multiplier option
321
322 BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
326
329
330 ACCELERATOR_3D* m_accelerator3DShapes; // used for mouse over searching
331
333
334#if defined( KICAD_USE_3DCONNEXION )
335 bool m_render3dmousePivot = false; // Render the 3dmouse pivot
336 SFVEC3F m_3dmousePivotPos; // The position of the 3dmouse pivot
337#endif
338
345 static const wxChar* m_logTrace;
346};
347
348
349#endif // EDA_3D_CANVAS_H
PROJECTION_TYPE
Definition: camera.h:38
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:69
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
A class used to derive camera objects from.
Definition: camera.h:78
void SetProjection(PROJECTION_TYPE aProjection)
Definition: camera.h:180
PROJECTION_TYPE GetProjection()
Definition: camera.h:179
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:49
int GetMovingSpeedMultiplier() const
RENDER_3D_OPENGL * m_3d_render_opengl
TOOL_DISPATCHER * m_eventDispatcher
void SetProjectionMode(int aMode)
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
unsigned m_strtime_camera_movement
RENDER_3D_RAYTRACE * m_3d_render_raytracing
void SetInfoBar(WX_INFOBAR *aInfoBar)
Definition: eda_3d_canvas.h:79
void restart_editingTimeOut_Timer()
Reset the editing timer.
BOARD_ITEM * m_currentRollOverItem
RENDER_3D_BASE * m_3d_render
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)
void OnMouseWheel(wxMouseEvent &event)
WX_INFOBAR * m_parentInfoBar
wxTimer m_editing_timeout_timer
RENDER_3D_BASE * GetCurrentRender() const
void OnLeftDown(wxMouseEvent &event)
int GetProjectionMode() const
wxGLContext * m_glRC
bool initializeOpenGL()
ACCELERATOR_3D * m_accelerator3DShapes
void OnTimerTimeout_Redraw(wxTimerEvent &event)
wxStatusBar * m_parentStatusBar
void DoRePaint()
The actual function to repaint the canvas.
int m_moving_speed_multiplier
bool SetView3D(int aKeycode)
Helper function to call view commands.
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 OnPaint(wxPaintEvent &aEvent)
Called by a wxPaintEvent event.
void SetStatusBar(wxStatusBar *aStatusBar)
Definition: eda_3d_canvas.h:74
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 m_animation_enabled
bool IsReloadRequestPending() const
Query if there is a pending reload request.
Definition: eda_3d_canvas.h:91
void OnLeftUp(wxMouseEvent &event)
bool GetAnimationEnabled() const
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
RAY getRayAtCurrentMousePosition()
void OnCloseWindow(wxCloseEvent &event)
EDA_3D_CANVAS(wxWindow *aParent, const int *aAttribList, BOARD_ADAPTER &aSettings, CAMERA &aCamera, S3D_CACHE *a3DCachePointer)
Create a new 3D Canvas with an attribute list.
void OnMiddleDown(wxMouseEvent &event)
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
void SetMovingSpeedMultiplier(int aMultiplier)
Set the camera animation moving speed multiplier option.
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::atomic_flag m_is_currently_painting
void OnRefreshRequest(wxEvent &aEvent)
void OnEraseBackground(wxEraseEvent &event)
void releaseOpenGL()
Free created targets and openGL context.
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.
void OnMouseMove(wxMouseEvent &event)
void SetRenderPivot(bool aValue)
Set aValue indicating whether to render the pivot.
void move_pivot_based_on_cur_mouse_position()
This function hits a ray to the board and start a movement.
void OnTimerTimeout_Editing(wxTimerEvent &event)
void stop_editingTimeOut_Timer()
Stop the editing time so it will not timeout.
Provides basic 3D controls ( zoom, rotate, translate, ... )
This is a base class to hold data and functions for render targets.
bool IsReloadRequestPending() const
Query if there is a pending reload request.
Object to render the board using openGL.
Cache for storing the 3D shapes.
Definition: 3d_cache.h:53
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:75
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Definition: ray.h:63
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44