2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-07-19 17:35:25 +00:00
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2021-06-28 18:06:30 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-06-28 18:06:30 +00:00
|
|
|
* @brief Implements a model viewer canvas. The purpose of the model viewer is to render
|
|
|
|
* 3d models that come in the original data from the files without any transformations.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
|
2023-01-24 03:52:18 +00:00
|
|
|
#include <gal/opengl/kiglew.h> // Must be included first
|
2015-12-08 07:31:57 +00:00
|
|
|
#include <iostream>
|
2021-10-21 13:29:19 +00:00
|
|
|
#include "3d_rendering/opengl/3d_model.h"
|
2021-06-19 17:28:45 +00:00
|
|
|
#include "eda_3d_model_viewer.h"
|
2021-10-21 13:29:19 +00:00
|
|
|
#include "../3d_rendering/opengl/opengl_utils.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
#include "../3d_cache/3d_cache.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
#include <wx/dcclient.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <base_units.h>
|
2016-06-03 13:46:12 +00:00
|
|
|
#include <gl_context_mgr.h>
|
2021-06-28 15:47:23 +00:00
|
|
|
#include <settings/common_settings.h>
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <gal/dpi_scaling.h>
|
2023-09-07 00:07:09 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2023-01-24 03:52:18 +00:00
|
|
|
#include <macros.h>
|
2015-12-09 07:30:48 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Scale conversion from 3d model units to pcb units
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
2022-09-17 00:45:14 +00:00
|
|
|
#define UNITS3D_TO_UNITSPCB ( pcbIUScale.IU_PER_MM )
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Trace mask used to enable or disable the trace output of this class.
|
|
|
|
* The debug output can be turned on by setting the WXTRACE environment variable to
|
|
|
|
* "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for
|
|
|
|
* more information.
|
|
|
|
*
|
|
|
|
* @ingroup trace_env_vars
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-06-19 17:28:45 +00:00
|
|
|
const wxChar* EDA_3D_MODEL_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_MODEL_VIEWER" );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
BEGIN_EVENT_TABLE( EDA_3D_MODEL_VIEWER, wxGLCanvas )
|
|
|
|
EVT_PAINT( EDA_3D_MODEL_VIEWER::OnPaint )
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
// mouse events
|
2021-06-19 17:28:45 +00:00
|
|
|
EVT_LEFT_DOWN( EDA_3D_MODEL_VIEWER::OnLeftDown )
|
|
|
|
EVT_LEFT_UP( EDA_3D_MODEL_VIEWER::OnLeftUp )
|
|
|
|
EVT_MIDDLE_UP( EDA_3D_MODEL_VIEWER::OnMiddleUp )
|
|
|
|
EVT_MIDDLE_DOWN( EDA_3D_MODEL_VIEWER::OnMiddleDown)
|
|
|
|
EVT_RIGHT_DOWN( EDA_3D_MODEL_VIEWER::OnRightClick )
|
|
|
|
EVT_MOUSEWHEEL( EDA_3D_MODEL_VIEWER::OnMouseWheel )
|
|
|
|
EVT_MOTION( EDA_3D_MODEL_VIEWER::OnMouseMove )
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
#ifdef USE_OSX_MAGNIFY_EVENT
|
2021-06-19 17:28:45 +00:00
|
|
|
EVT_MAGNIFY( EDA_3D_MODEL_VIEWER::OnMagnify )
|
2015-12-08 07:31:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// other events
|
2021-06-19 17:28:45 +00:00
|
|
|
EVT_ERASE_BACKGROUND( EDA_3D_MODEL_VIEWER::OnEraseBackground )
|
2015-12-08 07:31:57 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// This defines the range that all coord will have to be rendered.
|
|
|
|
// It will use this value to convert to a normalized value between
|
|
|
|
// -(RANGE_SCALE_3D/2) .. +(RANGE_SCALE_3D/2)
|
2015-12-08 07:31:57 +00:00
|
|
|
#define RANGE_SCALE_3D 8.0f
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER( wxWindow* aParent, const int* aAttribList,
|
|
|
|
S3D_CACHE* aCacheManager ) :
|
2023-09-07 00:07:09 +00:00
|
|
|
HIDPI_GL_CANVAS( EDA_DRAW_PANEL_GAL::GetVcSettings(), aParent, wxID_ANY, aAttribList,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2020-12-16 22:10:42 +00:00
|
|
|
wxFULL_REPAINT_ON_RESIZE ),
|
2021-09-15 22:01:24 +00:00
|
|
|
m_trackBallCamera( RANGE_SCALE_3D * 4.0f ),
|
2021-06-28 15:47:23 +00:00
|
|
|
m_cacheManager( aCacheManager )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-06-19 17:28:45 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
m_ogl_initialized = false;
|
|
|
|
m_reload_is_needed = false;
|
2020-12-16 22:10:42 +00:00
|
|
|
m_ogl_3dmodel = nullptr;
|
|
|
|
m_3d_model = nullptr;
|
2021-01-05 22:19:00 +00:00
|
|
|
m_BiuTo3dUnits = 1.0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
m_glRC = nullptr;
|
2021-06-28 15:47:23 +00:00
|
|
|
|
|
|
|
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
|
|
|
|
|
|
|
|
const DPI_SCALING dpi{ settings, this };
|
|
|
|
SetScaleFactor( dpi.GetScaleFactor() );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-06-28 18:06:30 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_glRC )
|
|
|
|
{
|
|
|
|
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
delete m_ogl_3dmodel;
|
2020-12-16 22:10:42 +00:00
|
|
|
m_ogl_3dmodel = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
|
|
|
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC );
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::Set3DModel( const S3DMODEL& a3DModel )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-06-19 17:28:45 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
// Validate a3DModel pointers
|
2020-12-16 22:10:42 +00:00
|
|
|
wxASSERT( a3DModel.m_Materials != nullptr );
|
|
|
|
wxASSERT( a3DModel.m_Meshes != nullptr );
|
2015-12-08 07:31:57 +00:00
|
|
|
wxASSERT( a3DModel.m_MaterialsSize > 0 );
|
|
|
|
wxASSERT( a3DModel.m_MeshesSize > 0 );
|
|
|
|
|
|
|
|
// Delete the old model
|
|
|
|
delete m_ogl_3dmodel;
|
2020-12-16 22:10:42 +00:00
|
|
|
m_ogl_3dmodel = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
m_3d_model = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
if( ( a3DModel.m_Materials != nullptr ) && ( a3DModel.m_Meshes != nullptr )
|
|
|
|
&& ( a3DModel.m_MaterialsSize > 0 ) && ( a3DModel.m_MeshesSize > 0 ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
m_3d_model = &a3DModel;
|
|
|
|
m_reload_is_needed = true;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::Set3DModel( const wxString& aModelPathName)
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-06-19 17:28:45 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::Set3DModel with a wxString" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( m_cacheManager )
|
|
|
|
{
|
2022-09-26 02:54:08 +00:00
|
|
|
const S3DMODEL* model = m_cacheManager->GetModel( aModelPathName, wxEmptyString );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( model )
|
|
|
|
Set3DModel( (const S3DMODEL &)*model );
|
|
|
|
else
|
|
|
|
Clear3DModel();
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::Clear3DModel()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
// Delete the old model
|
|
|
|
m_reload_is_needed = false;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
delete m_ogl_3dmodel;
|
2020-12-16 22:10:42 +00:00
|
|
|
m_ogl_3dmodel = nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
m_3d_model = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
Refresh();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::ogl_initialize()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2023-01-24 03:52:18 +00:00
|
|
|
const GLenum err = glewInit();
|
|
|
|
|
|
|
|
if( GLEW_OK != err )
|
|
|
|
{
|
|
|
|
const wxString msgError = (const char*) glewGetErrorString( err );
|
|
|
|
|
|
|
|
wxLogMessage( msgError );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::ogl_initialize Using GLEW version %s" ),
|
|
|
|
FROM_UTF8( (char*) glewGetString( GLEW_VERSION ) ) );
|
|
|
|
}
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
|
|
|
|
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
|
|
|
|
glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
|
|
|
|
|
|
|
|
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
|
|
|
glEnable( GL_DEPTH_TEST );
|
|
|
|
glEnable( GL_CULL_FACE );
|
|
|
|
glShadeModel( GL_SMOOTH );
|
|
|
|
glEnable( GL_LINE_SMOOTH );
|
|
|
|
glEnable( GL_NORMALIZE );
|
|
|
|
|
|
|
|
// Setup light
|
|
|
|
// https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
|
2016-02-04 01:16:19 +00:00
|
|
|
const GLfloat ambient[] = { 0.01f, 0.01f, 0.01f, 1.0f };
|
2015-12-08 07:31:57 +00:00
|
|
|
const GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
const GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// defines a directional light that points along the negative z-axis
|
|
|
|
const GLfloat position[] = { 0.0f, 0.0f, 2.0f * RANGE_SCALE_3D, 0.0f };
|
|
|
|
|
2016-02-04 01:16:19 +00:00
|
|
|
const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
|
|
|
|
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
|
|
|
|
glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
|
|
|
|
glLightfv( GL_LIGHT0, GL_POSITION, position );
|
2016-02-04 01:16:19 +00:00
|
|
|
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::ogl_set_arrow_material()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
glEnable( GL_COLOR_MATERIAL );
|
|
|
|
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
|
|
|
|
|
|
|
|
const SFVEC4F specular = SFVEC4F( 0.1f, 0.1f, 0.1f, 1.0f );
|
|
|
|
|
|
|
|
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
|
|
|
|
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnPaint( wxPaintEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
event.Skip( false );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
// SwapBuffer requires the window to be shown before calling
|
|
|
|
if( !IsShownOnScreen() )
|
|
|
|
{
|
2021-06-19 17:28:45 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnPaint !IsShown" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Makes the OpenGL state that is represented by the OpenGL rendering
|
|
|
|
// context context current, i.e. it will be used by all subsequent OpenGL calls.
|
|
|
|
// This function may only be called when the window is shown on screen"
|
2020-12-16 22:10:42 +00:00
|
|
|
if( m_glRC == nullptr )
|
2016-07-19 17:35:25 +00:00
|
|
|
m_glRC = GL_CONTEXT_MANAGER::Get().CreateCtx( this );
|
|
|
|
|
2023-02-15 02:18:28 +00:00
|
|
|
// CreateCtx could and does fail per sentry crash events, lets be graceful
|
|
|
|
if( m_glRC == nullptr )
|
|
|
|
{
|
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnPaint creating gl context failed" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-13 14:43:33 +00:00
|
|
|
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
// Set the OpenGL viewport according to the client size of this canvas.
|
|
|
|
// This is done here rather than in a wxSizeEvent handler because our
|
|
|
|
// OpenGL rendering context (and thus viewport setting) is used with
|
|
|
|
// multiple canvases: If we updated the viewport in the wxSizeEvent
|
|
|
|
// handler, changing the size of one canvas causes a viewport setting that
|
|
|
|
// is wrong when next another canvas is repainted.
|
2021-06-28 18:06:30 +00:00
|
|
|
wxSize clientSize = GetNativePixelSize();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( !m_ogl_initialized )
|
|
|
|
{
|
|
|
|
m_ogl_initialized = true;
|
|
|
|
ogl_initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_reload_is_needed )
|
|
|
|
{
|
2021-06-19 17:28:45 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
m_reload_is_needed = false;
|
2021-01-02 21:05:29 +00:00
|
|
|
m_ogl_3dmodel = new MODEL_3D( *m_3d_model, MATERIAL_MODE::NORMAL );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
// It convert a model as it was a board, so get the max size dimension of the board
|
|
|
|
// and compute the conversion scale
|
2021-01-05 22:19:00 +00:00
|
|
|
m_BiuTo3dUnits =
|
2020-12-16 22:10:42 +00:00
|
|
|
(double) RANGE_SCALE_3D
|
|
|
|
/ ( (double) m_ogl_3dmodel->GetBBox().GetMaxDimension() * UNITS3D_TO_UNITSPCB );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glViewport( 0, 0, clientSize.x, clientSize.y );
|
|
|
|
|
|
|
|
m_trackBallCamera.SetCurWindowSize( clientSize );
|
|
|
|
|
|
|
|
// clear color and depth buffers
|
|
|
|
glEnable( GL_DEPTH_TEST );
|
|
|
|
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
|
|
|
|
glClearDepth( 1.0f );
|
|
|
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// Set projection and modelview matrices
|
2015-12-08 07:31:57 +00:00
|
|
|
glMatrixMode( GL_PROJECTION );
|
|
|
|
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) );
|
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
glEnable( GL_LIGHTING );
|
|
|
|
glEnable( GL_LIGHT0 );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2015-12-09 05:43:30 +00:00
|
|
|
// Render Model
|
|
|
|
if( m_ogl_3dmodel )
|
|
|
|
{
|
2015-12-08 07:31:57 +00:00
|
|
|
glPushMatrix();
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
double modelunit_to_3d_units_factor = m_BiuTo3dUnits * UNITS3D_TO_UNITSPCB;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor,
|
2016-07-19 17:35:25 +00:00
|
|
|
modelunit_to_3d_units_factor );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-02-04 01:16:19 +00:00
|
|
|
// Center model in the render viewport
|
2015-12-16 09:01:44 +00:00
|
|
|
const SFVEC3F model_center = m_ogl_3dmodel->GetBBox().GetCenter();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2015-12-16 09:01:44 +00:00
|
|
|
glTranslatef( -model_center.x, -model_center.y, -model_center.z );
|
2015-12-10 00:31:44 +00:00
|
|
|
|
2020-09-02 16:22:12 +00:00
|
|
|
m_ogl_3dmodel->BeginDrawMulti( true );
|
2020-04-17 16:10:04 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_ogl_3dmodel->DrawOpaque( false );
|
2023-03-02 22:29:08 +00:00
|
|
|
|
|
|
|
glDepthMask( GL_FALSE );
|
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_ogl_3dmodel->DrawTransparent( 1.0f, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2023-03-02 22:29:08 +00:00
|
|
|
glDisable( GL_BLEND );
|
|
|
|
glDepthMask( GL_TRUE );
|
|
|
|
|
2020-04-17 16:10:04 +00:00
|
|
|
m_ogl_3dmodel->EndDrawMulti();
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// YxY squared view port
|
|
|
|
glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 );
|
2015-12-08 07:31:57 +00:00
|
|
|
glClear( GL_DEPTH_BUFFER_BIT );
|
|
|
|
|
|
|
|
glMatrixMode( GL_PROJECTION );
|
|
|
|
glLoadIdentity();
|
|
|
|
gluPerspective( 45.0f, 1.0f, 0.01f, RANGE_SCALE_3D * 2.0f );
|
|
|
|
|
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f),
|
|
|
|
SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
|
|
|
|
|
2016-02-04 01:16:19 +00:00
|
|
|
const glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
glLoadMatrixf( glm::value_ptr( ViewMatrix ) );
|
|
|
|
|
|
|
|
ogl_set_arrow_material();
|
|
|
|
|
|
|
|
glColor3f( 0.9f, 0.0f, 0.0f );
|
2021-01-02 21:05:29 +00:00
|
|
|
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
|
2015-12-08 07:31:57 +00:00
|
|
|
0.275f );
|
|
|
|
|
|
|
|
glColor3f( 0.0f, 0.9f, 0.0f );
|
2021-01-02 21:05:29 +00:00
|
|
|
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
|
2015-12-08 07:31:57 +00:00
|
|
|
0.275f );
|
|
|
|
|
|
|
|
glColor3f( 0.0f, 0.0f, 0.9f );
|
2021-01-02 21:05:29 +00:00
|
|
|
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
|
2015-12-08 07:31:57 +00:00
|
|
|
0.275f );
|
|
|
|
|
|
|
|
// "Swaps the double-buffer of this window, making the back-buffer the
|
|
|
|
// front-buffer and vice versa, so that the output of the previous OpenGL
|
|
|
|
// commands is displayed on the window."
|
|
|
|
SwapBuffers();
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnEraseBackground( wxEraseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-06-19 17:28:45 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnEraseBackground" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
// Do nothing, to avoid flashing.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnMouseWheel( wxMouseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-06-19 17:28:45 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_MODEL_VIEWER::OnMouseWheel" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( event.ShiftDown() )
|
|
|
|
{
|
|
|
|
//if( event.GetWheelRotation() < 0 )
|
2022-09-28 23:18:50 +00:00
|
|
|
//SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_UP ); // move up
|
2015-12-08 07:31:57 +00:00
|
|
|
//else
|
2022-09-28 23:18:50 +00:00
|
|
|
//SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_DOWN ); // move down
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
else if( event.ControlDown() )
|
|
|
|
{
|
|
|
|
//if( event.GetWheelRotation() > 0 )
|
2022-09-28 23:18:50 +00:00
|
|
|
//SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_RIGHT ); // move right
|
2015-12-08 07:31:57 +00:00
|
|
|
//else
|
2022-09-28 23:18:50 +00:00
|
|
|
//SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_LEFT ); // move left
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-14 14:17:56 +00:00
|
|
|
m_trackBallCamera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
//DisplayStatus();
|
|
|
|
Refresh( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_trackBallCamera.SetCurMousePosition( event.GetPosition() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_OSX_MAGNIFY_EVENT
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnMagnify( wxMouseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnMouseMove( wxMouseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-10-10 16:49:58 +00:00
|
|
|
const wxSize& nativeWinSize = GetNativePixelSize();
|
|
|
|
const wxPoint& nativePosition = GetNativePosition( event.GetPosition() );
|
|
|
|
|
|
|
|
m_trackBallCamera.SetCurWindowSize( nativeWinSize );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( event.Dragging() )
|
|
|
|
{
|
|
|
|
if( event.LeftIsDown() ) // Drag
|
2021-10-10 16:49:58 +00:00
|
|
|
m_trackBallCamera.Drag( nativePosition );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
// orientation has changed, redraw mesh
|
|
|
|
Refresh( false );
|
|
|
|
}
|
|
|
|
|
2021-10-10 16:49:58 +00:00
|
|
|
m_trackBallCamera.SetCurMousePosition( nativePosition );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnLeftDown( wxMouseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-03-02 01:29:20 +00:00
|
|
|
event.Skip();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnLeftUp( wxMouseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-03-02 01:29:20 +00:00
|
|
|
event.Skip();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnMiddleDown( wxMouseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-03-02 01:29:20 +00:00
|
|
|
event.Skip();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnMiddleUp( wxMouseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-03-02 01:29:20 +00:00
|
|
|
event.Skip();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_MODEL_VIEWER::OnRightClick( wxMouseEvent& event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-03-02 01:29:20 +00:00
|
|
|
event.Skip();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|