KiCad PCB EDA Suite
panel_setup_severities.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) 2020-2023 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#include <widgets/ui_common.h>
26#include <rc_item.h>
28#include <wx/radiobut.h>
29#include <wx/scrolwin.h>
30#include <wx/stattext.h>
31#include <wx/treebook.h>
32
33
35 std::vector<std::reference_wrapper<RC_ITEM>> aItems,
36 std::map<int, SEVERITY>& aSeverities,
37 RC_ITEM* aPinMapSpecialCase ) :
38 wxPanel( aParent->GetTreebook() ),
39 m_severities( aSeverities ),
40 m_items( aItems ),
41 m_pinMapSpecialCase( aPinMapSpecialCase )
42{
43 wxString severities[] = { _( "Error" ), _( "Warning" ), _( "Ignore" ) };
44 int severityCount = sizeof( severities ) / sizeof( wxString );
45 int baseID = 1000;
46 wxBoxSizer* panelSizer = new wxBoxSizer( wxVERTICAL );
47 wxScrolledWindow* scrollWin = new wxScrolledWindow( this, wxID_ANY,
48 wxDefaultPosition, wxDefaultSize,
49 wxTAB_TRAVERSAL | wxVSCROLL );
50 bool firstLine = true;
51
52 scrollWin->SetScrollRate( 0, 5 );
53
54 wxBoxSizer* scrollWinSizer = new wxBoxSizer( wxVERTICAL );
55 scrollWin->SetSizer( scrollWinSizer );
56
57 wxFlexGridSizer* gridSizer = new wxFlexGridSizer( 0, 2, 0, 5 );
58 gridSizer->SetFlexibleDirection( wxBOTH );
59 gridSizer->SetVGap( 5 );
60
61 for( const RC_ITEM& item : m_items )
62 {
63 int errorCode = item.GetErrorCode();
64 wxString msg = item.GetErrorText();
65
67 continue;
68
69 if( errorCode == 0 )
70 {
71 wxStaticText* heading = new wxStaticText( scrollWin, wxID_ANY, msg );
72 wxFont headingFont = heading->GetFont();
73
74 heading->SetFont( headingFont.Bold() );
75
76 if( !firstLine )
77 {
78 gridSizer->AddSpacer( 5 ); // col 1
79 gridSizer->AddSpacer( 5 ); // col 2
80 }
81
82 gridSizer->Add( heading, 0, wxALIGN_BOTTOM | wxALL | wxEXPAND, 4 );
83 gridSizer->AddSpacer( 0 ); // col 2
84 }
85 else if( !msg.IsEmpty() ) // items with no message are for internal use only
86 {
87 wxStaticText* errorLabel = new wxStaticText( scrollWin, wxID_ANY, msg + wxT( ":" ) );
88 gridSizer->Add( errorLabel, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 15 );
89
90 // OSX can't handle more than 100 radio buttons in a single window (yes, seriously),
91 // so we have to create a window for each set
92 wxPanel* radioPanel = new wxPanel( scrollWin );
93 wxBoxSizer* radioSizer = new wxBoxSizer( wxHORIZONTAL );
94
95 for( int i = 0; i < severityCount; ++i )
96 {
97 m_buttonMap[ errorCode ][i] = new wxRadioButton( radioPanel,
98 baseID + errorCode * 10 + i,
99 severities[i],
100 wxDefaultPosition, wxDefaultSize,
101 i == 0 ? wxRB_GROUP : 0 );
102 radioSizer->Add( m_buttonMap[ errorCode ][i], 0,
103 wxRIGHT | wxALIGN_CENTER_VERTICAL, 30 );
104 }
105
106 radioPanel->SetSizer( radioSizer );
107 radioPanel->Layout();
108 gridSizer->Add( radioPanel, 0, wxALIGN_CENTER_VERTICAL );
109 }
110
111 firstLine = false;
112 }
113
114
116 {
117 wxString pinMapSeverities[] = { _( "From Pin Conflicts Map" ), wxT( "" ), _( "Ignore" ) };
118 int errorCode = m_pinMapSpecialCase->GetErrorCode();
119 wxString msg = m_pinMapSpecialCase->GetErrorText();
120
121 wxStaticText* errorLabel = new wxStaticText( scrollWin, wxID_ANY, msg + wxT( ":" ) );
122 gridSizer->Add( errorLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 15 );
123
124 wxPanel* radioPanel = new wxPanel( scrollWin );
125 wxBoxSizer* radioSizer = new wxBoxSizer( wxHORIZONTAL );
126
127 for( size_t i = 0; i < 3; ++i )
128 {
129 if( pinMapSeverities[i] == wxT( "" ) )
130 {
131 wxStaticText* spacer = new wxStaticText( radioPanel, wxID_ANY, wxT( "" ) );
132 radioSizer->Add( spacer, 0, wxRIGHT | wxEXPAND, 17 );
133 }
134 else
135 {
136 m_buttonMap[ errorCode ][i] = new wxRadioButton( radioPanel,
137 baseID + errorCode * 10 + i,
138 pinMapSeverities[i],
139 wxDefaultPosition, wxDefaultSize,
140 i == 0 ? wxRB_GROUP : 0 );
141 radioSizer->Add( m_buttonMap[ errorCode ][i], 0, wxEXPAND );
142 }
143 }
144
145 radioPanel->SetSizer( radioSizer );
146 radioPanel->Layout();
147 gridSizer->Add( radioPanel, 0, wxALIGN_CENTER_VERTICAL );
148 }
149
150 scrollWinSizer->Add( gridSizer, 1, wxEXPAND | wxALL, 5 );
151 panelSizer->Add( scrollWin, 1, wxEXPAND, 0 );
152
153 SetSizer( panelSizer );
154 Layout();
155 panelSizer->Fit( this );
156}
157
158
159void PANEL_SETUP_SEVERITIES::ImportSettingsFrom( std::map<int, SEVERITY>& aSettings )
160{
161 for( const RC_ITEM& item : m_items )
162 {
163 int errorCode = item.GetErrorCode();
164
165 if(! m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
166 continue;
167
168 switch( aSettings[ errorCode ] )
169 {
170 case RPT_SEVERITY_ERROR: m_buttonMap[ errorCode ][0]->SetValue( true ); break;
171 case RPT_SEVERITY_WARNING: m_buttonMap[ errorCode ][1]->SetValue( true ); break;
172 case RPT_SEVERITY_IGNORE: m_buttonMap[ errorCode ][2]->SetValue( true ); break;
173 default: break;
174 }
175 }
176
178 {
179 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
180 int newSeverity = aSettings[ pinMapCode ];
181
182 m_buttonMap[ pinMapCode ][0]->SetValue( newSeverity != RPT_SEVERITY_IGNORE );
183 m_buttonMap[ pinMapCode ][2]->SetValue( newSeverity == RPT_SEVERITY_IGNORE );
184 }
185}
186
187
189{
190 for( const RC_ITEM& item : m_items )
191 {
192 int errorCode = item.GetErrorCode();
193
194 if( !m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
195 continue;
196
198 continue;
199
200 switch( m_severities[ errorCode ] )
201 {
202 case RPT_SEVERITY_ERROR: m_buttonMap[ errorCode ][0]->SetValue( true ); break;
203 case RPT_SEVERITY_WARNING: m_buttonMap[ errorCode ][1]->SetValue( true ); break;
204 case RPT_SEVERITY_IGNORE: m_buttonMap[ errorCode ][2]->SetValue( true ); break;
205 default: break;
206 }
207 }
208
210 {
211 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
212 int severity = m_severities[pinMapCode];
213
214 m_buttonMap[ pinMapCode ][0]->SetValue( severity != RPT_SEVERITY_IGNORE );
215 m_buttonMap[ pinMapCode ][2]->SetValue( severity == RPT_SEVERITY_IGNORE );
216 }
217
218 return true;
219}
220
221
223{
224 for( const RC_ITEM& item : m_items )
225 {
226 int errorCode = item.GetErrorCode();
227
229 continue;
230
231 if( !m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
232 continue;
233
235
236 if( m_buttonMap[ errorCode ][0]->GetValue() )
237 severity = RPT_SEVERITY_ERROR;
238 else if( m_buttonMap[ errorCode ][1]->GetValue() )
239 severity = RPT_SEVERITY_WARNING;
240 else if( m_buttonMap[ errorCode ][2]->GetValue() )
241 severity = RPT_SEVERITY_IGNORE;
242
243 m_severities[ errorCode ] = severity;
244 }
245
247 {
248 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
250
251 if( m_buttonMap[ pinMapCode ][0]->GetValue() )
252 severity = RPT_SEVERITY_ERROR;
253 else if( m_buttonMap[ pinMapCode ][2]->GetValue() )
254 severity = RPT_SEVERITY_IGNORE;
255
256 m_severities[ pinMapCode ] = severity;
257 }
258
259 return true;
260}
void ImportSettingsFrom(std::map< int, SEVERITY > &aSettings)
std::map< int, SEVERITY > & m_severities
RC_ITEM * m_pinMapSpecialCase
For ERC settings; a pointer to ERC_ITEM::pinTableConflict.
std::map< int, wxRadioButton *[4]> m_buttonMap
std::vector< std::reference_wrapper< RC_ITEM > > m_items
A list of item templates (to get descriptive text and error codes from)
PANEL_SETUP_SEVERITIES(PAGED_DIALOG *aParent, std::vector< std::reference_wrapper< RC_ITEM > > aItems, std::map< int, SEVERITY > &aSeverities, RC_ITEM *aPinMapSpecialCase=nullptr)
Creates the severities setup panel.
A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
Definition: rc_item.h:75
int GetErrorCode() const
Definition: rc_item.h:136
wxString GetErrorText() const
Definition: rc_item.h:149
#define _(s)
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
@ RPT_SEVERITY_IGNORE
Functions to provide common constants and other functions to assist in making a consistent UI.