KiCad PCB EDA Suite
plot_auxiliary_data.h File Reference

Go to the source code of this file.

Classes

class  GBR_APERTURE_METADATA
 
class  GBR_METADATA
 

Functions

std::string formatStringToGerber (const wxString &aString)
 This helper function "normalize" aString and convert it to a Gerber std::string Normalisation means convert any code > 0x7F and unautorized code to a hexadecimal 16 bits sequence unicode unautorized codes are ',' '*' '' '\'. More...
 
bool FormatNetAttribute (std::string &aPrintedText, std::string &aLastNetAttributes, GBR_NETLIST_METADATA *aData, bool &aClearPreviousAttributes)
 Generates the string to print to a gerber file, to set a net attribute for a graphic object. More...
 

Function Documentation

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

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

Parameters
aPrintedTextis the string to print
aLastNetAttributesis the current full set of attributes.
aClearPreviousAttributesreturns true if the full set of attributes must be deleted from file before adding new attribute (happens when a previous attribute does not exist no more).
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 176 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_NETLIST_METADATA::m_Cmpref, GBR_NETLIST_METADATA::m_NetAttribType, GBR_NETLIST_METADATA::m_Netname, GBR_NETLIST_METADATA::m_NotInNet, GBR_NETLIST_METADATA::m_Padname, NO_NET_NAME, and NO_PAD_NAME.

Referenced by GERBER_PLOTTER::formatNetAttribute().

178 {
179  aClearPreviousAttributes = false;
180 
181  // print a Gerber net attribute record.
182  // it is added to the object attributes dictionnary
183  // On file, only modified or new attributes are printed.
184  if( aData == NULL )
185  return false;
186 
187  std::string pad_attribute_string;
188  std::string net_attribute_string;
189  std::string cmp_attribute_string;
190 
192  return false; // idle command: do nothing
193 
195  {
196  // print info associated to a flashed pad (cmpref, pad name)
197  // example: %TO.P,R5,3*%
198  pad_attribute_string = "%TO.P,";
199  pad_attribute_string += formatStringToGerber( aData->m_Cmpref ) + ",";
200 
201  if( aData->m_Padname.IsEmpty() )
202  // Happens for "mechanical" or never connected pads
203  pad_attribute_string += formatStringToGerber( NO_PAD_NAME );
204  else
205  pad_attribute_string += formatStringToGerber( aData->m_Padname );
206 
207  pad_attribute_string += "*%\n";
208  }
209 
211  {
212  // print info associated to a net
213  // example: %TO.N,Clk3*%
214  net_attribute_string = "%TO.N,";
215 
216  if( aData->m_Netname.IsEmpty() )
217  {
218  if( aData->m_NotInNet )
219  {
220  // Happens for not connectable pads: mechanical pads
221  // and pads with no padname/num
222  // In this case the net name must be left empty
223  }
224  else
225  {
226  // Happens for not connected pads: use a normalized
227  // dummy name
228  net_attribute_string += formatStringToGerber( NO_NET_NAME );
229  }
230  }
231  else
232  net_attribute_string += formatStringToGerber( aData->m_Netname );
233 
234  net_attribute_string += "*%\n";
235  }
236 
239  {
240  // print info associated to a footprint
241  // example: %TO.C,R2*%
242  // Because GBR_NETINFO_PAD option already contains this info, it is not
243  // created here for a GBR_NETINFO_PAD attribute
244  cmp_attribute_string = "%TO.C,";
245  cmp_attribute_string += formatStringToGerber( aData->m_Cmpref ) + "*%\n";
246  }
247 
248  // the full list of requested attributes:
249  std::string full_attribute_string = pad_attribute_string + net_attribute_string
250  + cmp_attribute_string;
251  // the short list of requested attributes
252  // (only modified or new attributes are stored here):
253  std::string short_attribute_string;
254 
255  if( aLastNetAttributes != full_attribute_string )
256  {
257  // first, remove no more existing attributes.
258  // Because in Kicad the full attribute list is evaluated for each object,
259  // the entire dictionnary is cleared
260  bool clearDict = false;
261 
262  if( aLastNetAttributes.find( "%TO.P," ) != std::string::npos )
263  {
264  if( pad_attribute_string.empty() ) // No more this attribute
265  clearDict = true;
266  else if( aLastNetAttributes.find( pad_attribute_string )
267  == std::string::npos ) // This attribute has changed
268  short_attribute_string += pad_attribute_string;
269  }
270  else // New attribute
271  short_attribute_string += pad_attribute_string;
272 
273  if( aLastNetAttributes.find( "%TO.N," ) != std::string::npos )
274  {
275  if( net_attribute_string.empty() ) // No more this attribute
276  clearDict = true;
277  else if( aLastNetAttributes.find( net_attribute_string )
278  == std::string::npos ) // This attribute has changed
279  short_attribute_string += net_attribute_string;
280  }
281  else // New attribute
282  short_attribute_string += net_attribute_string;
283 
284  if( aLastNetAttributes.find( "%TO.C," ) != std::string::npos )
285  {
286  if( cmp_attribute_string.empty() ) // No more this attribute
287  clearDict = true;
288  else if( aLastNetAttributes.find( cmp_attribute_string )
289  == std::string::npos ) // This attribute has changed
290  short_attribute_string += cmp_attribute_string;
291  }
292  else // New attribute
293  short_attribute_string += cmp_attribute_string;
294 
295  aClearPreviousAttributes = clearDict;
296 
297  aLastNetAttributes = full_attribute_string;
298 
299  if( clearDict )
300  aPrintedText = full_attribute_string;
301  else
302  aPrintedText = short_attribute_string;
303  }
304 
305  return true;
306 }
#define NO_NET_NAME
print info associated to a component (TO.C attribute)
wxString m_Cmpref
the component reference parent of the data
std::string formatStringToGerber(const wxString &aString)
This helper function "normalize" aString and convert it to a Gerber std::string Normalisation means c...
wxString m_Padname
for a flashed pad: the pad name ((TO.P attribute)
#define NO_PAD_NAME
wxString m_Netname
for items associated to a net: the netname
print info associated to a flashed pad (TO.P attribute)
bool m_NotInNet
true if a pad of a footprint cannot be connected (for instance a mechanical NPTH, ot a not named pad)...
print info associated to a net (TO.N attribute)
int m_NetAttribType
the type of net info (used to define the gerber string to create)
std::string formatStringToGerber ( const wxString &  aString)

This helper function "normalize" aString and convert it to a Gerber std::string Normalisation means convert any code > 0x7F and unautorized code to a hexadecimal 16 bits sequence unicode unautorized codes are ',' '*' '' '\'.

Parameters
aString= the wxString to convert
Returns
a std::string (ASCII7 coded) compliant with a gerber string

Definition at line 126 of file gbr_metadata.cpp.

Referenced by FormatNetAttribute().

127 {
128  /* format string means convert any code > 0x7F and unautorized code to a hexadecimal
129  * 16 bits sequence unicode
130  * unautorized codes are ',' '*' '%' '\'
131  */
132  std::string txt;
133 
134  txt.reserve( aString.Length() );
135 
136  for( unsigned ii = 0; ii < aString.Length(); ++ii )
137  {
138  unsigned code = aString[ii];
139  bool convert = false;
140 
141  switch( code )
142  {
143  case '\\':
144  case '%':
145  case '*':
146  case ',':
147  convert = true;
148  break;
149 
150  default:
151  break;
152  }
153 
154  if( convert || code > 0x7F )
155  {
156  txt += '\\';
157 
158  // Convert code to 4 hexadecimal digit
159  // (Gerber allows only 4 hexadecimal digit)
160  char hexa[32];
161  sprintf( hexa,"%4.4X", code & 0xFFFF);
162  txt += hexa;
163  }
164  else
165  txt += char( code );
166  }
167 
168  return txt;
169 }