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.

120 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 Mike Williams <mike@mikebwilliams.com>
  5. * Copyright The 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. #include <panel_bom_presets.h>
  25. #include <wx/grid.h>
  26. #include <widgets/wx_grid.h>
  27. #include <bitmaps.h>
  28. #include <widgets/std_bitmap_button.h>
  29. PANEL_BOM_PRESETS::PANEL_BOM_PRESETS( wxWindow* aWindow, SCHEMATIC_SETTINGS& aSettings ) :
  30. PANEL_BOM_PRESETS_BASE( aWindow ), m_settings( aSettings )
  31. {
  32. m_btnDeleteBomPreset->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
  33. m_btnDeleteBomFmtPreset->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
  34. m_bomPresetsGrid->SetUseNativeColLabels();
  35. m_bomFmtPresetsGrid->SetUseNativeColLabels();
  36. }
  37. bool PANEL_BOM_PRESETS::TransferDataToWindow()
  38. {
  39. m_bomPresets = m_settings.m_BomPresets;
  40. m_bomFmtPresets = m_settings.m_BomFmtPresets;
  41. BuildGrid();
  42. return true;
  43. }
  44. bool PANEL_BOM_PRESETS::TransferDataFromWindow()
  45. {
  46. m_settings.m_BomPresets = m_bomPresets;
  47. m_settings.m_BomFmtPresets = m_bomFmtPresets;
  48. return true;
  49. }
  50. void PANEL_BOM_PRESETS::BuildGrid()
  51. {
  52. m_bomPresetsGrid->ClearRows();
  53. m_bomFmtPresetsGrid->ClearRows();
  54. for( const BOM_PRESET& p : m_bomPresets )
  55. {
  56. m_bomPresetsGrid->AppendRows( 1 );
  57. m_bomPresetsGrid->SetCellValue( m_bomPresetsGrid->GetNumberRows() - 1, 0, p.name );
  58. }
  59. for( const BOM_FMT_PRESET& p : m_bomFmtPresets )
  60. {
  61. m_bomFmtPresetsGrid->AppendRows( 1 );
  62. m_bomFmtPresetsGrid->SetCellValue( m_bomFmtPresetsGrid->GetNumberRows() - 1, 0, p.name );
  63. }
  64. }
  65. void PANEL_BOM_PRESETS::OnDeleteBomPreset( wxCommandEvent& event )
  66. {
  67. int curRow = m_bomPresetsGrid->GetGridCursorRow();
  68. if( curRow < 0 || m_bomPresetsGrid->GetNumberRows() <= curRow )
  69. return;
  70. m_bomPresetsGrid->DeleteRows( curRow, 1 );
  71. m_bomPresets.erase( m_bomPresets.begin() + curRow );
  72. }
  73. void PANEL_BOM_PRESETS::OnDeleteBomFmtPreset( wxCommandEvent& event )
  74. {
  75. int curRow = m_bomFmtPresetsGrid->GetGridCursorRow();
  76. if( curRow < 0 || m_bomFmtPresetsGrid->GetNumberRows() <= curRow )
  77. return;
  78. m_bomFmtPresetsGrid->DeleteRows( curRow, 1 );
  79. // Erase the bom preset from the bom presets list.
  80. m_bomFmtPresets.erase( m_bomFmtPresets.begin() + curRow );
  81. }
  82. void PANEL_BOM_PRESETS::ImportBomPresetsFrom( SCHEMATIC_SETTINGS& aSettings )
  83. {
  84. m_bomPresets = aSettings.m_BomPresets;
  85. BuildGrid();
  86. }
  87. void PANEL_BOM_PRESETS::ImportBomFmtPresetsFrom( SCHEMATIC_SETTINGS& aSettings )
  88. {
  89. m_bomFmtPresets = aSettings.m_BomFmtPresets;
  90. BuildGrid();
  91. }