kicad/3d-viewer/3d_model_viewer/eda_3d_model_viewer.h

142 lines
4.0 KiB
C
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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 eda_3d_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.
*/
#ifndef _C3D_MODEL_VIEWER_H_
#define _C3D_MODEL_VIEWER_H_
#include "3d_rendering/track_ball.h"
#include <gal/hidpi_gl_canvas.h>
class S3D_CACHE;
class MODEL_3D;
/**
2020-12-16 22:10:42 +00:00
* Implement a canvas based on a wxGLCanvas.
*/
2021-06-19 17:28:45 +00:00
class EDA_3D_MODEL_VIEWER : public HIDPI_GL_CANVAS
{
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.
* @param aAttribList a list of openGL options created by #OGL_ATT_LIST::GetAttributesList.
*/
2021-06-19 17:28:45 +00:00
EDA_3D_MODEL_VIEWER( wxWindow* aParent, const int* aAttribList = nullptr,
S3D_CACHE* aCacheManager = nullptr );
2021-06-19 17:28:45 +00:00
~EDA_3D_MODEL_VIEWER();
/**
2020-12-16 22:10:42 +00:00
* Set this model to be displayed.
*
* @param a3DModel 3D model data.
*/
2020-12-16 22:10:42 +00:00
void Set3DModel( const S3DMODEL& a3DModel );
/**
2020-12-16 22:10:42 +00:00
* Set this model to be displayed.
*
* @param aModelPathName 3D model path name.
*/
void Set3DModel( const wxString& aModelPathName );
/**
2020-12-16 22:10:42 +00:00
* Unload the displayed 3D model.
*/
void Clear3DModel();
private:
void ogl_initialize();
void ogl_set_arrow_material();
2020-12-16 22:10:42 +00:00
void OnPaint( wxPaintEvent& event );
2020-12-16 22:10:42 +00:00
void OnEraseBackground( wxEraseEvent& event );
2020-12-16 22:10:42 +00:00
void OnMouseWheel( wxMouseEvent& event );
#ifdef USE_OSX_MAGNIFY_EVENT
void OnMagnify( wxMouseEvent& event );
#endif
2020-12-16 22:10:42 +00:00
void OnMouseMove( wxMouseEvent& event );
2020-12-16 22:10:42 +00:00
void OnLeftDown( wxMouseEvent& event );
2020-12-16 22:10:42 +00:00
void OnLeftUp( wxMouseEvent& event );
2020-12-16 22:10:42 +00:00
void OnMiddleUp( wxMouseEvent& event );
2020-12-16 22:10:42 +00:00
void OnMiddleDown( wxMouseEvent& event );
2020-12-16 22:10:42 +00:00
void OnRightClick( wxMouseEvent& event );
2017-11-02 20:41:29 +00:00
DECLARE_EVENT_TABLE()
/// openGL context
2020-12-16 22:10:42 +00:00
wxGLContext* m_glRC;
/// Camera used in this canvas
TRACK_BALL m_trackBallCamera;
/// Original 3d model data
2020-12-16 22:10:42 +00:00
const S3DMODEL* m_3d_model;
/// Class holder for 3d model to display on openGL
MODEL_3D* m_ogl_3dmodel;
/// 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;
/// 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)
double m_BiuTo3dUnits;
/// Optional cache manager
S3D_CACHE* m_cacheManager;
/**
* 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;
};
#endif // _C3D_MODEL_VIEWER_H_