KiCad PCB EDA Suite
X2_ATTRIBUTE Class Reference

The attribute value consists of a number of substrings separated by a comma. More...

#include <X2_gerber_attributes.h>

Inheritance diagram for X2_ATTRIBUTE:
X2_ATTRIBUTE_FILEFUNCTION

Public Member Functions

 X2_ATTRIBUTE ()
 
 ~X2_ATTRIBUTE ()
 
wxArrayString & GetPrms ()
 
const wxString & GetPrm (int aIdx)
 
const wxString & GetAttribute ()
 
int GetPrmCount ()
 
bool ParseAttribCmd (FILE *aFile, char *aBuffer, int aBuffSize, char *&aText, int &aLineNum)
 Parse a TF command terminated with a % and fill m_Prms by the parameters found. More...
 
void DbgListPrms ()
 Debug function: print using wxLogMessage le list of parameters. More...
 
bool IsFileFunction ()
 Return true if the attribute is .FileFunction. More...
 
bool IsFileMD5 ()
 Return true if the attribute is .MD5. More...
 
bool IsFilePart ()
 Return true if the attribute is .Part. More...
 

Protected Attributes

wxArrayString m_Prms
 the list of parameters (after TF) in gbr file the first one is the attribute name, if starting by '. More...
 

Detailed Description

The attribute value consists of a number of substrings separated by a comma.

Definition at line 53 of file X2_gerber_attributes.h.

Constructor & Destructor Documentation

◆ X2_ATTRIBUTE()

X2_ATTRIBUTE::X2_ATTRIBUTE ( )

Definition at line 49 of file X2_gerber_attributes.cpp.

50 {
51 }

◆ ~X2_ATTRIBUTE()

X2_ATTRIBUTE::~X2_ATTRIBUTE ( )

Definition at line 54 of file X2_gerber_attributes.cpp.

55 {
56 }

Member Function Documentation

◆ DbgListPrms()

void X2_ATTRIBUTE::DbgListPrms ( )

Debug function: print using wxLogMessage le list of parameters.

Definition at line 76 of file X2_gerber_attributes.cpp.

77 {
78  wxLogMessage( wxT( "prms count %d" ), GetPrmCount() );
79 
80  for( int ii = 0; ii < GetPrmCount(); ii++ )
81  wxLogMessage( m_Prms.Item( ii ) );
82 }
wxArrayString m_Prms
the list of parameters (after TF) in gbr file the first one is the attribute name,...

References GetPrmCount(), and m_Prms.

◆ GetAttribute()

const wxString & X2_ATTRIBUTE::GetAttribute ( )
Returns
the attribute name (for instance .FileFunction) which is given by TF command (i.e. the first parameter read).

Definition at line 59 of file X2_gerber_attributes.cpp.

60 {
61  return m_Prms.Item( 0 );
62 }
wxArrayString m_Prms
the list of parameters (after TF) in gbr file the first one is the attribute name,...

References m_Prms.

Referenced by IsFileFunction(), IsFileMD5(), and IsFilePart().

◆ GetPrm()

const wxString & X2_ATTRIBUTE::GetPrm ( int  aIdx)
Returns
a parameter read in TF command.
Parameters
aIdx= the index of the parameter aIdx = 0 is the parameter read after the TF function (the same as GetAttribute())

Definition at line 65 of file X2_gerber_attributes.cpp.

66 {
67  static const wxString dummy;
68 
69  if( GetPrmCount() > aIdx && aIdx >= 0 )
70  return m_Prms.Item( aIdx );
71 
72  return dummy;
73 }
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
wxArrayString m_Prms
the list of parameters (after TF) in gbr file the first one is the attribute name,...

References dummy(), GetPrmCount(), and m_Prms.

Referenced by GERBER_FILE_IMAGE::RemoveAttribute().

◆ GetPrmCount()

int X2_ATTRIBUTE::GetPrmCount ( )
inline
Returns
the number of parameters read in TF (or similar like TA TO ...) command.

Definition at line 82 of file X2_gerber_attributes.h.

82 { return int( m_Prms.GetCount() ); }
wxArrayString m_Prms
the list of parameters (after TF) in gbr file the first one is the attribute name,...

References m_Prms.

Referenced by DbgListPrms(), GetPrm(), and X2_ATTRIBUTE_FILEFUNCTION::X2_ATTRIBUTE_FILEFUNCTION().

◆ GetPrms()

wxArrayString& X2_ATTRIBUTE::GetPrms ( )
inline
Returns
the parameters list read in TF command.

Definition at line 62 of file X2_gerber_attributes.h.

62 { return m_Prms; }
wxArrayString m_Prms
the list of parameters (after TF) in gbr file the first one is the attribute name,...

References m_Prms.

Referenced by X2_ATTRIBUTE_FILEFUNCTION::X2_ATTRIBUTE_FILEFUNCTION().

◆ IsFileFunction()

bool X2_ATTRIBUTE::IsFileFunction ( )
inline

Return true if the attribute is .FileFunction.

Definition at line 106 of file X2_gerber_attributes.h.

107  {
108  return GetAttribute().IsSameAs( wxT(".FileFunction"), false );
109  }
const wxString & GetAttribute()

References GetAttribute().

◆ IsFileMD5()

bool X2_ATTRIBUTE::IsFileMD5 ( )
inline

Return true if the attribute is .MD5.

Definition at line 114 of file X2_gerber_attributes.h.

115  {
116  return GetAttribute().IsSameAs( wxT(".MD5"), false );
117  }
const wxString & GetAttribute()

References GetAttribute().

◆ IsFilePart()

bool X2_ATTRIBUTE::IsFilePart ( )
inline

Return true if the attribute is .Part.

Definition at line 122 of file X2_gerber_attributes.h.

123  {
124  return GetAttribute().IsSameAs( wxT(".Part"), false );
125  }
const wxString & GetAttribute()

References GetAttribute().

◆ ParseAttribCmd()

bool X2_ATTRIBUTE::ParseAttribCmd ( FILE *  aFile,
char *  aBuffer,
int  aBuffSize,
char *&  aText,
int &  aLineNum 
)

Parse a TF command terminated with a % and fill m_Prms by the parameters found.

Parameters
aFile= a FILE* ptr to the current Gerber file.
aBuffer= the buffer containing current Gerber data (can be null)
aBuffSize= the size of the buffer
aText= a pointer to the first char to read from Gerber data stored in aBuffer After parsing, text points the last char of the command line ('') (X2 mode) or the end of line if the line does not contain '' or aBuffer == NULL (X1 mode)
aLineNum= a point to the current line number of aFile
Returns
true if no error.

Definition at line 85 of file X2_gerber_attributes.cpp.

87 {
88  // parse a TF, TA, TO ... command and fill m_Prms by the parameters found.
89  // the "%TF" (start of command) is already read by the caller
90 
91  bool ok = true;
92  std::string data;
93 
94  for( ; ; )
95  {
96  while( *aText )
97  {
98  switch( *aText )
99  {
100  case '%': // end of command
101  return ok; // success completion
102 
103  case ' ':
104  case '\r':
105  case '\n':
106  aText++;
107  break;
108 
109  case '*': // End of block
110  m_Prms.Add( FROM_UTF8( data.c_str() ) );
111  data.clear();
112  aText++;
113  break;
114 
115  case ',': // End of parameter (separator)
116  aText++;
117  m_Prms.Add( FROM_UTF8( data.c_str() ) );
118  data.clear();
119  break;
120 
121  default:
122  data += *aText;
123  aText++;
124  break;
125  }
126  }
127 
128  // end of current line, read another one.
129  if( aBuffer && aFile )
130  {
131  if( fgets( aBuffer, aBuffSize, aFile ) == nullptr )
132  {
133  // end of file
134  ok = false;
135  break;
136  }
137 
138  aLineNum++;
139  aText = aBuffer;
140  }
141  else
142  {
143  return ok;
144  }
145  }
146 
147  return ok;
148 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
wxArrayString m_Prms
the list of parameters (after TF) in gbr file the first one is the attribute name,...

References FROM_UTF8(), and m_Prms.

Member Data Documentation

◆ m_Prms


The documentation for this class was generated from the following files: