KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_sch_export_plot.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Mark Roszko <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <kiface_base.h>
22#include <sch_plotter.h>
24#include <cli/exit_codes.h>
27#include <layer_ids.h>
28#include <wx/crt.h>
29#include <string_utils.h>
30
31#include <macros.h>
32#include <wx/tokenzr.h>
33
34#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet"
35#define ARG_NO_BACKGROUND_COLOR "--no-background-color"
36#define ARG_PAGES "--pages"
37#define ARG_EXCLUDE_PDF_PROPERTY_POPUPS "--exclude-pdf-property-popups"
38#define ARG_EXCLUDE_PDF_HIERARCHICAL_LINKS "--exclude-pdf-hierarchical-links"
39#define ARG_EXCLUDE_PDF_METADATA "--exclude-pdf-metadata"
40#define ARG_FONT_NAME "--default-font"
41#define ARG_DRAW_HOP_OVER "--draw-hop-over"
42
43#define DEPRECATED_ARG_HPGL_PEN_SIZE "--pen-size"
44#define DEPRECATED_ARG_HPGL_ORIGIN "--origin"
45
47 const std::string& aDescription,
48 SCH_PLOT_FORMAT aPlotFormat,
49 bool aOutputIsDir ) :
50 COMMAND( aName ),
51 m_plotFormat( aPlotFormat )
52{
53 m_argParser.add_description( aDescription );
54
55 addCommonArgs( true, true, false, aOutputIsDir );
58
59 m_argParser.add_argument( "-t", ARG_THEME )
60 .default_value( std::string() )
61 .help( UTF8STDSTR( _( "Color theme to use (will default to schematic settings)" ) ) )
62 .metavar( "THEME_NAME" );
63 m_argParser.add_argument( "-b", ARG_BLACKANDWHITE )
65 .flag();
66
67 m_argParser.add_argument( "-e", ARG_EXCLUDE_DRAWING_SHEET )
68 .help( UTF8STDSTR( _( "No drawing sheet" ) ) )
69 .implicit_value( true )
70 .default_value( false );
71
72 m_argParser.add_argument( ARG_FONT_NAME )
73 .help( UTF8STDSTR( _( "Default font name" ) ) )
74 .default_value( wxString( "" ).ToStdString() );
75
76 m_argParser.add_argument( ARG_DRAW_HOP_OVER )
77 .help( UTF8STDSTR( _( "Draw hop over at wire crossings" ) ) )
78 .implicit_value( true )
79 .default_value( false );
80
81 if( aPlotFormat == SCH_PLOT_FORMAT::PDF )
82 {
84 .help( UTF8STDSTR( _( "Do not generate property popups in PDF" ) ) )
85 .flag();
86
88 .help( UTF8STDSTR( _( "Do not generate clickable links for hierarchical elements in PDF" ) ) )
89 .flag();
90
92 .help( UTF8STDSTR( _( "Do not generate PDF metadata from AUTHOR and SUBJECT variables" ) ) )
93 .flag();
94 }
95
96 if( aPlotFormat == SCH_PLOT_FORMAT::PDF
97 || aPlotFormat == SCH_PLOT_FORMAT::POST
98 || aPlotFormat == SCH_PLOT_FORMAT::SVG )
99 {
100 m_argParser.add_argument( "-n", ARG_NO_BACKGROUND_COLOR )
101 .help( UTF8STDSTR( _( "Avoid setting a background color (regardless of theme)" ) ) )
102 .flag();
103 }
104
105 m_argParser.add_argument( ARG_PAGES )
106 .default_value( std::string() )
107 .help( UTF8STDSTR( _( "List of page numbers separated by comma to print, blank or "
108 "unspecified is equivalent to all pages" ) ) )
109 .metavar( "PAGE_LIST" );
110
111 if( aPlotFormat == SCH_PLOT_FORMAT::HPGL )
112 {
113 m_argParser.add_argument( "-p", DEPRECATED_ARG_HPGL_PEN_SIZE )
114 .help( UTF8STDSTR( _( "Deprecated. Has no effect." ) ) )
115 .scan<'g', double>()
116 .default_value( 0.5 )
117 .metavar( "PEN_SIZE" );
118
119 m_argParser.add_argument( "-r", DEPRECATED_ARG_HPGL_ORIGIN )
120 .help( UTF8STDSTR( _( "Deprecated. Has no effect." ) ) )
121 .scan<'d', int>()
122 .default_value( 1 )
123 .metavar( "ORIGIN" );
124 }
125}
126
127
129{
130 if( m_plotFormat == SCH_PLOT_FORMAT::HPGL )
131 {
132 wxFprintf( stderr, _( "Plotting to HPGL is no longer supported as of KiCad 10.0.\n" ) );
134 }
135
136 wxString filename = m_argInput;
137
138 if( !wxFile::Exists( filename ) )
139 {
140 wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) );
142 }
143
144 std::vector<wxString> pages;
145 wxString pagesStr = From_UTF8( m_argParser.get<std::string>( ARG_PAGES ).c_str() );
146 wxStringTokenizer tokenizer( pagesStr, "," );
147
148 while( tokenizer.HasMoreTokens() )
149 pages.push_back( tokenizer.GetNextToken().Trim() );
150
151 std::unique_ptr<JOB_EXPORT_SCH_PLOT> plotJob;
152
153 switch( m_plotFormat )
154 {
155 case SCH_PLOT_FORMAT::PDF: plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PDF>( false ); break;
156 case SCH_PLOT_FORMAT::DXF: plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_DXF>(); break;
157 case SCH_PLOT_FORMAT::SVG: plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_SVG>(); break;
158 case SCH_PLOT_FORMAT::POST: plotJob = std::make_unique<JOB_EXPORT_SCH_PLOT_PS>(); break;
159 case SCH_PLOT_FORMAT::HPGL: /* no longer supported */ break;
160 }
161
162 plotJob->m_filename = filename;
163 plotJob->m_plotFormat = m_plotFormat;
164 plotJob->m_plotPages = pages;
165 plotJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
166 plotJob->m_pageSizeSelect = JOB_PAGE_SIZE::PAGE_SIZE_AUTO;
167 plotJob->m_defaultFont = m_argParser.get( ARG_FONT_NAME );
168 plotJob->m_show_hop_over = m_argParser.get<bool>( ARG_DRAW_HOP_OVER );
169
170 if( m_plotFormat == SCH_PLOT_FORMAT::PDF
171 || m_plotFormat == SCH_PLOT_FORMAT::POST
172 || m_plotFormat == SCH_PLOT_FORMAT::SVG )
173 {
174 plotJob->m_useBackgroundColor = !m_argParser.get<bool>( ARG_NO_BACKGROUND_COLOR );
175 }
176
177 plotJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
178 plotJob->m_theme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
179
180 plotJob->SetConfiguredOutputPath( m_argOutput );
181
182 plotJob->m_plotAll = plotJob->m_plotPages.size() == 0;
183
184 plotJob->m_drawingSheet = m_argDrawingSheet;
185 plotJob->SetVarOverrides( m_argDefineVars );
186
187 // PDF local options
188 if( m_plotFormat == SCH_PLOT_FORMAT::PDF )
189 {
190 plotJob->m_PDFPropertyPopups = !m_argParser.get<bool>( ARG_EXCLUDE_PDF_PROPERTY_POPUPS );
191 plotJob->m_PDFHierarchicalLinks = !m_argParser.get<bool>( ARG_EXCLUDE_PDF_HIERARCHICAL_LINKS );
192 plotJob->m_PDFMetadata = !m_argParser.get<bool>( ARG_EXCLUDE_PDF_METADATA );
193 }
194
195 int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, plotJob.get() );
196
197 return exitCode;
198}
void addCommonArgs(bool aInput, bool aOutput, bool aInputCanBeDir, bool aOutputIsDir)
Set up the most common of args used across cli.
Definition: command.cpp:115
argparse::ArgumentParser m_argParser
Definition: command.h:100
void addDefineArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:168
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:156
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
SCH_EXPORT_PLOT_COMMAND(const std::string &aName, const std::string &aDescription, SCH_PLOT_FORMAT aPlotFormat, bool aOutputIsDir=true)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
@ FACE_SCH
eeschema DSO
Definition: kiway.h:292
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr)
Definition: kiway.cpp:678
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_THEME
#define ARG_BLACKANDWHITE_DESC
#define ARG_BLACKANDWHITE
#define ARG_EXCLUDE_DRAWING_SHEET
#define ARG_EXCLUDE_PDF_PROPERTY_POPUPS
#define ARG_NO_BACKGROUND_COLOR
#define DEPRECATED_ARG_HPGL_ORIGIN
#define ARG_EXCLUDE_PDF_HIERARCHICAL_LINKS
#define ARG_FONT_NAME
#define ARG_DRAW_HOP_OVER
#define DEPRECATED_ARG_HPGL_PEN_SIZE
#define ARG_PAGES
#define ARG_EXCLUDE_PDF_METADATA
#define _(s)
SCH_PLOT_FORMAT
This file contains miscellaneous commonly used macros and functions.
static const int ERR_ARGS
Definition: exit_codes.h:31
static const int ERR_INVALID_INPUT_FILE
Definition: exit_codes.h:33
wxString From_UTF8(const char *cstring)