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.

241 lines
7.5 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) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  6. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. /**
  27. * @file eda_3d_viewer.h
  28. * @brief Declaration of the eda_3d_viewer class
  29. */
  30. #ifndef EDA_3D_VIEWER_H
  31. #define EDA_3D_VIEWER_H
  32. #include "../3d_canvas/cinfo3d_visu.h"
  33. #include "../3d_canvas/eda_3d_canvas.h"
  34. #include <kiway_player.h>
  35. #include <wx/colourdata.h>
  36. #include <../common/dialogs/dialog_color_picker.h> // for CUSTOM_COLORS_LIST definition
  37. /// A variable name whose value holds the path of 3D shape files.
  38. /// Currently an environment variable, eventually a project variable.
  39. #define KISYS3DMOD wxT( "KISYS3DMOD" )
  40. #define KICAD_DEFAULT_3D_DRAWFRAME_STYLE (wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS)
  41. #define VIEWER3D_FRAMENAME wxT( "Viewer3DFrameName" )
  42. #define QUALIFIED_VIEWER3D_FRAMENAME( parent ) \
  43. ( wxString( VIEWER3D_FRAMENAME ) + wxT( ":" ) + parent->GetName() )
  44. enum EDA_3D_VIEWER_STATUSBAR
  45. {
  46. STATUS_TEXT = 0,
  47. WARN_TEXT,
  48. X_POS,
  49. Y_POS
  50. };
  51. /**
  52. * Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard
  53. */
  54. class EDA_3D_VIEWER : public KIWAY_PLAYER
  55. {
  56. public:
  57. EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent,
  58. const wxString &aTitle,
  59. long style = KICAD_DEFAULT_3D_DRAWFRAME_STYLE );
  60. ~EDA_3D_VIEWER();
  61. PCB_BASE_FRAME* Parent() const { return (PCB_BASE_FRAME*)GetParent(); }
  62. BOARD* GetBoard() { return Parent()->GetBoard(); }
  63. /**
  64. * Request reloading the 3D view. However the request will be executed
  65. * only when the 3D canvas is refreshed.
  66. * It allows one to prepare changes and request for 3D rebuild only when all
  67. * changes are committed.
  68. * This is made because the 3D rebuild can take a long time, and this rebuild
  69. * cannot always made after each change, for calculation time reason.
  70. */
  71. void ReloadRequest();
  72. // !TODO: review this function: it need a way to tell what changed,
  73. // to only reload/rebuild things that have really changed
  74. /**
  75. * Reload and refresh (rebuild) the 3D scene.
  76. * Warning: rebuilding the 3D scene can take a bit of time, so
  77. * rebuilding the scene can be immediate, or made later, during
  78. * the next 3D canvas refresh (on zoom for instance)
  79. * @param aForceImmediateRedraw = true to immediately rebuild the 3D scene,
  80. * false to wait a refresh later.
  81. */
  82. void NewDisplay( bool aForceImmediateRedraw = false );
  83. /**
  84. * @return current settings
  85. */
  86. CINFO3D_VISU &GetSettings() { return m_settings; }
  87. /**
  88. * Get a SFVEC3D from a wx colour dialog
  89. * @param aColor is the SFVEC3D to change
  90. * @param aTitle is the title displayed in the colordialog selector
  91. * @param aPredefinedColors is a reference to a CUSTOM_COLOR_ITEM list
  92. * which contains a few predefined colors
  93. * if empty, no predefined colors are used.
  94. * no change if aborted by user
  95. */
  96. bool Set3DColorFromUser( SFVEC3D &aColor, const wxString& aTitle,
  97. CUSTOM_COLORS_LIST* aPredefinedColors );
  98. /**
  99. * Set the solder mask color from a set of colors
  100. * @return true if a new color is chosen, false if
  101. * no change or aborted by user
  102. */
  103. bool Set3DSolderMaskColorFromUser();
  104. /**
  105. * Set the solder mask color from a set of colors
  106. * @return true if a new color is chosen, false if
  107. * no change or aborted by user
  108. */
  109. bool Set3DSolderPasteColorFromUser();
  110. /**
  111. * Set the copper color from a set of colors
  112. * @return true if a new color is chosen, false if
  113. * no change or aborted by user
  114. */
  115. bool Set3DCopperColorFromUser();
  116. /**
  117. * Set the copper color from a set of colors
  118. * @return true if a new color is chosen, false if
  119. * no change or aborted by user
  120. */
  121. bool Set3DBoardBodyColorFromUser();
  122. /**
  123. * Set the silkscreen color from a set of colors
  124. * @return true if a new color is chosen, false if
  125. * no change or aborted by user
  126. */
  127. bool Set3DSilkScreenColorFromUser();
  128. /**
  129. * Notification that common settings are updated.
  130. *
  131. * This would be private (and only called by the Kiway), but we
  132. * need to do this manually from the PCB frame because the 3D viewer isn't
  133. * updated via the #KIWAY.
  134. */
  135. void CommonSettingsChanged( bool aEnvVarsChanged ) override;
  136. void SynchroniseColoursWithBoard( void );
  137. private:
  138. /// Called when user press the File->Exit
  139. void Exit3DFrame( wxCommandEvent &event );
  140. void OnCloseWindow( wxCloseEvent &event );
  141. void Process_Special_Functions( wxCommandEvent &event );
  142. void On3DGridSelection( wxCommandEvent &event );
  143. void OnRenderEngineSelection( wxCommandEvent &event );
  144. void OnDisableRayTracing( wxCommandEvent& aEvent );
  145. void ProcessZoom( wxCommandEvent &event );
  146. void OnActivate( wxActivateEvent &event );
  147. void OnSetFocus( wxFocusEvent &event );
  148. void Install3DViewOptionDialog( wxCommandEvent &event );
  149. void OnUpdateUIEngine( wxUpdateUIEvent& aEvent );
  150. void OnUpdateUIMaterial( wxUpdateUIEvent& aEvent );
  151. void CreateMenuBar();
  152. /**
  153. * Equivalent of EDA_DRAW_FRAME::ReCreateHToolbar
  154. */
  155. void ReCreateMainToolbar();
  156. void SaveSettings( APP_SETTINGS_BASE *aCfg ) override;
  157. void LoadSettings( APP_SETTINGS_BASE *aCfg ) override;
  158. void OnKeyEvent( wxKeyEvent& event );
  159. /**
  160. * Create a Screenshot of the current 3D view.
  161. * Output file format is png or jpeg, or image is copied to the clipboard
  162. */
  163. void takeScreenshot( wxCommandEvent& event );
  164. /**
  165. * @brief RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged
  166. */
  167. void RenderEngineChanged();
  168. DECLARE_EVENT_TABLE()
  169. private:
  170. /**
  171. * Load configuration from common settings.
  172. */
  173. void loadCommonSettings();
  174. wxFileName m_defaultSaveScreenshotFileName;
  175. wxAuiToolBar* m_mainToolBar;
  176. EDA_3D_CANVAS* m_canvas;
  177. CINFO3D_VISU m_settings;
  178. bool m_disable_ray_tracing;
  179. /**
  180. * Trace mask used to enable or disable the trace output of this class.
  181. * The debug output can be turned on by setting the WXTRACE environment variable to
  182. * "KI_TRACE_EDA_3D_VIEWER". See the wxWidgets documentation on wxLogTrace for
  183. * more information.
  184. */
  185. static const wxChar *m_logTrace;
  186. };
  187. #endif // EDA_3D_VIEWER_H