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:76
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 331 of file export_d356.cpp.

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

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