51#include <wx/checkbox.h>
52#include <wx/filedlg.h>
53#include <wx/filedlgcustomize.h>
63 if( !aLayerMask.any() )
67 if( aLayerMask[
F_Cu] && aLayerMask[
B_Cu] )
71 if( aLayerMask[
F_Cu] )
75 if( aLayerMask[
B_Cu] )
83 if( aLayerMask[layer] )
95 if( val > clamp )
return clamp;
96 if( val < -clamp )
return -clamp;
107 for(
PAD*
pad : footprint->Pads() )
120 rk.
pin =
pad->GetNumber();
121 rk.
refdes = footprint->GetReference();
124 rk.
drill = std::min( drill.
x, drill.
y );
126 rk.
smd =
pad->GetAttribute() == PAD_ATTRIB::SMD
127 ||
pad->GetAttribute() == PAD_ATTRIB::CONN;
133 rk.
x_size =
pad->GetSize( accessLayer ).x;
136 if(
pad->GetShape( accessLayer ) == PAD_SHAPE::CIRCLE )
139 rk.
y_size =
pad->GetSize( accessLayer ).y;
155 aRecords.push_back( std::move( rk ) );
167 if( (top_layer ==
F_Cu) && (bottom_layer ==
B_Cu) )
171 if( top_layer ==
F_Cu )
175 if( bottom_layer ==
B_Cu )
180 return ( top_layer / 2 ) + 1;
189 for(
auto track : aPcb->
Tracks() )
211 via->LayerPair( &top_layer, &bottom_layer );
231 aRecords.push_back( rk );
238 std::map<wxString, wxString> &aMap, std::set<wxString> &aSet )
242 for(
size_t ii = 0; ii < aNetname.Len(); ++ii )
245 wxUniChar ch = aNetname[ii];
247 if( ch > 126 || !std::isgraph(
static_cast<unsigned char>( ch ) ) )
258 if( canon.size() > 14 )
260 canon = canon.Right( 14 );
264 if( aSet.count( canon ) )
267 wxString base( canon );
268 if( base.size() > 10 )
270 base = base.Right( 10 );
279 }
while ( aSet.count( canon ) );
283 aMap[aNetname] = canon;
284 aSet.insert( canon );
292 std::map<wxString, wxString> d356_net_map;
293 std::set<wxString> d356_net_set;
295 for(
unsigned i = 0; i < aRecords.size(); i++ )
302 wxString d356_net( wxT(
"N/C" ) );
306 d356_net = d356_net_map[rk.
netname];
308 if( d356_net.empty() )
328 fprintf( aFile,
"%03d%-14.14s %-6.6s%c%-4.4s%c",
331 rk.
pin.empty()?
' ':
'-',
338 fprintf( aFile,
"D%04d%c",
343 fprintf( aFile,
" " );
346 fprintf( aFile,
"A%02dX%+07dY%+07dX%04dY%04dR%03d",
362 FILE* file =
nullptr;
365 if( ( file = wxFopen( aFilename, wxT(
"wt" ) ) ) ==
nullptr )
371 std::vector<D356_RECORD> d356_records;
379 fprintf( file,
"P CODE 00\n" );
380 fprintf( file,
"P UNITS CUST 0\n" );
381 fprintf( file,
"P arrayDim N\n" );
383 fprintf( file,
"999\n" );
406 m_cb = customizer.AddCheckBox(
_(
"Do not export unconnected pads" ) );
428 wxString ext, wildcard;
436 wxFileDialog dlg(
m_frame,
_(
"Generate IPC-D-356 netlist file" ), pro_dir, fn.GetFullName(),
437 wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
439 dlg.SetCustomizeHook( customizeHook );
441 if( dlg.ShowModal() == wxID_CANCEL )
449 if( writer.
Write( dlg.GetPath() ) )
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
const VECTOR2I & GetAuxOrigin() const
int GenD356File(const TOOL_EVENT &aEvent)
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
virtual void TransferDataFromCustomControls() override
D365_CUSTOMIZE_HOOK(bool aDoNotExportUnconnectedPads=false)
wxDECLARE_NO_COPY_CLASS(D365_CUSTOMIZE_HOOK)
wxFileDialogCheckBox * m_cb
bool GetDoNotExportUnconnectedPads() const
bool m_doNotExportUnconnectedPads
virtual void AddCustomControls(wxFileDialogCustomize &customizer) override
Wrapper to expose an API for writing IPC-D356 files.
bool m_doNotExportUnconnectedPads
void write_D356_records(std::vector< D356_RECORD > &aRecords, FILE *aFile)
Writes a list of records to the given output stream.
void build_pad_testpoints(BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
void SetDoNotExportUnconnectedPads(bool aDoNotExportUnconnectedPads)
Sets whether unconnected pads should be exported.
bool Write(const wxString &aFilename)
Generates and writes the netlist to a given path.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
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()
return AllCuMask( MAX_CU_LAYERS );
Handle the data for a net.
const wxString & GetNetname() const
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
@ 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
DIALOG_EXPORT_D356 m_ExportD356
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
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.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
bool doNotExportUnconnectedPads
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition of file extensions used in Kicad.