Hotglue a symbol upgrade function in cli
This commit is contained in:
parent
4a88d2a74d
commit
21fed9fc8c
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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 JOB_SYM_UPGRADE_H
|
||||||
|
#define JOB_SYM_UPGRADE_H
|
||||||
|
|
||||||
|
#include <wx/string.h>
|
||||||
|
#include "job.h"
|
||||||
|
|
||||||
|
class JOB_SYM_UPGRADE : public JOB
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JOB_SYM_UPGRADE( bool aIsCli ) :
|
||||||
|
JOB( "symupgrade", aIsCli ),
|
||||||
|
m_libraryPath(),
|
||||||
|
m_force( false )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString m_libraryPath;
|
||||||
|
|
||||||
|
bool m_force;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -24,6 +24,7 @@
|
||||||
#include <jobs/job_export_sch_netlist.h>
|
#include <jobs/job_export_sch_netlist.h>
|
||||||
#include <jobs/job_export_sch_pdf.h>
|
#include <jobs/job_export_sch_pdf.h>
|
||||||
#include <jobs/job_export_sch_svg.h>
|
#include <jobs/job_export_sch_svg.h>
|
||||||
|
#include <jobs/job_sym_upgrade.h>
|
||||||
#include <pgm_base.h>
|
#include <pgm_base.h>
|
||||||
#include <sch_plotter.h>
|
#include <sch_plotter.h>
|
||||||
#include <schematic.h>
|
#include <schematic.h>
|
||||||
|
@ -37,6 +38,9 @@
|
||||||
|
|
||||||
#include <settings/settings_manager.h>
|
#include <settings/settings_manager.h>
|
||||||
|
|
||||||
|
#include <sch_file_versions.h>
|
||||||
|
#include <sch_plugins/kicad/sch_sexpr_lib_plugin_cache.h>
|
||||||
|
|
||||||
#include <netlist.h>
|
#include <netlist.h>
|
||||||
#include <netlist_exporter_base.h>
|
#include <netlist_exporter_base.h>
|
||||||
#include <netlist_exporter_orcadpcb2.h>
|
#include <netlist_exporter_orcadpcb2.h>
|
||||||
|
@ -57,6 +61,8 @@ EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
|
||||||
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPdf, this, std::placeholders::_1 ) );
|
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPdf, this, std::placeholders::_1 ) );
|
||||||
Register( "svg",
|
Register( "svg",
|
||||||
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportSvg, this, std::placeholders::_1 ) );
|
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportSvg, this, std::placeholders::_1 ) );
|
||||||
|
Register( "symupgrade",
|
||||||
|
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportSymLibUpgrade, this, std::placeholders::_1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -309,4 +315,47 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
|
||||||
}
|
}
|
||||||
|
|
||||||
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int EESCHEMA_JOBS_HANDLER::JobExportSymLibUpgrade( JOB* aJob )
|
||||||
|
{
|
||||||
|
JOB_SYM_UPGRADE* upgradeJob = dynamic_cast<JOB_SYM_UPGRADE*>( aJob );
|
||||||
|
|
||||||
|
SCH_SEXPR_PLUGIN_CACHE schLibrary( upgradeJob->m_libraryPath );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
schLibrary.Load();
|
||||||
|
}
|
||||||
|
catch( ... )
|
||||||
|
{
|
||||||
|
wxFprintf( stderr, _( "Unable to load library\n" ) );
|
||||||
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool shouldSave = upgradeJob->m_force
|
||||||
|
|| schLibrary.GetFileFormatVersionAtLoad() < SEXPR_SYMBOL_LIB_FILE_VERSION;
|
||||||
|
|
||||||
|
if( shouldSave )
|
||||||
|
{
|
||||||
|
wxPrintf( _( "Saving symbol library in updated format\n" ) );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
schLibrary.SetModified();
|
||||||
|
schLibrary.Save();
|
||||||
|
}
|
||||||
|
catch( ... )
|
||||||
|
{
|
||||||
|
wxFprintf( stderr, _( "Unable to save library\n" ) );
|
||||||
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxPrintf( _( "Symbol library was not updated\n" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return CLI::EXIT_CODES::OK;
|
||||||
}
|
}
|
|
@ -43,6 +43,7 @@ public:
|
||||||
int JobExportNetlist( JOB* aJob );
|
int JobExportNetlist( JOB* aJob );
|
||||||
int JobExportPdf( JOB* aJob );
|
int JobExportPdf( JOB* aJob );
|
||||||
int JobExportSvg( JOB* aJob );
|
int JobExportSvg( JOB* aJob );
|
||||||
|
int JobExportSymLibUpgrade( JOB* aJob );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the SCH_RENDER_SETTINGS object with the correct data to be used with plotting
|
* Configures the SCH_RENDER_SETTINGS object with the correct data to be used with plotting
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
SCH_SEXPR_PLUGIN_CACHE::SCH_SEXPR_PLUGIN_CACHE( const wxString& aFullPathAndFileName ) :
|
SCH_SEXPR_PLUGIN_CACHE::SCH_SEXPR_PLUGIN_CACHE( const wxString& aFullPathAndFileName ) :
|
||||||
SCH_LIB_PLUGIN_CACHE( aFullPathAndFileName )
|
SCH_LIB_PLUGIN_CACHE( aFullPathAndFileName )
|
||||||
{
|
{
|
||||||
m_versionMajor = -1;
|
m_fileFormatVersionAtLoad = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ void SCH_SEXPR_PLUGIN_CACHE::Load()
|
||||||
// Remember the file modification time of library file when the cache snapshot was made,
|
// Remember the file modification time of library file when the cache snapshot was made,
|
||||||
// so that in a networked environment we will reload the cache as needed.
|
// so that in a networked environment we will reload the cache as needed.
|
||||||
m_fileModTime = GetLibModificationTime();
|
m_fileModTime = GetLibModificationTime();
|
||||||
|
SetFileFormatVersionAtLoad( parser.GetParsedRequiredVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,14 @@ public:
|
||||||
static void SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter,
|
static void SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter,
|
||||||
int aNestLevel = 0, const wxString& aLibName = wxEmptyString );
|
int aNestLevel = 0, const wxString& aLibName = wxEmptyString );
|
||||||
|
|
||||||
|
void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
|
||||||
|
int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend SCH_SEXPR_PLUGIN;
|
friend SCH_SEXPR_PLUGIN;
|
||||||
|
|
||||||
|
int m_fileFormatVersionAtLoad;
|
||||||
|
|
||||||
static void saveSymbolDrawItem( LIB_ITEM* aItem, OUTPUTFORMATTER& aFormatter,
|
static void saveSymbolDrawItem( LIB_ITEM* aItem, OUTPUTFORMATTER& aFormatter,
|
||||||
int aNestLevel );
|
int aNestLevel );
|
||||||
static void saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter, int aNestLevel );
|
static void saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter, int aNestLevel );
|
||||||
|
@ -69,8 +74,6 @@ private:
|
||||||
|
|
||||||
static void saveDcmInfoAsFields( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter,
|
static void saveDcmInfoAsFields( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter,
|
||||||
int& aNextFreeFieldId, int aNestLevel );
|
int& aNextFreeFieldId, int aNestLevel );
|
||||||
|
|
||||||
int m_versionMajor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _SCH_SEXPR_LIB_PLUGIN_CACHE_
|
#endif // _SCH_SEXPR_LIB_PLUGIN_CACHE_
|
||||||
|
|
|
@ -108,6 +108,8 @@ public:
|
||||||
void ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyablyOnly = false,
|
void ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyablyOnly = false,
|
||||||
int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
|
int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
|
||||||
|
|
||||||
|
int GetParsedRequiredVersion() const { return m_requiredVersion; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkpoint();
|
void checkpoint();
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ set( KICAD_SRCS
|
||||||
cli/command_export_sch_pdf.cpp
|
cli/command_export_sch_pdf.cpp
|
||||||
cli/command_export_sch_svg.cpp
|
cli/command_export_sch_svg.cpp
|
||||||
cli/command_sch_export.cpp
|
cli/command_sch_export.cpp
|
||||||
|
cli/command_sym_upgrade.cpp
|
||||||
dialogs/dialog_template_selector_base.cpp
|
dialogs/dialog_template_selector_base.cpp
|
||||||
dialogs/dialog_template_selector.cpp
|
dialogs/dialog_template_selector.cpp
|
||||||
dialogs/panel_kicad_launcher_base.cpp
|
dialogs/panel_kicad_launcher_base.cpp
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
CLI::FP_UPGRADE_COMMAND::FP_UPGRADE_COMMAND() : EXPORT_PCB_BASE_COMMAND( "upgrade" )
|
CLI::FP_UPGRADE_COMMAND::FP_UPGRADE_COMMAND() : EXPORT_PCB_BASE_COMMAND( "upgrade" )
|
||||||
{
|
{
|
||||||
m_argParser.add_argument( ARG_FORCE )
|
m_argParser.add_argument( ARG_FORCE )
|
||||||
.help( UTF8STDSTR( _( "Forces the footprint to be resaved regardless of versioning" ) ) )
|
.help( UTF8STDSTR(
|
||||||
|
_( "Forces the footprint library to be resaved regardless of versioning" ) ) )
|
||||||
.implicit_value( true )
|
.implicit_value( true )
|
||||||
.default_value( false );
|
.default_value( false );
|
||||||
}
|
}
|
||||||
|
@ -47,11 +48,11 @@ int CLI::FP_UPGRADE_COMMAND::Perform( KIWAY& aKiway )
|
||||||
|
|
||||||
if( !wxDir::Exists( fpJob->m_libraryPath ) )
|
if( !wxDir::Exists( fpJob->m_libraryPath ) )
|
||||||
{
|
{
|
||||||
wxFprintf( stderr, _( "Footprint file does not exist or is not accessible\n" ) );
|
wxFprintf( stderr, _( "Footprint path does not exist or is not accessible\n" ) );
|
||||||
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
|
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, fpJob.get() );
|
int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, fpJob.get() );
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* 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_SYM_H
|
||||||
|
#define COMMAND_SYM_H
|
||||||
|
|
||||||
|
#include "command.h"
|
||||||
|
|
||||||
|
namespace CLI
|
||||||
|
{
|
||||||
|
struct SYM_COMMAND : public COMMAND
|
||||||
|
{
|
||||||
|
SYM_COMMAND() : COMMAND( "sym" ) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "command_sym_upgrade.h"
|
||||||
|
#include <cli/exit_codes.h>
|
||||||
|
#include "jobs/job_sym_upgrade.h"
|
||||||
|
#include <kiface_base.h>
|
||||||
|
#include <layer_ids.h>
|
||||||
|
#include <wx/crt.h>
|
||||||
|
#include <wx/dir.h>
|
||||||
|
|
||||||
|
#include <macros.h>
|
||||||
|
|
||||||
|
#define ARG_FORCE "--force"
|
||||||
|
|
||||||
|
CLI::SYM_UPGRADE_COMMAND::SYM_UPGRADE_COMMAND() : EXPORT_PCB_BASE_COMMAND( "upgrade" )
|
||||||
|
{
|
||||||
|
m_argParser.add_argument( ARG_FORCE )
|
||||||
|
.help( UTF8STDSTR(
|
||||||
|
_( "Forces the symbol library to be resaved regardless of versioning" ) ) )
|
||||||
|
.implicit_value( true )
|
||||||
|
.default_value( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CLI::SYM_UPGRADE_COMMAND::Perform( KIWAY& aKiway )
|
||||||
|
{
|
||||||
|
std::unique_ptr<JOB_SYM_UPGRADE> symJob = std::make_unique<JOB_SYM_UPGRADE>( true );
|
||||||
|
|
||||||
|
symJob->m_libraryPath = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
|
||||||
|
|
||||||
|
if( !wxFile::Exists( symJob->m_libraryPath ) )
|
||||||
|
{
|
||||||
|
wxFprintf( stderr, _( "Symbol file does not exist or is not accessible\n" ) );
|
||||||
|
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, symJob.get() );
|
||||||
|
|
||||||
|
return exitCode;
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* 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_SYM_UPGRADE_H
|
||||||
|
#define COMMAND_SYM_UPGRADE_H
|
||||||
|
|
||||||
|
#include "command_export_pcb_base.h"
|
||||||
|
|
||||||
|
namespace CLI
|
||||||
|
{
|
||||||
|
class SYM_UPGRADE_COMMAND : public EXPORT_PCB_BASE_COMMAND
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SYM_UPGRADE_COMMAND();
|
||||||
|
|
||||||
|
int Perform( KIWAY& aKiway ) override;
|
||||||
|
};
|
||||||
|
} // namespace CLI
|
||||||
|
|
||||||
|
#endif
|
|
@ -63,6 +63,8 @@
|
||||||
#include "cli/command_fp_upgrade.h"
|
#include "cli/command_fp_upgrade.h"
|
||||||
#include "cli/command_sch.h"
|
#include "cli/command_sch.h"
|
||||||
#include "cli/command_sch_export.h"
|
#include "cli/command_sch_export.h"
|
||||||
|
#include "cli/command_sym.h"
|
||||||
|
#include "cli/command_sym_upgrade.h"
|
||||||
#include "cli/exit_codes.h"
|
#include "cli/exit_codes.h"
|
||||||
|
|
||||||
// a dummy to quiet linking with EDA_BASE_FRAME::config();
|
// a dummy to quiet linking with EDA_BASE_FRAME::config();
|
||||||
|
@ -127,6 +129,8 @@ static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd{};
|
||||||
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{};
|
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{};
|
||||||
static CLI::FP_COMMAND fpCmd{};
|
static CLI::FP_COMMAND fpCmd{};
|
||||||
static CLI::FP_UPGRADE_COMMAND fpUpgradeCmd{};
|
static CLI::FP_UPGRADE_COMMAND fpUpgradeCmd{};
|
||||||
|
static CLI::SYM_COMMAND symCmd{};
|
||||||
|
static CLI::SYM_UPGRADE_COMMAND symUpgradeCmd{};
|
||||||
|
|
||||||
static std::vector<COMMAND_ENTRY> commandStack = {
|
static std::vector<COMMAND_ENTRY> commandStack = {
|
||||||
{
|
{
|
||||||
|
@ -166,6 +170,14 @@ static std::vector<COMMAND_ENTRY> commandStack = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
&symCmd,
|
||||||
|
{
|
||||||
|
{
|
||||||
|
&symUpgradeCmd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue