KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 "confirm.h"
32
33
35 std::vector<std::reference_wrapper<RC_ITEM>> aItems,
36 std::map<int, SEVERITY>& aSeverities,
37 RC_ITEM* aPinMapSpecialCase ) :
38 wxPanel( aParentWindow ),
39 m_severities( aSeverities ),
40 m_items( std::move( 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 Bind( wxEVT_IDLE,
154 [this]( wxIdleEvent& aEvent )
155 {
157 {
158 wxWindow* dialog = wxGetTopLevelParent( this );
159 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
160
161 if( topLevelFocus == dialog )
162 checkReload();
163 }
164 } );
165
166 SetSizer( panelSizer );
167 Layout();
168 panelSizer->Fit( this );
169}
170
171
173{
174 // MUST update lastLoaded before calling IsOK (or we'll end up re-entering through the idle
175 // event until we crash the stack).
177
178 if( IsOK( m_parent, _( "The violation severities have been changed outside the Setup dialog.\n"
179 "Do you wish to reload them?" ) ) )
180 {
182 }
183}
184
185
186void PANEL_SETUP_SEVERITIES::ImportSettingsFrom( std::map<int, SEVERITY>& aSettings )
187{
188 for( const RC_ITEM& item : m_items )
189 {
190 int errorCode = item.GetErrorCode();
191
192 wxRadioButton* button = nullptr;
193
194 switch( aSettings[ errorCode ] )
195 {
196 case RPT_SEVERITY_ERROR: button = m_buttonMap[ errorCode ][0]; break;
197 case RPT_SEVERITY_WARNING: button = m_buttonMap[ errorCode ][1]; break;
198 case RPT_SEVERITY_IGNORE: button = m_buttonMap[ errorCode ][2]; break;
199 default: break;
200 }
201
202 if( button ) // this entry must actually exist
203 button->SetValue( true );
204 }
205
207 {
208 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
209 int newSeverity = aSettings[ pinMapCode ];
210
211 m_buttonMap[ pinMapCode ][0]->SetValue( newSeverity != RPT_SEVERITY_IGNORE );
212 m_buttonMap[ pinMapCode ][2]->SetValue( newSeverity == RPT_SEVERITY_IGNORE );
213 }
214}
215
216
218{
220
221 for( const RC_ITEM& item : m_items )
222 {
223 int errorCode = item.GetErrorCode();
224
225 if( !m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
226 continue;
227
229 continue;
230
231 switch( m_severities[ errorCode ] )
232 {
233 case RPT_SEVERITY_ERROR: m_buttonMap[ errorCode ][0]->SetValue( true ); break;
234 case RPT_SEVERITY_WARNING: m_buttonMap[ errorCode ][1]->SetValue( true ); break;
235 case RPT_SEVERITY_IGNORE: m_buttonMap[ errorCode ][2]->SetValue( true ); break;
236 default: break;
237 }
238 }
239
241 {
242 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
243 int severity = m_severities[pinMapCode];
244
245 m_buttonMap[ pinMapCode ][0]->SetValue( severity != RPT_SEVERITY_IGNORE );
246 m_buttonMap[ pinMapCode ][2]->SetValue( severity == RPT_SEVERITY_IGNORE );
247 }
248
249 return true;
250}
251
252
254{
255 for( const RC_ITEM& item : m_items )
256 {
257 int errorCode = item.GetErrorCode();
258
260 continue;
261
262 if( !m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
263 continue;
264
266
267 if( m_buttonMap[ errorCode ][0]->GetValue() )
268 severity = RPT_SEVERITY_ERROR;
269 else if( m_buttonMap[ errorCode ][1]->GetValue() )
270 severity = RPT_SEVERITY_WARNING;
271 else if( m_buttonMap[ errorCode ][2]->GetValue() )
272 severity = RPT_SEVERITY_IGNORE;
273
274 m_severities[ errorCode ] = severity;
275 }
276
278 {
279 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
281
282 if( m_buttonMap[ pinMapCode ][0]->GetValue() )
283 severity = RPT_SEVERITY_ERROR;
284 else if( m_buttonMap[ pinMapCode ][2]->GetValue() )
285 severity = RPT_SEVERITY_IGNORE;
286
287 m_severities[ pinMapCode ] = severity;
288 }
289
290 return true;
291}
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.
PANEL_SETUP_SEVERITIES(wxWindow *aParentWindow, std::vector< std::reference_wrapper< RC_ITEM > > aItems, std::map< int, SEVERITY > &aSeverities, RC_ITEM *aPinMapSpecialCase=nullptr)
Creates the severities setup panel.
std::map< int, wxRadioButton *[4]> m_buttonMap
std::map< int, SEVERITY > m_lastLoaded
std::vector< std::reference_wrapper< RC_ITEM > > m_items
A list of item templates (to get descriptive text and error codes from)
A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
Definition: rc_item.h:79
int GetErrorCode() const
Definition: rc_item.h:153
wxString GetErrorText() const
Definition: rc_item.h:166
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:360
This file is part of the common library.
#define _(s)
STL namespace.
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.