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-07-27 12:22:27 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file c3d_model_viewer.h
|
2020-12-16 22:10:42 +00:00
|
|
|
* @brief Implements a model viewer canvas.
|
|
|
|
*
|
|
|
|
* The purpose of 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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _C3D_MODEL_VIEWER_H_
|
|
|
|
#define _C3D_MODEL_VIEWER_H_
|
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "3d_rendering/track_ball.h"
|
2017-12-07 15:57:47 +00:00
|
|
|
#include <gal/hidpi_gl_canvas.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
class S3D_CACHE;
|
2021-01-02 21:05:29 +00:00
|
|
|
class MODEL_3D;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Implement a canvas based on a wxGLCanvas.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-06-19 17:28:45 +00:00
|
|
|
class EDA_3D_MODEL_VIEWER : public HIDPI_GL_CANVAS
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Create a new 3D Canvas with a attribute list.
|
|
|
|
*
|
|
|
|
* @param aParent the parent creator of this canvas.
|
2021-01-02 21:05:29 +00:00
|
|
|
* @param aAttribList a list of openGL options created by #OGL_ATT_LIST::GetAttributesList.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-06-19 17:28:45 +00:00
|
|
|
EDA_3D_MODEL_VIEWER( wxWindow* aParent, const int* aAttribList = nullptr,
|
|
|
|
S3D_CACHE* aCacheManager = nullptr );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
~EDA_3D_MODEL_VIEWER();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Set this model to be displayed.
|
|
|
|
*
|
|
|
|
* @param a3DModel 3D model data.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2020-12-16 22:10:42 +00:00
|
|
|
void Set3DModel( const S3DMODEL& a3DModel );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Set this model to be displayed.
|
|
|
|
*
|
|
|
|
* @param aModelPathName 3D model path name.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
2021-07-27 12:22:27 +00:00
|
|
|
void Set3DModel( const wxString& aModelPathName );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Unload the displayed 3D model.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
void Clear3DModel();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ogl_initialize();
|
|
|
|
void ogl_set_arrow_material();
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnPaint( wxPaintEvent& event );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnEraseBackground( wxEraseEvent& event );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnMouseWheel( wxMouseEvent& event );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
#ifdef USE_OSX_MAGNIFY_EVENT
|
|
|
|
void OnMagnify( wxMouseEvent& event );
|
|
|
|
#endif
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnMouseMove( wxMouseEvent& event );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnLeftDown( wxMouseEvent& event );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnLeftUp( wxMouseEvent& event );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnMiddleUp( wxMouseEvent& event );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnMiddleDown( wxMouseEvent& event );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
void OnRightClick( wxMouseEvent& event );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2017-11-02 20:41:29 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/// openGL context
|
2020-12-16 22:10:42 +00:00
|
|
|
wxGLContext* m_glRC;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/// Camera used in this canvas
|
2021-01-02 21:05:29 +00:00
|
|
|
TRACK_BALL m_trackBallCamera;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/// Original 3d model data
|
2020-12-16 22:10:42 +00:00
|
|
|
const S3DMODEL* m_3d_model;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/// Class holder for 3d model to display on openGL
|
2021-01-02 21:05:29 +00:00
|
|
|
MODEL_3D* m_ogl_3dmodel;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/// Flag that we have a new model and it need to be reloaded when the paint is called
|
|
|
|
bool m_reload_is_needed;
|
|
|
|
|
|
|
|
/// Flag if open gl was initialized
|
|
|
|
bool m_ogl_initialized;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/// factor to convert the model or any other items to keep it in relation to
|
|
|
|
/// the +/-RANGE_SCALE_3D
|
2015-12-08 07:31:57 +00:00
|
|
|
/// (it is named same as the board render for better understanding proposes)
|
2021-01-05 22:19:00 +00:00
|
|
|
double m_BiuTo3dUnits;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/// Optional cache manager
|
|
|
|
S3D_CACHE* m_cacheManager;
|
|
|
|
|
2015-12-08 07:31:57 +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.
|
|
|
|
*/
|
2020-12-16 22:10:42 +00:00
|
|
|
static const wxChar* m_logTrace;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _C3D_MODEL_VIEWER_H_
|