ADDED: ERC over cli....mostly

This commit is contained in:
Marek Roszko 2023-08-13 20:31:19 -04:00
parent f341fde938
commit 5d001d4858
19 changed files with 592 additions and 28 deletions

View File

@ -311,6 +311,7 @@ set( COMMON_SRCS
bitmap_store.cpp
board_printout.cpp
build_version.cpp
cli_progress_reporter.cpp
commit.cpp
common.cpp
config_params.cpp

View File

@ -0,0 +1,54 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2023 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 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 <cli_progress_reporter.h>
#include <wx/crt.h>
PROGRESS_REPORTER& CLI_PROGRESS_REPORTER::GetInstance()
{
static CLI_PROGRESS_REPORTER s_cliReporter;
return s_cliReporter;
}
void CLI_PROGRESS_REPORTER::AdvancePhase( const wxString& aMessage )
{
printLine( aMessage );
}
void CLI_PROGRESS_REPORTER::Report( const wxString& aMessage )
{
printLine( aMessage );
}
void CLI_PROGRESS_REPORTER::printLine( const wxString& aMessage )
{
if( aMessage.EndsWith( wxS( "\n" ) ) )
wxFprintf( stdout, aMessage );
else
wxFprintf( stdout, aMessage + wxS( "\n" ) );
}

View File

@ -53,3 +53,10 @@ void JOB_DISPATCHER::SetReporter( REPORTER* aReporter )
wxCHECK( aReporter != nullptr, /*void*/ );
m_reporter = aReporter;
}
void JOB_DISPATCHER::SetProgressReporter( PROGRESS_REPORTER* aReporter )
{
wxCHECK( aReporter != nullptr, /*void*/ );
m_progressReporter = aReporter;
}

View File

@ -28,6 +28,7 @@
class REPORTER;
class PROGRESS_REPORTER;
class JOB_DISPATCHER
{
@ -36,9 +37,11 @@ public:
void Register( const std::string& aJobTypeName, std::function<int( JOB* job )> aHandler );
int RunJob( JOB* job );
void SetReporter( REPORTER* aReporter );
void SetProgressReporter( PROGRESS_REPORTER* aReporter );
protected:
REPORTER* m_reporter; // non-owning
PROGRESS_REPORTER* m_progressReporter; // non-owning
private:
std::map<std::string, std::function<int( JOB* job )>> m_jobHandlers;

67
common/jobs/job_sch_erc.h Normal file
View File

@ -0,0 +1,67 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2023 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 1992-2023 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 <http://www.gnu.org/licenses/>.
*/
#ifndef JOB_PCB_DRC_H
#define JOB_PCB_DRC_H
#include <layer_ids.h>
#include <wx/string.h>
#include <widgets/report_severity.h>
#include "job.h"
class JOB_SCH_ERC : public JOB
{
public:
JOB_SCH_ERC( bool aIsCli ) :
JOB( "erc", aIsCli ),
m_filename(),
m_units( JOB_SCH_ERC::UNITS::MILLIMETERS ),
m_severity( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING ),
m_format( OUTPUT_FORMAT::REPORT ),
m_exitCodeViolations( false )
{
}
wxString m_filename;
wxString m_outputFile;
enum class UNITS
{
INCHES,
MILLIMETERS,
MILS
};
UNITS m_units;
int m_severity;
enum class OUTPUT_FORMAT
{
REPORT,
JSON
};
OUTPUT_FORMAT m_format;
bool m_exitCodeViolations;
};
#endif

View File

@ -481,7 +481,7 @@ void DIALOG_ERC::testErc()
{
wxBusyCursor dummy;
tester.RunTests( sch, m_parent->GetCanvas()->GetView()->GetDrawingSheet(), m_parent, this );
tester.RunTests( m_parent->GetCanvas()->GetView()->GetDrawingSheet(), m_parent, this );
}
// Update marker list:

View File

@ -25,6 +25,7 @@
#include <pgm_base.h>
#include <kiface_base.h>
#include <cli_progress_reporter.h>
#include <confirm.h>
#include <gestfich.h>
#include <eda_dde.h>
@ -350,7 +351,10 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
m_jobHandler = std::make_unique<EESCHEMA_JOBS_HANDLER>();
if( m_start_flags & KFCTL_CLI )
{
m_jobHandler->SetReporter( &CLI_REPORTER::GetInstance() );
m_jobHandler->SetProgressReporter( &CLI_PROGRESS_REPORTER::GetInstance() );
}
return true;
}

View File

@ -23,10 +23,12 @@
#include <pgm_base.h>
#include <cli/exit_codes.h>
#include <sch_plotter.h>
#include <drawing_sheet/ds_proxy_view_item.h>
#include <jobs/job_export_sch_bom.h>
#include <jobs/job_export_sch_pythonbom.h>
#include <jobs/job_export_sch_netlist.h>
#include <jobs/job_export_sch_plot.h>
#include <jobs/job_sch_erc.h>
#include <jobs/job_sym_export_svg.h>
#include <jobs/job_sym_upgrade.h>
#include <schematic.h>
@ -38,6 +40,7 @@
#include <sch_painter.h>
#include <locale_io.h>
#include <erc.h>
#include <erc_report.h>
#include <wildcards_and_files_ext.h>
#include <plotters/plotters_pslike.h>
#include <drawing_sheet/ds_data_model.h>
@ -74,6 +77,8 @@ EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
std::bind( &EESCHEMA_JOBS_HANDLER::JobSymUpgrade, this, std::placeholders::_1 ) );
Register( "symsvg",
std::bind( &EESCHEMA_JOBS_HANDLER::JobSymExportSvg, this, std::placeholders::_1 ) );
Register( "erc",
std::bind( &EESCHEMA_JOBS_HANDLER::JobSchErc, this, std::placeholders::_1 ) );
}
@ -700,3 +705,114 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob )
return CLI::EXIT_CODES::OK;
}
int EESCHEMA_JOBS_HANDLER::JobSchErc( JOB* aJob )
{
JOB_SCH_ERC* ercJob = dynamic_cast<JOB_SCH_ERC*>( aJob );
if( !ercJob )
return CLI::EXIT_CODES::ERR_UNKNOWN;
SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( ercJob->m_filename, SCH_IO_MGR::SCH_KICAD );
if( sch == nullptr )
{
m_reporter->Report( _( "Failed to load schematic file\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
}
if( ercJob->m_outputFile.IsEmpty() )
{
wxFileName fn = sch->GetFileName();
fn.SetName( fn.GetName() );
if( ercJob->m_format == JOB_SCH_ERC::OUTPUT_FORMAT::JSON )
fn.SetExt( JsonFileExtension );
else
fn.SetExt( ReportFileExtension );
ercJob->m_outputFile = fn.GetFullName();
}
EDA_UNITS units;
switch( ercJob->m_units )
{
case JOB_SCH_ERC::UNITS::INCHES:
units = EDA_UNITS::INCHES;
break;
case JOB_SCH_ERC::UNITS::MILS:
units = EDA_UNITS::MILS;
break;
case JOB_SCH_ERC::UNITS::MILLIMETERS:
default:
units = EDA_UNITS::MILLIMETRES; break;
}
std::shared_ptr<SHEETLIST_ERC_ITEMS_PROVIDER> markersProvider =
std::make_shared<SHEETLIST_ERC_ITEMS_PROVIDER>( sch );
ERC_TESTER ercTester( sch );
m_reporter->Report( _( "Running ERC...\n" ), RPT_SEVERITY_INFO );
DS_PROXY_VIEW_ITEM* drawingSheet = getDrawingSheetProxyView( sch );
ercTester.RunTests( drawingSheet, nullptr, m_progressReporter );
markersProvider->SetSeverities( ercJob->m_severity );
m_reporter->Report(
wxString::Format( _( "Found %d violations\n" ), markersProvider->GetCount() ),
RPT_SEVERITY_INFO );
ERC_REPORT reportWriter( sch, units );
bool wroteReport = false;
if( ercJob->m_format == JOB_SCH_ERC::OUTPUT_FORMAT::JSON )
wroteReport = reportWriter.WriteJsonReport( ercJob->m_outputFile );
else
wroteReport = reportWriter.WriteTextReport( ercJob->m_outputFile );
if( !wroteReport )
{
m_reporter->Report(
wxString::Format( _( "Unable to save ERC report to %s\n" ), ercJob->m_outputFile ),
RPT_SEVERITY_INFO );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
m_reporter->Report( wxString::Format( _( "Saved ERC Report to %s\n" ), ercJob->m_outputFile ),
RPT_SEVERITY_INFO );
if( ercJob->m_exitCodeViolations )
{
if( markersProvider->GetCount() > 0 )
{
return CLI::EXIT_CODES::ERR_RC_VIOLATIONS;
}
}
return CLI::EXIT_CODES::SUCCESS;
}
DS_PROXY_VIEW_ITEM* EESCHEMA_JOBS_HANDLER::getDrawingSheetProxyView( SCHEMATIC* aSch )
{
DS_PROXY_VIEW_ITEM* drawingSheet =
new DS_PROXY_VIEW_ITEM( schIUScale, &aSch->RootScreen()->GetPageSettings(), &aSch->Prj(),
&aSch->RootScreen()->GetTitleBlock(), aSch->GetProperties() );
drawingSheet->SetPageNumber( TO_UTF8( aSch->RootScreen()->GetPageNumber() ) );
drawingSheet->SetSheetCount( aSch->RootScreen()->GetPageCount() );
drawingSheet->SetFileName( TO_UTF8( aSch->RootScreen()->GetFileName() ) );
drawingSheet->SetColorLayer( LAYER_SCHEMATIC_DRAWINGSHEET );
drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
drawingSheet->SetIsFirstPage( aSch->RootScreen()->GetVirtualPageNumber() == 1 );
drawingSheet->SetSheetName( "" );
drawingSheet->SetSheetPath( "" );
return drawingSheet;
}

View File

@ -32,6 +32,7 @@ class SCH_RENDER_SETTINGS;
class SCHEMATIC;
class JOB_SYM_EXPORT_SVG;
class LIB_SYMBOL;
class DS_PROXY_VIEW_ITEM;
/**
* Handles eeschema job dispatches
@ -44,6 +45,7 @@ public:
int JobExportPythonBom( JOB* aJob );
int JobExportNetlist( JOB* aJob );
int JobExportPlot( JOB* aJob );
int JobSchErc( JOB* aJob );
int JobSymUpgrade( JOB* aJob );
int JobSymExportSvg( JOB* aJob );
@ -63,6 +65,7 @@ private:
int doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob, KIGFX::SCH_RENDER_SETTINGS* aRenderSettings,
LIB_SYMBOL* symbol );
DS_PROXY_VIEW_ITEM* getDrawingSheetProxyView( SCHEMATIC* aSch );
};
#endif

View File

@ -45,7 +45,7 @@
#include <drawing_sheet/ds_proxy_view_item.h>
#include <wx/ffile.h>
#include <sim/sim_lib_mgr.h>
#include <widgets/progress_reporter_base.h>
#include <progress_reporter.h>
/* ERC tests :
@ -1067,11 +1067,10 @@ int ERC_TESTER::TestSimModelIssues()
}
void ERC_TESTER::RunTests( SCHEMATIC* aSch, DS_PROXY_VIEW_ITEM* aDrawingSheet,
SCH_EDIT_FRAME* aEditFrame,
PROGRESS_REPORTER_BASE* aProgressReporter )
void ERC_TESTER::RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aEditFrame,
PROGRESS_REPORTER* aProgressReporter )
{
ERC_SETTINGS& settings = aSch->ErcSettings();
ERC_SETTINGS& settings = m_schematic->ErcSettings();
// Test duplicate sheet names inside a given sheet. While one can have multiple references
// to the same file, each must have a unique name.
@ -1102,7 +1101,7 @@ void ERC_TESTER::RunTests( SCHEMATIC* aSch, DS_PROXY_VIEW_ITEM* aDrawingSheet,
aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
}
aSch->ConnectionGraph()->RunERC();
m_schematic->ConnectionGraph()->RunERC();
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking units..." ) );
@ -1123,7 +1122,8 @@ void ERC_TESTER::RunTests( SCHEMATIC* aSch, DS_PROXY_VIEW_ITEM* aDrawingSheet,
TestMissingUnits();
}
aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
TestMultUnitPinConflicts();
@ -1140,40 +1140,46 @@ void ERC_TESTER::RunTests( SCHEMATIC* aSch, DS_PROXY_VIEW_ITEM* aDrawingSheet,
// using case insensitive comparisons)
if( settings.IsTestEnabled( ERCE_SIMILAR_LABELS ) )
{
aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
TestSimilarLabels();
}
if( settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
{
aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
TestTextVars( aDrawingSheet );
}
if( settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
{
aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
TestSimModelIssues();
}
if( settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
{
aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
TestNoConnectPins();
}
if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
{
aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
TestLibSymbolIssues();
}
if( settings.IsTestEnabled( ERCE_ENDPOINT_OFF_GRID ) )
{
aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
if( aEditFrame )
TestOffGridEndpoints( aEditFrame->GetCanvas()->GetView()->GetGAL()->GetGridSize().x );
}
aSch->ResolveERCExclusionsPostUpdate();
m_schematic->ResolveERCExclusionsPostUpdate();
}

View File

@ -39,7 +39,7 @@ class SCH_SHEET_LIST;
class SCHEMATIC;
class DS_PROXY_VIEW_ITEM;
class SCH_EDIT_FRAME;
class PROGRESS_REPORTER_BASE;
class PROGRESS_REPORTER;
extern const wxString CommentERC_H[];
@ -146,8 +146,8 @@ public:
*/
int TestMissingUnits();
void RunTests( SCHEMATIC* aSch, DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aEditFrame,
PROGRESS_REPORTER_BASE* aProgressReporter );
void RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aEditFrame,
PROGRESS_REPORTER* aProgressReporter );
private:

View File

@ -32,7 +32,8 @@ namespace CLI
static const int ERR_UNKNOWN = 2;
static const int ERR_INVALID_INPUT_FILE = 3;
static const int ERR_INVALID_OUTPUT_CONFLICT = 4;
static const int ERR_DRC_VIOLATIONS = 5;
///< Rules check violation count was greater than 0
static const int ERR_RC_VIOLATIONS = 5;
};
}

View File

@ -0,0 +1,109 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2023 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 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
*/
#ifndef CLI_PROGRESS_REPORTER_H
#define CLI_PROGRESS_REPORTER_H
#include <wx/string.h>
#include <progress_reporter.h>
/**
* Reporter forwarding messages to stdout or stderr as appropriate
*/
class CLI_PROGRESS_REPORTER : public PROGRESS_REPORTER
{
public:
CLI_PROGRESS_REPORTER() {}
virtual ~CLI_PROGRESS_REPORTER() {}
static PROGRESS_REPORTER& GetInstance();
/**
* Set the number of phases.
*/
virtual void SetNumPhases( int aNumPhases ) override {}
virtual void AddPhases( int aNumPhases ) override {};
/**
* Initialize the \a aPhase virtual zone of the dialog progress bar.
*/
virtual void BeginPhase( int aPhase ) override {}
/**
* Use the next available virtual zone of the dialog progress bar.
*/
virtual void AdvancePhase() override {}
/**
* Use the next available virtual zone of the dialog progress bar and updates the message.
*/
virtual void AdvancePhase( const wxString& aMessage ) override;
/**
* Display \a aMessage in the progress bar dialog.
*/
virtual void Report( const wxString& aMessage ) override;
/**
* Set the progress value to aProgress (0..1).
*/
virtual void SetCurrentProgress( double aProgress ) override {}
/**
* Fix the value that gives the 100 percent progress bar length
* (inside the current virtual zone).
*/
virtual void SetMaxProgress( int aMaxProgress ) override {}
/**
* Increment the progress bar length (inside the current virtual zone).
*/
virtual void AdvanceProgress() override {}
/**
* Update the UI (if any).
*
* @warning This should only be called from the main thread.
*
* @return false if the user cancelled.
*/
virtual bool KeepRefreshing( bool aWait = false ) override { return false; }
/**
* Change the title displayed on the window caption.
*
* Has meaning only for some reporters. Does nothing for others.
*
* @warning This should only be called from the main thread.
*/
virtual void SetTitle( const wxString& aTitle ) override {}
virtual bool IsCancelled() const override { return false; }
private:
void printLine( const wxString& aMessage );
};
#endif

View File

@ -51,6 +51,7 @@ set( KICAD_CLI_SRCS
cli/command_export_sch_pythonbom.cpp
cli/command_export_sch_netlist.cpp
cli/command_export_sch_plot.cpp
cli/command_sch_erc.cpp
cli/command_sym_export_svg.cpp
cli/command_sym_upgrade.cpp
cli/command_version.cpp

View File

@ -0,0 +1,146 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 1992-2023 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 <http://www.gnu.org/licenses/>.
*/
#include "command_sch_erc.h"
#include <cli/exit_codes.h>
#include "jobs/job_sch_erc.h"
#include <kiface_base.h>
#include <layer_ids.h>
#include <wx/crt.h>
#include <macros.h>
#include <wx/tokenzr.h>
#define ARG_FORMAT "--format"
#define ARG_UNITS "--units"
#define ARG_SEVERITY_ALL "--severity-all"
#define ARG_SEVERITY_ERROR "--severity-error"
#define ARG_SEVERITY_WARNING "--severity-warning"
#define ARG_SEVERITY_EXCLUSIONS "--severity-exclusions"
#define ARG_EXIT_CODE_VIOLATIONS "--exit-code-violations"
CLI::SCH_ERC_COMMAND::SCH_ERC_COMMAND() : EXPORT_PCB_BASE_COMMAND( "erc" )
{
m_argParser.add_argument( ARG_FORMAT )
.default_value( std::string( "report" ) )
.help( UTF8STDSTR( _( "Output file format, options: json, report" ) ) );
m_argParser.add_argument( ARG_UNITS )
.default_value( std::string( "mm" ) )
.help( UTF8STDSTR(
_( "Report units; valid options: in, mm, mils" ) ) );
m_argParser.add_argument( ARG_SEVERITY_ALL )
.help( UTF8STDSTR( _( "Report all DRC violations, this is equivalent to including all the other severity arguments" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_SEVERITY_ERROR )
.help( UTF8STDSTR( _( "Report all DRC error level violations, this can be combined with the other severity arguments" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_SEVERITY_WARNING )
.help( UTF8STDSTR( _( "Report all DRC warning level violations, this can be combined with the other severity arguments" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_SEVERITY_EXCLUSIONS )
.help( UTF8STDSTR( _( "Report all excluded DRC violations, this can be combined with the other severity arguments" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_EXIT_CODE_VIOLATIONS )
.help( UTF8STDSTR( _( "Return a exit code depending on whether or not violations exist" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-o", ARG_OUTPUT )
.default_value( std::string() )
.help( UTF8STDSTR( _( "Output file name" ) ) );
}
int CLI::SCH_ERC_COMMAND::doPerform( KIWAY& aKiway )
{
std::unique_ptr<JOB_SCH_ERC> ercJob( new JOB_SCH_ERC( true ) );
ercJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
ercJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
ercJob->m_exitCodeViolations = m_argParser.get<bool>( ARG_EXIT_CODE_VIOLATIONS );
if( m_argParser.get<bool>( ARG_SEVERITY_ALL ) )
{
ercJob->m_severity = RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING | RPT_SEVERITY_EXCLUSION;
}
if( m_argParser.get<bool>( ARG_SEVERITY_ERROR ) )
{
ercJob->m_severity |= RPT_SEVERITY_ERROR;
}
if( m_argParser.get<bool>( ARG_SEVERITY_WARNING ) )
{
ercJob->m_severity |= RPT_SEVERITY_WARNING;
}
if( m_argParser.get<bool>( ARG_SEVERITY_EXCLUSIONS ) )
{
ercJob->m_severity |= RPT_SEVERITY_EXCLUSION;
}
wxString units = FROM_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
if( units == wxS( "mm" ) )
{
ercJob->m_units = JOB_SCH_ERC::UNITS::MILLIMETERS;
}
else if( units == wxS( "in" ) )
{
ercJob->m_units = JOB_SCH_ERC::UNITS::INCHES;
}
else if( units == wxS( "mils" ) )
{
ercJob->m_units = JOB_SCH_ERC::UNITS::MILS;
}
else if( !units.IsEmpty() )
{
wxFprintf( stderr, _( "Invalid units specified\n" ) );
return EXIT_CODES::ERR_ARGS;
}
wxString format = FROM_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
if( format == "report" )
{
ercJob->m_format = JOB_SCH_ERC::OUTPUT_FORMAT::REPORT;
}
else if( format == "json" )
{
ercJob->m_format = JOB_SCH_ERC::OUTPUT_FORMAT::JSON;
}
else
{
wxFprintf( stderr, _( "Invalid report format\n" ) );
return EXIT_CODES::ERR_ARGS;
}
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, ercJob.get() );
return exitCode;
}

View File

@ -0,0 +1,38 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 1992-2022 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 <http://www.gnu.org/licenses/>.
*/
#ifndef COMMAND_SCH_ERC_H
#define COMMAND_SCH_ERC_H
#include "command_export_pcb_base.h"
namespace CLI
{
class SCH_ERC_COMMAND : public EXPORT_PCB_BASE_COMMAND
{
public:
SCH_ERC_COMMAND();
protected:
int doPerform( KIWAY& aKiway ) override;
};
} // namespace CLI
#endif

View File

@ -66,6 +66,7 @@
#include "cli/command_fp_export_svg.h"
#include "cli/command_fp_upgrade.h"
#include "cli/command_sch.h"
#include "cli/command_sch_erc.h"
#include "cli/command_sch_export.h"
#include "cli/command_sym.h"
#include "cli/command_sym_export.h"
@ -125,7 +126,8 @@ struct COMMAND_ENTRY
handler( aHandler ), subCommands( aSub ){};
};
static CLI::PCB_DRC_COMMAND pcbDrcCmd{};
static CLI::PCB_COMMAND pcbCmd{};
static CLI::PCB_DRC_COMMAND pcbDrcCmd{};
static CLI::EXPORT_PCB_DRILL_COMMAND exportPcbDrillCmd{};
static CLI::EXPORT_PCB_DXF_COMMAND exportPcbDxfCmd{};
static CLI::EXPORT_PCB_STEP_COMMAND exportPcbStepCmd{};
@ -135,9 +137,9 @@ static CLI::EXPORT_PCB_POS_COMMAND exportPcbPosCmd{};
static CLI::EXPORT_PCB_GERBER_COMMAND exportPcbGerberCmd{};
static CLI::EXPORT_PCB_GERBERS_COMMAND exportPcbGerbersCmd{};
static CLI::EXPORT_PCB_COMMAND exportPcbCmd{};
static CLI::PCB_COMMAND pcbCmd{};
static CLI::EXPORT_SCH_COMMAND exportSchCmd{};
static CLI::SCH_COMMAND schCmd{};
static CLI::SCH_ERC_COMMAND schErcCmd{};
static CLI::EXPORT_SCH_BOM_COMMAND exportSchBomCmd{};
static CLI::EXPORT_SCH_PYTHONBOM_COMMAND exportSchPythonBomCmd{};
static CLI::EXPORT_SCH_NETLIST_COMMAND exportSchNetlistCmd{};
@ -175,6 +177,9 @@ static std::vector<COMMAND_ENTRY> commandStack = {
{
&pcbCmd,
{
{
&pcbDrcCmd
},
{
&exportPcbCmd,
{
@ -187,15 +192,15 @@ static std::vector<COMMAND_ENTRY> commandStack = {
&exportPcbStepCmd,
&exportPcbSvgCmd
}
},
{
&pcbDrcCmd
}
}
},
{
&schCmd,
{
{
&schErcCmd
},
{
&exportSchCmd,
{

View File

@ -25,9 +25,10 @@
#include <pcbnew_scripting_helpers.h>
#include <pgm_base.h>
#include <cli_progress_reporter.h>
#include <confirm.h>
#include <kiface_base.h>
#include <kiface_ids.h>
#include <confirm.h>
#include <pcb_edit_frame.h>
#include <eda_dde.h>
#include <macros.h>
@ -365,7 +366,10 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
m_jobHandler = std::make_unique<PCBNEW_JOBS_HANDLER>();
if( m_start_flags & KFCTL_CLI )
{
m_jobHandler->SetReporter( &CLI_REPORTER::GetInstance() );
m_jobHandler->SetProgressReporter( &CLI_PROGRESS_REPORTER::GetInstance() );
}
return true;
}

View File

@ -960,7 +960,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrc( JOB* aJob )
if( markersProvider->GetCount() > 0 || ratsnestProvider->GetCount() > 0
|| fpWarningsProvider->GetCount() > 0 )
{
return CLI::EXIT_CODES::ERR_DRC_VIOLATIONS;
return CLI::EXIT_CODES::ERR_RC_VIOLATIONS;
}
}
@ -980,8 +980,7 @@ DS_PROXY_VIEW_ITEM* PCBNEW_JOBS_HANDLER::getDrawingSheetProxyView( BOARD* aBrd )
drawingSheet->SetSheetPath( std::string() );
drawingSheet->SetIsFirstPage( true );
if( BOARD* board = GetBoard() )
drawingSheet->SetFileName( TO_UTF8( board->GetFileName() ) );
drawingSheet->SetFileName( TO_UTF8( aBrd->GetFileName() ) );
return drawingSheet;
}