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.

269 lines
12 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2009-2022 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. #ifndef PANEL_SETUP_BOARD_STACKUP_H
  25. #define PANEL_SETUP_BOARD_STACKUP_H
  26. #include <board.h>
  27. #include <widgets/unit_binder.h>
  28. #include <wx/gdicmn.h>
  29. #include "panel_board_stackup_base.h"
  30. #include "board_stackup.h"
  31. #include "stackup_predefined_prms.h"
  32. #include "dielectric_material.h"
  33. class wxBitmapComboBox;
  34. class PANEL_SETUP_LAYERS;
  35. // A helper class to handle UI items managed by m_fgGridSizer
  36. // in PANEL_SETUP_BOARD_STACKUP
  37. // these items are shown or not in m_fgGridSizer, depending on
  38. // the enabled layers in the current board.
  39. // So we need to store the list of these UI items int m_fgGridSizer
  40. // row by row
  41. struct BOARD_STACKUP_ROW_UI_ITEM
  42. {
  43. BOARD_STACKUP_ITEM* m_Item; // The BOARD_STACKUP_ITEM managed by this BOARD_STACKUP_ROW_UI_ITEM
  44. int m_SubItem; // For multilayer dielectric, the index in sublayer list.
  45. // Must be >= 0 and < m_Item sublayer count. Used only for dielectic
  46. // 0 is the base list of parameters (always existing)
  47. bool m_isEnabled; // True if the row is in board
  48. // false if not (this row is not shown on the panel)
  49. wxStaticBitmap* m_Icon; // Color icon in first column (column 1)
  50. wxStaticText* m_LayerName; // string shown in column 2
  51. wxControl* m_LayerTypeCtrl; // control shown in column 3
  52. wxControl* m_MaterialCtrl; // control shown in column 4, with m_MaterialButt
  53. wxButton* m_MaterialButt; // control shown in column 4, with m_MaterialCtrl
  54. wxControl* m_ThicknessCtrl; // control shown in column 5
  55. wxControl* m_ThicknessLockCtrl;// control shown in column 6
  56. wxControl* m_ColorCtrl; // control shown in column 7
  57. wxControl* m_EpsilonCtrl; // control shown in column 8
  58. wxControl* m_LossTgCtrl; // control shown in column 9
  59. COLOR4D m_UserColor; // User-specified color (if any)
  60. BOARD_STACKUP_ROW_UI_ITEM( BOARD_STACKUP_ITEM* aItem, int aSubItem = 1 ) :
  61. m_Item( aItem ),
  62. m_SubItem( aSubItem ),
  63. m_isEnabled( true ),
  64. m_Icon( nullptr ),
  65. m_LayerName( nullptr ),
  66. m_LayerTypeCtrl( nullptr ),
  67. m_MaterialCtrl( nullptr ),
  68. m_MaterialButt( nullptr ),
  69. m_ThicknessCtrl( nullptr ),
  70. m_ThicknessLockCtrl( nullptr ),
  71. m_ColorCtrl( nullptr ),
  72. m_EpsilonCtrl( nullptr ),
  73. m_LossTgCtrl( nullptr )
  74. {}
  75. };
  76. class PANEL_SETUP_BOARD_STACKUP : public PANEL_SETUP_BOARD_STACKUP_BASE
  77. {
  78. public:
  79. PANEL_SETUP_BOARD_STACKUP( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame,
  80. PANEL_SETUP_LAYERS* aPanelLayers );
  81. ~PANEL_SETUP_BOARD_STACKUP();
  82. void ImportSettingsFrom( BOARD* aBoard );
  83. /** Must be called if the copper layers count has changed
  84. * or solder mask, solder paste or silkscreen layers are
  85. * enabled or disabled
  86. * Rebuild the Layer Stack Panel if the new layer set differs
  87. * from the current layet set
  88. */
  89. void OnLayersOptionsChanged( LSET aNewLayerSet );
  90. /// @return the number of copper layers configured for the board stackup
  91. int GetCopperLayerCount() const;
  92. /// @return the BOARD_STACKUP_ITEM managed by the row aRow
  93. BOARD_STACKUP_ITEM* GetStackupItem( int aRow );
  94. /// @return the BOARD_STACKUP_ITEM sublayermanaged by the row aRow
  95. int GetSublayerId( int aRow );
  96. /// Return the color currently selected for the row aRow
  97. wxColor GetSelectedColor( int aRow ) const;
  98. BOARD_STACKUP& GetStackup() { return m_stackup; }
  99. // Called by wxWidgets: transfer current settings stored in m_stackup to the board
  100. bool TransferDataFromWindow() override;
  101. private:
  102. /** Creates a BOARD_STACKUP_ROW_UI_ITEM relative to the aStackupItem.
  103. * @return a BOARD_STACKUP_ROW_UI_ITEM filled with corresponding widgets
  104. * @param aRow is the row index in the row list
  105. * @param aStackupItem is the stackup item controlled by the created
  106. * BOARD_STACKUP_ROW_UI_ITEM.
  107. * @param aSublayerIdx is used only for BS_ITEM_TYPE_DIELECTRIC stackup items.
  108. * this is the index of the sublayer to used inside aStackupItem
  109. * (from 0 to sub layer count - 1)
  110. */
  111. BOARD_STACKUP_ROW_UI_ITEM createRowData( int aRow, BOARD_STACKUP_ITEM* aStackupItem,
  112. int aSublayerIdx );
  113. /** add a Spacer in m_fgGridSizer when a empty cell is needed
  114. */
  115. wxControl* addSpacer();
  116. /** add a control (a wxTextCtrl + a button) in m_fgGridSizer to select a material
  117. * @param aId is the wxControl id, used to know the event source
  118. * @param aMaterialName is the name of the currently selected material (can be null)
  119. * @param aUiRowItem is the BOARD_STACKUP_ROW_UI_ITEM to store the controls
  120. * created
  121. */
  122. void addMaterialChooser( wxWindowID aId, const wxString * aMaterialName,
  123. BOARD_STACKUP_ROW_UI_ITEM& aUiRowItem );
  124. /** Populate m_fgGridSizer with items to handle stackup parameters
  125. * This is a full list:
  126. * all copper layers and all tech layers that are supported by the stackup
  127. * items not in the current board stackup will be not shown, but they are
  128. * existing in list
  129. * @param aCreatedInitialStackup = true to create a initial stackup list for the dialog
  130. * false to build the stackup panel from the existing stackup list.
  131. */
  132. void buildLayerStackPanel( bool aCreatedInitialStackup );
  133. /** Synchronize the full stackup shown in m_fgGridSizer according to the stackup of the
  134. * current board and optionally update the stackup params (thickness, color ... )
  135. * @param aFullSync = true to update stackup params, false to only update the list
  136. * of shown items
  137. */
  138. void synchronizeWithBoard( bool aFullSync );
  139. /** Show or do not show items in m_fgGridSizer according to the stackup of the
  140. * current board.
  141. * The panel stackup stores all possible layers (because the number of layers is set
  142. * from an other panel), but only some of them must be actually shown on screen
  143. */
  144. void showOnlyActiveLayers();
  145. /** Populate m_fgGridSizer with items to handle stackup parameters
  146. * If previous items are in list, remove old items
  147. * New prms are added
  148. * must be called after adding or deleting a dielectric parameter set
  149. */
  150. void rebuildLayerStackPanel();
  151. /** Transfer current UI settings to m_stackup but not to the board
  152. */
  153. bool transferDataFromUIToStackup();
  154. /**
  155. * Updates the enabled copper layers when the dropdown is changed
  156. */
  157. void updateCopperLayerCount();
  158. /**
  159. * Recompute the board thickness and update the textbox
  160. * @return the computed value
  161. */
  162. int computeBoardThickness();
  163. /**
  164. * Set the widths of dielectric layers to sensible defaults
  165. * @param targetThickness target thickness of PCB in IU
  166. */
  167. void setDefaultLayerWidths( int targetThickness );
  168. void onColorSelected( wxCommandEvent& event );
  169. void onMaterialChange( wxCommandEvent& event );
  170. void onThicknessChange( wxCommandEvent& event );
  171. void onExportToClipboard( wxCommandEvent& event ) override;
  172. void onAddDielectricLayer( wxCommandEvent& event ) override;
  173. void onRemoveDielectricLayer( wxCommandEvent& event ) override;
  174. void onRemoveDielUI( wxUpdateUIEvent& event ) override;
  175. void onCopperLayersSelCount( wxCommandEvent& event ) override;
  176. void onAdjustDielectricThickness( wxCommandEvent& event ) override;
  177. /** Update the icons color (swatches in first grid column)
  178. * @param aRow is the row (index in m_rowUiItemsList) that manages the icon to update.
  179. * if -1 all icons will be updated
  180. */
  181. void updateIconColor( int aRow = -1 );
  182. /** @return the color of the BOARD_STACKUP_ITEM at row aRow,
  183. * to draw a bitmap color according to the selected color
  184. * or the best default color (for dielectric or copper item)
  185. * @param aRow is the row index to find the color.
  186. */
  187. wxColor getColorIconItem( int aRow );
  188. /** creates a bitmap combobox to select a layer color
  189. * @return the created wxBitmapComboBox
  190. * @param aStackupItem = the BOARD_STACKUP_ITEM related to the bitmap combobox
  191. * (to set the user color, if any)
  192. * can be nullptr
  193. * @param aRow = the row index in the wxFlexGridSizer (used to build a wxWidget unique id)
  194. */
  195. wxBitmapComboBox* createColorBox( BOARD_STACKUP_ITEM* aStackupItem, int aRow );
  196. /**
  197. * disconnect event handlers connected to wxControl items
  198. * found in list m_controlItemsList
  199. */
  200. void disconnectEvents();
  201. private:
  202. BOARD_STACKUP m_stackup;
  203. PANEL_SETUP_LAYERS* m_panelLayers; // The associated PANEL_SETUP_LAYERS, to know
  204. // enabled layers and copper layer names
  205. LSET m_enabledLayers; // the current enabled layers in this panel
  206. // restricted to allowed layers in stackup.
  207. // when do not match the enabled layers
  208. // in PANEL_SETUP_LAYERS the stackup is not up to date
  209. // a list of currently available dielectric materials
  210. DIELECTRIC_SUBSTRATE_LIST m_delectricMatList;
  211. // a list of currently available solder mask materials
  212. DIELECTRIC_SUBSTRATE_LIST m_solderMaskMatList;
  213. // a list of currently available solder mask materials
  214. DIELECTRIC_SUBSTRATE_LIST m_silkscreenMatList;
  215. // List of items in m_fgGridSizer
  216. std::vector<BOARD_STACKUP_ROW_UI_ITEM> m_rowUiItemsList;
  217. PAGED_DIALOG* m_parentDialog;
  218. BOARD* m_board;
  219. BOARD_DESIGN_SETTINGS* m_brdSettings;
  220. PCB_EDIT_FRAME* m_frame;
  221. wxSize m_numericTextCtrlSize; // Best size to enter values with units in wxTextCtrl
  222. wxSize m_numericFieldsSize; // Best size to enter double values in wxTextCtrl
  223. wxArrayString m_core_prepreg_choice; // Used to display the option list in dialog
  224. wxSize m_colorSwatchesSize; // the size of color swatches in the wxBitmapComboBox.
  225. wxSize m_colorIconsSize; // the size of color swatches in grid, left column.
  226. // The list of controls (wxChoice, wxBitmapComboBox, wxTextCtrl) added to the panel
  227. // when building the BOARD_STACKUP_ITEM list editor and connected to command events
  228. // Used to disconnect event handlers
  229. std::vector<wxControl*> m_controlItemsList;
  230. };
  231. #endif // #ifndef PANEL_SETUP_BOARD_STACKUP_H