48#include <wx/filedlg.h>
57 if( !aLayerMask.
any() )
61 if( aLayerMask[
F_Cu] && aLayerMask[
B_Cu] )
65 if( aLayerMask[
F_Cu] )
69 if( aLayerMask[
B_Cu] )
75 for(
int layer =
In1_Cu; layer <
B_Cu; ++layer )
77 if( aLayerMask[layer] )
89 if( val > clamp )
return clamp;
90 if( val < -clamp )
return -clamp;
101 for(
PAD*
pad : footprint->Pads() )
110 rk.
pin =
pad->GetNumber();
111 rk.
refdes = footprint->GetReference();
114 rk.
drill = std::min( drill.
x, drill.
y );
143 aRecords.push_back( rk );
156 if( (top_layer ==
F_Cu) && (bottom_layer ==
B_Cu) )
160 if( top_layer ==
F_Cu )
164 if( bottom_layer ==
B_Cu )
169 return bottom_layer + 1;
178 for(
auto track : aPcb->
Tracks() )
200 via->LayerPair( &top_layer, &bottom_layer );
210 aRecords.push_back( rk );
217 std::map<wxString, wxString> &aMap, std::set<wxString> &aSet )
221 for(
size_t ii = 0; ii < aNetname.Len(); ++ii )
224 wxUniChar ch = aNetname[ii];
226 if( ch > 126 || !std::isgraph(
static_cast<unsigned char>( ch ) ) )
237 if( canon.size() > 14 )
239 canon = canon.Right( 14 );
243 if( aSet.count( canon ) )
246 wxString base( canon );
247 if( base.size() > 10 )
249 base = base.Right( 10 );
258 }
while ( aSet.count( canon ) );
262 aMap[aNetname] = canon;
263 aSet.insert( canon );
271 std::map<wxString, wxString> d356_net_map;
272 std::set<wxString> d356_net_set;
274 for(
unsigned i = 0; i < aRecords.size(); i++ )
281 wxString d356_net( wxT(
"N/C" ) );
285 d356_net = d356_net_map[rk.
netname];
287 if( d356_net.empty() )
305 fprintf( aFile,
"%03d%-14.14s %-6.6s%c%-4.4s%c",
308 rk.
pin.empty()?
' ':
'-',
315 fprintf( aFile,
"D%04d%c",
320 fprintf( aFile,
" " );
323 fprintf( aFile,
"A%02dX%+07dY%+07dX%04dY%04dR%03d",
339 FILE* file =
nullptr;
342 if( ( file = wxFopen( aFilename, wxT(
"wt" ) ) ) ==
nullptr )
345 details.Printf( wxT(
"The file %s could not be opened for writing." ), aFilename );
351 std::vector<D356_RECORD> d356_records;
359 fprintf( file,
"P CODE 00\n" );
360 fprintf( file,
"P UNITS CUST 0\n" );
361 fprintf( file,
"P arrayDim N\n" );
363 fprintf( file,
"999\n" );
372 wxString ext, wildcard;
378 wxString pro_dir = wxPathOnly(
Prj().GetProjectFullName() );
380 wxFileDialog dlg(
this,
_(
"Export D-356 Test File" ), pro_dir,
381 fn.GetFullName(), wildcard,
382 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
384 if( dlg.ShowModal() == wxID_CANCEL )
389 writer.
Write( dlg.GetPath() );
constexpr EDA_IU_SCALE pcbIUScale
const VECTOR2I & GetAuxOrigin()
Information pertinent to a Pcbnew printed circuit board.
int GetCopperLayerCount() const
const FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
const wxString & GetFileName() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Wrapper to expose an API for writing IPC-D356 files.
void Write(const wxString &aFilename)
Generates and writes the netlist to a given path.
void write_D356_records(std::vector< D356_RECORD > &aRecords, FILE *aFile)
Writes a list of records to the given output stream.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
LSET is a set of PCB_LAYER_IDs.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Handle the data for a net.
const wxString & GetNetname() const
void GenD356File(wxCommandEvent &event)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static void build_pad_testpoints(BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
static void build_via_testpoints(BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
static int iu_to_d356(int iu, int clamp)
static const wxString intern_new_d356_netname(const wxString &aNetname, std::map< wxString, wxString > &aMap, std::set< wxString > &aSet)
static int via_access_code(BOARD *aPcb, int top_layer, int bottom_layer)
static int compute_pad_access_code(BOARD *aPcb, LSET aLayerMask)
static const std::string IpcD356FileExtension
static wxString IpcD356FileWildcard()
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ SMD
Smd pad, appears on the solder paste layer (default)
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
constexpr ret_type KiROUND(fp_type v, bool aQuiet=false)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition of file extensions used in Kicad.