2020-02-28 00:05:40 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-01-11 01:00:47 +00:00
|
|
|
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-02-28 00:05:40 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <widgets/paged_dialog.h>
|
|
|
|
#include <widgets/ui_common.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <rc_item.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/panel_setup_severities.h>
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/radiobut.h>
|
2021-06-04 17:46:07 +00:00
|
|
|
#include <wx/scrolwin.h>
|
2021-06-03 11:49:49 +00:00
|
|
|
#include <wx/stattext.h>
|
2023-05-24 15:54:16 +00:00
|
|
|
#include <wx/treebook.h>
|
2020-02-28 00:05:40 +00:00
|
|
|
|
|
|
|
|
2023-05-24 15:54:16 +00:00
|
|
|
PANEL_SETUP_SEVERITIES::PANEL_SETUP_SEVERITIES( PAGED_DIALOG* aParent,
|
2020-06-08 02:19:46 +00:00
|
|
|
std::vector<std::reference_wrapper<RC_ITEM>> aItems,
|
2020-12-14 13:33:51 +00:00
|
|
|
std::map<int, SEVERITY>& aSeverities,
|
2020-06-08 02:19:46 +00:00
|
|
|
RC_ITEM* aPinMapSpecialCase ) :
|
2023-05-24 15:54:16 +00:00
|
|
|
wxPanel( aParent->GetTreebook() ),
|
2020-03-16 11:05:01 +00:00
|
|
|
m_severities( aSeverities ),
|
2020-06-08 02:19:46 +00:00
|
|
|
m_items( aItems ),
|
2020-04-28 08:55:44 +00:00
|
|
|
m_pinMapSpecialCase( aPinMapSpecialCase )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-09-01 16:15:23 +00:00
|
|
|
wxString severities[] = { _( "Error" ), _( "Warning" ), _( "Ignore" ) };
|
2020-04-28 08:55:44 +00:00
|
|
|
int severityCount = sizeof( severities ) / sizeof( wxString );
|
2020-09-01 16:15:23 +00:00
|
|
|
int baseID = 1000;
|
|
|
|
wxBoxSizer* panelSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
wxScrolledWindow* scrollWin = new wxScrolledWindow( this, wxID_ANY,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTAB_TRAVERSAL | wxVSCROLL );
|
2021-07-09 22:37:50 +00:00
|
|
|
bool firstLine = true;
|
2020-04-28 08:55:44 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
scrollWin->SetScrollRate( 0, 5 );
|
|
|
|
|
2023-01-11 01:00:47 +00:00
|
|
|
wxBoxSizer* scrollWinSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
scrollWin->SetSizer( scrollWinSizer );
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
wxFlexGridSizer* gridSizer = new wxFlexGridSizer( 0, 2, 0, 5 );
|
|
|
|
gridSizer->SetFlexibleDirection( wxBOTH );
|
2020-12-06 18:45:05 +00:00
|
|
|
gridSizer->SetVGap( 5 );
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-09-01 16:15:23 +00:00
|
|
|
for( const RC_ITEM& item : m_items )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
int errorCode = item.GetErrorCode();
|
|
|
|
wxString msg = item.GetErrorText();
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-08-26 01:52:52 +00:00
|
|
|
if( m_pinMapSpecialCase && errorCode == m_pinMapSpecialCase->GetErrorCode() )
|
|
|
|
continue;
|
|
|
|
|
2020-12-06 18:45:05 +00:00
|
|
|
if( errorCode == 0 )
|
|
|
|
{
|
|
|
|
wxStaticText* heading = new wxStaticText( scrollWin, wxID_ANY, msg );
|
|
|
|
wxFont headingFont = heading->GetFont();
|
|
|
|
|
|
|
|
heading->SetFont( headingFont.Bold() );
|
|
|
|
|
2021-07-09 22:37:50 +00:00
|
|
|
if( !firstLine )
|
|
|
|
{
|
|
|
|
gridSizer->AddSpacer( 5 ); // col 1
|
|
|
|
gridSizer->AddSpacer( 5 ); // col 2
|
|
|
|
}
|
2020-12-06 18:45:05 +00:00
|
|
|
|
2020-12-17 00:23:31 +00:00
|
|
|
gridSizer->Add( heading, 0, wxALIGN_BOTTOM | wxALL | wxEXPAND, 4 );
|
2020-12-06 18:45:05 +00:00
|
|
|
gridSizer->AddSpacer( 0 ); // col 2
|
|
|
|
}
|
|
|
|
else if( !msg.IsEmpty() ) // items with no message are for internal use only
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
|
|
|
wxStaticText* errorLabel = new wxStaticText( scrollWin, wxID_ANY, msg + wxT( ":" ) );
|
2020-12-06 18:45:05 +00:00
|
|
|
gridSizer->Add( errorLabel, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 15 );
|
2020-02-28 00:05:40 +00:00
|
|
|
|
|
|
|
// OSX can't handle more than 100 radio buttons in a single window (yes, seriously),
|
|
|
|
// so we have to create a window for each set
|
2020-09-01 16:15:23 +00:00
|
|
|
wxPanel* radioPanel = new wxPanel( scrollWin );
|
|
|
|
wxBoxSizer* radioSizer = new wxBoxSizer( wxHORIZONTAL );
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-05-02 08:35:40 +00:00
|
|
|
for( int i = 0; i < severityCount; ++i )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
m_buttonMap[ errorCode ][i] = new wxRadioButton( radioPanel,
|
|
|
|
baseID + errorCode * 10 + i,
|
|
|
|
severities[i],
|
2020-12-06 18:45:05 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2020-03-16 11:05:01 +00:00
|
|
|
i == 0 ? wxRB_GROUP : 0 );
|
2020-12-06 18:45:05 +00:00
|
|
|
radioSizer->Add( m_buttonMap[ errorCode ][i], 0,
|
|
|
|
wxRIGHT | wxALIGN_CENTER_VERTICAL, 30 );
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
radioPanel->SetSizer( radioSizer );
|
|
|
|
radioPanel->Layout();
|
2020-12-06 18:45:05 +00:00
|
|
|
gridSizer->Add( radioPanel, 0, wxALIGN_CENTER_VERTICAL );
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
2021-07-09 22:37:50 +00:00
|
|
|
|
|
|
|
firstLine = false;
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 16:15:23 +00:00
|
|
|
|
|
|
|
if( m_pinMapSpecialCase )
|
2020-04-28 08:55:44 +00:00
|
|
|
{
|
2020-05-02 08:35:40 +00:00
|
|
|
wxString pinMapSeverities[] = { _( "From Pin Conflicts Map" ), wxT( "" ), _( "Ignore" ) };
|
2020-06-08 02:19:46 +00:00
|
|
|
int errorCode = m_pinMapSpecialCase->GetErrorCode();
|
|
|
|
wxString msg = m_pinMapSpecialCase->GetErrorText();
|
2020-04-28 08:55:44 +00:00
|
|
|
|
|
|
|
wxStaticText* errorLabel = new wxStaticText( scrollWin, wxID_ANY, msg + wxT( ":" ) );
|
2020-12-06 18:45:05 +00:00
|
|
|
gridSizer->Add( errorLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 15 );
|
2020-04-28 08:55:44 +00:00
|
|
|
|
|
|
|
wxPanel* radioPanel = new wxPanel( scrollWin );
|
|
|
|
wxBoxSizer* radioSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < 3; ++i )
|
|
|
|
{
|
|
|
|
if( pinMapSeverities[i] == wxT( "" ) )
|
|
|
|
{
|
|
|
|
wxStaticText* spacer = new wxStaticText( radioPanel, wxID_ANY, wxT( "" ) );
|
|
|
|
radioSizer->Add( spacer, 0, wxRIGHT | wxEXPAND, 17 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_buttonMap[ errorCode ][i] = new wxRadioButton( radioPanel,
|
|
|
|
baseID + errorCode * 10 + i,
|
|
|
|
pinMapSeverities[i],
|
2020-12-06 18:45:05 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2020-04-28 08:55:44 +00:00
|
|
|
i == 0 ? wxRB_GROUP : 0 );
|
2021-02-13 08:08:50 +00:00
|
|
|
radioSizer->Add( m_buttonMap[ errorCode ][i], 0, wxEXPAND );
|
2020-04-28 08:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
radioPanel->SetSizer( radioSizer );
|
|
|
|
radioPanel->Layout();
|
2020-12-06 18:45:05 +00:00
|
|
|
gridSizer->Add( radioPanel, 0, wxALIGN_CENTER_VERTICAL );
|
2020-04-28 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 01:00:47 +00:00
|
|
|
scrollWinSizer->Add( gridSizer, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
panelSizer->Add( scrollWin, 1, wxEXPAND, 0 );
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2021-02-09 16:35:43 +00:00
|
|
|
SetSizer( panelSizer );
|
|
|
|
Layout();
|
2020-09-01 16:15:23 +00:00
|
|
|
panelSizer->Fit( this );
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-14 13:33:51 +00:00
|
|
|
void PANEL_SETUP_SEVERITIES::ImportSettingsFrom( std::map<int, SEVERITY>& aSettings )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
for( const RC_ITEM& item : m_items )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
int errorCode = item.GetErrorCode();
|
|
|
|
|
2020-03-18 08:17:43 +00:00
|
|
|
if(! m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
|
|
|
|
continue;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
switch( aSettings[ errorCode ] )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
case RPT_SEVERITY_ERROR: m_buttonMap[ errorCode ][0]->SetValue( true ); break;
|
|
|
|
case RPT_SEVERITY_WARNING: m_buttonMap[ errorCode ][1]->SetValue( true ); break;
|
|
|
|
case RPT_SEVERITY_IGNORE: m_buttonMap[ errorCode ][2]->SetValue( true ); break;
|
|
|
|
default: break;
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-28 08:55:44 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
if( m_pinMapSpecialCase )
|
2020-04-28 08:55:44 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
|
|
|
|
int newSeverity = aSettings[ pinMapCode ];
|
2020-04-28 08:55:44 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_buttonMap[ pinMapCode ][0]->SetValue( newSeverity != RPT_SEVERITY_IGNORE );
|
2021-09-04 16:20:36 +00:00
|
|
|
m_buttonMap[ pinMapCode ][2]->SetValue( newSeverity == RPT_SEVERITY_IGNORE );
|
2020-04-28 08:55:44 +00:00
|
|
|
}
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
bool PANEL_SETUP_SEVERITIES::TransferDataToWindow()
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
for( const RC_ITEM& item : m_items )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
int errorCode = item.GetErrorCode();
|
|
|
|
|
2020-04-28 08:55:44 +00:00
|
|
|
if( !m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
|
2020-03-18 08:17:43 +00:00
|
|
|
continue;
|
|
|
|
|
2020-08-27 15:25:18 +00:00
|
|
|
if( m_pinMapSpecialCase && errorCode == m_pinMapSpecialCase->GetErrorCode() )
|
|
|
|
continue;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
switch( m_severities[ errorCode ] )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
case RPT_SEVERITY_ERROR: m_buttonMap[ errorCode ][0]->SetValue( true ); break;
|
|
|
|
case RPT_SEVERITY_WARNING: m_buttonMap[ errorCode ][1]->SetValue( true ); break;
|
|
|
|
case RPT_SEVERITY_IGNORE: m_buttonMap[ errorCode ][2]->SetValue( true ); break;
|
|
|
|
default: break;
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
if( m_pinMapSpecialCase )
|
2020-04-28 08:55:44 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
|
|
|
|
int severity = m_severities[pinMapCode];
|
2020-04-28 08:55:44 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_buttonMap[ pinMapCode ][0]->SetValue( severity != RPT_SEVERITY_IGNORE );
|
|
|
|
m_buttonMap[ pinMapCode ][2]->SetValue( severity == RPT_SEVERITY_IGNORE );
|
2020-04-28 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
bool PANEL_SETUP_SEVERITIES::TransferDataFromWindow()
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
for( const RC_ITEM& item : m_items )
|
2020-02-28 00:05:40 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
int errorCode = item.GetErrorCode();
|
|
|
|
|
2020-10-25 19:37:29 +00:00
|
|
|
if( m_pinMapSpecialCase && m_pinMapSpecialCase->GetErrorCode() == errorCode )
|
|
|
|
continue;
|
|
|
|
|
2020-04-28 08:55:44 +00:00
|
|
|
if( !m_buttonMap[ errorCode ][0] ) // this entry does not actually exist
|
2020-03-18 08:17:43 +00:00
|
|
|
continue;
|
|
|
|
|
2020-12-14 13:33:51 +00:00
|
|
|
SEVERITY severity = RPT_SEVERITY_UNDEFINED;
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-04-28 08:55:44 +00:00
|
|
|
if( m_buttonMap[ errorCode ][0]->GetValue() )
|
2020-03-04 09:48:18 +00:00
|
|
|
severity = RPT_SEVERITY_ERROR;
|
2020-04-28 08:55:44 +00:00
|
|
|
else if( m_buttonMap[ errorCode ][1]->GetValue() )
|
2020-03-04 09:48:18 +00:00
|
|
|
severity = RPT_SEVERITY_WARNING;
|
2020-04-28 08:55:44 +00:00
|
|
|
else if( m_buttonMap[ errorCode ][2]->GetValue() )
|
|
|
|
severity = RPT_SEVERITY_IGNORE;
|
|
|
|
|
|
|
|
m_severities[ errorCode ] = severity;
|
|
|
|
}
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
if( m_pinMapSpecialCase )
|
2020-04-28 08:55:44 +00:00
|
|
|
{
|
2020-12-14 13:33:51 +00:00
|
|
|
int pinMapCode = m_pinMapSpecialCase->GetErrorCode();
|
|
|
|
SEVERITY severity = RPT_SEVERITY_UNDEFINED;
|
2020-04-28 08:55:44 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
if( m_buttonMap[ pinMapCode ][0]->GetValue() )
|
2020-04-28 08:55:44 +00:00
|
|
|
severity = RPT_SEVERITY_ERROR;
|
2020-06-08 02:19:46 +00:00
|
|
|
else if( m_buttonMap[ pinMapCode ][2]->GetValue() )
|
2020-03-04 09:48:18 +00:00
|
|
|
severity = RPT_SEVERITY_IGNORE;
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_severities[ pinMapCode ] = severity;
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|