KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_drc_group_header.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) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26
27PANEL_DRC_GROUP_HEADER::PANEL_DRC_GROUP_HEADER( wxWindow* aParent, const std::vector<DRC_RULE_ROW>& aRows ) :
29 m_rows( aRows )
30{
31 int cols = m_dataGrid->GetNumberCols();
32
33 if( cols )
34 m_dataGrid->DeleteCols( 0, cols );
35
36 int rows = m_dataGrid->GetNumberRows();
37
38 if( rows )
39 m_dataGrid->DeleteRows( 0, rows );
40
41 m_dataGrid->AppendCols( 3 );
42 m_dataGrid->SetColLabelValue( 0, _( "Rule type" ) );
43 m_dataGrid->SetColLabelValue( 1, _( "Rule name" ) );
44 m_dataGrid->SetColLabelValue( 2, _( "Comment" ) );
45
46 m_dataGrid->AppendRows( m_rows.size() );
47
48 for( size_t i = 0; i < m_rows.size(); ++i )
49 {
50 m_dataGrid->SetCellValue( i, 0, m_rows[i].m_ruleType );
51 m_dataGrid->SetCellValue( i, 1, m_rows[i].m_ruleName );
52 m_dataGrid->SetCellValue( i, 2, m_rows[i].m_comment );
53 }
54
55 // Disable horizontal scroll bar
56 m_dataGrid->EnableScrolling( false, true );
57}
58
59
63
64
66{
67 return true;
68}
69
70
75
76void PANEL_DRC_GROUP_HEADER::OnSize( wxSizeEvent& event )
77{
78 wxSize clientSize = GetClientSize();
79 int availableWidth = clientSize.GetWidth() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
80 int availableHeight = clientSize.GetHeight() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y );
81
82 m_dataGrid->SetSize( wxSize( availableWidth, availableHeight ) );
83 double total_column_width = m_dataGrid->GetColSize( 0 ) + m_dataGrid->GetColSize( 1 ) + m_dataGrid->GetColSize( 2 );
84 double col0_width_ratio = m_dataGrid->GetColSize( 0 ) / total_column_width;
85 double col1_width_ratio = m_dataGrid->GetColSize( 1 ) / total_column_width;
86 int col0_size = static_cast<int>( availableWidth * col0_width_ratio );
87 int col1_size = static_cast<int>( availableWidth * col1_width_ratio );
88 int col2_size = availableWidth - col0_size - col1_size;
89
90 m_dataGrid->SetColSize( 0, col0_size );
91 m_dataGrid->SetColSize( 1, col1_size );
92 m_dataGrid->SetColSize( 2, col2_size );
93
94 // Refresh the grid to apply the new sizes.
95 m_dataGrid->ForceRefresh();
96
97 event.Skip(); // Allow further processing of the event.
98}
99
100void PANEL_DRC_GROUP_HEADER::OnGridSize( wxGridSizeEvent& event )
101{
102 wxSizeEvent evt( m_dataGrid->GetSize() );
103 OnSize( evt );
104}
PANEL_DRC_GROUP_HEADER_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void OnSize(wxSizeEvent &event) override
void OnGridSize(wxGridSizeEvent &event) override
PANEL_DRC_GROUP_HEADER(wxWindow *aParent, const std::vector< DRC_RULE_ROW > &aRows)
std::vector< DRC_RULE_ROW > m_rows
#define _(s)