2023-03-22 02:14:50 +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>
|
|
|
|
* 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 <kiface_base.h>
|
|
|
|
#include <sch_plotter.h>
|
2023-08-19 11:46:18 -04:00
|
|
|
#include "command_sch_export_plot.h"
|
2023-03-22 02:14:50 +00:00
|
|
|
#include <cli/exit_codes.h>
|
|
|
|
#include "jobs/job_export_sch_plot.h"
|
|
|
|
#include <layer_ids.h>
|
|
|
|
#include <wx/crt.h>
|
2023-09-03 09:17:51 -04:00
|
|
|
#include <string_utils.h>
|
2023-03-22 02:14:50 +00:00
|
|
|
|
|
|
|
#include <macros.h>
|
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
|
|
|
|
#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet"
|
|
|
|
#define ARG_NO_BACKGROUND_COLOR "--no-background-color"
|
|
|
|
#define ARG_HPGL_PEN_SIZE "--pen-size"
|
|
|
|
#define ARG_HPGL_ORIGIN "--origin"
|
2023-09-03 09:17:51 -04:00
|
|
|
#define ARG_PAGES "--pages"
|
2023-03-22 02:14:50 +00:00
|
|
|
|
|
|
|
const HPGL_PLOT_ORIGIN_AND_UNITS hpgl_origin_ops[4] = {
|
|
|
|
HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT, HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER,
|
|
|
|
HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE, HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT
|
|
|
|
};
|
|
|
|
|
2023-08-19 11:51:50 -04:00
|
|
|
CLI::SCH_EXPORT_PLOT_COMMAND::SCH_EXPORT_PLOT_COMMAND( const std::string& aName,
|
2023-08-31 22:17:14 -04:00
|
|
|
const std::string& aDescription,
|
2023-03-22 02:14:50 +00:00
|
|
|
PLOT_FORMAT aPlotFormat,
|
|
|
|
bool aOutputIsDir ) :
|
2023-08-31 18:43:32 -04:00
|
|
|
COMMAND( aName ),
|
|
|
|
m_plotFormat( aPlotFormat )
|
2023-03-22 02:14:50 +00:00
|
|
|
{
|
2023-08-31 22:17:14 -04:00
|
|
|
m_argParser.add_description( aDescription );
|
|
|
|
|
2023-08-31 18:43:32 -04:00
|
|
|
addCommonArgs( true, true, aOutputIsDir );
|
2023-08-31 19:37:12 -04:00
|
|
|
addDrawingSheetArg();
|
2023-08-31 21:45:51 -04:00
|
|
|
addDefineArg();
|
2023-08-31 18:43:32 -04:00
|
|
|
|
2023-03-22 02:14:50 +00:00
|
|
|
m_argParser.add_argument( "-t", ARG_THEME )
|
|
|
|
.default_value( std::string() )
|
2023-08-31 22:01:07 -04:00
|
|
|
.help( UTF8STDSTR( _( "Color theme to use (will default to schematic settings)" ) ) )
|
|
|
|
.metavar( "THEME_NAME" );
|
2023-03-22 02:14:50 +00:00
|
|
|
|
|
|
|
m_argParser.add_argument( "-b", ARG_BLACKANDWHITE )
|
|
|
|
.help( UTF8STDSTR( _( ARG_BLACKANDWHITE_DESC ) ) )
|
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
|
|
|
|
m_argParser.add_argument( "-e", ARG_EXCLUDE_DRAWING_SHEET )
|
|
|
|
.help( UTF8STDSTR( _( "No drawing sheet" ) ) )
|
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
|
|
|
|
m_argParser.add_argument( "-n", ARG_NO_BACKGROUND_COLOR )
|
|
|
|
.help( UTF8STDSTR( _( "Avoid setting a background color (regardless of theme)" ) ) )
|
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
|
2023-09-03 09:17:51 -04:00
|
|
|
m_argParser.add_argument( "-p", ARG_PAGES )
|
|
|
|
.default_value( std::string() )
|
|
|
|
.help( UTF8STDSTR( _( "List of page numbers separated by comma to print, blank or unspecified is equivalent to all pages" ) ) )
|
|
|
|
.metavar( "PAGE_LIST" );
|
2023-03-22 02:14:50 +00:00
|
|
|
|
|
|
|
if( aPlotFormat == PLOT_FORMAT::HPGL )
|
|
|
|
{
|
|
|
|
m_argParser.add_argument( "-p", ARG_HPGL_PEN_SIZE )
|
|
|
|
.help( UTF8STDSTR( _( "Pen size [mm]" ) ) )
|
|
|
|
.scan<'g', double>()
|
2023-08-31 22:01:07 -04:00
|
|
|
.default_value( 0.5 )
|
|
|
|
.metavar( "PEN_SIZE" );
|
2023-03-22 02:14:50 +00:00
|
|
|
|
|
|
|
m_argParser.add_argument( "-r", ARG_HPGL_ORIGIN )
|
|
|
|
.help( UTF8STDSTR( _( "Origin and scale: 0 bottom left, 1 centered, 2 page fit, 3 "
|
|
|
|
"content fit" ) ) )
|
|
|
|
.scan<'d', int>()
|
2023-08-31 22:01:07 -04:00
|
|
|
.default_value( 1 )
|
|
|
|
.metavar( "ORIGIN" );
|
2023-03-22 02:14:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-19 11:51:50 -04:00
|
|
|
int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway )
|
2023-03-22 02:14:50 +00:00
|
|
|
{
|
2023-08-31 18:43:32 -04:00
|
|
|
wxString filename = m_argInput;
|
2023-03-22 02:14:50 +00:00
|
|
|
if( !wxFile::Exists( filename ) )
|
|
|
|
{
|
|
|
|
wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) );
|
|
|
|
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
|
|
|
|
}
|
|
|
|
|
2023-09-03 09:17:51 -04:00
|
|
|
std::vector<wxString> pages;
|
|
|
|
wxString pagesStr = FROM_UTF8( m_argParser.get<std::string>( ARG_PAGES ).c_str() );
|
|
|
|
wxStringTokenizer tokenizer( pagesStr, "," );
|
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
pages.push_back( tokenizer.GetNextToken().Trim() );
|
|
|
|
}
|
|
|
|
|
2023-03-22 02:14:50 +00:00
|
|
|
std::unique_ptr<JOB_EXPORT_SCH_PLOT> plotJob =
|
|
|
|
std::make_unique<JOB_EXPORT_SCH_PLOT>( true, m_plotFormat, filename );
|
|
|
|
|
|
|
|
SCH_PLOT_SETTINGS& settings = plotJob->settings;
|
2023-09-03 09:17:51 -04:00
|
|
|
settings.m_plotPages = pages;
|
2023-03-22 02:14:50 +00:00
|
|
|
settings.m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
|
|
|
|
settings.m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
|
|
|
|
settings.m_pageSizeSelect = PAGE_SIZE_AUTO;
|
|
|
|
settings.m_useBackgroundColor = !m_argParser.get<bool>( ARG_NO_BACKGROUND_COLOR );
|
|
|
|
settings.m_theme = FROM_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
|
2023-08-31 18:43:32 -04:00
|
|
|
if( m_outputArgExpectsDir )
|
|
|
|
settings.m_outputDirectory = m_argOutput;
|
2023-03-22 02:14:50 +00:00
|
|
|
else
|
2023-08-31 18:43:32 -04:00
|
|
|
settings.m_outputFile = m_argOutput;
|
2023-08-31 19:37:12 -04:00
|
|
|
|
2023-09-03 09:17:51 -04:00
|
|
|
settings.m_plotAll = settings.m_plotPages.size() == 0;
|
|
|
|
|
2023-08-31 19:37:12 -04:00
|
|
|
plotJob->m_drawingSheet = m_argDrawingSheet;
|
2023-08-31 21:45:51 -04:00
|
|
|
plotJob->SetVarOverrides( m_argDefineVars );
|
2023-08-31 19:37:12 -04:00
|
|
|
|
2023-03-22 02:14:50 +00:00
|
|
|
// HPGL local options
|
|
|
|
if( m_plotFormat == PLOT_FORMAT::HPGL )
|
|
|
|
{
|
|
|
|
settings.m_HPGLPenSize =
|
|
|
|
m_argParser.get<double>( ARG_HPGL_PEN_SIZE ) * schIUScale.IU_PER_MM;
|
|
|
|
int origin = m_argParser.get<int>( ARG_HPGL_ORIGIN );
|
|
|
|
if( origin < 0 || origin > 3 )
|
|
|
|
{
|
|
|
|
wxFprintf( stderr, _( "HPGL origin option must be 0, 1, 2 or 3\n" ) );
|
|
|
|
return EXIT_CODES::ERR_ARGS;
|
|
|
|
}
|
|
|
|
settings.m_HPGLPlotOrigin = hpgl_origin_ops[origin];
|
|
|
|
}
|
|
|
|
|
|
|
|
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, plotJob.get() );
|
|
|
|
|
|
|
|
return exitCode;
|
|
|
|
}
|