KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_bom_presets.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 Mike Williams <[email protected]>
5 * Copyright (C) 2023 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
25#include <panel_bom_presets.h>
26
27#include <wx/grid.h>
28#include <widgets/wx_grid.h>
29#include <bitmaps.h>
31
32
34 PANEL_BOM_PRESETS_BASE( aWindow ), m_settings( aSettings )
35{
36 m_btnDeleteBomPreset->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
37 m_btnDeleteBomFmtPreset->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
38
39 m_bomPresetsGrid->SetUseNativeColLabels();
40 m_bomFmtPresetsGrid->SetUseNativeColLabels();
41}
42
43
45{
48
49 BuildGrid();
50
51 return true;
52}
53
54
56{
59
60 return true;
61}
62
63
65{
68
69 for( const BOM_PRESET& p : m_bomPresets )
70 {
71 m_bomPresetsGrid->AppendRows( 1 );
72 m_bomPresetsGrid->SetCellValue( m_bomPresetsGrid->GetNumberRows() - 1, 0, p.name );
73 }
74
75 for( const BOM_FMT_PRESET& p : m_bomFmtPresets )
76 {
77 m_bomFmtPresetsGrid->AppendRows( 1 );
78 m_bomFmtPresetsGrid->SetCellValue( m_bomFmtPresetsGrid->GetNumberRows() - 1, 0, p.name );
79 }
80}
81
82
83void PANEL_BOM_PRESETS::OnDeleteBomPreset( wxCommandEvent& event )
84{
85 int curRow = m_bomPresetsGrid->GetGridCursorRow();
86
87 if( curRow < 0 || m_bomPresetsGrid->GetNumberRows() <= curRow )
88 return;
89
90 m_bomPresetsGrid->DeleteRows( curRow, 1 );
91 m_bomPresets.erase( m_bomPresets.begin() + curRow );
92}
93
94
95void PANEL_BOM_PRESETS::OnDeleteBomFmtPreset( wxCommandEvent& event )
96{
97 int curRow = m_bomFmtPresetsGrid->GetGridCursorRow();
98
99 if( curRow < 0 || m_bomFmtPresetsGrid->GetNumberRows() <= curRow )
100 return;
101
102 m_bomFmtPresetsGrid->DeleteRows( curRow, 1 );
103 // Erase the bom preset from the bom presets list.
104 m_bomFmtPresets.erase( m_bomFmtPresets.begin() + curRow );
105}
106
107
109{
110 m_bomPresets = aSettings.m_BomPresets;
111 BuildGrid();
112}
113
114
116{
118 BuildGrid();
119}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
Class PANEL_BOM_PRESETS_BASE.
STD_BITMAP_BUTTON * m_btnDeleteBomPreset
STD_BITMAP_BUTTON * m_btnDeleteBomFmtPreset
std::vector< BOM_FMT_PRESET > m_bomFmtPresets
std::vector< BOM_PRESET > m_bomPresets
void OnDeleteBomFmtPreset(wxCommandEvent &event) override
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
void ImportBomFmtPresetsFrom(SCHEMATIC_SETTINGS &aSettings)
PANEL_BOM_PRESETS(wxWindow *aWindow, SCHEMATIC_SETTINGS &aSettings)
void ImportBomPresetsFrom(SCHEMATIC_SETTINGS &aSettings)
SCHEMATIC_SETTINGS & m_settings
void OnDeleteBomPreset(wxCommandEvent &event) override
These are loaded from Eeschema settings but then overwritten by the project settings.
std::vector< BOM_PRESET > m_BomPresets
std::vector< BOM_FMT_PRESET > m_BomFmtPresets
void SetBitmap(const wxBitmapBundle &aBmp)
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184