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;
43 
44 
49 {
50  public:
58  EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard,
59  BOARD_ADAPTER& aSettings, CCAMERA& aCamera, S3D_CACHE* a3DCachePointer );
60 
62 
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 = NULL, S3D_CACHE *aCachePointer = NULL );
83 
89  {
90  if( m_3d_render )
92  else
93  return false;
94  }
95 
100 
105  void GetScreenshot( wxImage &aDstImage );
106 
113  bool SetView3D( int aKeycode );
114 
119  void AnimationEnabledSet( bool aAnimationEnabled ) { m_animation_enabled = aAnimationEnabled; }
120 
125  bool AnimationEnabledGet() const { return m_animation_enabled; }
126 
131  void MovingSpeedMultiplierSet( int aMovingSpeedMultiplier ) { m_moving_speed_multiplier = aMovingSpeedMultiplier; }
132 
138 
142  void RenderEngineChanged();
143 
147  void DisplayStatus();
148 
154  void Request_refresh( bool aRedrawImmediately = true );
155 
159  void OnEvent( wxEvent& aEvent );
160 
161 private:
164  void OnPaint( wxPaintEvent& aEvent );
165 
171  void DoRePaint();
172 
173  void OnEraseBackground( wxEraseEvent &event );
174 
175  void OnRefreshRequest( wxEvent& aEvent );
176 
177  void OnMouseWheel( wxMouseEvent &event );
178 
179 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
180  void OnMagnify( wxMouseEvent& event );
181 #endif
182 
183  void OnMouseMove( wxMouseEvent &event );
184  void OnLeftDown( wxMouseEvent &event );
185  void OnLeftUp( wxMouseEvent &event );
186  void OnMiddleUp( wxMouseEvent &event );
187  void OnMiddleDown( wxMouseEvent &event );
188  void OnTimerTimeout_Editing( wxTimerEvent& event );
189  void OnCloseWindow( wxCloseEvent &event );
190  void OnResize( wxSizeEvent &event );
191  void OnTimerTimeout_Redraw( wxTimerEvent& event );
192 
193  DECLARE_EVENT_TABLE()
194 
195  private:
200 
205 
211  void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true );
212 
218 
224  void render_pivot( float t, float aScale );
225 
230  bool initializeOpenGL();
231 
235  void releaseOpenGL();
236 
238 
239  private:
240 
242  wxStatusBar* m_parentStatusBar; // Parent statusbar to report progress
244 
245  wxGLContext* m_glRC; // Current OpenGL context
248 
249  wxTimer m_editing_timeout_timer; // Expires after some time signalling that
250  // the mouse / keyboard movements are over
251  wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
252  std::atomic_flag m_is_currently_painting; // Avoid drawing twice at the same time
253 
254  bool m_mouse_is_moving; // Mouse activity is in progress
256  bool m_camera_is_moving; // Camera animation is ongoing
257  bool m_render_pivot; // Render the pivot while camera moving
258  float m_camera_moving_speed; // 1.0f will be 1:1
259  unsigned m_strtime_camera_movement; // Ticktime of camera movement start
260  bool m_animation_enabled; // Camera animation enabled
261  int m_moving_speed_multiplier; // Camera animation speed multiplier option
262 
263  BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
268 
269  static const float m_delta_move_step_factor; // Step factor to used with cursor on
270  // relation to the current zoom
271 
274 
275  CCONTAINER m_3DShapes_container; // Holds 3D shapes from footprints
276  CGENERICACCELERATOR *m_accelerator3DShapes; // used for mouse over searching
277 
279 
286  static const wxChar *m_logTrace;
287 };
288 
289 
290 #endif // EDA_3D_CANVAS_H
C3D_RENDER_RAYTRACING * m_3d_render_raytracing
void AnimationEnabledSet(bool aAnimationEnabled)
AnimationEnabledSet - Enable or disable camera animation when switching to a pre-defined view.
void OnMouseMove(wxMouseEvent &event)
void OnResize(wxSizeEvent &event)
void request_start_moving_camera(float aMovingSpeed=2.0f, bool aRenderPivot=true)
request_start_moving_camera - start a camera movement
void releaseOpenGL()
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
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
RAY getRayAtCurrrentMousePosition()
void stop_editingTimeOut_Timer()
stop_editingTimeOut_Timer - stop the editing time, so it will not timeout
wxStatusBar * m_parentStatusBar
Class CCAMERA is a virtual class used to derive CCAMERA objects from.
Definition: ccamera.h:79
wxGLContext * m_glRC
void OnCloseWindow(wxCloseEvent &event)
wxGLCanvas wrapper for HiDPI/Retina support.
void SetStatusBar(wxStatusBar *aStatusBar)
Definition: eda_3d_canvas.h:72
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:48
bool IsReloadRequestPending() const
IsReloadRequestPending - Query if there is a pending reload request.
Definition: eda_3d_canvas.h:88
wxTimer m_editing_timeout_timer
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:58
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()
DisplayStatus - Update the status bar with the position information.
C3D_RENDER_OGL_LEGACY * m_3d_render_ogl_legacy
S3D_CACHE.
Definition: 3d_cache.h:54
void Request_refresh(bool aRedrawImmediately=true)
Request_refresh - Schedule a refresh update of the canvas.
void ReloadRequest(BOARD *aBoard=NULL, S3D_CACHE *aCachePointer=NULL)
void DoRePaint()
The actual function to repaint the canvas.
void MovingSpeedMultiplierSet(int aMovingSpeedMultiplier)
MovingSpeedMultiplierSet - 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
void OnLeftUp(wxMouseEvent &event)
void SetInfoBar(WX_INFOBAR *aInfoBar)
Definition: eda_3d_canvas.h:77
void restart_editingTimeOut_Timer()
restart_editingTimeOut_Timer - reset the editing timer
void RenderRaytracingRequest()
RenderRaytracingRequest - Request to render the current view in Raytracing mode.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools.
#define NULL
void OnMiddleDown(wxMouseEvent &event)
CCAMERA & m_camera
bool m_mouse_was_moved
void OnPaint(wxPaintEvent &aEvent)
Called by a wxPaintEvent event.
void OnEraseBackground(wxEraseEvent &event)
void OnMouseWheel(wxMouseEvent &event)
void RenderEngineChanged()
RenderEngineChanged - Notify that the render engine was changed.
bool m_camera_is_moving
bool AnimationEnabledGet() const
AnimationEnabledGet - Returns whether camera animation is enabled when switching to a pre-defined vie...
void OnTimerTimeout_Redraw(wxTimerEvent &event)
bool m_animation_enabled
bool m_is_opengl_initialized
bool IsReloadRequestPending() const
IsReloadRequestPending - Query if there is a pending reload request.
C3D_RENDER_BASE * m_3d_render
void OnMiddleUp(wxMouseEvent &event)
The C3D_RENDER_OGL_LEGACY class render the board using openGL legacy mode.
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:70
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
MovingSpeedMultiplierGet - Return the current camera animation moving speed multiplier option.
CGENERICACCELERATOR * m_accelerator3DShapes
bool initializeOpenGL()
initializeOpenGL
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
bool m_opengl_supports_raytracing
void move_pivot_based_on_cur_mouse_position()
move_pivot_based_on_cur_mouse_position - This function hits a ray to the board and start a moviment
EDA_3D_CANVAS(wxWindow *aParent, const int *aAttribList, BOARD *aBoard, BOARD_ADAPTER &aSettings, CCAMERA &aCamera, S3D_CACHE *a3DCachePointer)
EDA_3D_CANVAS - Creates a new 3D Canvas with a attribute list.
std::atomic_flag m_is_currently_painting
CCONTAINER m_3DShapes_container
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
bool SetView3D(int aKeycode)
SetView3D - Helper function to call view commands.
defines the display data cache manager for 3D models
void OnTimerTimeout_Editing(wxTimerEvent &event)
wxTimer m_redraw_trigger_timer
Class BOARD_ADAPTER Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:68
static const float m_delta_move_step_factor
void render_pivot(float t, float aScale)
render_pivot - render the pivot cursor
This is a base class to hold data and functions for render targets.
bool m_render_raytracing_was_requested