19 changed files with 592 additions and 28 deletions
-
1common/CMakeLists.txt
-
54common/cli_progress_reporter.cpp
-
7common/jobs/job_dispatcher.cpp
-
3common/jobs/job_dispatcher.h
-
67common/jobs/job_sch_erc.h
-
2eeschema/dialogs/dialog_erc.cpp
-
4eeschema/eeschema.cpp
-
116eeschema/eeschema_jobs_handler.cpp
-
3eeschema/eeschema_jobs_handler.h
-
34eeschema/erc.cpp
-
6eeschema/erc.h
-
3include/cli/exit_codes.h
-
109include/cli_progress_reporter.h
-
1kicad/CMakeLists.txt
-
146kicad/cli/command_sch_erc.cpp
-
38kicad/cli/command_sch_erc.h
-
15kicad/kicad_cli.cpp
-
6pcbnew/pcbnew.cpp
-
5pcbnew/pcbnew_jobs_handler.cpp
@ -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" ) ); |
|||
} |
|||
@ -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 |
|||
@ -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 |
|||
@ -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; |
|||
} |
|||
@ -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 |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue