From 2ad69fc56b949c0ac817b8c55551971fa3dfe012 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 31 Mar 2021 22:33:30 +0100 Subject: [PATCH] Move importers from wxLog to REPORTER. Fixes https://gitlab.com/kicad/code/kicad/issues/6389 --- common/reporter.cpp | 46 ++++-- eeschema/files-io.cpp | 18 ++- eeschema/sch_io_mgr.cpp | 44 ++---- eeschema/sch_io_mgr.h | 6 + .../sch_plugins/altium/sch_altium_plugin.cpp | 88 +++++++---- .../sch_plugins/altium/sch_altium_plugin.h | 4 + .../cadstar/cadstar_sch_archive_loader.cpp | 144 ++++++++++-------- .../cadstar/cadstar_sch_archive_loader.h | 4 +- .../cadstar/cadstar_sch_archive_plugin.cpp | 2 +- .../cadstar/cadstar_sch_archive_plugin.h | 7 + .../sch_plugins/eagle/sch_eagle_plugin.cpp | 15 +- eeschema/sch_plugins/eagle/sch_eagle_plugin.h | 30 ++-- include/reporter.h | 22 ++- 13 files changed, 268 insertions(+), 162 deletions(-) diff --git a/common/reporter.cpp b/common/reporter.cpp index 86fc52f82e..c116572986 100644 --- a/common/reporter.cpp +++ b/common/reporter.cpp @@ -113,20 +113,20 @@ REPORTER& NULL_REPORTER::GetInstance() } -REPORTER& STDOUT_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) +REPORTER& STDOUT_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity ) { switch( aSeverity ) { - case RPT_SEVERITY_UNDEFINED: std::cout << "SEVERITY_UNDEFINED: "; break; - case RPT_SEVERITY_INFO: std::cout << "SEVERITY_INFO: "; break; - case RPT_SEVERITY_WARNING: std::cout << "SEVERITY_WARNING: "; break; - case RPT_SEVERITY_ERROR: std::cout << "SEVERITY_ERROR: "; break; - case RPT_SEVERITY_ACTION: std::cout << "SEVERITY_ACTION: "; break; - case RPT_SEVERITY_EXCLUSION: - case RPT_SEVERITY_IGNORE: break; + case RPT_SEVERITY_UNDEFINED: std::cout << "SEVERITY_UNDEFINED: "; break; + case RPT_SEVERITY_INFO: std::cout << "SEVERITY_INFO: "; break; + case RPT_SEVERITY_WARNING: std::cout << "SEVERITY_WARNING: "; break; + case RPT_SEVERITY_ERROR: std::cout << "SEVERITY_ERROR: "; break; + case RPT_SEVERITY_ACTION: std::cout << "SEVERITY_ACTION: "; break; + case RPT_SEVERITY_EXCLUSION: + case RPT_SEVERITY_IGNORE: break; } - std::cout << aText << std::endl; + std::cout << aMsg << std::endl; return *this; } @@ -143,6 +143,34 @@ REPORTER& STDOUT_REPORTER::GetInstance() } +REPORTER& WXLOG_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity ) +{ + switch( aSeverity ) + { + case RPT_SEVERITY_ERROR: wxLogError( aMsg ); break; + case RPT_SEVERITY_WARNING: wxLogWarning( aMsg ); break; + case RPT_SEVERITY_UNDEFINED: wxLogMessage( aMsg ); break; + case RPT_SEVERITY_INFO: wxLogInfo( aMsg ); break; + case RPT_SEVERITY_ACTION: wxLogInfo( aMsg ); break; + case RPT_SEVERITY_EXCLUSION: break; + case RPT_SEVERITY_IGNORE: break; + } + + return *this; +} + + +REPORTER& WXLOG_REPORTER::GetInstance() +{ + static REPORTER* s_wxLogReporter = nullptr; + + if( !s_wxLogReporter ) + s_wxLogReporter = new WXLOG_REPORTER(); + + return *s_wxLogReporter; +} + + REPORTER& STATUSBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) { if( m_statusBar ) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index ae60b7f890..6f9e62b604 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include #include @@ -930,8 +932,8 @@ bool SCH_EDIT_FRAME::doAutoSave() bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) { - wxFileName newfilename; - SCH_SHEET_LIST sheetList = Schematic().GetSheets(); + wxFileName newfilename; + SCH_SHEET_LIST sheetList = Schematic().GetSheets(); SCH_IO_MGR::SCH_FILE_T fileType = (SCH_IO_MGR::SCH_FILE_T) aFileType; switch( fileType ) @@ -953,10 +955,18 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) try { - SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( - SCH_IO_MGR::FindPlugin( (SCH_IO_MGR::SCH_FILE_T) aFileType ) ); + SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); + DIALOG_HTML_REPORTER* reporter = new DIALOG_HTML_REPORTER( this ); + + pi->SetReporter( reporter->m_Reporter ); Schematic().SetRoot( pi->Load( aFileName, &Schematic() ) ); + if( reporter->m_Reporter->HasMessage() ) + reporter->ShowModal(); + + pi->SetReporter( &WXLOG_REPORTER::GetInstance() ); + delete reporter; + // Non-KiCad schematics do not use a drawing-sheet (or if they do, it works differently // to KiCad), so set it to an empty one DS_DATA_MODEL& drawingSheet = DS_DATA_MODEL::GetTheInstance(); diff --git a/eeschema/sch_io_mgr.cpp b/eeschema/sch_io_mgr.cpp index e32846ca4a..7b1a53206e 100644 --- a/eeschema/sch_io_mgr.cpp +++ b/eeschema/sch_io_mgr.cpp @@ -56,21 +56,13 @@ SCH_PLUGIN* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType ) switch( aFileType ) { - case SCH_LEGACY: - return new SCH_LEGACY_PLUGIN(); - case SCH_KICAD: - return new SCH_SEXPR_PLUGIN(); - case SCH_ALTIUM: - return new SCH_ALTIUM_PLUGIN(); - case SCH_CADSTAR_ARCHIVE: - return new CADSTAR_SCH_ARCHIVE_PLUGIN(); - case SCH_EAGLE: - return new SCH_EAGLE_PLUGIN(); - default: - ; + case SCH_LEGACY: return new SCH_LEGACY_PLUGIN(); + case SCH_KICAD: return new SCH_SEXPR_PLUGIN(); + case SCH_ALTIUM: return new SCH_ALTIUM_PLUGIN(); + case SCH_CADSTAR_ARCHIVE: return new CADSTAR_SCH_ARCHIVE_PLUGIN(); + case SCH_EAGLE: return new SCH_EAGLE_PLUGIN(); + default: return nullptr; } - - return NULL; } @@ -92,23 +84,13 @@ const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType ) switch( aType ) { - default: - return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ), aType ); - - case SCH_LEGACY: - return wxString( wxT( "Legacy" ) ); - - case SCH_KICAD: - return wxString( wxT( "KiCad" ) ); - - case SCH_ALTIUM: - return wxString( wxT( "Altium" ) ); - - case SCH_CADSTAR_ARCHIVE: - return wxString( wxT( "CADSTAR Schematic Archive" ) ); - - case SCH_EAGLE: - return wxString( wxT( "EAGLE" ) ); + case SCH_LEGACY: return wxString( wxT( "Legacy" ) ); + case SCH_KICAD: return wxString( wxT( "KiCad" ) ); + case SCH_ALTIUM: return wxString( wxT( "Altium" ) ); + case SCH_CADSTAR_ARCHIVE: return wxString( wxT( "CADSTAR Schematic Archive" ) ); + case SCH_EAGLE: return wxString( wxT( "EAGLE" ) ); + default: return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ), + aType ); } } diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index 0f0cce59e8..8d9516286b 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -27,6 +27,7 @@ #include #include #include +#include class SCH_SHEET; @@ -158,6 +159,11 @@ public: */ virtual const wxString GetName() const = 0; + /** + * Set an optional reporter for warnings/errors. + */ + virtual void SetReporter( REPORTER* aReporter ) {} + /** * Return the file extension for the #SCH_PLUGIN. */ diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index e0be2bb662..01a7512cb4 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -80,6 +80,8 @@ SCH_ALTIUM_PLUGIN::SCH_ALTIUM_PLUGIN() m_rootSheet = nullptr; m_currentSheet = nullptr; m_schematic = nullptr; + + m_reporter = &WXLOG_REPORTER::GetInstance(); } @@ -241,7 +243,8 @@ void SCH_ALTIUM_PLUGIN::ParseAltiumSch( const wxString& aFileName ) if( fp == nullptr ) { - wxLogError( wxString::Format( _( "Cannot open file '%s'" ), aFileName ) ); + m_reporter->Report( wxString::Format( _( "Cannot open file '%s'." ), aFileName ), + RPT_SEVERITY_ERROR ); return; } @@ -434,7 +437,8 @@ void SCH_ALTIUM_PLUGIN::Parse( const CFB::CompoundFileReader& aReader ) case ALTIUM_SCH_RECORD::RECORD_226: break; default: - wxLogError( wxString::Format( "Unknown Record id: %d", recordId ) ); + m_reporter->Report( wxString::Format( _( "Unknown Record id: %d." ), recordId ), + RPT_SEVERITY_ERROR ); break; } } @@ -532,8 +536,9 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map& aPropertie if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Pin has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Pin has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -572,7 +577,7 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map& aPropertie pinLocation.y += elem.pinlength; break; default: - wxLogWarning( "Pin has unexpected orientation" ); + m_reporter->Report( _( "Pin has unexpected orientation." ), RPT_SEVERITY_WARNING ); break; } @@ -610,15 +615,15 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map& aPropertie case ASCH_PIN_ELECTRICAL::UNKNOWN: default: pin->SetType( ELECTRICAL_PINTYPE::PT_UNSPECIFIED ); - wxLogWarning( "Pin has unexpected electrical type" ); + m_reporter->Report( _( "Pin has unexpected electrical type." ), RPT_SEVERITY_WARNING ); break; } if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::UNKNOWN ) - wxLogWarning( "Pin has unexpected outer edge type" ); + m_reporter->Report( _( "Pin has unexpected outer edge type." ), RPT_SEVERITY_WARNING ); if( elem.symbolInnerEdge == ASCH_PIN_SYMBOL_INNEREDGE::UNKNOWN ) - wxLogWarning( "Pin has unexpected inner edge type" ); + m_reporter->Report( _( "Pin has unexpected inner edge type." ), RPT_SEVERITY_WARNING ); if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::NEGATED ) { @@ -740,8 +745,9 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map& aPropert if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Label has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Label has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -775,8 +781,10 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper if( elem.points.size() < 2 ) { - wxLogWarning( wxString::Format( "Bezier has %d control points. At least 2 are expected.", - static_cast( elem.points.size() ) ) ); + m_reporter->Report( wxString::Format( _( "Bezier has %d control points. At least 2 are " + "expected." ), + static_cast( elem.points.size() ) ), + RPT_SEVERITY_WARNING ); return; } @@ -831,8 +839,9 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Bezier has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Bezier has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -915,8 +924,9 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map& aProp if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Polyline has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Polyline has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -976,8 +986,9 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map& aPrope if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Polygon has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Polygon has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -1057,8 +1068,10 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map& if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Rounded Rectangle has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Rounded rectangle has non-existent " + "ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -1093,7 +1106,8 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map& aPropertie if( elem.ownerpartid == ALTIUM_COMPONENT_NONE ) { - wxLogError( "Arc drawing is not possible for now on schematic." ); + m_reporter->Report( _( "Arc drawing is not possible for now on schematic." ), + RPT_SEVERITY_ERROR ); } else { @@ -1101,8 +1115,9 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map& aPropertie if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Arc has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Arc has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -1161,8 +1176,9 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map& aProperti if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Line has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Line has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -1232,8 +1248,9 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map& aPro if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Rectangle has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Rectangle has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } @@ -1351,7 +1368,8 @@ void SCH_ALTIUM_PLUGIN::ParseSheetEntry( const std::map& aPr } -wxPoint HelperGeneratePowerPortGraphics( LIB_PART* aKPart, ASCH_POWER_PORT_STYLE aStyle ) +wxPoint HelperGeneratePowerPortGraphics( LIB_PART* aKPart, ASCH_POWER_PORT_STYLE aStyle, + REPORTER* aReporter ) { if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE || aStyle == ASCH_POWER_PORT_STYLE::ARROW ) { @@ -1534,7 +1552,10 @@ wxPoint HelperGeneratePowerPortGraphics( LIB_PART* aKPart, ASCH_POWER_PORT_STYLE else { if( aStyle != ASCH_POWER_PORT_STYLE::BAR ) - wxLogWarning( "Power Port has unknown style, use bar instead. " ); + { + aReporter->Report( _( "Power Port has unknown style, use bar instead." ), + RPT_SEVERITY_WARNING ); + } LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart ); aKPart->AddDrawItem( line1 ); @@ -1591,7 +1612,7 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map& aPro pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN ); pin->SetVisible( false ); - wxPoint valueFieldPos = HelperGeneratePowerPortGraphics( kpart, elem.style ); + wxPoint valueFieldPos = HelperGeneratePowerPortGraphics( kpart, elem.style, m_reporter ); kpart->GetValueField().SetPosition( valueFieldPos ); @@ -1641,7 +1662,7 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map& aPro valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER ); break; default: - wxLogWarning( "Pin has unexpected orientation" ); + m_reporter->Report( _( "Pin has unexpected orientation." ), RPT_SEVERITY_WARNING ); break; } @@ -2012,8 +2033,9 @@ void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map& aPr if( symbol == m_symbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 - wxLogWarning( wxString::Format( "Designator has non-existent ownerindex %d", - elem.ownerindex ) ); + m_reporter->Report( wxString::Format( _( "Designator has non-existent ownerindex %d." ), + elem.ownerindex ), + RPT_SEVERITY_WARNING ); return; } diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index d287fcfe4c..7e70417b80 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -55,6 +55,8 @@ public: const wxString GetName() const override; + void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; } + const wxString GetFileExtension() const override; const wxString GetLibraryFileExtension() const override; @@ -134,6 +136,8 @@ private: void ParseParameter( const std::map& aProperties ); private: + REPORTER* m_reporter; // current reporter for warnings/errors + SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded.. SCH_SHEET* m_currentSheet; // The current sheet of the schematic being loaded.. SCHEMATIC* m_schematic; // Passed to Load(), the schematic object being loaded diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 4b8871e0b1..2a354990cd 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -99,24 +99,26 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSh if( Schematic.VariantHierarchy.Variants.size() > 0 ) { - wxLogWarning( wxString::Format( - _( "The CADSTAR design contains variants which has no KiCad equivalent. Only " - "the master variant ('%s') was loaded." ), - Schematic.VariantHierarchy.Variants.at( "V0" ).Name ) ); + m_reporter->Report( wxString::Format( _( "The CADSTAR design contains variants which has " + "no KiCad equivalent. Only the master variant " + "('%s') was loaded." ), + Schematic.VariantHierarchy.Variants.at( "V0" ).Name ), + RPT_SEVERITY_WARNING ); } if( Schematic.Groups.size() > 0 ) { - wxLogWarning( - _( "The CADSTAR design contains grouped items which has no KiCad equivalent. Any " - "grouped items have been ungrouped." ) ); + m_reporter->Report( _( "The CADSTAR design contains grouped items which has no KiCad " + "equivalent. Any grouped items have been ungrouped." ), + RPT_SEVERITY_WARNING ); } if( Schematic.ReuseBlocks.size() > 0 ) { - wxLogWarning( - _( "The CADSTAR design contains re-use blocks which has no KiCad equivalent. The " - "re-use block information has been discarded during the import." ) ); + m_reporter->Report( _( "The CADSTAR design contains re-use blocks which has no KiCad " + "equivalent. The re-use block information has been discarded during " + "the import." ), + RPT_SEVERITY_WARNING ); } @@ -216,9 +218,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSh } } - wxLogMessage( - _( "The CADSTAR design has been imported successfully.\n" - "Please review the import errors and warnings (if any)." ) ); + m_reporter->Report( _( "The CADSTAR design has been imported successfully.\n" + "Please review the import errors and warnings (if any)." ) ); } @@ -348,11 +349,14 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadPartsLibrary() if( symbolID.IsEmpty() ) { - wxLogWarning( wxString::Format( - _( "Part definition '%s' references symbol '%s' (alternate '%s') " - "which could not be found in the symbol library. The part has not " - "been loaded into the KiCad library." ), - part.Name, gate.Name, gate.Alternate ) ); + m_reporter->Report( wxString::Format( _( "Part definition '%s' references symbol " + "'%s' (alternate '%s') which could not be " + "found in the symbol library. The part has " + "not been loaded into the KiCad library." ), + part.Name, + gate.Name, + gate.Alternate ), + RPT_SEVERITY_WARNING); ok = false; break; @@ -393,10 +397,12 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances() { if( m_partMap.find( sym.PartRef.RefID ) == m_partMap.end() ) { - wxLogError( wxString::Format( - _( "Symbol '%s' references part '%s' which could not be found " - "in the library. The symbol was not loaded" ), - sym.ComponentRef.Designator, sym.PartRef.RefID ) ); + m_reporter->Report( wxString::Format( _( "Symbol '%s' references part '%s' which " + "could not be found in the library. The " + "symbol was not loaded" ), + sym.ComponentRef.Designator, + sym.PartRef.RefID ), + RPT_SEVERITY_ERROR); continue; } @@ -617,10 +623,11 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances() } else { - wxLogError( wxString::Format( - _( "Symbol ID '%s' is of an unknown type. It is neither a component or a " - "net power / symbol. The symbol was not loaded." ), - sym.ID ) ); + m_reporter->Report( wxString::Format( _( "Symbol ID '%s' is of an unknown type. It is " + "neither a component or a net power / symbol. " + "The symbol was not loaded." ), + sym.ID ), + RPT_SEVERITY_ERROR ); } if( sym.ScaleRatioDenominator != 1 || sym.ScaleRatioNumerator != 1 ) @@ -630,11 +637,13 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances() if( symbolName.empty() ) symbolName = wxString::Format( "ID: %s", sym.ID); - wxLogError( wxString::Format( - _( "Symbol '%s' is scaled in the original CADSTAR schematic but this is not" - " supported in KiCad. The symbol was loaded with 1:1 scale and may require " - "manual fixing." ), - symbolName, sym.PartRef.RefID ) ); + m_reporter->Report( wxString::Format( _( "Symbol '%s' is scaled in the original " + "CADSTAR schematic but this is not supported " + "in KiCad. The symbol was loaded with 1:1 " + "scale and may require manual fixing." ), + symbolName, + sym.PartRef.RefID ), + RPT_SEVERITY_ERROR ); } } } @@ -1057,11 +1066,12 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadDocumentationSymbols() if( Library.SymbolDefinitions.find( docSym.SymdefID ) == Library.SymbolDefinitions.end() ) { - wxLogError( - wxString::Format( _( "Documentation Symbol '%s' refers to symbol definition " - "ID '%s' which does not exist in the library. The symbol " - "was not loaded." ), - docSym.ID, docSym.SymdefID ) ); + m_reporter->Report( wxString::Format( _( "Documentation Symbol '%s' refers to symbol " + "definition ID '%s' which does not exist in " + "the library. The symbol was not loaded." ), + docSym.ID, + docSym.SymdefID ), + RPT_SEVERITY_ERROR ); continue; } @@ -1163,7 +1173,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadTextVariables() } else { - wxLogError( _( "Text Variables could not be set as there is no project attached." ) ); + m_reporter->Report( _( "Text Variables could not be set as there is no project attached." ), + RPT_SEVERITY_ERROR ); } } @@ -1560,22 +1571,26 @@ SCH_COMPONENT* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol( if( NormalizeAngle180( compAngleDeciDeg ) != NormalizeAngle180( aComponentOrientationDeciDeg ) ) { - wxLogError( - wxString::Format( _( "Symbol '%s' is rotated by an angle of %.1f degrees in the " - "original CADSTAR design but KiCad only supports rotation " - "angles multiples of 90 degrees. The connecting wires will " - "need manual fixing." ), - aCadstarSymbol.ComponentRef.Designator, compAngleDeciDeg / 10.0 ) ); + m_reporter->Report( wxString::Format( _( "Symbol '%s' is rotated by an angle of %.1f " + "degrees in the original CADSTAR design but " + "KiCad only supports rotation angles multiples " + "of 90 degrees. The connecting wires will need " + "manual fixing." ), + aCadstarSymbol.ComponentRef.Designator, + compAngleDeciDeg / 10.0 ), + RPT_SEVERITY_ERROR); } component->SetOrientation( compOrientation ); if( m_sheetMap.find( aCadstarSymbol.LayerID ) == m_sheetMap.end() ) { - wxLogError( - wxString::Format( _( "Symbol '%s' references sheet ID '%s' which does not exist in " - "the design. The symbol was not loaded." ), - aCadstarSymbol.ComponentRef.Designator, aCadstarSymbol.LayerID ) ); + m_reporter->Report( wxString::Format( _( "Symbol '%s' references sheet ID '%s' which does " + "not exist in the design. The symbol was not " + "loaded." ), + aCadstarSymbol.ComponentRef.Designator, + aCadstarSymbol.LayerID ), + RPT_SEVERITY_ERROR ); delete component; return nullptr; @@ -1656,7 +1671,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolFieldAttribute( case ALIGNMENT::CENTERLEFT: fieldAlignment = ALIGNMENT::CENTERRIGHT; break; case ALIGNMENT::TOPLEFT: fieldAlignment = ALIGNMENT::TOPRIGHT; break; //Change right to left: - case ALIGNMENT::BOTTOMRIGHT: fieldAlignment = ALIGNMENT::BOTTOMLEFT; break; + case ALIGNMENT::BOTTOMRIGHT: fieldAlignment = ALIGNMENT::BOTTOMLEFT; break; case ALIGNMENT::CENTERRIGHT: fieldAlignment = ALIGNMENT::CENTERLEFT; break; case ALIGNMENT::TOPRIGHT: fieldAlignment = ALIGNMENT::TOPLEFT; break; // Center alignment does not mirror: @@ -1718,10 +1733,12 @@ CADSTAR_SCH_ARCHIVE_LOADER::POINT CADSTAR_SCH_ARCHIVE_LOADER::getLocationOfNetEl auto logUnknownNetElementError = [&]() { - wxLogError( wxString::Format( _( - "Net %s references unknown net element %s. The net was " - "not properly loaded and may require manual fixing." ), - getNetName( aNet ), aNetElementID ) ); + m_reporter->Report( wxString::Format( _( "Net %s references unknown net element %s. " + "The net was not properly loaded and may " + "require manual fixing." ), + getNetName( aNet ), + aNetElementID ), + RPT_SEVERITY_ERROR ); return POINT(); }; @@ -2002,12 +2019,15 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadChildSheets( { if( block.Figures.size() > 0 ) { - wxLogError( wxString::Format( - _( "The block ID %s (Block name: '%s') is drawn on sheet '%s' but is " - "not linked to another sheet in the design. KiCad requires all " - "sheet symbols to be associated to a sheet, so the block was not " - "loaded." ), - block.ID, block.Name, Sheets.SheetNames.at( aCadstarSheetID ) ) ); + m_reporter->Report( wxString::Format( _( "The block ID %s (Block name: '%s') " + "is drawn on sheet '%s' but is not " + "linked to another sheet in the " + "design. KiCad requires all sheet " + "symbols to be associated to a sheet, " + "so the block was not loaded." ), + block.ID, block.Name, + Sheets.SheetNames.at( aCadstarSheetID ) ), + RPT_SEVERITY_ERROR ); } continue; @@ -2024,10 +2044,10 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadChildSheets( } else { - THROW_IO_ERROR( wxString::Format( - _( "The CADSTAR schematic might be corrupt: Block %s references a " - "child sheet but has no Figure defined." ), - block.ID ) ); + THROW_IO_ERROR( wxString::Format( _( "The CADSTAR schematic might be corrupt: " + "Block %s references a child sheet but has no " + "Figure defined." ), + block.ID ) ); } loadSheetAndChildSheets( block.AssocLayerID, blockExtents.first, blockExtents.second, aSheet ); diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index 6f5729a515..6f7fb49b81 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -52,7 +52,7 @@ class SCHEMATIC; class CADSTAR_SCH_ARCHIVE_LOADER : public CADSTAR_SCH_ARCHIVE_PARSER { public: - explicit CADSTAR_SCH_ARCHIVE_LOADER( wxString aFilename ) + explicit CADSTAR_SCH_ARCHIVE_LOADER( wxString aFilename, REPORTER* aReporter ) : CADSTAR_SCH_ARCHIVE_PARSER( aFilename ) { m_schematic = nullptr; @@ -60,6 +60,7 @@ public: m_plugin = nullptr; m_designCenter.x = 0; m_designCenter.y = 0; + m_reporter = aReporter; } @@ -86,6 +87,7 @@ private: */ typedef std::map TERMINAL_TO_PINNUM_MAP; + REPORTER* m_reporter; SCHEMATIC* m_schematic; SCH_SHEET* m_rootSheet; SCH_PLUGIN::SCH_PLUGIN_RELEASER* m_plugin; diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp index aff60b486c..5c2c2f640b 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp @@ -134,7 +134,7 @@ SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::Load( const wxString& aFileName, SCHEMATI aSchematic->Prj().SchSymbolLibTable(); } - CADSTAR_SCH_ARCHIVE_LOADER csaFile( aFileName ); + CADSTAR_SCH_ARCHIVE_LOADER csaFile( aFileName, m_reporter ); csaFile.Load( aSchematic, rootSheet, &sch_plugin, libFileName ); sch_plugin->SaveLibrary( libFileName.GetFullPath() ); diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h index 985398d164..4326dad368 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h @@ -29,6 +29,8 @@ #include +#include + class SCH_SHEET; class SCH_SCREEN; @@ -40,6 +42,8 @@ public: const wxString GetName() const override; + void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; } + const wxString GetFileExtension() const override; const wxString GetLibraryFileExtension() const override; @@ -88,11 +92,14 @@ public: CADSTAR_SCH_ARCHIVE_PLUGIN() { + m_reporter = &WXLOG_REPORTER::GetInstance(); } ~CADSTAR_SCH_ARCHIVE_PLUGIN() { } + + REPORTER* m_reporter; // current reporter for warnings/errors }; #endif // CADSTAR_SCH_ARCHIVE_PLUGIN_H_ diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index 5929468bde..67dd96ee36 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -351,10 +351,11 @@ static void eagleToKicadAlignment( EDA_TEXT* aText, int aEagleAlignment, int aRe SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN() { - m_kiway = nullptr; m_rootSheet = nullptr; m_currentSheet = nullptr; m_schematic = nullptr; + + m_reporter = &WXLOG_REPORTER::GetInstance(); } @@ -1157,9 +1158,10 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) if( part_it == m_partlist.end() ) { - wxLogError( _( "Error parsing Eagle file. " - "Could not find \"%s\" instance but it is referenced in the schematic." ), - einstance.part ); + m_reporter->Report( wxString::Format( _( "Error parsing Eagle file. Could not find '%s' " + "instance but it is referenced in the schematic." ), + einstance.part ), + RPT_SEVERITY_ERROR ); return; } @@ -1187,8 +1189,9 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) if( !part ) { - wxLogMessage( wxString::Format( _( "Could not find %s in the imported library" ), - kisymbolname ) ); + m_reporter->Report( wxString::Format( _( "Could not find '%s' in the imported library." ), + kisymbolname ), + RPT_SEVERITY_ERROR ); return; } diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.h b/eeschema/sch_plugins/eagle/sch_eagle_plugin.h index cf8dd7cc0e..554e6429c5 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.h +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.h @@ -86,6 +86,8 @@ public: const wxString GetName() const override; + void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; } + const wxString GetFileExtension() const override; const wxString GetLibraryFileExtension() const override; @@ -212,32 +214,34 @@ private: std::map units; }; + REPORTER* m_reporter; ///< Reporter for warnings/errors + ///< Map references to missing component units data std::map m_missingCmps; - KIWAY* m_kiway; ///< For creating sub sheets. - SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded.. - SCH_SHEET* m_currentSheet; ///< The current sheet of the schematic being loaded.. - wxString m_version; ///< Eagle file version. - wxFileName m_filename; - wxString m_libName; ///< Library name to save symbols - SCHEMATIC* m_schematic; ///< Passed to Load(), the schematic object being loaded + SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded + SCH_SHEET* m_currentSheet; ///< The current sheet of the schematic being loaded + wxString m_version; ///< Eagle file version. + wxFileName m_filename; + wxString m_libName; ///< Library name to save symbols + SCHEMATIC* m_schematic; ///< Passed to Load(), the schematic object being loaded - EPART_MAP m_partlist; + EPART_MAP m_partlist; std::map m_eagleLibs; - SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; ///< Plugin to create the KiCad symbol library. - std::unique_ptr< PROPERTIES > m_properties; ///< Library plugin properties. + SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; ///< Plugin to create the KiCad symbol library. + std::unique_ptr< PROPERTIES > m_properties; ///< Library plugin properties. - std::map m_netCounts; - std::map m_layerMap; + std::map m_netCounts; + std::map m_layerMap; ///< Wire intersection points, used for quick checks whether placing a net label in a particular ///< place would short two nets. std::vector m_wireIntersections; ///< Wires and labels of a single connection (segment in Eagle nomenclature) - typedef struct SEG_DESC_STRUCT { + typedef struct SEG_DESC_STRUCT + { ///< Test if a particular label is attached to any of the stored segments const SEG* LabelAttached( const SCH_TEXT* aLabel ) const; diff --git a/include/reporter.h b/include/reporter.h index 0e710d48b2..28a136de67 100644 --- a/include/reporter.h +++ b/include/reporter.h @@ -249,8 +249,26 @@ public: static REPORTER& GetInstance(); - REPORTER& Report( const wxString& aText, - SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; + REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; + + bool HasMessage() const override { return false; } +}; + + +class WXLOG_REPORTER : public REPORTER +{ +public: + WXLOG_REPORTER() + { + } + + virtual ~WXLOG_REPORTER() + { + } + + static REPORTER& GetInstance(); + + REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; bool HasMessage() const override { return false; } };