kicad-cli: Remove -O for plot and add --pages to specify list of pages instead

--pages 1 is equivalent to -O

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15402
This commit is contained in:
Marek Roszko 2023-09-03 09:17:51 -04:00
parent f8cb239f40
commit fb8d52f19e
5 changed files with 77 additions and 9 deletions

View File

@ -117,13 +117,20 @@ void SCH_PLOTTER::createPDFFile( const SCH_PLOT_SETTINGS& aPlotSettings,
*/
SCH_SHEET_LIST sheetList;
if( aPlotSettings.m_plotAll )
if( aPlotSettings.m_plotAll || aPlotSettings.m_plotPages.size() > 0 )
{
sheetList.BuildSheetList( &m_schematic->Root(), true );
sheetList.SortByPageNumbers();
// remove the non-selected pages if we are in plot pages mode
if( aPlotSettings.m_plotPages.size() > 0 )
{
sheetList.TrimToPageNumbers( aPlotSettings.m_plotPages );
}
}
else
{
// in eeschema, this prints the current page
sheetList.push_back( m_schematic->CurrentSheet() );
}
@ -302,6 +309,12 @@ void SCH_PLOTTER::createPSFiles( const SCH_PLOT_SETTINGS& aPlotSettings,
{
sheetList.BuildSheetList( &m_schematic->Root(), true );
sheetList.SortByPageNumbers();
// remove the non-selected pages if we are in plot pages mode
if( aPlotSettings.m_plotPages.size() > 0 )
{
sheetList.TrimToPageNumbers( aPlotSettings.m_plotPages );
}
}
else
{
@ -462,9 +475,16 @@ void SCH_PLOTTER::createSVGFiles( const SCH_PLOT_SETTINGS& aPlotSettings,
{
sheetList.BuildSheetList( &m_schematic->Root(), true );
sheetList.SortByPageNumbers();
// remove the non-selected pages if we are in plot pages mode
if( aPlotSettings.m_plotPages.size() > 0 )
{
sheetList.TrimToPageNumbers( aPlotSettings.m_plotPages );
}
}
else
{
// in eeschema, this prints the current page
sheetList.push_back( m_schematic->CurrentSheet() );
}
@ -636,9 +656,16 @@ void SCH_PLOTTER::createHPGLFiles( const SCH_PLOT_SETTINGS& aPlotSettings,
{
sheetList.BuildSheetList( &m_schematic->Root(), true );
sheetList.SortByPageNumbers();
// remove the non-selected pages if we are in plot pages mode
if( aPlotSettings.m_plotPages.size() > 0 )
{
sheetList.TrimToPageNumbers( aPlotSettings.m_plotPages );
}
}
else
{
// in eeschema, this prints the current page
sheetList.push_back( m_schematic->CurrentSheet() );
}
@ -818,9 +845,16 @@ void SCH_PLOTTER::createDXFFiles( const SCH_PLOT_SETTINGS& aPlotSettings,
{
sheetList.BuildSheetList( &m_schematic->Root(), true );
sheetList.SortByPageNumbers();
// remove the non-selected pages if we are in plot pages mode
if( aPlotSettings.m_plotPages.size() > 0 )
{
sheetList.TrimToPageNumbers( aPlotSettings.m_plotPages );
}
}
else
{
// in eeschema, this prints the current page
sheetList.push_back( m_schematic->CurrentSheet() );
}

View File

@ -80,6 +80,8 @@ struct SCH_PLOT_SETTINGS
{
bool m_plotAll;
bool m_plotDrawingSheet;
std::vector<wxString> m_plotPages;
bool m_blackAndWhite;
int m_pageSizeSelect;
bool m_useBackgroundColor;

View File

@ -767,6 +767,20 @@ bool SCH_SHEET_LIST::PageNumberExists( const wxString& aPageNumber ) const
}
void SCH_SHEET_LIST::TrimToPageNumbers( const std::vector<wxString>& aPageInclusions )
{
auto it = std::remove_if( begin(), end(),
[&]( SCH_SHEET_PATH sheet )
{
return std::find( aPageInclusions.begin(), aPageInclusions.end(),
sheet.GetPageNumber() )
== aPageInclusions.end();
} );
erase( it, end() );
}
bool SCH_SHEET_LIST::IsModified() const
{
for( const SCH_SHEET_PATH& sheet : *this )

View File

@ -614,6 +614,13 @@ public:
bool PageNumberExists( const wxString& aPageNumber ) const;
/**
* Truncates the list by removing sheet's with page numbers not in the given list
*
* @param aPageInclusions List of Page Numbers (non-virtual) to keep
*/
void TrimToPageNumbers( const std::vector<wxString>& aPageInclusions );
/**
* Update all of the symbol instance information using \a aSymbolInstances.
* WARNING: Do not call this on anything other than the full hierarchy.

View File

@ -25,15 +25,16 @@
#include "jobs/job_export_sch_plot.h"
#include <layer_ids.h>
#include <wx/crt.h>
#include <string_utils.h>
#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_PLOT_ONE "--plot-one"
#define ARG_HPGL_PEN_SIZE "--pen-size"
#define ARG_HPGL_ORIGIN "--origin"
#define ARG_PAGES "--pages"
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,
@ -73,10 +74,10 @@ CLI::SCH_EXPORT_PLOT_COMMAND::SCH_EXPORT_PLOT_COMMAND( const std::string& aName,
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-O", ARG_PLOT_ONE )
.help( UTF8STDSTR( _( "Plot only the first page (no sub-sheets)" ) ) )
.implicit_value( true )
.default_value( false );
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" );
if( aPlotFormat == PLOT_FORMAT::HPGL )
{
@ -105,11 +106,19 @@ int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway )
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
}
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() );
}
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;
settings.m_plotAll = !m_argParser.get<bool>( ARG_PLOT_ONE );
settings.m_plotPages = pages;
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;
@ -120,6 +129,8 @@ int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway )
else
settings.m_outputFile = m_argOutput;
settings.m_plotAll = settings.m_plotPages.size() == 0;
plotJob->m_drawingSheet = m_argDrawingSheet;
plotJob->SetVarOverrides( m_argDefineVars );