Hotglue footprint to svg export

This needs additional work
This commit is contained in:
Marek Roszko 2022-12-13 22:48:07 -05:00
parent eb10d7d1d8
commit 2f8cc84551
13 changed files with 343 additions and 17 deletions

View File

@ -30,7 +30,7 @@ class JOB_EXPORT_PCB_SVG : public JOB
public:
JOB_EXPORT_PCB_SVG( bool aIsCli ) :
JOB( "svg", aIsCli ), m_filename(), m_outputFile(), m_colorTheme(), m_mirror( false ),
m_blackAndWhite( false ), m_pageSizeMode( 0 ), m_printMaskLayer()
m_blackAndWhite( false ), m_plotDrawingSheet( true ), m_pageSizeMode( 0 ), m_printMaskLayer()
{
}
@ -41,6 +41,7 @@ public:
bool m_mirror;
bool m_blackAndWhite;
bool m_plotDrawingSheet;
int m_pageSizeMode;
LSET m_printMaskLayer;

View File

@ -0,0 +1,49 @@
/*
* 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_FP_EXPORT_SVG_H
#define JOB_FP_EXPORT_SVG_H
#include <wx/string.h>
#include "job.h"
class JOB_FP_EXPORT_SVG : public JOB
{
public:
JOB_FP_EXPORT_SVG( bool aIsCli ) :
JOB( "fpsvg", aIsCli ),
m_libraryPath(),
m_footprint(),
m_outputDirectory(),
m_blackAndWhite( false )
{
}
wxString m_libraryPath;
wxString m_footprint;
wxString m_outputDirectory;
wxString m_colorTheme;
bool m_blackAndWhite;
};
#endif

View File

@ -44,6 +44,7 @@ set( KICAD_CLI_SRCS
cli/command_export_pcb_pos.cpp
cli/command_export_pcb_step.cpp
cli/command_export_pcb_svg.cpp
cli/command_fp_export_svg.cpp
cli/command_fp_upgrade.cpp
cli/command_export_sch_pythonbom.cpp
cli/command_export_sch_netlist.cpp
@ -52,7 +53,7 @@ set( KICAD_CLI_SRCS
cli/command_sym_export_svg.cpp
cli/command_sym_upgrade.cpp
)
if( WIN32 )
if( MINGW )
# KICAD_RESOURCES variable is set by the macro.

View File

@ -30,6 +30,7 @@
#include <macros.h>
#include <wx/tokenzr.h>
#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet"
#define ARG_PAGE_SIZE "--page-size-mode"
#define ARG_MIRROR "--mirror"
@ -57,6 +58,11 @@ CLI::EXPORT_PCB_SVG_COMMAND::EXPORT_PCB_SVG_COMMAND() : EXPORT_PCB_BASE_COMMAND(
"current page size, 2 = board area only)" ) ) )
.scan<'i', int>()
.default_value( 0 );
m_argParser.add_argument( ARG_EXCLUDE_DRAWING_SHEET )
.help( UTF8STDSTR( _( "No drawing sheet" ) ) )
.implicit_value( true )
.default_value( false );
}
@ -75,6 +81,7 @@ int CLI::EXPORT_PCB_SVG_COMMAND::Perform( KIWAY& aKiway )
svgJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
svgJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
svgJob->m_colorTheme = FROM_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
svgJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
if( !wxFile::Exists( svgJob->m_filename ) )
{

View File

@ -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_FP_EXPORT_H
#define COMMAND_FP_EXPORT_H
#include "command.h"
namespace CLI
{
struct FP_EXPORT_COMMAND : public COMMAND
{
FP_EXPORT_COMMAND() : COMMAND( "export" ) {}
};
}
#endif

View File

@ -0,0 +1,71 @@
/*
* 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_fp_export_svg.h"
#include <cli/exit_codes.h>
#include "jobs/job_fp_export_svg.h"
#include <kiface_base.h>
#include <layer_ids.h>
#include <wx/crt.h>
#include <wx/dir.h>
#include <macros.h>
#include <wx/tokenzr.h>
#define ARG_FOOTPRINT "--footprint"
CLI::FP_EXPORT_SVG_COMMAND::FP_EXPORT_SVG_COMMAND() : EXPORT_PCB_BASE_COMMAND( "svg" )
{
m_argParser.add_argument( "-t", ARG_THEME )
.default_value( std::string() )
.help( UTF8STDSTR( _( "Color theme to use (will default to pcbnew settings)" ) ) );
m_argParser.add_argument( "-fp", ARG_FOOTPRINT )
.default_value( std::string() )
.help( UTF8STDSTR( _( "Specific symbol to export within the library" ) ) );
m_argParser.add_argument( ARG_BLACKANDWHITE )
.help( UTF8STDSTR( _( "Black and white only" ) ) )
.implicit_value( true )
.default_value( false );
}
int CLI::FP_EXPORT_SVG_COMMAND::Perform( KIWAY& aKiway )
{
std::unique_ptr<JOB_FP_EXPORT_SVG> svgJob = std::make_unique<JOB_FP_EXPORT_SVG>( true );
svgJob->m_libraryPath = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
svgJob->m_outputDirectory = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
svgJob->m_footprint = FROM_UTF8( m_argParser.get<std::string>( ARG_FOOTPRINT ).c_str() );
if( !wxDir::Exists( svgJob->m_libraryPath ) )
{
wxFprintf( stderr, _( "Footprint library does not exist or is not accessible\n" ) );
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
}
svgJob->m_colorTheme = FROM_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
return exitCode;
}

View File

@ -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_FP_EXPORT_SVG_H
#define COMMAND_FP_EXPORT_SVG_H
#include "command_export_pcb_base.h"
namespace CLI
{
class FP_EXPORT_SVG_COMMAND : public EXPORT_PCB_BASE_COMMAND
{
public:
FP_EXPORT_SVG_COMMAND();
int Perform( KIWAY& aKiway ) override;
};
} // namespace CLI
#endif

View File

@ -62,6 +62,8 @@
#include "cli/command_export_sch_pdf.h"
#include "cli/command_export_sch_svg.h"
#include "cli/command_fp.h"
#include "cli/command_fp_export.h"
#include "cli/command_fp_export_svg.h"
#include "cli/command_fp_upgrade.h"
#include "cli/command_sch.h"
#include "cli/command_sch_export.h"
@ -134,6 +136,8 @@ static CLI::EXPORT_SCH_NETLIST_COMMAND exportSchNetlistCmd{};
static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd{};
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{};
static CLI::FP_COMMAND fpCmd{};
static CLI::FP_EXPORT_COMMAND fpExportCmd{};
static CLI::FP_EXPORT_SVG_COMMAND fpExportSvgCmd{};
static CLI::FP_UPGRADE_COMMAND fpUpgradeCmd{};
static CLI::SYM_COMMAND symCmd{};
static CLI::SYM_EXPORT_COMMAND symExportCmd{};
@ -144,6 +148,12 @@ static std::vector<COMMAND_ENTRY> commandStack = {
{
&fpCmd,
{
{
&fpExportCmd,
{
&fpExportSvgCmd
}
},
{
&fpUpgradeCmd
}

View File

@ -286,6 +286,7 @@ void DIALOG_EXPORT_SVG::ExportSVGFile( bool aOnlyOneFile )
svgPlotOptions.m_pageSizeMode = m_rbSvgPageSizeOpt->GetSelection();
svgPlotOptions.m_colorTheme = ""; // will use default
svgPlotOptions.m_mirror = m_printMirror;
svgPlotOptions.m_plotFrame = svgPlotOptions.m_pageSizeMode == 0;
for( LSEQ seq = all_selected.Seq(); seq; ++seq )
{

View File

@ -34,7 +34,7 @@ bool PCB_PLOT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOpti
PCB_PLOT_PARAMS plot_opts;
wxString outputFile = aSvgPlotOptions.m_outputFile;
plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_pageSizeMode );
plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_plotFrame );
// Adding drill marks, for copper layers
if( ( aSvgPlotOptions.m_printMaskLayer & LSET::AllCuMask() ).any() )
@ -79,17 +79,6 @@ bool PCB_PLOT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOpti
plot_opts.SetColorSettings( mgr.GetColorSettings( cfg->m_ColorTheme ) );
COLOR_SETTINGS* theme = nullptr;
if( !aSvgPlotOptions.m_colorTheme.IsEmpty() )
{
theme = mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme );
}
if( !theme )
{
theme = mgr.GetColorSettings( cfg->m_ColorTheme );
}
LOCALE_IO toggle;
//@todo allow controlling the sheet name and path that will be displayed in the title block

View File

@ -28,6 +28,7 @@ struct PCB_PLOT_SVG_OPTIONS
bool m_mirror;
bool m_blackAndWhite;
bool m_plotFrame;
int m_pageSizeMode;

View File

@ -19,6 +19,7 @@
*/
#include "pcbnew_jobs_handler.h"
#include <jobs/job_fp_export_svg.h>
#include <jobs/job_fp_upgrade.h>
#include <jobs/job_export_pcb_gerber.h>
#include <jobs/job_export_pcb_gerbers.h>
@ -38,6 +39,7 @@
#include <pgm_base.h>
#include <pcbplot.h>
#include <board_design_settings.h>
#include <pad.h>
#include <pcbnew_settings.h>
#include <wx/crt.h>
#include <wx/dir.h>
@ -63,7 +65,10 @@ PCBNEW_JOBS_HANDLER::PCBNEW_JOBS_HANDLER()
Register( "drill",
std::bind( &PCBNEW_JOBS_HANDLER::JobExportDrill, this, std::placeholders::_1 ) );
Register( "pos", std::bind( &PCBNEW_JOBS_HANDLER::JobExportPos, this, std::placeholders::_1 ) );
Register( "fpupgrade", std::bind( &PCBNEW_JOBS_HANDLER::JobExportFpUpgrade, this, std::placeholders::_1 ) );
Register( "fpupgrade",
std::bind( &PCBNEW_JOBS_HANDLER::JobExportFpUpgrade, this, std::placeholders::_1 ) );
Register( "fpsvg",
std::bind( &PCBNEW_JOBS_HANDLER::JobExportFpSvg, this, std::placeholders::_1 ) );
}
@ -124,6 +129,7 @@ int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob )
svgPlotOptions.m_mirror = aSvgJob->m_mirror;
svgPlotOptions.m_pageSizeMode = aSvgJob->m_pageSizeMode;
svgPlotOptions.m_printMaskLayer = aSvgJob->m_printMaskLayer;
svgPlotOptions.m_plotFrame = aSvgJob->m_plotDrawingSheet;
if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) );
@ -569,7 +575,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) );
wxPrintf( _( "Loading footprint library\n" ) );
if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
{
@ -628,5 +634,119 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob )
wxPrintf( _( "Footprint library was not updated\n" ) );
}
return CLI::EXIT_CODES::OK;
}
int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob )
{
JOB_FP_EXPORT_SVG* svgJob = dynamic_cast<JOB_FP_EXPORT_SVG*>( aJob );
if( svgJob == nullptr )
return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() )
wxPrintf( _( "Loading footprint library\n" ) );
PCB_PLUGIN pcb_io( CTL_FOR_LIBRARY );
FP_CACHE fpLib( &pcb_io, svgJob->m_libraryPath );
try
{
fpLib.Load();
}
catch( ... )
{
wxFprintf( stderr, _( "Unable to load library\n" ) );
return CLI::EXIT_CODES::ERR_UNKNOWN;
}
FOOTPRINT* symbol = nullptr;
if( !svgJob->m_outputDirectory.IsEmpty() && !wxDir::Exists( svgJob->m_outputDirectory ) )
{
wxFileName::Mkdir( svgJob->m_outputDirectory );
}
int exitCode = CLI::EXIT_CODES::OK;
// Just plot all the symbols we can
FP_CACHE_FOOTPRINT_MAP& footprintMap = fpLib.GetFootprints();
bool singleFpPlotted = false;
for( FP_CACHE_FOOTPRINT_MAP::iterator it = footprintMap.begin(); it != footprintMap.end();
++it )
{
const FOOTPRINT* fp = it->second->GetFootprint();
if( !svgJob->m_footprint.IsEmpty() )
{
if( fp->GetFPID().GetLibItemName().wx_str() != svgJob->m_footprint )
{
// skip until we find the right footprint
continue;
}
else
{
singleFpPlotted = true;
}
}
exitCode = doFpExportSvg( svgJob, fp );
if( exitCode != CLI::EXIT_CODES::OK )
break;
}
if( !svgJob->m_footprint.IsEmpty() && !singleFpPlotted )
wxFprintf( stderr, _( "The given footprint could not be found to export." ) );
return CLI::EXIT_CODES::OK;
}
int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPRINT* aFootprint )
{
// the hack for now is we create fake boards containing the footprint and plot the board
// until we refactor better plot api later
std::unique_ptr<BOARD> brd;
brd.reset( CreateEmptyBoard() );
FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aFootprint->Clone() );
fp->SetLink( niluuid );
fp->SetFlags( IS_NEW );
fp->SetParent( brd.get() );
for( PAD* pad : fp->Pads() )
{
pad->SetLocalRatsnestVisible( false );
pad->SetNetCode( 0 );
}
fp->SetOrientation( ANGLE_0 );
fp->SetPosition( VECTOR2I( 0, 0 ) );
brd->Add( fp, ADD_MODE::INSERT, true );
wxFileName outputFile;
outputFile.SetPath( aSvgJob->m_outputDirectory );
outputFile.SetName( aFootprint->GetFPID().GetLibItemName().wx_str() );
outputFile.SetExt( SVGFileExtension );
wxPrintf( _( "Plotting footprint '%s' to '%s'\n" ),
aFootprint->GetFPID().GetLibItemName().wx_str(), outputFile.GetFullPath() );
PCB_PLOT_SVG_OPTIONS svgPlotOptions;
svgPlotOptions.m_blackAndWhite = aSvgJob->m_blackAndWhite;
svgPlotOptions.m_colorTheme = aSvgJob->m_colorTheme;
svgPlotOptions.m_outputFile = outputFile.GetFullPath();
svgPlotOptions.m_mirror = false;
svgPlotOptions.m_pageSizeMode = 2; // board bounding box
svgPlotOptions.m_printMaskLayer = LSET::AllLayersMask();
svgPlotOptions.m_plotFrame = false;
if( !PCB_PLOT_SVG::Plot( brd.get(), svgPlotOptions ) )
wxFprintf( stderr, _( "Error creating svg file" ) );
return CLI::EXIT_CODES::OK;
}

View File

@ -25,6 +25,8 @@
#include <pcb_plot_params.h>
class JOB_EXPORT_PCB_GERBER;
class JOB_FP_EXPORT_SVG;
class FOOTPRINT;
class PCBNEW_JOBS_HANDLER : public JOB_DISPATCHER
{
@ -39,9 +41,12 @@ public:
int JobExportDrill( JOB* aJob );
int JobExportPos( JOB* aJob );
int JobExportFpUpgrade( JOB* aJob );
int JobExportFpSvg( JOB* aJob );
private:
void populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts, JOB_EXPORT_PCB_GERBER* aJob );
void populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts,
JOB_EXPORT_PCB_GERBER* aJob );
int doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPRINT* aFootprint );
};
#endif