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.

214 lines
6.7 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-2016 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. /**
  26. * @file panel_prev_model.h
  27. * @brief Defines a panel which is to be added to a wxFileDialog via
  28. * SetExtraControl();
  29. * The panel shows a preview of the module being edited and provides controls
  30. * to set the offset/rotation/scale of each model 3d shape as per KiCad's
  31. * current behavior. The panel may also be used in the 3D configuration dialog
  32. * to tune the positioning of the models without invoking a file selector dialog.
  33. */
  34. #ifndef PANEL_PREV_MODEL_H
  35. #define PANEL_PREV_MODEL_H
  36. #include "panel_prev_3d_base.h"
  37. #include <vector>
  38. #include <tool/tools_holder.h>
  39. #include <3d_canvas/eda_3d_canvas.h>
  40. #include <3d_viewer_id.h>
  41. #include <3d_rendering/ctrack_ball.h>
  42. // Define min and max parameter values
  43. #define MAX_SCALE 10000.0
  44. #define MAX_ROTATION 180.0
  45. #define MAX_OFFSET 1000.0
  46. #define SCALE_INCREMENT_FINE 0.02
  47. #define SCALE_INCREMENT 0.1
  48. #define ROTATION_INCREMENT 90 // in degrees, for spin button command
  49. #define ROTATION_INCREMENT_WHEEL 90 // in degrees, for mouse wheel command
  50. #define ROTATION_INCREMENT_WHEEL_FINE 1 // in degrees, for mouse wheel command
  51. #define OFFSET_INCREMENT_MM 0.5
  52. #define OFFSET_INCREMENT_MM_FINE 0.1
  53. #define OFFSET_INCREMENT_MIL 25.0
  54. #define OFFSET_INCREMENT_MIL_FINE 5.0
  55. // Declared classes to create pointers
  56. class S3D_CACHE;
  57. class FILENAME_RESOLVER;
  58. class BOARD;
  59. class BOARD_ADAPTER;
  60. class MODULE;
  61. class PANEL_PREV_3D: public EDA_3D_BOARD_HOLDER, public TOOLS_HOLDER, public PANEL_PREV_3D_BASE
  62. {
  63. public:
  64. PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule,
  65. std::vector<MODULE_3D_SETTINGS>* aParentModelList );
  66. ~PANEL_PREV_3D();
  67. private:
  68. EDA_3D_CANVAS* m_previewPane;
  69. BOARD_ADAPTER m_boardAdapter;
  70. CCAMERA& m_currentCamera;
  71. CTRACK_BALL m_trackBallCamera;
  72. BOARD* m_dummyBoard;
  73. MODULE* m_dummyModule;
  74. std::vector<MODULE_3D_SETTINGS>* m_parentModelList;
  75. int m_selected; /// Index into m_parentInfoList
  76. EDA_UNITS m_userUnits;
  77. // Methods of the class
  78. private:
  79. /**
  80. * Load 3D relevant settings from the user configuration
  81. */
  82. void loadCommonSettings();
  83. /**
  84. * @brief updateOrientation - it will receive the events from editing the fields
  85. * @param event
  86. */
  87. void updateOrientation( wxCommandEvent &event ) override;
  88. void onMouseWheelScale( wxMouseEvent& event ) override;
  89. void onMouseWheelRot( wxMouseEvent& event ) override;
  90. void onMouseWheelOffset( wxMouseEvent& event ) override;
  91. void onIncrementRot( wxSpinEvent& event ) override
  92. {
  93. doIncrementRotation( event, 1.0 );
  94. }
  95. void onDecrementRot( wxSpinEvent& event ) override
  96. {
  97. doIncrementRotation( event, -1.0 );
  98. }
  99. void onIncrementScale( wxSpinEvent& event ) override
  100. {
  101. doIncrementScale( event, 1.0 );
  102. }
  103. void onDecrementScale( wxSpinEvent& event ) override
  104. {
  105. doIncrementScale( event, -1.0 );
  106. }
  107. void onIncrementOffset( wxSpinEvent& event ) override
  108. {
  109. doIncrementOffset( event, 1.0 );
  110. }
  111. void onDecrementOffset( wxSpinEvent& event ) override
  112. {
  113. doIncrementOffset( event, -1.0 );
  114. }
  115. void onOpacitySlider( 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. wxString formatScaleValue( double aValue );
  120. wxString formatRotationValue( double aValue );
  121. wxString formatOffsetValue( double aValue );
  122. void View3DISO( wxCommandEvent& event ) override
  123. {
  124. m_currentCamera.ToggleProjection();
  125. m_previewPane->Refresh();
  126. }
  127. void View3DLeft( wxCommandEvent& event ) override
  128. {
  129. m_previewPane->SetView3D( ID_VIEW3D_LEFT );
  130. }
  131. void View3DFront( wxCommandEvent& event ) override
  132. {
  133. m_previewPane->SetView3D( ID_VIEW3D_FRONT );
  134. }
  135. void View3DTop( wxCommandEvent& event ) override
  136. {
  137. m_previewPane->SetView3D( ID_VIEW3D_TOP );
  138. }
  139. void View3DUpdate( wxCommandEvent& event ) override
  140. {
  141. m_previewPane->ReloadRequest();
  142. m_previewPane->Refresh();
  143. }
  144. void View3DRight( wxCommandEvent& event ) override
  145. {
  146. m_previewPane->SetView3D( ID_VIEW3D_RIGHT );
  147. }
  148. void View3DBack( wxCommandEvent& event ) override
  149. {
  150. m_previewPane->SetView3D( ID_VIEW3D_BACK );
  151. }
  152. void View3DBottom( wxCommandEvent& event ) override
  153. {
  154. m_previewPane->SetView3D( ID_VIEW3D_BOTTOM );
  155. }
  156. public:
  157. /**
  158. * The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu
  159. * events aren't captured by the menus themselves.
  160. */
  161. void OnMenuEvent( wxMenuEvent& aEvent );
  162. wxWindow* GetToolCanvas() const override { return m_previewPane; }
  163. BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; }
  164. CCAMERA& GetCurrentCamera() override { return m_currentCamera; }
  165. /**
  166. * @brief SetModelDataIdx - Sets the currently selected index in the model list so that
  167. * the scale/rotation/offset controls can be updated.
  168. */
  169. void SetSelectedModel( int idx );
  170. /**
  171. * @brief UpdateModelInfoList - copy shapes from the current shape list which are flagged
  172. * for preview to the copy of module that is on the preview dummy board
  173. */
  174. void UpdateDummyModule( bool aRelaodRequired = true );
  175. };
  176. #endif // PANEL_PREV_MODEL_H