KiCad PCB EDA Suite
EDA_3D_CANVAS Class Reference

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, BOARD_ADAPTER &aSettings, CAMERA &aCamera, S3D_CACHE *a3DCachePointer)
 Create a new 3D Canvas with an attribute list. More...
 
 ~EDA_3D_CANVAS ()
 
void SetEventDispatcher (TOOL_DISPATCHER *aEventDispatcher)
 Set a dispatcher that processes events and forwards them to tools. More...
 
void SetStatusBar (wxStatusBar *aStatusBar)
 
void SetInfoBar (WX_INFOBAR *aInfoBar)
 
void ReloadRequest (BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
 
bool IsReloadRequestPending () const
 Query if there is a pending reload request. More...
 
RENDER_3D_BASEGetCurrentRender () const
 
void 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...
 
bool SetView3D (int aKeycode)
 Helper function to call view commands. More...
 
void SetAnimationEnabled (bool aEnable)
 Enable or disable camera animation when switching to a pre-defined view. More...
 
bool GetAnimationEnabled () const
 
void SetMovingSpeedMultiplier (int aMultiplier)
 Set the camera animation moving speed multiplier option. More...
 
int GetMovingSpeedMultiplier () const
 
int GetProjectionMode () const
 
void SetProjectionMode (int aMode)
 
void RenderEngineChanged ()
 Notify that the render engine was changed. More...
 
void DisplayStatus ()
 Update the status bar with the position information. More...
 
void Request_refresh (bool aRedrawImmediately=true)
 Schedule a refresh update of the canvas. More...
 
void OnEvent (wxEvent &aEvent)
 Used to forward events to the canvas from popups, etc. More...
 
virtual wxSize GetNativePixelSize () const
 
wxPoint GetNativePosition (const wxPoint &aPoint) const
 Convert the given point from client coordinates to native pixel coordinates. More...
 
void SetScaleFactor (double aFactor)
 Set the canvas scale factor, probably for a hi-DPI display. More...
 
double GetScaleFactor () const
 Get the current scale factor. More...
 

Private Member Functions

void OnPaint (wxPaintEvent &aEvent)
 Called by a wxPaintEvent event. More...
 
void DoRePaint ()
 The actual function to repaint the canvas. More...
 
void OnEraseBackground (wxEraseEvent &event)
 
void OnRefreshRequest (wxEvent &aEvent)
 
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 OnTimerTimeout_Editing (wxTimerEvent &event)
 
void OnCloseWindow (wxCloseEvent &event)
 
void OnResize (wxSizeEvent &event)
 
void OnTimerTimeout_Redraw (wxTimerEvent &event)
 
void stop_editingTimeOut_Timer ()
 Stop the editing time so it will not timeout. More...
 
void restart_editingTimeOut_Timer ()
 Reset the editing timer. More...
 
void request_start_moving_camera (float aMovingSpeed=2.0f, bool aRenderPivot=true)
 Start a camera movement. More...
 
void move_pivot_based_on_cur_mouse_position ()
 This function hits a ray to the board and start a movement. More...
 
void render_pivot (float t, float aScale)
 Render the pivot cursor. More...
 
bool initializeOpenGL ()
 
void releaseOpenGL ()
 Free created targets and openGL context. More...
 
RAY getRayAtCurrrentMousePosition ()
 

Private Attributes

TOOL_DISPATCHERm_eventDispatcher
 
wxStatusBar * m_parentStatusBar
 
WX_INFOBARm_parentInfoBar
 
wxGLContext * m_glRC
 
bool m_is_opengl_initialized
 
bool m_is_opengl_version_supported
 
wxTimer m_editing_timeout_timer
 
wxTimer m_redraw_trigger_timer
 
std::atomic_flag m_is_currently_painting
 
bool m_mouse_is_moving
 
bool m_mouse_was_moved
 
bool m_camera_is_moving
 
bool m_render_pivot
 
float m_camera_moving_speed
 
unsigned m_strtime_camera_movement
 
bool m_animation_enabled
 
int m_moving_speed_multiplier
 
BOARD_ADAPTERm_boardAdapter
 
CAMERAm_camera
 
RENDER_3D_BASEm_3d_render
 
RENDER_3D_RAYTRACEm_3d_render_raytracing
 
RENDER_3D_OPENGLm_3d_render_opengl
 
bool m_opengl_supports_raytracing
 
bool m_render_raytracing_was_requested
 
ACCELERATOR_3Dm_accelerator3DShapes
 
BOARD_ITEMm_currentRollOverItem
 

Static Private Attributes

static const float m_delta_move_step_factor = 0.7f
 
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

Implement a canvas based on a wxGLCanvas.

Definition at line 48 of file eda_3d_canvas.h.

Constructor & Destructor Documentation

◆ EDA_3D_CANVAS()

EDA_3D_CANVAS::EDA_3D_CANVAS ( wxWindow *  aParent,
const int *  aAttribList,
BOARD_ADAPTER aSettings,
CAMERA aCamera,
S3D_CACHE a3DCachePointer 
)

Create a new 3D Canvas with an 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.

Definition at line 90 of file eda_3d_canvas.cpp.

93  : HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
94  wxFULL_REPAINT_ON_RESIZE ),
95  m_eventDispatcher( nullptr ),
96  m_parentStatusBar( nullptr ),
97  m_parentInfoBar( nullptr ),
98  m_glRC( nullptr ),
99  m_is_opengl_initialized( false ),
101  m_mouse_is_moving( false ),
102  m_mouse_was_moved( false ),
103  m_camera_is_moving( false ),
104  m_render_pivot( false ),
105  m_camera_moving_speed( 1.0f ),
107  m_animation_enabled( true ),
109  m_boardAdapter( aBoardAdapter ),
110  m_camera( aCamera ),
111  m_3d_render( nullptr ),
114  m_accelerator3DShapes( nullptr ),
115  m_currentRollOverItem( nullptr )
116 {
117  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::EDA_3D_CANVAS" );
118 
119  m_editing_timeout_timer.SetOwner( this );
120  Connect( m_editing_timeout_timer.GetId(), wxEVT_TIMER,
121  wxTimerEventHandler( EDA_3D_CANVAS::OnTimerTimeout_Editing ), nullptr, this );
122 
123  m_redraw_trigger_timer.SetOwner( this );
124  Connect( m_redraw_trigger_timer.GetId(), wxEVT_TIMER,
125  wxTimerEventHandler( EDA_3D_CANVAS::OnTimerTimeout_Redraw ), nullptr, this );
126 
127  m_is_currently_painting.clear();
128 
131 
132  wxASSERT( m_3d_render_raytracing != nullptr );
133  wxASSERT( m_3d_render_opengl != nullptr );
134 
135  auto busy_indicator_factory = []() { return std::make_unique<WX_BUSY_INDICATOR>(); };
136 
137  m_3d_render_raytracing->SetBusyIndicatorFactory( busy_indicator_factory );
138  m_3d_render_opengl->SetBusyIndicatorFactory( busy_indicator_factory );
139 
141 
142  m_boardAdapter.SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
143 
144  wxASSERT( a3DCachePointer != nullptr );
145  m_boardAdapter.Set3dCacheManager( a3DCachePointer );
146 
147  const wxEventType events[] =
148  {
149  // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events,
150  // especially special key like arrow keys, are handled by the GAL event dispatcher,
151  // and not sent to GUI without filtering, because they have a default action (scroll)
152  // that must not be called.
153  wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK,
154  wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK,
155  wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK,
156  wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, wxEVT_CHAR_HOOK,
157 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
158  wxEVT_MAGNIFY,
159 #endif
160  wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT
161  };
162 
163  for( wxEventType eventType : events )
164  Connect( eventType, wxEventHandler( EDA_3D_CANVAS::OnEvent ), nullptr, m_eventDispatcher );
165 }
Object to render the board using openGL.
bool m_mouse_is_moving
unsigned m_strtime_camera_movement
WX_INFOBAR * m_parentInfoBar
wxStatusBar * m_parentStatusBar
wxGLContext * m_glRC
wxTimer m_editing_timeout_timer
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
HIDPI_GL_CANVAS(wxWindow *parent, wxWindowID id=wxID_ANY, const int *attribList=nullptr, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxGLCanvasName, const wxPalette &palette=wxNullPalette)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
BOARD_ADAPTER & m_boardAdapter
float m_camera_moving_speed
bool m_is_opengl_version_supported
void Set3dCacheManager(S3D_CACHE *aCachePointer) noexcept
Update the cache manager pointer.
Definition: board_adapter.h:80
bool m_mouse_was_moved
void RenderEngineChanged()
Notify that the render engine was changed.
RENDER_3D_RAYTRACE * m_3d_render_raytracing
bool m_camera_is_moving
RENDER_3D_BASE * m_3d_render
void SetBusyIndicatorFactory(BUSY_INDICATOR::FACTORY aNewFactory)
Set a new busy indicator factory.
void OnTimerTimeout_Redraw(wxTimerEvent &event)
SETTINGS_MANAGER * GetSettingsManager()
bool m_animation_enabled
bool m_is_opengl_initialized
TOOL_DISPATCHER * m_eventDispatcher
int m_moving_speed_multiplier
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
bool m_opengl_supports_raytracing
ACCELERATOR_3D * m_accelerator3DShapes
std::atomic_flag m_is_currently_painting
RENDER_3D_OPENGL * m_3d_render_opengl
void OnTimerTimeout_Editing(wxTimerEvent &event)
void SetColorSettings(COLOR_SETTINGS *aSettings) noexcept
BOARD_ITEM * m_currentRollOverItem
CAMERA & m_camera
wxTimer m_redraw_trigger_timer
bool m_render_raytracing_was_requested

References GetSettingsManager(), OnEvent(), OnTimerTimeout_Editing(), OnTimerTimeout_Redraw(), and Pgm().

◆ ~EDA_3D_CANVAS()

EDA_3D_CANVAS::~EDA_3D_CANVAS ( )

Definition at line 168 of file eda_3d_canvas.cpp.

169 {
170  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::~EDA_3D_CANVAS" );
171 
172  delete m_accelerator3DShapes;
173  m_accelerator3DShapes = nullptr;
174 
175  releaseOpenGL();
176 }
void 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.
ACCELERATOR_3D * m_accelerator3DShapes

References m_accelerator3DShapes, m_logTrace, and releaseOpenGL().

Member Function Documentation

◆ DisplayStatus()

void EDA_3D_CANVAS::DisplayStatus ( )

Update the status bar with the position information.

Definition at line 324 of file eda_3d_canvas.cpp.

325 {
326  if( m_parentStatusBar )
327  {
328  wxString msg;
329 
330  msg.Printf( "dx %3.2f", m_camera.GetCameraPos().x );
331  m_parentStatusBar->SetStatusText( msg, static_cast<int>( EDA_3D_VIEWER_STATUSBAR::X_POS ) );
332 
333  msg.Printf( "dy %3.2f", m_camera.GetCameraPos().y );
334  m_parentStatusBar->SetStatusText( msg, static_cast<int>( EDA_3D_VIEWER_STATUSBAR::Y_POS ) );
335  }
336 }
wxStatusBar * m_parentStatusBar
const SFVEC3F & GetCameraPos() const
Definition: camera.h:130
CAMERA & m_camera

References CAMERA::GetCameraPos(), m_camera, m_parentStatusBar, X_POS, and Y_POS.

Referenced by DoRePaint(), EDA_3D_CONTROLLER::doZoomInOut(), OnMouseMove(), OnMouseWheel(), request_start_moving_camera(), SetView3D(), and EDA_3D_CONTROLLER::ZoomFitScreen().

◆ DoRePaint()

void EDA_3D_CANVAS::DoRePaint ( )
private

The actual function to repaint the canvas.

It is usually called by OnPaint() but because it does not use a wxPaintDC it can be called outside a wxPaintEvent

Definition at line 346 of file eda_3d_canvas.cpp.

347 {
348  if( m_is_currently_painting.test_and_set() )
349  return;
350 
351  // SwapBuffer requires the window to be shown before calling
352  if( !IsShownOnScreen() )
353  {
354  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::DoRePaint !IsShown" );
355  m_is_currently_painting.clear();
356  return;
357  }
358 
359  // Because the board to draw is handled by the parent viewer frame,
360  // ensure this parent is still alive. When it is closed before the viewer
361  // frame, a paint event can be generated after the parent is closed,
362  // therefore with invalid board.
363  // This is dependent of the platform.
364  // Especially on OSX, but also on Windows, it frequently happens
365  if( !GetParent()->GetParent()->IsShown() )
366  return; // The parent board editor frame is no more alive
367 
368  wxString err_messages;
369 
370  // !TODO: implement error reporter
371  INFOBAR_REPORTER warningReporter( m_parentInfoBar );
372  STATUSBAR_REPORTER activityReporter( m_parentStatusBar,
374 
375  unsigned strtime = GetRunningMicroSecs();
376 
377  // "Makes the OpenGL state that is represented by the OpenGL rendering
378  // context context current, i.e. it will be used by all subsequent OpenGL calls.
379  // This function may only be called when the window is shown on screen"
380 
381  // Explicitly create a new rendering context instance for this canvas.
382  if( m_glRC == nullptr )
384 
386 
387  // Set the OpenGL viewport according to the client size of this canvas.
388  // This is done here rather than in a wxSizeEvent handler because our
389  // OpenGL rendering context (and thus viewport setting) is used with
390  // multiple canvases: If we updated the viewport in the wxSizeEvent
391  // handler, changing the size of one canvas causes a viewport setting that
392  // is wrong when next another canvas is repainted.
393  wxSize clientSize = GetNativePixelSize();
394 
395  const bool windows_size_changed = m_camera.SetCurWindowSize( clientSize );
396 
397  // Initialize openGL if need
399  {
400  if( !initializeOpenGL() )
401  {
403  m_is_currently_painting.clear();
404 
405  return;
406  }
407 
409  {
410  warningReporter.Report( _( "Your OpenGL version is not supported. Minimum required "
411  "is 1.5." ), RPT_SEVERITY_ERROR );
412 
413  warningReporter.Finalize();
414  }
415  }
416 
418  {
419  glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
420  glClear( GL_COLOR_BUFFER_BIT );
421 
422  SwapBuffers();
423 
425  m_is_currently_painting.clear();
426 
427  return;
428  }
429 
430  // Don't attend to ray trace if OpenGL doesn't support it.
432  {
436  }
437 
438  // Check if a raytacing was requested and need to switch to raytracing mode
440  {
441  const bool was_camera_changed = m_camera.ParametersChanged();
442 
443  // It reverts back to OpenGL mode if it was requested a raytracing
444  // render of the current scene. AND the mouse / camera is moving
445  if( ( m_mouse_is_moving || m_camera_is_moving || was_camera_changed
446  || windows_size_changed )
448  {
451  }
452  }
453 
454  float curtime_delta_s = 0.0f;
455 
456  if( m_camera_is_moving )
457  {
458  const unsigned curtime_delta = GetRunningMicroSecs() - m_strtime_camera_movement;
459  curtime_delta_s = (curtime_delta / 1e6) * m_camera_moving_speed;
460  m_camera.Interpolate( curtime_delta_s );
461 
462  if( curtime_delta_s > 1.0f )
463  {
464  m_render_pivot = false;
465  m_camera_is_moving = false;
466  m_mouse_was_moved = true;
467 
469  DisplayStatus();
470  }
471  else
472  {
473  Request_refresh();
474  }
475  }
476 
477  // It will return true if the render request a new redraw
478  bool requested_redraw = false;
479 
480  if( m_3d_render )
481  {
482  try
483  {
484  m_3d_render->SetCurWindowSize( clientSize );
485 
486  bool reloadRaytracingForCalculations = false;
487 
490  {
491  reloadRaytracingForCalculations = true;
492  }
493 
494  requested_redraw = m_3d_render->Redraw( m_mouse_was_moved || m_camera_is_moving,
495  &activityReporter, &warningReporter );
496 
497  // Raytracer renderer is responsible for some features also used by the OpenGL
498  // renderer.
499  // FIXME: Presumably because raytracing renderer reload is called only after current
500  // renderer redraw, the old zoom value stays for a single frame. This is ugly, but only
501  // cosmetic, so I'm not fixing that for now: I don't know how to do this without
502  // reloading twice (maybe it's not too bad of an idea?) or doing a complicated
503  // refactor.
504  if( reloadRaytracingForCalculations )
505  m_3d_render_raytracing->Reload( nullptr, nullptr, true );
506  }
507  catch( std::runtime_error& )
508  {
511  m_is_opengl_initialized = false;
513  m_is_currently_painting.clear();
514  return;
515  }
516  }
517 
518  if( m_render_pivot )
519  {
520  const float scale = glm::min( m_camera.GetZoom(), 1.0f );
521  render_pivot( curtime_delta_s, scale );
522  }
523 
524  // "Swaps the double-buffer of this window, making the back-buffer the
525  // front-buffer and vice versa, so that the output of the previous OpenGL
526  // commands is displayed on the window."
527  SwapBuffers();
528 
530 
531  if( !activityReporter.HasMessage() )
532  {
534  {
535  // Calculation time in milliseconds
536  const double calculation_time = (double)( GetRunningMicroSecs() - strtime) / 1e3;
537 
538  activityReporter.Report( wxString::Format( _( "Last render time %.0f ms" ),
539  calculation_time ) );
540  }
541  }
542 
543  // This will reset the flag of camera parameters changed
545 
546  warningReporter.Finalize();
547 
548  if( !err_messages.IsEmpty() )
549  wxLogMessage( err_messages );
550 
551  if( ( !m_camera_is_moving ) && requested_redraw )
552  {
553  m_mouse_was_moved = false;
554  Request_refresh( false );
555  }
556 
557  m_is_currently_painting.clear();
558 }
A wrapper for reporting to a specific text location in a statusbar.
Definition: reporter.h:286
virtual wxSize GetNativePixelSize() const
bool IsReloadRequestPending() const
Query if there is a pending reload request.
bool m_mouse_is_moving
unsigned m_strtime_camera_movement
WX_INFOBAR * m_parentInfoBar
wxStatusBar * m_parentStatusBar
virtual void SetCurWindowSize(const wxSize &aSize)=0
Before each render, the canvas will tell the render what is the size of its windows,...
wxGLContext * m_glRC
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void DisplayStatus()
Update the status bar with the position information.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
void UnlockCtx(wxGLContext *aContext)
Allow other canvases to bind an OpenGL context.
BOARD_ADAPTER & m_boardAdapter
float m_camera_moving_speed
RENDER_ENGINE GetRenderEngine() const noexcept
bool m_is_opengl_version_supported
static GL_CONTEXT_MANAGER & Get()
Return the GL_CONTEXT_MANAGER instance (singleton).
void restart_editingTimeOut_Timer()
Reset the editing timer.
bool m_mouse_was_moved
RENDER_3D_RAYTRACE * m_3d_render_raytracing
bool m_camera_is_moving
RENDER_3D_BASE * m_3d_render
float GetZoom() const
Definition: camera.h:177
virtual bool Redraw(bool aIsMoving, REPORTER *aStatusReporter=nullptr, REPORTER *aWarningReporter=nullptr)=0
Redraw the view.
void Reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter, bool aOnlyLoadCopperAndShapes)
#define _(s)
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=nullptr)
Create a managed OpenGL context.
void SetRenderEngine(RENDER_ENGINE aRenderEngine) noexcept
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Set a context as current and prevents other canvases from switching it.
bool m_is_opengl_initialized
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool SetCurWindowSize(const wxSize &aSize)
Update the windows size of the camera.
Definition: camera.cpp:456
const int scale
bool initializeOpenGL()
bool m_opengl_supports_raytracing
std::atomic_flag m_is_currently_painting
virtual void Interpolate(float t)
It will update the matrix to interpolate between T0 and T1 values.
Definition: camera.cpp:572
unsigned GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
RENDER_3D_OPENGL * m_3d_render_opengl
bool ParametersChanged()
Definition: camera.cpp:590
CAMERA & m_camera
void render_pivot(float t, float aScale)
Render the pivot cursor.
A wrapper for reporting to a WX_INFOBAR UI element.
Definition: reporter.h:315
bool m_render_raytracing_was_requested

References _, ACTIVITY, GL_CONTEXT_MANAGER::CreateCtx(), DisplayStatus(), INFOBAR_REPORTER::Finalize(), Format(), GL_CONTEXT_MANAGER::Get(), HIDPI_GL_CANVAS::GetNativePixelSize(), BOARD_ADAPTER::GetRenderEngine(), GetRunningMicroSecs(), CAMERA::GetZoom(), STATUSBAR_REPORTER::HasMessage(), initializeOpenGL(), CAMERA::Interpolate(), RENDER_3D_BASE::IsReloadRequestPending(), GL_CONTEXT_MANAGER::LockCtx(), m_3d_render, m_3d_render_opengl, m_3d_render_raytracing, m_boardAdapter, m_camera, m_camera_is_moving, m_camera_moving_speed, m_glRC, m_is_currently_painting, m_is_opengl_initialized, m_is_opengl_version_supported, m_logTrace, m_mouse_is_moving, m_mouse_was_moved, m_opengl_supports_raytracing, m_parentInfoBar, m_parentStatusBar, m_render_pivot, m_render_raytracing_was_requested, m_strtime_camera_movement, OPENGL, CAMERA::ParametersChanged(), RENDER_3D_BASE::Redraw(), RENDER_3D_RAYTRACE::Reload(), render_pivot(), STATUSBAR_REPORTER::Report(), INFOBAR_REPORTER::Report(), Request_refresh(), restart_editingTimeOut_Timer(), RPT_SEVERITY_ERROR, scale, RENDER_3D_BASE::SetCurWindowSize(), CAMERA::SetCurWindowSize(), BOARD_ADAPTER::SetRenderEngine(), and GL_CONTEXT_MANAGER::UnlockCtx().

Referenced by OnPaint(), and OnRefreshRequest().

◆ GetAnimationEnabled()

bool EDA_3D_CANVAS::GetAnimationEnabled ( ) const
inline

◆ GetCurrentRender()

RENDER_3D_BASE* EDA_3D_CANVAS::GetCurrentRender ( ) const
inline
Returns
the current render ( a RENDER_3D_RAYTRACE* or a RENDER_3D_OPENGL* render )

Definition at line 102 of file eda_3d_canvas.h.

102 { return m_3d_render; }
RENDER_3D_BASE * m_3d_render

References m_3d_render.

Referenced by EDA_3D_CONTROLLER::ToggleVisibility().

◆ GetMovingSpeedMultiplier()

int EDA_3D_CANVAS::GetMovingSpeedMultiplier ( ) const
inline

◆ GetNativePixelSize()

wxSize HIDPI_GL_CANVAS::GetNativePixelSize ( ) const
virtualinherited

Definition at line 41 of file hidpi_gl_canvas.cpp.

42 {
43  wxSize size = wxGLCanvas::GetClientSize();
44 
45  const double scaleFactor = GetScaleFactor();
46  size.x *= scaleFactor;
47  size.y *= scaleFactor;
48 
49  return size;
50 }
double GetScaleFactor() const
Get the current scale factor.

References HIDPI_GL_CANVAS::GetScaleFactor().

Referenced by DoRePaint(), EDA_3D_MODEL_VIEWER::OnMouseMove(), OnMouseMove(), EDA_3D_MODEL_VIEWER::OnPaint(), and KIGFX::OPENGL_GAL::OPENGL_GAL().

◆ GetNativePosition()

wxPoint HIDPI_GL_CANVAS::GetNativePosition ( const wxPoint &  aPoint) const
inherited

Convert the given point from client coordinates to native pixel coordinates.

Definition at line 53 of file hidpi_gl_canvas.cpp.

54 {
55  wxPoint nativePoint = aPoint;
56 
57  const double scaleFactor = GetScaleFactor();
58  nativePoint.x *= scaleFactor;
59  nativePoint.y *= scaleFactor;
60 
61  return nativePoint;
62 }
double GetScaleFactor() const
Get the current scale factor.

References HIDPI_GL_CANVAS::GetScaleFactor().

Referenced by EDA_3D_MODEL_VIEWER::OnMouseMove(), OnMouseMove(), and OnMouseWheel().

◆ GetProjectionMode()

int EDA_3D_CANVAS::GetProjectionMode ( ) const
inline

Definition at line 138 of file eda_3d_canvas.h.

138 { return (int) m_camera.GetProjection(); };
PROJECTION_TYPE GetProjection()
Definition: camera.h:161
CAMERA & m_camera

References CAMERA::GetProjection(), and m_camera.

Referenced by EDA_3D_VIEWER_FRAME::SaveSettings().

◆ getRayAtCurrrentMousePosition()

RAY EDA_3D_CANVAS::getRayAtCurrrentMousePosition ( )
private

Definition at line 1130 of file eda_3d_canvas.cpp.

1131 {
1132  SFVEC3F rayOrigin;
1133  SFVEC3F rayDir;
1134 
1135  // Generate a ray origin and direction based on current mouser position and camera
1136  m_camera.MakeRayAtCurrrentMousePosition( rayOrigin, rayDir );
1137 
1138  RAY mouseRay;
1139  mouseRay.Init( rayOrigin, rayDir );
1140 
1141  return mouseRay;
1142 }
void Init(const SFVEC3F &o, const SFVEC3F &d)
Definition: ray.cpp:35
Definition: ray.h:62
void MakeRayAtCurrrentMousePosition(SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
Make a ray based on the latest mouse position.
Definition: camera.cpp:379
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
CAMERA & m_camera

References RAY::Init(), m_camera, and CAMERA::MakeRayAtCurrrentMousePosition().

Referenced by move_pivot_based_on_cur_mouse_position(), OnLeftDown(), and OnMouseMove().

◆ GetScaleFactor()

◆ GetScreenshot()

void EDA_3D_CANVAS::GetScreenshot ( wxImage &  aDstImage)

Request a screenshot and output it to the aDstImage.

Parameters
aDstImage- Screenshot destination image

Definition at line 290 of file eda_3d_canvas.cpp.

291 {
292  OglGetScreenshot( aDstImage );
293 }
void OglGetScreenshot(wxImage &aDstImage)
Get the pixel data of current OpenGL image.
Definition: ogl_utils.cpp:37

References OglGetScreenshot().

Referenced by EDA_3D_VIEWER_FRAME::takeScreenshot().

◆ initializeOpenGL()

bool EDA_3D_CANVAS::initializeOpenGL ( )
private
Returns
true if OpenGL initialization succeeded.

Definition at line 215 of file eda_3d_canvas.cpp.

216 {
217  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::initializeOpenGL" );
218 
219  const GLenum err = glewInit();
220 
221  if( GLEW_OK != err )
222  {
223  const wxString msgError = (const char*) glewGetErrorString( err );
224 
225  wxLogMessage( msgError );
226 
227  return false;
228  }
229  else
230  {
231  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::initializeOpenGL Using GLEW version %s",
232  FROM_UTF8( (char*) glewGetString( GLEW_VERSION ) ) );
233  }
234 
235  wxString version = FROM_UTF8( (char *) glGetString( GL_VERSION ) );
236 
237  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::%s OpenGL version string %s.",
238  __WXFUNCTION__, version );
239 
240  // Extract OpenGL version from string. This method is used because prior to OpenGL 2,
241  // getting the OpenGL major and minor version as integers didn't exist.
242  wxString tmp;
243 
244  wxStringTokenizer tokenizer( version );
245 
246  if( tokenizer.HasMoreTokens() )
247  {
248  long major = 0;
249  long minor = 0;
250 
251  tmp = tokenizer.GetNextToken();
252 
253  tokenizer.SetString( tmp, wxString( "." ) );
254 
255  if( tokenizer.HasMoreTokens() )
256  tokenizer.GetNextToken().ToLong( &major );
257 
258  if( tokenizer.HasMoreTokens() )
259  tokenizer.GetNextToken().ToLong( &minor );
260 
261  if( major < 2 || ( ( major == 2 ) && ( minor < 1 ) ) )
262  {
263  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::%s OpenGL ray tracing not supported.",
264  __WXFUNCTION__ );
265 
266  if( GetParent() )
267  {
268  wxCommandEvent evt( wxEVT_MENU, ID_DISABLE_RAY_TRACING );
269  GetParent()->ProcessWindowEvent( evt );
270  }
271 
273  }
274 
275  if( ( major == 1 ) && ( minor < 5 ) )
276  {
277  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::%s OpenGL not supported.", __WXFUNCTION__ );
278 
280  }
281  }
282 
285 
286  return true;
287 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
bool m_is_opengl_version_supported
bool m_is_opengl_initialized
bool m_opengl_supports_raytracing
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.
Definition: gl_utils.h:42

References FROM_UTF8(), ID_DISABLE_RAY_TRACING, m_is_opengl_initialized, m_is_opengl_version_supported, m_logTrace, m_opengl_supports_raytracing, and GL_UTILS::SetSwapInterval().

Referenced by DoRePaint().

◆ IsReloadRequestPending()

bool EDA_3D_CANVAS::IsReloadRequestPending ( ) const
inline

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 91 of file eda_3d_canvas.h.

92  {
93  if( m_3d_render )
95  else
96  return false;
97  }
bool IsReloadRequestPending() const
Query if there is a pending reload request.
RENDER_3D_BASE * m_3d_render

References RENDER_3D_BASE::IsReloadRequestPending(), and m_3d_render.

Referenced by EDA_3D_VIEWER_FRAME::OnActivate().

◆ move_pivot_based_on_cur_mouse_position()

void EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position ( )
private

This function hits a ray to the board and start a movement.

Definition at line 931 of file eda_3d_canvas.cpp.

932 {
933  RAY mouseRay = getRayAtCurrrentMousePosition();
934 
935  float hit_t;
936 
937  // Test it with the board bounding box
938  if( m_boardAdapter.GetBBox().Intersect( mouseRay, &hit_t ) )
939  {
942  m_camera.SetLookAtPos_T1( mouseRay.at( hit_t ) );
944 
946  }
947 }
void SetLookAtPos_T1(const SFVEC3F &aLookAtPos)
Definition: camera.h:123
void request_start_moving_camera(float aMovingSpeed=2.0f, bool aRenderPivot=true)
Start a camera movement.
RAY getRayAtCurrrentMousePosition()
bool Intersect(const RAY &aRay, float *t) const
Definition: bbox_3d_ray.cpp:46
Definition: ray.h:62
SFVEC3F at(float t) const
Definition: ray.h:84
BOARD_ADAPTER & m_boardAdapter
void SetInterpolateMode(CAMERA_INTERPOLATION aInterpolateMode)
Definition: camera.h:213
const BBOX_3D & GetBBox() const noexcept
Get the board outling bounding box.
virtual void SetT0_and_T1_current_T()
This will set T0 and T1 with the current values.
Definition: camera.cpp:558
void ResetXYpos_T1()
Definition: camera.cpp:420
CAMERA & m_camera

References RAY::at(), BEZIER, BOARD_ADAPTER::GetBBox(), getRayAtCurrrentMousePosition(), BBOX_3D::Intersect(), m_boardAdapter, m_camera, request_start_moving_camera(), CAMERA::ResetXYpos_T1(), CAMERA::SetInterpolateMode(), CAMERA::SetLookAtPos_T1(), and CAMERA::SetT0_and_T1_current_T().

Referenced by OnMiddleUp(), and SetView3D().

◆ OnCloseWindow()

void EDA_3D_CANVAS::OnCloseWindow ( wxCloseEvent &  event)
private

Definition at line 201 of file eda_3d_canvas.cpp.

202 {
203  releaseOpenGL();
204 
205  event.Skip();
206 }
void releaseOpenGL()
Free created targets and openGL context.

References releaseOpenGL().

◆ OnEraseBackground()

void EDA_3D_CANVAS::OnEraseBackground ( wxEraseEvent &  event)
private

Definition at line 578 of file eda_3d_canvas.cpp.

579 {
580  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::OnEraseBackground" );
581  // Do nothing, to avoid flashing.
582 }
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.

References m_logTrace.

◆ OnEvent()

void EDA_3D_CANVAS::OnEvent ( wxEvent &  aEvent)

Used to forward events to the canvas from popups, etc.

Definition at line 567 of file eda_3d_canvas.cpp.

568 {
569  if( !m_eventDispatcher )
570  aEvent.Skip();
571  else
573 
574  Refresh();
575 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
TOOL_DISPATCHER * m_eventDispatcher

References TOOL_DISPATCHER::DispatchWxEvent(), m_eventDispatcher, and Refresh().

Referenced by EDA_3D_CANVAS().

◆ OnLeftDown()

void EDA_3D_CANVAS::OnLeftDown ( wxMouseEvent &  event)
private

Definition at line 794 of file eda_3d_canvas.cpp.

795 {
796  SetFocus();
798 
799  if( !event.Dragging() && ( m_3d_render_raytracing != nullptr ) )
800  {
801  RAY mouseRay = getRayAtCurrrentMousePosition();
802 
803  BOARD_ITEM *intersectedBoardItem = m_3d_render_raytracing->IntersectBoardItem( mouseRay );
804 
805  // !TODO: send a selection item to pcbnew, eg: via kiway?
806  }
807 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
RAY getRayAtCurrrentMousePosition()
void stop_editingTimeOut_Timer()
Stop the editing time so it will not timeout.
Definition: ray.h:62
RENDER_3D_RAYTRACE * m_3d_render_raytracing
BOARD_ITEM * IntersectBoardItem(const RAY &aRay)

References getRayAtCurrrentMousePosition(), RENDER_3D_RAYTRACE::IntersectBoardItem(), m_3d_render_raytracing, and stop_editingTimeOut_Timer().

◆ OnLeftUp()

void EDA_3D_CANVAS::OnLeftUp ( wxMouseEvent &  event)
private

Definition at line 810 of file eda_3d_canvas.cpp.

811 {
812  if( m_camera_is_moving )
813  return;
814 
815  if( m_mouse_is_moving )
816  {
817  m_mouse_is_moving = false;
819  }
820 }
bool m_mouse_is_moving
void restart_editingTimeOut_Timer()
Reset the editing timer.
bool m_camera_is_moving

References m_camera_is_moving, m_mouse_is_moving, and restart_editingTimeOut_Timer().

◆ OnMiddleDown()

void EDA_3D_CANVAS::OnMiddleDown ( wxMouseEvent &  event)
private

Definition at line 823 of file eda_3d_canvas.cpp.

824 {
825  SetFocus();
827 }
void stop_editingTimeOut_Timer()
Stop the editing time so it will not timeout.

References stop_editingTimeOut_Timer().

◆ OnMiddleUp()

void EDA_3D_CANVAS::OnMiddleUp ( wxMouseEvent &  event)
private

Definition at line 830 of file eda_3d_canvas.cpp.

831 {
832  if( m_camera_is_moving )
833  return;
834 
835  if( m_mouse_is_moving )
836  {
837  m_mouse_is_moving = false;
839  }
840  else
841  {
843  }
844 }
bool m_mouse_is_moving
void restart_editingTimeOut_Timer()
Reset the editing timer.
bool m_camera_is_moving
void move_pivot_based_on_cur_mouse_position()
This function hits a ray to the board and start a movement.

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

◆ OnMouseMove()

void EDA_3D_CANVAS::OnMouseMove ( wxMouseEvent &  event)
private

Definition at line 673 of file eda_3d_canvas.cpp.

674 {
675  //wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnMouseMove" ) );
676 
677  if( m_camera_is_moving )
678  return;
679 
680  const wxSize& nativeWinSize = GetNativePixelSize();
681  const wxPoint& nativePosition = GetNativePosition( event.GetPosition() );
682 
683  m_camera.SetCurWindowSize( nativeWinSize );
684 
685  if( event.Dragging() )
686  {
687  if( event.LeftIsDown() ) // Drag
688  m_camera.Drag( nativePosition );
689  else if( event.MiddleIsDown() ) // Pan
690  m_camera.Pan( nativePosition );
691 
692  m_mouse_is_moving = true;
693  m_mouse_was_moved = true;
694 
695  // orientation has changed, redraw mesh
696  DisplayStatus();
697  Request_refresh();
698  }
699 
700  m_camera.SetCurMousePosition( nativePosition );
701 
702  if( !event.Dragging() && m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL )
703  {
705  static_cast<int>( EDA_3D_VIEWER_STATUSBAR::HOVERED_ITEM ) );
706 
707  RAY mouseRay = getRayAtCurrrentMousePosition();
708 
709  BOARD_ITEM *rollOverItem = m_3d_render_raytracing->IntersectBoardItem( mouseRay );
710 
711  if( rollOverItem )
712  {
713  if( rollOverItem != m_currentRollOverItem )
714  {
716  m_currentRollOverItem = rollOverItem;
717 
718  Request_refresh();
719  }
720 
721  switch( rollOverItem->Type() )
722  {
723  case PCB_PAD_T:
724  {
725  PAD* pad = dynamic_cast<PAD*>( rollOverItem );
726 
727  if( pad && pad->IsOnCopperLayer() )
728  {
729  reporter.Report( wxString::Format( _( "Net %s\tNetClass %s\tPadName %s" ),
730  pad->GetNet()->GetNetname(),
731  pad->GetNet()->GetNetClassName(),
732  pad->GetNumber() ) );
733  }
734  }
735  break;
736 
737  case PCB_FOOTPRINT_T:
738  {
739  FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( rollOverItem );
740 
741  if( footprint )
742  reporter.Report( footprint->GetReference() );
743  }
744  break;
745 
746  case PCB_TRACE_T:
747  case PCB_VIA_T:
748  case PCB_ARC_T:
749  {
750  PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( rollOverItem );
751 
752  if( track )
753  {
754  reporter.Report( wxString::Format( _( "Net %s\tNetClass %s" ),
755  track->GetNet()->GetNetname(),
756  track->GetNet()->GetNetClassName() ) );
757  }
758  }
759  break;
760 
761  case PCB_ZONE_T:
762  {
763  ZONE* zone = dynamic_cast<ZONE*>( rollOverItem );
764 
765  if( zone && zone->IsOnCopperLayer() )
766  {
767  reporter.Report( wxString::Format( _( "Net %s\tNetClass %s" ),
768  zone->GetNet()->GetNetname(),
769  zone->GetNet()->GetNetClassName() ) );
770  }
771  }
772  break;
773 
774  default:
775  break;
776  }
777  }
778  else
779  {
781  {
783  Request_refresh();
784 
785  reporter.Report( "" );
786  }
787 
788  m_currentRollOverItem = nullptr;
789  }
790  }
791 }
A wrapper for reporting to a specific text location in a statusbar.
Definition: reporter.h:286
virtual wxSize GetNativePixelSize() const
virtual void Pan(const wxPoint &aNewMousePosition)=0
bool m_mouse_is_moving
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
RAY getRayAtCurrrentMousePosition()
wxString GetNetClassName() const
Definition: netinfo.h:115
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
wxStatusBar * m_parentStatusBar
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class PAD, a pad in a footprint
Definition: typeinfo.h:89
Definition: ray.h:62
void DisplayStatus()
Update the status bar with the position information.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
virtual void Drag(const wxPoint &aNewMousePosition)=0
Calculate a new mouse drag position.
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
BOARD_ADAPTER & m_boardAdapter
RENDER_ENGINE GetRenderEngine() const noexcept
bool m_mouse_was_moved
RENDER_3D_RAYTRACE * m_3d_render_raytracing
bool m_camera_is_moving
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
Definition: camera.cpp:439
const wxString & GetNetname() const
Definition: netinfo.h:126
const wxString & GetReference() const
Definition: footprint.h:464
#define _(s)
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
BOARD_ITEM * IntersectBoardItem(const RAY &aRay)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxPoint GetNativePosition(const wxPoint &aPoint) const
Convert the given point from client coordinates to native pixel coordinates.
bool SetCurWindowSize(const wxSize &aSize)
Update the windows size of the camera.
Definition: camera.cpp:456
bool IsOnCopperLayer() const override
Definition: zone.cpp:228
RENDER_3D_OPENGL * m_3d_render_opengl
void SetCurrentRollOverItem(BOARD_ITEM *aRollOverItem)
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Definition: pad.h:57
BOARD_ITEM * m_currentRollOverItem
CAMERA & m_camera
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References _, DisplayStatus(), CAMERA::Drag(), Format(), HIDPI_GL_CANVAS::GetNativePixelSize(), HIDPI_GL_CANVAS::GetNativePosition(), BOARD_CONNECTED_ITEM::GetNet(), NETINFO_ITEM::GetNetClassName(), NETINFO_ITEM::GetNetname(), getRayAtCurrrentMousePosition(), FOOTPRINT::GetReference(), BOARD_ADAPTER::GetRenderEngine(), HOVERED_ITEM, RENDER_3D_RAYTRACE::IntersectBoardItem(), ZONE::IsOnCopperLayer(), m_3d_render_opengl, m_3d_render_raytracing, m_boardAdapter, m_camera, m_camera_is_moving, m_currentRollOverItem, m_mouse_is_moving, m_mouse_was_moved, m_parentStatusBar, OPENGL, pad, CAMERA::Pan(), PCB_ARC_T, PCB_FOOTPRINT_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, STATUSBAR_REPORTER::Report(), Request_refresh(), CAMERA::SetCurMousePosition(), RENDER_3D_OPENGL::SetCurrentRollOverItem(), CAMERA::SetCurWindowSize(), and EDA_ITEM::Type().

◆ OnMouseWheel()

void EDA_3D_CANVAS::OnMouseWheel ( wxMouseEvent &  event)
private

Definition at line 585 of file eda_3d_canvas.cpp.

586 {
587  bool mouseActivity = false;
588 
589  wxLogTrace( m_logTrace, "EDA_3D_CANVAS::OnMouseWheel" );
590 
591  if( m_camera_is_moving )
592  return;
593 
594  float delta_move = m_delta_move_step_factor * m_camera.GetZoom();
595 
597  delta_move *= 0.01f * event.GetWheelRotation();
598  else
599  if( event.GetWheelRotation() < 0 )
600  delta_move = -delta_move;
601 
602  // mousewheel_panning enabled:
603  // wheel -> pan;
604  // wheel + shift -> horizontal scrolling;
605  // wheel + ctrl -> zooming;
606  // mousewheel_panning disabled:
607  // wheel + shift -> vertical scrolling;
608  // wheel + ctrl -> horizontal scrolling;
609  // wheel -> zooming.
610 
611  if( m_boardAdapter.GetFlag( FL_MOUSEWHEEL_PANNING ) && !event.ControlDown() )
612  {
613  if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL || event.ShiftDown() )
614  m_camera.Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
615  else
616  m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
617 
618  mouseActivity = true;
619  }
620  else if( event.ShiftDown() && !m_boardAdapter.GetFlag( FL_MOUSEWHEEL_PANNING ) )
621  {
622  m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
623  mouseActivity = true;
624  }
625  else if( event.ControlDown() && !m_boardAdapter.GetFlag( FL_MOUSEWHEEL_PANNING ) )
626  {
627  m_camera.Pan( SFVEC3F( delta_move, 0.0f, 0.0f ) );
628  mouseActivity = true;
629  }
630  else
631  {
632  mouseActivity = m_camera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f );
633  }
634 
635  // If it results on a camera movement
636  if( mouseActivity )
637  {
638  DisplayStatus();
639  Request_refresh();
640 
641  m_mouse_is_moving = true;
642  m_mouse_was_moved = true;
643 
645  }
646 
647  // Update the cursor current mouse position on the camera
648  m_camera.SetCurMousePosition( GetNativePosition( event.GetPosition() ) );
649 }
virtual void Pan(const wxPoint &aNewMousePosition)=0
bool GetFlag(DISPLAY3D_FLG aFlag) const
Get a configuration status of a flag.
bool m_mouse_is_moving
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void DisplayStatus()
Update the status bar with the position information.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
BOARD_ADAPTER & m_boardAdapter
void restart_editingTimeOut_Timer()
Reset the editing timer.
bool m_mouse_was_moved
bool m_camera_is_moving
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
Definition: camera.cpp:439
float GetZoom() const
Definition: camera.h:177
bool Zoom(float aFactor)
Definition: camera.cpp:482
wxPoint GetNativePosition(const wxPoint &aPoint) const
Convert the given point from client coordinates to native pixel coordinates.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
CAMERA & m_camera
static const float m_delta_move_step_factor

References DisplayStatus(), FL_MOUSEWHEEL_PANNING, BOARD_ADAPTER::GetFlag(), HIDPI_GL_CANVAS::GetNativePosition(), CAMERA::GetZoom(), m_boardAdapter, m_camera, m_camera_is_moving, m_delta_move_step_factor, m_logTrace, m_mouse_is_moving, m_mouse_was_moved, CAMERA::Pan(), Request_refresh(), restart_editingTimeOut_Timer(), CAMERA::SetCurMousePosition(), and CAMERA::Zoom().

◆ OnPaint()

void EDA_3D_CANVAS::OnPaint ( wxPaintEvent &  aEvent)
private

Called by a wxPaintEvent event.

Definition at line 339 of file eda_3d_canvas.cpp.

340 {
341  // Please have a look at: https://lists.launchpad.net/kicad-developers/msg25149.html
342  DoRePaint();
343 }
void DoRePaint()
The actual function to repaint the canvas.

References DoRePaint().

◆ OnRefreshRequest()

void EDA_3D_CANVAS::OnRefreshRequest ( wxEvent &  aEvent)
private

Definition at line 875 of file eda_3d_canvas.cpp.

876 {
877  DoRePaint();
878 }
void DoRePaint()
The actual function to repaint the canvas.

References DoRePaint().

◆ OnResize()

void EDA_3D_CANVAS::OnResize ( wxSizeEvent &  event)
private

Definition at line 209 of file eda_3d_canvas.cpp.

210 {
211  this->Request_refresh();
212 }
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.

References Request_refresh().

◆ OnTimerTimeout_Editing()

void EDA_3D_CANVAS::OnTimerTimeout_Editing ( wxTimerEvent &  event)
private

Definition at line 847 of file eda_3d_canvas.cpp.

848 {
849  m_mouse_is_moving = false;
850  m_mouse_was_moved = false;
851 
852  Request_refresh();
853 }
bool m_mouse_is_moving
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
bool m_mouse_was_moved

References m_mouse_is_moving, m_mouse_was_moved, and Request_refresh().

Referenced by EDA_3D_CANVAS().

◆ OnTimerTimeout_Redraw()

void EDA_3D_CANVAS::OnTimerTimeout_Redraw ( wxTimerEvent &  event)
private

Definition at line 869 of file eda_3d_canvas.cpp.

870 {
871  Request_refresh( true );
872 }
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.

References Request_refresh().

Referenced by EDA_3D_CANVAS().

◆ releaseOpenGL()

void EDA_3D_CANVAS::releaseOpenGL ( )
private

Free created targets and openGL context.

Definition at line 179 of file eda_3d_canvas.cpp.

180 {
181  if( m_glRC )
182  {
184 
185  delete m_3d_render_raytracing;
186  m_3d_render_raytracing = nullptr;
187 
188  delete m_3d_render_opengl;
189  m_3d_render_opengl = nullptr;
190 
191  // This is just a copy of a pointer, can safely be set to NULL.
192  m_3d_render = nullptr;
193 
196  m_glRC = nullptr;
197  }
198 }
wxGLContext * m_glRC
void UnlockCtx(wxGLContext *aContext)
Allow other canvases to bind an OpenGL context.
static GL_CONTEXT_MANAGER & Get()
Return the GL_CONTEXT_MANAGER instance (singleton).
RENDER_3D_RAYTRACE * m_3d_render_raytracing
RENDER_3D_BASE * m_3d_render
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Set a context as current and prevents other canvases from switching it.
RENDER_3D_OPENGL * m_3d_render_opengl
void DestroyCtx(wxGLContext *aContext)
Destroy a managed OpenGL context.

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

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

◆ ReloadRequest()

void EDA_3D_CANVAS::ReloadRequest ( BOARD aBoard = nullptr,
S3D_CACHE aCachePointer = nullptr 
)

Definition at line 296 of file eda_3d_canvas.cpp.

297 {
298  if( aCachePointer != nullptr )
299  m_boardAdapter.Set3dCacheManager( aCachePointer );
300 
301  if( aBoard != nullptr )
302  m_boardAdapter.SetBoard( aBoard );
303 
304  m_boardAdapter.SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
305 
306  if( m_3d_render )
308 }
void ReloadRequest()
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void SetBoard(BOARD *aBoard) noexcept
Set current board to be rendered.
BOARD_ADAPTER & m_boardAdapter
void Set3dCacheManager(S3D_CACHE *aCachePointer) noexcept
Update the cache manager pointer.
Definition: board_adapter.h:80
RENDER_3D_BASE * m_3d_render
SETTINGS_MANAGER * GetSettingsManager()
void SetColorSettings(COLOR_SETTINGS *aSettings) noexcept

References GetSettingsManager(), m_3d_render, m_boardAdapter, Pgm(), RENDER_3D_BASE::ReloadRequest(), BOARD_ADAPTER::Set3dCacheManager(), BOARD_ADAPTER::SetBoard(), and BOARD_ADAPTER::SetColorSettings().

Referenced by EDA_3D_VIEWER_FRAME::ReloadRequest(), PANEL_PREVIEW_3D_MODEL::UpdateDummyFootprint(), and PANEL_PREVIEW_3D_MODEL::View3DUpdate().

◆ render_pivot()

void EDA_3D_CANVAS::render_pivot ( float  t,
float  aScale 
)
private

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.

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_camera.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  glMatrixMode( GL_PROJECTION );
92  glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
93 
94  glMatrixMode( GL_MODELVIEW );
95  glLoadIdentity();
96  glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
97 
98  glEnable( GL_COLOR_MATERIAL );
99  glColor4f( 0.0f, 1.0f, 0.0f, 0.75f - t * 0.75f );
100 
101  // Translate to the look at position
102  glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z );
103 
104  glScalef( aScale, aScale, aScale );
105  pivot_render_triangles( t * 0.5f );
106 
107  t = t * 0.80f;
108  glScalef( 1.0f - t, 1.0f - t, 1.0f - t );
109  glColor4f( 0.0f, 1.0f, 0.0f, 0.8f - t );
110 
111  glPushMatrix();
112  glRotatef( t * 90.0f, 0.0f, 0.0f, 1.0f );
113  pivot_render_triangles( t * 0.5f );
114  glPopMatrix();
115 
116  glPushMatrix();
117  glRotatef( -t * 90.0f, 0.0f, 0.0f, 1.0f );
118  pivot_render_triangles( t * 0.5f );
119  glPopMatrix();
120 }
const glm::mat4 & GetProjectionMatrix() const
Definition: camera.cpp:391
const SFVEC3F & GetLookAtPos_T1() const
Definition: camera.h:128
const glm::mat4 & GetViewMatrix() const
Definition: camera.cpp:427
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
static void pivot_render_triangles(float t)
CAMERA & m_camera

References CAMERA::GetLookAtPos_T1(), CAMERA::GetProjectionMatrix(), CAMERA::GetViewMatrix(), m_camera, and pivot_render_triangles().

Referenced by DoRePaint().

◆ RenderEngineChanged()

void EDA_3D_CANVAS::RenderEngineChanged ( )

Notify that the render engine was changed.

Definition at line 1112 of file eda_3d_canvas.cpp.

1113 {
1114  switch( m_boardAdapter.GetRenderEngine() )
1115  {
1118  default: m_3d_render = nullptr; break;
1119  }
1120 
1121  if( m_3d_render )
1123 
1124  m_mouse_was_moved = false;
1125 
1126  Request_refresh();
1127 }
void ReloadRequest()
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
BOARD_ADAPTER & m_boardAdapter
RENDER_ENGINE GetRenderEngine() const noexcept
bool m_mouse_was_moved
RENDER_3D_RAYTRACE * m_3d_render_raytracing
RENDER_3D_BASE * m_3d_render
RENDER_3D_OPENGL * m_3d_render_opengl

References BOARD_ADAPTER::GetRenderEngine(), m_3d_render, m_3d_render_opengl, m_3d_render_raytracing, m_boardAdapter, m_mouse_was_moved, OPENGL, RAYTRACING, RENDER_3D_BASE::ReloadRequest(), and Request_refresh().

Referenced by EDA_3D_VIEWER_FRAME::RenderEngineChanged().

◆ RenderRaytracingRequest()

void EDA_3D_CANVAS::RenderRaytracingRequest ( )

Request to render the current view in Raytracing mode.

Definition at line 311 of file eda_3d_canvas.cpp.

312 {
314 
315  if( m_3d_render )
317 
319 
320  Request_refresh();
321 }
void ReloadRequest()
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
RENDER_3D_RAYTRACE * m_3d_render_raytracing
RENDER_3D_BASE * m_3d_render
bool m_render_raytracing_was_requested

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

Referenced by EDA_3D_CONTROLLER::RotateView(), EDA_3D_CONTROLLER::ToggleOrtho(), and EDA_3D_CONTROLLER::ToggleVisibility().

◆ Request_refresh()

void EDA_3D_CANVAS::Request_refresh ( bool  aRedrawImmediately = true)

Schedule a refresh update of the canvas.

Parameters
aRedrawImmediatelytrue will request a redraw, false will schedule a redraw after a short timeout.

Definition at line 881 of file eda_3d_canvas.cpp.

882 {
883  if( aRedrawImmediately )
884  {
885  // Just calling Refresh() does not work always
886  // Using an event to call DoRepaint ensure the repaint code will be executed,
887  // and PostEvent will take priority to other events like mouse movements, keys, etc.
888  // and is executed during the next idle time
889  wxCommandEvent redrawEvent( wxEVT_REFRESH_CUSTOM_COMMAND, ID_CUSTOM_EVENT_1 );
890  wxPostEvent( this, redrawEvent );
891  }
892  else
893  {
894  // Schedule a timed redraw
895  m_redraw_trigger_timer.Start( 10 , wxTIMER_ONE_SHOT );
896  }
897 }
wxTimer m_redraw_trigger_timer

References ID_CUSTOM_EVENT_1, and m_redraw_trigger_timer.

Referenced by DoRePaint(), EDA_3D_CONTROLLER::On3DGridSelection(), EDA_3D_VIEWER_FRAME::OnActivate(), OnMouseMove(), OnMouseWheel(), OnResize(), OnTimerTimeout_Editing(), OnTimerTimeout_Redraw(), EDA_3D_VIEWER_FRAME::Redraw(), EDA_3D_VIEWER_FRAME::refreshRender(), RenderEngineChanged(), RenderRaytracingRequest(), request_start_moving_camera(), EDA_3D_CONTROLLER::RotateView(), EDA_3D_CONTROLLER::SetMaterial(), SetView3D(), EDA_3D_VIEWER_FRAME::takeScreenshot(), EDA_3D_CONTROLLER::ToggleOrtho(), EDA_3D_CONTROLLER::ToggleVisibility(), PANEL_PREVIEW_3D_MODEL::UpdateDummyFootprint(), and EDA_3D_CONTROLLER::ZoomRedraw().

◆ request_start_moving_camera()

void EDA_3D_CANVAS::request_start_moving_camera ( float  aMovingSpeed = 2.0f,
bool  aRenderPivot = true 
)
private

Start a camera movement.

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

Definition at line 900 of file eda_3d_canvas.cpp.

901 {
902  wxASSERT( aMovingSpeed > FLT_EPSILON );
903 
904  // Fast forward the animation if the animation is disabled
905  if( !m_animation_enabled )
906  {
907  m_camera.Interpolate( 1.0f );
908  DisplayStatus();
909  Request_refresh();
910  return;
911  }
912 
913  // Map speed multiplier option to actual multiplier value
914  // [1,2,3,4,5] -> [0.25, 0.5, 1, 2, 4]
915  aMovingSpeed *= ( 1 << m_moving_speed_multiplier ) / 8.0f;
916 
917  m_render_pivot = aRenderPivot;
918  m_camera_moving_speed = aMovingSpeed;
919 
921 
922  DisplayStatus();
923  Request_refresh();
924 
925  m_camera_is_moving = true;
926 
928 }
unsigned m_strtime_camera_movement
void stop_editingTimeOut_Timer()
Stop the editing time so it will not timeout.
void DisplayStatus()
Update the status bar with the position information.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
float m_camera_moving_speed
bool m_camera_is_moving
bool m_animation_enabled
int m_moving_speed_multiplier
virtual void Interpolate(float t)
It will update the matrix to interpolate between T0 and T1 values.
Definition: camera.cpp:572
unsigned GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
CAMERA & m_camera

References DisplayStatus(), GetRunningMicroSecs(), CAMERA::Interpolate(), m_animation_enabled, m_camera, m_camera_is_moving, m_camera_moving_speed, m_moving_speed_multiplier, m_render_pivot, m_strtime_camera_movement, Request_refresh(), and stop_editingTimeOut_Timer().

Referenced by move_pivot_based_on_cur_mouse_position(), and SetView3D().

◆ restart_editingTimeOut_Timer()

void EDA_3D_CANVAS::restart_editingTimeOut_Timer ( )
private

Reset the editing timer.

Definition at line 862 of file eda_3d_canvas.cpp.

863 {
864  if( m_3d_render )
865  m_editing_timeout_timer.Start( m_3d_render->GetWaitForEditingTimeOut(), wxTIMER_ONE_SHOT );
866 }
wxTimer m_editing_timeout_timer
virtual int GetWaitForEditingTimeOut()=0
Give the interface the time (in ms) that it should wait for editing or movements before (this works f...
RENDER_3D_BASE * m_3d_render

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

Referenced by DoRePaint(), OnLeftUp(), OnMiddleUp(), OnMouseWheel(), and SetView3D().

◆ SetAnimationEnabled()

void EDA_3D_CANVAS::SetAnimationEnabled ( bool  aEnable)
inline

Enable or disable camera animation when switching to a pre-defined view.

Definition at line 127 of file eda_3d_canvas.h.

127 { m_animation_enabled = aEnable; }
bool m_animation_enabled

References m_animation_enabled.

Referenced by PANEL_PREVIEW_3D_MODEL::loadSettings(), EDA_3D_VIEWER_FRAME::LoadSettings(), and PANEL_3D_DISPLAY_OPTIONS::TransferDataFromWindow().

◆ SetEventDispatcher()

void EDA_3D_CANVAS::SetEventDispatcher ( TOOL_DISPATCHER aEventDispatcher)

Set a dispatcher that processes events and forwards them to tools.

#DRAW_PANEL_GAL does not take over the ownership. Passing NULL disconnects all event handlers from the DRAW_PANEL_GAL and parent frame.

Parameters
aEventDispatcheris the object that will be used for dispatching events.

Definition at line 561 of file eda_3d_canvas.cpp.

562 {
563  m_eventDispatcher = aEventDispatcher;
564 }
TOOL_DISPATCHER * m_eventDispatcher

References m_eventDispatcher.

Referenced by PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL(), and EDA_3D_VIEWER_FRAME::~EDA_3D_VIEWER_FRAME().

◆ SetInfoBar()

void EDA_3D_CANVAS::SetInfoBar ( WX_INFOBAR aInfoBar)
inline

Definition at line 79 of file eda_3d_canvas.h.

80  {
81  m_parentInfoBar = aInfoBar;
82  }
WX_INFOBAR * m_parentInfoBar

References m_parentInfoBar.

Referenced by PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL().

◆ SetMovingSpeedMultiplier()

void EDA_3D_CANVAS::SetMovingSpeedMultiplier ( int  aMultiplier)
inline

Set the camera animation moving speed multiplier option.

Parameters
aMultiplierone of the possible integer options: [1,2,3,4,5].

Definition at line 135 of file eda_3d_canvas.h.

135 { m_moving_speed_multiplier = aMultiplier; }
int m_moving_speed_multiplier

References m_moving_speed_multiplier.

Referenced by PANEL_PREVIEW_3D_MODEL::loadSettings(), EDA_3D_VIEWER_FRAME::LoadSettings(), and PANEL_3D_DISPLAY_OPTIONS::TransferDataFromWindow().

◆ SetProjectionMode()

void EDA_3D_CANVAS::SetProjectionMode ( int  aMode)
inline

Definition at line 139 of file eda_3d_canvas.h.

139 { m_camera.SetProjection( (PROJECTION_TYPE) aMode ); }
PROJECTION_TYPE
Definition: camera.h:37
CAMERA & m_camera
void SetProjection(PROJECTION_TYPE aProjection)
Definition: camera.h:162

References m_camera, and CAMERA::SetProjection().

Referenced by PANEL_PREVIEW_3D_MODEL::loadSettings(), and EDA_3D_VIEWER_FRAME::LoadSettings().

◆ SetScaleFactor()

void HIDPI_GL_CANVAS::SetScaleFactor ( double  aFactor)
inherited

Set the canvas scale factor, probably for a hi-DPI display.

Definition at line 65 of file hidpi_gl_canvas.cpp.

66 {
67  m_scale_factor = aNewScaleFactor;
68 }
double m_scale_factor
The current scale factor (e.g.

References HIDPI_GL_CANVAS::m_scale_factor.

Referenced by EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER(), EDA_3D_VIEWER_FRAME::loadCommonSettings(), PANEL_PREVIEW_3D_MODEL::loadSettings(), and KIGFX::OPENGL_GAL::updatedGalDisplayOptions().

◆ SetStatusBar()

void EDA_3D_CANVAS::SetStatusBar ( wxStatusBar *  aStatusBar)
inline

Definition at line 74 of file eda_3d_canvas.h.

75  {
76  m_parentStatusBar = aStatusBar;
77  }
wxStatusBar * m_parentStatusBar

References m_parentStatusBar.

◆ SetView3D()

bool EDA_3D_CANVAS::SetView3D ( int  aKeycode)

Helper function to call view commands.

Parameters
aKeycodeascii key commands.
Returns
true if the key code was handled, false if no command found for this code.

Definition at line 950 of file eda_3d_canvas.cpp.

951 {
952  if( m_camera_is_moving )
953  return false;
954 
955  const float delta_move = m_delta_move_step_factor * m_camera.GetZoom();
956  const float arrow_moving_time_speed = 8.0f;
957  bool handled = false;
958 
959  switch( aKeycode )
960  {
961  case WXK_SPACE:
963  return true;
964 
965  case WXK_LEFT:
968  m_camera.Pan_T1( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
969  request_start_moving_camera( arrow_moving_time_speed, false );
970  return true;
971 
972  case WXK_RIGHT:
975  m_camera.Pan_T1( SFVEC3F( +delta_move, 0.0f, 0.0f ) );
976  request_start_moving_camera( arrow_moving_time_speed, false );
977  return true;
978 
979  case WXK_UP:
982  m_camera.Pan_T1( SFVEC3F( 0.0f, +delta_move, 0.0f ) );
983  request_start_moving_camera( arrow_moving_time_speed, false );
984  return true;
985 
986  case WXK_DOWN:
989  m_camera.Pan_T1( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
990  request_start_moving_camera( arrow_moving_time_speed, false );
991  return true;
992 
993  case WXK_HOME:
996  m_camera.Reset_T1();
997  request_start_moving_camera( glm::min( glm::max( m_camera.GetZoom(), 1 / 1.26f ), 1.26f ) );
998  return true;
999 
1000  case WXK_END:
1001  break;
1002 
1003  case WXK_TAB:
1006  m_camera.RotateZ_T1( glm::radians( 45.0f ) );
1008  handled = true;
1009  break;
1010 
1011  case WXK_F1:
1014 
1015  if( m_camera.Zoom_T1( 1.26f ) ) // 3 steps per doubling
1017 
1018  return true;
1019 
1020  case WXK_F2:
1023 
1024  if( m_camera.Zoom_T1( 1/1.26f ) ) // 3 steps per halving
1026 
1027  return true;
1028 
1029  case ID_VIEW3D_RESET:
1032  m_camera.Reset_T1();
1033  request_start_moving_camera( glm::min( glm::max( m_camera.GetZoom(), 0.5f ), 1.125f ) );
1034  return true;
1035 
1036  case ID_VIEW3D_RIGHT:
1039  m_camera.Reset_T1();
1040  m_camera.RotateZ_T1( glm::radians( -90.0f ) );
1041  m_camera.RotateX_T1( glm::radians( -90.0f ) );
1043  return true;
1044 
1045  case ID_VIEW3D_LEFT:
1048  m_camera.Reset_T1();
1049  m_camera.RotateZ_T1( glm::radians( 90.0f ) );
1050  m_camera.RotateX_T1( glm::radians( -90.0f ) );
1052  return true;
1053 
1054  case ID_VIEW3D_FRONT:
1057  m_camera.Reset_T1();
1058  m_camera.RotateX_T1( glm::radians( -90.0f ) );
1060  return true;
1061 
1062  case ID_VIEW3D_BACK:
1065  m_camera.Reset_T1();
1066  m_camera.RotateX_T1( glm::radians( -90.0f ) );
1067 
1068  // The rotation angle should be 180.
1069  // We use 179.999 (180 - epsilon) to avoid a full 360 deg rotation when
1070  // using 180 deg if the previous rotated position was already 180 deg
1071  m_camera.RotateZ_T1( glm::radians( 179.999f ) );
1073  return true;
1074 
1075  case ID_VIEW3D_TOP:
1078  m_camera.Reset_T1();
1079  request_start_moving_camera( glm::min( glm::max( m_camera.GetZoom(), 0.5f ), 1.125f ) );
1080  return true;
1081 
1082  case ID_VIEW3D_BOTTOM:
1085  m_camera.Reset_T1();
1086  m_camera.RotateY_T1( glm::radians( 179.999f ) ); // Rotation = 180 - epsilon
1087  request_start_moving_camera( glm::min( glm::max( m_camera.GetZoom(), 0.5f ), 1.125f ) );
1088  return true;
1089 
1090  case ID_VIEW3D_FLIP:
1093  m_camera.RotateY_T1( glm::radians( 179.999f ) );
1095  return true;
1096 
1097  default:
1098  return false;
1099  }
1100 
1101  m_mouse_was_moved = true;
1102 
1104 
1105  DisplayStatus();
1106  Request_refresh();
1107 
1108  return handled;
1109 }
void RotateZ_T1(float aAngleInRadians)
Definition: camera.cpp:552
bool Zoom_T1(float aFactor)
Definition: camera.cpp:497
void request_start_moving_camera(float aMovingSpeed=2.0f, bool aRenderPivot=true)
Start a camera movement.
virtual void Pan_T1(const SFVEC3F &aDeltaOffsetInc)=0
void RotateY_T1(float aAngleInRadians)
Definition: camera.cpp:546
void DisplayStatus()
Update the status bar with the position information.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
void restart_editingTimeOut_Timer()
Reset the editing timer.
bool m_mouse_was_moved
bool m_camera_is_moving
float GetZoom() const
Definition: camera.h:177
virtual void Reset_T1()
Definition: camera.cpp:103
void SetInterpolateMode(CAMERA_INTERPOLATION aInterpolateMode)
Definition: camera.h:213
virtual void SetT0_and_T1_current_T()
This will set T0 and T1 with the current values.
Definition: camera.cpp:558
void move_pivot_based_on_cur_mouse_position()
This function hits a ray to the board and start a movement.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
CAMERA & m_camera
static const float m_delta_move_step_factor
void RotateX_T1(float aAngleInRadians)
Definition: camera.cpp:540

References BEZIER, DisplayStatus(), EASING_IN_OUT, CAMERA::GetZoom(), ID_VIEW3D_BACK, ID_VIEW3D_BOTTOM, ID_VIEW3D_FLIP, ID_VIEW3D_FRONT, ID_VIEW3D_LEFT, ID_VIEW3D_RESET, ID_VIEW3D_RIGHT, ID_VIEW3D_TOP, LINEAR, m_camera, m_camera_is_moving, m_delta_move_step_factor, m_mouse_was_moved, move_pivot_based_on_cur_mouse_position(), CAMERA::Pan_T1(), Request_refresh(), request_start_moving_camera(), CAMERA::Reset_T1(), restart_editingTimeOut_Timer(), CAMERA::RotateX_T1(), CAMERA::RotateY_T1(), CAMERA::RotateZ_T1(), CAMERA::SetInterpolateMode(), CAMERA::SetT0_and_T1_current_T(), and CAMERA::Zoom_T1().

Referenced by EDA_3D_CONTROLLER::doZoomInOut(), EDA_3D_CONTROLLER::PanControl(), PANEL_PREVIEW_3D_MODEL::View3DBack(), PANEL_PREVIEW_3D_MODEL::View3DBottom(), PANEL_PREVIEW_3D_MODEL::View3DFront(), PANEL_PREVIEW_3D_MODEL::View3DLeft(), PANEL_PREVIEW_3D_MODEL::View3DRight(), PANEL_PREVIEW_3D_MODEL::View3DTop(), EDA_3D_CONTROLLER::ViewControl(), and EDA_3D_CONTROLLER::ZoomFitScreen().

◆ stop_editingTimeOut_Timer()

void EDA_3D_CANVAS::stop_editingTimeOut_Timer ( )
private

Stop the editing time so it will not timeout.

Definition at line 856 of file eda_3d_canvas.cpp.

857 {
859 }
wxTimer m_editing_timeout_timer

References m_editing_timeout_timer.

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

Member Data Documentation

◆ m_3d_render

◆ m_3d_render_opengl

RENDER_3D_OPENGL* EDA_3D_CANVAS::m_3d_render_opengl
private

Definition at line 270 of file eda_3d_canvas.h.

Referenced by DoRePaint(), OnMouseMove(), releaseOpenGL(), and RenderEngineChanged().

◆ m_3d_render_raytracing

RENDER_3D_RAYTRACE* EDA_3D_CANVAS::m_3d_render_raytracing
private

◆ m_accelerator3DShapes

ACCELERATOR_3D* EDA_3D_CANVAS::m_accelerator3DShapes
private

Definition at line 278 of file eda_3d_canvas.h.

Referenced by ~EDA_3D_CANVAS().

◆ m_animation_enabled

bool EDA_3D_CANVAS::m_animation_enabled
private

◆ m_boardAdapter

BOARD_ADAPTER& EDA_3D_CANVAS::m_boardAdapter
private

◆ m_camera

◆ m_camera_is_moving

bool EDA_3D_CANVAS::m_camera_is_moving
private

◆ m_camera_moving_speed

float EDA_3D_CANVAS::m_camera_moving_speed
private

Definition at line 261 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and request_start_moving_camera().

◆ m_currentRollOverItem

BOARD_ITEM* EDA_3D_CANVAS::m_currentRollOverItem
private

Definition at line 280 of file eda_3d_canvas.h.

Referenced by OnMouseMove().

◆ m_delta_move_step_factor

const float EDA_3D_CANVAS::m_delta_move_step_factor = 0.7f
staticprivate

Definition at line 272 of file eda_3d_canvas.h.

Referenced by OnMouseWheel(), and SetView3D().

◆ m_editing_timeout_timer

wxTimer EDA_3D_CANVAS::m_editing_timeout_timer
private

Definition at line 252 of file eda_3d_canvas.h.

Referenced by restart_editingTimeOut_Timer(), and stop_editingTimeOut_Timer().

◆ m_eventDispatcher

TOOL_DISPATCHER* EDA_3D_CANVAS::m_eventDispatcher
private

Definition at line 244 of file eda_3d_canvas.h.

Referenced by OnEvent(), and SetEventDispatcher().

◆ m_glRC

wxGLContext* EDA_3D_CANVAS::m_glRC
private

Definition at line 248 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and releaseOpenGL().

◆ m_is_currently_painting

std::atomic_flag EDA_3D_CANVAS::m_is_currently_painting
private

Definition at line 255 of file eda_3d_canvas.h.

Referenced by DoRePaint().

◆ m_is_opengl_initialized

bool EDA_3D_CANVAS::m_is_opengl_initialized
private

Definition at line 249 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and initializeOpenGL().

◆ m_is_opengl_version_supported

bool EDA_3D_CANVAS::m_is_opengl_version_supported
private

Definition at line 250 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and initializeOpenGL().

◆ m_mouse_is_moving

bool EDA_3D_CANVAS::m_mouse_is_moving
private

◆ m_mouse_was_moved

bool EDA_3D_CANVAS::m_mouse_was_moved
private

◆ m_moving_speed_multiplier

int EDA_3D_CANVAS::m_moving_speed_multiplier
private

◆ m_opengl_supports_raytracing

bool EDA_3D_CANVAS::m_opengl_supports_raytracing
private

Definition at line 275 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and initializeOpenGL().

◆ m_parentInfoBar

WX_INFOBAR* EDA_3D_CANVAS::m_parentInfoBar
private

Definition at line 246 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and SetInfoBar().

◆ m_parentStatusBar

wxStatusBar* EDA_3D_CANVAS::m_parentStatusBar
private

Definition at line 245 of file eda_3d_canvas.h.

Referenced by DisplayStatus(), DoRePaint(), OnMouseMove(), and SetStatusBar().

◆ m_redraw_trigger_timer

wxTimer EDA_3D_CANVAS::m_redraw_trigger_timer
private

Definition at line 254 of file eda_3d_canvas.h.

Referenced by Request_refresh().

◆ m_render_pivot

bool EDA_3D_CANVAS::m_render_pivot
private

Definition at line 260 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and request_start_moving_camera().

◆ m_render_raytracing_was_requested

bool EDA_3D_CANVAS::m_render_raytracing_was_requested
private

Definition at line 276 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and RenderRaytracingRequest().

◆ m_strtime_camera_movement

unsigned EDA_3D_CANVAS::m_strtime_camera_movement
private

Definition at line 262 of file eda_3d_canvas.h.

Referenced by DoRePaint(), and request_start_moving_camera().


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