KiCad PCB EDA Suite
C3D_MODEL_VIEWER Class Reference

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

#include <3d_model_viewer.h>

Inheritance diagram for C3D_MODEL_VIEWER:
HIDPI_GL_CANVAS

Public Member Functions

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

Constructor & Destructor Documentation

◆ C3D_MODEL_VIEWER()

C3D_MODEL_VIEWER::C3D_MODEL_VIEWER ( wxWindow *  aParent,
const int *  aAttribList = 0,
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 3d_model_viewer.cpp.

86  :
87  HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
88  wxFULL_REPAINT_ON_RESIZE ),
89  m_trackBallCamera( RANGE_SCALE_3D * 2.0f ), m_cacheManager( aCacheManager )
90 {
91  wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::C3D_MODEL_VIEWER" ) );
92 
93  m_ogl_initialized = false;
94  m_reload_is_needed = false;
95  m_ogl_3dmodel = nullptr;
96  m_3d_model = nullptr;
97  m_BiuTo3dUnits = 1.0;
98 
99  m_glRC = nullptr;
100 }
const S3DMODEL * m_3d_model
Original 3d model data.
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
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.
HIDPI_GL_CANVAS(wxWindow *parent, wxWindowID id=wxID_ANY, const int *attribList=NULL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxGLCanvasName, const wxPalette &palette=wxNullPalette)
#define RANGE_SCALE_3D
S3D_CACHE * m_cacheManager
Optional cache manager.
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.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
bool m_ogl_initialized
Flag if open gl was initialized.

References m_3d_model, m_BiuTo3dUnits, m_glRC, m_logTrace, m_ogl_3dmodel, m_ogl_initialized, and m_reload_is_needed.

◆ ~C3D_MODEL_VIEWER()

C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER ( )

Definition at line 103 of file 3d_model_viewer.cpp.

104 {
105  wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER" ) );
106 
107  if( m_glRC )
108  {
110 
111  delete m_ogl_3dmodel;
112  m_ogl_3dmodel = nullptr;
113 
116  }
117 }
wxGLContext * m_glRC
openGL context
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.
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.

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 C3D_MODEL_VIEWER::Clear3DModel ( )

Unload the displayed 3D model.

Definition at line 163 of file 3d_model_viewer.cpp.

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

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 46 of file hidpi_gl_canvas.cpp.

47 {
48  wxSize size = wxGLCanvas::GetClientSize();
49 
50  const double scaleFactor = GetScaleFactor();
51  size.x *= scaleFactor;
52  size.y *= scaleFactor;
53 
54  return size;
55 }
double GetScaleFactor() const
Get the current scale factor.

References HIDPI_GL_CANVAS::GetScaleFactor().

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

◆ GetScaleFactor()

double HIDPI_GL_CANVAS::GetScaleFactor ( ) const
inherited

◆ ogl_initialize()

void C3D_MODEL_VIEWER::ogl_initialize ( )
private

Definition at line 177 of file 3d_model_viewer.cpp.

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

References RANGE_SCALE_3D.

Referenced by OnPaint().

◆ ogl_set_arrow_material()

void C3D_MODEL_VIEWER::ogl_set_arrow_material ( )
private

Definition at line 209 of file 3d_model_viewer.cpp.

210 {
211  glEnable( GL_COLOR_MATERIAL );
212  glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
213 
214  const SFVEC4F specular = SFVEC4F( 0.1f, 0.1f, 0.1f, 1.0f );
215 
216  glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
217  glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
218 }
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46

Referenced by OnPaint().

◆ OnEraseBackground()

void C3D_MODEL_VIEWER::OnEraseBackground ( wxEraseEvent &  event)
private

Definition at line 352 of file 3d_model_viewer.cpp.

353 {
354  wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnEraseBackground" ) );
355  // Do nothing, to avoid flashing.
356 }
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.

References m_logTrace.

◆ OnLeftDown()

void C3D_MODEL_VIEWER::OnLeftDown ( wxMouseEvent &  event)
private

Definition at line 413 of file 3d_model_viewer.cpp.

414 {
415  event.Skip();
416 }

◆ OnLeftUp()

void C3D_MODEL_VIEWER::OnLeftUp ( wxMouseEvent &  event)
private

Definition at line 419 of file 3d_model_viewer.cpp.

420 {
421  event.Skip();
422 }

◆ OnMiddleDown()

void C3D_MODEL_VIEWER::OnMiddleDown ( wxMouseEvent &  event)
private

Definition at line 425 of file 3d_model_viewer.cpp.

426 {
427  event.Skip();
428 }

◆ OnMiddleUp()

void C3D_MODEL_VIEWER::OnMiddleUp ( wxMouseEvent &  event)
private

Definition at line 431 of file 3d_model_viewer.cpp.

432 {
433  event.Skip();
434 }

◆ OnMouseMove()

void C3D_MODEL_VIEWER::OnMouseMove ( wxMouseEvent &  event)
private

Definition at line 396 of file 3d_model_viewer.cpp.

397 {
398  m_trackBallCamera.SetCurWindowSize( GetClientSize() );
399 
400  if( event.Dragging() )
401  {
402  if( event.LeftIsDown() ) // Drag
403  m_trackBallCamera.Drag( event.GetPosition() );
404 
405  // orientation has changed, redraw mesh
406  Refresh( false );
407  }
408 
409  m_trackBallCamera.SetCurMousePosition( event.GetPosition() );
410 }
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:418
TRACK_BALL m_trackBallCamera
Camera used in this canvas.
bool SetCurWindowSize(const wxSize &aSize)
Update the windows size of the camera.
Definition: camera.cpp:435
void Drag(const wxPoint &aNewMousePosition) override
Calculate a new mouse drag position.
Definition: track_ball.cpp:51

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

◆ OnMouseWheel()

void C3D_MODEL_VIEWER::OnMouseWheel ( wxMouseEvent &  event)
private

Definition at line 359 of file 3d_model_viewer.cpp.

360 {
361  wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnMouseWheel" ) );
362 
363  if( event.ShiftDown() )
364  {
365  //if( event.GetWheelRotation() < 0 )
366  //SetView3D( WXK_UP ); // move up
367  //else
368  //SetView3D( WXK_DOWN ); // move down
369  }
370  else if( event.ControlDown() )
371  {
372  //if( event.GetWheelRotation() > 0 )
373  //SetView3D( WXK_RIGHT ); // move right
374  //else
375  //SetView3D( WXK_LEFT ); // move left
376  }
377  else
378  {
379  m_trackBallCamera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f );
380 
381  //DisplayStatus();
382  Refresh( false );
383  }
384 
385  m_trackBallCamera.SetCurMousePosition( event.GetPosition() );
386 }
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:418
bool Zoom(float aFactor)
Definition: camera.cpp:461
TRACK_BALL m_trackBallCamera
Camera used in this canvas.
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 C3D_MODEL_VIEWER::OnPaint ( wxPaintEvent &  event)
private

Definition at line 221 of file 3d_model_viewer.cpp.

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

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(), 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 C3D_MODEL_VIEWER::OnRightClick ( wxMouseEvent &  event)
private

Definition at line 437 of file 3d_model_viewer.cpp.

438 {
439  event.Skip();
440 }

◆ Set3DModel() [1/2]

void C3D_MODEL_VIEWER::Set3DModel ( const S3DMODEL a3DModel)

Set this model to be displayed.

Parameters
a3DModel3D model data.

Definition at line 120 of file 3d_model_viewer.cpp.

121 {
122  wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) );
123 
124  // Validate a3DModel pointers
125  wxASSERT( a3DModel.m_Materials != nullptr );
126  wxASSERT( a3DModel.m_Meshes != nullptr );
127  wxASSERT( a3DModel.m_MaterialsSize > 0 );
128  wxASSERT( a3DModel.m_MeshesSize > 0 );
129 
130  // Delete the old model
131  delete m_ogl_3dmodel;
132  m_ogl_3dmodel = nullptr;
133 
134  m_3d_model = nullptr;
135 
136  if( ( a3DModel.m_Materials != nullptr ) && ( a3DModel.m_Meshes != nullptr )
137  && ( a3DModel.m_MaterialsSize > 0 ) && ( a3DModel.m_MeshesSize > 0 ) )
138  {
139  m_3d_model = &a3DModel;
140  m_reload_is_needed = true;
141  }
142 
143  Refresh();
144 }
const S3DMODEL * m_3d_model
Original 3d model data.
bool m_reload_is_needed
Flag that we have a new model and it need to be reloaded when the paint is called.
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.
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...
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

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 DLG_SELECT_3DMODEL::OnFileActivated(), DLG_SELECT_3DMODEL::OnSelectionChanged(), and Set3DModel().

◆ Set3DModel() [2/2]

void C3D_MODEL_VIEWER::Set3DModel ( wxString const &  aModelPathName)

Set this model to be displayed.

Parameters
aModelPathName3D model path name.

Definition at line 147 of file 3d_model_viewer.cpp.

148 {
149  wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a wxString" ) );
150 
151  if( m_cacheManager )
152  {
153  const S3DMODEL* model = m_cacheManager->GetModel( aModelPathName );
154 
155  if( model )
156  Set3DModel( (const S3DMODEL &)*model );
157  else
158  Clear3DModel();
159  }
160 }
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 Set3DModel(const S3DMODEL &a3DModel)
Set this model to be displayed.
S3D_CACHE * m_cacheManager
Optional cache manager.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
void Clear3DModel()
Unload the displayed 3D model.

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 58 of file hidpi_gl_canvas.cpp.

59 {
60  m_scale_factor = aNewScaleFactor;
61 }
double m_scale_factor
The current scale factor (e.g.

References HIDPI_GL_CANVAS::m_scale_factor.

Referenced by PANEL_PREV_3D::loadCommonSettings(), EDA_3D_VIEWER::loadCommonSettings(), and KIGFX::OPENGL_GAL::updatedGalDisplayOptions().

Member Data Documentation

◆ m_3d_model

const S3DMODEL* C3D_MODEL_VIEWER::m_3d_model
private

Original 3d model data.

Definition at line 113 of file 3d_model_viewer.h.

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

◆ m_BiuTo3dUnits

double C3D_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 3d_model_viewer.h.

Referenced by C3D_MODEL_VIEWER(), and OnPaint().

◆ m_cacheManager

S3D_CACHE* C3D_MODEL_VIEWER::m_cacheManager
private

Optional cache manager.

Definition at line 130 of file 3d_model_viewer.h.

Referenced by Set3DModel().

◆ m_glRC

wxGLContext* C3D_MODEL_VIEWER::m_glRC
private

openGL context

Definition at line 107 of file 3d_model_viewer.h.

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

◆ m_ogl_3dmodel

MODEL_3D* C3D_MODEL_VIEWER::m_ogl_3dmodel
private

Class holder for 3d model to display on openGL.

Definition at line 116 of file 3d_model_viewer.h.

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

◆ m_ogl_initialized

bool C3D_MODEL_VIEWER::m_ogl_initialized
private

Flag if open gl was initialized.

Definition at line 122 of file 3d_model_viewer.h.

Referenced by C3D_MODEL_VIEWER(), and OnPaint().

◆ m_reload_is_needed

bool C3D_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 3d_model_viewer.h.

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

◆ m_trackBallCamera

TRACK_BALL C3D_MODEL_VIEWER::m_trackBallCamera
private

Camera used in this canvas.

Definition at line 110 of file 3d_model_viewer.h.

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


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