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 <wx/clipbrd.h>
40 #include <wx/dataobj.h>
41 #include <wx/glcanvas.h>
42 #include <wx/image.h>
43 #include <wx/wupdlock.h>
44 #include <wx/timer.h>
45 #include <wx/statusbr.h>
46 #include <wxBasePcbFrame.h>
47 
48 
53 class EDA_3D_CANVAS : public wxGLCanvas
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 
105  void SetView3D( int keycode );
106 
110  void RenderEngineChanged();
111 
115  void DisplayStatus();
116 
122  void Request_refresh( bool aRedrawImmediately = true );
123 
124  private:
125 
126  void OnPaint( wxPaintEvent &event );
127 
128  void OnEraseBackground( wxEraseEvent &event );
129 
130  void OnMouseWheel( wxMouseEvent &event );
131 
132 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
133  void OnMagnify( wxMouseEvent& event );
134 #endif
135 
136  void OnMouseMove( wxMouseEvent &event );
137 
138  void OnLeftDown( wxMouseEvent &event );
139 
140  void OnLeftUp( wxMouseEvent &event );
141 
142  void OnMiddleUp( wxMouseEvent &event );
143 
144  void OnMiddleDown( wxMouseEvent &event );
145 
146  void OnRightClick( wxMouseEvent &event );
147 
148  void OnPopUpMenu( wxCommandEvent &event );
149 
150  void OnCharHook( wxKeyEvent& event );
151 
152  void OnKeyEvent( wxKeyEvent& event );
153 
154  void OnTimerTimeout_Editing( wxTimerEvent& event );
155 
160  void OnCloseWindow( wxCloseEvent &event );
161 
162  void OnTimerTimeout_Redraw( wxTimerEvent& event );
163 
165 
166  private:
167 
172 
173 
178 
179 
185  void request_start_moving_camera( float aMovingSpeed = 2.0f,
186  bool aRenderPivot = true );
187 
188 
194 
195 
201  void render_pivot( float t, float aScale );
202 
207  bool initializeOpenGL();
208 
212  void releaseOpenGL();
213 
214  private:
215 
217  wxGLContext *m_glRC;
218 
220  wxStatusBar *m_parentStatusBar;
221 
225 
228 
231 
235 
238 
241 
244 
247 
250 
253 
256 
259 
262 
264  static const float m_delta_move_step_factor;
265 
268 
275  static const wxChar *m_logTrace;
276 };
277 
278 
279 #endif // EDA_3D_CANVAS_H
C3D_RENDER_RAYTRACING * m_3d_render_raytracing
Raytracing render class.
void OnMouseMove(wxMouseEvent &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.
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)
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)
Classes used in Pcbnew, CvPcb and GerbView.
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)
void SetView3D(int keycode)
SetView3D - Helper function to call view commands.
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:166
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.