Support json reports as option in erc/drc dialogs

This commit is contained in:
Marek Roszko 2023-08-13 18:48:29 -04:00
parent e842a788db
commit 061d18cbb0
5 changed files with 31 additions and 6 deletions

View File

@ -485,9 +485,15 @@ wxString PSFileWildcard()
} }
wxString JsonFileWildcard()
{
return _( "Json files" ) + AddFileExtListToFilter( { JsonFileExtension } );
}
wxString ReportFileWildcard() wxString ReportFileWildcard()
{ {
return _( "Report files" ) + AddFileExtListToFilter( { "rpt" } ); return _( "Report files" ) + AddFileExtListToFilter( { ReportFileExtension } );
} }

View File

@ -964,12 +964,16 @@ void DIALOG_ERC::OnSaveReport( wxCommandEvent& aEvent )
wxFileName fn( wxS( "ERC." ) + ReportFileExtension ); wxFileName fn( wxS( "ERC." ) + ReportFileExtension );
wxFileDialog dlg( this, _( "Save Report to File" ), Prj().GetProjectPath(), fn.GetFullName(), wxFileDialog dlg( this, _( "Save Report to File" ), Prj().GetProjectPath(), fn.GetFullName(),
ReportFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); ReportFileWildcard() + wxS( "|" ) + JsonFileWildcard(),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
return; return;
fn = EnsureFileExtension( dlg.GetPath(), ReportFileExtension ); fn = dlg.GetPath();
if( fn.GetExt().IsEmpty() )
fn.SetExt( ReportFileExtension );
if( !fn.IsAbsolute() ) if( !fn.IsAbsolute() )
{ {
@ -979,7 +983,13 @@ void DIALOG_ERC::OnSaveReport( wxCommandEvent& aEvent )
ERC_REPORT reportWriter( &m_parent->Schematic(), m_parent->GetUserUnits() ); ERC_REPORT reportWriter( &m_parent->Schematic(), m_parent->GetUserUnits() );
if( reportWriter.WriteTextReport( fn.GetFullPath() ) ) bool success = false;
if( fn.GetExt() == JsonFileExtension )
success = reportWriter.WriteJsonReport( fn.GetFullPath() );
else
success = reportWriter.WriteTextReport( fn.GetFullPath() );
if( success )
{ {
m_messages->Report( wxString::Format( _( "Report file '%s' created." ), m_messages->Report( wxString::Format( _( "Report file '%s' created." ),
fn.GetFullPath() ) ); fn.GetFullPath() ) );

View File

@ -129,6 +129,7 @@ bool ERC_REPORT::WriteJsonReport( const wxString& aFullFileName )
{ {
RC_JSON::ERC_SHEET jsonSheet; RC_JSON::ERC_SHEET jsonSheet;
jsonSheet.path = sheetList[i].PathHumanReadable(); jsonSheet.path = sheetList[i].PathHumanReadable();
jsonSheet.uuid = sheetList[i].Path().AsString();
for( SCH_ITEM* aItem : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) ) for( SCH_ITEM* aItem : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
{ {

View File

@ -239,6 +239,7 @@ extern wxString PSFileWildcard();
extern wxString MacrosFileWildcard(); extern wxString MacrosFileWildcard();
extern wxString DrillFileWildcard(); extern wxString DrillFileWildcard();
extern wxString SVGFileWildcard(); extern wxString SVGFileWildcard();
extern wxString JsonFileWildcard();
extern wxString ReportFileWildcard(); extern wxString ReportFileWildcard();
extern wxString FootprintPlaceFileWildcard(); extern wxString FootprintPlaceFileWildcard();
extern wxString Shapes3DFileWildcard(); extern wxString Shapes3DFileWildcard();

View File

@ -854,7 +854,8 @@ void DIALOG_DRC::OnSaveReport( wxCommandEvent& aEvent )
wxFileName fn( "DRC." + ReportFileExtension ); wxFileName fn( "DRC." + ReportFileExtension );
wxFileDialog dlg( this, _( "Save Report to File" ), Prj().GetProjectPath(), fn.GetFullName(), wxFileDialog dlg( this, _( "Save Report to File" ), Prj().GetProjectPath(), fn.GetFullName(),
ReportFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); ReportFileWildcard() + wxS( "|" ) + JsonFileWildcard(),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
return; return;
@ -873,7 +874,13 @@ void DIALOG_DRC::OnSaveReport( wxCommandEvent& aEvent )
DRC_REPORT reportWriter( m_frame->GetBoard(), GetUserUnits(), m_markersProvider, DRC_REPORT reportWriter( m_frame->GetBoard(), GetUserUnits(), m_markersProvider,
m_ratsnestProvider, m_fpWarningsProvider ); m_ratsnestProvider, m_fpWarningsProvider );
if( reportWriter.WriteJsonReport( fn.GetFullPath() ) ) bool success = false;
if( fn.GetExt() == JsonFileExtension )
success = reportWriter.WriteJsonReport( fn.GetFullPath() );
else
success = reportWriter.WriteTextReport( fn.GetFullPath() );
if( success )
{ {
m_messages->Report( wxString::Format( _( "Report file '%s' created<br>" ), m_messages->Report( wxString::Format( _( "Report file '%s' created<br>" ),
fn.GetFullPath() ) ); fn.GetFullPath() ) );