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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22
23PANEL_DRC_GROUP_HEADER::PANEL_DRC_GROUP_HEADER( wxWindow* aParent, const std::vector<DRC_RULE_ROW>& aRows ) :
25 m_rows( aRows )
26{
27 int cols = m_dataGrid->GetNumberCols();
28
29 if( cols )
30 m_dataGrid->DeleteCols( 0, cols );
31
32 int rows = m_dataGrid->GetNumberRows();
33
34 if( rows )
35 m_dataGrid->DeleteRows( 0, rows );
36
37 m_dataGrid->AppendCols( 3 );
38 m_dataGrid->SetColLabelValue( 0, _( "Rule type" ) );
39 m_dataGrid->SetColLabelValue( 1, _( "Rule name" ) );
40 m_dataGrid->SetColLabelValue( 2, _( "Comment" ) );
41
42 m_dataGrid->AppendRows( m_rows.size() );
43
44 for( size_t i = 0; i < m_rows.size(); ++i )
45 {
46 m_dataGrid->SetCellValue( i, 0, m_rows[i].m_ruleType );
47 m_dataGrid->SetCellValue( i, 1, m_rows[i].m_ruleName );
48 m_dataGrid->SetCellValue( i, 2, m_rows[i].m_comment );
49 }
50
51 // Disable horizontal scroll bar
52 m_dataGrid->EnableScrolling( false, true );
53}
54
55
59
60
62{
63 return true;
64}
65
66
71
72void PANEL_DRC_GROUP_HEADER::OnSize( wxSizeEvent& event )
73{
74 wxSize clientSize = GetClientSize();
75 int availableWidth = clientSize.GetWidth() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
76 int availableHeight = clientSize.GetHeight() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y );
77
78 m_dataGrid->SetSize( wxSize( availableWidth, availableHeight ) );
79 double total_column_width = m_dataGrid->GetColSize( 0 ) + m_dataGrid->GetColSize( 1 ) + m_dataGrid->GetColSize( 2 );
80 double col0_width_ratio = m_dataGrid->GetColSize( 0 ) / total_column_width;
81 double col1_width_ratio = m_dataGrid->GetColSize( 1 ) / total_column_width;
82 int col0_size = static_cast<int>( availableWidth * col0_width_ratio );
83 int col1_size = static_cast<int>( availableWidth * col1_width_ratio );
84 int col2_size = availableWidth - col0_size - col1_size;
85
86 m_dataGrid->SetColSize( 0, col0_size );
87 m_dataGrid->SetColSize( 1, col1_size );
88 m_dataGrid->SetColSize( 2, col2_size );
89
90 // Refresh the grid to apply the new sizes.
91 m_dataGrid->ForceRefresh();
92
93 event.Skip(); // Allow further processing of the event.
94}
95
96void PANEL_DRC_GROUP_HEADER::OnGridSize( wxGridSizeEvent& event )
97{
98 wxSizeEvent evt( m_dataGrid->GetSize() );
99 OnSize( evt );
100}
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)