diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index fc9cdad6ae..7952f6ed2d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -103,6 +103,8 @@ set( KICOMMON_SRCS jobs/job_sch_erc.cpp jobs/job_sym_export_svg.cpp jobs/job_sym_upgrade.cpp + jobs/job_pcb_upgrade.cpp + jobs/job_sch_upgrade.cpp kicad_curl/kicad_curl.cpp kicad_curl/kicad_curl_easy.cpp diff --git a/common/jobs/job_pcb_upgrade.cpp b/common/jobs/job_pcb_upgrade.cpp new file mode 100644 index 0000000000..a8a2740aac --- /dev/null +++ b/common/jobs/job_pcb_upgrade.cpp @@ -0,0 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 . + */ + +#include + +JOB_PCB_UPGRADE::JOB_PCB_UPGRADE() : + JOB( "upgrade", false ), + m_filename(), + m_force( false ) +{ +} diff --git a/common/jobs/job_pcb_upgrade.h b/common/jobs/job_pcb_upgrade.h new file mode 100644 index 0000000000..80e7f3ccd6 --- /dev/null +++ b/common/jobs/job_pcb_upgrade.h @@ -0,0 +1,35 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 JOB_PCB_UPGRADE_H +#define JOB_PCB_UPGRADE_H + +#include +#include "job.h" + +class KICOMMON_API JOB_PCB_UPGRADE : public JOB +{ +public: + JOB_PCB_UPGRADE(); + + wxString m_filename; + bool m_force; +}; + +#endif diff --git a/common/jobs/job_sch_upgrade.cpp b/common/jobs/job_sch_upgrade.cpp new file mode 100644 index 0000000000..19f6533919 --- /dev/null +++ b/common/jobs/job_sch_upgrade.cpp @@ -0,0 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 . + */ + +#include + +JOB_SCH_UPGRADE::JOB_SCH_UPGRADE() : + JOB( "upgrade", false ), + m_filename(), + m_force( false ) +{ +} diff --git a/common/jobs/job_sch_upgrade.h b/common/jobs/job_sch_upgrade.h new file mode 100644 index 0000000000..c82be46ef1 --- /dev/null +++ b/common/jobs/job_sch_upgrade.h @@ -0,0 +1,35 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 JOB_SCH_UPGRADE_H +#define JOB_SCH_UPGRADE_H + +#include +#include "job.h" + +class KICOMMON_API JOB_SCH_UPGRADE : public JOB +{ +public: + JOB_SCH_UPGRADE(); + + wxString m_filename; + bool m_force; +}; + +#endif diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index 252dd79a0b..c929c7b884 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ #include #include +#include #include #include @@ -158,6 +160,11 @@ EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER( KIWAY* aKiway ) : DIALOG_ERC_JOB_CONFIG dlg( aParent, ercJob ); return dlg.ShowModal() == wxID_OK; } ); + Register( "upgrade", std::bind( &EESCHEMA_JOBS_HANDLER::JobUpgrade, this, std::placeholders::_1 ), + []( JOB* job, wxWindow* aParent ) -> bool + { + return true; + } ); } @@ -1070,8 +1077,8 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob ) if( m_progressReporter ) m_progressReporter->KeepRefreshing(); - bool shouldSave = upgradeJob->m_force - || schLibrary.GetFileFormatVersionAtLoad() < SEXPR_SYMBOL_LIB_FILE_VERSION; + bool shouldSave = + upgradeJob->m_force || schLibrary.GetFileFormatVersionAtLoad() < SEXPR_SYMBOL_LIB_FILE_VERSION; if( shouldSave ) { @@ -1198,6 +1205,54 @@ int EESCHEMA_JOBS_HANDLER::JobSchErc( JOB* aJob ) } +int EESCHEMA_JOBS_HANDLER::JobUpgrade( JOB* aJob ) +{ + JOB_SCH_UPGRADE* aUpgradeJob = dynamic_cast( aJob ); + + if( aUpgradeJob == nullptr ) + return CLI::EXIT_CODES::ERR_UNKNOWN; + + SCHEMATIC* sch = getSchematic( aUpgradeJob->m_filename ); + + if( !sch ) + return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; + + bool shouldSave = aUpgradeJob->m_force; + + if( sch->RootScreen()->GetFileFormatVersionAtLoad() < SEXPR_SCHEMATIC_FILE_VERSION ) + shouldSave = true; + + if( !shouldSave ) + { + m_reporter->Report( _( "Schematic file was not updated\n" ), RPT_SEVERITY_ERROR ); + return CLI::EXIT_CODES::SUCCESS; + } + + // needs an absolute path + wxFileName schPath( aUpgradeJob->m_filename ); + schPath.MakeAbsolute(); + const wxString schFullPath = schPath.GetFullPath(); + + try + { + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); + SCH_SHEET* loadedSheet = pi->LoadSchematicFile( schFullPath, sch ); + pi->SaveSchematicFile( schFullPath, loadedSheet, sch ); + } + catch( const IO_ERROR& ioe ) + { + wxString msg = + wxString::Format( _( "Error saving schematic file '%s'.\n%s" ), schFullPath, ioe.What().GetData() ); + m_reporter->Report( msg, RPT_SEVERITY_ERROR ); + return CLI::EXIT_CODES::ERR_UNKNOWN; + } + + m_reporter->Report( _( "Successfully saved schematic file using the latest format\n" ), RPT_SEVERITY_INFO ); + + return CLI::EXIT_CODES::SUCCESS; +} + + DS_PROXY_VIEW_ITEM* EESCHEMA_JOBS_HANDLER::getDrawingSheetProxyView( SCHEMATIC* aSch ) { DS_PROXY_VIEW_ITEM* drawingSheet = diff --git a/eeschema/eeschema_jobs_handler.h b/eeschema/eeschema_jobs_handler.h index a99a04f4d8..1b4d92a00b 100644 --- a/eeschema/eeschema_jobs_handler.h +++ b/eeschema/eeschema_jobs_handler.h @@ -45,6 +45,7 @@ public: int JobSchErc( JOB* aJob ); int JobSymUpgrade( JOB* aJob ); int JobSymExportSvg( JOB* aJob ); + int JobUpgrade( JOB* aJob ); /** * Configure the SCH_RENDER_SETTINGS object with the correct data to be used with plotting. diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index c09ca778d9..280017b12a 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -70,8 +70,10 @@ set( KICAD_CLI_SRCS cli/command_pcb_export_pos.cpp cli/command_pcb_export_ps.cpp cli/command_pcb_export_svg.cpp + cli/command_pcb_upgrade.cpp cli/command_fp_export_svg.cpp cli/command_fp_upgrade.cpp + cli/command_sch_upgrade.cpp cli/command_sch_export_bom.cpp cli/command_sch_export_pythonbom.cpp cli/command_sch_export_netlist.cpp diff --git a/kicad/cli/command_pcb_upgrade.cpp b/kicad/cli/command_pcb_upgrade.cpp new file mode 100644 index 0000000000..4064d12548 --- /dev/null +++ b/kicad/cli/command_pcb_upgrade.cpp @@ -0,0 +1,54 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 . + */ + +#include "command_pcb_upgrade.h" +#include "jobs/job_pcb_upgrade.h" +#include "cli/exit_codes.h" +#include + +#define ARG_FORCE "--force" + +CLI::PCB_UPGRADE_COMMAND::PCB_UPGRADE_COMMAND() : + COMMAND( "upgrade" ) +{ + addCommonArgs( true, false, false, false ); + m_argParser.add_description( UTF8STDSTR( _( "Upgrade the board file's format to the latest one" ) ) ); + + m_argParser.add_argument( ARG_FORCE ) + .help( UTF8STDSTR( _( "Forces the board file to be resaved regardless of versioning" ) ) ) + .flag(); +} + +int CLI::PCB_UPGRADE_COMMAND::doPerform( KIWAY& aKiway ) +{ + std::unique_ptr upgradeJob = std::make_unique(); + + upgradeJob->m_filename = m_argInput; + upgradeJob->m_force = m_argParser.get( ARG_FORCE ); + + if( !wxFile::Exists( upgradeJob->m_filename ) ) + { + wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) ); + return EXIT_CODES::ERR_INVALID_INPUT_FILE; + } + + int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, upgradeJob.get() ); + + return exitCode; +} diff --git a/kicad/cli/command_pcb_upgrade.h b/kicad/cli/command_pcb_upgrade.h new file mode 100644 index 0000000000..4f5a466da2 --- /dev/null +++ b/kicad/cli/command_pcb_upgrade.h @@ -0,0 +1,36 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 COMMAND_PCB_UPGRADE_H +#define COMMAND_PCB_UPGRADE_H + +#include "command.h" + +namespace CLI +{ +struct PCB_UPGRADE_COMMAND : public COMMAND +{ + PCB_UPGRADE_COMMAND(); + +protected: + int doPerform( KIWAY& aKiway ) override; +}; +} // namespace CLI + +#endif diff --git a/kicad/cli/command_sch_upgrade.cpp b/kicad/cli/command_sch_upgrade.cpp new file mode 100644 index 0000000000..342e950d2d --- /dev/null +++ b/kicad/cli/command_sch_upgrade.cpp @@ -0,0 +1,54 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 . + */ + +#include "command_sch_upgrade.h" +#include "jobs/job_sch_upgrade.h" +#include "cli/exit_codes.h" +#include + +#define ARG_FORCE "--force" + +CLI::SCH_UPGRADE_COMMAND::SCH_UPGRADE_COMMAND() : + COMMAND( "upgrade" ) +{ + addCommonArgs( true, false, false, false ); + m_argParser.add_description( UTF8STDSTR( _( "Upgrade the schematic file's format to the latest one" ) ) ); + + m_argParser.add_argument( ARG_FORCE ) + .help( UTF8STDSTR( _( "Forces the schematic file to be resaved regardless of versioning" ) ) ) + .flag(); +} + +int CLI::SCH_UPGRADE_COMMAND::doPerform( KIWAY& aKiway ) +{ + std::unique_ptr upgradeJob = std::make_unique(); + + upgradeJob->m_filename = m_argInput; + upgradeJob->m_force = m_argParser.get( ARG_FORCE ); + + if( !wxFile::Exists( upgradeJob->m_filename ) ) + { + wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) ); + return EXIT_CODES::ERR_INVALID_INPUT_FILE; + } + + int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, upgradeJob.get() ); + + return exitCode; +} diff --git a/kicad/cli/command_sch_upgrade.h b/kicad/cli/command_sch_upgrade.h new file mode 100644 index 0000000000..ff056d320f --- /dev/null +++ b/kicad/cli/command_sch_upgrade.h @@ -0,0 +1,36 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 COMMAND_SCH_UPGRADE_H +#define COMMAND_SCH_UPGRADE_H + +#include "command.h" + +namespace CLI +{ +struct SCH_UPGRADE_COMMAND : public COMMAND +{ + SCH_UPGRADE_COMMAND(); + +protected: + int doPerform( KIWAY& aKiway ) override; +}; +} // namespace CLI + +#endif diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index 7d3bfde13a..13ae7d23c1 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -70,6 +70,7 @@ #include "cli/command_sch_export_pythonbom.h" #include "cli/command_sch_export_netlist.h" #include "cli/command_sch_export_plot.h" +#include "cli/command_pcb_upgrade.h" #include "cli/command_fp.h" #include "cli/command_fp_export.h" #include "cli/command_fp_export_svg.h" @@ -77,6 +78,7 @@ #include "cli/command_sch.h" #include "cli/command_sch_erc.h" #include "cli/command_sch_export.h" +#include "cli/command_sch_upgrade.h" #include "cli/command_sym.h" #include "cli/command_sym_export.h" #include "cli/command_sym_export_svg.h" @@ -117,6 +119,7 @@ static CLI::JOBSET_RUN_COMMAND jobsetRunCmd{}; static CLI::PCB_COMMAND pcbCmd{}; static CLI::PCB_DRC_COMMAND pcbDrcCmd{}; static CLI::PCB_RENDER_COMMAND pcbRenderCmd{}; +static CLI::PCB_UPGRADE_COMMAND pcbUpgradeCmd{}; static CLI::PCB_EXPORT_DRILL_COMMAND exportPcbDrillCmd{}; static CLI::PCB_EXPORT_DXF_COMMAND exportPcbDxfCmd{}; static CLI::PCB_EXPORT_3D_COMMAND exportPcbGlbCmd{ "glb", UTF8STDSTR( _( "Export GLB (binary GLTF)" ) ), JOB_EXPORT_PCB_3D::FORMAT::GLB }; @@ -142,6 +145,7 @@ static CLI::PCB_EXPORT_COMMAND exportPcbCmd{}; static CLI::SCH_EXPORT_COMMAND exportSchCmd{}; static CLI::SCH_COMMAND schCmd{}; static CLI::SCH_ERC_COMMAND schErcCmd{}; +static CLI::SCH_UPGRADE_COMMAND schUpgradeCmd{}; static CLI::SCH_EXPORT_BOM_COMMAND exportSchBomCmd{}; static CLI::SCH_EXPORT_PYTHONBOM_COMMAND exportSchPythonBomCmd{}; static CLI::SCH_EXPORT_NETLIST_COMMAND exportSchNetlistCmd{}; @@ -219,6 +223,9 @@ static std::vector commandStack = { &exportPcbStlCmd, &exportPcbStepzCmd } + }, + { + &pcbUpgradeCmd } } }, @@ -240,6 +247,9 @@ static std::vector commandStack = { &exportSchPythonBomCmd, &exportSchSvgCmd } + }, + { + &schUpgradeCmd } } }, diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index 8e61df3c0e..cb656b6628 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -136,6 +137,11 @@ PCBNEW_JOBS_HANDLER::PCBNEW_JOBS_HANDLER( KIWAY* aKiway ) : DIALOG_RENDER_JOB dlg( aParent, renderJob ); return dlg.ShowModal() == wxID_OK; } ); + Register( "upgrade", std::bind( &PCBNEW_JOBS_HANDLER::JobUpgrade, this, std::placeholders::_1 ), + []( JOB* job, wxWindow* aParent ) -> bool + { + return true; + } ); Register( "svg", std::bind( &PCBNEW_JOBS_HANDLER::JobExportSvg, this, std::placeholders::_1 ), [aKiway]( JOB* job, wxWindow* aParent ) -> bool { @@ -2516,6 +2522,42 @@ int PCBNEW_JOBS_HANDLER::JobExportOdb( JOB* aJob ) return CLI::EXIT_CODES::SUCCESS; } +int PCBNEW_JOBS_HANDLER::JobUpgrade( JOB* aJob ) +{ + JOB_PCB_UPGRADE* job = dynamic_cast( aJob ); + + if( job == nullptr ) + return CLI::EXIT_CODES::ERR_UNKNOWN; + + bool shouldSave = job->m_force; + + try + { + IO_RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); + BOARD* brd = getBoard( job->m_filename ); + if( brd->GetFileFormatVersionAtLoad() < SEXPR_BOARD_FILE_VERSION ) + shouldSave = true; + + if( shouldSave ) + { + pi->SaveBoard( brd->GetFileName(), brd ); + m_reporter->Report( _( "Successfully saved board file using the latest format\n" ), RPT_SEVERITY_INFO ); + } + else + { + m_reporter->Report( _( "Board file was not updated\n" ), RPT_SEVERITY_ERROR ); + } + } + catch( const IO_ERROR& ioe ) + { + wxString msg = + wxString::Format( _( "Error saving board file '%s'.\n%s" ), job->m_filename, ioe.What().GetData() ); + m_reporter->Report( msg, RPT_SEVERITY_ERROR ); + return CLI::EXIT_CODES::ERR_UNKNOWN; + } + + return CLI::EXIT_CODES::SUCCESS; +} DS_PROXY_VIEW_ITEM* PCBNEW_JOBS_HANDLER::getDrawingSheetProxyView( BOARD* aBrd ) { diff --git a/pcbnew/pcbnew_jobs_handler.h b/pcbnew/pcbnew_jobs_handler.h index eb7834dd0a..fe73102339 100644 --- a/pcbnew/pcbnew_jobs_handler.h +++ b/pcbnew/pcbnew_jobs_handler.h @@ -56,6 +56,7 @@ public: int JobExportIpc2581( JOB* aJob ); int JobExportOdb( JOB* aJob ); int JobExportIpcD356( JOB* aJob ); + int JobUpgrade( JOB* aJob ); private: BOARD* getBoard( const wxString& aPath = wxEmptyString );