You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
  5. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file c3d_model_viewer.h
  26. * @brief Implements a model viewer canvas.
  27. *
  28. * The purpose of model viewer is to render 3d models that come in the original data from
  29. * the files without any transformations.
  30. */
  31. #ifndef _C3D_MODEL_VIEWER_H_
  32. #define _C3D_MODEL_VIEWER_H_
  33. #include "3d_rendering/ctrack_ball.h"
  34. #include <gal/hidpi_gl_canvas.h>
  35. class S3D_CACHE;
  36. class C_OGL_3DMODEL;
  37. /**
  38. * Implement a canvas based on a wxGLCanvas.
  39. */
  40. class C3D_MODEL_VIEWER : public HIDPI_GL_CANVAS
  41. {
  42. public:
  43. /**
  44. * Create a new 3D Canvas with a attribute list.
  45. *
  46. * @param aParent the parent creator of this canvas.
  47. * @param aAttribList a list of openGL options created by #COGL_ATT_LIST::GetAttributesList.
  48. */
  49. C3D_MODEL_VIEWER( wxWindow* aParent, const int* aAttribList = 0,
  50. S3D_CACHE* aCacheManager = nullptr );
  51. ~C3D_MODEL_VIEWER();
  52. /**
  53. * Set this model to be displayed.
  54. *
  55. * @param a3DModel 3D model data.
  56. */
  57. void Set3DModel( const S3DMODEL& a3DModel );
  58. /**
  59. * Set this model to be displayed.
  60. *
  61. * @param aModelPathName 3D model path name.
  62. */
  63. void Set3DModel( wxString const& aModelPathName );
  64. /**
  65. * Unload the displayed 3D model.
  66. */
  67. void Clear3DModel();
  68. private:
  69. void ogl_initialize();
  70. void ogl_set_arrow_material();
  71. void OnPaint( wxPaintEvent& event );
  72. void OnEraseBackground( wxEraseEvent& event );
  73. void OnMouseWheel( wxMouseEvent& event );
  74. #ifdef USE_OSX_MAGNIFY_EVENT
  75. void OnMagnify( wxMouseEvent& event );
  76. #endif
  77. void OnMouseMove( wxMouseEvent& event );
  78. void OnLeftDown( wxMouseEvent& event );
  79. void OnLeftUp( wxMouseEvent& event );
  80. void OnMiddleUp( wxMouseEvent& event );
  81. void OnMiddleDown( wxMouseEvent& event );
  82. void OnRightClick( wxMouseEvent& event );
  83. DECLARE_EVENT_TABLE()
  84. /// openGL context
  85. wxGLContext* m_glRC;
  86. /// Camera used in this canvas
  87. CTRACK_BALL m_trackBallCamera;
  88. /// Original 3d model data
  89. const S3DMODEL* m_3d_model;
  90. /// Class holder for 3d model to display on openGL
  91. C_OGL_3DMODEL* m_ogl_3dmodel;
  92. /// Flag that we have a new model and it need to be reloaded when the paint is called
  93. bool m_reload_is_needed;
  94. /// Flag if open gl was initialized
  95. bool m_ogl_initialized;
  96. /// factor to convert the model or any other items to keep it in relation to
  97. /// the +/-RANGE_SCALE_3D
  98. /// (it is named same as the board render for better understanding proposes)
  99. double m_BiuTo3Dunits;
  100. /// Optional cache manager
  101. S3D_CACHE* m_cacheManager;
  102. /**
  103. * Trace mask used to enable or disable the trace output of this class.
  104. * The debug output can be turned on by setting the WXTRACE environment variable to
  105. * "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for
  106. * more information.
  107. */
  108. static const wxChar* m_logTrace;
  109. };
  110. #endif // _C3D_MODEL_VIEWER_H_