Gerber X1 plot files: prepare adding more structured comments (aperture and object attributes)

structured comments are lines starting by "G04 #@!" and are therefore Gerber X1 comments.
But these comments contain X2 attributes.
This commit is contained in:
jean-pierre charras 2018-05-17 08:54:25 +02:00
parent dfcdfe91fa
commit d1cab6ec62
3 changed files with 82 additions and 38 deletions

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -32,7 +32,8 @@
#include <gbr_metadata.h> #include <gbr_metadata.h>
std::string GBR_APERTURE_METADATA::FormatAttribute( GBR_APERTURE_ATTRIB aAttribute ) std::string GBR_APERTURE_METADATA::FormatAttribute( GBR_APERTURE_ATTRIB aAttribute,
bool aUseX1StructuredComment )
{ {
std::string attribute_string; std::string attribute_string;
@ -46,80 +47,99 @@ std::string GBR_APERTURE_METADATA::FormatAttribute( GBR_APERTURE_ATTRIB aAttribu
case GBR_APERTURE_ATTRIB_ETCHEDCMP: // print info associated to an item case GBR_APERTURE_ATTRIB_ETCHEDCMP: // print info associated to an item
// which connects 2 different nets // which connects 2 different nets
// (Net tees, microwave component) // (Net tees, microwave component)
attribute_string = "%TA.AperFunction,EtchedComponent*%\n"; attribute_string = "TA.AperFunction,EtchedComponent";
break; break;
case GBR_APERTURE_ATTRIB_CONDUCTOR: // print info associated to a track case GBR_APERTURE_ATTRIB_CONDUCTOR: // print info associated to a track
attribute_string = "%TA.AperFunction,Conductor*%\n"; attribute_string = "TA.AperFunction,Conductor";
break; break;
case GBR_APERTURE_ATTRIB_CUTOUT: // print info associated to a outline case GBR_APERTURE_ATTRIB_CUTOUT: // print info associated to a outline
attribute_string = "%TA.AperFunction,CutOut*%\n"; attribute_string = "TA.AperFunction,CutOut";
break; break;
case GBR_APERTURE_ATTRIB_VIAPAD: // print info associated to a flashed via case GBR_APERTURE_ATTRIB_VIAPAD: // print info associated to a flashed via
attribute_string = "%TA.AperFunction,ViaPad*%\n"; attribute_string = "TA.AperFunction,ViaPad";
break; break;
case GBR_APERTURE_ATTRIB_NONCONDUCTOR: // print info associated to a item on a copper layer case GBR_APERTURE_ATTRIB_NONCONDUCTOR: // print info associated to a item on a copper layer
// which is not a track (for instance a text) // which is not a track (for instance a text)
attribute_string = "%TA.AperFunction,NonConductor*%\n"; attribute_string = "TA.AperFunction,NonConductor";
break; break;
case GBR_APERTURE_ATTRIB_COMPONENTPAD: // print info associated to a flashed case GBR_APERTURE_ATTRIB_COMPONENTPAD: // print info associated to a flashed
// through hole component on outer layer // through hole component on outer layer
attribute_string = "%TA.AperFunction,ComponentPad*%\n"; attribute_string = "TA.AperFunction,ComponentPad";
break; break;
case GBR_APERTURE_ATTRIB_SMDPAD_SMDEF: // print info associated to a flashed for SMD pad. case GBR_APERTURE_ATTRIB_SMDPAD_SMDEF: // print info associated to a flashed for SMD pad.
// with solder mask defined from the copper shape // with solder mask defined from the copper shape
// Excluded BGA pads which have their own type // Excluded BGA pads which have their own type
attribute_string = "%TA.AperFunction,SMDPad,SMDef*%\n"; attribute_string = "TA.AperFunction,SMDPad,SMDef";
break; break;
case GBR_APERTURE_ATTRIB_SMDPAD_CUDEF: // print info associated to a flashed SMD pad with case GBR_APERTURE_ATTRIB_SMDPAD_CUDEF: // print info associated to a flashed SMD pad with
// a solder mask defined by the solder mask // a solder mask defined by the solder mask
attribute_string = "%TA.AperFunction,SMDPad,CuDef*%\n"; attribute_string = "TA.AperFunction,SMDPad,CuDef";
break; break;
case GBR_APERTURE_ATTRIB_BGAPAD_SMDEF: // print info associated to flashed BGA pads with case GBR_APERTURE_ATTRIB_BGAPAD_SMDEF: // print info associated to flashed BGA pads with
// a solder mask defined by the copper shape // a solder mask defined by the copper shape
attribute_string = "%TA.AperFunction,BGAPad,SMDef*%\n"; attribute_string = "TA.AperFunction,BGAPad,SMDef";
break; break;
case GBR_APERTURE_ATTRIB_BGAPAD_CUDEF: // print info associated to a flashed BGA pad with case GBR_APERTURE_ATTRIB_BGAPAD_CUDEF: // print info associated to a flashed BGA pad with
// a solder mask defined by the solder mask // a solder mask defined by the solder mask
attribute_string = "%TA.AperFunction,BGAPad,CuDef*%\n"; attribute_string = "%TA.AperFunction,BGAPad,CuDef";
break; break;
case GBR_APERTURE_ATTRIB_CONNECTORPAD: // print info associated to a flashed edge connector pad (outer layers) case GBR_APERTURE_ATTRIB_CONNECTORPAD: // print info associated to a flashed edge connector pad (outer layers)
attribute_string = "%TA.AperFunction,ConnectorPad*%\n"; attribute_string = "TA.AperFunction,ConnectorPad";
break; break;
case GBR_APERTURE_ATTRIB_WASHERPAD: // print info associated to flashed mechanical pads (NPTH) case GBR_APERTURE_ATTRIB_WASHERPAD: // print info associated to flashed mechanical pads (NPTH)
attribute_string = "%TA.AperFunction,WasherPad*%\n"; attribute_string = "TA.AperFunction,WasherPad";
break; break;
case GBR_APERTURE_ATTRIB_HEATSINKPAD: // print info associated to a flashed heat sink pad case GBR_APERTURE_ATTRIB_HEATSINKPAD: // print info associated to a flashed heat sink pad
// (typically for SMDs) // (typically for SMDs)
attribute_string = "%TA.AperFunction,HeatsinkPad*%\n"; attribute_string = "TA.AperFunction,HeatsinkPad";
break; break;
case GBR_APERTURE_ATTRIB_VIADRILL: // print info associated to a via hole in drill files case GBR_APERTURE_ATTRIB_VIADRILL: // print info associated to a via hole in drill files
attribute_string = "%TA.AperFunction,ViaDrill*%\n"; attribute_string = "TA.AperFunction,ViaDrill";
break; break;
case GBR_APERTURE_ATTRIB_COMPONENTDRILL: // print info associated to a component case GBR_APERTURE_ATTRIB_COMPONENTDRILL: // print info associated to a component
// round hole in drill files // round hole in drill files
attribute_string = "%TA.AperFunction,ComponentDrill*%\n"; attribute_string = "TA.AperFunction,ComponentDrill";
break; break;
case GBR_APERTURE_ATTRIB_SLOTDRILL: // print info associated to a oblong hole in drill files case GBR_APERTURE_ATTRIB_SLOTDRILL: // print info associated to a oblong hole in drill files
attribute_string = "%TA.AperFunction,Slot*%\n"; attribute_string = "TA.AperFunction,Slot";
break; break;
} }
return attribute_string; std::string full_attribute_string;
wxString eol_string;
if( !attribute_string.empty() )
{
if( aUseX1StructuredComment )
{
full_attribute_string = "G04 #@! ";
eol_string = "*\n";
}
else
{
full_attribute_string = "%";
eol_string = "*%\n";
}
}
full_attribute_string += attribute_string + eol_string;
return full_attribute_string;
} }
wxString FormatStringFromGerber( const wxString& aString ) wxString FormatStringFromGerber( const wxString& aString )
@ -209,9 +229,23 @@ std::string formatStringToGerber( const wxString& aString )
#define NO_PAD_NAME wxT( "" ) // pad name of pads without pad name/number (not normalized) #define NO_PAD_NAME wxT( "" ) // pad name of pads without pad name/number (not normalized)
bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttributes, bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttributes,
GBR_NETLIST_METADATA* aData, bool& aClearPreviousAttributes ) GBR_NETLIST_METADATA* aData, bool& aClearPreviousAttributes,
bool aUseX1StructuredComment )
{ {
aClearPreviousAttributes = false; aClearPreviousAttributes = false;
wxString prepend_string;
wxString eol_string;
if( aUseX1StructuredComment )
{
prepend_string = "G04 #@! ";
eol_string = "*\n";
}
else
{
prepend_string = "%";
eol_string = "*%\n";
}
// print a Gerber net attribute record. // print a Gerber net attribute record.
// it is added to the object attributes dictionnary // it is added to the object attributes dictionnary
@ -230,7 +264,7 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu
{ {
// print info associated to a flashed pad (cmpref, pad name) // print info associated to a flashed pad (cmpref, pad name)
// example: %TO.P,R5,3*% // example: %TO.P,R5,3*%
pad_attribute_string = "%TO.P,"; pad_attribute_string = prepend_string + "TO.P,";
pad_attribute_string += formatStringToGerber( aData->m_Cmpref ) + ","; pad_attribute_string += formatStringToGerber( aData->m_Cmpref ) + ",";
if( aData->m_Padname.IsEmpty() ) if( aData->m_Padname.IsEmpty() )
@ -239,14 +273,14 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu
else else
pad_attribute_string += formatStringToGerber( aData->m_Padname ); pad_attribute_string += formatStringToGerber( aData->m_Padname );
pad_attribute_string += "*%\n"; pad_attribute_string += eol_string;
} }
if( ( aData->m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_NET ) ) if( ( aData->m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_NET ) )
{ {
// print info associated to a net // print info associated to a net
// example: %TO.N,Clk3*% // example: %TO.N,Clk3*%
net_attribute_string = "%TO.N,"; net_attribute_string = prepend_string + "TO.N,";
if( aData->m_Netname.IsEmpty() ) if( aData->m_Netname.IsEmpty() )
{ {
@ -266,7 +300,7 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu
else else
net_attribute_string += formatStringToGerber( aData->m_Netname ); net_attribute_string += formatStringToGerber( aData->m_Netname );
net_attribute_string += "*%\n"; net_attribute_string += eol_string;
} }
if( ( aData->m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_CMP ) && if( ( aData->m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_CMP ) &&
@ -276,8 +310,8 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu
// example: %TO.C,R2*% // example: %TO.C,R2*%
// Because GBR_NETINFO_PAD option already contains this info, it is not // Because GBR_NETINFO_PAD option already contains this info, it is not
// created here for a GBR_NETINFO_PAD attribute // created here for a GBR_NETINFO_PAD attribute
cmp_attribute_string = "%TO.C,"; cmp_attribute_string = prepend_string + "TO.C,";
cmp_attribute_string += formatStringToGerber( aData->m_Cmpref ) + "*%\n"; cmp_attribute_string += formatStringToGerber( aData->m_Cmpref ) + eol_string;
} }
// the full list of requested attributes: // the full list of requested attributes:
@ -294,7 +328,7 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu
// the entire dictionnary is cleared // the entire dictionnary is cleared
bool clearDict = false; bool clearDict = false;
if( aLastNetAttributes.find( "%TO.P," ) != std::string::npos ) if( aLastNetAttributes.find( "TO.P," ) != std::string::npos )
{ {
if( pad_attribute_string.empty() ) // No more this attribute if( pad_attribute_string.empty() ) // No more this attribute
clearDict = true; clearDict = true;
@ -305,7 +339,7 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu
else // New attribute else // New attribute
short_attribute_string += pad_attribute_string; short_attribute_string += pad_attribute_string;
if( aLastNetAttributes.find( "%TO.N," ) != std::string::npos ) if( aLastNetAttributes.find( "TO.N," ) != std::string::npos )
{ {
if( net_attribute_string.empty() ) // No more this attribute if( net_attribute_string.empty() ) // No more this attribute
clearDict = true; clearDict = true;
@ -316,7 +350,7 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu
else // New attribute else // New attribute
short_attribute_string += net_attribute_string; short_attribute_string += net_attribute_string;
if( aLastNetAttributes.find( "%TO.C," ) != std::string::npos ) if( aLastNetAttributes.find( "TO.C," ) != std::string::npos )
{ {
if( cmp_attribute_string.empty() ) // No more this attribute if( cmp_attribute_string.empty() ) // No more this attribute
clearDict = true; clearDict = true;

View File

@ -145,7 +145,7 @@ void GERBER_PLOTTER::formatNetAttribute( GBR_NETLIST_METADATA* aData )
std::string short_attribute_string; std::string short_attribute_string;
if( !FormatNetAttribute( short_attribute_string, m_objectAttributesDictionnary, if( !FormatNetAttribute( short_attribute_string, m_objectAttributesDictionnary,
aData, clearDict ) ) aData, clearDict, false ) )
return; return;
if( clearDict ) if( clearDict )
@ -351,7 +351,8 @@ void GERBER_PLOTTER::writeApertureList()
if( attribute != m_apertureAttribute ) if( attribute != m_apertureAttribute )
fputs( GBR_APERTURE_METADATA::FormatAttribute( fputs( GBR_APERTURE_METADATA::FormatAttribute(
(GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB) attribute ).c_str(), outputFile ); (GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB) attribute, false ).c_str(),
outputFile );
char* text = cbuf + sprintf( cbuf, "%%ADD%d", tool->m_DCode ); char* text = cbuf + sprintf( cbuf, "%%ADD%d", tool->m_DCode );

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -82,11 +82,17 @@ public:
/** /**
* @return the full command string corresponding to the aperture attribute * @return the full command string corresponding to the aperture attribute
* like "%TA.AperFunction,<function>*%" * like "%TA.AperFunction,<function>*%"
* @param aUseX1StructuredComment = false in X2 mode,
* and true in X1 mode to add the net attribut
* inside a compatible X1 structured comment starting by "G04 #@! "
* like "G04 #@! TA.AperFunction,<function>*"
*/ */
static std::string FormatAttribute( GBR_APERTURE_ATTRIB aAttribute ); static std::string FormatAttribute( GBR_APERTURE_ATTRIB aAttribute,
std::string FormatAttribute() bool aUseX1StructuredComment );
std::string FormatAttribute( bool aUseX1StructuredComment )
{ {
return FormatAttribute( m_ApertAttribute ); return FormatAttribute( m_ApertAttribute, aUseX1StructuredComment );
} }
// The id of the aperture attribute // The id of the aperture attribute
@ -180,12 +186,15 @@ wxString FormatStringFromGerber( const wxString& aString );
* @param aClearPreviousAttributes returns true if the full set of attributes * @param aClearPreviousAttributes returns true if the full set of attributes
* must be deleted from file before adding new attribute (happens when a previous * must be deleted from file before adding new attribute (happens when a previous
* attribute does not exist no more). * attribute does not exist no more).
* @param aUseX1StructuredComment = false in X2 mode, and true in X1 mode to add the net attribut
* in compatible X1 structured comment (i.e. prefixed by "G04 #@! ")
* @return false if nothing can be done (GBR_NETLIST_METADATA has GBR_APERTURE_ATTRIB_NONE, * @return false if nothing can be done (GBR_NETLIST_METADATA has GBR_APERTURE_ATTRIB_NONE,
* and true if OK * and true if OK
* if the new attribute(s) is the same as current attribute(s), aPrintedText * if the new attribute(s) is the same as current attribute(s), aPrintedText
* will be empty * will be empty
*/ */
bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttributes, bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttributes,
GBR_NETLIST_METADATA* aData, bool& aClearPreviousAttributes ); GBR_NETLIST_METADATA* aData, bool& aClearPreviousAttributes,
bool aUseX1StructuredComment );
#endif // GBR_METADATA_H #endif // GBR_METADATA_H