From 6d6542e13324d0efd09584a6fd2952d5163c1d1b Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 30 Nov 2016 17:48:31 +0100 Subject: [PATCH] Gerber file generation: in X1 format, in header, use structured comments instead of basic comments. (a structured comment starts by "G04 #@! " followed by a X2 attribute, and is a comment for old Gerber readers) --- pcbnew/pcbplot.cpp | 41 ++++++++++++++++++++++-------------- pcbnew/pcbplot.h | 13 ++++++------ pcbnew/plot_board_layers.cpp | 9 ++++---- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/pcbnew/pcbplot.cpp b/pcbnew/pcbplot.cpp index 96b781cd5a..60bf961698 100644 --- a/pcbnew/pcbplot.cpp +++ b/pcbnew/pcbplot.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 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 @@ -85,8 +85,8 @@ const wxString GetGerberProtelExtension( LAYER_NUM aLayer ) } } -const wxString GetGerberFileFunctionAttribute( const BOARD *aBoard, - LAYER_NUM aLayer, bool aUseX1CompatibilityMode ) + +const wxString GetGerberFileFunctionAttribute( const BOARD *aBoard, LAYER_NUM aLayer ) { wxString attrib; @@ -193,11 +193,7 @@ const wxString GetGerberFileFunctionAttribute( const BOARD *aBoard, } wxString fileFct; - - if( aUseX1CompatibilityMode ) - fileFct.Printf( "G04 #@! TF.FileFunction,%s*", GetChars( attrib ) ); - else - fileFct.Printf( "%%TF.FileFunction,%s*%%", GetChars( attrib ) ); + fileFct.Printf( "%%TF.FileFunction,%s*%%", GetChars( attrib ) ); return fileFct; } @@ -260,15 +256,28 @@ static const wxString GetGerberFilePolarityAttribute( LAYER_NUM aLayer ) /* Add some X2 attributes to the file header, as defined in the * Gerber file format specification J4 and "Revision 2015.06" */ + +// A helper function to convert a X2 attribute string to a X1 structured comment: +static wxString& makeStringCompatX1( wxString& aText, bool aUseX1CompatibilityMode ) +{ + if( aUseX1CompatibilityMode ) + { + aText.Replace( "%", "" ); + aText.Prepend( "G04 #@! " ); + } + + return aText; +} + void AddGerberX2Attribute( PLOTTER * aPlotter, - const BOARD *aBoard, LAYER_NUM aLayer ) + const BOARD *aBoard, LAYER_NUM aLayer, bool aUseX1CompatibilityMode ) { wxString text; // Creates the TF,.GenerationSoftware. Format is: // %TF,.GenerationSoftware,,[,]*% text.Printf( wxT( "%%TF.GenerationSoftware,KiCad,Pcbnew,%s*%%" ), GetBuildVersion() ); - aPlotter->AddLineToHeader( text ); + aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) ); // creates the TF.CreationDate ext: // The attribute value must conform to the full version of the ISO 8601 @@ -283,7 +292,7 @@ void AddGerberX2Attribute( PLOTTER * aPlotter, if( msg.Len() > 3 ) msg.insert( 3, ":", 1 ), text.Printf( wxT( "%%TF.CreationDate,%s%s*%%" ), GetChars( date.FormatISOCombined() ), GetChars( msg ) ); - aPlotter->AddLineToHeader( text ); + aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) ); // Creates the TF,.ProjectId. Format is (from Gerber file format doc): // %TF.ProjectId,,,*% @@ -329,17 +338,17 @@ void AddGerberX2Attribute( PLOTTER * aPlotter, rev = wxT( "rev?" ); text.Printf( wxT( "%%TF.ProjectId,%s,%s,%s*%%" ), msg.ToAscii(), GetChars( guid ), rev.ToAscii() ); - aPlotter->AddLineToHeader( text ); + aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) ); // Add the TF.FileFunction - text = GetGerberFileFunctionAttribute( aBoard, aLayer, false ); - aPlotter->AddLineToHeader( text ); + text = GetGerberFileFunctionAttribute( aBoard, aLayer ); + aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) ); // Add the TF.FilePolarity (for layers which support that) text = GetGerberFilePolarityAttribute( aLayer ); if( !text.IsEmpty() ) - aPlotter->AddLineToHeader( text ); + aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) ); } diff --git a/pcbnew/pcbplot.h b/pcbnew/pcbplot.h index 4ef67b6d05..602f3bac00 100644 --- a/pcbnew/pcbplot.h +++ b/pcbnew/pcbplot.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 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 @@ -264,12 +264,9 @@ const wxString GetGerberProtelExtension( LAYER_NUM aLayer ); * the "%TF.FileFunction" attribute prefix and the "*%" suffix. * @param aBoard = the board, needed to get the total count of copper layers * @param aLayer = the layer number to create the attribute for - * @param aUseX1CompatibilityMode = true to use a file function attribute like G04 comment - * , compatible with X1 (rx274) notation (G04#@!TF.FileFunction) * @return The attribute, as a text string */ -const wxString GetGerberFileFunctionAttribute( const BOARD *aBoard, - LAYER_NUM aLayer, bool aUseX1CompatibilityMode ); +const wxString GetGerberFileFunctionAttribute( const BOARD *aBoard, LAYER_NUM aLayer ); /** * Function AddGerberX2Attribute @@ -279,7 +276,11 @@ const wxString GetGerberFileFunctionAttribute( const BOARD *aBoard, * @param aPlotter, the current plotter. * @param aBoard = the board, needed to extract some info * @param aLayer = the layer number to create the attribute for + * @param aUseX1CompatibilityMode = false to generate X2 attributes, true to + * use X1 compatibility (X2 attributes added as structured comments, + * starting by "G04 #@! " followed by the X2 attribute */ -extern void AddGerberX2Attribute( PLOTTER * aPlotter, const BOARD *aBoard, LAYER_NUM aLayer ); +extern void AddGerberX2Attribute( PLOTTER * aPlotter, const BOARD *aBoard, + LAYER_NUM aLayer, bool aUseX1CompatibilityMode ); #endif // PCBPLOT_H_ diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 73d8aac2a5..beb6b665b0 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -8,7 +8,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 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 @@ -1031,14 +1031,15 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, PCB_PLOT_PARAMS *aPlotOpts, if( useX2mode ) { - AddGerberX2Attribute( plotter, aBoard, aLayer ); + AddGerberX2Attribute( plotter, aBoard, aLayer, false ); GERBER_PLOTTER* gbrplotter = static_cast ( plotter ); gbrplotter->UseX2Attributes( true ); gbrplotter->UseX2NetAttributes( plotOpts.GetIncludeGerberNetlistInfo() ); } else - plotter->AddLineToHeader( GetGerberFileFunctionAttribute( - aBoard, aLayer, true ) ); + { + AddGerberX2Attribute( plotter, aBoard, aLayer, true ); + } } plotter->StartPlot();