From 6b145b28302613cae6772d963eb0586219a04da6 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 4 May 2024 15:27:52 +0000 Subject: [PATCH] Add optional reporting of non-KiCad design issues Also add HTML reporter to PCB side to match schematic (cherry picked from commit b8fa10ab2b3685309639e14ad1cd6e37a6b497dd) Co-authored-by: Jon Evans --- common/settings/app_settings.cpp | 3 ++ eeschema/files-io.cpp | 12 ++++- include/settings/app_settings.h | 2 + include/widgets/filedlg_import_non_kicad.h | 55 ++++++++++++++++++++++ pcbnew/files.cpp | 28 ++++++++++- pcbnew/pcb_io/altium/altium_pcb.cpp | 32 +++++++++---- 6 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 include/widgets/filedlg_import_non_kicad.h diff --git a/common/settings/app_settings.cpp b/common/settings/app_settings.cpp index 533cbef62a..2da2474baf 100644 --- a/common/settings/app_settings.cpp +++ b/common/settings/app_settings.cpp @@ -160,6 +160,9 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaV m_params.emplace_back( new PARAM( "system.last_imperial_units", &m_System.last_imperial_units, static_cast( EDA_UNITS::MILS ) ) ); + m_params.emplace_back( new PARAM( "system.show_import_issues", + &m_System.show_import_issues, true ) ); + m_params.emplace_back( new PARAM( "appearance.color_theme", &m_ColorTheme, COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT ) ); diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 0b20a85da2..6e2f1a87ef 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -734,9 +735,14 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent ) wxFileDialog dlg( this, _( "Import Schematic" ), path, wxEmptyString, fileFiltersStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); // TODO + FILEDLG_IMPORT_NON_KICAD importOptions( eeconfig()->m_System.show_import_issues ); + dlg.SetCustomizeHook( importOptions ); + if( dlg.ShowModal() == wxID_CANCEL ) return; + eeconfig()->m_System.show_import_issues = importOptions.GetShowIssues(); + // Don't leave dangling pointers to previously-opened document. m_toolManager->GetTool()->ClearSelection(); ClearUndoRedoList(); @@ -1396,7 +1402,11 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType, std::placeholders::_1 ) ); } - pi->SetReporter( errorReporter.m_Reporter ); + if( eeconfig()->m_System.show_import_issues ) + pi->SetReporter( errorReporter.m_Reporter ); + else + pi->SetReporter( &NULL_REPORTER::GetInstance() ); + pi->SetProgressReporter( &progressReporter ); SCH_SHEET* loadedSheet = diff --git a/include/settings/app_settings.h b/include/settings/app_settings.h index 2c63f847f8..5637c4991d 100644 --- a/include/settings/app_settings.h +++ b/include/settings/app_settings.h @@ -142,6 +142,8 @@ public: int units; int last_metric_units; int last_imperial_units; + /// Stored value for "show import issues" when importing non-KiCad designs to this application + bool show_import_issues; }; APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion ); diff --git a/include/widgets/filedlg_import_non_kicad.h b/include/widgets/filedlg_import_non_kicad.h new file mode 100644 index 0000000000..01311f9567 --- /dev/null +++ b/include/widgets/filedlg_import_non_kicad.h @@ -0,0 +1,55 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 3 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, see . + */ + +#ifndef KICAD_FILEDLG_IMPORT_NON_KICAD_H +#define KICAD_FILEDLG_IMPORT_NON_KICAD_H + +#include +#include + + +class FILEDLG_IMPORT_NON_KICAD : public wxFileDialogCustomizeHook +{ +public: + FILEDLG_IMPORT_NON_KICAD( bool aDefaultShowIssues = true ) : + m_showIssues( aDefaultShowIssues ) + {}; + + virtual void AddCustomControls( wxFileDialogCustomize& customizer ) override + { + m_cb = customizer.AddCheckBox( _( "Show import issues" ) ); + m_cb->SetValue( m_showIssues ); + } + + virtual void TransferDataFromCustomControls() override + { + m_showIssues = m_cb->GetValue(); + } + + bool GetShowIssues() const { return m_showIssues; } + +private: + bool m_showIssues; + + wxFileDialogCheckBox* m_cb = nullptr; + + wxDECLARE_NO_COPY_CLASS( FILEDLG_IMPORT_NON_KICAD ); +}; + +#endif //KICAD_FILEDLG_IMPORT_NON_KICAD_H diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 5c39412540..9a0ef47f72 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,8 @@ #include "footprint_info_impl.h" #include #include +#include +#include #include // For ::ResolvePossibleSymlinks() #include @@ -170,15 +173,25 @@ bool AskLoadBoardFileName( PCB_EDIT_FRAME* aParent, wxString* aFileName, int aCt // leave name empty } + bool kicadFormat = ( aCtl & KICTL_KICAD_ONLY ); + wxFileDialog dlg( aParent, - ( aCtl & KICTL_KICAD_ONLY ) ? _( "Open Board File" ) - : _( "Import Non KiCad Board File" ), + kicadFormat ? _( "Open Board File" ) : _( "Import Non KiCad Board File" ), path, name, fileFiltersStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); + FILEDLG_IMPORT_NON_KICAD importOptions( aParent->config()->m_System.show_import_issues ); + + if( !kicadFormat ) + dlg.SetCustomizeHook( importOptions ); + if( dlg.ShowModal() == wxID_OK ) { *aFileName = dlg.GetPath(); aParent->SetMruPath( wxFileName( dlg.GetPath() ).GetPath() ); + + if( !kicadFormat ) + aParent->config()->m_System.show_import_issues = importOptions.GetShowIssues(); + return true; } else @@ -646,6 +659,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in CheckForAutoSaveFile( fullFileName ); } + DIALOG_HTML_REPORTER errorReporter( this ); bool failedLoad = false; try @@ -682,6 +696,10 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // measure the time to load a BOARD. int64_t startTime = GetRunningMicroSecs(); #endif + if( config()->m_System.show_import_issues ) + pi->SetReporter( errorReporter.m_Reporter ); + else + pi->SetReporter( &NULL_REPORTER::GetInstance() ); pi->SetProgressReporter( &progressReporter ); loadedBoard = pi->LoadBoard( fullFileName, nullptr, &props, &Prj() ); @@ -732,6 +750,12 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // compiled. Raise(); + if( errorReporter.m_Reporter->HasMessage() ) + { + errorReporter.m_Reporter->Flush(); // Build HTML messages + errorReporter.ShowModal(); + } + // Skip (possibly expensive) connectivity build here; we build it below after load SetBoard( loadedBoard, false, &progressReporter ); diff --git a/pcbnew/pcb_io/altium/altium_pcb.cpp b/pcbnew/pcb_io/altium/altium_pcb.cpp index 469f5ad65d..b363602f5b 100644 --- a/pcbnew/pcb_io/altium/altium_pcb.cpp +++ b/pcbnew/pcb_io/altium/altium_pcb.cpp @@ -253,9 +253,13 @@ std::vector ALTIUM_PCB::GetKicadLayersToIterate( ALTIUM_LAYER aAlt if( klayer == UNDEFINED_LAYER ) { - wxLogWarning( _( "Altium layer (%d) has no KiCad equivalent. It has been moved to KiCad " - "layer Eco1_User." ), - aAltiumLayer ); + if( m_reporter ) + { + m_reporter->Report( wxString::Format( + _( "Altium layer (%d) has no KiCad equivalent. It has been moved to KiCad " + "layer Eco1_User." ), aAltiumLayer ), RPT_SEVERITY_INFO ); + } + klayer = Eco1_User; } @@ -1292,9 +1296,14 @@ void ALTIUM_PCB::HelperParseDimensions6Linear( const ADIMENSION6& aElem ) if( klayer == UNDEFINED_LAYER ) { - wxLogWarning( _( "Dimension found on an Altium layer (%d) with no KiCad equivalent. " - "It has been moved to KiCad layer Eco1_User." ), - aElem.layer ); + if( m_reporter ) + { + m_reporter->Report( wxString::Format( + _( "Dimension found on an Altium layer (%d) with no KiCad equivalent. " + "It has been moved to KiCad layer Eco1_User." ), aElem.layer ), + RPT_SEVERITY_INFO ); + } + klayer = Eco1_User; } @@ -1394,9 +1403,14 @@ void ALTIUM_PCB::HelperParseDimensions6Radial(const ADIMENSION6 &aElem) if( klayer == UNDEFINED_LAYER ) { - wxLogWarning( _( "Dimension found on an Altium layer (%d) with no KiCad equivalent. " - "It has been moved to KiCad layer Eco1_User." ), - aElem.layer ); + if( m_reporter ) + { + m_reporter->Report( wxString::Format( + _( "Dimension found on an Altium layer (%d) with no KiCad equivalent. " + "It has been moved to KiCad layer Eco1_User." ), + aElem.layer ), RPT_SEVERITY_INFO ); + } + klayer = Eco1_User; }