2022-10-04 01:53:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
|
2024-01-31 01:42:18 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2022-10-04 01:53:37 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <wx/dir.h>
|
2022-10-04 01:53:37 +00:00
|
|
|
#include "pcbnew_jobs_handler.h"
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <board_commit.h>
|
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <drc/drc_item.h>
|
2023-08-13 18:44:31 +00:00
|
|
|
#include <drc/drc_report.h>
|
2023-08-31 23:37:12 +00:00
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
2022-12-14 03:48:07 +00:00
|
|
|
#include <jobs/job_fp_export_svg.h>
|
2022-11-28 02:27:34 +00:00
|
|
|
#include <jobs/job_fp_upgrade.h>
|
2024-01-31 01:42:18 +00:00
|
|
|
#include <jobs/job_export_pcb_ipc2581.h>
|
2022-10-28 13:43:35 +00:00
|
|
|
#include <jobs/job_export_pcb_gerber.h>
|
2022-12-11 18:57:21 +00:00
|
|
|
#include <jobs/job_export_pcb_gerbers.h>
|
2022-10-28 13:43:35 +00:00
|
|
|
#include <jobs/job_export_pcb_drill.h>
|
2022-10-26 03:03:21 +00:00
|
|
|
#include <jobs/job_export_pcb_dxf.h>
|
2022-10-28 13:43:35 +00:00
|
|
|
#include <jobs/job_export_pcb_pdf.h>
|
2022-11-07 12:15:55 +00:00
|
|
|
#include <jobs/job_export_pcb_pos.h>
|
2022-10-04 01:53:37 +00:00
|
|
|
#include <jobs/job_export_pcb_svg.h>
|
2023-08-19 17:39:40 +00:00
|
|
|
#include <jobs/job_export_pcb_3d.h>
|
2024-03-03 18:11:42 +00:00
|
|
|
#include <jobs/job_pcb_render.h>
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <jobs/job_pcb_drc.h>
|
2022-10-04 01:53:37 +00:00
|
|
|
#include <cli/exit_codes.h>
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <exporters/place_file_exporter.h>
|
|
|
|
#include <exporters/step/exporter_step.h>
|
2022-10-26 03:03:21 +00:00
|
|
|
#include <plotters/plotter_dxf.h>
|
2022-10-28 13:43:35 +00:00
|
|
|
#include <plotters/plotter_gerber.h>
|
|
|
|
#include <plotters/plotters_pslike.h>
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/drc_tool.h>
|
|
|
|
#include <gerber_jobfile_writer.h>
|
2022-11-07 12:15:55 +00:00
|
|
|
#include "gerber_placefile_writer.h"
|
2022-10-28 13:43:35 +00:00
|
|
|
#include <gendrill_Excellon_writer.h>
|
|
|
|
#include <gendrill_gerber_writer.h>
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <kiface_base.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pad.h>
|
|
|
|
#include <pcb_marker.h>
|
2023-08-31 23:37:12 +00:00
|
|
|
#include <project/project_file.h>
|
2023-08-18 17:44:54 +00:00
|
|
|
#include <exporters/export_svg.h>
|
2024-02-02 23:04:56 +00:00
|
|
|
#include <kiface_ids.h>
|
|
|
|
#include <netlist_reader/pcb_netlist.h>
|
|
|
|
#include <netlist_reader/netlist_reader.h>
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <pcbnew_settings.h>
|
|
|
|
#include <pcbplot.h>
|
|
|
|
#include <pgm_base.h>
|
2024-03-03 18:11:42 +00:00
|
|
|
#include <3d_rendering/raytracing/render_3d_raytrace_ram.h>
|
|
|
|
#include <3d_rendering/track_ball.h>
|
|
|
|
#include <project_pcb.h>
|
2023-12-24 01:21:58 +00:00
|
|
|
#include <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
|
2023-06-10 22:12:32 +00:00
|
|
|
#include <reporter.h>
|
2024-01-31 01:42:18 +00:00
|
|
|
#include <string_utf8_map.h>
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2023-08-25 00:24:51 +00:00
|
|
|
#include <export_vrml.h>
|
2024-01-31 01:42:18 +00:00
|
|
|
#include <wx/wfstream.h>
|
|
|
|
#include <wx/zipstrm.h>
|
2022-10-04 01:53:37 +00:00
|
|
|
|
|
|
|
#include "pcbnew_scripting_helpers.h"
|
|
|
|
|
2023-03-04 18:02:05 +00:00
|
|
|
|
2024-03-03 18:11:42 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef TRANSPARENT
|
|
|
|
#undef TRANSPARENT
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2024-02-02 23:04:56 +00:00
|
|
|
PCBNEW_JOBS_HANDLER::PCBNEW_JOBS_HANDLER( KIWAY* aKiway ) :
|
|
|
|
JOB_DISPATCHER( aKiway )
|
2022-10-04 01:53:37 +00:00
|
|
|
{
|
2023-08-19 17:39:40 +00:00
|
|
|
Register( "3d", std::bind( &PCBNEW_JOBS_HANDLER::JobExportStep, this, std::placeholders::_1 ) );
|
2024-03-03 18:11:42 +00:00
|
|
|
Register( "render", std::bind( &PCBNEW_JOBS_HANDLER::JobExportRender, this, std::placeholders::_1 ) );
|
2022-10-26 03:03:21 +00:00
|
|
|
Register( "svg", std::bind( &PCBNEW_JOBS_HANDLER::JobExportSvg, this, std::placeholders::_1 ) );
|
|
|
|
Register( "dxf", std::bind( &PCBNEW_JOBS_HANDLER::JobExportDxf, this, std::placeholders::_1 ) );
|
2022-10-28 13:43:35 +00:00
|
|
|
Register( "pdf", std::bind( &PCBNEW_JOBS_HANDLER::JobExportPdf, this, std::placeholders::_1 ) );
|
|
|
|
Register( "gerber",
|
|
|
|
std::bind( &PCBNEW_JOBS_HANDLER::JobExportGerber, this, std::placeholders::_1 ) );
|
2022-12-11 18:57:21 +00:00
|
|
|
Register( "gerbers",
|
|
|
|
std::bind( &PCBNEW_JOBS_HANDLER::JobExportGerbers, this, std::placeholders::_1 ) );
|
2022-11-13 23:42:23 +00:00
|
|
|
Register( "drill",
|
|
|
|
std::bind( &PCBNEW_JOBS_HANDLER::JobExportDrill, this, std::placeholders::_1 ) );
|
2022-11-28 02:27:34 +00:00
|
|
|
Register( "pos", std::bind( &PCBNEW_JOBS_HANDLER::JobExportPos, this, std::placeholders::_1 ) );
|
2022-12-14 03:48:07 +00:00
|
|
|
Register( "fpupgrade",
|
|
|
|
std::bind( &PCBNEW_JOBS_HANDLER::JobExportFpUpgrade, this, std::placeholders::_1 ) );
|
|
|
|
Register( "fpsvg",
|
|
|
|
std::bind( &PCBNEW_JOBS_HANDLER::JobExportFpSvg, this, std::placeholders::_1 ) );
|
2023-08-19 17:39:40 +00:00
|
|
|
Register( "drc", std::bind( &PCBNEW_JOBS_HANDLER::JobExportDrc, this, std::placeholders::_1 ) );
|
2024-01-31 01:42:18 +00:00
|
|
|
Register( "ipc2581",
|
|
|
|
std::bind( &PCBNEW_JOBS_HANDLER::JobExportIpc2581, this, std::placeholders::_1 ) );
|
2022-10-04 01:53:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportStep( JOB* aJob )
|
|
|
|
{
|
2023-08-19 17:39:40 +00:00
|
|
|
JOB_EXPORT_PCB_3D* aStepJob = dynamic_cast<JOB_EXPORT_PCB_3D*>( aJob );
|
2022-10-04 01:53:37 +00:00
|
|
|
|
|
|
|
if( aStepJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
if( aJob->IsCli() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
2022-10-08 22:00:05 +00:00
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( aStepJob->m_filename, true );
|
2023-09-01 01:45:51 +00:00
|
|
|
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
|
2022-10-08 22:00:05 +00:00
|
|
|
|
2024-01-09 02:39:20 +00:00
|
|
|
if( aStepJob->m_outputFile.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn = brd->GetFileName();
|
|
|
|
fn.SetName( fn.GetName() );
|
|
|
|
|
|
|
|
switch( aStepJob->m_format )
|
|
|
|
{
|
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::VRML: fn.SetExt( FILEEXT::VrmlFileExtension );
|
|
|
|
break;
|
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::STEP: fn.SetExt( FILEEXT::StepFileExtension );
|
|
|
|
break;
|
2024-04-17 14:31:07 +00:00
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::BREP: fn.SetExt( FILEEXT::BrepFileExtension );
|
|
|
|
break;
|
2024-04-25 22:53:39 +00:00
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::XAO: fn.SetExt( FILEEXT::XaoFileExtension );
|
|
|
|
break;
|
2024-01-09 02:39:20 +00:00
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::GLB: fn.SetExt( FILEEXT::GltfBinaryFileExtension );
|
|
|
|
break;
|
2024-02-02 17:54:12 +00:00
|
|
|
default:
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN; // shouldnt have gotten here
|
2024-01-09 02:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aStepJob->m_outputFile = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
2023-08-25 00:24:51 +00:00
|
|
|
if( aStepJob->m_format == JOB_EXPORT_PCB_3D::FORMAT::VRML )
|
2023-08-19 15:40:45 +00:00
|
|
|
{
|
2024-01-09 02:39:20 +00:00
|
|
|
|
2023-08-25 00:24:51 +00:00
|
|
|
double scale = 0.0;
|
|
|
|
switch ( aStepJob->m_vrmlUnits )
|
|
|
|
{
|
2024-02-02 17:54:12 +00:00
|
|
|
case JOB_EXPORT_PCB_3D::VRML_UNITS::MILLIMETERS: scale = 1.0; break;
|
|
|
|
case JOB_EXPORT_PCB_3D::VRML_UNITS::METERS: scale = 0.001; break;
|
|
|
|
case JOB_EXPORT_PCB_3D::VRML_UNITS::TENTHS: scale = 10.0 / 25.4; break;
|
|
|
|
case JOB_EXPORT_PCB_3D::VRML_UNITS::INCHES: scale = 1.0 / 25.4; break;
|
2023-08-25 00:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORTER_VRML vrmlExporter( brd );
|
|
|
|
wxString messages;
|
|
|
|
|
|
|
|
double originX = pcbIUScale.IUTomm( aStepJob->m_xOrigin );
|
|
|
|
double originY = pcbIUScale.IUTomm( aStepJob->m_yOrigin );
|
|
|
|
|
|
|
|
if( !aStepJob->m_hasUserOrigin )
|
|
|
|
{
|
2024-05-06 20:34:40 +00:00
|
|
|
BOX2I bbox = brd->ComputeBoundingBox( true, false );
|
2023-08-25 00:24:51 +00:00
|
|
|
originX = pcbIUScale.IUTomm( bbox.GetCenter().x );
|
|
|
|
originY = pcbIUScale.IUTomm( bbox.GetCenter().y );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool success = vrmlExporter.ExportVRML_File(
|
|
|
|
brd->GetProject(), &messages, aStepJob->m_outputFile, scale,
|
2024-03-04 15:05:53 +00:00
|
|
|
aStepJob->m_includeUnspecified, aStepJob->m_includeDNP,
|
2023-08-25 00:24:51 +00:00
|
|
|
!aStepJob->m_vrmlModelDir.IsEmpty(), aStepJob->m_vrmlRelativePaths,
|
|
|
|
aStepJob->m_vrmlModelDir, originX, originY );
|
|
|
|
|
|
|
|
if ( success )
|
|
|
|
{
|
2024-02-02 17:54:12 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Successfully exported VRML to %s" ),
|
|
|
|
aStepJob->m_outputFile ),
|
2023-08-25 00:24:51 +00:00
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_reporter->Report( _( "Error exporting VRML" ), RPT_SEVERITY_ERROR );
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
}
|
2023-08-19 15:40:45 +00:00
|
|
|
}
|
2023-08-25 00:24:51 +00:00
|
|
|
else
|
2022-10-08 22:00:05 +00:00
|
|
|
{
|
2023-08-25 00:24:51 +00:00
|
|
|
EXPORTER_STEP_PARAMS params;
|
2024-04-22 00:39:43 +00:00
|
|
|
params.m_exportBoardBody = aStepJob->m_exportBoardBody;
|
|
|
|
params.m_exportComponents = aStepJob->m_exportComponents;
|
|
|
|
params.m_exportTracksVias = aStepJob->m_exportTracks;
|
2024-05-19 01:28:43 +00:00
|
|
|
params.m_exportPads = aStepJob->m_exportPads;
|
2023-08-25 00:24:51 +00:00
|
|
|
params.m_exportZones = aStepJob->m_exportZones;
|
2024-04-22 00:39:43 +00:00
|
|
|
params.m_exportInnerCopper = aStepJob->m_exportInnerCopper;
|
2024-05-19 01:28:43 +00:00
|
|
|
params.m_exportSilkscreen = aStepJob->m_exportSilkscreen;
|
|
|
|
params.m_exportSoldermask = aStepJob->m_exportSoldermask;
|
2024-04-19 00:42:41 +00:00
|
|
|
params.m_fuseShapes = aStepJob->m_fuseShapes;
|
2023-08-25 00:24:51 +00:00
|
|
|
params.m_includeUnspecified = aStepJob->m_includeUnspecified;
|
|
|
|
params.m_includeDNP = aStepJob->m_includeDNP;
|
|
|
|
params.m_BoardOutlinesChainingEpsilon = aStepJob->m_BoardOutlinesChainingEpsilon;
|
|
|
|
params.m_overwrite = aStepJob->m_overwrite;
|
|
|
|
params.m_substModels = aStepJob->m_substModels;
|
|
|
|
params.m_origin = VECTOR2D( aStepJob->m_xOrigin, aStepJob->m_yOrigin );
|
|
|
|
params.m_useDrillOrigin = aStepJob->m_useDrillOrigin;
|
|
|
|
params.m_useGridOrigin = aStepJob->m_useGridOrigin;
|
|
|
|
params.m_boardOnly = aStepJob->m_boardOnly;
|
2023-11-19 12:21:25 +00:00
|
|
|
params.m_optimizeStep = aStepJob->m_optimizeStep;
|
2024-04-24 15:28:44 +00:00
|
|
|
params.m_netFilter = aStepJob->m_netFilter;
|
2023-08-25 00:24:51 +00:00
|
|
|
|
|
|
|
switch( aStepJob->m_format )
|
|
|
|
{
|
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::STEP:
|
|
|
|
params.m_format = EXPORTER_STEP_PARAMS::FORMAT::STEP;
|
|
|
|
break;
|
2024-04-17 14:31:07 +00:00
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::BREP:
|
|
|
|
params.m_format = EXPORTER_STEP_PARAMS::FORMAT::BREP;
|
|
|
|
break;
|
2024-04-25 22:53:39 +00:00
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::XAO:
|
|
|
|
params.m_format = EXPORTER_STEP_PARAMS::FORMAT::XAO;
|
|
|
|
break;
|
2023-08-25 00:24:51 +00:00
|
|
|
case JOB_EXPORT_PCB_3D::FORMAT::GLB:
|
|
|
|
params.m_format = EXPORTER_STEP_PARAMS::FORMAT::GLB;
|
|
|
|
break;
|
2024-02-02 17:54:12 +00:00
|
|
|
default:
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN; // shouldnt have gotten here
|
2023-08-25 00:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORTER_STEP stepExporter( brd, params );
|
|
|
|
stepExporter.m_outputFile = aStepJob->m_outputFile;
|
|
|
|
|
|
|
|
if( !stepExporter.Export() )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
2022-10-08 22:00:05 +00:00
|
|
|
}
|
2022-10-04 01:53:37 +00:00
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
return CLI::EXIT_CODES::OK;
|
2022-10-04 01:53:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-03 18:11:42 +00:00
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportRender( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_PCB_RENDER* aRenderJob = dynamic_cast<JOB_PCB_RENDER*>( aJob );
|
|
|
|
|
|
|
|
if( aRenderJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
|
|
|
|
|
|
|
BOARD* brd = LoadBoard( aRenderJob->m_filename, true );
|
|
|
|
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
|
|
|
|
|
2024-05-15 11:46:49 +00:00
|
|
|
BOARD_ADAPTER boardAdapter;
|
2024-03-03 18:11:42 +00:00
|
|
|
|
2024-05-15 11:46:49 +00:00
|
|
|
boardAdapter.SetBoard( brd );
|
|
|
|
boardAdapter.m_IsBoardView = false;
|
|
|
|
boardAdapter.m_IsPreviewer =
|
2024-03-03 18:11:42 +00:00
|
|
|
true; // Force display 3D models, regardless the 3D viewer options
|
|
|
|
|
|
|
|
EDA_3D_VIEWER_SETTINGS* cfg =
|
|
|
|
Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
|
|
|
|
|
|
|
|
if( aRenderJob->m_quality == JOB_PCB_RENDER::QUALITY::BASIC )
|
|
|
|
{
|
|
|
|
// Silkscreen is pixelated without antialiasing
|
|
|
|
cfg->m_Render.raytrace_anti_aliasing = true;
|
|
|
|
|
|
|
|
cfg->m_Render.raytrace_backfloor = false;
|
|
|
|
cfg->m_Render.raytrace_post_processing = false;
|
|
|
|
|
|
|
|
cfg->m_Render.raytrace_procedural_textures = false;
|
|
|
|
cfg->m_Render.raytrace_reflections = false;
|
|
|
|
cfg->m_Render.raytrace_shadows = false;
|
|
|
|
|
|
|
|
// Better colors
|
|
|
|
cfg->m_Render.differentiate_plated_copper = true;
|
|
|
|
|
|
|
|
// Tracks below soldermask are not visible without refractions
|
|
|
|
cfg->m_Render.raytrace_refractions = true;
|
|
|
|
cfg->m_Render.raytrace_recursivelevel_refractions = 1;
|
|
|
|
}
|
|
|
|
else if( aRenderJob->m_quality == JOB_PCB_RENDER::QUALITY::HIGH )
|
|
|
|
{
|
|
|
|
cfg->m_Render.raytrace_anti_aliasing = true;
|
|
|
|
cfg->m_Render.raytrace_backfloor = true;
|
|
|
|
cfg->m_Render.raytrace_post_processing = true;
|
|
|
|
cfg->m_Render.raytrace_procedural_textures = true;
|
|
|
|
cfg->m_Render.raytrace_reflections = true;
|
|
|
|
cfg->m_Render.raytrace_shadows = true;
|
|
|
|
cfg->m_Render.raytrace_refractions = true;
|
|
|
|
cfg->m_Render.differentiate_plated_copper = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aRenderJob->m_floor )
|
|
|
|
{
|
|
|
|
cfg->m_Render.raytrace_backfloor = true;
|
|
|
|
cfg->m_Render.raytrace_shadows = true;
|
|
|
|
cfg->m_Render.raytrace_post_processing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg->m_CurrentPreset = aRenderJob->m_colorPreset;
|
2024-05-15 11:46:49 +00:00
|
|
|
boardAdapter.m_Cfg = cfg;
|
|
|
|
|
|
|
|
if( aRenderJob->m_bgStyle == JOB_PCB_RENDER::BG_STYLE::TRANSPARENT
|
|
|
|
|| ( aRenderJob->m_bgStyle == JOB_PCB_RENDER::BG_STYLE::DEFAULT
|
|
|
|
&& aRenderJob->m_format == JOB_PCB_RENDER::FORMAT::PNG ) )
|
|
|
|
{
|
|
|
|
boardAdapter.m_ColorOverrides[LAYER_3D_BACKGROUND_TOP] = COLOR4D( 1.0, 1.0, 1.0, 0.0 );
|
|
|
|
boardAdapter.m_ColorOverrides[LAYER_3D_BACKGROUND_BOTTOM] = COLOR4D( 1.0, 1.0, 1.0, 0.0 );
|
|
|
|
}
|
2024-03-03 18:11:42 +00:00
|
|
|
|
2024-05-15 11:46:49 +00:00
|
|
|
boardAdapter.Set3dCacheManager( PROJECT_PCB::Get3DCacheManager( brd->GetProject() ) );
|
2024-03-03 18:11:42 +00:00
|
|
|
|
|
|
|
static std::map<JOB_PCB_RENDER::SIDE, VIEW3D_TYPE> s_viewCmdMap = {
|
|
|
|
{ JOB_PCB_RENDER::SIDE::TOP, VIEW3D_TYPE::VIEW3D_TOP },
|
|
|
|
{ JOB_PCB_RENDER::SIDE::BOTTOM, VIEW3D_TYPE::VIEW3D_BOTTOM },
|
|
|
|
{ JOB_PCB_RENDER::SIDE::LEFT, VIEW3D_TYPE::VIEW3D_LEFT },
|
|
|
|
{ JOB_PCB_RENDER::SIDE::RIGHT, VIEW3D_TYPE::VIEW3D_RIGHT },
|
|
|
|
{ JOB_PCB_RENDER::SIDE::FRONT, VIEW3D_TYPE::VIEW3D_FRONT },
|
|
|
|
{ JOB_PCB_RENDER::SIDE::BACK, VIEW3D_TYPE::VIEW3D_BACK },
|
|
|
|
};
|
|
|
|
|
|
|
|
PROJECTION_TYPE projection =
|
|
|
|
aRenderJob->m_perspective ? PROJECTION_TYPE::PERSPECTIVE : PROJECTION_TYPE::ORTHO;
|
|
|
|
|
|
|
|
wxSize windowSize( aRenderJob->m_width, aRenderJob->m_height );
|
|
|
|
TRACK_BALL camera( 2 * RANGE_SCALE_3D );
|
|
|
|
|
|
|
|
camera.SetProjection( projection );
|
|
|
|
camera.SetCurWindowSize( windowSize );
|
|
|
|
|
2024-05-15 11:46:49 +00:00
|
|
|
RENDER_3D_RAYTRACE_RAM raytrace( boardAdapter, camera );
|
2024-03-03 18:11:42 +00:00
|
|
|
raytrace.SetCurWindowSize( windowSize );
|
|
|
|
|
|
|
|
for( bool first = true; raytrace.Redraw( false, m_reporter, m_reporter ); first = false )
|
|
|
|
{
|
|
|
|
if( first )
|
|
|
|
{
|
2024-05-15 11:46:49 +00:00
|
|
|
const float cmTo3D = boardAdapter.BiuTo3dUnits() * pcbIUScale.mmToIU( 10.0 );
|
2024-03-03 18:11:42 +00:00
|
|
|
|
|
|
|
// First redraw resets lookat point to the board center, so set up the camera here
|
|
|
|
camera.ViewCommand_T1( s_viewCmdMap[aRenderJob->m_side] );
|
|
|
|
|
|
|
|
camera.SetLookAtPos_T1(
|
|
|
|
camera.GetLookAtPos_T1()
|
|
|
|
+ SFVEC3F( aRenderJob->m_pivot.x, aRenderJob->m_pivot.y, aRenderJob->m_pivot.z )
|
|
|
|
* cmTo3D );
|
|
|
|
|
|
|
|
camera.Pan_T1(
|
|
|
|
SFVEC3F( aRenderJob->m_pan.x, aRenderJob->m_pan.y, aRenderJob->m_pan.z ) );
|
|
|
|
|
|
|
|
camera.Zoom_T1( aRenderJob->m_zoom );
|
|
|
|
|
|
|
|
camera.RotateX_T1( DEG2RAD( aRenderJob->m_rotation.x ) );
|
|
|
|
camera.RotateY_T1( DEG2RAD( aRenderJob->m_rotation.y ) );
|
|
|
|
camera.RotateZ_T1( DEG2RAD( aRenderJob->m_rotation.z ) );
|
|
|
|
|
|
|
|
camera.Interpolate( 1.0f );
|
|
|
|
camera.SetT0_and_T1_current_T();
|
|
|
|
camera.ParametersChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLubyte* rgbaBuffer = raytrace.GetBuffer();
|
|
|
|
wxSize realSize = raytrace.GetRealBufferSize();
|
|
|
|
bool success = !!rgbaBuffer;
|
|
|
|
|
|
|
|
if( rgbaBuffer )
|
|
|
|
{
|
|
|
|
const unsigned int wxh = realSize.x * realSize.y;
|
|
|
|
|
|
|
|
unsigned char* rgbBuffer = (unsigned char*) malloc( wxh * 3 );
|
|
|
|
unsigned char* alphaBuffer = (unsigned char*) malloc( wxh );
|
|
|
|
|
|
|
|
unsigned char* rgbaPtr = rgbaBuffer;
|
|
|
|
unsigned char* rgbPtr = rgbBuffer;
|
|
|
|
unsigned char* alphaPtr = alphaBuffer;
|
|
|
|
|
|
|
|
for( int y = 0; y < realSize.y; y++ )
|
|
|
|
{
|
|
|
|
for( int x = 0; x < realSize.x; x++ )
|
|
|
|
{
|
|
|
|
rgbPtr[0] = rgbaPtr[0];
|
|
|
|
rgbPtr[1] = rgbaPtr[1];
|
|
|
|
rgbPtr[2] = rgbaPtr[2];
|
|
|
|
alphaPtr[0] = rgbaPtr[3];
|
|
|
|
|
|
|
|
rgbaPtr += 4;
|
|
|
|
rgbPtr += 3;
|
|
|
|
alphaPtr += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxImage image( realSize );
|
|
|
|
image.SetData( rgbBuffer );
|
|
|
|
image.SetAlpha( alphaBuffer );
|
|
|
|
image = image.Mirror( false );
|
|
|
|
|
|
|
|
image.SetOption( wxIMAGE_OPTION_QUALITY, 90 );
|
|
|
|
image.SaveFile( aRenderJob->m_outputFile,
|
|
|
|
aRenderJob->m_format == JOB_PCB_RENDER::FORMAT::PNG ? wxBITMAP_TYPE_PNG
|
|
|
|
: wxBITMAP_TYPE_JPEG );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_reporter->Report( wxString::Format( _( "Actual image size: %dx%d" ), realSize.x, realSize.y )
|
|
|
|
+ wxS( "\n" ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
|
|
|
|
if( success )
|
|
|
|
m_reporter->Report( _( "Successfully created 3D render image" ) + wxS( "\n" ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
else
|
|
|
|
m_reporter->Report( _( "Error creating 3D render image" ) + wxS( "\n" ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
|
|
|
|
return CLI::EXIT_CODES::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-04 01:53:37 +00:00
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_EXPORT_PCB_SVG* aSvgJob = dynamic_cast<JOB_EXPORT_PCB_SVG*>( aJob );
|
|
|
|
|
|
|
|
if( aSvgJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
PCB_PLOT_SVG_OPTIONS svgPlotOptions;
|
|
|
|
svgPlotOptions.m_blackAndWhite = aSvgJob->m_blackAndWhite;
|
|
|
|
svgPlotOptions.m_colorTheme = aSvgJob->m_colorTheme;
|
|
|
|
svgPlotOptions.m_outputFile = aSvgJob->m_outputFile;
|
|
|
|
svgPlotOptions.m_mirror = aSvgJob->m_mirror;
|
2023-06-03 18:44:03 +00:00
|
|
|
svgPlotOptions.m_negative = aSvgJob->m_negative;
|
2022-10-04 01:53:37 +00:00
|
|
|
svgPlotOptions.m_pageSizeMode = aSvgJob->m_pageSizeMode;
|
|
|
|
svgPlotOptions.m_printMaskLayer = aSvgJob->m_printMaskLayer;
|
2022-12-14 03:48:07 +00:00
|
|
|
svgPlotOptions.m_plotFrame = aSvgJob->m_plotDrawingSheet;
|
2023-08-05 16:18:18 +00:00
|
|
|
svgPlotOptions.m_drillShapeOption = aSvgJob->m_drillShapeOption;
|
2022-10-04 01:53:37 +00:00
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
2022-10-04 01:53:37 +00:00
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( aSvgJob->m_filename, true );
|
2023-08-31 23:37:12 +00:00
|
|
|
loadOverrideDrawingSheet( brd, aSvgJob->m_drawingSheet );
|
2023-09-01 01:45:51 +00:00
|
|
|
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
|
2022-10-04 01:53:37 +00:00
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
|
|
|
{
|
2023-08-18 17:44:54 +00:00
|
|
|
if( EXPORT_SVG::Plot( brd, svgPlotOptions ) )
|
2024-02-12 02:12:21 +00:00
|
|
|
m_reporter->Report( _( "Successfully created svg file" ) + wxS( "\n" ), RPT_SEVERITY_INFO );
|
2022-10-04 01:53:37 +00:00
|
|
|
else
|
2024-02-12 02:12:21 +00:00
|
|
|
m_reporter->Report( _( "Error creating svg file" ) + wxS( "\n" ), RPT_SEVERITY_ERROR );
|
2022-10-04 01:53:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 03:03:21 +00:00
|
|
|
return CLI::EXIT_CODES::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_EXPORT_PCB_DXF* aDxfJob = dynamic_cast<JOB_EXPORT_PCB_DXF*>( aJob );
|
|
|
|
|
|
|
|
if( aDxfJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
2022-10-26 03:03:21 +00:00
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( aDxfJob->m_filename, true );
|
2023-08-31 23:37:12 +00:00
|
|
|
loadOverrideDrawingSheet( brd, aDxfJob->m_drawingSheet );
|
2023-09-01 01:45:51 +00:00
|
|
|
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
|
2022-10-26 03:03:21 +00:00
|
|
|
|
|
|
|
if( aDxfJob->m_outputFile.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn = brd->GetFileName();
|
|
|
|
fn.SetName( fn.GetName() );
|
2022-10-28 13:43:35 +00:00
|
|
|
fn.SetExt( GetDefaultPlotExtension( PLOT_FORMAT::DXF ) );
|
2022-10-26 03:03:21 +00:00
|
|
|
|
|
|
|
aDxfJob->m_outputFile = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_PLOT_PARAMS plotOpts;
|
|
|
|
plotOpts.SetFormat( PLOT_FORMAT::DXF );
|
|
|
|
|
|
|
|
plotOpts.SetDXFPlotPolygonMode( aDxfJob->m_plotGraphicItemsUsingContours );
|
|
|
|
|
|
|
|
if( aDxfJob->m_dxfUnits == JOB_EXPORT_PCB_DXF::DXF_UNITS::MILLIMETERS )
|
|
|
|
plotOpts.SetDXFPlotUnits( DXF_UNITS::MILLIMETERS );
|
|
|
|
else
|
|
|
|
plotOpts.SetDXFPlotUnits( DXF_UNITS::INCHES );
|
2023-03-04 18:02:05 +00:00
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
plotOpts.SetPlotFrameRef( aDxfJob->m_plotBorderTitleBlocks );
|
2022-10-26 03:03:21 +00:00
|
|
|
plotOpts.SetPlotValue( aDxfJob->m_plotFootprintValues );
|
|
|
|
plotOpts.SetPlotReference( aDxfJob->m_plotRefDes );
|
|
|
|
plotOpts.SetLayerSelection( aDxfJob->m_printMaskLayer );
|
|
|
|
|
2024-05-13 19:03:45 +00:00
|
|
|
PCB_LAYER_ID layer = UNDEFINED_LAYER;
|
|
|
|
wxString layerName;
|
|
|
|
wxString sheetName;
|
|
|
|
wxString sheetPath;
|
|
|
|
|
|
|
|
if( aDxfJob->m_printMaskLayer.size() == 1 )
|
|
|
|
{
|
|
|
|
layer = aDxfJob->m_printMaskLayer.front();
|
|
|
|
layerName = brd->GetLayerName( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "LAYER" ) ) )
|
|
|
|
layerName = aJob->GetVarOverrides().at( wxT( "LAYER" ) );
|
|
|
|
|
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "SHEETNAME" ) ) )
|
|
|
|
sheetName = aJob->GetVarOverrides().at( wxT( "SHEETNAME" ) );
|
|
|
|
|
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "SHEETPATH" ) ) )
|
|
|
|
sheetPath = aJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
|
|
|
|
|
|
|
|
DXF_PLOTTER* plotter = (DXF_PLOTTER*) StartPlotBoard( brd, &plotOpts, layer, layerName,
|
|
|
|
aDxfJob->m_outputFile, sheetName,
|
|
|
|
sheetPath );
|
2022-10-26 03:03:21 +00:00
|
|
|
|
|
|
|
if( plotter )
|
|
|
|
{
|
2023-09-28 14:59:11 +00:00
|
|
|
PlotBoardLayers( brd, plotter, aDxfJob->m_printMaskLayer, plotOpts );
|
2022-10-26 03:03:21 +00:00
|
|
|
plotter->EndPlot();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete plotter;
|
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
return CLI::EXIT_CODES::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportPdf( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_EXPORT_PCB_PDF* aPdfJob = dynamic_cast<JOB_EXPORT_PCB_PDF*>( aJob );
|
|
|
|
|
|
|
|
if( aPdfJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
2022-10-28 13:43:35 +00:00
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( aPdfJob->m_filename, true );
|
2023-08-31 23:37:12 +00:00
|
|
|
loadOverrideDrawingSheet( brd, aPdfJob->m_drawingSheet );
|
2023-09-01 01:45:51 +00:00
|
|
|
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
|
2022-10-28 13:43:35 +00:00
|
|
|
|
|
|
|
if( aPdfJob->m_outputFile.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn = brd->GetFileName();
|
|
|
|
fn.SetName( fn.GetName() );
|
|
|
|
fn.SetExt( GetDefaultPlotExtension( PLOT_FORMAT::PDF ) );
|
|
|
|
|
|
|
|
aPdfJob->m_outputFile = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_PLOT_PARAMS plotOpts;
|
|
|
|
plotOpts.SetFormat( PLOT_FORMAT::PDF );
|
|
|
|
|
|
|
|
plotOpts.SetPlotFrameRef( aPdfJob->m_plotBorderTitleBlocks );
|
|
|
|
plotOpts.SetPlotValue( aPdfJob->m_plotFootprintValues );
|
|
|
|
plotOpts.SetPlotReference( aPdfJob->m_plotRefDes );
|
|
|
|
|
|
|
|
plotOpts.SetLayerSelection( aPdfJob->m_printMaskLayer );
|
|
|
|
|
2023-02-07 19:15:34 +00:00
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
plotOpts.SetColorSettings( mgr.GetColorSettings( aPdfJob->m_colorTheme ) );
|
2023-06-10 01:54:11 +00:00
|
|
|
plotOpts.SetMirror( aPdfJob->m_mirror );
|
2023-02-07 19:15:34 +00:00
|
|
|
plotOpts.SetBlackAndWhite( aPdfJob->m_blackAndWhite );
|
2023-06-03 18:44:03 +00:00
|
|
|
plotOpts.SetNegative( aPdfJob->m_negative );
|
2023-02-07 19:15:34 +00:00
|
|
|
|
2023-08-05 16:18:18 +00:00
|
|
|
switch( aPdfJob->m_drillShapeOption )
|
|
|
|
{
|
|
|
|
default:
|
2024-02-02 17:54:12 +00:00
|
|
|
case 0: plotOpts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE ); break;
|
|
|
|
case 1: plotOpts.SetDrillMarksType( DRILL_MARKS::SMALL_DRILL_SHAPE ); break;
|
|
|
|
case 2: plotOpts.SetDrillMarksType( DRILL_MARKS::FULL_DRILL_SHAPE ); break;
|
2023-08-05 16:18:18 +00:00
|
|
|
}
|
|
|
|
|
2024-05-13 19:03:45 +00:00
|
|
|
PCB_LAYER_ID layer = UNDEFINED_LAYER;
|
|
|
|
wxString layerName;
|
|
|
|
wxString sheetName;
|
|
|
|
wxString sheetPath;
|
|
|
|
|
|
|
|
if( aPdfJob->m_printMaskLayer.size() == 1 )
|
|
|
|
{
|
|
|
|
layer = aPdfJob->m_printMaskLayer.front();
|
|
|
|
layerName = brd->GetLayerName( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aPdfJob->GetVarOverrides().contains( wxT( "LAYER" ) ) )
|
|
|
|
layerName = aPdfJob->GetVarOverrides().at( wxT( "LAYER" ) );
|
|
|
|
|
|
|
|
if( aPdfJob->GetVarOverrides().contains( wxT( "SHEETNAME" ) ) )
|
|
|
|
sheetName = aPdfJob->GetVarOverrides().at( wxT( "SHEETNAME" ) );
|
|
|
|
|
|
|
|
if( aPdfJob->GetVarOverrides().contains( wxT( "SHEETPATH" ) ) )
|
|
|
|
sheetPath = aPdfJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
|
|
|
|
|
|
|
|
PDF_PLOTTER* plotter = (PDF_PLOTTER*) StartPlotBoard( brd, &plotOpts, layer, layerName,
|
|
|
|
aPdfJob->m_outputFile, sheetName,
|
|
|
|
sheetPath );
|
2022-10-28 13:43:35 +00:00
|
|
|
|
|
|
|
if( plotter )
|
|
|
|
{
|
2023-09-28 14:59:11 +00:00
|
|
|
PlotBoardLayers( brd, plotter, aPdfJob->m_printMaskLayer, plotOpts );
|
2023-04-30 17:09:40 +00:00
|
|
|
PlotInteractiveLayer( brd, plotter, plotOpts );
|
2022-10-28 13:43:35 +00:00
|
|
|
plotter->EndPlot();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete plotter;
|
|
|
|
|
|
|
|
return CLI::EXIT_CODES::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 18:57:21 +00:00
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
|
|
|
|
{
|
2023-04-21 03:28:32 +00:00
|
|
|
int exitCode = CLI::EXIT_CODES::OK;
|
2022-12-11 18:57:21 +00:00
|
|
|
JOB_EXPORT_PCB_GERBERS* aGerberJob = dynamic_cast<JOB_EXPORT_PCB_GERBERS*>( aJob );
|
|
|
|
|
|
|
|
if( aGerberJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
2022-12-11 18:57:21 +00:00
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( aGerberJob->m_filename, true );
|
2023-08-31 23:37:12 +00:00
|
|
|
loadOverrideDrawingSheet( brd, aGerberJob->m_drawingSheet );
|
2024-03-11 12:33:52 +00:00
|
|
|
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
|
2023-08-31 23:37:12 +00:00
|
|
|
|
2023-12-12 15:59:58 +00:00
|
|
|
PCB_PLOT_PARAMS boardPlotOptions = brd->GetPlotOptions();
|
2023-01-09 04:03:30 +00:00
|
|
|
LSET plotOnAllLayersSelection = boardPlotOptions.GetPlotOnAllLayersSelection();
|
|
|
|
GERBER_JOBFILE_WRITER jobfile_writer( brd );
|
2022-12-11 18:57:21 +00:00
|
|
|
|
|
|
|
wxString fileExt;
|
|
|
|
|
|
|
|
if( aGerberJob->m_useBoardPlotParams )
|
|
|
|
{
|
2023-12-12 15:59:58 +00:00
|
|
|
// The board plot options are saved with all copper layers enabled, even those that don't
|
|
|
|
// exist in the current stackup. This is done so the layers are automatically enabled in the plot
|
|
|
|
// dialog when the user enables them. We need to filter out these not-enabled layers here so
|
|
|
|
// we don't plot 32 layers when we only have 4, etc.
|
|
|
|
LSET plotLayers = ( boardPlotOptions.GetLayerSelection() & LSET::AllNonCuMask() )
|
|
|
|
| ( brd->GetEnabledLayers() & LSET::AllCuMask() );
|
|
|
|
aGerberJob->m_printMaskLayer = plotLayers.SeqStackupForPlotting();
|
2022-12-11 18:57:21 +00:00
|
|
|
aGerberJob->m_layersIncludeOnAll = boardPlotOptions.GetPlotOnAllLayersSelection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// default to the board enabled layers
|
|
|
|
if( aGerberJob->m_printMaskLayer == 0 )
|
2023-12-11 20:07:58 +00:00
|
|
|
aGerberJob->m_printMaskLayer = brd->GetEnabledLayers().SeqStackupForPlotting();
|
2022-12-11 18:57:21 +00:00
|
|
|
|
|
|
|
if( aGerberJob->m_layersIncludeOnAllSet )
|
|
|
|
aGerberJob->m_layersIncludeOnAll = plotOnAllLayersSelection;
|
|
|
|
}
|
|
|
|
|
2023-09-28 14:59:11 +00:00
|
|
|
for( LSEQ seq = LSET( aGerberJob->m_printMaskLayer ).UIOrder(); seq; ++seq )
|
2022-12-11 18:57:21 +00:00
|
|
|
{
|
|
|
|
LSEQ plotSequence;
|
|
|
|
|
|
|
|
// Base layer always gets plotted first.
|
|
|
|
plotSequence.push_back( *seq );
|
|
|
|
|
|
|
|
// Now all the "include on all" layers
|
|
|
|
for( LSEQ seqAll = aGerberJob->m_layersIncludeOnAll.UIOrder(); seqAll; ++seqAll )
|
|
|
|
{
|
|
|
|
// Don't plot the same layer more than once;
|
|
|
|
if( find( plotSequence.begin(), plotSequence.end(), *seqAll ) != plotSequence.end() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
plotSequence.push_back( *seqAll );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pick the basename from the board file
|
2024-05-13 19:03:45 +00:00
|
|
|
wxFileName fn( brd->GetFileName() );
|
|
|
|
PCB_LAYER_ID layer = *seq;
|
|
|
|
wxString layerName = brd->GetLayerName( layer );
|
|
|
|
wxString sheetName;
|
|
|
|
wxString sheetPath;
|
2022-12-11 18:57:21 +00:00
|
|
|
PCB_PLOT_PARAMS plotOpts;
|
|
|
|
|
|
|
|
if( aGerberJob->m_useBoardPlotParams )
|
|
|
|
plotOpts = boardPlotOptions;
|
|
|
|
else
|
|
|
|
populateGerberPlotOptionsFromJob( plotOpts, aGerberJob );
|
|
|
|
|
2023-06-16 11:13:45 +00:00
|
|
|
if( plotOpts.GetUseGerberProtelExtensions() )
|
|
|
|
fileExt = GetGerberProtelExtension( layer );
|
|
|
|
else
|
2023-12-28 02:10:01 +00:00
|
|
|
fileExt = FILEEXT::GerberFileExtension;
|
2023-06-16 11:13:45 +00:00
|
|
|
|
2024-05-13 19:03:45 +00:00
|
|
|
BuildPlotFileName( &fn, aGerberJob->m_outputFile, layerName, fileExt );
|
2022-12-11 18:57:21 +00:00
|
|
|
wxString fullname = fn.GetFullName();
|
|
|
|
|
2023-01-09 04:03:30 +00:00
|
|
|
jobfile_writer.AddGbrFile( layer, fullname );
|
|
|
|
|
2024-05-13 19:03:45 +00:00
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "LAYER" ) ) )
|
|
|
|
layerName = aJob->GetVarOverrides().at( wxT( "LAYER" ) );
|
|
|
|
|
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "SHEETNAME" ) ) )
|
|
|
|
sheetName = aJob->GetVarOverrides().at( wxT( "SHEETNAME" ) );
|
|
|
|
|
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "SHEETPATH" ) ) )
|
|
|
|
sheetPath = aJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
|
|
|
|
|
2022-12-11 18:57:21 +00:00
|
|
|
// We are feeding it one layer at the start here to silence a logic check
|
2024-05-13 19:03:45 +00:00
|
|
|
GERBER_PLOTTER* plotter = (GERBER_PLOTTER*) StartPlotBoard( brd, &plotOpts, layer,
|
|
|
|
layerName, fn.GetFullPath(),
|
|
|
|
sheetName, sheetPath );
|
2022-12-11 18:57:21 +00:00
|
|
|
|
|
|
|
if( plotter )
|
|
|
|
{
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Plotted to '%s'.\n" ), fn.GetFullPath() ),
|
|
|
|
RPT_SEVERITY_ACTION );
|
2022-12-11 18:57:21 +00:00
|
|
|
PlotBoardLayers( brd, plotter, plotSequence, plotOpts );
|
|
|
|
plotter->EndPlot();
|
|
|
|
}
|
2023-04-21 03:28:32 +00:00
|
|
|
else
|
|
|
|
{
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Failed to plot to '%s'.\n" ),
|
|
|
|
fn.GetFullPath() ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2023-04-21 03:28:32 +00:00
|
|
|
exitCode = CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
}
|
2022-12-11 18:57:21 +00:00
|
|
|
|
|
|
|
delete plotter;
|
|
|
|
}
|
|
|
|
|
2023-01-09 04:03:30 +00:00
|
|
|
wxFileName fn( aGerberJob->m_filename );
|
2023-06-16 11:13:45 +00:00
|
|
|
|
2023-01-09 04:03:30 +00:00
|
|
|
// Build gerber job file from basename
|
2023-12-28 02:10:01 +00:00
|
|
|
BuildPlotFileName( &fn, aGerberJob->m_outputFile, wxT( "job" ),
|
|
|
|
FILEEXT::GerberJobFileExtension );
|
2023-01-09 04:03:30 +00:00
|
|
|
jobfile_writer.CreateJobFile( fn.GetFullPath() );
|
|
|
|
|
2023-04-21 03:28:32 +00:00
|
|
|
return exitCode;
|
2022-12-11 18:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-02 17:54:12 +00:00
|
|
|
void PCBNEW_JOBS_HANDLER::populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts,
|
2022-12-11 18:57:21 +00:00
|
|
|
JOB_EXPORT_PCB_GERBER* aJob )
|
|
|
|
{
|
|
|
|
aPlotOpts.SetFormat( PLOT_FORMAT::GERBER );
|
|
|
|
|
|
|
|
aPlotOpts.SetPlotFrameRef( aJob->m_plotBorderTitleBlocks );
|
|
|
|
aPlotOpts.SetPlotValue( aJob->m_plotFootprintValues );
|
|
|
|
aPlotOpts.SetPlotReference( aJob->m_plotRefDes );
|
|
|
|
|
|
|
|
aPlotOpts.SetSubtractMaskFromSilk( aJob->m_subtractSolderMaskFromSilk );
|
2023-03-04 18:02:05 +00:00
|
|
|
|
2022-12-11 18:57:21 +00:00
|
|
|
// Always disable plot pad holes
|
|
|
|
aPlotOpts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE );
|
|
|
|
|
|
|
|
aPlotOpts.SetDisableGerberMacros( aJob->m_disableApertureMacros );
|
|
|
|
aPlotOpts.SetUseGerberX2format( aJob->m_useX2Format );
|
|
|
|
aPlotOpts.SetIncludeGerberNetlistInfo( aJob->m_includeNetlistAttributes );
|
2023-03-21 12:18:14 +00:00
|
|
|
aPlotOpts.SetUseAuxOrigin( aJob->m_useAuxOrigin );
|
2023-06-16 11:13:45 +00:00
|
|
|
aPlotOpts.SetUseGerberProtelExtensions( aJob->m_useProtelFileExtension );
|
2022-12-11 18:57:21 +00:00
|
|
|
aPlotOpts.SetGerberPrecision( aJob->m_precision );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob )
|
|
|
|
{
|
2023-04-21 03:28:32 +00:00
|
|
|
int exitCode = CLI::EXIT_CODES::OK;
|
2022-10-28 13:43:35 +00:00
|
|
|
JOB_EXPORT_PCB_GERBER* aGerberJob = dynamic_cast<JOB_EXPORT_PCB_GERBER*>( aJob );
|
|
|
|
|
|
|
|
if( aGerberJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
2022-10-28 13:43:35 +00:00
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( aGerberJob->m_filename, true );
|
2023-09-01 01:45:51 +00:00
|
|
|
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
|
2022-10-28 13:43:35 +00:00
|
|
|
|
|
|
|
if( aGerberJob->m_outputFile.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn = brd->GetFileName();
|
|
|
|
fn.SetName( fn.GetName() );
|
|
|
|
fn.SetExt( GetDefaultPlotExtension( PLOT_FORMAT::GERBER ) );
|
|
|
|
|
|
|
|
aGerberJob->m_outputFile = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_PLOT_PARAMS plotOpts;
|
2022-12-11 18:57:21 +00:00
|
|
|
populateGerberPlotOptionsFromJob( plotOpts, aGerberJob );
|
2022-10-28 13:43:35 +00:00
|
|
|
plotOpts.SetLayerSelection( aGerberJob->m_printMaskLayer );
|
|
|
|
|
2024-05-13 19:03:45 +00:00
|
|
|
PCB_LAYER_ID layer = UNDEFINED_LAYER;
|
|
|
|
wxString layerName;
|
|
|
|
wxString sheetName;
|
|
|
|
wxString sheetPath;
|
|
|
|
|
|
|
|
if( aGerberJob->m_printMaskLayer.size() == 1 )
|
|
|
|
{
|
|
|
|
layer = aGerberJob->m_printMaskLayer.front();
|
|
|
|
layerName = brd->GetLayerName( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "LAYER" ) ) )
|
|
|
|
layerName = aJob->GetVarOverrides().at( wxT( "LAYER" ) );
|
|
|
|
|
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "SHEETNAME" ) ) )
|
|
|
|
sheetName = aJob->GetVarOverrides().at( wxT( "SHEETNAME" ) );
|
|
|
|
|
|
|
|
if( aJob->GetVarOverrides().contains( wxT( "SHEETPATH" ) ) )
|
|
|
|
sheetPath = aJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
|
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
// We are feeding it one layer at the start here to silence a logic check
|
2024-05-13 19:03:45 +00:00
|
|
|
GERBER_PLOTTER* plotter = (GERBER_PLOTTER*) StartPlotBoard( brd, &plotOpts, layer, layerName,
|
|
|
|
aGerberJob->m_outputFile,
|
|
|
|
sheetName, sheetPath );
|
2022-10-28 13:43:35 +00:00
|
|
|
|
|
|
|
if( plotter )
|
|
|
|
{
|
2023-09-28 14:59:11 +00:00
|
|
|
PlotBoardLayers( brd, plotter, aGerberJob->m_printMaskLayer, plotOpts );
|
2022-10-28 13:43:35 +00:00
|
|
|
plotter->EndPlot();
|
|
|
|
}
|
2023-04-21 03:28:32 +00:00
|
|
|
else
|
|
|
|
{
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Failed to plot to '%s'.\n" ),
|
|
|
|
aGerberJob->m_outputFile ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2023-04-21 03:28:32 +00:00
|
|
|
exitCode = CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
}
|
2022-10-28 13:43:35 +00:00
|
|
|
|
|
|
|
delete plotter;
|
|
|
|
|
2023-04-21 03:28:32 +00:00
|
|
|
return exitCode;
|
2022-10-28 13:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static DRILL_PRECISION precisionListForInches( 2, 4 );
|
|
|
|
static DRILL_PRECISION precisionListForMetric( 3, 3 );
|
|
|
|
|
2023-03-04 18:02:05 +00:00
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_EXPORT_PCB_DRILL* aDrillJob = dynamic_cast<JOB_EXPORT_PCB_DRILL*>( aJob );
|
|
|
|
|
|
|
|
if( aDrillJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
2022-10-28 13:43:35 +00:00
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( aDrillJob->m_filename, true );
|
2022-10-28 13:43:35 +00:00
|
|
|
|
2023-11-07 02:11:35 +00:00
|
|
|
// ensure output dir exists
|
|
|
|
wxFileName fn( aDrillJob->m_outputDir + wxT( "/" ) );
|
2024-02-02 17:54:12 +00:00
|
|
|
|
2023-11-07 02:11:35 +00:00
|
|
|
if( !fn.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
|
|
|
|
{
|
|
|
|
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
|
|
|
|
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
}
|
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
std::unique_ptr<GENDRILL_WRITER_BASE> drillWriter;
|
2023-03-04 18:02:05 +00:00
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
if( aDrillJob->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::EXCELLON )
|
|
|
|
drillWriter = std::make_unique<EXCELLON_WRITER>( brd );
|
|
|
|
else
|
|
|
|
drillWriter = std::make_unique<GERBER_WRITER>( brd );
|
|
|
|
|
|
|
|
VECTOR2I offset;
|
2023-03-04 18:02:05 +00:00
|
|
|
|
2023-08-09 23:38:43 +00:00
|
|
|
if( aDrillJob->m_drillOrigin == JOB_EXPORT_PCB_DRILL::DRILL_ORIGIN::ABS )
|
2022-10-28 13:43:35 +00:00
|
|
|
offset = VECTOR2I( 0, 0 );
|
|
|
|
else
|
|
|
|
offset = brd->GetDesignSettings().GetAuxOrigin();
|
|
|
|
|
|
|
|
PLOT_FORMAT mapFormat = PLOT_FORMAT::PDF;
|
2023-03-04 18:02:05 +00:00
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
switch( aDrillJob->m_mapFormat )
|
|
|
|
{
|
2024-02-02 17:54:12 +00:00
|
|
|
case JOB_EXPORT_PCB_DRILL::MAP_FORMAT::POSTSCRIPT: mapFormat = PLOT_FORMAT::POST; break;
|
|
|
|
case JOB_EXPORT_PCB_DRILL::MAP_FORMAT::GERBER_X2: mapFormat = PLOT_FORMAT::GERBER; break;
|
|
|
|
case JOB_EXPORT_PCB_DRILL::MAP_FORMAT::DXF: mapFormat = PLOT_FORMAT::DXF; break;
|
|
|
|
case JOB_EXPORT_PCB_DRILL::MAP_FORMAT::SVG: mapFormat = PLOT_FORMAT::SVG; break;
|
2022-10-28 13:43:35 +00:00
|
|
|
default:
|
2024-02-02 17:54:12 +00:00
|
|
|
case JOB_EXPORT_PCB_DRILL::MAP_FORMAT::PDF: mapFormat = PLOT_FORMAT::PDF; break;
|
2022-10-28 13:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aDrillJob->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::EXCELLON )
|
|
|
|
{
|
|
|
|
EXCELLON_WRITER::ZEROS_FMT zeroFmt;
|
|
|
|
switch( aDrillJob->m_zeroFormat )
|
|
|
|
{
|
|
|
|
case JOB_EXPORT_PCB_DRILL::ZEROS_FORMAT::KEEP_ZEROS:
|
|
|
|
zeroFmt = EXCELLON_WRITER::KEEP_ZEROS;
|
|
|
|
break;
|
2022-11-22 18:31:57 +00:00
|
|
|
case JOB_EXPORT_PCB_DRILL::ZEROS_FORMAT::SUPPRESS_LEADING:
|
2022-10-28 13:43:35 +00:00
|
|
|
zeroFmt = EXCELLON_WRITER::SUPPRESS_LEADING;
|
|
|
|
break;
|
2022-11-22 18:31:57 +00:00
|
|
|
case JOB_EXPORT_PCB_DRILL::ZEROS_FORMAT::SUPPRESS_TRAILING:
|
2022-10-28 13:43:35 +00:00
|
|
|
zeroFmt = EXCELLON_WRITER::SUPPRESS_TRAILING;
|
|
|
|
break;
|
|
|
|
case JOB_EXPORT_PCB_DRILL::ZEROS_FORMAT::DECIMAL:
|
|
|
|
default:
|
|
|
|
zeroFmt = EXCELLON_WRITER::DECIMAL_FORMAT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DRILL_PRECISION precision;
|
2023-03-04 18:02:05 +00:00
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
if( aDrillJob->m_drillUnits == JOB_EXPORT_PCB_DRILL::DRILL_UNITS::INCHES )
|
|
|
|
precision = precisionListForInches;
|
|
|
|
else
|
|
|
|
precision = precisionListForMetric;
|
|
|
|
|
|
|
|
EXCELLON_WRITER* excellonWriter = dynamic_cast<EXCELLON_WRITER*>( drillWriter.get() );
|
2023-03-04 18:02:05 +00:00
|
|
|
|
|
|
|
if( excellonWriter == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
excellonWriter->SetFormat( aDrillJob->m_drillUnits
|
|
|
|
== JOB_EXPORT_PCB_DRILL::DRILL_UNITS::MILLIMETERS,
|
2023-03-04 18:02:05 +00:00
|
|
|
zeroFmt, precision.m_Lhs, precision.m_Rhs );
|
|
|
|
excellonWriter->SetOptions( aDrillJob->m_excellonMirrorY,
|
|
|
|
aDrillJob->m_excellonMinimalHeader,
|
|
|
|
offset, aDrillJob->m_excellonCombinePTHNPTH );
|
2022-10-28 13:43:35 +00:00
|
|
|
excellonWriter->SetRouteModeForOvalHoles( aDrillJob->m_excellonOvalDrillRoute );
|
|
|
|
excellonWriter->SetMapFileFormat( mapFormat );
|
|
|
|
|
2023-04-21 03:28:32 +00:00
|
|
|
if( !excellonWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true,
|
2023-03-24 10:31:08 +00:00
|
|
|
aDrillJob->m_generateMap, m_reporter ) )
|
2023-04-21 03:28:32 +00:00
|
|
|
{
|
|
|
|
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
}
|
2022-10-28 13:43:35 +00:00
|
|
|
}
|
|
|
|
else if( aDrillJob->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::GERBER )
|
|
|
|
{
|
|
|
|
GERBER_WRITER* gerberWriter = dynamic_cast<GERBER_WRITER*>( drillWriter.get() );
|
2023-03-04 18:02:05 +00:00
|
|
|
|
|
|
|
if( gerberWriter == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
2022-10-28 13:43:35 +00:00
|
|
|
// Set gerber precision: only 5 or 6 digits for mantissa are allowed
|
|
|
|
// (SetFormat() accept 5 or 6, and any other value set the precision to 5)
|
|
|
|
// the integer part precision is always 4, and units always mm
|
|
|
|
gerberWriter->SetFormat( aDrillJob->m_gerberPrecision );
|
|
|
|
gerberWriter->SetOptions( offset );
|
|
|
|
gerberWriter->SetMapFileFormat( mapFormat );
|
|
|
|
|
2023-04-21 03:28:32 +00:00
|
|
|
if( !gerberWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true,
|
2023-03-24 10:31:08 +00:00
|
|
|
aDrillJob->m_generateMap, m_reporter ) )
|
2023-04-21 03:28:32 +00:00
|
|
|
{
|
|
|
|
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
}
|
2022-10-28 13:43:35 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 12:15:55 +00:00
|
|
|
return CLI::EXIT_CODES::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportPos( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_EXPORT_PCB_POS* aPosJob = dynamic_cast<JOB_EXPORT_PCB_POS*>( aJob );
|
|
|
|
|
|
|
|
if( aPosJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
2022-11-07 12:15:55 +00:00
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( aPosJob->m_filename, true );
|
2022-11-07 12:15:55 +00:00
|
|
|
|
|
|
|
if( aPosJob->m_outputFile.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn = brd->GetFileName();
|
|
|
|
fn.SetName( fn.GetName() );
|
|
|
|
|
|
|
|
if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::ASCII )
|
2023-12-28 02:10:01 +00:00
|
|
|
fn.SetExt( FILEEXT::FootprintPlaceFileExtension );
|
2022-11-07 12:15:55 +00:00
|
|
|
else if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::CSV )
|
2023-12-28 02:10:01 +00:00
|
|
|
fn.SetExt( FILEEXT::CsvFileExtension );
|
2022-11-07 12:15:55 +00:00
|
|
|
else if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::GERBER )
|
2023-12-28 02:10:01 +00:00
|
|
|
fn.SetExt( FILEEXT::GerberFileExtension );
|
2022-11-07 12:15:55 +00:00
|
|
|
|
|
|
|
aPosJob->m_outputFile = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
2023-03-04 18:02:05 +00:00
|
|
|
if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::ASCII
|
|
|
|
|| aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::CSV )
|
2022-11-07 12:15:55 +00:00
|
|
|
{
|
2022-11-12 15:00:33 +00:00
|
|
|
FILE* file = nullptr;
|
|
|
|
file = wxFopen( aPosJob->m_outputFile, wxS( "wt" ) );
|
|
|
|
|
|
|
|
if( file == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
|
2022-11-07 12:15:55 +00:00
|
|
|
std::string data;
|
|
|
|
|
|
|
|
bool frontSide = aPosJob->m_side == JOB_EXPORT_PCB_POS::SIDE::FRONT
|
|
|
|
|| aPosJob->m_side == JOB_EXPORT_PCB_POS::SIDE::BOTH;
|
|
|
|
|
|
|
|
bool backSide = aPosJob->m_side == JOB_EXPORT_PCB_POS::SIDE::BACK
|
|
|
|
|| aPosJob->m_side == JOB_EXPORT_PCB_POS::SIDE::BOTH;
|
|
|
|
|
2023-03-04 18:02:05 +00:00
|
|
|
PLACE_FILE_EXPORTER exporter( brd,
|
|
|
|
aPosJob->m_units == JOB_EXPORT_PCB_POS::UNITS::MILLIMETERS,
|
|
|
|
aPosJob->m_smdOnly, aPosJob->m_excludeFootprintsWithTh,
|
2023-08-04 18:02:10 +00:00
|
|
|
aPosJob->m_excludeDNP,
|
2023-03-04 18:02:05 +00:00
|
|
|
frontSide, backSide,
|
|
|
|
aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::CSV,
|
|
|
|
aPosJob->m_useDrillPlaceFileOrigin,
|
|
|
|
aPosJob->m_negateBottomX );
|
2022-11-07 12:15:55 +00:00
|
|
|
data = exporter.GenPositionData();
|
|
|
|
|
|
|
|
fputs( data.c_str(), file );
|
|
|
|
fclose( file );
|
|
|
|
}
|
|
|
|
else if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::GERBER )
|
|
|
|
{
|
|
|
|
PLACEFILE_GERBER_WRITER exporter( brd );
|
|
|
|
|
2022-11-08 10:53:13 +00:00
|
|
|
PCB_LAYER_ID gbrLayer = F_Cu;
|
|
|
|
|
|
|
|
if( aPosJob->m_side == JOB_EXPORT_PCB_POS::SIDE::BACK )
|
2022-11-07 12:15:55 +00:00
|
|
|
gbrLayer = B_Cu;
|
|
|
|
|
|
|
|
exporter.CreatePlaceFile( aPosJob->m_outputFile, gbrLayer, aPosJob->m_gerberBoardEdge );
|
|
|
|
}
|
|
|
|
|
2022-10-04 01:53:37 +00:00
|
|
|
return CLI::EXIT_CODES::OK;
|
2022-11-22 18:31:57 +00:00
|
|
|
}
|
2022-11-28 02:27:34 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
extern FOOTPRINT* try_load_footprint( const wxFileName& aFileName, PCB_IO_MGR::PCB_FILE_T aFileType,
|
2022-11-28 02:27:34 +00:00
|
|
|
const wxString& aName );
|
|
|
|
|
|
|
|
|
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_FP_UPGRADE* upgradeJob = dynamic_cast<JOB_FP_UPGRADE*>( aJob );
|
|
|
|
|
|
|
|
if( upgradeJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
2024-02-13 21:19:24 +00:00
|
|
|
PCB_IO_MGR::PCB_FILE_T fileType = PCB_IO_MGR::GuessPluginTypeFromLibPath( upgradeJob->m_libraryPath );
|
2022-11-28 02:27:34 +00:00
|
|
|
|
2022-12-07 02:20:19 +00:00
|
|
|
if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) ||
|
|
|
|
wxDir::Exists( upgradeJob->m_outputLibraryPath) )
|
|
|
|
{
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Output path must not conflict with existing path\n" ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2022-12-07 02:20:19 +00:00
|
|
|
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
}
|
|
|
|
}
|
2024-02-13 21:19:24 +00:00
|
|
|
else if( fileType != PCB_IO_MGR::KICAD_SEXP )
|
2022-11-28 02:27:34 +00:00
|
|
|
{
|
2024-02-13 21:19:24 +00:00
|
|
|
m_reporter->Report( _( "Output path must be specified to convert legacy and non-KiCad libraries\n" ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2022-11-28 02:27:34 +00:00
|
|
|
|
2024-02-13 21:19:24 +00:00
|
|
|
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
}
|
2022-11-28 02:27:34 +00:00
|
|
|
|
2024-02-13 21:19:24 +00:00
|
|
|
if( fileType == PCB_IO_MGR::KICAD_SEXP )
|
2022-11-28 02:27:34 +00:00
|
|
|
{
|
2024-02-13 21:19:24 +00:00
|
|
|
if( !wxDir::Exists( upgradeJob->m_libraryPath ) )
|
2022-11-28 02:27:34 +00:00
|
|
|
{
|
2024-02-13 21:19:24 +00:00
|
|
|
m_reporter->Report( _( "Footprint library path does not exist or is not accessible\n" ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
|
2022-11-28 02:27:34 +00:00
|
|
|
}
|
|
|
|
|
2024-02-13 21:19:24 +00:00
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
|
|
|
m_reporter->Report( _( "Loading footprint library\n" ), RPT_SEVERITY_INFO );
|
|
|
|
|
|
|
|
PCB_IO_KICAD_SEXPR pcb_io( CTL_FOR_LIBRARY );
|
|
|
|
FP_CACHE fpLib( &pcb_io, upgradeJob->m_libraryPath );
|
2022-11-28 02:27:34 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2024-02-13 21:19:24 +00:00
|
|
|
fpLib.Load();
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldSave = upgradeJob->m_force;
|
|
|
|
|
|
|
|
for( const auto& footprint : fpLib.GetFootprints() )
|
|
|
|
{
|
|
|
|
if( footprint.second->GetFootprint()->GetFileFormatVersionAtLoad()
|
|
|
|
< SEXPR_BOARD_FILE_VERSION )
|
2022-12-07 02:20:19 +00:00
|
|
|
{
|
2024-02-13 21:19:24 +00:00
|
|
|
shouldSave = true;
|
2022-12-07 02:20:19 +00:00
|
|
|
}
|
2024-02-13 21:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( shouldSave )
|
|
|
|
{
|
|
|
|
m_reporter->Report( _( "Saving footprint library\n" ), RPT_SEVERITY_INFO );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
|
|
|
|
{
|
|
|
|
fpLib.SetPath( upgradeJob->m_outputLibraryPath );
|
|
|
|
}
|
2022-12-07 02:20:19 +00:00
|
|
|
|
2024-02-13 21:19:24 +00:00
|
|
|
fpLib.Save();
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
m_reporter->Report( _( "Unable to save library\n" ), RPT_SEVERITY_ERROR );
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
}
|
2022-11-28 02:27:34 +00:00
|
|
|
}
|
2024-02-13 21:19:24 +00:00
|
|
|
else
|
2022-11-28 02:27:34 +00:00
|
|
|
{
|
2024-02-13 21:19:24 +00:00
|
|
|
m_reporter->Report( _( "Footprint library was not updated\n" ), RPT_SEVERITY_INFO );
|
2022-11-28 02:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-13 21:19:24 +00:00
|
|
|
if( !PCB_IO_MGR::ConvertLibrary( nullptr, upgradeJob->m_libraryPath, upgradeJob->m_outputLibraryPath ) )
|
|
|
|
{
|
|
|
|
m_reporter->Report( ( "Unable to convert library\n" ), RPT_SEVERITY_ERROR );
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
}
|
2022-11-28 02:27:34 +00:00
|
|
|
}
|
|
|
|
|
2022-12-14 03:48:07 +00:00
|
|
|
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() )
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Loading footprint library\n" ), RPT_SEVERITY_INFO );
|
2022-12-14 03:48:07 +00:00
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_SEXPR pcb_io( CTL_FOR_LIBRARY );
|
2022-12-14 03:48:07 +00:00
|
|
|
FP_CACHE fpLib( &pcb_io, svgJob->m_libraryPath );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fpLib.Load();
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
|
2022-12-14 03:48:07 +00:00
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 )
|
2023-03-24 10:31:08 +00:00
|
|
|
{
|
2024-02-12 02:12:21 +00:00
|
|
|
m_reporter->Report( _( "The given footprint could not be found to export." ) + wxS( "\n" ),
|
2023-03-24 10:31:08 +00:00
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2022-12-14 03:48:07 +00:00
|
|
|
|
|
|
|
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() );
|
2023-09-01 01:45:51 +00:00
|
|
|
brd->GetProject()->ApplyTextVars( aSvgJob->GetVarOverrides() );
|
2022-12-14 03:48:07 +00:00
|
|
|
|
|
|
|
FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aFootprint->Clone() );
|
|
|
|
|
2023-03-04 18:02:05 +00:00
|
|
|
if( fp == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
2022-12-14 03:48:07 +00:00
|
|
|
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() );
|
2023-12-28 02:10:01 +00:00
|
|
|
outputFile.SetExt( FILEEXT::SVGFileExtension );
|
2022-12-14 03:48:07 +00:00
|
|
|
|
2023-03-24 10:31:08 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Plotting footprint '%s' to '%s'\n" ),
|
|
|
|
aFootprint->GetFPID().GetLibItemName().wx_str(),
|
|
|
|
outputFile.GetFullPath() ),
|
|
|
|
RPT_SEVERITY_ACTION );
|
2022-12-14 03:48:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2023-01-28 04:45:35 +00:00
|
|
|
svgPlotOptions.m_printMaskLayer = aSvgJob->m_printMaskLayer;
|
2022-12-14 03:48:07 +00:00
|
|
|
svgPlotOptions.m_plotFrame = false;
|
|
|
|
|
2023-08-18 17:44:54 +00:00
|
|
|
if( !EXPORT_SVG::Plot( brd.get(), svgPlotOptions ) )
|
2024-02-12 02:12:21 +00:00
|
|
|
m_reporter->Report( _( "Error creating svg file" ) + wxS( "\n" ), RPT_SEVERITY_ERROR );
|
2022-12-14 03:48:07 +00:00
|
|
|
|
|
|
|
|
2022-11-28 02:27:34 +00:00
|
|
|
return CLI::EXIT_CODES::OK;
|
2023-03-04 18:02:05 +00:00
|
|
|
}
|
2023-04-21 03:28:32 +00:00
|
|
|
|
2023-08-09 23:38:43 +00:00
|
|
|
|
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportDrc( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_PCB_DRC* drcJob = dynamic_cast<JOB_PCB_DRC*>( aJob );
|
|
|
|
|
|
|
|
if( drcJob == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( aJob->IsCli() )
|
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( drcJob->m_filename, true );
|
2023-09-01 01:45:51 +00:00
|
|
|
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
|
2023-08-09 23:38:43 +00:00
|
|
|
|
|
|
|
if( drcJob->m_outputFile.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn = brd->GetFileName();
|
|
|
|
fn.SetName( fn.GetName() );
|
2023-08-13 18:44:31 +00:00
|
|
|
|
|
|
|
if( drcJob->m_format == JOB_PCB_DRC::OUTPUT_FORMAT::JSON )
|
2023-12-28 02:10:01 +00:00
|
|
|
fn.SetExt( FILEEXT::JsonFileExtension );
|
2023-08-13 18:44:31 +00:00
|
|
|
else
|
2023-12-28 02:10:01 +00:00
|
|
|
fn.SetExt( FILEEXT::ReportFileExtension );
|
2023-08-09 23:38:43 +00:00
|
|
|
|
|
|
|
drcJob->m_outputFile = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
|
|
|
EDA_UNITS units;
|
2024-02-02 17:54:12 +00:00
|
|
|
|
2023-08-09 23:38:43 +00:00
|
|
|
switch( drcJob->m_units )
|
|
|
|
{
|
2024-02-02 17:54:12 +00:00
|
|
|
case JOB_PCB_DRC::UNITS::INCHES: units = EDA_UNITS::INCHES; break;
|
|
|
|
case JOB_PCB_DRC::UNITS::MILS: units = EDA_UNITS::MILS; break;
|
|
|
|
case JOB_PCB_DRC::UNITS::MILLIMETERS: units = EDA_UNITS::MILLIMETRES; break;
|
|
|
|
default: units = EDA_UNITS::MILLIMETRES; break;
|
2023-08-09 23:38:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<DRC_ENGINE> drcEngine = brd->GetDesignSettings().m_DRCEngine;
|
2024-02-09 20:14:42 +00:00
|
|
|
std::unique_ptr<NETLIST> netlist = std::make_unique<NETLIST>();
|
2023-08-09 23:38:43 +00:00
|
|
|
|
|
|
|
drcEngine->SetDrawingSheet( getDrawingSheetProxyView( brd ) );
|
|
|
|
|
|
|
|
// BOARD_COMMIT uses TOOL_MANAGER to grab the board internally so we must give it one
|
|
|
|
TOOL_MANAGER* toolManager = new TOOL_MANAGER;
|
|
|
|
toolManager->SetEnvironment( brd, nullptr, nullptr, Kiface().KifaceSettings(), nullptr );
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( toolManager );
|
|
|
|
|
|
|
|
m_reporter->Report( _( "Running DRC...\n" ), RPT_SEVERITY_INFO );
|
|
|
|
|
2024-02-02 23:04:56 +00:00
|
|
|
if( drcJob->m_parity )
|
|
|
|
{
|
|
|
|
typedef bool (*NETLIST_FN_PTR)( const wxString&, std::string& );
|
|
|
|
|
|
|
|
KIFACE* eeschema = m_kiway->KiFACE( KIWAY::FACE_SCH );
|
|
|
|
wxFileName schematicPath( drcJob->m_filename );
|
|
|
|
NETLIST_FN_PTR netlister = (NETLIST_FN_PTR) eeschema->IfaceOrAddress( KIFACE_NETLIST_SCHEMATIC );
|
|
|
|
std::string netlist_str;
|
|
|
|
|
|
|
|
schematicPath.SetExt( FILEEXT::KiCadSchematicFileExtension );
|
|
|
|
|
|
|
|
if( !schematicPath.Exists() )
|
|
|
|
schematicPath.SetExt( FILEEXT::LegacySchematicFileExtension );
|
|
|
|
|
|
|
|
if( !schematicPath.Exists() )
|
|
|
|
{
|
|
|
|
m_reporter->Report( _( "Failed to find schematic for parity tests.\n" ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(*netlister)( schematicPath.GetFullPath(), netlist_str );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto lineReader = new STRING_LINE_READER( netlist_str, _( "Eeschema netlist" ) );
|
2024-02-09 20:14:42 +00:00
|
|
|
KICAD_NETLIST_READER netlistReader( lineReader, netlist.get() );
|
2024-02-02 23:04:56 +00:00
|
|
|
netlistReader.LoadNetlist();
|
|
|
|
}
|
2024-04-20 17:11:14 +00:00
|
|
|
catch( const IO_ERROR& )
|
2024-02-02 23:04:56 +00:00
|
|
|
{
|
|
|
|
m_reporter->Report( _( "Failed to fetch schematic netlist for parity tests.\n" ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
|
2024-02-09 20:14:42 +00:00
|
|
|
drcEngine->SetSchematicNetlist( netlist.get() );
|
2024-02-02 23:04:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 23:38:43 +00:00
|
|
|
drcEngine->SetProgressReporter( nullptr );
|
|
|
|
drcEngine->SetViolationHandler(
|
|
|
|
[&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
|
|
|
|
{
|
|
|
|
PCB_MARKER* marker = new PCB_MARKER( aItem, aPos, aLayer );
|
|
|
|
commit.Add( marker );
|
|
|
|
} );
|
|
|
|
|
2024-01-11 00:55:18 +00:00
|
|
|
brd->RecordDRCExclusions();
|
|
|
|
brd->DeleteMARKERs( true, true );
|
2024-01-26 03:14:49 +00:00
|
|
|
drcEngine->RunTests( units, drcJob->m_reportAllTrackErrors, drcJob->m_parity );
|
2024-01-11 00:55:18 +00:00
|
|
|
drcEngine->ClearViolationHandler();
|
2023-08-09 23:38:43 +00:00
|
|
|
|
|
|
|
commit.Push( _( "DRC" ), SKIP_UNDO | SKIP_SET_DIRTY );
|
|
|
|
|
2024-03-17 16:28:46 +00:00
|
|
|
// Update the exclusion status on any excluded markers that still exist.
|
|
|
|
brd->ResolveDRCExclusions( false );
|
2024-01-11 00:55:18 +00:00
|
|
|
|
2023-08-09 23:38:43 +00:00
|
|
|
std::shared_ptr<DRC_ITEMS_PROVIDER> markersProvider = std::make_shared<DRC_ITEMS_PROVIDER>(
|
|
|
|
brd, MARKER_BASE::MARKER_DRC, MARKER_BASE::MARKER_DRAWING_SHEET );
|
|
|
|
|
|
|
|
std::shared_ptr<DRC_ITEMS_PROVIDER> ratsnestProvider =
|
|
|
|
std::make_shared<DRC_ITEMS_PROVIDER>( brd, MARKER_BASE::MARKER_RATSNEST );
|
|
|
|
|
|
|
|
std::shared_ptr<DRC_ITEMS_PROVIDER> fpWarningsProvider =
|
|
|
|
std::make_shared<DRC_ITEMS_PROVIDER>( brd, MARKER_BASE::MARKER_PARITY );
|
|
|
|
|
|
|
|
markersProvider->SetSeverities( drcJob->m_severity );
|
|
|
|
ratsnestProvider->SetSeverities( drcJob->m_severity );
|
|
|
|
fpWarningsProvider->SetSeverities( drcJob->m_severity );
|
|
|
|
|
2024-02-02 23:04:56 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Found %d violations\n" ),
|
|
|
|
markersProvider->GetCount() ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
m_reporter->Report( wxString::Format( _( "Found %d unconnected items\n" ),
|
|
|
|
ratsnestProvider->GetCount() ),
|
2023-08-13 18:44:31 +00:00
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
|
2024-02-02 23:04:56 +00:00
|
|
|
if( drcJob->m_parity )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( _( "Found %d schematic parity issues\n" ),
|
|
|
|
fpWarningsProvider->GetCount() ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
}
|
|
|
|
|
2023-08-13 18:44:31 +00:00
|
|
|
DRC_REPORT reportWriter( brd, units, markersProvider, ratsnestProvider, fpWarningsProvider );
|
|
|
|
|
|
|
|
bool wroteReport = false;
|
2024-02-02 17:54:12 +00:00
|
|
|
|
2023-08-13 18:44:31 +00:00
|
|
|
if( drcJob->m_format == JOB_PCB_DRC::OUTPUT_FORMAT::JSON )
|
|
|
|
wroteReport = reportWriter.WriteJsonReport( drcJob->m_outputFile );
|
|
|
|
else
|
|
|
|
wroteReport = reportWriter.WriteTextReport( drcJob->m_outputFile );
|
2023-08-09 23:38:43 +00:00
|
|
|
|
|
|
|
if( !wroteReport )
|
|
|
|
{
|
2024-02-02 17:54:12 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Unable to save DRC report to %s\n" ),
|
|
|
|
drcJob->m_outputFile ),
|
2023-08-09 23:38:43 +00:00
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
|
|
|
|
}
|
|
|
|
|
2024-02-02 17:54:12 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Saved DRC Report to %s\n" ),
|
|
|
|
drcJob->m_outputFile ),
|
2023-08-09 23:38:43 +00:00
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
|
|
|
|
if( drcJob->m_exitCodeViolations )
|
|
|
|
{
|
|
|
|
if( markersProvider->GetCount() > 0 || ratsnestProvider->GetCount() > 0
|
|
|
|
|| fpWarningsProvider->GetCount() > 0 )
|
|
|
|
{
|
2023-08-14 00:31:19 +00:00
|
|
|
return CLI::EXIT_CODES::ERR_RC_VIOLATIONS;
|
2023-08-09 23:38:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CLI::EXIT_CODES::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-31 01:42:18 +00:00
|
|
|
int PCBNEW_JOBS_HANDLER::JobExportIpc2581( JOB* aJob )
|
|
|
|
{
|
|
|
|
JOB_EXPORT_PCB_IPC2581* job = dynamic_cast<JOB_EXPORT_PCB_IPC2581*>( aJob );
|
|
|
|
|
|
|
|
if( job == nullptr )
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
|
|
|
|
if( job->IsCli() )
|
|
|
|
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
|
|
|
|
|
2024-02-16 04:06:11 +00:00
|
|
|
BOARD* brd = LoadBoard( job->m_filename, true );
|
2024-01-31 01:42:18 +00:00
|
|
|
|
|
|
|
if( job->m_outputFile.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn = brd->GetFileName();
|
|
|
|
fn.SetName( fn.GetName() );
|
|
|
|
fn.SetExt( FILEEXT::Ipc2581FileExtension );
|
|
|
|
|
|
|
|
job->m_outputFile = fn.GetFullName();
|
|
|
|
}
|
|
|
|
|
|
|
|
STRING_UTF8_MAP props;
|
2024-02-02 17:54:12 +00:00
|
|
|
props["units"] = job->m_units == JOB_EXPORT_PCB_IPC2581::IPC2581_UNITS::MILLIMETERS ? "mm"
|
|
|
|
: "inch";
|
2024-01-31 01:42:18 +00:00
|
|
|
props["sigfig"] = wxString::Format( "%d", job->m_units );
|
|
|
|
props["version"] = job->m_version == JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::C ? "C" : "B";
|
|
|
|
props["OEMRef"] = job->m_colInternalId;
|
|
|
|
props["mpn"] = job->m_colMfgPn;
|
|
|
|
props["mfg"] = job->m_colMfg;
|
|
|
|
props["dist"] = job->m_colDist;
|
|
|
|
props["distpn"] = job->m_colDistPn;
|
|
|
|
|
|
|
|
wxString tempFile = wxFileName::CreateTempFileName( wxS( "pcbnew_ipc" ) );
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IO_RELEASER<PCB_IO> pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::IPC2581 ) );
|
|
|
|
pi->SetProgressReporter( m_progressReporter );
|
|
|
|
pi->SaveBoard( tempFile, brd, &props );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( _( "Error generating IPC2581 file '%s'.\n%s" ),
|
|
|
|
job->m_filename, ioe.What() ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
|
|
|
|
wxRemoveFile( tempFile );
|
|
|
|
|
|
|
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( job->m_compress )
|
|
|
|
{
|
|
|
|
wxFileName tempfn = job->m_outputFile;
|
|
|
|
tempfn.SetExt( FILEEXT::Ipc2581FileExtension );
|
|
|
|
wxFileName zipfn = tempFile;
|
|
|
|
zipfn.SetExt( "zip" );
|
|
|
|
|
|
|
|
wxFFileOutputStream fnout( zipfn.GetFullPath() );
|
|
|
|
wxZipOutputStream zip( fnout );
|
|
|
|
wxFFileInputStream fnin( tempFile );
|
|
|
|
|
|
|
|
zip.PutNextEntry( tempfn.GetFullName() );
|
|
|
|
fnin.Read( zip );
|
|
|
|
zip.Close();
|
|
|
|
fnout.Close();
|
|
|
|
|
|
|
|
wxRemoveFile( tempFile );
|
|
|
|
tempFile = zipfn.GetFullPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If save succeeded, replace the original with what we just wrote
|
|
|
|
if( !wxRenameFile( tempFile, job->m_outputFile ) )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( _( "Error generating IPC2581 file '%s'.\n"
|
2024-02-12 02:12:21 +00:00
|
|
|
"Failed to rename temporary file '%s." )
|
|
|
|
+ wxS( "\n" ),
|
2024-01-31 01:42:18 +00:00
|
|
|
job->m_outputFile, tempFile ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
return CLI::EXIT_CODES::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-09 23:38:43 +00:00
|
|
|
DS_PROXY_VIEW_ITEM* PCBNEW_JOBS_HANDLER::getDrawingSheetProxyView( BOARD* aBrd )
|
|
|
|
{
|
|
|
|
DS_PROXY_VIEW_ITEM* drawingSheet = new DS_PROXY_VIEW_ITEM( pcbIUScale,
|
|
|
|
&aBrd->GetPageSettings(),
|
|
|
|
aBrd->GetProject(),
|
|
|
|
&aBrd->GetTitleBlock(),
|
|
|
|
&aBrd->GetProperties() );
|
|
|
|
|
|
|
|
drawingSheet->SetSheetName( std::string() );
|
|
|
|
drawingSheet->SetSheetPath( std::string() );
|
|
|
|
drawingSheet->SetIsFirstPage( true );
|
|
|
|
|
2023-08-14 00:31:19 +00:00
|
|
|
drawingSheet->SetFileName( TO_UTF8( aBrd->GetFileName() ) );
|
2023-08-09 23:38:43 +00:00
|
|
|
|
|
|
|
return drawingSheet;
|
2023-08-31 23:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCBNEW_JOBS_HANDLER::loadOverrideDrawingSheet( BOARD* aBrd, const wxString& aSheetPath )
|
|
|
|
{
|
|
|
|
// dont bother attempting to load a empty path, if there was one
|
|
|
|
if( aSheetPath.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
2024-02-02 17:54:12 +00:00
|
|
|
auto loadSheet =
|
|
|
|
[&]( const wxString& path ) -> bool
|
|
|
|
{
|
|
|
|
BASE_SCREEN::m_DrawingSheetFileName = path;
|
|
|
|
wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
|
|
|
|
aBrd->GetProject()->GetProjectPath() );
|
|
|
|
|
|
|
|
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ) + wxS( "\n" ),
|
|
|
|
path ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
2023-08-31 23:37:12 +00:00
|
|
|
|
|
|
|
if( loadSheet( aSheetPath ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// failed loading custom path, revert back to default
|
|
|
|
loadSheet( aBrd->GetProject()->GetProjectFile().m_BoardDrawingSheetFile );
|
2024-03-04 15:05:53 +00:00
|
|
|
}
|