Merge branch 'feat/cli/convert' into 'master'
kicad-cli: Add feature import Altium pcb/sch See merge request kicad/code/kicad!1932
This commit is contained in:
commit
5a19d5a891
|
@ -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
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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 )
|
||||
{
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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 <kicommon.h>
|
||||
#include <wx/string.h>
|
||||
#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
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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 )
|
||||
{
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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 <kicommon.h>
|
||||
#include <wx/string.h>
|
||||
#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
|
|
@ -25,6 +25,7 @@
|
|||
#include <sch_plotter.h>
|
||||
#include <drawing_sheet/ds_proxy_view_item.h>
|
||||
#include <jobs/job_export_sch_bom.h>
|
||||
#include <jobs/job_sch_convert.h>
|
||||
#include <jobs/job_export_sch_pythonbom.h>
|
||||
#include <jobs/job_export_sch_netlist.h>
|
||||
#include <jobs/job_export_sch_plot.h>
|
||||
|
@ -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<JOB_SCH_CONVERT*>( 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_IO_MGR::SCH_FILE_T > {
|
||||
{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_IO_MGR::SCH_FILE_T > {
|
||||
{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<SCH_IO> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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 <cli/exit_codes.h>
|
||||
#include "command_utils.h"
|
||||
#include <kiface_base.h>
|
||||
#include <layer_ids.h>
|
||||
#include <string_utils.h>
|
||||
#include <wx/crt.h>
|
||||
#include <magic_enum.hpp>
|
||||
|
||||
#include <macros.h>
|
||||
#include <wx/tokenzr.h>
|
||||
|
||||
#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<JOB_PCB_CONVERT::From>() )
|
||||
.metavar( "FROM" )
|
||||
.help( UTF8STDSTR( wxString::Format( _( "Accepted PCB format. Options: %s" ),
|
||||
enumString<JOB_PCB_CONVERT::From>() ) ) );
|
||||
|
||||
|
||||
m_argParser.add_argument( ARG_TO )
|
||||
.default_value( std::string( "kicad_sexp" ) )
|
||||
.add_choices( enumChoices<JOB_PCB_CONVERT::To>() )
|
||||
.metavar( "TO" )
|
||||
.help( UTF8STDSTR( wxString::Format( _( "Converted format. Options: %s" ),
|
||||
enumString<JOB_PCB_CONVERT::To>() ) ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
int CLI::PCB_CONVERT_COMMAND::doPerform( KIWAY& aKiway )
|
||||
{
|
||||
std::unique_ptr<JOB_PCB_CONVERT> convertJob( new JOB_PCB_CONVERT( true ) );
|
||||
|
||||
convertJob->m_outputFile = m_argOutput;
|
||||
convertJob->m_filename = m_argInput;
|
||||
convertJob->SetVarOverrides( m_argDefineVars );
|
||||
getToEnum( m_argParser.get<std::string>( ARG_FROM ), convertJob->m_from );
|
||||
getToEnum( m_argParser.get<std::string>( ARG_TO ), convertJob->m_to );
|
||||
int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, convertJob.get() );
|
||||
return exitCode;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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 <cli/exit_codes.h>
|
||||
#include "command_utils.h"
|
||||
#include <kiface_base.h>
|
||||
#include <layer_ids.h>
|
||||
#include <string_utils.h>
|
||||
#include <wx/crt.h>
|
||||
#include <magic_enum.hpp>
|
||||
|
||||
#include <macros.h>
|
||||
#include <wx/tokenzr.h>
|
||||
|
||||
#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<JOB_SCH_CONVERT::From>() )
|
||||
.metavar( "FROM" )
|
||||
.help( UTF8STDSTR( wxString::Format( _( "Accepted PCB format. Options: %s" ),
|
||||
enumString<JOB_SCH_CONVERT::From>() ) ) );
|
||||
|
||||
|
||||
m_argParser.add_argument( ARG_TO )
|
||||
.default_value( std::string( "sch_kicad" ) )
|
||||
.add_choices( enumChoices<JOB_SCH_CONVERT::To>() )
|
||||
.metavar( "TO" )
|
||||
.help( UTF8STDSTR( wxString::Format( _( "Converted format. Options: %s" ),
|
||||
enumString<JOB_SCH_CONVERT::To>() ) ) );
|
||||
}
|
||||
|
||||
|
||||
int CLI::SCH_CONVERT_COMMAND::doPerform( KIWAY& aKiway )
|
||||
{
|
||||
std::unique_ptr<JOB_SCH_CONVERT> convertJob( new JOB_SCH_CONVERT( true ) );
|
||||
|
||||
convertJob->m_outputFile = m_argOutput;
|
||||
convertJob->m_filename = m_argInput;
|
||||
convertJob->SetVarOverrides( m_argDefineVars );
|
||||
getToEnum( m_argParser.get<std::string>( ARG_FROM ), convertJob->m_from );
|
||||
getToEnum( m_argParser.get<std::string>( ARG_TO ), convertJob->m_to );
|
||||
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, convertJob.get() );
|
||||
return exitCode;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 Ethan Chien <liangtie.qian@gmail.com>
|
||||
* 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 <magic_enum.hpp>
|
||||
#include <wx/string.h>
|
||||
|
||||
template <typename T>
|
||||
inline wxString enumString()
|
||||
{
|
||||
wxString str;
|
||||
auto names = magic_enum::enum_names<T>();
|
||||
|
||||
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 <typename T>
|
||||
inline std::vector<std::string> enumChoices()
|
||||
{
|
||||
std::vector<std::string> out;
|
||||
|
||||
for( auto& strView : magic_enum::enum_names<T>() )
|
||||
{
|
||||
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 <typename T>
|
||||
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<T>( aInput, magic_enum::case_insensitive ) )
|
||||
{
|
||||
aOutput = *opt;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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<COMMAND_ENTRY> commandStack = {
|
|||
{
|
||||
&pcbRenderCmd
|
||||
},
|
||||
{
|
||||
&pcbConvertCmd
|
||||
},
|
||||
{
|
||||
&exportPcbCmd,
|
||||
{
|
||||
|
@ -194,6 +201,9 @@ static std::vector<COMMAND_ENTRY> commandStack = {
|
|||
{
|
||||
&schErcCmd
|
||||
},
|
||||
{
|
||||
&schConvertCmd
|
||||
},
|
||||
{
|
||||
&exportSchCmd,
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <wx/dir.h>
|
||||
#include "pcbnew_jobs_handler.h"
|
||||
#include <board_commit.h>
|
||||
|
@ -39,6 +40,7 @@
|
|||
#include <jobs/job_export_pcb_3d.h>
|
||||
#include <jobs/job_pcb_render.h>
|
||||
#include <jobs/job_pcb_drc.h>
|
||||
#include <jobs/job_pcb_convert.h>
|
||||
#include <cli/exit_codes.h>
|
||||
#include <exporters/place_file_exporter.h>
|
||||
#include <exporters/step/exporter_step.h>
|
||||
|
@ -73,6 +75,9 @@
|
|||
#include <export_vrml.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/zipstrm.h>
|
||||
#include <pcb_io/altium/pcb_io_altium_circuit_maker.h>
|
||||
#include <pcb_io/altium/pcb_io_altium_circuit_studio.h>
|
||||
#include <pcb_io/altium/pcb_io_altium_designer.h>
|
||||
|
||||
#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<JOB_PCB_CONVERT*>( 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, PCB_IO_MGR::PCB_FILE_T>{
|
||||
{ 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, PCB_IO_MGR::PCB_FILE_T>{
|
||||
{ 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<PCB_IO> 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 )
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue