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.

195 lines
5.9 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 <3d_canvas/eda_3d_canvas.h>
  39. // Define min and max parameter values
  40. #define MAX_SCALE 10000.0
  41. #define MAX_ROTATION 180.0
  42. #define MAX_OFFSET 1000.0
  43. #define SCALE_INCREMENT_FINE 0.02
  44. #define SCALE_INCREMENT 0.1
  45. #define ROTATION_INCREMENT 5 // in degrees, for spin button command
  46. #define ROTATION_INCREMENT_WHEEL 15 // in degrees, for mouse wheel command
  47. #define ROTATION_INCREMENT_WHEEL_FINE 1 // in degrees, for mouse wheel command
  48. #define OFFSET_INCREMENT_MM 0.5
  49. #define OFFSET_INCREMENT_MM_FINE 0.1
  50. #define OFFSET_INCREMENT_MIL 25.0
  51. #define OFFSET_INCREMENT_MIL_FINE 5.0
  52. // Declared classes to create pointers
  53. class S3D_CACHE;
  54. class FILENAME_RESOLVER;
  55. class BOARD;
  56. class CINFO3D_VISU;
  57. class MODULE;
  58. class COLORS_DESIGN_SETTINGS;
  59. class PANEL_PREV_3D: public PANEL_PREV_3D_BASE
  60. {
  61. public:
  62. PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule,
  63. std::vector<MODULE_3D_SETTINGS> *aParentModelList );
  64. ~PANEL_PREV_3D();
  65. private:
  66. EDA_3D_CANVAS* m_previewPane;
  67. CINFO3D_VISU* m_settings3Dviewer;
  68. BOARD* m_dummyBoard;
  69. MODULE* m_dummyModule;
  70. std::vector<MODULE_3D_SETTINGS>* m_parentModelList;
  71. int m_selected; /// Index into m_parentInfoList
  72. EDA_UNITS_T m_userUnits;
  73. // Methods of the class
  74. private:
  75. void initPanel();
  76. /**
  77. * @brief updateOrientation - it will receive the events from editing the fields
  78. * @param event
  79. */
  80. void updateOrientation( wxCommandEvent &event ) override;
  81. void onMouseWheelScale( wxMouseEvent& event ) override;
  82. void onMouseWheelRot( wxMouseEvent& event ) override;
  83. void onMouseWheelOffset( wxMouseEvent& event ) override;
  84. void onIncrementRot( wxSpinEvent& event ) override
  85. {
  86. doIncrementRotation( event, 1.0 );
  87. }
  88. void onDecrementRot( wxSpinEvent& event ) override
  89. {
  90. doIncrementRotation( event, -1.0 );
  91. }
  92. void onIncrementScale( wxSpinEvent& event ) override
  93. {
  94. doIncrementScale( event, 1.0 );
  95. }
  96. void onDecrementScale( wxSpinEvent& event ) override
  97. {
  98. doIncrementScale( event, -1.0 );
  99. }
  100. void onIncrementOffset( wxSpinEvent& event ) override
  101. {
  102. doIncrementOffset( event, 1.0 );
  103. }
  104. void onDecrementOffset( wxSpinEvent& event ) override
  105. {
  106. doIncrementOffset( event, -1.0 );
  107. }
  108. void doIncrementScale( wxSpinEvent& aEvent, double aSign );
  109. void doIncrementRotation( wxSpinEvent& aEvent, double aSign );
  110. void doIncrementOffset( wxSpinEvent& aEvent, double aSign );
  111. wxString formatScaleValue( double aValue );
  112. wxString formatRotationValue( double aValue );
  113. wxString formatOffsetValue( double aValue );
  114. void View3DISO( wxCommandEvent& event ) override
  115. {
  116. m_settings3Dviewer->CameraGet().ToggleProjection();
  117. m_previewPane->Refresh();
  118. }
  119. void View3DLeft( wxCommandEvent& event ) override
  120. {
  121. m_previewPane->SetView3D( GR_KB_SHIFT + 'X' );
  122. }
  123. void View3DFront( wxCommandEvent& event ) override
  124. {
  125. m_previewPane->SetView3D( 'Y' );
  126. }
  127. void View3DTop( wxCommandEvent& event ) override
  128. {
  129. m_previewPane->SetView3D( 'Z' );
  130. }
  131. void View3DUpdate( wxCommandEvent& event ) override
  132. {
  133. m_previewPane->ReloadRequest();
  134. m_previewPane->Refresh();
  135. }
  136. void View3DRight( wxCommandEvent& event ) override
  137. {
  138. m_previewPane->SetView3D( 'X' );
  139. }
  140. void View3DBack( wxCommandEvent& event ) override
  141. {
  142. m_previewPane->SetView3D( GR_KB_SHIFT + 'Y' );
  143. }
  144. void View3DBottom( wxCommandEvent& event ) override
  145. {
  146. m_previewPane->SetView3D( GR_KB_SHIFT + 'Z' );
  147. }
  148. public:
  149. /**
  150. * @brief SetModelDataIdx - Sets the currently selected index in the model list so that
  151. * the scale/rotation/offset controls can be updated.
  152. */
  153. void SetSelectedModel( int idx );
  154. /**
  155. * @brief UpdateModelInfoList - copy shapes from the current shape list which are flagged
  156. * for preview to the copy of module that is on the preview dummy board
  157. */
  158. void UpdateDummyModule( bool aRelaodRequired = true );
  159. };
  160. #endif // PANEL_PREV_MODEL_H