KiCad PCB EDA Suite
EDA_3D_MODEL_VIEWER Class Reference

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

#include <eda_3d_model_viewer.h>

Inheritance diagram for EDA_3D_MODEL_VIEWER:
HIDPI_GL_CANVAS

Public Member Functions

 EDA_3D_MODEL_VIEWER (wxWindow *aParent, const int *aAttribList=nullptr, S3D_CACHE *aCacheManager=nullptr)
 Create a new 3D Canvas with a attribute list. More...
 
 ~EDA_3D_MODEL_VIEWER ()
 
void Set3DModel (const S3DMODEL &a3DModel)
 Set this model to be displayed. More...
 
void Set3DModel (const wxString &aModelPathName)
 Set this model to be displayed. More...
 
void Clear3DModel ()
 Unload the displayed 3D model. 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 ogl_initialize ()
 
void ogl_set_arrow_material ()
 
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)
 

Private Attributes

wxGLContext * m_glRC
 openGL context More...
 
TRACK_BALL m_trackBallCamera
 Camera used in this canvas. More...
 
const S3DMODELm_3d_model
 Original 3d model data. More...
 
MODEL_3Dm_ogl_3dmodel
 Class holder for 3d model to display on openGL. More...
 
bool m_reload_is_needed
 Flag that we have a new model and it need to be reloaded when the paint is called. More...
 
bool m_ogl_initialized
 Flag if open gl was initialized. More...
 
double m_BiuTo3dUnits
 factor to convert the model or any other items to keep it in relation to the +/-RANGE_SCALE_3D (it is named same as the board render for better understanding proposes) More...
 
S3D_CACHEm_cacheManager
 Optional cache manager. More...
 

Static Private Attributes

static const wxChar * m_logTrace = wxT( "KI_TRACE_EDA_3D_MODEL_VIEWER" )
 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 45 of file eda_3d_model_viewer.h.

Constructor & Destructor Documentation

◆ EDA_3D_MODEL_VIEWER()

EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER ( wxWindow *  aParent,
const int *  aAttribList = nullptr,
S3D_CACHE aCacheManager = nullptr 
)

Create a new 3D Canvas with a attribute list.

Parameters
aParentthe parent creator of this canvas.
aAttribLista list of openGL options created by OGL_ATT_LIST::GetAttributesList.

Definition at line 85 of file eda_3d_model_viewer.cpp.

86  :
87  HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
88  wxFULL_REPAINT_ON_RESIZE ),
90  m_cacheManager( aCacheManager )
91 {
92  wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER" ) );
93 
94  m_ogl_initialized = false;
95  m_reload_is_needed = false;
96  m_ogl_3dmodel = nullptr;
97  m_3d_model = nullptr;
98  m_BiuTo3dUnits = 1.0;
99 
100  m_glRC = nullptr;
101 
102  COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
103 
104  const DPI_SCALING dpi{ settings, this };
105  SetScaleFactor( dpi.GetScaleFactor() );
106 }
double m_BiuTo3dUnits
factor to convert the model or any other items to keep it in relation to the +/-RANGE_SCALE_3D (it is...
TRACK_BALL m_trackBallCamera
Camera used in this canvas.
S3D_CACHE * m_cacheManager
Optional cache manager.
bool m_reload_is_needed
Flag that we have a new model and it need to be reloaded when the paint is called.
wxGLContext * m_glRC
openGL context
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
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:36
#define RANGE_SCALE_3D
const S3DMODEL * m_3d_model
Original 3d model data.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void SetScaleFactor(double aFactor)
Set the canvas scale factor, probably for a hi-DPI display.
bool m_ogl_initialized
Flag if open gl was initialized.
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.

References m_3d_model, m_BiuTo3dUnits, m_glRC, m_logTrace, m_ogl_3dmodel, m_ogl_initialized, m_reload_is_needed, Pgm(), and HIDPI_GL_CANVAS::SetScaleFactor().

◆ ~EDA_3D_MODEL_VIEWER()

EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER ( )

Definition at line 109 of file eda_3d_model_viewer.cpp.

110 {
111  wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER" ) );
112 
113  if( m_glRC )
114  {
116 
117  delete m_ogl_3dmodel;
118  m_ogl_3dmodel = nullptr;
119 
122  }
123 }
wxGLContext * m_glRC
openGL context
void UnlockCtx(wxGLContext *aContext)
Allow other canvases to bind an OpenGL context.
static GL_CONTEXT_MANAGER & Get()
Return the GL_CONTEXT_MANAGER instance (singleton).
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Set a context as current and prevents other canvases from switching it.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void DestroyCtx(wxGLContext *aContext)
Destroy a managed OpenGL context.
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.

References GL_CONTEXT_MANAGER::DestroyCtx(), GL_CONTEXT_MANAGER::Get(), GL_CONTEXT_MANAGER::LockCtx(), m_glRC, m_logTrace, m_ogl_3dmodel, and GL_CONTEXT_MANAGER::UnlockCtx().

Member Function Documentation

◆ Clear3DModel()

void EDA_3D_MODEL_VIEWER::Clear3DModel ( )

Unload the displayed 3D model.

Definition at line 169 of file eda_3d_model_viewer.cpp.

170 {
171  // Delete the old model
172  m_reload_is_needed = false;
173 
174  delete m_ogl_3dmodel;
175  m_ogl_3dmodel = nullptr;
176 
177  m_3d_model = nullptr;
178 
179  Refresh();
180 }
bool m_reload_is_needed
Flag that we have a new model and it need to be reloaded when the paint is called.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
const S3DMODEL * m_3d_model
Original 3d model data.
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.

References m_3d_model, m_ogl_3dmodel, m_reload_is_needed, and Refresh().

Referenced by Set3DModel().

◆ 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 EDA_3D_CANVAS::DoRePaint(), OnMouseMove(), EDA_3D_CANVAS::OnMouseMove(), 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 OnMouseMove(), EDA_3D_CANVAS::OnMouseMove(), and EDA_3D_CANVAS::OnMouseWheel().

◆ GetScaleFactor()

◆ ogl_initialize()

void EDA_3D_MODEL_VIEWER::ogl_initialize ( )
private

Definition at line 183 of file eda_3d_model_viewer.cpp.

184 {
185  glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
186  glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
187  glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
188 
189  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
190  glEnable( GL_DEPTH_TEST );
191  glEnable( GL_CULL_FACE );
192  glShadeModel( GL_SMOOTH );
193  glEnable( GL_LINE_SMOOTH );
194  glEnable( GL_NORMALIZE );
195 
196  // Setup light
197  // https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
198  const GLfloat ambient[] = { 0.01f, 0.01f, 0.01f, 1.0f };
199  const GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
200  const GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
201 
202  // defines a directional light that points along the negative z-axis
203  const GLfloat position[] = { 0.0f, 0.0f, 2.0f * RANGE_SCALE_3D, 0.0f };
204 
205  const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
206 
207  glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
208  glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
209  glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
210  glLightfv( GL_LIGHT0, GL_POSITION, position );
211  glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
212 }
#define RANGE_SCALE_3D

References RANGE_SCALE_3D.

Referenced by OnPaint().

◆ ogl_set_arrow_material()

void EDA_3D_MODEL_VIEWER::ogl_set_arrow_material ( )
private

Definition at line 215 of file eda_3d_model_viewer.cpp.

216 {
217  glEnable( GL_COLOR_MATERIAL );
218  glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
219 
220  const SFVEC4F specular = SFVEC4F( 0.1f, 0.1f, 0.1f, 1.0f );
221 
222  glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
223  glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
224 }
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46

Referenced by OnPaint().

◆ OnEraseBackground()

void EDA_3D_MODEL_VIEWER::OnEraseBackground ( wxEraseEvent &  event)
private

Definition at line 358 of file eda_3d_model_viewer.cpp.

359 {
360  wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnEraseBackground" ) );
361  // Do nothing, to avoid flashing.
362 }
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.

References m_logTrace.

◆ OnLeftDown()

void EDA_3D_MODEL_VIEWER::OnLeftDown ( wxMouseEvent &  event)
private

Definition at line 422 of file eda_3d_model_viewer.cpp.

423 {
424  event.Skip();
425 }

◆ OnLeftUp()

void EDA_3D_MODEL_VIEWER::OnLeftUp ( wxMouseEvent &  event)
private

Definition at line 428 of file eda_3d_model_viewer.cpp.

429 {
430  event.Skip();
431 }

◆ OnMiddleDown()

void EDA_3D_MODEL_VIEWER::OnMiddleDown ( wxMouseEvent &  event)
private

Definition at line 434 of file eda_3d_model_viewer.cpp.

435 {
436  event.Skip();
437 }

◆ OnMiddleUp()

void EDA_3D_MODEL_VIEWER::OnMiddleUp ( wxMouseEvent &  event)
private

Definition at line 440 of file eda_3d_model_viewer.cpp.

441 {
442  event.Skip();
443 }

◆ OnMouseMove()

void EDA_3D_MODEL_VIEWER::OnMouseMove ( wxMouseEvent &  event)
private

Definition at line 402 of file eda_3d_model_viewer.cpp.

403 {
404  const wxSize& nativeWinSize = GetNativePixelSize();
405  const wxPoint& nativePosition = GetNativePosition( event.GetPosition() );
406 
407  m_trackBallCamera.SetCurWindowSize( nativeWinSize );
408 
409  if( event.Dragging() )
410  {
411  if( event.LeftIsDown() ) // Drag
412  m_trackBallCamera.Drag( nativePosition );
413 
414  // orientation has changed, redraw mesh
415  Refresh( false );
416  }
417 
418  m_trackBallCamera.SetCurMousePosition( nativePosition );
419 }
virtual wxSize GetNativePixelSize() const
TRACK_BALL m_trackBallCamera
Camera used in this canvas.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
Definition: camera.cpp:439
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
void Drag(const wxPoint &aNewMousePosition) override
Calculate a new mouse drag position.
Definition: track_ball.cpp:52

References TRACK_BALL::Drag(), HIDPI_GL_CANVAS::GetNativePixelSize(), HIDPI_GL_CANVAS::GetNativePosition(), m_trackBallCamera, Refresh(), CAMERA::SetCurMousePosition(), and CAMERA::SetCurWindowSize().

◆ OnMouseWheel()

void EDA_3D_MODEL_VIEWER::OnMouseWheel ( wxMouseEvent &  event)
private

Definition at line 365 of file eda_3d_model_viewer.cpp.

366 {
367  wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnMouseWheel" ) );
368 
369  if( event.ShiftDown() )
370  {
371  //if( event.GetWheelRotation() < 0 )
372  //SetView3D( WXK_UP ); // move up
373  //else
374  //SetView3D( WXK_DOWN ); // move down
375  }
376  else if( event.ControlDown() )
377  {
378  //if( event.GetWheelRotation() > 0 )
379  //SetView3D( WXK_RIGHT ); // move right
380  //else
381  //SetView3D( WXK_LEFT ); // move left
382  }
383  else
384  {
385  m_trackBallCamera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f );
386 
387  //DisplayStatus();
388  Refresh( false );
389  }
390 
391  m_trackBallCamera.SetCurMousePosition( event.GetPosition() );
392 }
TRACK_BALL m_trackBallCamera
Camera used in this canvas.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
Definition: camera.cpp:439
bool Zoom(float aFactor)
Definition: camera.cpp:482
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.

References m_logTrace, m_trackBallCamera, Refresh(), CAMERA::SetCurMousePosition(), and CAMERA::Zoom().

◆ OnPaint()

void EDA_3D_MODEL_VIEWER::OnPaint ( wxPaintEvent &  event)
private

Definition at line 227 of file eda_3d_model_viewer.cpp.

228 {
229  event.Skip( false );
230 
231  // SwapBuffer requires the window to be shown before calling
232  if( !IsShownOnScreen() )
233  {
234  wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnPaint !IsShown" ) );
235  return;
236  }
237 
238  // "Makes the OpenGL state that is represented by the OpenGL rendering
239  // context context current, i.e. it will be used by all subsequent OpenGL calls.
240  // This function may only be called when the window is shown on screen"
241  if( m_glRC == nullptr )
243 
245 
246  // Set the OpenGL viewport according to the client size of this canvas.
247  // This is done here rather than in a wxSizeEvent handler because our
248  // OpenGL rendering context (and thus viewport setting) is used with
249  // multiple canvases: If we updated the viewport in the wxSizeEvent
250  // handler, changing the size of one canvas causes a viewport setting that
251  // is wrong when next another canvas is repainted.
252  wxSize clientSize = GetNativePixelSize();
253 
254  if( !m_ogl_initialized )
255  {
256  m_ogl_initialized = true;
257  ogl_initialize();
258  }
259 
260  if( m_reload_is_needed )
261  {
262  wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );
263 
264  m_reload_is_needed = false;
266 
267  // It convert a model as it was a board, so get the max size dimension of the board
268  // and compute the conversion scale
270  (double) RANGE_SCALE_3D
272  }
273 
274  glViewport( 0, 0, clientSize.x, clientSize.y );
275 
276  m_trackBallCamera.SetCurWindowSize( clientSize );
277 
278  // clear color and depth buffers
279  glEnable( GL_DEPTH_TEST );
280  glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
281  glClearDepth( 1.0f );
282  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
283 
284  // Set projection and modelview matrices
285  glMatrixMode( GL_PROJECTION );
286  glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) );
287  glMatrixMode( GL_MODELVIEW );
288  glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) );
289  glEnable( GL_LIGHTING );
290  glEnable( GL_LIGHT0 );
291 
292  // Render Model
293  if( m_ogl_3dmodel )
294  {
295  glPushMatrix();
296 
297  double modelunit_to_3d_units_factor = m_BiuTo3dUnits * UNITS3D_TO_UNITSPCB;
298 
299  glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor,
300  modelunit_to_3d_units_factor );
301 
302  // Center model in the render viewport
303  const SFVEC3F model_center = m_ogl_3dmodel->GetBBox().GetCenter();
304 
305  glTranslatef( -model_center.x, -model_center.y, -model_center.z );
306 
307  m_ogl_3dmodel->BeginDrawMulti( true );
308 
309  m_ogl_3dmodel->DrawOpaque( false );
310  m_ogl_3dmodel->DrawTransparent( 1.0f, false );
311 
313 
314  glPopMatrix();
315  }
316 
317  // YxY squared view port
318  glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 );
319  glClear( GL_DEPTH_BUFFER_BIT );
320 
321  glMatrixMode( GL_PROJECTION );
322  glLoadIdentity();
323  gluPerspective( 45.0f, 1.0f, 0.01f, RANGE_SCALE_3D * 2.0f );
324 
325  glMatrixMode( GL_MODELVIEW );
326  glLoadIdentity();
327 
328  const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f),
329  SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
330 
331  const glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();
332 
333  glLoadMatrixf( glm::value_ptr( ViewMatrix ) );
334 
336 
337  glColor3f( 0.9f, 0.0f, 0.0f );
338  DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
339  0.275f );
340 
341  glColor3f( 0.0f, 0.9f, 0.0f );
342  DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
343  0.275f );
344 
345  glColor3f( 0.0f, 0.0f, 0.9f );
346  DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
347  0.275f );
348 
349  // "Swaps the double-buffer of this window, making the back-buffer the
350  // front-buffer and vice versa, so that the output of the previous OpenGL
351  // commands is displayed on the window."
352  SwapBuffers();
353 
355 }
virtual wxSize GetNativePixelSize() const
double m_BiuTo3dUnits
factor to convert the model or any other items to keep it in relation to the +/-RANGE_SCALE_3D (it is...
TRACK_BALL m_trackBallCamera
Camera used in this canvas.
const glm::mat4 & GetProjectionMatrix() const
Definition: camera.cpp:391
bool m_reload_is_needed
Flag that we have a new model and it need to be reloaded when the paint is called.
#define UNITS3D_TO_UNITSPCB
Implements a model viewer canvas.
wxGLContext * m_glRC
openGL context
const glm::mat4 GetRotationMatrix() const
Get the rotation matrix to be applied in a transformation camera.
Definition: camera.cpp:168
void UnlockCtx(wxGLContext *aContext)
Allow other canvases to bind an OpenGL context.
#define RANGE_SCALE_3D
static GL_CONTEXT_MANAGER & Get()
Return the GL_CONTEXT_MANAGER instance (singleton).
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition: bbox_3d.cpp:132
Use all material properties from model file.
float GetMaxDimension() const
Definition: bbox_3d.cpp:167
const glm::mat4 & GetViewMatrix() const
Definition: camera.cpp:427
const S3DMODEL * m_3d_model
Original 3d model data.
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=nullptr)
Create a managed OpenGL context.
void DrawRoundArrow(SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize)
Draw a round arrow.
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Set a context as current and prevents other canvases from switching it.
bool SetCurWindowSize(const wxSize &aSize)
Update the windows size of the camera.
Definition: camera.cpp:456
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void DrawOpaque(bool aUseSelectedMaterial, SFVEC3F aSelectionColor=SFVEC3F(0.0f)) const
Render the model into the current context.
Definition: 3d_model.h:55
static void EndDrawMulti()
Cleanup render states after drawing multiple models.
Definition: 3d_model.cpp:401
void DrawTransparent(float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor=SFVEC3F(0.0f)) const
Render the model into the current context.
Definition: 3d_model.h:63
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
bool m_ogl_initialized
Flag if open gl was initialized.
const BBOX_3D & GetBBox() const
Get the main bounding box.
Definition: 3d_model.h:93
static void BeginDrawMulti(bool aUseColorInformation)
Set some basic render states before drawing multiple models.
Definition: 3d_model.cpp:385
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.

References MODEL_3D::BeginDrawMulti(), GL_CONTEXT_MANAGER::CreateCtx(), MODEL_3D::DrawOpaque(), DrawRoundArrow(), MODEL_3D::DrawTransparent(), MODEL_3D::EndDrawMulti(), GL_CONTEXT_MANAGER::Get(), MODEL_3D::GetBBox(), BBOX_3D::GetCenter(), BBOX_3D::GetMaxDimension(), HIDPI_GL_CANVAS::GetNativePixelSize(), CAMERA::GetProjectionMatrix(), CAMERA::GetRotationMatrix(), CAMERA::GetViewMatrix(), GL_CONTEXT_MANAGER::LockCtx(), m_3d_model, m_BiuTo3dUnits, m_glRC, m_logTrace, m_ogl_3dmodel, m_ogl_initialized, m_reload_is_needed, m_trackBallCamera, NORMAL, ogl_initialize(), ogl_set_arrow_material(), RANGE_SCALE_3D, CAMERA::SetCurWindowSize(), UNITS3D_TO_UNITSPCB, and GL_CONTEXT_MANAGER::UnlockCtx().

◆ OnRightClick()

void EDA_3D_MODEL_VIEWER::OnRightClick ( wxMouseEvent &  event)
private

Definition at line 446 of file eda_3d_model_viewer.cpp.

447 {
448  event.Skip();
449 }

◆ Set3DModel() [1/2]

void EDA_3D_MODEL_VIEWER::Set3DModel ( const S3DMODEL a3DModel)

Set this model to be displayed.

Parameters
a3DModel3D model data.

Definition at line 126 of file eda_3d_model_viewer.cpp.

127 {
128  wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) );
129 
130  // Validate a3DModel pointers
131  wxASSERT( a3DModel.m_Materials != nullptr );
132  wxASSERT( a3DModel.m_Meshes != nullptr );
133  wxASSERT( a3DModel.m_MaterialsSize > 0 );
134  wxASSERT( a3DModel.m_MeshesSize > 0 );
135 
136  // Delete the old model
137  delete m_ogl_3dmodel;
138  m_ogl_3dmodel = nullptr;
139 
140  m_3d_model = nullptr;
141 
142  if( ( a3DModel.m_Materials != nullptr ) && ( a3DModel.m_Meshes != nullptr )
143  && ( a3DModel.m_MaterialsSize > 0 ) && ( a3DModel.m_MeshesSize > 0 ) )
144  {
145  m_3d_model = &a3DModel;
146  m_reload_is_needed = true;
147  }
148 
149  Refresh();
150 }
bool m_reload_is_needed
Flag that we have a new model and it need to be reloaded when the paint is called.
SMESH * m_Meshes
The meshes list of this model.
Definition: c3dmodel.h:93
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
const S3DMODEL * m_3d_model
Original 3d model data.
unsigned int m_MaterialsSize
Number of materials in the material array.
Definition: c3dmodel.h:95
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
SMATERIAL * m_Materials
The materials list of this model.
Definition: c3dmodel.h:96
unsigned int m_MeshesSize
Number of meshes in the array.
Definition: c3dmodel.h:92
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.

References m_3d_model, m_logTrace, S3DMODEL::m_Materials, S3DMODEL::m_MaterialsSize, S3DMODEL::m_Meshes, S3DMODEL::m_MeshesSize, m_ogl_3dmodel, m_reload_is_needed, and Refresh().

Referenced by DIALOG_SELECT_3DMODEL::OnFileActivated(), DIALOG_SELECT_3DMODEL::OnSelectionChanged(), and Set3DModel().

◆ Set3DModel() [2/2]

void EDA_3D_MODEL_VIEWER::Set3DModel ( const wxString &  aModelPathName)

Set this model to be displayed.

Parameters
aModelPathName3D model path name.

Definition at line 153 of file eda_3d_model_viewer.cpp.

154 {
155  wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::Set3DModel with a wxString" ) );
156 
157  if( m_cacheManager )
158  {
159  const S3DMODEL* model = m_cacheManager->GetModel( aModelPathName );
160 
161  if( model )
162  Set3DModel( (const S3DMODEL &)*model );
163  else
164  Clear3DModel();
165  }
166 }
S3D_CACHE * m_cacheManager
Optional cache manager.
S3DMODEL * GetModel(const wxString &aModelFileName)
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for displa...
Definition: 3d_cache.cpp:646
void Clear3DModel()
Unload the displayed 3D model.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void Set3DModel(const S3DMODEL &a3DModel)
Set this model to be displayed.
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90

References Clear3DModel(), S3D_CACHE::GetModel(), m_cacheManager, m_logTrace, and Set3DModel().

◆ 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_VIEWER_FRAME::loadCommonSettings(), PANEL_PREVIEW_3D_MODEL::loadSettings(), and KIGFX::OPENGL_GAL::updatedGalDisplayOptions().

Member Data Documentation

◆ m_3d_model

const S3DMODEL* EDA_3D_MODEL_VIEWER::m_3d_model
private

Original 3d model data.

Definition at line 113 of file eda_3d_model_viewer.h.

Referenced by Clear3DModel(), EDA_3D_MODEL_VIEWER(), OnPaint(), and Set3DModel().

◆ m_BiuTo3dUnits

double EDA_3D_MODEL_VIEWER::m_BiuTo3dUnits
private

factor to convert the model or any other items to keep it in relation to the +/-RANGE_SCALE_3D (it is named same as the board render for better understanding proposes)

Definition at line 127 of file eda_3d_model_viewer.h.

Referenced by EDA_3D_MODEL_VIEWER(), and OnPaint().

◆ m_cacheManager

S3D_CACHE* EDA_3D_MODEL_VIEWER::m_cacheManager
private

Optional cache manager.

Definition at line 130 of file eda_3d_model_viewer.h.

Referenced by Set3DModel().

◆ m_glRC

wxGLContext* EDA_3D_MODEL_VIEWER::m_glRC
private

openGL context

Definition at line 107 of file eda_3d_model_viewer.h.

Referenced by EDA_3D_MODEL_VIEWER(), OnPaint(), and ~EDA_3D_MODEL_VIEWER().

◆ m_ogl_3dmodel

MODEL_3D* EDA_3D_MODEL_VIEWER::m_ogl_3dmodel
private

Class holder for 3d model to display on openGL.

Definition at line 116 of file eda_3d_model_viewer.h.

Referenced by Clear3DModel(), EDA_3D_MODEL_VIEWER(), OnPaint(), Set3DModel(), and ~EDA_3D_MODEL_VIEWER().

◆ m_ogl_initialized

bool EDA_3D_MODEL_VIEWER::m_ogl_initialized
private

Flag if open gl was initialized.

Definition at line 122 of file eda_3d_model_viewer.h.

Referenced by EDA_3D_MODEL_VIEWER(), and OnPaint().

◆ m_reload_is_needed

bool EDA_3D_MODEL_VIEWER::m_reload_is_needed
private

Flag that we have a new model and it need to be reloaded when the paint is called.

Definition at line 119 of file eda_3d_model_viewer.h.

Referenced by Clear3DModel(), EDA_3D_MODEL_VIEWER(), OnPaint(), and Set3DModel().

◆ m_trackBallCamera

TRACK_BALL EDA_3D_MODEL_VIEWER::m_trackBallCamera
private

Camera used in this canvas.

Definition at line 110 of file eda_3d_model_viewer.h.

Referenced by OnMouseMove(), OnMouseWheel(), and OnPaint().


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