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();
114 const wxSize& drill =
pad->GetDrillSize();
115 rk.
drill = std::min( drill.x, drill.y );
140 aRecords.push_back( rk );
153 if( (top_layer ==
F_Cu) && (bottom_layer ==
B_Cu) )
157 if( top_layer ==
F_Cu )
161 if( bottom_layer ==
B_Cu )
166 return bottom_layer + 1;
175 for(
auto track : aPcb->
Tracks() )
179 PCB_VIA *
via = static_cast<PCB_VIA*>( track );
197 via->LayerPair( &top_layer, &bottom_layer );
207 aRecords.push_back( rk );
214 std::map<wxString, wxString> &aMap, std::set<wxString> &aSet )
218 for(
size_t ii = 0; ii < aNetname.Len(); ++ii )
221 wxUniChar ch = aNetname[ii];
223 if( ch > 126 || !std::isgraph( static_cast<unsigned char>( ch ) ) )
234 if( canon.size() > 14 )
236 canon = canon.Right( 14 );
240 if( aSet.count( canon ) )
243 wxString base( canon );
244 if( base.size() > 10 )
246 base = base.Right( 10 );
255 }
while ( aSet.count( canon ) );
259 aMap[aNetname] = canon;
260 aSet.insert( canon );
268 std::map<wxString, wxString> d356_net_map;
269 std::set<wxString> d356_net_set;
271 for(
unsigned i = 0; i < aRecords.size(); i++ )
278 wxString d356_net( wxT(
"N/C" ) );
282 d356_net = d356_net_map[rk.
netname];
284 if( d356_net.empty() )
302 fprintf( aFile,
"%03d%-14.14s %-6.6s%c%-4.4s%c",
305 rk.
pin.empty()?
' ':
'-',
312 fprintf( aFile,
"D%04d%c",
317 fprintf( aFile,
" " );
320 fprintf( aFile,
"A%02dX%+07dY%+07dX%04dY%04dR%03d",
336 FILE* file =
nullptr;
339 if( ( file = wxFopen( aFilename, wxT(
"wt" ) ) ) ==
nullptr )
342 details.Printf( wxT(
"The file %s could not be opened for writing." ), aFilename );
348 std::vector<D356_RECORD> d356_records;
356 fprintf( file,
"P CODE 00\n" );
357 fprintf( file,
"P UNITS CUST 0\n" );
358 fprintf( file,
"P arrayDim N\n" );
360 fprintf( file,
"999\n" );
369 wxString msg, ext, wildcard;
375 wxString pro_dir = wxPathOnly(
Prj().GetProjectFullName() );
377 wxFileDialog dlg(
this,
_(
"Export D-356 Test File" ), pro_dir,
378 fn.GetFullName(), wildcard,
379 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
381 if( dlg.ShowModal() == wxID_CANCEL )
386 writer.
Write( dlg.GetPath() );
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
void Write(const wxString &aFilename)
Generates and writes the netlist to a given path.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
static int iu_to_d356(int iu, int clamp)
This file is part of the common library.
static void build_pad_testpoints(BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
void write_D356_records(std::vector< D356_RECORD > &aRecords, FILE *aFile)
Writes a list of records to the given output stream.
Like smd, does not appear on the solder paste layer (default)
Smd pad, appears on the solder paste layer (default)
int LAYER_NUM
This can be replaced with int and removed.
const wxString & GetFileName() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
like PAD_PTH, but not plated
LSET is a set of PCB_LAYER_IDs.
Wrapper to expose an API for writing IPC-D356 files.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
FOOTPRINTS & Footprints()
static void build_via_testpoints(BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
Definition of file extensions used in Kicad.
const wxString & GetNetname() const
const std::string IpcD356FileExtension
wxString IpcD356FileWildcard()
Handle the data for a net.
static const wxString intern_new_d356_netname(const wxString &aNetname, std::map< wxString, wxString > &aMap, std::set< wxString > &aSet)
const wxPoint & GetAuxOrigin()
void GenD356File(wxCommandEvent &event)
Information pertinent to a Pcbnew printed circuit board.
PCB_LAYER_ID
A quick note on layer IDs:
static int compute_pad_access_code(BOARD *aPcb, LSET aLayerMask)
int GetCopperLayerCount() const
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
static int via_access_code(BOARD *aPcb, int top_layer, int bottom_layer)
class PCB_VIA, a via (like a track segment on a copper layer)