KiCad PCB EDA Suite
IPC356D_WRITER Class Reference

Wrapper to expose an API for writing IPC-D356 files. More...

#include <export_d356.h>

Public Member Functions

 IPC356D_WRITER (BOARD *aPcb, wxWindow *aParent=nullptr)
 Constructs an IPC-356D file writer. More...
 
virtual ~IPC356D_WRITER ()
 
void Write (const wxString &aFilename)
 Generates and writes the netlist to a given path. More...
 

Private Member Functions

void write_D356_records (std::vector< D356_RECORD > &aRecords, FILE *aFile)
 Writes a list of records to the given output stream. More...
 

Private Attributes

BOARDm_pcb
 
wxWindow * m_parent
 

Detailed Description

Wrapper to expose an API for writing IPC-D356 files.

Definition at line 53 of file export_d356.h.

Constructor & Destructor Documentation

◆ IPC356D_WRITER()

IPC356D_WRITER::IPC356D_WRITER ( BOARD aPcb,
wxWindow *  aParent = nullptr 
)
inline

Constructs an IPC-356D file writer.

Parameters
aPcbis the board to extract a netlist from
aParentwill be used as the parent for any warning dialogs

Definition at line 61 of file export_d356.h.

61  :
62  m_pcb( aPcb ), m_parent( aParent )
63  {}
wxWindow * m_parent
Definition: export_d356.h:75
BOARD * m_pcb
Definition: export_d356.h:74

◆ ~IPC356D_WRITER()

virtual IPC356D_WRITER::~IPC356D_WRITER ( )
inlinevirtual

Definition at line 65 of file export_d356.h.

65 {}

Member Function Documentation

◆ Write()

void IPC356D_WRITER::Write ( const wxString &  aFilename)

Generates and writes the netlist to a given path.

Parameters
aFilenameis the full path and name of the output file

Definition at line 333 of file export_d356.cpp.

334 {
335  FILE* file = nullptr;
336  LOCALE_IO toggle; // Switch the locale to standard C
337 
338  if( ( file = wxFopen( aFilename, wxT( "wt" ) ) ) == nullptr )
339  {
340  wxString details;
341  details.Printf( "The file %s could not be opened for writing.", aFilename );
342  DisplayErrorMessage( m_parent, "Could not write IPC-356D file!", details );
343  return;
344  }
345 
346  // This will contain everything needed for the 356 file
347  std::vector<D356_RECORD> d356_records;
348 
349  build_via_testpoints( m_pcb, d356_records );
350 
351  build_pad_testpoints( m_pcb, d356_records );
352 
353  // Code 00 AFAIK is ASCII, CUST 0 is decimils/degrees
354  // CUST 1 would be metric but gerbtool simply ignores it!
355  fprintf( file, "P CODE 00\n" );
356  fprintf( file, "P UNITS CUST 0\n" );
357  fprintf( file, "P arrayDim N\n" );
358  write_D356_records( d356_records, file );
359  fprintf( file, "999\n" );
360 
361  fclose( file );
362 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
wxWindow * m_parent
Definition: export_d356.h:75
static void build_pad_testpoints(BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
Definition: export_d356.cpp:96
void write_D356_records(std::vector< D356_RECORD > &aRecords, FILE *aFile)
Writes a list of records to the given output stream.
static void build_via_testpoints(BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
BOARD * m_pcb
Definition: export_d356.h:74

References build_pad_testpoints(), build_via_testpoints(), DisplayErrorMessage(), m_parent, m_pcb, and write_D356_records().

Referenced by PCB_EDIT_FRAME::GenD356File().

◆ write_D356_records()

void IPC356D_WRITER::write_D356_records ( std::vector< D356_RECORD > &  aRecords,
FILE *  aFile 
)
private

Writes a list of records to the given output stream.

Definition at line 264 of file export_d356.cpp.

265 {
266  // Sanified and shorted network names and set of short names
267  std::map<wxString, wxString> d356_net_map;
268  std::set<wxString> d356_net_set;
269 
270  for( unsigned i = 0; i < aRecords.size(); i++ )
271  {
272  D356_RECORD &rk = aRecords[i];
273 
274  // Try to sanify the network name (there are limits on this), if
275  // not already done. Also 'empty' net are marked as N/C, as
276  // specified.
277  wxString d356_net( wxT( "N/C" ) );
278 
279  if( !rk.netname.empty() )
280  {
281  d356_net = d356_net_map[rk.netname];
282 
283  if( d356_net.empty() )
284  d356_net = intern_new_d356_netname( rk.netname, d356_net_map, d356_net_set );
285  }
286 
287  // Choose the best record type
288  int rktype;
289 
290  if( rk.smd )
291  rktype = 327;
292  else
293  {
294  if( rk.mechanical )
295  rktype = 367;
296  else
297  rktype = 317;
298  }
299 
300  // Operation code, signal and component
301  fprintf( aFile, "%03d%-14.14s %-6.6s%c%-4.4s%c",
302  rktype, TO_UTF8(d356_net),
303  TO_UTF8(rk.refdes),
304  rk.pin.empty()?' ':'-',
305  TO_UTF8(rk.pin),
306  rk.midpoint?'M':' ' );
307 
308  // Hole definition
309  if( rk.hole )
310  {
311  fprintf( aFile, "D%04d%c",
312  iu_to_d356( rk.drill, 9999 ),
313  rk.mechanical ? 'U':'P' );
314  }
315  else
316  fprintf( aFile, " " );
317 
318  // Test point access
319  fprintf( aFile, "A%02dX%+07dY%+07dX%04dY%04dR%03d",
320  rk.access,
321  iu_to_d356( rk.x_location, 999999 ),
322  iu_to_d356( rk.y_location, 999999 ),
323  iu_to_d356( rk.x_size, 9999 ),
324  iu_to_d356( rk.y_size, 9999 ),
325  rk.rotation );
326 
327  // Soldermask
328  fprintf( aFile, "S%d\n", rk.soldermask );
329  }
330 }
wxString pin
Definition: export_d356.h:35
int x_location
Definition: export_d356.h:42
static int iu_to_d356(int iu, int clamp)
Definition: export_d356.cpp:87
bool mechanical
Definition: export_d356.h:38
bool midpoint
Definition: export_d356.h:36
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
wxString refdes
Definition: export_d356.h:34
int soldermask
Definition: export_d356.h:40
wxString netname
Definition: export_d356.h:33
static const wxString intern_new_d356_netname(const wxString &aNetname, std::map< wxString, wxString > &aMap, std::set< wxString > &aSet)
int y_location
Definition: export_d356.h:43

References D356_RECORD::access, D356_RECORD::drill, D356_RECORD::hole, intern_new_d356_netname(), iu_to_d356(), D356_RECORD::mechanical, D356_RECORD::midpoint, D356_RECORD::netname, D356_RECORD::pin, D356_RECORD::refdes, D356_RECORD::rotation, D356_RECORD::smd, D356_RECORD::soldermask, TO_UTF8, D356_RECORD::x_location, D356_RECORD::x_size, D356_RECORD::y_location, and D356_RECORD::y_size.

Referenced by Write().

Member Data Documentation

◆ m_parent

wxWindow* IPC356D_WRITER::m_parent
private

Definition at line 75 of file export_d356.h.

Referenced by Write().

◆ m_pcb

BOARD* IPC356D_WRITER::m_pcb
private

Definition at line 74 of file export_d356.h.

Referenced by Write().


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