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