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
33
34class WX_INFOBAR;
35class wxStatusBar;
36class BOARD;
39
40
41#define EDA_3D_CANVAS_ID (wxID_HIGHEST + 1321)
42
47{
48public:
57 EDA_3D_CANVAS( wxWindow* aParent, const wxGLAttributes& aGLAttribs, BOARD_ADAPTER& aSettings,
58 CAMERA& aCamera, S3D_CACHE* a3DCachePointer );
59
60 ~EDA_3D_CANVAS() override;
61
70 void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
71
72 void SetStatusBar( wxStatusBar* aStatusBar )
73 {
74 m_parentStatusBar = aStatusBar;
75 }
76
77 void SetInfoBar( WX_INFOBAR* aInfoBar )
78 {
79 m_parentInfoBar = aInfoBar;
80 }
81
82 void ReloadRequest( BOARD* aBoard = nullptr, S3D_CACHE* aCachePointer = nullptr );
83
90 {
91 if( m_3d_render )
92 return m_3d_render->IsReloadRequestPending();
93 else
94 return false;
95 }
96
101
106
112 void GetScreenshot( wxImage& aDstImage );
113
120 bool SetView3D( VIEW3D_TYPE aRequestedView );
121
125 void SetAnimationEnabled( bool aEnable ) { m_animation_enabled = aEnable; }
127
133 void SetMovingSpeedMultiplier( int aMultiplier ) { m_moving_speed_multiplier = aMultiplier; }
135
136 int GetProjectionMode() const { return (int) m_camera.GetProjection(); };
137 void SetProjectionMode( int aMode ) { m_camera.SetProjection( (PROJECTION_TYPE) aMode ); }
138
142 void RenderEngineChanged();
143
147 void DisplayStatus();
148
155 void Request_refresh( bool aRedrawImmediately = true );
156
160 void OnEvent( wxEvent& aEvent );
161
166
171
177 void SetRenderPivot( bool aValue ) { m_render_pivot = aValue; }
178
183 {
185 }
186
187
193 void SetRender3dmousePivot( bool aValue )
194 {
195 m_render3dmousePivot = aValue;
196 }
197
198
204 void Set3dmousePivotPos( const SFVEC3F& aPos )
205 {
206 m_3dmousePivotPos = aPos;
207 }
208
215 void DoRePaint();
216
217 void RenderToFrameBuffer( unsigned char* aBuffer, int aWidth, int aHeight );
218
219 void OnCloseWindow( wxCloseEvent& event );
220
221private:
222 // The wxPaintEvent event. mainly calls DoRePaint()
223 void OnPaint( wxPaintEvent& aEvent );
224
225 void OnEraseBackground( wxEraseEvent& event );
226
227 void OnRefreshRequest( wxEvent& aEvent );
228
229 void OnMouseWheel( wxMouseEvent& event );
230
231 void OnMagnify( wxMouseEvent& event );
232 void OnMouseMove( wxMouseEvent& event );
233 void OnLeftDown( wxMouseEvent& event );
234 void OnLeftUp( wxMouseEvent& event );
235 void OnMiddleUp( wxMouseEvent& event );
236 void OnMiddleDown( wxMouseEvent& event );
237 void OnRightUp( wxMouseEvent& event );
238 void OnRightDown( wxMouseEvent& event );
239
240 void OnTimerTimeout_Editing( wxTimerEvent& event );
241 void OnResize( wxSizeEvent& event );
242 void OnTimerTimeout_Redraw( wxTimerEvent& event );
243
244 void OnZoomGesture( wxZoomGestureEvent& event );
245 void OnPanGesture( wxPanGestureEvent& event );
246 void OnRotateGesture( wxRotateGestureEvent& 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
286 void render3dmousePivot( float aScale );
287
291 bool initializeOpenGL();
292
296 void releaseOpenGL();
297
299
300private:
302 wxStatusBar* m_parentStatusBar = nullptr; // Parent statusbar to report progress
304
305 wxGLContext* m_glRC = nullptr; // Current OpenGL context
308
309 wxTimer m_editing_timeout_timer; // Expires after some time signaling that
310 // the mouse / keyboard movements are over
311 wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
312 std::atomic_flag m_is_currently_painting = ATOMIC_FLAG_INIT; // Avoid drawing twice at the same time
313
314 bool m_render_pivot = false; // Render the pivot while camera moving
315 float m_camera_moving_speed = 1.0f; // 1.0f will be 1:1
316 int64_t m_strtime_camera_movement = 0; // Ticktime of camera movement start
317 bool m_animation_enabled = true; // Camera animation enabled
318 int m_moving_speed_multiplier = 3; // Camera animation speed multiplier option
319
320 BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
324
327
328 ACCELERATOR_3D* m_accelerator3DShapes = nullptr; // used for mouse over searching
329
331
332 bool m_render3dmousePivot = false; // Render the 3dmouse pivot
333 SFVEC3F m_3dmousePivotPos; // The position of the 3dmouse pivot
334
337 double m_gestureLastAngle = 0.0;
338
345 static const wxChar* m_logTrace;
346};
347
348
349#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:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
A class used to derive camera objects from.
Definition camera.h:99
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.
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
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.
void OnRightDown(wxMouseEvent &event)
int m_moving_speed_multiplier
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 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.
RENDER_3D_RAYTRACE_GL * m_3d_render_raytracing
void OnZoomGesture(wxZoomGestureEvent &event)
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 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.
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)
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 modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
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