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 The 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#include <widgets/ui_common.h>
22#include <rc_item.h>
24#include <wx/radiobut.h>
25#include <wx/scrolwin.h>
26#include <wx/sizer.h>
27#include <wx/stattext.h>
28#include "confirm.h"
29
30
32 std::vector<std::reference_wrapper<RC_ITEM>> aItems,
33 std::map<int, SEVERITY>& aSeverities,
34 RC_ITEM* aPinMapSpecialCase ) :
35 wxPanel( aParentWindow ),
36 m_severities( aSeverities ),
37 m_items( std::move( aItems ) ),
38 m_pinMapSpecialCase( aPinMapSpecialCase )
39{
40 wxString severities[] = { _( "Error" ), _( "Warning" ), _( "Ignore" ) };
41 int severityCount = sizeof( severities ) / sizeof( wxString );
42 int baseID = 1000;
43 wxBoxSizer* panelSizer = new wxBoxSizer( wxVERTICAL );
44 wxScrolledWindow* scrollWin = new wxScrolledWindow( this, wxID_ANY,
45 wxDefaultPosition, wxDefaultSize,
46 wxTAB_TRAVERSAL | wxVSCROLL );
47 bool firstLine = true;
48
49 scrollWin->SetScrollRate( 0, 5 );
50
51 wxBoxSizer* scrollWinSizer = new wxBoxSizer( wxVERTICAL );
52 scrollWin->SetSizer( scrollWinSizer );
53
54 wxFlexGridSizer* gridSizer = new wxFlexGridSizer( 0, 2, 0, 5 );
55 gridSizer->SetFlexibleDirection( wxBOTH );
56 gridSizer->SetVGap( 5 );
57
58 for( const RC_ITEM& item : m_items )
59 {
60 int errorCode = item.GetErrorCode();
61 wxString msg = item.GetErrorText( true );
62
63 if( m_pinMapSpecialCase && errorCode == m_pinMapSpecialCase->GetErrorCode() )
64 continue;
65
66 if( errorCode == 0 )
67 {
68 wxStaticText* heading = new wxStaticText( scrollWin, wxID_ANY, msg );
69 wxFont headingFont = heading->GetFont();
70
71 heading->SetFont( headingFont.Bold() );
72
73 if( !firstLine )
74 {
75 gridSizer->AddSpacer( 5 ); // col 1
76 gridSizer->AddSpacer( 5 ); // col 2
77 }
78
79 gridSizer->Add( heading, 0, wxALIGN_BOTTOM | wxALL | wxEXPAND, 4 );
80 gridSizer->AddSpacer( 0 ); // col 2
81 }
82 else if( !msg.IsEmpty() ) // items with no message are for internal use only
83 {
84 wxStaticText* errorLabel = new wxStaticText( scrollWin, wxID_ANY, msg + wxT( ":" ) );
85 gridSizer->Add( errorLabel, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 15 );
86
87 // OSX can't handle more than 100 radio buttons in a single window (yes, seriously),
88 // so we have to create a window for each set
89 wxPanel* radioPanel = new wxPanel( scrollWin );
90 wxBoxSizer* radioSizer = new wxBoxSizer( wxHORIZONTAL );
91
92 for( int i = 0; i < severityCount; ++i )
93 {
94 m_buttonMap[ errorCode ][i] = new wxRadioButton( radioPanel,
95 baseID + errorCode * 10 + i,
96 severities[i],
97 wxDefaultPosition, wxDefaultSize,
98 i == 0 ? wxRB_GROUP : 0 );
99 radioSizer->Add( m_buttonMap[ errorCode ][i], 0,
100 wxRIGHT | wxALIGN_CENTER_VERTICAL, 30 );
101 }
102
103 radioPanel->SetSizer( radioSizer );
104 radioPanel->Layout();
105 gridSizer->Add( radioPanel, 0, wxALIGN_CENTER_VERTICAL );
106 }
107
108 firstLine = false;
109 }
110
111
113 {
114 wxString pinMapSeverities[] = { _( "From Pin Conflicts Map" ), wxT( "" ), _( "Ignore" ) };
115 int errorCode = m_pinMapSpecialCase->GetErrorCode();
116 wxString msg = m_pinMapSpecialCase->GetErrorText( true );
117
118 wxStaticText* errorLabel = new wxStaticText( scrollWin, wxID_ANY, msg + wxT( ":" ) );
119 gridSizer->Add( errorLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 15 );
120
121 wxPanel* radioPanel = new wxPanel( scrollWin );
122 wxBoxSizer* radioSizer = new wxBoxSizer( wxHORIZONTAL );
123
124 for( size_t i = 0; i < 3; ++i )
125 {
126 if( pinMapSeverities[i] == wxT( "" ) )
127 {
128 wxStaticText* spacer = new wxStaticText( radioPanel, wxID_ANY, wxT( "" ) );
129 radioSizer->Add( spacer, 0, wxRIGHT | wxEXPAND, 17 );
130 }
131 else
132 {
133 m_buttonMap[ errorCode ][i] = new wxRadioButton( radioPanel,
134 baseID + errorCode * 10 + i,
135 pinMapSeverities[i],
136 wxDefaultPosition, wxDefaultSize,
137 i == 0 ? wxRB_GROUP : 0 );
138 radioSizer->Add( m_buttonMap[ errorCode ][i], 0, wxEXPAND );
139 }
140 }
141
142 radioPanel->SetSizer( radioSizer );
143 radioPanel->Layout();
144 gridSizer->Add( radioPanel, 0, wxALIGN_CENTER_VERTICAL );
145 }
146
147 scrollWinSizer->Add( gridSizer, 1, wxEXPAND | wxALL, 5 );
148 panelSizer->Add( scrollWin, 1, wxEXPAND, 0 );
149
150 Bind( wxEVT_IDLE,
151 [this]( wxIdleEvent& aEvent )
152 {
154 {
155 wxWindow* dialog = wxGetTopLevelParent( this );
156 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
157
158 if( topLevelFocus == dialog )
159 checkReload();
160 }
161 } );
162
163 SetSizer( panelSizer );
164 Layout();
165 panelSizer->Fit( this );
166}
167
168
170{
171 // MUST update lastLoaded before calling IsOK (or we'll end up re-entering through the idle
172 // event until we crash the stack).
174
175 if( IsOK( m_parent, _( "The violation severities have been changed outside the Setup dialog.\n"
176 "Do you wish to reload them?" ) ) )
177 {
179 }
180}
181
182
183void PANEL_SETUP_SEVERITIES::ImportSettingsFrom( std::map<int, SEVERITY>& aSettings )
184{
185 for( const RC_ITEM& item : m_items )
186 {
187 int errorCode = item.GetErrorCode();
188
189 wxRadioButton* button = nullptr;
190
191 switch( aSettings[ errorCode ] )
192 {
193 case RPT_SEVERITY_ERROR: button = m_buttonMap[ errorCode ][0]; break;
194 case RPT_SEVERITY_WARNING: button = m_buttonMap[ errorCode ][1]; break;
195 case RPT_SEVERITY_IGNORE: button = m_buttonMap[ errorCode ][2]; break;
196 default: break;
197 }
198
199 if( button ) // this entry must actually exist
200 button->SetValue( true );
201 }
202
204 {
205 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
206 int newSeverity = aSettings[ pinMapCode ];
207
208 m_buttonMap[ pinMapCode ][0]->SetValue( newSeverity != RPT_SEVERITY_IGNORE );
209 m_buttonMap[ pinMapCode ][2]->SetValue( newSeverity == RPT_SEVERITY_IGNORE );
210 }
211}
212
213
215{
217
218 for( const RC_ITEM& item : m_items )
219 {
220 int errorCode = item.GetErrorCode();
221
222 if( !m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
223 continue;
224
225 if( m_pinMapSpecialCase && errorCode == m_pinMapSpecialCase->GetErrorCode() )
226 continue;
227
228 switch( m_severities[ errorCode ] )
229 {
230 case RPT_SEVERITY_ERROR: m_buttonMap[ errorCode ][0]->SetValue( true ); break;
231 case RPT_SEVERITY_WARNING: m_buttonMap[ errorCode ][1]->SetValue( true ); break;
232 case RPT_SEVERITY_IGNORE: m_buttonMap[ errorCode ][2]->SetValue( true ); break;
233 default: break;
234 }
235 }
236
238 {
239 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
240 int severity = m_severities[pinMapCode];
241
242 m_buttonMap[ pinMapCode ][0]->SetValue( severity != RPT_SEVERITY_IGNORE );
243 m_buttonMap[ pinMapCode ][2]->SetValue( severity == RPT_SEVERITY_IGNORE );
244 }
245
246 return true;
247}
248
249
251{
252 for( const RC_ITEM& item : m_items )
253 {
254 int errorCode = item.GetErrorCode();
255
256 if( m_pinMapSpecialCase && m_pinMapSpecialCase->GetErrorCode() == errorCode )
257 continue;
258
259 if( !m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
260 continue;
261
263
264 if( m_buttonMap[ errorCode ][0]->GetValue() )
265 severity = RPT_SEVERITY_ERROR;
266 else if( m_buttonMap[ errorCode ][1]->GetValue() )
267 severity = RPT_SEVERITY_WARNING;
268 else if( m_buttonMap[ errorCode ][2]->GetValue() )
269 severity = RPT_SEVERITY_IGNORE;
270
271 m_severities[ errorCode ] = severity;
272 }
273
275 {
276 int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
278
279 if( m_buttonMap[ pinMapCode ][0]->GetValue() )
280 severity = RPT_SEVERITY_ERROR;
281 else if( m_buttonMap[ pinMapCode ][2]->GetValue() )
282 severity = RPT_SEVERITY_IGNORE;
283
284 m_severities[ pinMapCode ] = severity;
285 }
286
287 return true;
288}
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)
Create 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:80
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
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.