KiCad PCB EDA Suite
EDA_3D_CANVAS Class Reference

Class EDA_3D_CANVAS Implement a canvas based on a wxGLCanvas. More...

#include <eda_3d_canvas.h>

Inheritance diagram for EDA_3D_CANVAS:
HIDPI_GL_CANVAS

Public Member Functions

 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. More...
 
 ~EDA_3D_CANVAS ()
 
void SetStatusBar (wxStatusBar *aStatusBar)
 
void ReloadRequest (BOARD *aBoard=NULL, S3D_CACHE *aCachePointer=NULL)
 
bool IsReloadRequestPending () const
 IsReloadRequestPending - Query if there is a pending reload request. More...
 
void RenderRaytracingRequest ()
 RenderRaytracingRequest - Request to render the current view in Raytracing mode. More...
 
void GetScreenshot (wxImage &aDstImage)
 Request a screenshot and output it to the aDstImage. More...
 
void SetView3D (int keycode)
 SetView3D - Helper function to call view commands. More...
 
void RenderEngineChanged ()
 RenderEngineChanged - Notify that the render engine was changed. More...
 
void DisplayStatus ()
 DisplayStatus - Update the status bar with the position information. More...
 
void Request_refresh (bool aRedrawImmediately=true)
 Request_refresh - Schedule a refresh update of the canvas. More...
 
virtual wxSize GetClientSize () const
 
virtual float GetBackingScaleFactor () const
 

Private Member Functions

void OnPaint (wxPaintEvent &event)
 
void OnEraseBackground (wxEraseEvent &event)
 
void OnMouseWheel (wxMouseEvent &event)
 
void OnMouseMove (wxMouseEvent &event)
 
void OnLeftDown (wxMouseEvent &event)
 
void OnLeftUp (wxMouseEvent &event)
 
void OnMiddleUp (wxMouseEvent &event)
 
void OnMiddleDown (wxMouseEvent &event)
 
void OnRightClick (wxMouseEvent &event)
 
void OnPopUpMenu (wxCommandEvent &event)
 
void OnCharHook (wxKeyEvent &event)
 
void OnKeyEvent (wxKeyEvent &event)
 
void OnTimerTimeout_Editing (wxTimerEvent &event)
 
void OnCloseWindow (wxCloseEvent &event)
 OnCloseWindow - called when the frame is closed. More...
 
void OnResize (wxSizeEvent &event)
 
void OnTimerTimeout_Redraw (wxTimerEvent &event)
 
void stop_editingTimeOut_Timer ()
 stop_editingTimeOut_Timer - stop the editing time, so it will not timeout More...
 
void restart_editingTimeOut_Timer ()
 restart_editingTimeOut_Timer - reset the editing timer More...
 
void request_start_moving_camera (float aMovingSpeed=2.0f, bool aRenderPivot=true)
 request_start_moving_camera - start a camera movement More...
 
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 More...
 
void render_pivot (float t, float aScale)
 render_pivot - render the pivot cursor More...
 
bool initializeOpenGL ()
 initializeOpenGL More...
 
void releaseOpenGL ()
 releaseOpenGL - free created targets and openGL context More...
 

Private Attributes

wxGLContext * m_glRC
 current OpenGL context More...
 
wxStatusBar * m_parentStatusBar
 Parent statusbar to report progress. More...
 
wxTimer m_editing_timeout_timer
 Time timeout will expires after some time sinalizing that the mouse / keyboard movements are over. More...
 
wxTimer m_redraw_trigger_timer
 This timer will be used to schedule a redraw event. More...
 
bool m_mouse_is_moving
 true if mouse activity is on progress More...
 
bool m_mouse_was_moved
 true if there was some type of activity, it will be used to render in preview mode More...
 
bool m_camera_is_moving
 true if camera animation is ongoing More...
 
bool m_render_pivot
 activated the render of pivot while camera moving More...
 
float m_camera_moving_speed
 1.0f will be 1:1 More...
 
unsigned m_strtime_camera_movement
 Stores the ticktime when the camera star its movement. More...
 
CINFO3D_VISUm_settings
 Stores all pre-computed 3D information and visualization settings to render the board. More...
 
C3D_RENDER_BASEm_3d_render
 The current render in used for this canvas. More...
 
C3D_RENDER_RAYTRACINGm_3d_render_raytracing
 Raytracing render class. More...
 
C3D_RENDER_OGL_LEGACYm_3d_render_ogl_legacy
 OpenGL legacy render class. More...
 
bool m_is_opengl_initialized
 Flag to store if opengl was initialized already. More...
 
bool m_render_raytracing_was_requested
 Flags that the user requested the current view to be render with raytracing. More...
 

Static Private Attributes

static const float m_delta_move_step_factor = 0.7f
 Step factor to used with cursor on relation to the current zoom. More...
 
static const wxChar * m_logTrace = wxT( "KI_TRACE_EDA_3D_CANVAS" )
 Trace mask used to enable or disable the trace output of this class. More...
 

Detailed Description

Class EDA_3D_CANVAS Implement a canvas based on a wxGLCanvas.

Definition at line 53 of file eda_3d_canvas.h.

Constructor & Destructor Documentation

EDA_3D_CANVAS::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.

Parameters
aParentthe parent creator of this canvas
aAttribLista list of openGL options created by GetOpenGL_AttributesList
aBoardThe board
aSettingsthe settings options to be used by this canvas
EDA_3D_CANVAS::~EDA_3D_CANVAS ( )

Definition at line 155 of file eda_3d_canvas.cpp.

References m_logTrace, and releaseOpenGL().

156 {
157  wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::~EDA_3D_CANVAS" ) );
158 
159  releaseOpenGL();
160 }
void releaseOpenGL()
releaseOpenGL - free created targets and openGL context
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.

Member Function Documentation

void EDA_3D_CANVAS::DisplayStatus ( )

DisplayStatus - Update the status bar with the position information.

Definition at line 257 of file eda_3d_canvas.cpp.

References CINFO3D_VISU::CameraGet(), CCAMERA::GetCameraPos(), m_parentStatusBar, and m_settings.

Referenced by IsReloadRequestPending(), OnMouseMove(), OnMouseWheel(), OnPaint(), EDA_3D_VIEWER::ProcessZoom(), request_start_moving_camera(), and SetView3D().

258 {
259  if( m_parentStatusBar )
260  {
261  wxString msg;
262 
263  msg.Printf( wxT( "dx %3.2f" ), m_settings.CameraGet().GetCameraPos().x );
264  m_parentStatusBar->SetStatusText( msg, 1 );
265 
266  msg.Printf( wxT( "dy %3.2f" ), m_settings.CameraGet().GetCameraPos().y );
267  m_parentStatusBar->SetStatusText( msg, 2 );
268 
269  //msg.Printf( _( "Zoom: %3.1f" ), 50 * m_settings.CameraGet().ZoomGet() );
270  //m_parentStatusBar->SetStatusText( msg, 3 );
271  }
272 }
CINFO3D_VISU & m_settings
Stores all pre-computed 3D information and visualization settings to render the board.
wxStatusBar * m_parentStatusBar
Parent statusbar to report progress.
const SFVEC3F & GetCameraPos() const
Definition: ccamera.h:131
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
float HIDPI_GL_CANVAS::GetBackingScaleFactor ( ) const
virtualinherited

Definition at line 59 of file hidpi_gl_canvas.cpp.

Referenced by HIDPI_GL_CANVAS::GetClientSize(), and KIGFX::OPENGL_GAL::ResizeScreen().

60 {
61 #ifdef RETINA_OPENGL_PATCH
62  // this is ugly, but original method isn't marked const although it doesn't modify anything
63  // => clean up when it officially has arrived in wxWidgets
64  return static_cast< wxGLCanvas* >( const_cast< HIDPI_GL_CANVAS* >( this ))->GetBackingScaleFactor();
65 #else
66  return 1.0f;
67 #endif
68 }
wxGLCanvas wrapper for HiDPI/Retina support.
wxSize HIDPI_GL_CANVAS::GetClientSize ( ) const
virtualinherited

Definition at line 46 of file hidpi_gl_canvas.cpp.

References HIDPI_GL_CANVAS::GetBackingScaleFactor().

Referenced by C3D_MODEL_VIEWER::OnMouseMove(), OnMouseMove(), C3D_MODEL_VIEWER::OnPaint(), and OnPaint().

47 {
48  wxSize size = wxGLCanvas::GetClientSize();
49 
50 #ifdef RETINA_OPENGL_PATCH
51  const float scaleFactor = GetBackingScaleFactor();
52  size.x *= scaleFactor;
53  size.y *= scaleFactor;
54 #endif
55 
56  return size;
57 }
virtual float GetBackingScaleFactor() const
void EDA_3D_CANVAS::GetScreenshot ( wxImage &  aDstImage)

Request a screenshot and output it to the aDstImage.

Parameters
aDstImage- Screenshot destination image

Definition at line 224 of file eda_3d_canvas.cpp.

References OGL_GetScreenshot().

Referenced by IsReloadRequestPending(), and EDA_3D_VIEWER::takeScreenshot().

225 {
226  OGL_GetScreenshot( aDstImage );
227 }
void OGL_GetScreenshot(wxImage &aDstImage)
OGL_GetScreenshot - got the pixel data of current OpenGL image.
Definition: ogl_utils.cpp:35
bool EDA_3D_CANVAS::initializeOpenGL ( )
private

initializeOpenGL

Returns
if OpenGL initialization succeed

Definition at line 197 of file eda_3d_canvas.cpp.

References FROM_UTF8(), m_is_opengl_initialized, and m_logTrace.

Referenced by IsReloadRequestPending(), and OnPaint().

198 {
199  wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::initializeOpenGL" ) );
200 
201  const GLenum err = glewInit();
202 
203  if( GLEW_OK != err )
204  {
205  const wxString msgError = (const char*) glewGetErrorString( err );
206 
207  wxLogMessage( msgError );
208 
209  return false;
210  }
211  else
212  {
213  wxLogTrace( m_logTrace,
214  wxString( wxT( "EDA_3D_CANVAS::initializeOpenGL Using GLEW " ) ) +
215  FROM_UTF8( (char*) glewGetString( GLEW_VERSION ) ) );
216  }
217 
219 
220  return true;
221 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
bool m_is_opengl_initialized
Flag to store if opengl was initialized already.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
bool EDA_3D_CANVAS::IsReloadRequestPending ( ) const
inline

IsReloadRequestPending - Query if there is a pending reload request.

Returns
true if it wants to reload, false if there is no reload pending

Definition at line 82 of file eda_3d_canvas.h.

References DisplayStatus(), GetScreenshot(), initializeOpenGL(), C3D_RENDER_BASE::IsReloadRequestPending(), m_3d_render, move_pivot_based_on_cur_mouse_position(), OnCharHook(), OnCloseWindow(), OnEraseBackground(), OnKeyEvent(), OnLeftDown(), OnLeftUp(), OnMiddleDown(), OnMiddleUp(), OnMouseMove(), OnMouseWheel(), OnPaint(), OnPopUpMenu(), OnResize(), OnRightClick(), OnTimerTimeout_Editing(), OnTimerTimeout_Redraw(), releaseOpenGL(), render_pivot(), RenderEngineChanged(), RenderRaytracingRequest(), Request_refresh(), request_start_moving_camera(), restart_editingTimeOut_Timer(), SetView3D(), and stop_editingTimeOut_Timer().

Referenced by EDA_3D_VIEWER::OnActivate().

83  {
84  if( m_3d_render )
86  else
87  return false;
88  }
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 EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position ( )
private

move_pivot_based_on_cur_mouse_position - This function hits a ray to the board and start a moviment

Definition at line 852 of file eda_3d_canvas.cpp.

References RAY::at(), CINFO3D_VISU::CameraGet(), CINFO3D_VISU::GetBBox3DU(), RAY::Init(), INTERPOLATION_BEZIER, CBBOX::Intersect(), m_settings, CCAMERA::MakeRayAtCurrrentMousePosition(), request_start_moving_camera(), CCAMERA::ResetXYpos_T1(), CCAMERA::SetInterpolateMode(), CCAMERA::SetLookAtPos_T1(), and CCAMERA::SetT0_and_T1_current_T().

Referenced by IsReloadRequestPending(), OnMiddleUp(), and SetView3D().

853 {
854  SFVEC3F rayOrigin;
855  SFVEC3F rayDir;
856 
857  // Generate a ray origin and direction based on current mouser position and camera
858  m_settings.CameraGet().MakeRayAtCurrrentMousePosition( rayOrigin, rayDir );
859 
860  RAY mouseRay;
861  mouseRay.Init( rayOrigin, rayDir );
862 
863  float hit_t;
864 
865  // Test it with the board bounding box
866  if( m_settings.GetBBox3DU().Intersect( mouseRay, &hit_t ) )
867  {
870  m_settings.CameraGet().SetLookAtPos_T1( mouseRay.at( hit_t ) );
872 
874  }
875 }
void SetLookAtPos_T1(const SFVEC3F &aLookAtPos)
Definition: ccamera.h:125
void request_start_moving_camera(float aMovingSpeed=2.0f, bool aRenderPivot=true)
request_start_moving_camera - start a camera movement
virtual void SetT0_and_T1_current_T()
SetT0_and_T1_current_T - This will set T0 and T1 with the current values.
Definition: ccamera.cpp:535
CINFO3D_VISU & m_settings
Stores all pre-computed 3D information and visualization settings to render the board.
void ResetXYpos_T1()
Definition: ccamera.cpp:382
void Init(const SFVEC3F &o, const SFVEC3F &d)
Definition: ray.cpp:40
SFVEC3F at(float t) const
Definition: ray.h:65
Definition: ray.h:43
bool Intersect(const RAY &aRay, float *t) const
Function Intersect.
Definition: cbbox_ray.cpp:46
void MakeRayAtCurrrentMousePosition(SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
MakeRayAtCurrrentMousePosition - Make a ray based on the latest mouse position.
Definition: ccamera.cpp:350
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
void SetInterpolateMode(CAMERA_INTERPOLATION aInterpolateMode)
Definition: ccamera.h:198
const CBBOX & GetBBox3DU() const
GetBBox3DU - Get the bbox of the pcb board.
Definition: cinfo3d_visu.h:147
void EDA_3D_CANVAS::OnCharHook ( wxKeyEvent &  event)
private

Definition at line 751 of file eda_3d_canvas.cpp.

Referenced by IsReloadRequestPending().

752 {
753  //wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnCharHook" ) );
754  event.Skip();
755 }
void EDA_3D_CANVAS::OnCloseWindow ( wxCloseEvent &  event)
private

OnCloseWindow - called when the frame is closed.

Parameters
event

Definition at line 185 of file eda_3d_canvas.cpp.

References releaseOpenGL().

Referenced by IsReloadRequestPending().

186 {
187  releaseOpenGL();
188 
189  event.Skip();
190 }
void releaseOpenGL()
releaseOpenGL - free created targets and openGL context
void EDA_3D_CANVAS::OnEraseBackground ( wxEraseEvent &  event)
private

Definition at line 434 of file eda_3d_canvas.cpp.

References m_logTrace.

Referenced by IsReloadRequestPending().

435 {
436  wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnEraseBackground" ) );
437  // Do nothing, to avoid flashing.
438 }
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void EDA_3D_CANVAS::OnKeyEvent ( wxKeyEvent &  event)
private

Definition at line 758 of file eda_3d_canvas.cpp.

References m_camera_is_moving, and SetView3D().

Referenced by IsReloadRequestPending().

759 {
760  //wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnKeyEvent" ) );
761 
762  if( m_camera_is_moving )
763  return;
764 
765  SetView3D( event.GetKeyCode() );
766  event.Skip();
767 }
bool m_camera_is_moving
true if camera animation is ongoing
void SetView3D(int keycode)
SetView3D - Helper function to call view commands.
void EDA_3D_CANVAS::OnLeftDown ( wxMouseEvent &  event)
private

Definition at line 556 of file eda_3d_canvas.cpp.

References stop_editingTimeOut_Timer().

Referenced by IsReloadRequestPending().

557 {
559 }
void stop_editingTimeOut_Timer()
stop_editingTimeOut_Timer - stop the editing time, so it will not timeout
void EDA_3D_CANVAS::OnLeftUp ( wxMouseEvent &  event)
private

Definition at line 562 of file eda_3d_canvas.cpp.

References m_camera_is_moving, m_mouse_is_moving, and restart_editingTimeOut_Timer().

Referenced by IsReloadRequestPending().

563 {
564  if( m_camera_is_moving )
565  return;
566 
567  if( m_mouse_is_moving )
568  {
569  m_mouse_is_moving = false;
571  }
572 }
bool m_mouse_is_moving
true if mouse activity is on progress
void restart_editingTimeOut_Timer()
restart_editingTimeOut_Timer - reset the editing timer
bool m_camera_is_moving
true if camera animation is ongoing
void EDA_3D_CANVAS::OnMiddleDown ( wxMouseEvent &  event)
private

Definition at line 575 of file eda_3d_canvas.cpp.

References stop_editingTimeOut_Timer().

Referenced by IsReloadRequestPending().

576 {
578 }
void stop_editingTimeOut_Timer()
stop_editingTimeOut_Timer - stop the editing time, so it will not timeout
void EDA_3D_CANVAS::OnMiddleUp ( wxMouseEvent &  event)
private

Definition at line 581 of file eda_3d_canvas.cpp.

References m_camera_is_moving, m_mouse_is_moving, move_pivot_based_on_cur_mouse_position(), and restart_editingTimeOut_Timer().

Referenced by IsReloadRequestPending().

582 {
583  if( m_camera_is_moving )
584  return;
585 
586  if( m_mouse_is_moving )
587  {
588  m_mouse_is_moving = false;
590  }
591  else
592  {
594  }
595 }
bool m_mouse_is_moving
true if mouse activity is on progress
void restart_editingTimeOut_Timer()
restart_editingTimeOut_Timer - reset the editing timer
bool m_camera_is_moving
true if camera animation is ongoing
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 ...
void EDA_3D_CANVAS::OnMouseMove ( wxMouseEvent &  event)
private

Definition at line 527 of file eda_3d_canvas.cpp.

References CINFO3D_VISU::CameraGet(), DisplayStatus(), CCAMERA::Drag(), HIDPI_GL_CANVAS::GetClientSize(), m_camera_is_moving, m_mouse_is_moving, m_mouse_was_moved, m_settings, CCAMERA::Pan(), Request_refresh(), CCAMERA::SetCurMousePosition(), and CCAMERA::SetCurWindowSize().

Referenced by IsReloadRequestPending().

528 {
529  //wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnMouseMove" ) );
530 
531  if( m_camera_is_moving )
532  return;
533 
535 
536  if( event.Dragging() )
537  {
538  if( event.LeftIsDown() ) // Drag
539  m_settings.CameraGet().Drag( event.GetPosition() );
540  else if( event.MiddleIsDown() ) // Pan
541  m_settings.CameraGet().Pan( event.GetPosition() );
542 
543  m_mouse_is_moving = true;
544  m_mouse_was_moved = true;
545 
546  // orientation has changed, redraw mesh
547  DisplayStatus();
548  Request_refresh();
549  }
550 
551  const wxPoint eventPosition = event.GetPosition();
552  m_settings.CameraGet().SetCurMousePosition( eventPosition );
553 }
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.
void DisplayStatus()
DisplayStatus - Update the status bar with the position information.
void Request_refresh(bool aRedrawImmediately=true)
Request_refresh - Schedule a refresh update of the canvas.
void SetCurMousePosition(const wxPoint &aPosition)
It updates the current mouse position without make any new recalculations on camera.
Definition: ccamera.cpp:401
bool m_mouse_was_moved
true if there was some type of activity, it will be used to render in preview mode ...
virtual wxSize GetClientSize() const
bool m_camera_is_moving
true if camera animation is ongoing
virtual void Drag(const wxPoint &aNewMousePosition)=0
Calculate a new mouse drag position.
bool SetCurWindowSize(const wxSize &aSize)
SetCurWindowSize - update the windows size of the camera.
Definition: ccamera.cpp:428
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
virtual void Pan(const wxPoint &aNewMousePosition)=0
void EDA_3D_CANVAS::OnMouseWheel ( wxMouseEvent &  event)
private

Definition at line 441 of file eda_3d_canvas.cpp.

References CINFO3D_VISU::CameraGet(), DisplayStatus(), FL_MOUSEWHEEL_PANNING, CINFO3D_VISU::GetFlag(), m_camera_is_moving, m_delta_move_step_factor, m_logTrace, m_mouse_is_moving, m_mouse_was_moved, m_settings, CCAMERA::Pan(), Request_refresh(), restart_editingTimeOut_Timer(), CCAMERA::SetCurMousePosition(), CCAMERA::Zoom(), and CCAMERA::ZoomGet().

Referenced by IsReloadRequestPending().

442 {
443  bool mouseActivity = false;
444 
445  wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnMouseWheel" ) );
446 
447  if( m_camera_is_moving )
448  return;
449 
450  float delta_move = m_delta_move_step_factor * m_settings.CameraGet().ZoomGet();
451 
453  delta_move *= (0.01f * event.GetWheelRotation());
454  else
455  if( event.GetWheelRotation() < 0 )
456  delta_move = -delta_move;
457 
458  // mousewheel_panning enabled:
459  // wheel -> pan;
460  // wheel + shift -> horizontal scrolling;
461  // wheel + ctrl -> zooming;
462  // mousewheel_panning disabled:
463  // wheel + shift -> vertical scrolling;
464  // wheel + ctrl -> horizontal scrolling;
465  // wheel -> zooming.
466 
467  if( m_settings.GetFlag( FL_MOUSEWHEEL_PANNING ) && !event.ControlDown() )
468  {
469  if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL || event.ShiftDown() )
470  m_settings.CameraGet().Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
471  else
472  m_settings.CameraGet().Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
473 
474  mouseActivity = true;
475  }
476  else if( event.ShiftDown() && !m_settings.GetFlag( FL_MOUSEWHEEL_PANNING ) )
477  {
478  m_settings.CameraGet().Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
479  mouseActivity = true;
480  }
481  else if( event.ControlDown() && !m_settings.GetFlag( FL_MOUSEWHEEL_PANNING ) )
482  {
483  m_settings.CameraGet().Pan( SFVEC3F( delta_move, 0.0f, 0.0f ) );
484  mouseActivity = true;
485  }
486  else
487  {
488  mouseActivity = m_settings.CameraGet().Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f );
489  }
490 
491  // If it results on a camera movement
492  if( mouseActivity )
493  {
494  DisplayStatus();
495  Request_refresh();
496 
497  m_mouse_is_moving = true;
498  m_mouse_was_moved = true;
499 
501  }
502 
503  // Update the cursor current mouse position on the camera
504  m_settings.CameraGet().SetCurMousePosition( event.GetPosition() );
505 }
float ZoomGet() const
Definition: ccamera.cpp:490
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.
void DisplayStatus()
DisplayStatus - Update the status bar with the position information.
void Request_refresh(bool aRedrawImmediately=true)
Request_refresh - Schedule a refresh update of the canvas.
void SetCurMousePosition(const wxPoint &aPosition)
It updates the current mouse position without make any new recalculations on camera.
Definition: ccamera.cpp:401
bool Zoom(float aFactor)
Definition: ccamera.cpp:454
void restart_editingTimeOut_Timer()
restart_editingTimeOut_Timer - reset the editing timer
bool m_mouse_was_moved
true if there was some type of activity, it will be used to render in preview mode ...
bool m_camera_is_moving
true if camera animation is ongoing
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
virtual void Pan(const wxPoint &aNewMousePosition)=0
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
static const float m_delta_move_step_factor
Step factor to used with cursor on relation to the current zoom.
void EDA_3D_CANVAS::OnPaint ( wxPaintEvent &  event)
private

Definition at line 275 of file eda_3d_canvas.cpp.

References CINFO3D_VISU::CameraGet(), GL_CONTEXT_MANAGER::CreateCtx(), DisplayStatus(), Format(), GL_CONTEXT_MANAGER::Get(), HIDPI_GL_CANVAS::GetClientSize(), GetRunningMicroSecs(), STATUS_TEXT_REPORTER::HasMessage(), initializeOpenGL(), CCAMERA::Interpolate(), GL_CONTEXT_MANAGER::LockCtx(), m_3d_render, m_3d_render_ogl_legacy, m_camera_is_moving, m_camera_moving_speed, m_glRC, m_is_opengl_initialized, m_logTrace, m_mouse_is_moving, m_mouse_was_moved, m_parentStatusBar, m_render_pivot, m_render_raytracing_was_requested, m_settings, m_strtime_camera_movement, min, CCAMERA::ParametersChanged(), C3D_RENDER_BASE::Redraw(), RENDER_ENGINE_OPENGL_LEGACY, render_pivot(), CINFO3D_VISU::RenderEngineGet(), STATUS_TEXT_REPORTER::Report(), Request_refresh(), restart_editingTimeOut_Timer(), scale, C3D_RENDER_BASE::SetCurWindowSize(), CCAMERA::SetCurWindowSize(), GL_CONTEXT_MANAGER::UnlockCtx(), and CCAMERA::ZoomGet().

Referenced by IsReloadRequestPending().

276 {
277  // Please have a look at:
278  // https://lists.launchpad.net/kicad-developers/msg25149.html
279  // wxPaintDC( this );
280  // event.Skip( false );
281 
282  // SwapBuffer requires the window to be shown before calling
283  if( !IsShownOnScreen() )
284  {
285  wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnPaint !IsShown" ) );
286  return;
287  }
288 
289  // Because the board to draw is handled by the parent viewer frame,
290  // ensure this parent is still alive. When it is closed before the viewer
291  // frame, a paint event can be generated after the parent is closed,
292  // therefore with invalid board.
293  // This is dependant of the platform.
294  // Especially on OSX, but also on Windows, it frequently happens
295  if( !GetParent()->GetParent()->IsShown() )
296  return; // The parent board editor frame is no more alive
297 
298  wxString err_messages;
299 
300  // !TODO: implement error reporter
301  //WX_STRING_REPORTER errorReporter( &err_messages );
302  STATUS_TEXT_REPORTER activityReporter( m_parentStatusBar, 0 );
303 
304 
305  unsigned strtime = GetRunningMicroSecs();
306 
307  // "Makes the OpenGL state that is represented by the OpenGL rendering
308  // context context current, i.e. it will be used by all subsequent OpenGL calls.
309  // This function may only be called when the window is shown on screen"
310 
311  // Explicitly create a new rendering context instance for this canvas.
312  if( m_glRC == NULL )
314 
316 
317  // Set the OpenGL viewport according to the client size of this canvas.
318  // This is done here rather than in a wxSizeEvent handler because our
319  // OpenGL rendering context (and thus viewport setting) is used with
320  // multiple canvases: If we updated the viewport in the wxSizeEvent
321  // handler, changing the size of one canvas causes a viewport setting that
322  // is wrong when next another canvas is repainted.
323  wxSize clientSize = GetClientSize();
324 
325  const bool windows_size_changed = m_settings.CameraGet().SetCurWindowSize( clientSize );
326 
327 
328  // Initialize openGL if need
329  // /////////////////////////////////////////////////////////////////////////
331  {
332  if( !initializeOpenGL() )
333  {
335 
336  return;
337  }
338  }
339 
340 
341  // Check if a raytacing was requented and need to switch to raytracing mode
343  {
344  const bool was_camera_changed = m_settings.CameraGet().ParametersChanged();
345 
346  // It reverts back to OpenGL mode if it was requested a raytracing
347  // render of the current scene. AND the mouse / camera is moving
348  if( ( m_mouse_is_moving ||
350  was_camera_changed ||
351  windows_size_changed ) &&
353  {
356  }
357  }
358 
359 
360  float curtime_delta_s = 0.0f;
361 
362  if( m_camera_is_moving )
363  {
364  const unsigned curtime_delta = GetRunningMicroSecs() - m_strtime_camera_movement;
365  curtime_delta_s = (curtime_delta / 1e6) * m_camera_moving_speed;
366  m_settings.CameraGet().Interpolate( curtime_delta_s );
367 
368  if( curtime_delta_s > 1.0f )
369  {
370  m_render_pivot = false;
371  m_camera_is_moving = false;
372  m_mouse_was_moved = true;
373 
375  DisplayStatus();
376  }
377  else
378  {
379  Request_refresh();
380  }
381  }
382 
383 
384  // It will return true if the render request a new redraw
385  bool requested_redraw = false;
386 
387  if( m_3d_render )
388  {
389  m_3d_render->SetCurWindowSize( clientSize );
390 
391  requested_redraw = m_3d_render->Redraw( m_mouse_was_moved || m_camera_is_moving,
392  &activityReporter );
393  }
394 
395  if( m_render_pivot )
396  {
397  const float scale = glm::min( m_settings.CameraGet().ZoomGet(), 1.0f );
398  render_pivot( curtime_delta_s, scale * scale );
399  }
400 
401  // "Swaps the double-buffer of this window, making the back-buffer the
402  // front-buffer and vice versa, so that the output of the previous OpenGL
403  // commands is displayed on the window."
404  SwapBuffers();
405 
407 
408  if( !activityReporter.HasMessage() )
409  {
411  {
412  // Calculation time in miliseconds
413  const double calculation_time = (double)( GetRunningMicroSecs() - strtime) / 1e3;
414 
415  activityReporter.Report( wxString::Format( _( "Render time %.0f ms ( %.1f fps)" ),
416  calculation_time, 1000.0 / calculation_time ) );
417  }
418  }
419 
420  // This will reset the flag of camera parameters changed
422 
423  if( !err_messages.IsEmpty() )
424  wxLogMessage( err_messages );
425 
426  if( (!m_camera_is_moving) && requested_redraw )
427  {
428  m_mouse_was_moved = false;
429  Request_refresh( false );
430  }
431 }
float ZoomGet() const
Definition: ccamera.cpp:490
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.
wxStatusBar * m_parentStatusBar
Parent statusbar to report progress.
wxGLContext * m_glRC
current OpenGL context
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 UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
float m_camera_moving_speed
1.0f will be 1:1
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
void restart_editingTimeOut_Timer()
restart_editingTimeOut_Timer - reset the editing timer
bool m_mouse_was_moved
true if there was some type of activity, it will be used to render in preview mode ...
virtual wxSize GetClientSize() const
Class STATUS_TEXT_REPORTER is a wrapper for reporting to a wxString in a wxFrame status text...
bool m_camera_is_moving
true if camera animation is ongoing
virtual void Interpolate(float t)
Interpolate - It will update the matrix to interpolate between T0 and T1 values.
Definition: ccamera.cpp:549
bool SetCurWindowSize(const wxSize &aSize)
SetCurWindowSize - update the windows size of the camera.
Definition: ccamera.cpp:428
RENDER_ENGINE RenderEngineGet() const
RenderEngineGet.
Definition: cinfo3d_visu.h:234
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it...
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.
virtual bool Redraw(bool aIsMoving, REPORTER *aStatusTextReporter=NULL)=0
Redraw - Ask to redraw the view.
const int scale
bool initializeOpenGL()
initializeOpenGL
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
unsigned GetRunningMicroSecs()
Function GetRunningMicroSecs An alternate way to calculate an elapset time (in microsecondes) to clas...
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=NULL)
Function CreateCtx creates a managed OpenGL context.
virtual void SetCurWindowSize(const wxSize &aSize)=0
SetCurWindowSize - Before each render, the canvas will tell the render what is the size of its window...
void render_pivot(float t, float aScale)
render_pivot - render the pivot cursor
#define min(a, b)
Definition: auxiliary.h:85
bool ParametersChanged()
Function ParametersChanged.
Definition: ccamera.cpp:567
bool m_render_raytracing_was_requested
Flags that the user requested the current view to be render with raytracing.
void EDA_3D_CANVAS::OnPopUpMenu ( wxCommandEvent &  event)
private

Definition at line 685 of file eda_3d_canvas.cpp.

References ID_POPUP_MOVE3D_DOWN, ID_POPUP_MOVE3D_LEFT, ID_POPUP_MOVE3D_RIGHT, ID_POPUP_MOVE3D_UP, ID_POPUP_VIEW_XNEG, ID_POPUP_VIEW_XPOS, ID_POPUP_VIEW_YNEG, ID_POPUP_VIEW_YPOS, ID_POPUP_VIEW_ZNEG, ID_POPUP_VIEW_ZPOS, ID_POPUP_ZOOMIN, ID_POPUP_ZOOMOUT, m_logTrace, and SetView3D().

Referenced by IsReloadRequestPending().

686 {
687  int id = event.GetId();
688 
689  wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnPopUpMenu id:%d" ), id );
690 
691  int key = 0;
692 
693  switch( id )
694  {
695  case ID_POPUP_ZOOMIN:
696  key = WXK_F1;
697  break;
698 
699  case ID_POPUP_ZOOMOUT:
700  key = WXK_F2;
701  break;
702 
703  case ID_POPUP_VIEW_XPOS:
704  key = 'x';
705  break;
706 
707  case ID_POPUP_VIEW_XNEG:
708  key = 'X';
709  break;
710 
711  case ID_POPUP_VIEW_YPOS:
712  key = 'y';
713  break;
714 
715  case ID_POPUP_VIEW_YNEG:
716  key = 'Y';
717  break;
718 
719  case ID_POPUP_VIEW_ZPOS:
720  key = 'z';
721  break;
722 
723  case ID_POPUP_VIEW_ZNEG:
724  key = 'Z';
725  break;
726 
728  key = WXK_LEFT;
729  break;
730 
732  key = WXK_RIGHT;
733  break;
734 
735  case ID_POPUP_MOVE3D_UP:
736  key = WXK_UP;
737  break;
738 
740  key = WXK_DOWN;
741  break;
742 
743  default:
744  return;
745  }
746 
747  SetView3D( key );
748 }
void SetView3D(int keycode)
SetView3D - Helper function to call view commands.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void EDA_3D_CANVAS::OnResize ( wxSizeEvent &  event)
private

Definition at line 192 of file eda_3d_canvas.cpp.

References Request_refresh().

Referenced by IsReloadRequestPending().

193 {
194  this->Request_refresh();
195 }
void Request_refresh(bool aRedrawImmediately=true)
Request_refresh - Schedule a refresh update of the canvas.
void EDA_3D_CANVAS::OnRightClick ( wxMouseEvent &  event)
private

Definition at line 598 of file eda_3d_canvas.cpp.

References AddHotkeyName(), AddMenuItem(), g_3DViewer_Hokeys_Descr, ID_POPUP_MOVE3D_DOWN, ID_POPUP_MOVE3D_LEFT, ID_POPUP_MOVE3D_RIGHT, ID_POPUP_MOVE3D_UP, ID_POPUP_VIEW_XNEG, ID_POPUP_VIEW_XPOS, ID_POPUP_VIEW_YNEG, ID_POPUP_VIEW_YPOS, ID_POPUP_VIEW_ZNEG, ID_POPUP_VIEW_ZPOS, ID_POPUP_ZOOMIN, ID_POPUP_ZOOMOUT, KiBitmap(), m_camera_is_moving, m_logTrace, wxPoint::x, and wxPoint::y.

Referenced by IsReloadRequestPending().

599 {
600  wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnRightClick" ) );
601 
602  if( m_camera_is_moving )
603  return;
604 
605  wxPoint pos;
606  wxMenu PopUpMenu;
607  wxString msg;
608 
609  pos.x = event.GetX();
610  pos.y = event.GetY();
611 
612  msg = AddHotkeyName( _( "Zoom +" ), g_3DViewer_Hokeys_Descr,
613  ID_POPUP_ZOOMIN );
614  AddMenuItem( &PopUpMenu, ID_POPUP_ZOOMIN,
615  msg, KiBitmap( zoom_in_xpm ) );
616 
617 
618  msg = AddHotkeyName( _( "Zoom -" ), g_3DViewer_Hokeys_Descr,
620  AddMenuItem( &PopUpMenu, ID_POPUP_ZOOMOUT,
621  msg, KiBitmap( zoom_out_xpm ) );
622 
623  PopUpMenu.AppendSeparator();
624 
625  msg = AddHotkeyName( _( "Top View" ), g_3DViewer_Hokeys_Descr,
627  AddMenuItem( &PopUpMenu, ID_POPUP_VIEW_ZPOS,
628  msg, KiBitmap( axis3d_top_xpm ) );
629 
630  msg = AddHotkeyName( _( "Bottom View" ), g_3DViewer_Hokeys_Descr,
632  AddMenuItem( &PopUpMenu, ID_POPUP_VIEW_ZNEG,
633  msg, KiBitmap( axis3d_bottom_xpm ) );
634 
635  PopUpMenu.AppendSeparator();
636 
637  msg = AddHotkeyName( _( "Right View" ), g_3DViewer_Hokeys_Descr,
639  AddMenuItem( &PopUpMenu, ID_POPUP_VIEW_XPOS,
640  msg, KiBitmap( axis3d_right_xpm ) );
641 
642  msg = AddHotkeyName( _( "Left View" ), g_3DViewer_Hokeys_Descr,
644  AddMenuItem( &PopUpMenu, ID_POPUP_VIEW_XNEG,
645  msg, KiBitmap( axis3d_left_xpm ) );
646 
647  PopUpMenu.AppendSeparator();
648 
649  msg = AddHotkeyName( _( "Front View" ), g_3DViewer_Hokeys_Descr,
651  AddMenuItem( &PopUpMenu, ID_POPUP_VIEW_YPOS,
652  msg, KiBitmap( axis3d_front_xpm ) );
653 
654  msg = AddHotkeyName( _( "Back View" ), g_3DViewer_Hokeys_Descr,
656  AddMenuItem( &PopUpMenu, ID_POPUP_VIEW_YNEG,
657  msg, KiBitmap( axis3d_back_xpm ) );
658 
659  PopUpMenu.AppendSeparator();
660 
661  msg = AddHotkeyName( _( "Move Left <-" ), g_3DViewer_Hokeys_Descr,
663  AddMenuItem( &PopUpMenu, ID_POPUP_MOVE3D_LEFT,
664  msg, KiBitmap( left_xpm ) );
665 
666  msg = AddHotkeyName( _( "Move Right ->" ), g_3DViewer_Hokeys_Descr,
668  AddMenuItem( &PopUpMenu, ID_POPUP_MOVE3D_RIGHT,
669  msg, KiBitmap( right_xpm ) );
670 
671  msg = AddHotkeyName( _( "Move Up ^" ), g_3DViewer_Hokeys_Descr,
673  AddMenuItem( &PopUpMenu, ID_POPUP_MOVE3D_UP,
674  msg, KiBitmap( up_xpm ) );
675 
676  msg = AddHotkeyName( _( "Move Down" ), g_3DViewer_Hokeys_Descr,
678  AddMenuItem( &PopUpMenu, ID_POPUP_MOVE3D_DOWN,
679  msg, KiBitmap( down_xpm ) );
680 
681  PopupMenu( &PopUpMenu, pos );
682 }
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:174
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
bool m_camera_is_moving
true if camera animation is ongoing
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
struct EDA_HOTKEY_CONFIG g_3DViewer_Hokeys_Descr[]
void EDA_3D_CANVAS::OnTimerTimeout_Editing ( wxTimerEvent &  event)
private

Definition at line 770 of file eda_3d_canvas.cpp.

References m_mouse_is_moving, m_mouse_was_moved, and Request_refresh().

Referenced by EVT_MENU_RANGE(), and IsReloadRequestPending().

771 {
772  (void)event;
773 
774  m_mouse_is_moving = false;
775  m_mouse_was_moved = false;
776 
777  Request_refresh();
778 }
bool m_mouse_is_moving
true if mouse activity is on progress
void Request_refresh(bool aRedrawImmediately=true)
Request_refresh - Schedule a refresh update of the canvas.
bool m_mouse_was_moved
true if there was some type of activity, it will be used to render in preview mode ...
void EDA_3D_CANVAS::OnTimerTimeout_Redraw ( wxTimerEvent &  event)
private

Definition at line 793 of file eda_3d_canvas.cpp.

Referenced by EVT_MENU_RANGE(), and IsReloadRequestPending().

794 {
795  (void)event;
796 
797  //Refresh();
798  //Update();
799 
800  wxPaintEvent redrawEvent;
801  wxPostEvent( this, redrawEvent );
802 }
void EDA_3D_CANVAS::releaseOpenGL ( )
private

releaseOpenGL - free created targets and openGL context

Definition at line 163 of file eda_3d_canvas.cpp.

References GL_CONTEXT_MANAGER::DestroyCtx(), GL_CONTEXT_MANAGER::Get(), GL_CONTEXT_MANAGER::LockCtx(), m_3d_render, m_3d_render_ogl_legacy, m_3d_render_raytracing, m_glRC, and GL_CONTEXT_MANAGER::UnlockCtx().

Referenced by IsReloadRequestPending(), OnCloseWindow(), and ~EDA_3D_CANVAS().

164 {
165  if( m_glRC )
166  {
168 
169  delete m_3d_render_raytracing;
170  m_3d_render_raytracing = NULL;
171 
172  delete m_3d_render_ogl_legacy;
173  m_3d_render_ogl_legacy = NULL;
174 
175  // This is just a copy of a pointer, can safelly be set to NULL
176  m_3d_render = NULL;
177 
180  m_glRC = NULL;
181  }
182 }
C3D_RENDER_RAYTRACING * m_3d_render_raytracing
Raytracing render class.
wxGLContext * m_glRC
current OpenGL context
C3D_RENDER_OGL_LEGACY * m_3d_render_ogl_legacy
OpenGL legacy render class.
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it...
C3D_RENDER_BASE * m_3d_render
The current render in used for this canvas.
void DestroyCtx(wxGLContext *aContext)
Function DestroyCtx destroys a managed OpenGL context.
void EDA_3D_CANVAS::ReloadRequest ( BOARD aBoard = NULL,
S3D_CACHE aCachePointer = NULL 
)

Definition at line 230 of file eda_3d_canvas.cpp.

References m_3d_render, m_settings, C3D_RENDER_BASE::ReloadRequest(), CINFO3D_VISU::Set3DCacheManager(), and CINFO3D_VISU::SetBoard().

Referenced by EDA_3D_VIEWER::ReloadRequest(), PANEL_PREV_3D::ResetModelData(), PANEL_PREV_3D::SetModelDataIdx(), SetStatusBar(), SetView3D(), PANEL_PREV_3D::UpdateModelName(), and PANEL_PREV_3D::View3DUpdate().

231 {
232  if( aCachePointer != NULL )
233  m_settings.Set3DCacheManager( aCachePointer );
234 
235  if( aBoard != NULL )
236  m_settings.SetBoard( aBoard );
237 
238  if( m_3d_render )
240 }
CINFO3D_VISU & m_settings
Stores all pre-computed 3D information and visualization settings to render the board.
C3D_RENDER_BASE * m_3d_render
The current render in used for this canvas.
void ReloadRequest()
ReloadRequest - !TODO: this must be reviewed to add flags to improve specific render.
void SetBoard(BOARD *aBoard)
SetBoard - Set current board to be rendered.
Definition: cinfo3d_visu.h:122
void Set3DCacheManager(S3D_CACHE *aCachePointer)
Set3DCacheManager - Update the Cache manager pointer.
Definition: cinfo3d_visu.h:82
void EDA_3D_CANVAS::render_pivot ( float  t,
float  aScale 
)
private

render_pivot - render the pivot cursor

Parameters
ttime between 0.0 and 1.0
aScalescale to apply on the cursor

Definition at line 76 of file eda_3d_canvas_pivot.cpp.

References CINFO3D_VISU::CameraGet(), CCAMERA::GetLookAtPos_T1(), CCAMERA::GetProjectionMatrix(), CCAMERA::GetViewMatrix(), m_settings, and pivot_render_triangles().

Referenced by IsReloadRequestPending(), and OnPaint().

77 {
78  wxASSERT( aScale >= 0.0f );
79  wxASSERT( t >= 0.0f );
80 
81  if( t > 1.0f )
82  t = 1.0f;
83 
84  const SFVEC3F &lookAtPos = m_settings.CameraGet().GetLookAtPos_T1();
85 
86  glDisable( GL_LIGHTING );
87  glDisable( GL_DEPTH_TEST );
88  glDisable( GL_CULL_FACE );
89 
90  // Set projection and modelview matrixes
91  // /////////////////////////////////////////////////////////////////////////
92  glMatrixMode( GL_PROJECTION );
93  glLoadMatrixf( glm::value_ptr( m_settings.CameraGet().GetProjectionMatrix() ) );
94 
95  glMatrixMode( GL_MODELVIEW );
96  glLoadIdentity();
97  glLoadMatrixf( glm::value_ptr( m_settings.CameraGet().GetViewMatrix() ) );
98 
99  glEnable( GL_COLOR_MATERIAL );
100  glColor4f( 0.0f, 1.0f, 0.0f, 0.75f - t * 0.75f );
101 
102  // Translate to the look at position
103  glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z );
104 
105  glScalef( aScale, aScale, aScale );
106 
107  pivot_render_triangles( t * 0.5f );
108 
109  t = t * 0.80f;
110  glScalef( 1.0f - t, 1.0f - t, 1.0f - t );
111  glColor4f( 0.0f, 1.0f, 0.0f, 0.8f - t );
112 
113  glPushMatrix();
114  glRotatef( t * 90.0f, 0.0f, 0.0f, 1.0f );
115  pivot_render_triangles( t * 0.5f );
116  glPopMatrix();
117 
118  glPushMatrix();
119  glRotatef( -t * 90.0f, 0.0f, 0.0f, 1.0f );
120  pivot_render_triangles( t * 0.5f );
121  glPopMatrix();
122 }
CINFO3D_VISU & m_settings
Stores all pre-computed 3D information and visualization settings to render the board.
const glm::mat4 & GetProjectionMatrix() const
Definition: ccamera.cpp:359
const glm::mat4 & GetViewMatrix() const
Definition: ccamera.cpp:389
const SFVEC3F & GetLookAtPos_T1() const
Definition: ccamera.h:129
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
static void pivot_render_triangles(float t)
void EDA_3D_CANVAS::RenderEngineChanged ( )

RenderEngineChanged - Notify that the render engine was changed.

Definition at line 1051 of file eda_3d_canvas.cpp.

References m_3d_render, m_3d_render_ogl_legacy, m_3d_render_raytracing, m_mouse_was_moved, m_settings, C3D_RENDER_BASE::ReloadRequest(), RENDER_ENGINE_OPENGL_LEGACY, RENDER_ENGINE_RAYTRACING, CINFO3D_VISU::RenderEngineGet(), and Request_refresh().

Referenced by IsReloadRequestPending(), and EDA_3D_VIEWER::RenderEngineChanged().

1052 {
1053 
1054  switch( m_settings.RenderEngineGet() )
1055  {
1058  break;
1059 
1062  break;
1063 
1064  default:
1065  m_3d_render = NULL;
1066  break;
1067  }
1068 
1069  if( m_3d_render )
1071 
1072  m_mouse_was_moved = false;
1073 
1074  Request_refresh();
1075 }
C3D_RENDER_RAYTRACING * m_3d_render_raytracing
Raytracing render class.
CINFO3D_VISU & m_settings
Stores all pre-computed 3D information and visualization settings to render the board.
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.
bool m_mouse_was_moved
true if there was some type of activity, it will be used to render in preview mode ...
RENDER_ENGINE RenderEngineGet() const
RenderEngineGet.
Definition: cinfo3d_visu.h:234
C3D_RENDER_BASE * m_3d_render
The current render in used for this canvas.
void ReloadRequest()
ReloadRequest - !TODO: this must be reviewed to add flags to improve specific render.
void EDA_3D_CANVAS::RenderRaytracingRequest ( )

RenderRaytracingRequest - Request to render the current view in Raytracing mode.

Definition at line 243 of file eda_3d_canvas.cpp.

References m_3d_render, m_3d_render_raytracing, m_render_raytracing_was_requested, C3D_RENDER_BASE::ReloadRequest(), and Request_refresh().

Referenced by IsReloadRequestPending(), and EDA_3D_VIEWER::Process_Special_Functions().

244 {
246 
247  if( m_3d_render )
249 
251  //m_mouse_was_moved = true;
252 
253  Request_refresh();
254 }
C3D_RENDER_RAYTRACING * m_3d_render_raytracing
Raytracing render class.
void Request_refresh(bool aRedrawImmediately=true)
Request_refresh - Schedule a refresh update of the canvas.
C3D_RENDER_BASE * m_3d_render
The current render in used for this canvas.
void ReloadRequest()
ReloadRequest - !TODO: this must be reviewed to add flags to improve specific render.
bool m_render_raytracing_was_requested
Flags that the user requested the current view to be render with raytracing.
void EDA_3D_CANVAS::Request_refresh ( bool  aRedrawImmediately = true)

Request_refresh - Schedule a refresh update of the canvas.

Parameters
aRedrawImmediately- true will request a redraw, false will schedule a redraw, after a short timeout.

Definition at line 805 of file eda_3d_canvas.cpp.

References m_redraw_trigger_timer.

Referenced by IsReloadRequestPending(), EDA_3D_VIEWER::On3DGridSelection(), EDA_3D_VIEWER::OnActivate(), OnMouseMove(), OnMouseWheel(), OnPaint(), OnResize(), OnTimerTimeout_Editing(), EDA_3D_VIEWER::Process_Special_Functions(), EDA_3D_VIEWER::ProcessZoom(), RenderEngineChanged(), RenderRaytracingRequest(), request_start_moving_camera(), PANEL_PREV_3D::ResetModelData(), PANEL_PREV_3D::SetModelDataIdx(), and SetView3D().

806 {
807  if( aRedrawImmediately )
808  {
809  // On some systems, just calling Refresh does not work always
810  // (Issue experienced on Win7 MSYS2)
811  //Refresh();
812  //Update();
813 
814  // Using PostEvent will take priority to other events, like
815  // mouse movements, keys, etc.
816  wxPaintEvent redrawEvent;
817  wxPostEvent( this, redrawEvent );
818 
819  // This behaves the same
820  // wxQueueEvent( this,
821  // From wxWidget documentation: "The heap-allocated and
822  // non-NULL event to queue, the function takes ownership of it."
823  // new wxPaintEvent()
824  // );
825  }
826  else
827  {
828  // Schedule a timed redraw
829  m_redraw_trigger_timer.Start( 10 , wxTIMER_ONE_SHOT );
830  }
831 }
wxTimer m_redraw_trigger_timer
This timer will be used to schedule a redraw event.
void EDA_3D_CANVAS::request_start_moving_camera ( float  aMovingSpeed = 2.0f,
bool  aRenderPivot = true 
)
private

request_start_moving_camera - start a camera movement

Parameters
aMovingSpeedthe time speed
aRenderPivotif it should display pivot cursor while move

Definition at line 834 of file eda_3d_canvas.cpp.

References DisplayStatus(), GetRunningMicroSecs(), m_camera_is_moving, m_camera_moving_speed, m_render_pivot, m_strtime_camera_movement, Request_refresh(), and stop_editingTimeOut_Timer().

Referenced by IsReloadRequestPending(), move_pivot_based_on_cur_mouse_position(), and SetView3D().

835 {
836  wxASSERT( aMovingSpeed > FLT_EPSILON );
837 
838  m_render_pivot = aRenderPivot;
839  m_camera_moving_speed = aMovingSpeed;
840 
842 
843  DisplayStatus();
844  Request_refresh();
845 
846  m_camera_is_moving = true;
847 
849 }
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
void DisplayStatus()
DisplayStatus - Update the status bar with the position information.
void Request_refresh(bool aRedrawImmediately=true)
Request_refresh - Schedule a refresh update of the canvas.
float m_camera_moving_speed
1.0f will be 1:1
bool m_camera_is_moving
true if camera animation is ongoing
bool m_render_pivot
activated the render of pivot while camera moving
unsigned GetRunningMicroSecs()
Function GetRunningMicroSecs An alternate way to calculate an elapset time (in microsecondes) to clas...
void EDA_3D_CANVAS::restart_editingTimeOut_Timer ( )
private

restart_editingTimeOut_Timer - reset the editing timer

Definition at line 787 of file eda_3d_canvas.cpp.

References C3D_RENDER_BASE::GetWaitForEditingTimeOut(), m_3d_render, and m_editing_timeout_timer.

Referenced by IsReloadRequestPending(), OnLeftUp(), OnMiddleUp(), OnMouseWheel(), OnPaint(), and SetView3D().

788 {
789  m_editing_timeout_timer.Start( m_3d_render->GetWaitForEditingTimeOut() , wxTIMER_ONE_SHOT );
790 }
wxTimer m_editing_timeout_timer
Time timeout will expires after some time sinalizing that the mouse / keyboard movements are over...
virtual int GetWaitForEditingTimeOut()=0
GetWaitForEditingTimeOut - Give the interface the time (in ms) that it should wait for editing or mov...
C3D_RENDER_BASE * m_3d_render
The current render in used for this canvas.
void EDA_3D_CANVAS::SetStatusBar ( wxStatusBar *  aStatusBar)
inline

Definition at line 74 of file eda_3d_canvas.h.

References m_parentStatusBar, and ReloadRequest().

Referenced by EDA_3D_VIEWER::EDA_3D_VIEWER().

74 { m_parentStatusBar = aStatusBar; }
wxStatusBar * m_parentStatusBar
Parent statusbar to report progress.
void EDA_3D_CANVAS::SetView3D ( int  keycode)

SetView3D - Helper function to call view commands.

Parameters
keycodeascii key commands

Definition at line 878 of file eda_3d_canvas.cpp.

References CINFO3D_VISU::CameraGet(), DisplayStatus(), FL_MODULE_ATTRIBUTES_NORMAL, FL_MODULE_ATTRIBUTES_NORMAL_INSERT, FL_MODULE_ATTRIBUTES_VIRTUAL, CINFO3D_VISU::GetFlag(), INTERPOLATION_BEZIER, INTERPOLATION_EASING_IN_OUT, INTERPOLATION_LINEAR, m_camera_is_moving, m_delta_move_step_factor, m_mouse_was_moved, m_settings, max, min, move_pivot_based_on_cur_mouse_position(), CCAMERA::Pan_T1(), ReloadRequest(), Request_refresh(), request_start_moving_camera(), CCAMERA::Reset_T1(), restart_editingTimeOut_Timer(), CCAMERA::RotateX_T1(), CCAMERA::RotateZ_T1(), CINFO3D_VISU::SetFlag(), CCAMERA::SetInterpolateMode(), CCAMERA::SetT0_and_T1_current_T(), CCAMERA::Zoom_T1(), and CCAMERA::ZoomGet().

Referenced by IsReloadRequestPending(), OnKeyEvent(), OnPopUpMenu(), EDA_3D_VIEWER::Process_Special_Functions(), EDA_3D_VIEWER::ProcessZoom(), PANEL_PREV_3D::View3DBack(), PANEL_PREV_3D::View3DBottom(), PANEL_PREV_3D::View3DFront(), PANEL_PREV_3D::View3DLeft(), PANEL_PREV_3D::View3DRight(), and PANEL_PREV_3D::View3DTop().

879 {
880  if( m_camera_is_moving )
881  return;
882 
883  const float delta_move = m_delta_move_step_factor * m_settings.CameraGet().ZoomGet();
884  const float arrow_moving_time_speed = 8.0f;
885 
886  switch( keycode )
887  {
888  case WXK_SPACE:
890  return;
891 
892  case WXK_LEFT:
895  m_settings.CameraGet().Pan_T1( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
896  request_start_moving_camera( arrow_moving_time_speed, false );
897  return;
898 
899  case WXK_RIGHT:
902  m_settings.CameraGet().Pan_T1( SFVEC3F( +delta_move, 0.0f, 0.0f ) );
903  request_start_moving_camera( arrow_moving_time_speed, false );
904  return;
905 
906  case WXK_UP:
909  m_settings.CameraGet().Pan_T1( SFVEC3F( 0.0f, +delta_move, 0.0f ) );
910  request_start_moving_camera( arrow_moving_time_speed, false );
911  return;
912 
913  case WXK_DOWN:
916  m_settings.CameraGet().Pan_T1( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
917  request_start_moving_camera( arrow_moving_time_speed, false );
918  return;
919 
920  case WXK_HOME:
925  return;
926 
927  case WXK_END:
928  break;
929 
930  case WXK_TAB:
933  m_settings.CameraGet().RotateZ_T1( glm::radians( 45.0f ) );
935  break;
936 
937  case WXK_F1:
940  if( m_settings.CameraGet().Zoom_T1( 1.4f ) )
942  return;
943 
944  case WXK_F2:
947  if( m_settings.CameraGet().Zoom_T1( 1/1.4f ) )
949  return;
950 
951  case '+':
952  break;
953 
954  case '-':
955  break;
956 
957  case 't':
958  case 'T':
961  ReloadRequest();
962  break;
963 
964  case 's':
965  case 'S':
968  ReloadRequest();
969  break;
970 
971  case 'v':
972  case 'V':
975  ReloadRequest();
976  break;
977 
978  case 'r':
979  case 'R':
984  return;
985 
986  case 'x':
990  m_settings.CameraGet().RotateZ_T1( glm::radians( -90.0f ) );
991  m_settings.CameraGet().RotateX_T1( glm::radians( -90.0f ) );
993  return;
994 
995  case 'X':
999  m_settings.CameraGet().RotateZ_T1( glm::radians( 90.0f ) );
1000  m_settings.CameraGet().RotateX_T1( glm::radians( -90.0f ) );
1002  return;
1003 
1004  case 'y':
1008  m_settings.CameraGet().RotateX_T1( glm::radians( -90.0f ) );
1010  return;
1011 
1012  case 'Y':
1016  m_settings.CameraGet().RotateX_T1( glm::radians( -90.0f ) );
1017  m_settings.CameraGet().RotateZ_T1( glm::radians( -180.0f ) );
1019  return;
1020 
1021  case 'z':
1026  glm::min( glm::max( m_settings.CameraGet().ZoomGet(), 0.5f ), 1.125f ) );
1027  return;
1028 
1029  case 'Z':
1033  m_settings.CameraGet().RotateX_T1( glm::radians( -180.0f ) );
1035  glm::min( glm::max( m_settings.CameraGet().ZoomGet(), 0.5f ), 1.125f ) );
1036  return;
1037 
1038  default:
1039  return;
1040  }
1041 
1042  m_mouse_was_moved = true;
1043 
1045 
1046  DisplayStatus();
1047  Request_refresh();
1048 }
float ZoomGet() const
Definition: ccamera.cpp:490
void request_start_moving_camera(float aMovingSpeed=2.0f, bool aRenderPivot=true)
request_start_moving_camera - start a camera movement
virtual void SetT0_and_T1_current_T()
SetT0_and_T1_current_T - This will set T0 and T1 with the current values.
Definition: ccamera.cpp:535
CINFO3D_VISU & m_settings
Stores all pre-computed 3D information and visualization settings to render the board.
void DisplayStatus()
DisplayStatus - Update the status bar with the position information.
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 restart_editingTimeOut_Timer()
restart_editingTimeOut_Timer - reset the editing timer
bool m_mouse_was_moved
true if there was some type of activity, it will be used to render in preview mode ...
bool m_camera_is_moving
true if camera animation is ongoing
bool Zoom_T1(float aFactor)
Definition: ccamera.cpp:473
virtual void Pan_T1(const SFVEC3F &aDeltaOffsetInc)=0
void RotateX_T1(float aAngleInRadians)
Definition: ccamera.cpp:517
virtual void Reset_T1()
Definition: ccamera.cpp:92
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
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 ...
#define max(a, b)
Definition: auxiliary.h:86
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
void SetFlag(DISPLAY3D_FLG aFlag, bool aState)
SetFlag - set the status of a flag.
void RotateZ_T1(float aAngleInRadians)
Definition: ccamera.cpp:529
static const float m_delta_move_step_factor
Step factor to used with cursor on relation to the current zoom.
void SetInterpolateMode(CAMERA_INTERPOLATION aInterpolateMode)
Definition: ccamera.h:198
#define min(a, b)
Definition: auxiliary.h:85
void EDA_3D_CANVAS::stop_editingTimeOut_Timer ( )
private

stop_editingTimeOut_Timer - stop the editing time, so it will not timeout

Definition at line 781 of file eda_3d_canvas.cpp.

References m_editing_timeout_timer.

Referenced by IsReloadRequestPending(), OnLeftDown(), OnMiddleDown(), and request_start_moving_camera().

782 {
784 }
wxTimer m_editing_timeout_timer
Time timeout will expires after some time sinalizing that the mouse / keyboard movements are over...

Member Data Documentation

C3D_RENDER_BASE* EDA_3D_CANVAS::m_3d_render
private

The current render in used for this canvas.

Definition at line 254 of file eda_3d_canvas.h.

Referenced by IsReloadRequestPending(), OnPaint(), releaseOpenGL(), ReloadRequest(), RenderEngineChanged(), RenderRaytracingRequest(), and restart_editingTimeOut_Timer().

C3D_RENDER_OGL_LEGACY* EDA_3D_CANVAS::m_3d_render_ogl_legacy
private

OpenGL legacy render class.

Definition at line 260 of file eda_3d_canvas.h.

Referenced by OnPaint(), releaseOpenGL(), and RenderEngineChanged().

C3D_RENDER_RAYTRACING* EDA_3D_CANVAS::m_3d_render_raytracing
private

Raytracing render class.

Definition at line 257 of file eda_3d_canvas.h.

Referenced by releaseOpenGL(), RenderEngineChanged(), and RenderRaytracingRequest().

bool EDA_3D_CANVAS::m_camera_is_moving
private

true if camera animation is ongoing

Definition at line 239 of file eda_3d_canvas.h.

Referenced by OnKeyEvent(), OnLeftUp(), OnMiddleUp(), OnMouseMove(), OnMouseWheel(), OnPaint(), OnRightClick(), request_start_moving_camera(), and SetView3D().

float EDA_3D_CANVAS::m_camera_moving_speed
private

1.0f will be 1:1

Definition at line 245 of file eda_3d_canvas.h.

Referenced by OnPaint(), and request_start_moving_camera().

const float EDA_3D_CANVAS::m_delta_move_step_factor = 0.7f
staticprivate

Step factor to used with cursor on relation to the current zoom.

Definition at line 266 of file eda_3d_canvas.h.

Referenced by OnMouseWheel(), and SetView3D().

wxTimer EDA_3D_CANVAS::m_editing_timeout_timer
private

Time timeout will expires after some time sinalizing that the mouse / keyboard movements are over.

Definition at line 226 of file eda_3d_canvas.h.

Referenced by restart_editingTimeOut_Timer(), and stop_editingTimeOut_Timer().

wxGLContext* EDA_3D_CANVAS::m_glRC
private

current OpenGL context

Definition at line 219 of file eda_3d_canvas.h.

Referenced by OnPaint(), and releaseOpenGL().

bool EDA_3D_CANVAS::m_is_opengl_initialized
private

Flag to store if opengl was initialized already.

Definition at line 263 of file eda_3d_canvas.h.

Referenced by initializeOpenGL(), and OnPaint().

const wxChar * EDA_3D_CANVAS::m_logTrace = wxT( "KI_TRACE_EDA_3D_CANVAS" )
staticprivate

Trace mask used to enable or disable the trace output of this class.

The debug output can be turned on by setting the WXTRACE environment variable to "KI_TRACE_EDA_3D_CANVAS". See the wxWidgets documentation on wxLogTrace for more information.

Definition at line 277 of file eda_3d_canvas.h.

Referenced by initializeOpenGL(), OnEraseBackground(), OnMouseWheel(), OnPaint(), OnPopUpMenu(), OnRightClick(), and ~EDA_3D_CANVAS().

bool EDA_3D_CANVAS::m_mouse_is_moving
private

true if mouse activity is on progress

Definition at line 232 of file eda_3d_canvas.h.

Referenced by OnLeftUp(), OnMiddleUp(), OnMouseMove(), OnMouseWheel(), OnPaint(), and OnTimerTimeout_Editing().

bool EDA_3D_CANVAS::m_mouse_was_moved
private

true if there was some type of activity, it will be used to render in preview mode

Definition at line 236 of file eda_3d_canvas.h.

Referenced by OnMouseMove(), OnMouseWheel(), OnPaint(), OnTimerTimeout_Editing(), RenderEngineChanged(), and SetView3D().

wxStatusBar* EDA_3D_CANVAS::m_parentStatusBar
private

Parent statusbar to report progress.

Definition at line 222 of file eda_3d_canvas.h.

Referenced by DisplayStatus(), OnPaint(), and SetStatusBar().

wxTimer EDA_3D_CANVAS::m_redraw_trigger_timer
private

This timer will be used to schedule a redraw event.

Definition at line 229 of file eda_3d_canvas.h.

Referenced by Request_refresh().

bool EDA_3D_CANVAS::m_render_pivot
private

activated the render of pivot while camera moving

Definition at line 242 of file eda_3d_canvas.h.

Referenced by OnPaint(), and request_start_moving_camera().

bool EDA_3D_CANVAS::m_render_raytracing_was_requested
private

Flags that the user requested the current view to be render with raytracing.

Definition at line 269 of file eda_3d_canvas.h.

Referenced by OnPaint(), and RenderRaytracingRequest().

CINFO3D_VISU& EDA_3D_CANVAS::m_settings
private

Stores all pre-computed 3D information and visualization settings to render the board.

Definition at line 251 of file eda_3d_canvas.h.

Referenced by DisplayStatus(), move_pivot_based_on_cur_mouse_position(), OnMouseMove(), OnMouseWheel(), OnPaint(), ReloadRequest(), render_pivot(), RenderEngineChanged(), and SetView3D().

unsigned EDA_3D_CANVAS::m_strtime_camera_movement
private

Stores the ticktime when the camera star its movement.

Definition at line 248 of file eda_3d_canvas.h.

Referenced by OnPaint(), and request_start_moving_camera().


The documentation for this class was generated from the following files: