KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gbr_metadata.cpp File Reference

helper functions to handle the gerber metadata in files, related to the netlist info and aperture attribute. More...

#include <wx/string.h>
#include <wx/datetime.h>
#include <gbr_metadata.h>
#include <core/utf8.h>

Go to the source code of this file.

Macros

#define NO_NET_NAME   wxT( "N/C" )
 
#define NO_PAD_NAME   wxT( "" )
 

Functions

wxString GbrMakeCreationDateAttributeString (GBR_NC_STRING_FORMAT aFormat)
 
wxString GbrMakeProjectGUIDfromString (const wxString &aText)
 Build a project GUID using format RFC4122 Version 1 or 4 from the project name, because a KiCad project has no specific GUID. More...
 
int char2Hex (unsigned aCode)
 
wxString FormatStringFromGerber (const wxString &aString)
 Convert a gerber string into a 16 bit Unicode string. More...
 
wxString ConvertNotAllowedCharsInGerber (const wxString &aString, bool aAllowUtf8Chars, bool aQuoteString)
 Normalize aString and convert it to a Gerber compatible wxString. More...
 
std::string FormatStringToGerber (const wxString &aString)
 Normalize aString and convert it to a Gerber std::string. More...
 
bool FormatNetAttribute (std::string &aPrintedText, std::string &aLastNetAttributes, const GBR_NETLIST_METADATA *aData, bool &aClearPreviousAttributes, bool aUseX1StructuredComment)
 Generate the string to set a net attribute for a graphic object to print to a gerber file. More...
 

Detailed Description

helper functions to handle the gerber metadata in files, related to the netlist info and aperture attribute.

Definition in file gbr_metadata.cpp.

Macro Definition Documentation

◆ NO_NET_NAME

#define NO_NET_NAME   wxT( "N/C" )

Definition at line 538 of file gbr_metadata.cpp.

◆ NO_PAD_NAME

#define NO_PAD_NAME   wxT( "" )

Definition at line 539 of file gbr_metadata.cpp.

Function Documentation

◆ char2Hex()

int char2Hex ( unsigned  aCode)

Definition at line 354 of file gbr_metadata.cpp.

Referenced by FormatStringFromGerber().

◆ ConvertNotAllowedCharsInGerber()

wxString ConvertNotAllowedCharsInGerber ( const wxString &  aString,
bool  aAllowUtf8Chars,
bool  aQuoteString 
)

Normalize aString and convert it to a Gerber compatible wxString.

Normalization means convert to a hexadecimal 16 bit sequence Unicode and on request convert any code > 0x7F. Illegal characters are ',' '*' '' '\'.

Parameters
aStringthe string to convert.
aAllowUtf8Charsfalse to convert non ASCII7 values to Unicode sequence.
aQuoteStringtrue to double quote the returned string.
Returns
a without illegal chars (and converted non ASCII7 chars on request)

Definition at line 435 of file gbr_metadata.cpp.

References convert.

Referenced by PLACEFILE_GERBER_WRITER::CreatePlaceFile(), FormatStringToGerber(), and GBR_DATA_FIELD::GetGerberString().

◆ FormatNetAttribute()

bool FormatNetAttribute ( std::string &  aPrintedText,
std::string &  aLastNetAttributes,
const GBR_NETLIST_METADATA aData,
bool &  aClearPreviousAttributes,
bool  aUseX1StructuredComment 
)

Generate the string to set a net attribute for a graphic object to print to a gerber file.

Parameters
aPrintedTextis the string to print.
aLastNetAttributesis the current full set of attributes.
aDatais the GBR_NETLIST_METADATA associated to the graphic object (can be NULL if no associated metadata, and aClearPreviousAttributes will be set to false)
aClearPreviousAttributesreturns true if the full set of attributes must be deleted from file before adding new attribute (happens when a previous attribute no longer exists).
aUseX1StructuredCommentfalse in X2 mode and true in X1 mode to add the net attribute in compatible X1 structured comment (i.e. prefixed by "G04 #@! ")
Returns
false if nothing can be done (GBR_NETLIST_METADATA has GBR_APERTURE_ATTRIB_NONE, and true if OK. If the new attribute(s) is the same as current attribute(s), aPrintedText will be empty.

Definition at line 542 of file gbr_metadata.cpp.

References FormatStringToGerber(), GBR_NETLIST_METADATA::GBR_NETINFO_CMP, GBR_NETLIST_METADATA::GBR_NETINFO_NET, GBR_NETLIST_METADATA::GBR_NETINFO_PAD, GBR_NETLIST_METADATA::GBR_NETINFO_UNSPECIFIED, GBR_DATA_FIELD::GetGerberString(), GBR_DATA_FIELD::IsEmpty(), GBR_NETLIST_METADATA::m_Cmpref, GBR_NETLIST_METADATA::m_NetAttribType, GBR_NETLIST_METADATA::m_Netname, GBR_NETLIST_METADATA::m_NotInNet, GBR_NETLIST_METADATA::m_Padname, GBR_NETLIST_METADATA::m_PadPinFunction, GBR_NETLIST_METADATA::m_TryKeepPreviousAttributes, NO_NET_NAME, and NO_PAD_NAME.

Referenced by GERBER_PLOTTER::formatNetAttribute().

◆ FormatStringFromGerber()

wxString FormatStringFromGerber ( const wxString &  aString)

Convert a gerber string into a 16 bit Unicode string.

Parameters
aStringthe gerber string to format.
Returns
a 16 bit Unicode string.

Definition at line 369 of file gbr_metadata.cpp.

References char2Hex().

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand().

◆ FormatStringToGerber()

std::string FormatStringToGerber ( const wxString &  aString)

Normalize aString and convert it to a Gerber std::string.

Normalization means convert any code > 0x7F and unauthorized code to a hexadecimal 16 bit sequence Unicode. Illegal characters are ',' '*' '' '\'.

Parameters
aStringthe string to convert.
Returns
an ASCII7 coded compliant gerber string.

Definition at line 512 of file gbr_metadata.cpp.

References ConvertNotAllowedCharsInGerber().

Referenced by FormatNetAttribute().

◆ GbrMakeCreationDateAttributeString()

◆ GbrMakeProjectGUIDfromString()

wxString GbrMakeProjectGUIDfromString ( const wxString &  aText)

Build a project GUID using format RFC4122 Version 1 or 4 from the project name, because a KiCad project has no specific GUID.

RFC4122 is used mainly for its syntax, because fields have no meaning for Gerber files and therefore the GUID generated has no meaning because it do not use any time and time stamp specific to the project, just a random pattern (random is here a pattern specific to a project).

See en.wikipedia.org/wiki/Universally_unique_identifier

Definition at line 81 of file gbr_metadata.cpp.

Referenced by AddGerberX2Header(), and GERBER_JOBFILE_WRITER::addJSONGeneralSpecs().