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 <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2020 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"
33 #include <gal/hidpi_gl_canvas.h>
34 #include <wx/image.h>
35 #include <wx/timer.h>
36 
37 
38 class WX_INFOBAR;
39 class wxStatusBar;
40 class BOARD;
41 class RENDER_3D_RAYTRACE;
42 class RENDER_3D_LEGACY;
43 
44 
49 {
50 public:
59  EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard,
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 
109  void GetScreenshot( wxImage& aDstImage );
110 
117  bool SetView3D( int aKeycode );
118 
124  void AnimationEnabledSet( bool aAnimationEnabled ) { m_animation_enabled = aAnimationEnabled; }
125 
131  bool AnimationEnabledGet() const { return m_animation_enabled; }
132 
138  void MovingSpeedMultiplierSet( int aMovingSpeedMultiplier )
139  {
140  m_moving_speed_multiplier = aMovingSpeedMultiplier;
141  }
142 
149 
153  void RenderEngineChanged();
154 
158  void DisplayStatus();
159 
166  void Request_refresh( bool aRedrawImmediately = true );
167 
171  void OnEvent( wxEvent& aEvent );
172 
173 private:
177  void OnPaint( wxPaintEvent& aEvent );
178 
185  void DoRePaint();
186 
187  void OnEraseBackground( wxEraseEvent& event );
188 
189  void OnRefreshRequest( wxEvent& aEvent );
190 
191  void OnMouseWheel( wxMouseEvent& event );
192 
193 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
194  void OnMagnify( wxMouseEvent& event );
195 #endif
196 
197  void OnMouseMove( wxMouseEvent& event );
198  void OnLeftDown( wxMouseEvent& event );
199  void OnLeftUp( wxMouseEvent& event );
200  void OnMiddleUp( wxMouseEvent& event );
201  void OnMiddleDown( wxMouseEvent& event );
202  void OnTimerTimeout_Editing( wxTimerEvent& event );
203  void OnCloseWindow( wxCloseEvent& event );
204  void OnResize( wxSizeEvent& event );
205  void OnTimerTimeout_Redraw( wxTimerEvent& event );
206 
207  DECLARE_EVENT_TABLE()
208 
209 
213 
218 
225  void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true );
226 
231 
238  void render_pivot( float t, float aScale );
239 
243  bool initializeOpenGL();
244 
248  void releaseOpenGL();
249 
251 
252 private:
254  wxStatusBar* m_parentStatusBar; // Parent statusbar to report progress
256 
257  wxGLContext* m_glRC; // Current OpenGL context
260 
261  wxTimer m_editing_timeout_timer; // Expires after some time signaling that
262  // the mouse / keyboard movements are over
263  wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
264  std::atomic_flag m_is_currently_painting; // Avoid drawing twice at the same time
265 
266  bool m_mouse_is_moving; // Mouse activity is in progress
268  bool m_camera_is_moving; // Camera animation is ongoing
269  bool m_render_pivot; // Render the pivot while camera moving
270  float m_camera_moving_speed; // 1.0f will be 1:1
271  unsigned m_strtime_camera_movement; // Ticktime of camera movement start
272  bool m_animation_enabled; // Camera animation enabled
273  int m_moving_speed_multiplier; // Camera animation speed multiplier option
274 
275  BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
280 
281  static const float m_delta_move_step_factor; // Step factor to used with cursor on
282  // relation to the current zoom
283 
286 
287  CONTAINER_3D m_3DShapes_container; // Holds 3D shapes from footprints
288  ACCELERATOR_3D* m_accelerator3DShapes; // used for mouse over searching
289 
291 
298  static const wxChar* m_logTrace;
299 };
300 
301 
302 #endif // EDA_3D_CANVAS_H
void AnimationEnabledSet(bool aAnimationEnabled)
Enable or disable camera animation when switching to a pre-defined view.
bool IsReloadRequestPending() const
Query if there is a pending reload request.
void OnMouseMove(wxMouseEvent &event)
void OnResize(wxSizeEvent &event)
void request_start_moving_camera(float aMovingSpeed=2.0f, bool aRenderPivot=true)
Start a camera movement.
void releaseOpenGL()
Free created targets and openGL context.
bool m_mouse_is_moving
void OnRefreshRequest(wxEvent &aEvent)
unsigned m_strtime_camera_movement
WX_INFOBAR * m_parentInfoBar
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
RAY getRayAtCurrrentMousePosition()
void stop_editingTimeOut_Timer()
Stop the editing time so it will not timeout.
CONTAINER_3D m_3DShapes_container
wxStatusBar * m_parentStatusBar
wxGLContext * m_glRC
void OnCloseWindow(wxCloseEvent &event)
wxGLCanvas wrapper for HiDPI/Retina support.
void SetStatusBar(wxStatusBar *aStatusBar)
Definition: eda_3d_canvas.h:74
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:48
bool IsReloadRequestPending() const
Query if there is a pending reload request.
Definition: eda_3d_canvas.h:91
wxTimer m_editing_timeout_timer
Definition: bitmap.cpp:58
EDA_3D_CANVAS(wxWindow *aParent, const int *aAttribList, BOARD *aBoard, BOARD_ADAPTER &aSettings, CAMERA &aCamera, S3D_CACHE *a3DCachePointer)
Create a new 3D Canvas with an attribute list.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
BOARD_ITEM * m_currentIntersectedBoardItem
Definition: ray.h:67
void DisplayStatus()
Update the status bar with the position information.
Cache for storing the 3D shapes.
Definition: 3d_cache.h:52
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
void DoRePaint()
The actual function to repaint the canvas.
void MovingSpeedMultiplierSet(int aMovingSpeedMultiplier)
Set the camera animation moving speed multiplier option.
BOARD_ADAPTER & m_boardAdapter
void OnLeftDown(wxMouseEvent &event)
float m_camera_moving_speed
bool m_is_opengl_version_supported
A class used to derive camera objects from.
Definition: camera.h:77
void OnLeftUp(wxMouseEvent &event)
void SetInfoBar(WX_INFOBAR *aInfoBar)
Definition: eda_3d_canvas.h:79
void restart_editingTimeOut_Timer()
Reset the editing timer.
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.
RENDER_3D_LEGACY * m_3d_render_ogl_legacy
void OnMiddleDown(wxMouseEvent &event)
bool m_mouse_was_moved
void OnPaint(wxPaintEvent &aEvent)
Called by a wxPaintEvent event.
void OnEraseBackground(wxEraseEvent &event)
void OnMouseWheel(wxMouseEvent &event)
void RenderEngineChanged()
Notify that the render engine was changed.
RENDER_3D_RAYTRACE * m_3d_render_raytracing
Object to render the board using openGL legacy mode.
bool m_camera_is_moving
bool AnimationEnabledGet() const
Return whether camera animation is enabled when switching to a pre-defined view.
RENDER_3D_BASE * m_3d_render
This is a base class to hold data and functions for render targets.
void OnTimerTimeout_Redraw(wxTimerEvent &event)
bool m_animation_enabled
bool m_is_opengl_initialized
void OnMiddleUp(wxMouseEvent &event)
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:71
TOOL_DISPATCHER * m_eventDispatcher
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
int m_moving_speed_multiplier
int MovingSpeedMultiplierGet() const
Return the current camera animation moving speed multiplier option.
bool initializeOpenGL()
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
bool m_opengl_supports_raytracing
ACCELERATOR_3D * m_accelerator3DShapes
void move_pivot_based_on_cur_mouse_position()
This function hits a ray to the board and start a movement.
std::atomic_flag m_is_currently_painting
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
bool SetView3D(int aKeycode)
Helper function to call view commands.
void OnTimerTimeout_Editing(wxTimerEvent &event)
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
CAMERA & m_camera
wxTimer m_redraw_trigger_timer
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:67
static const float m_delta_move_step_factor
void render_pivot(float t, float aScale)
Render the pivot cursor.
bool m_render_raytracing_was_requested