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.

209 lines
6.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
  5. * Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
  6. * Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef PANEL_PREVIEW_3D_MODEL_H
  26. #define PANEL_PREVIEW_3D_MODEL_H
  27. #include "panel_preview_3d_model_base.h"
  28. #include <vector>
  29. #include <widgets/unit_binder.h>
  30. #include <tool/tools_holder.h>
  31. #include <3d_canvas/eda_3d_canvas.h>
  32. #include <3d_viewer_id.h>
  33. #include <3d_rendering/track_ball.h>
  34. // Define min and max parameter values
  35. #define MAX_SCALE 10000.0
  36. #define MAX_ROTATION 180.0
  37. #define MAX_OFFSET 1000.0
  38. #define SCALE_INCREMENT_FINE 0.02
  39. #define SCALE_INCREMENT 0.1
  40. #define ROTATION_INCREMENT 90 // in degrees, for spin button command
  41. #define ROTATION_INCREMENT_WHEEL 90 // in degrees, for mouse wheel command
  42. #define ROTATION_INCREMENT_WHEEL_FINE 1 // in degrees, for mouse wheel command
  43. #define OFFSET_INCREMENT_MM 0.5
  44. #define OFFSET_INCREMENT_MM_FINE 0.1
  45. #define OFFSET_INCREMENT_MIL 25.0
  46. #define OFFSET_INCREMENT_MIL_FINE 5.0
  47. // Declared classes to create pointers
  48. class WX_INFOBAR;
  49. class S3D_CACHE;
  50. class FILENAME_RESOLVER;
  51. class BOARD;
  52. class BOARD_ADAPTER;
  53. class FOOTPRINT;
  54. class PANEL_PREVIEW_3D_MODEL: public EDA_3D_BOARD_HOLDER, public TOOLS_HOLDER, public PANEL_PREVIEW_3D_MODEL_BASE
  55. {
  56. public:
  57. PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame, FOOTPRINT* aFootprint,
  58. std::vector<FP_3DMODEL>* aParentModelList );
  59. ~PANEL_PREVIEW_3D_MODEL();
  60. /**
  61. * The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu
  62. * events aren't captured by the menus themselves.
  63. */
  64. void OnMenuEvent( wxMenuEvent& aEvent );
  65. wxWindow* GetToolCanvas() const override { return m_previewPane; }
  66. BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; }
  67. CAMERA& GetCurrentCamera() override { return m_currentCamera; }
  68. /**
  69. * Set the currently selected index in the model list so that the scale/rotation/offset
  70. * controls can be updated.
  71. */
  72. void SetSelectedModel( int idx );
  73. /**
  74. * Copy shapes from the current shape list which are flagged for preview to the copy of
  75. * footprint that is on the preview dummy board.
  76. */
  77. void UpdateDummyFootprint( bool aRelaodRequired = true );
  78. private:
  79. /**
  80. * Load 3D relevant settings from the user configuration
  81. */
  82. void loadSettings();
  83. /**
  84. * It will receive the events from editing the fields.
  85. */
  86. void updateOrientation( wxCommandEvent& event ) override;
  87. void onMouseWheelScale( wxMouseEvent& event ) override;
  88. void onMouseWheelRot( wxMouseEvent& event ) override;
  89. void onMouseWheelOffset( wxMouseEvent& event ) override;
  90. void onIncrementRot( wxSpinEvent& event ) override
  91. {
  92. doIncrementRotation( event, 1.0 );
  93. }
  94. void onDecrementRot( wxSpinEvent& event ) override
  95. {
  96. doIncrementRotation( event, -1.0 );
  97. }
  98. void onIncrementScale( wxSpinEvent& event ) override
  99. {
  100. doIncrementScale( event, 1.0 );
  101. }
  102. void onDecrementScale( wxSpinEvent& event ) override
  103. {
  104. doIncrementScale( event, -1.0 );
  105. }
  106. void onIncrementOffset( wxSpinEvent& event ) override
  107. {
  108. doIncrementOffset( event, 1.0 );
  109. }
  110. void onDecrementOffset( wxSpinEvent& event ) override
  111. {
  112. doIncrementOffset( event, -1.0 );
  113. }
  114. void onOpacitySlider( wxCommandEvent& event ) override;
  115. void updateBoardThickness( wxCommandEvent& event ) override;
  116. void doIncrementScale( wxSpinEvent& aEvent, double aSign );
  117. void doIncrementRotation( wxSpinEvent& aEvent, double aSign );
  118. void doIncrementOffset( wxSpinEvent& aEvent, double aSign );
  119. void onUnitsChanged( wxCommandEvent& aEvent );
  120. wxString formatScaleValue( double aValue );
  121. wxString formatRotationValue( double aValue );
  122. wxString formatOffsetValue( double aValue );
  123. void View3DISO( wxCommandEvent& event ) override
  124. {
  125. m_currentCamera.ToggleProjection();
  126. m_previewPane->Refresh();
  127. }
  128. void View3DLeft( wxCommandEvent& event ) override
  129. {
  130. m_previewPane->SetView3D( ID_VIEW3D_LEFT );
  131. }
  132. void View3DFront( wxCommandEvent& event ) override
  133. {
  134. m_previewPane->SetView3D( ID_VIEW3D_FRONT );
  135. }
  136. void View3DTop( wxCommandEvent& event ) override
  137. {
  138. m_previewPane->SetView3D( ID_VIEW3D_TOP );
  139. }
  140. void View3DUpdate( wxCommandEvent& event ) override
  141. {
  142. m_previewPane->ReloadRequest();
  143. m_previewPane->Refresh();
  144. }
  145. void View3DRight( wxCommandEvent& event ) override
  146. {
  147. m_previewPane->SetView3D( ID_VIEW3D_RIGHT );
  148. }
  149. void View3DBack( wxCommandEvent& event ) override
  150. {
  151. m_previewPane->SetView3D( ID_VIEW3D_BACK );
  152. }
  153. void View3DBottom( wxCommandEvent& event ) override
  154. {
  155. m_previewPane->SetView3D( ID_VIEW3D_BOTTOM );
  156. }
  157. private:
  158. EDA_3D_CANVAS* m_previewPane;
  159. WX_INFOBAR* m_infobar;
  160. BOARD_ADAPTER m_boardAdapter;
  161. CAMERA& m_currentCamera;
  162. TRACK_BALL m_trackBallCamera;
  163. BOARD* m_dummyBoard;
  164. FOOTPRINT* m_dummyFootprint;
  165. std::vector<FP_3DMODEL>* m_parentModelList;
  166. int m_selected; /// Index into m_parentInfoList
  167. UNIT_BINDER m_boardThickness;
  168. EDA_UNITS m_userUnits;
  169. };
  170. #endif // PANEL_PREVIEW_3D_MODEL_H