diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 196902c9cc..47c2f7433a 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -80,6 +80,8 @@ set( KICOMMON_SRCS jobs/job_sch_erc.cpp jobs/job_sym_export_svg.cpp jobs/job_sym_upgrade.cpp + jobs/job_pcb_convert.cpp + jobs/job_sch_convert.cpp kicad_curl/kicad_curl.cpp kicad_curl/kicad_curl_easy.cpp diff --git a/common/jobs/job_pcb_convert.cpp b/common/jobs/job_pcb_convert.cpp new file mode 100644 index 0000000000..98cf72b9b6 --- /dev/null +++ b/common/jobs/job_pcb_convert.cpp @@ -0,0 +1,30 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Ethan Chien + * 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 "job_pcb_convert.h" +#include "job.h" + +JOB_PCB_CONVERT::JOB_PCB_CONVERT( bool aIsCli ) : JOB( "convert", aIsCli ) +{ +} diff --git a/common/jobs/job_pcb_convert.h b/common/jobs/job_pcb_convert.h new file mode 100644 index 0000000000..06e1f83a51 --- /dev/null +++ b/common/jobs/job_pcb_convert.h @@ -0,0 +1,57 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2024 Ethan Chien + * Copyright (C) 2024 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 JOB_PCB_CONVERT_H +#define JOB_PCB_CONVERT_H + +#include +#include +#include "job.h" + +class KICOMMON_API JOB_PCB_CONVERT : public JOB +{ +public: + JOB_PCB_CONVERT( bool aIsCli ); + + wxString m_filename; + wxString m_outputFile; + + enum class From + { + ALTIUM_CIRCUIT_MAKER, + ALTIUM_CIRCUIT_STUDIO, + ALTIUM_DESIGNER + }; + + enum class To + { + KICAD_SEXP + }; + + + From m_from; + To m_to ; +}; + +#endif diff --git a/common/jobs/job_sch_convert.cpp b/common/jobs/job_sch_convert.cpp new file mode 100644 index 0000000000..b281211559 --- /dev/null +++ b/common/jobs/job_sch_convert.cpp @@ -0,0 +1,30 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Ethan Chien + * 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 "job_sch_convert.h" +#include "job.h" + +JOB_SCH_CONVERT::JOB_SCH_CONVERT( bool aIsCli ) : JOB( "convert", aIsCli ) +{ +} diff --git a/common/jobs/job_sch_convert.h b/common/jobs/job_sch_convert.h new file mode 100644 index 0000000000..406908ec62 --- /dev/null +++ b/common/jobs/job_sch_convert.h @@ -0,0 +1,55 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2024 Ethan Chien + * Copyright (C) 2024 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 JOB_SCH_CONVERT_H +#define JOB_SCH_CONVERT_H + +#include +#include +#include "job.h" + + +class KICOMMON_API JOB_SCH_CONVERT : public JOB +{ +public: + JOB_SCH_CONVERT( bool aIsCli ); + wxString m_filename; + wxString m_outputFile; + + enum class From + { + SCH_ALTIUM + }; + + enum class To + { + SCH_KICAD + }; + + + From m_from; + To m_to; +}; + +#endif \ No newline at end of file diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index 0ad6b7beef..b452ff07ac 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +86,8 @@ EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER( KIWAY* aKiway ) : std::bind( &EESCHEMA_JOBS_HANDLER::JobSymExportSvg, this, std::placeholders::_1 ) ); Register( "erc", std::bind( &EESCHEMA_JOBS_HANDLER::JobSchErc, this, std::placeholders::_1 ) ); + Register( "convert", + std::bind( &EESCHEMA_JOBS_HANDLER::JobSchConvert, this, std::placeholders::_1 ) ); } @@ -1056,3 +1059,66 @@ DS_PROXY_VIEW_ITEM* EESCHEMA_JOBS_HANDLER::getDrawingSheetProxyView( SCHEMATIC* return drawingSheet; } + +int EESCHEMA_JOBS_HANDLER::JobSchConvert( JOB* aJob ) +{ + JOB_SCH_CONVERT* aConvertJob = dynamic_cast( aJob ); + + if( !aConvertJob ) + return CLI::EXIT_CODES::ERR_UNKNOWN; + + if( aJob->IsCli() ) + m_reporter->Report( _( "Loading schematic\n" ), RPT_SEVERITY_INFO ); + + static const auto convertFromSCH = std::map { + {JOB_SCH_CONVERT::From::SCH_ALTIUM, SCH_IO_MGR::SCH_FILE_T::SCH_ALTIUM} + }; + + static const auto convertToSCH = std::map { + {JOB_SCH_CONVERT::To::SCH_KICAD, SCH_IO_MGR::SCH_FILE_T::SCH_KICAD} + }; + + if( auto from_type = convertFromSCH.find( aConvertJob->m_from ); from_type == convertFromSCH.end() ) + { + return CLI::EXIT_CODES::ERR_ARGS; + } + else + { + + if (auto to_type = convertToSCH.find( aConvertJob->m_to ); to_type == convertToSCH.end() ) + { + return CLI::EXIT_CODES::ERR_ARGS; + } + else + { + try + { + SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aConvertJob->m_filename, from_type->second, true ); + + if(!sch || !sch->IsValid()) + { + m_reporter->Report( _( "Failed to load schematic file." ) ); + return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; + } + + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( to_type->second ) ); + pi->SetProgressReporter( m_progressReporter ); + pi->SaveSchematicFile( aConvertJob->m_outputFile, &sch->Root() ,sch ); + } + catch( const IO_ERROR& ioe ) + { + m_reporter->Report( wxString::Format( _( "Error converting schematic file '%s'.\n%s" ), + aConvertJob->m_filename, ioe.What() ), + RPT_SEVERITY_ERROR ); + + return CLI::EXIT_CODES::ERR_UNKNOWN; + } + + m_reporter->Report( _( "Successfully converted schematic file" ) + wxS( "\n" ), RPT_SEVERITY_INFO ); + return CLI::EXIT_CODES::OK; + } + + } +} + + diff --git a/eeschema/eeschema_jobs_handler.h b/eeschema/eeschema_jobs_handler.h index f06ab85974..f343b9a107 100644 --- a/eeschema/eeschema_jobs_handler.h +++ b/eeschema/eeschema_jobs_handler.h @@ -43,6 +43,7 @@ public: int JobExportNetlist( JOB* aJob ); int JobExportPlot( JOB* aJob ); int JobSchErc( JOB* aJob ); + int JobSchConvert( JOB* aJob ); int JobSymUpgrade( JOB* aJob ); int JobSymExportSvg( JOB* aJob ); diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index e34422c9a2..c476682845 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -62,6 +62,8 @@ set( KICAD_CLI_SRCS cli/command_sym_export_svg.cpp cli/command_sym_upgrade.cpp cli/command_version.cpp + cli/command_pcb_convert.cpp + cli/command_sch_convert.cpp ) if( WIN32 ) diff --git a/kicad/cli/command_pcb_convert.cpp b/kicad/cli/command_pcb_convert.cpp new file mode 100644 index 0000000000..4d14642b75 --- /dev/null +++ b/kicad/cli/command_pcb_convert.cpp @@ -0,0 +1,82 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Ethan Chien + * 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 "command_pcb_convert.h" +#include "jobs/job_pcb_convert.h" + + +#include +#include "command_utils.h" +#include +#include +#include +#include +#include + +#include +#include + +#define ARG_FROM "--from" +#define ARG_TO "--to" + + +CLI::PCB_CONVERT_COMMAND::PCB_CONVERT_COMMAND() : COMMAND( "convert" ) +{ + addCommonArgs( true, true, false, false ); + addDefineArg(); + + m_argParser.add_description( + UTF8STDSTR( _( "Convert a vendor's PCB document to another vendor's PCB document" ) ) ); + + + m_argParser.add_argument( ARG_FROM ) + .default_value( std::string( "altium_designer" ) ) + .add_choices( enumChoices() ) + .metavar( "FROM" ) + .help( UTF8STDSTR( wxString::Format( _( "Accepted PCB format. Options: %s" ), + enumString() ) ) ); + + + m_argParser.add_argument( ARG_TO ) + .default_value( std::string( "kicad_sexp" ) ) + .add_choices( enumChoices() ) + .metavar( "TO" ) + .help( UTF8STDSTR( wxString::Format( _( "Converted format. Options: %s" ), + enumString() ) ) ); + +} + + +int CLI::PCB_CONVERT_COMMAND::doPerform( KIWAY& aKiway ) +{ + std::unique_ptr convertJob( new JOB_PCB_CONVERT( true ) ); + + convertJob->m_outputFile = m_argOutput; + convertJob->m_filename = m_argInput; + convertJob->SetVarOverrides( m_argDefineVars ); + getToEnum( m_argParser.get( ARG_FROM ), convertJob->m_from ); + getToEnum( m_argParser.get( ARG_TO ), convertJob->m_to ); + int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, convertJob.get() ); + return exitCode; +} diff --git a/kicad/cli/command_pcb_convert.h b/kicad/cli/command_pcb_convert.h new file mode 100644 index 0000000000..9b5cd6c110 --- /dev/null +++ b/kicad/cli/command_pcb_convert.h @@ -0,0 +1,45 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2024 Ethan Chien + * Copyright (C) 2024 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 COMMAND_PCB_CONVERT_H +#define COMMAND_PCB_CONVERT_H + +#include "command.h" + +namespace CLI +{ + +class PCB_CONVERT_COMMAND : public COMMAND +{ +public: + PCB_CONVERT_COMMAND(); + +protected: + int doPerform( KIWAY& aKiway ) override; +}; + +} // namespace CLI + + +#endif \ No newline at end of file diff --git a/kicad/cli/command_sch_convert.cpp b/kicad/cli/command_sch_convert.cpp new file mode 100644 index 0000000000..be38e2e844 --- /dev/null +++ b/kicad/cli/command_sch_convert.cpp @@ -0,0 +1,83 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Ethan Chien + * 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 "command_sch_convert.h" +#include "command_utils.h" + +#include "jobs/job_sch_convert.h" + + +#include +#include "command_utils.h" +#include +#include +#include +#include +#include + +#include +#include + +#define ARG_FROM "--from" +#define ARG_TO "--to" + + +CLI::SCH_CONVERT_COMMAND::SCH_CONVERT_COMMAND() : COMMAND( "convert" ) +{ + addCommonArgs( true, true, false, false ); + addDefineArg(); + + m_argParser.add_description( UTF8STDSTR( + _( "Convert a vendor's schematic document to another vendor's schematic document" ) ) ); + + + m_argParser.add_argument( ARG_FROM ) + .default_value( std::string( "sch_altium" ) ) + .add_choices( enumChoices() ) + .metavar( "FROM" ) + .help( UTF8STDSTR( wxString::Format( _( "Accepted PCB format. Options: %s" ), + enumString() ) ) ); + + + m_argParser.add_argument( ARG_TO ) + .default_value( std::string( "sch_kicad" ) ) + .add_choices( enumChoices() ) + .metavar( "TO" ) + .help( UTF8STDSTR( wxString::Format( _( "Converted format. Options: %s" ), + enumString() ) ) ); +} + + +int CLI::SCH_CONVERT_COMMAND::doPerform( KIWAY& aKiway ) +{ + std::unique_ptr convertJob( new JOB_SCH_CONVERT( true ) ); + + convertJob->m_outputFile = m_argOutput; + convertJob->m_filename = m_argInput; + convertJob->SetVarOverrides( m_argDefineVars ); + getToEnum( m_argParser.get( ARG_FROM ), convertJob->m_from ); + getToEnum( m_argParser.get( ARG_TO ), convertJob->m_to ); + int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, convertJob.get() ); + return exitCode; +} diff --git a/kicad/cli/command_sch_convert.h b/kicad/cli/command_sch_convert.h new file mode 100644 index 0000000000..2ab9b79df9 --- /dev/null +++ b/kicad/cli/command_sch_convert.h @@ -0,0 +1,45 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2024 Ethan Chien + * Copyright (C) 2024 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 COMMAND_SCH_CONVERT_H +#define COMMAND_SCH_CONVERT_H +#include "command.h" + + +namespace CLI +{ + +class SCH_CONVERT_COMMAND : public COMMAND +{ +public: + SCH_CONVERT_COMMAND(); + +protected: + int doPerform( KIWAY& aKiway ) override; +}; + +} // namespace CLI + + +#endif \ No newline at end of file diff --git a/kicad/cli/command_utils.h b/kicad/cli/command_utils.h new file mode 100644 index 0000000000..4ef65b2d38 --- /dev/null +++ b/kicad/cli/command_utils.h @@ -0,0 +1,94 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2024 Ethan Chien + * Copyright (C) 2024 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 COMMAND_UTILS_H +#define COMMAND_UTILS_H +#include +#include + +template +inline wxString enumString() +{ + wxString str; + auto names = magic_enum::enum_names(); + + for( size_t i = 0; i < names.size(); i++ ) + { + std::string name = { names[i].begin(), names[i].end() }; + + if( i > 0 ) + str << ", "; + + std::transform( name.begin(), name.end(), name.begin(), + []( unsigned char c ) + { + return std::tolower( c ); + } ); + + str << name; + } + + return str; +} + + +template +inline std::vector enumChoices() +{ + std::vector out; + + for( auto& strView : magic_enum::enum_names() ) + { + std::string name = { strView.begin(), strView.end() }; + + std::transform( name.begin(), name.end(), name.begin(), + []( unsigned char c ) + { + return std::tolower( c ); + } ); + + out.emplace_back( name ); + } + + return out; +} + + +template +inline bool getToEnum( const std::string& aInput, T& aOutput ) +{ + // If not specified, leave at default + if( aInput.empty() ) + return true; + + if( auto opt = magic_enum::enum_cast( aInput, magic_enum::case_insensitive ) ) + { + aOutput = *opt; + return true; + } + + return false; +} + +#endif diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index a6a27be7f2..114e8b8e36 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -50,6 +50,7 @@ #include "cli/command_pcb_export.h" #include "cli/command_pcb_drc.h" #include "cli/command_pcb_render.h" +#include "cli/command_pcb_convert.h" #include "cli/command_pcb_export_3d.h" #include "cli/command_pcb_export_drill.h" #include "cli/command_pcb_export_dxf.h" @@ -70,6 +71,7 @@ #include "cli/command_sch.h" #include "cli/command_sch_erc.h" #include "cli/command_sch_export.h" +#include "cli/command_sch_convert.h" #include "cli/command_sym.h" #include "cli/command_sym_export.h" #include "cli/command_sym_export_svg.h" @@ -108,6 +110,7 @@ struct COMMAND_ENTRY static CLI::PCB_COMMAND pcbCmd{}; static CLI::PCB_DRC_COMMAND pcbDrcCmd{}; static CLI::PCB_RENDER_COMMAND pcbRenderCmd{}; +static CLI::PCB_CONVERT_COMMAND pcbConvertCmd{}; 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 }; @@ -125,6 +128,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_CONVERT_COMMAND schConvertCmd{}; static CLI::SCH_EXPORT_BOM_COMMAND exportSchBomCmd{}; static CLI::SCH_EXPORT_PYTHONBOM_COMMAND exportSchPythonBomCmd{}; static CLI::SCH_EXPORT_NETLIST_COMMAND exportSchNetlistCmd{}; @@ -168,6 +172,9 @@ static std::vector commandStack = { { &pcbRenderCmd }, + { + &pcbConvertCmd + }, { &exportPcbCmd, { @@ -194,6 +201,9 @@ static std::vector commandStack = { { &schErcCmd }, + { + &schConvertCmd + }, { &exportSchCmd, { diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index d12115703c..36d6261efa 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -18,6 +18,7 @@ * with this program. If not, see . */ +#include #include #include "pcbnew_jobs_handler.h" #include @@ -39,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +75,9 @@ #include #include #include +#include +#include +#include #include "pcbnew_scripting_helpers.h" @@ -106,6 +111,8 @@ PCBNEW_JOBS_HANDLER::PCBNEW_JOBS_HANDLER( KIWAY* aKiway ) : Register( "drc", std::bind( &PCBNEW_JOBS_HANDLER::JobExportDrc, this, std::placeholders::_1 ) ); Register( "ipc2581", std::bind( &PCBNEW_JOBS_HANDLER::JobExportIpc2581, this, std::placeholders::_1 ) ); + Register( "convert", + std::bind( &PCBNEW_JOBS_HANDLER::JobExportConvert, this, std::placeholders::_1 ) ); } @@ -1522,6 +1529,68 @@ int PCBNEW_JOBS_HANDLER::JobExportIpc2581( JOB* aJob ) return CLI::EXIT_CODES::SUCCESS; } +int PCBNEW_JOBS_HANDLER::JobExportConvert( JOB* aJob ) +{ + JOB_PCB_CONVERT* aConvertJob = dynamic_cast( aJob ); + + if( aConvertJob == nullptr ) + return CLI::EXIT_CODES::ERR_UNKNOWN; + + if( aJob->IsCli() ) + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); + + static const auto converFromPCBType = std::map{ + { JOB_PCB_CONVERT::From::ALTIUM_CIRCUIT_MAKER, + PCB_IO_MGR::PCB_FILE_T::ALTIUM_CIRCUIT_MAKER }, + { JOB_PCB_CONVERT::From::ALTIUM_CIRCUIT_STUDIO, + PCB_IO_MGR::PCB_FILE_T::ALTIUM_CIRCUIT_STUDIO }, + { JOB_PCB_CONVERT::From::ALTIUM_DESIGNER, PCB_IO_MGR::PCB_FILE_T::ALTIUM_DESIGNER }, + }; + + static const auto convertToPCBTYPE = std::map{ + { JOB_PCB_CONVERT::To::KICAD_SEXP, + PCB_IO_MGR::PCB_FILE_T::KICAD_SEXP } + }; + + if( auto from_type = converFromPCBType.find( aConvertJob->m_from ); from_type == converFromPCBType.end() ) + { + return CLI::EXIT_CODES::ERR_ARGS; + } + else + { + + if (auto to_type = convertToPCBTYPE.find( aConvertJob->m_to ); to_type == convertToPCBTYPE.end() ) + { + return CLI::EXIT_CODES::ERR_ARGS; + } + else + { + BOARD* brd = LoadBoard( aConvertJob->m_filename, from_type->second, + true ); + try + { + IO_RELEASER pi( PCB_IO_MGR::PluginFind( to_type->second ) ); + pi->SetProgressReporter( m_progressReporter ); + pi->SaveBoard( aConvertJob->m_outputFile, brd ); + } + catch( const IO_ERROR& ioe ) + { + m_reporter->Report( wxString::Format( _( "Error converting pcb file '%s'.\n%s" ), + aConvertJob->m_filename, ioe.What() ), + RPT_SEVERITY_ERROR ); + + return CLI::EXIT_CODES::ERR_UNKNOWN; + } + + m_reporter->Report( _( "Successfully converted board" ) + wxS( "\n" ), + RPT_SEVERITY_INFO ); + return CLI::EXIT_CODES::OK; + } + + } + +} + 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 39e50eda71..25ce7769b2 100644 --- a/pcbnew/pcbnew_jobs_handler.h +++ b/pcbnew/pcbnew_jobs_handler.h @@ -48,6 +48,7 @@ public: int JobExportFpSvg( JOB* aJob ); int JobExportDrc( JOB* aJob ); int JobExportIpc2581( JOB* aJob ); + int JobExportConvert( JOB* aJob ); private: void populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts,