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-2019 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 
30 #ifndef EDA_3D_CANVAS_H
31 #define EDA_3D_CANVAS_H
32 
33 
34 #include "cinfo3d_visu.h"
38 #include "3d_cache/3d_cache.h"
39 #include <gal/hidpi_gl_canvas.h>
40 #include <wx/clipbrd.h>
41 #include <wx/dataobj.h>
42 #include <wx/image.h>
43 #include <wx/wupdlock.h>
44 #include <wx/timer.h>
45 #include <wx/statusbr.h>
46 #include <pcb_base_frame.h>
47 
48 // Flag for special keys
49 // TODO Remove these when Action-ifying 3d viewer
50 #define GR_KB_RIGHTSHIFT ( 0x01000000U )
51 #define GR_KB_LEFTSHIFT ( 0x02000000U )
52 #define GR_KB_CTRL ( 0x04000000U )
53 #define GR_KB_ALT ( 0x08000000U )
54 #define GR_KB_SHIFT ( GR_KB_LEFTSHIFT | GR_KB_RIGHTSHIFT )
55 
56 
61 {
62 
63  public:
64 
65 
73  EDA_3D_CANVAS( wxWindow *aParent,
74  const int *aAttribList = 0,
75  BOARD *aBoard = NULL,
76  CINFO3D_VISU &aSettings = G_null_CINFO3D_VISU,
77  S3D_CACHE *a3DCachePointer = NULL );
78 
80 
81  void SetStatusBar( wxStatusBar *aStatusBar ) { m_parentStatusBar = aStatusBar; }
82 
83  void ReloadRequest( BOARD *aBoard = NULL, S3D_CACHE *aCachePointer = NULL );
84 
90  {
91  if( m_3d_render )
93  else
94  return false;
95  }
96 
101 
106  void GetScreenshot( wxImage &aDstImage );
107 
114  bool SetView3D( int aKeycode );
115 
119  void RenderEngineChanged();
120 
124  void DisplayStatus();
125 
131  void Request_refresh( bool aRedrawImmediately = true );
132 
133  void OnKeyEvent( wxKeyEvent& event );
134 
136 
138 
139 private:
140 
141  void OnPaint( wxPaintEvent &event );
142 
143  void OnEraseBackground( wxEraseEvent &event );
144 
145  void OnMouseWheel( wxMouseEvent &event );
146 
147 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
148  void OnMagnify( wxMouseEvent& event );
149 #endif
150 
151  void OnMouseMove( wxMouseEvent &event );
152 
153  void OnLeftDown( wxMouseEvent &event );
154 
155  void OnLeftUp( wxMouseEvent &event );
156 
157  void OnMiddleUp( wxMouseEvent &event );
158 
159  void OnMiddleDown( wxMouseEvent &event );
160 
161  void OnRightClick( wxMouseEvent &event );
162 
163  void OnPopUpMenu( wxCommandEvent &event );
164 
165  void OnCharHook( wxKeyEvent& event );
166 
167  void OnTimerTimeout_Editing( wxTimerEvent& event );
168 
173  void OnCloseWindow( wxCloseEvent &event );
174 
175  void OnResize( wxSizeEvent &event );
176 
177  void OnTimerTimeout_Redraw( wxTimerEvent& event );
178 
179  DECLARE_EVENT_TABLE()
180 
181  private:
182 
187 
188 
193 
194 
200  void request_start_moving_camera( float aMovingSpeed = 2.0f,
201  bool aRenderPivot = true );
202 
203 
209 
210 
216  void render_pivot( float t, float aScale );
217 
222  bool initializeOpenGL();
223 
227  void releaseOpenGL();
228 
229  private:
230 
232  wxGLContext *m_glRC;
233 
235  wxStatusBar *m_parentStatusBar;
236 
240 
243 
246 
250 
253 
256 
259 
262 
265 
268 
271 
274 
277 
279  static const float m_delta_move_step_factor;
280 
283 
285 
292  static const wxChar *m_logTrace;
293 };
294 
295 
296 #endif // EDA_3D_CANVAS_H
C3D_RENDER_RAYTRACING * m_3d_render_raytracing
Raytracing render class.
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
true if mouse activity is on progress
CINFO3D_VISU & m_settings
Stores all pre-computed 3D information and visualization settings to render the board.
unsigned m_strtime_camera_movement
Stores the ticktime when the camera star its movement.
void stop_editingTimeOut_Timer()
stop_editingTimeOut_Timer - stop the editing time, so it will not timeout
wxStatusBar * m_parentStatusBar
Parent statusbar to report progress.
bool IsOpenGLInitialized() const
wxGLContext * m_glRC
current OpenGL context
Handles data related with the board to be visualized.
void OnCloseWindow(wxCloseEvent &event)
OnCloseWindow - called when the frame is closed.
wxGLCanvas wrapper for HiDPI/Retina support.
void SetStatusBar(wxStatusBar *aStatusBar)
Definition: eda_3d_canvas.h:81
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:60
bool IsReloadRequestPending() const
IsReloadRequestPending - Query if there is a pending reload request.
Definition: eda_3d_canvas.h:89
wxTimer m_editing_timeout_timer
Time timeout will expires after some time sinalizing that the mouse / keyboard movements are over.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
CINFO3D_VISU G_null_CINFO3D_VISU
This is a dummy visualization configuration.
void DisplayStatus()
DisplayStatus - Update the status bar with the position information.
C3D_RENDER_OGL_LEGACY * m_3d_render_ogl_legacy
OpenGL legacy render class.
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)
Classes used in Pcbnew, CvPcb and GerbView.
void OnLeftDown(wxMouseEvent &event)
float m_camera_moving_speed
1.0f will be 1:1
void OnLeftUp(wxMouseEvent &event)
void restart_editingTimeOut_Timer()
restart_editingTimeOut_Timer - reset the editing timer
void RenderRaytracingRequest()
RenderRaytracingRequest - Request to render the current view in Raytracing mode.
void OnKeyEvent(wxKeyEvent &event)
#define NULL
void OnMiddleDown(wxMouseEvent &event)
bool m_mouse_was_moved
true if there was some type of activity, it will be used to render in preview mode
void OnEraseBackground(wxEraseEvent &event)
void OnMouseWheel(wxMouseEvent &event)
void RenderEngineChanged()
RenderEngineChanged - Notify that the render engine was changed.
Class CINFO3D_VISU Helper class to handle information needed to display 3D board.
Definition: cinfo3d_visu.h:70
bool m_camera_is_moving
true if camera animation is ongoing
void OnPopUpMenu(wxCommandEvent &event)
void OnTimerTimeout_Redraw(wxTimerEvent &event)
bool m_render_pivot
activated the render of pivot while camera moving
bool m_is_opengl_initialized
Flag to store if opengl was initialized already.
bool IsReloadRequestPending() const
IsReloadRequestPending - Query if there is a pending reload request.
C3D_RENDER_BASE * m_3d_render
The current render in used for this canvas.
void OnMiddleUp(wxMouseEvent &event)
The C3D_RENDER_OGL_LEGACY class render the board using openGL legacy mode.
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
void OnCharHook(wxKeyEvent &event)
bool initializeOpenGL()
initializeOpenGL
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
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
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 OnRightClick(wxMouseEvent &event)
bool SupportsRayTracing() const
void OnTimerTimeout_Editing(wxTimerEvent &event)
wxTimer m_redraw_trigger_timer
This timer will be used to schedule a redraw event.
static const float m_delta_move_step_factor
Step factor to used with cursor on relation to the current zoom.
void render_pivot(float t, float aScale)
render_pivot - render the pivot cursor
EDA_3D_CANVAS(wxWindow *aParent, const int *aAttribList=0, BOARD *aBoard=NULL, CINFO3D_VISU &aSettings=G_null_CINFO3D_VISU, S3D_CACHE *a3DCachePointer=NULL)
EDA_3D_CANVAS - Creates a new 3D Canvas with a attribute list.
This is a base class to hold data and functions for render targets.
bool m_render_raytracing_was_requested
Flags that the user requested the current view to be render with raytracing.