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 
29 #include "board_adapter.h"
31 #include "3d_cache/3d_cache.h"
32 #include <gal/hidpi_gl_canvas.h>
33 #include <wx/image.h>
34 #include <wx/timer.h>
35 
36 
37 class WX_INFOBAR;
38 class wxStatusBar;
39 class BOARD;
42 
43 
48 {
49  public:
57  EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard,
58  BOARD_ADAPTER& aSettings, CCAMERA& aCamera, S3D_CACHE* a3DCachePointer );
59 
61 
69  void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
70 
71  void SetStatusBar( wxStatusBar* aStatusBar )
72  {
73  m_parentStatusBar = aStatusBar;
74  }
75 
76  void SetInfoBar( WX_INFOBAR* aInfoBar )
77  {
78  m_parentInfoBar = aInfoBar;
79  }
80 
81  void ReloadRequest( BOARD *aBoard = NULL, S3D_CACHE *aCachePointer = NULL );
82 
88  {
89  if( m_3d_render )
91  else
92  return false;
93  }
94 
99 
104  void GetScreenshot( wxImage &aDstImage );
105 
112  bool SetView3D( int aKeycode );
113 
118  void AnimationEnabledSet( bool aAnimationEnabled ) { m_animation_enabled = aAnimationEnabled; }
119 
124  bool AnimationEnabledGet() const { return m_animation_enabled; }
125 
130  void MovingSpeedMultiplierSet( int aMovingSpeedMultiplier ) { m_moving_speed_multiplier = aMovingSpeedMultiplier; }
131 
137 
141  void RenderEngineChanged();
142 
146  void DisplayStatus();
147 
153  void Request_refresh( bool aRedrawImmediately = true );
154 
158  void OnEvent( wxEvent& aEvent );
159 
160 private:
161 
162  void OnPaint( wxPaintEvent &event );
163 
164  void OnEraseBackground( wxEraseEvent &event );
165 
166  void OnMouseWheel( wxMouseEvent &event );
167 
168 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
169  void OnMagnify( wxMouseEvent& event );
170 #endif
171 
172  void OnMouseMove( wxMouseEvent &event );
173  void OnLeftDown( wxMouseEvent &event );
174  void OnLeftUp( wxMouseEvent &event );
175  void OnMiddleUp( wxMouseEvent &event );
176  void OnMiddleDown( wxMouseEvent &event );
177  void OnTimerTimeout_Editing( wxTimerEvent& event );
178  void OnCloseWindow( wxCloseEvent &event );
179  void OnResize( wxSizeEvent &event );
180  void OnTimerTimeout_Redraw( wxTimerEvent& event );
181 
182  DECLARE_EVENT_TABLE()
183 
184  private:
189 
194 
200  void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true );
201 
207 
213  void render_pivot( float t, float aScale );
214 
219  bool initializeOpenGL();
220 
224  void releaseOpenGL();
225 
226  private:
227 
229  wxStatusBar* m_parentStatusBar; // Parent statusbar to report progress
231 
232  wxGLContext* m_glRC; // Current OpenGL context
234 
235  wxTimer m_editing_timeout_timer; // Expires after some time signalling that
236  // the mouse / keyboard movements are over
237  wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
238 
239  bool m_mouse_is_moving; // Mouse activity is in progress
241  bool m_camera_is_moving; // Camera animation is ongoing
242  bool m_render_pivot; // Render the pivot while camera moving
243  float m_camera_moving_speed; // 1.0f will be 1:1
244  unsigned m_strtime_camera_movement; // Ticktime of camera movement start
245  bool m_animation_enabled; // Camera animation enabled
246  int m_moving_speed_multiplier; // Camera animation speed multiplier option
247 
248  BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
253 
254  static const float m_delta_move_step_factor; // Step factor to used with cursor on
255  // relation to the current zoom
256 
259 
266  static const wxChar *m_logTrace;
267 };
268 
269 
270 #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
unsigned m_strtime_camera_movement
WX_INFOBAR * m_parentInfoBar
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:71
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:47
bool IsReloadRequestPending() const
IsReloadRequestPending - Query if there is a pending reload request.
Definition: eda_3d_canvas.h:87
wxTimer m_editing_timeout_timer
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
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 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
void OnLeftUp(wxMouseEvent &event)
void SetInfoBar(WX_INFOBAR *aInfoBar)
Definition: eda_3d_canvas.h:76
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 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
TOOL_DISPATCHER.
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:68
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.
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.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
bool SetView3D(int aKeycode)
SetView3D - Helper function to call view commands.
void OnPaint(wxPaintEvent &event)
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