49#include <wx/filedlg.h>
58 if( !aLayerMask.any() )
62 if( aLayerMask[
F_Cu] && aLayerMask[
B_Cu] )
66 if( aLayerMask[
F_Cu] )
70 if( aLayerMask[
B_Cu] )
78 if( aLayerMask[layer] )
90 if( val > clamp )
return clamp;
91 if( val < -clamp )
return -clamp;
102 for(
PAD*
pad : footprint->Pads() )
111 rk.
pin =
pad->GetNumber();
112 rk.
refdes = footprint->GetReference();
115 rk.
drill = std::min( drill.
x, drill.
y );
124 rk.
x_size =
pad->GetSize( accessLayer ).x;
130 rk.
y_size =
pad->GetSize( accessLayer ).y;
146 aRecords.push_back( rk );
159 if( (top_layer ==
F_Cu) && (bottom_layer ==
B_Cu) )
163 if( top_layer ==
F_Cu )
167 if( bottom_layer ==
B_Cu )
172 return bottom_layer + 1;
181 for(
auto track : aPcb->
Tracks() )
203 via->LayerPair( &top_layer, &bottom_layer );
223 aRecords.push_back( rk );
230 std::map<wxString, wxString> &aMap, std::set<wxString> &aSet )
234 for(
size_t ii = 0; ii < aNetname.Len(); ++ii )
237 wxUniChar ch = aNetname[ii];
239 if( ch > 126 || !std::isgraph(
static_cast<unsigned char>( ch ) ) )
250 if( canon.size() > 14 )
252 canon = canon.Right( 14 );
256 if( aSet.count( canon ) )
259 wxString base( canon );
260 if( base.size() > 10 )
262 base = base.Right( 10 );
271 }
while ( aSet.count( canon ) );
275 aMap[aNetname] = canon;
276 aSet.insert( canon );
284 std::map<wxString, wxString> d356_net_map;
285 std::set<wxString> d356_net_set;
287 for(
unsigned i = 0; i < aRecords.size(); i++ )
294 wxString d356_net( wxT(
"N/C" ) );
298 d356_net = d356_net_map[rk.
netname];
300 if( d356_net.empty() )
318 fprintf( aFile,
"%03d%-14.14s %-6.6s%c%-4.4s%c",
321 rk.
pin.empty()?
' ':
'-',
328 fprintf( aFile,
"D%04d%c",
333 fprintf( aFile,
" " );
336 fprintf( aFile,
"A%02dX%+07dY%+07dX%04dY%04dR%03d",
352 FILE* file =
nullptr;
355 if( ( file = wxFopen( aFilename, wxT(
"wt" ) ) ) ==
nullptr )
358 details.Printf( wxT(
"The file %s could not be opened for writing." ), aFilename );
364 std::vector<D356_RECORD> d356_records;
372 fprintf( file,
"P CODE 00\n" );
373 fprintf( file,
"P UNITS CUST 0\n" );
374 fprintf( file,
"P arrayDim N\n" );
376 fprintf( file,
"999\n" );
385 wxString ext, wildcard;
391 wxString pro_dir = wxPathOnly(
Prj().GetProjectFullName() );
393 wxFileDialog dlg(
this,
_(
"Export D-356 Test File" ), pro_dir,
394 fn.GetFullName(), wildcard,
395 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
397 if( dlg.ShowModal() == wxID_CANCEL )
402 writer.
Write( dlg.GetPath() );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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
@ NORMAL
Shape is the same on all layers.
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
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)
Definition of file extensions used in Kicad.