KiCad PCB EDA Suite
Loading...
Searching...
No Matches
legacy_pcb_plot_format.h
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
23#include <pcb_plot_params.h>
24
26{
27
28// PCB plot grammar from 9.0.0 ccafeabf1503 and 10.0.7 93a8a4827b0b.
29
30inline std::string FormatLayerSet( const LSET& aLayers )
31{
32 for( size_t bit = 128; bit < aLayers.size(); ++bit )
33 {
34 if( aLayers.test( bit ) )
35 THROW_IO_ERROR( wxT( "Unreviewed plot layer in a frozen writer." ) );
36 }
37
38 std::string result;
39 constexpr char hex[] = "0123456789abcdef";
40
41 for( int nibble = 31; nibble >= 0; --nibble )
42 {
43 if( nibble != 31 && ( nibble + 1 ) % 8 == 0 )
44 result += '_';
45
46 int value = 0;
47
48 for( int bit = 0; bit < 4; ++bit )
49 {
50 const size_t index = nibble * 4 + bit;
51
52 if( index < aLayers.size() && aLayers.test( index ) )
53 value |= 1 << bit;
54 }
55
56 result += hex[value];
57 }
58
59 return result;
60}
61
62
63inline int PlotFormatValue( PLOT_FORMAT aFormat )
64{
65 switch( aFormat )
66 {
67 case PLOT_FORMAT::UNDEFINED: return -1;
68 case PLOT_FORMAT::HPGL: return 0;
69 case PLOT_FORMAT::GERBER: return 1;
70 case PLOT_FORMAT::POST: return 2;
71 case PLOT_FORMAT::DXF: return 3;
72 case PLOT_FORMAT::PDF: return 4;
73 case PLOT_FORMAT::SVG: return 5;
74 default: THROW_IO_ERROR( wxT( "Unsupported plot format in a frozen writer." ) );
75 }
76}
77
78
79inline void FormatPlot( OUTPUTFORMATTER* aOut, const PCB_PLOT_PARAMS& aPlot, bool aV9 )
80{
81 const int format = PlotFormatValue( aPlot.GetFormat() );
82 LSET commonLayers;
83
84 for( PCB_LAYER_ID layer : aPlot.GetPlotOnAllLayersSequence() )
85 commonLayers.set( layer );
86
87 aOut->Print( "(pcbplotparams(layerselection 0x%s)", FormatLayerSet( aPlot.GetLayerSelection() ).c_str() );
88 aOut->Print( "(plot_on_all_layers_selection 0x%s)", FormatLayerSet( commonLayers ).c_str() );
89 FormatBool( aOut, "disableapertmacros", aPlot.GetDisableGerberMacros() );
90 FormatBool( aOut, "usegerberextensions", aPlot.GetUseGerberProtelExtensions() );
91 FormatBool( aOut, "usegerberattributes", aPlot.GetUseGerberX2format() );
92 FormatBool( aOut, "usegerberadvancedattributes", aPlot.GetIncludeGerberNetlistInfo() );
93 FormatBool( aOut, "creategerberjobfile", aPlot.GetCreateGerberJobFile() );
94
95 if( aPlot.GetGerberPrecision() != 6 )
96 aOut->Print( "(gerberprecision %d)", aPlot.GetGerberPrecision() );
97
98 if( aV9 )
99 {
100 aOut->Print( "(dashed_line_dash_ratio %f)", aPlot.GetDashedLineDashRatio() );
101 aOut->Print( "(dashed_line_gap_ratio %f)", aPlot.GetDashedLineGapRatio() );
102 }
103 else
104 {
105 aOut->Print( "(dashed_line_dash_ratio %s)", FormatDouble2Str( aPlot.GetDashedLineDashRatio() ).c_str() );
106 aOut->Print( "(dashed_line_gap_ratio %s)", FormatDouble2Str( aPlot.GetDashedLineGapRatio() ).c_str() );
107 }
108
109 aOut->Print( "(svgprecision %d)", aPlot.GetSvgPrecision() );
110 FormatBool( aOut, "plotframeref", aPlot.GetPlotFrameRef() );
111 aOut->Print( "(mode %d)", aPlot.GetDXFPlotMode() == SKETCH ? 2 : 1 );
112 FormatBool( aOut, "useauxorigin", aPlot.GetUseAuxOrigin() );
113
114 if( aV9 )
115 {
116 // Removed model preferences use the pinned release's defaults.
117 aOut->Print( "(hpglpennumber 1)(hpglpenspeed 20)(hpglpendiameter %f)", 15.0 );
118 }
119
120 FormatBool( aOut, "pdf_front_fp_property_popups", aPlot.m_PDFFrontFPPropertyPopups );
121 FormatBool( aOut, "pdf_back_fp_property_popups", aPlot.m_PDFBackFPPropertyPopups );
122 FormatBool( aOut, "pdf_metadata", aPlot.m_PDFMetadata );
123 FormatBool( aOut, "pdf_single_document", aPlot.m_PDFSingle );
124 FormatBool( aOut, "dxfpolygonmode", aPlot.GetDXFPlotPolygonMode() );
125 FormatBool( aOut, "dxfimperialunits", aPlot.GetDXFPlotUnits() == DXF_UNITS::INCH );
126 FormatBool( aOut, "dxfusepcbnewfont", aPlot.GetTextMode() != PLOT_TEXT_MODE::NATIVE );
127 FormatBool( aOut, "psnegative", aPlot.GetNegative() );
128 FormatBool( aOut, "psa4output", aPlot.GetA4Output() );
129 FormatBool( aOut, "plot_black_and_white", aPlot.GetBlackAndWhite() );
130
131 if( aV9 )
132 FormatBool( aOut, "plotinvisibletext", false );
133
134 FormatBool( aOut, "sketchpadsonfab", aPlot.GetSketchPadsOnFabLayers() );
135 FormatBool( aOut, "plotpadnumbers", aPlot.GetPlotPadNumbers() );
136 FormatBool( aOut, "hidednponfab", aPlot.GetHideDNPFPsOnFabLayers() );
137 FormatBool( aOut, "sketchdnponfab", aPlot.GetSketchDNPFPsOnFabLayers() );
138 FormatBool( aOut, "crossoutdnponfab", aPlot.GetCrossoutDNPFPsOnFabLayers() );
139 FormatBool( aOut, "subtractmaskfromsilk", aPlot.GetSubtractMaskFromSilk() );
140 aOut->Print( "(outputformat %d)", format );
141 FormatBool( aOut, "mirror", aPlot.GetMirror() );
142 aOut->Print( "(drillshape %d)", static_cast<int>( aPlot.GetDrillMarksType() ) );
143 aOut->Print( "(scaleselection %d)", aPlot.GetScaleSelection() );
144 aOut->Print( "(outputdirectory %s))", aOut->Quotew( aPlot.GetOutputDirectory() ).c_str() );
145}
146
147
148inline void FormatPlotV9( OUTPUTFORMATTER* aOut, const PCB_PLOT_PARAMS& aPlot )
149{
150 FormatPlot( aOut, aPlot, true );
151}
152
153
154inline void FormatPlotV10( OUTPUTFORMATTER* aOut, const PCB_PLOT_PARAMS& aPlot )
155{
156 FormatPlot( aOut, aPlot, false );
157}
158
159} // namespace KICAD_FORMAT::LEGACY
int index
BASE_SET & set(size_t pos)
Definition base_set.h:126
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
An interface used to output 8 bit text in a convenient way.
Definition richio.h:294
std::string Quotew(const wxString &aWrapee) const
Definition richio.cpp:505
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition richio.cpp:432
Parameters and options when plotting/printing a board.
bool GetNegative() const
PLOT_FORMAT GetFormat() const
bool GetUseAuxOrigin() const
LSEQ GetPlotOnAllLayersSequence() const
bool GetHideDNPFPsOnFabLayers() const
bool GetMirror() const
DXF_UNITS GetDXFPlotUnits() const
bool GetCrossoutDNPFPsOnFabLayers() const
bool GetSketchDNPFPsOnFabLayers() const
unsigned GetSvgPrecision() const
bool m_PDFMetadata
Generate PDF metadata for SUBJECT and AUTHOR.
PLOT_TEXT_MODE GetTextMode() const override
bool GetCreateGerberJobFile() const
bool GetDXFPlotPolygonMode() const
LSET GetLayerSelection() const
wxString GetOutputDirectory() const
int GetScaleSelection() const
bool m_PDFFrontFPPropertyPopups
Generate PDF property popup menus for footprints.
DXF_OUTLINE_MODE GetDXFPlotMode() const override
bool GetSketchPadsOnFabLayers() const
bool GetSubtractMaskFromSilk() const
int GetGerberPrecision() const
bool GetPlotPadNumbers() const
bool GetA4Output() const
DRILL_MARKS GetDrillMarksType() const
bool GetUseGerberX2format() const
bool GetIncludeGerberNetlistInfo() const
bool m_PDFSingle
Generate a single PDF file for all layers.
bool GetBlackAndWhite() const
double GetDashedLineGapRatio() const
bool m_PDFBackFPPropertyPopups
on front and/or back of board
bool GetUseGerberProtelExtensions() const
double GetDashedLineDashRatio() const
bool GetPlotFrameRef() const
bool GetDisableGerberMacros() const
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
void FormatPlotV9(OUTPUTFORMATTER *aOut, const PCB_PLOT_PARAMS &aPlot)
void FormatPlot(OUTPUTFORMATTER *aOut, const PCB_PLOT_PARAMS &aPlot, bool aV9)
void FormatPlotV10(OUTPUTFORMATTER *aOut, const PCB_PLOT_PARAMS &aPlot)
std::string FormatLayerSet(const LSET &aLayers)
int PlotFormatValue(PLOT_FORMAT aFormat)
@ SKETCH
Definition plotter.h:81
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:63
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
wxString result
Test unit parsing edge cases and error handling.