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-2016 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 
54 {
55 
56  public:
57 
58 
66  EDA_3D_CANVAS( wxWindow *aParent,
67  const int *aAttribList = 0,
68  BOARD *aBoard = NULL,
69  CINFO3D_VISU &aSettings = G_null_CINFO3D_VISU,
70  S3D_CACHE *a3DCachePointer = NULL );
71 
73 
74  void SetStatusBar( wxStatusBar *aStatusBar ) { m_parentStatusBar = aStatusBar; }
75 
76  void ReloadRequest( BOARD *aBoard = NULL, S3D_CACHE *aCachePointer = NULL );
77 
83  {
84  if( m_3d_render )
86  else
87  return false;
88  }
89 
94 
99  void GetScreenshot( wxImage &aDstImage );
100 
107  bool SetView3D( int aKeycode );
108 
112  void RenderEngineChanged();
113 
117  void DisplayStatus();
118 
124  void Request_refresh( bool aRedrawImmediately = true );
125 
126  private:
127 
128  void OnPaint( wxPaintEvent &event );
129 
130  void OnEraseBackground( wxEraseEvent &event );
131 
132  void OnMouseWheel( wxMouseEvent &event );
133 
134 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
135  void OnMagnify( wxMouseEvent& event );
136 #endif
137 
138  void OnMouseMove( wxMouseEvent &event );
139 
140  void OnLeftDown( wxMouseEvent &event );
141 
142  void OnLeftUp( wxMouseEvent &event );
143 
144  void OnMiddleUp( wxMouseEvent &event );
145 
146  void OnMiddleDown( wxMouseEvent &event );
147 
148  void OnRightClick( wxMouseEvent &event );
149 
150  void OnPopUpMenu( wxCommandEvent &event );
151 
152  void OnCharHook( wxKeyEvent& event );
153 
154  void OnKeyEvent( wxKeyEvent& event );
155 
156  void OnTimerTimeout_Editing( wxTimerEvent& event );
157 
162  void OnCloseWindow( wxCloseEvent &event );
163 
164  void OnResize( wxSizeEvent &event );
165 
166  void OnTimerTimeout_Redraw( wxTimerEvent& event );
167 
168  DECLARE_EVENT_TABLE()
169 
170  private:
171 
176 
177 
182 
183 
189  void request_start_moving_camera( float aMovingSpeed = 2.0f,
190  bool aRenderPivot = true );
191 
192 
198 
199 
205  void render_pivot( float t, float aScale );
206 
211  bool initializeOpenGL();
212 
216  void releaseOpenGL();
217 
218  private:
219 
221  wxGLContext *m_glRC;
222 
224  wxStatusBar *m_parentStatusBar;
225 
229 
232 
235 
239 
242 
245 
248 
251 
254 
257 
260 
263 
266 
268  static const float m_delta_move_step_factor;
269 
272 
279  static const wxChar *m_logTrace;
280 };
281 
282 
283 #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.
bool IsReloadRequestPending() const
IsReloadRequestPending - Query if there is a pending reload request.
Definition: eda_3d_canvas.h:82
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.
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:74
Class EDA_3D_CANVAS Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:53
wxTimer m_editing_timeout_timer
Time timeout will expires after some time sinalizing that the mouse / keyboard movements are over...
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.
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)
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
bool IsReloadRequestPending() const
IsReloadRequestPending - Query if there is a pending reload request.
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.
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
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 ...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
bool SetView3D(int aKeycode)
SetView3D - Helper function to call view commands.
void OnPaint(wxPaintEvent &event)
defines the display data cache manager for 3D models
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void OnRightClick(wxMouseEvent &event)
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.