38 extern int ReadInt(
char*& text,
bool aSkipSeparator =
true );
39 extern double ReadDouble(
char*& text,
bool aSkipSeparator =
true );
42 #define CODE( x, y ) ( ( (x) << 8 ) + (y) ) 125 result = ( currbyte & 0xFF ) << 8;
133 result += currbyte & 0xFF;
198 unsigned int aBuffSize,
char*& aText )
206 bool x_fmt_known =
false;
207 bool y_fmt_known =
false;
220 while( *aText !=
'*' )
229 msg.Printf(
_(
"RS274X: Invalid GERBER format command '%c' at line %d: \"%s\"" ),
232 msg.Printf(
_(
"GERBER file \"%s\" may not display as intended." ),
264 if( (seq_char >=
'0') && (seq_char <=
'9') )
265 seq_len = seq_char -
'0';
275 if( ( code >=
'0' ) && ( code <=
'9' ) )
284 char ctmp = *(aText++) -
'0';
322 msg.Printf( wxT(
"Unknown id (%c) in FS command" ),
331 if( !x_fmt_known || !y_fmt_known )
332 AddMessageToList( wxT(
"RS274X: Format Statement (FS) without X or Y format" ) );
339 if( strncasecmp( aText,
"AYBX", 4 ) == 0 )
347 while( *aText && *aText !=
'*' )
390 if(
dummy.IsFileFunction() )
399 else if(
dummy.IsFileMD5() )
403 else if(
dummy.IsFilePart() )
415 if(
dummy.GetAttribute() ==
".AperFunction" )
420 for(
int ii = 2; ii <
dummy.GetPrmCount(); ii++ )
432 if(
dummy.GetAttribute() ==
".N" )
437 else if(
dummy.GetAttribute() ==
".C" )
442 else if(
dummy.GetAttribute() ==
".P" )
448 if(
dummy.GetPrmCount() > 3 )
471 while( *aText !=
'*' )
492 while( *aText !=
'*' )
511 while( *aText !=
'*' )
531 if( strncasecmp( aText,
"0*", 2 ) == 0 )
533 else if( strncasecmp( aText,
"90*", 3 ) == 0 )
535 else if( strncasecmp( aText,
"180*", 4 ) == 0 )
537 else if( strncasecmp( aText,
"270*", 4 ) == 0 )
552 while( *aText && *aText !=
'*' )
587 while( *aText && *aText !=
'*' )
600 else if( *aText ==
'L' )
620 else if( *aText ==
'L' )
648 msg =
_(
"RS274X: Command KNOCKOUT ignored by GerbView" ) ;
660 while( *aText !=
'*' )
667 while( *aText && *aText !=
'*' )
673 if( strncasecmp( aText,
"NEG", 3 ) == 0 )
702 if( *aText++ !=
'D' )
723 if( aText[1] ==
',' )
725 char stdAperture = *aText;
733 switch( stdAperture )
737 while( *aText ==
' ' )
748 while( *aText ==
' ' )
766 while( *aText ==
' ' )
776 while( *aText ==
' ' )
787 while( *aText ==
' ' )
807 while( *aText ==
' ' )
816 while( *aText ==
' ' )
825 while( *aText ==
' ' )
836 while( *aText ==
' ' )
853 while( *aText && *aText !=
'*' && *aText !=
',' )
854 am_lookup.
name.Append( *aText++ );
862 while( *aText && *aText !=
'*' )
867 while( isspace( *aText ) )
871 if( *aText ==
'X' || *aText ==
'x' )
881 msg.Printf( wxT(
"RS274X: aperture macro %s not found\n" ),
911 while( (aText < aBuff + aBuffSize) && *aText )
922 if( fgets( aBuff, aBuffSize, gerber_file ) ==
NULL )
946 if( fgets( aBuff, aBuffSize, aFile ) ==
NULL )
977 am.
name.Append( *aText++ );
986 aText =
GetNextLine( aBuff, aBuffSize, aText, gerber_file );
1012 aText =
GetNextLine( aBuff, aBuffSize, aText, gerber_file );
1018 else if( !isdigit(*aText) )
1020 msg.Printf( wxT(
"RS274X: Aperture Macro \"%s\": ill. symbol, line: \"%s\"" ),
1026 primitive_type =
ReadInt( aText );
1028 bool is_comment =
false;
1030 switch( primitive_type )
1037 while( *aText && ( *aText !=
'*' ) )
1078 msg.Printf( wxT(
"RS274X: Aperture Macro \"%s\": Invalid primitive id code %d, line %d: \"%s\"" ),
1091 for( ii = 0; ii < paramCount && *aText && *aText !=
'*'; ++ii )
1097 aText =
GetNextLine( aBuff, aBuffSize, aText, gerber_file );
1105 if( ii < paramCount )
1108 msg.Printf(
"RS274X: read macro descr type %d: read %d parameters, insufficient parameters\n",
1121 wxASSERT( prim.
params[1].IsImmediate() );
1123 paramCount = (int) prim.
params[1].GetValue( 0 ) * 2 + 1;
1125 for(
int jj = 0; jj < paramCount && *aText !=
'*'; ++jj )
1131 aText =
GetNextLine( aBuff, aBuffSize, aText, gerber_file );
APERTURE_MACRO_SET m_aperture_macros
X2_ATTRIBUTE_FILEFUNCTION ( from TF.FileFunction in Gerber file) Example file function: TF....
int m_LineNum
< Line number of the gerber file while reading.
void AddMessageToList(const wxString &aMessage)
Add a message to the message list.
X2_ATTRIBUTE_FILEFUNCTION * m_FileFunction
X2_ATTRIBUTE The attribute value consists of a number of substrings separated by a comma.
wxString name
The name of the aperture macro.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Implementation of conversion functions that require both schematic and board internal units.
wxSize m_Size
Horizontal and vertical dimensions.
int ReadInt(char *&text, bool aSkipSeparator=true)
Function ReadInt reads an int from an ASCII character buffer.
bool m_ImageJustifyXCenter
< Image Justify Center on X axis (default = false).
APERTURE_T m_Shape
shape ( Line, rectangle, circle , oval .. )
double m_Rotation
shape rotation in degrees
wxSize m_Drill
dimension of the hole (if any) (draill file)
wxRealPoint m_StepForRepeat
bool m_ImageJustifyYCenter
Image Justify Offset on XY axis (default = 0,0).
wxSize m_FmtLen
Image rotation (0, 90, 180, 270 only) in degrees.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
wxPoint m_ImageJustifyOffset
wxSize m_FmtScale
< Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4.
int ReadXCommandID(char *&text)
Read two bytes of data and assembles them into an int with the first byte in the sequence put into th...
bool ReadParam(char *&aText)
Function ReadParam Read one aperture macro parameter a parameter can be: a number a reference to an a...
AM_PARAMS m_localparamStack
This file contains miscellaneous commonly used macros and functions.
bool m_IsX2_file
< True if a X2 gerber attribute was found in file.
bool ExecuteRS274XCommand(int aCommand, char *aBuff, unsigned int aBuffSize, char *&aText)
Execute a RS274X command.
char * GetNextLine(char *aBuff, unsigned int aBuffSize, char *aText, FILE *aFile)
Test for an end of line.
void SetField(const wxString &aField, bool aUseUTF8, bool aEscapeString)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
double ReadDouble(char *&text, bool aSkipSeparator=true)
Function ReadDouble reads a double from an ASCII character buffer.
bool m_Defined
false if the aperture is not defined in the header
void AppendParam(double aValue)
AppendParam() Add a parameter to the D_CODE parameter list.
AM_PARAM holds a parameter value for an "aperture macro" as defined within standard RS274X.
APERTURE_MACRO * FindApertureMacro(const APERTURE_MACRO &aLookup)
Look up a previously read in aperture macro.
bool m_Relative
< false = absolute Coord, true = relative Coord.
bool m_StepForRepeatMetric
bool ReadApertureMacro(char *aBuff, unsigned int aBuffSize, char *&text, FILE *gerber_file)
Read in an aperture macro and saves it in m_aperture_macros.
wxString m_AperFunction
the aperture attribute (created by a TA.AperFunction command) attached to the D_CODE
void RemoveAttribute(X2_ATTRIBUTE &aAttribute)
Called when a TD command is found the Gerber file.
APERTURE_DEF_HOLETYPE m_DrillShape
shape of the hole (0 = no hole, round = 1, rect = 2) */
bool m_Has_DCode
< True if has DCodes in file or false if no DCodes found. Perhaps deprecated RS274D file.
AM_PRIMITIVES primitives
A sequence of AM_PRIMITIVEs.
D_CODE holds a gerber DCODE (also called Aperture) definition.
GBR_NETLIST_METADATA m_NetAttributeDict
bool ReadRS274XCommand(char *aBuff, unsigned int aBuffSize, char *&aText)
Read a single RS274X command terminated with a %.
Struct AM_PRIMITIVE holds an aperture macro primitive as given in Table 3 of http://gerbv....
void SetMacro(APERTURE_MACRO *aMacro)
bool GetEndOfBlock(char *aBuff, unsigned int aBuffSize, char *&aText, FILE *aGerberFile)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
int m_EdgesCount
in aperture definition Polygon only: number of edges for the polygon
AM_PRIMITIVE_ID
Enum AM_PRIMITIVE_ID is the set of all "aperture macro primitives" (primitive numbers).
Struct APERTURE_MACRO helps support the "aperture macro" defined within standard RS274X.
D_CODE * GetDCODEOrCreate(int aDCODE, bool aCreateIfNoExist=true)
Return a pointer to the D_CODE within this GERBER for the given aDCODE.
AM_PARAMS params
A sequence of parameters used by.
GERBER_LAYER & GetLayerParams()
int m_ImageRotation
Local rotation in degrees added to m_ImageRotation.
AM_PRIMITIVE_ID primitive_id
The primitive type.