KiCad PCB EDA Suite
export_d356.cpp File Reference

Export IPC-D-356 test format. More...

#include <confirm.h>
#include <gestfich.h>
#include <kiface_i.h>
#include <pcb_edit_frame.h>
#include <trigo.h>
#include <build_version.h>
#include <macros.h>
#include <wildcards_and_files_ext.h>
#include <locale_io.h>
#include <pcbnew.h>
#include <board.h>
#include <footprint.h>
#include <track.h>
#include <vector>
#include <cctype>
#include <math/util.h>
#include <export_d356.h>

Go to the source code of this file.

Functions

static int compute_pad_access_code (BOARD *aPcb, LSET aLayerMask)
 
static int iu_to_d356 (int iu, int clamp)
 
static void build_pad_testpoints (BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
 
static int via_access_code (BOARD *aPcb, int top_layer, int bottom_layer)
 
static void build_via_testpoints (BOARD *aPcb, std::vector< D356_RECORD > &aRecords)
 
static const wxString intern_new_d356_netname (const wxString &aNetname, std::map< wxString, wxString > &aMap, std::set< wxString > &aSet)
 

Detailed Description

Export IPC-D-356 test format.

Definition in file export_d356.cpp.

Function Documentation

◆ build_pad_testpoints()

static void build_pad_testpoints ( BOARD aPcb,
std::vector< D356_RECORD > &  aRecords 
)
static

Definition at line 93 of file export_d356.cpp.

94 {
95  wxPoint origin = aPcb->GetDesignSettings().m_AuxOrigin;
96 
97  for( FOOTPRINT* footprint : aPcb->Footprints() )
98  {
99  for( PAD* pad : footprint->Pads() )
100  {
101  D356_RECORD rk;
102  rk.access = compute_pad_access_code( aPcb, pad->GetLayerSet() );
103 
104  // It could be a mask only pad, we only handle pads with copper here
105  if( rk.access != -1 )
106  {
107  rk.netname = pad->GetNetname();
108  rk.pin = pad->GetName();
109  rk.refdes = footprint->GetReference();
110  rk.midpoint = false; // XXX MAYBE need to be computed (how?)
111  const wxSize& drill = pad->GetDrillSize();
112  rk.drill = std::min( drill.x, drill.y );
113  rk.hole = (rk.drill != 0);
114  rk.smd = pad->GetAttribute() == PAD_ATTRIB_SMD;
115  rk.mechanical = ( pad->GetAttribute() == PAD_ATTRIB_NPTH );
116  rk.x_location = pad->GetPosition().x - origin.x;
117  rk.y_location = origin.y - pad->GetPosition().y;
118  rk.x_size = pad->GetSize().x;
119 
120  // Rule: round pads have y = 0
121  if( pad->GetShape() == PAD_SHAPE_CIRCLE )
122  rk.y_size = 0;
123  else
124  rk.y_size = pad->GetSize().y;
125 
126  rk.rotation = -KiROUND( pad->GetOrientation() ) / 10;
127  if( rk.rotation < 0 ) rk.rotation += 360;
128 
129  // the value indicates which sides are *not* accessible
130  rk.soldermask = 3;
131  if( pad->GetLayerSet()[F_Mask] )
132  rk.soldermask &= ~1;
133  if( pad->GetLayerSet()[B_Mask] )
134  rk.soldermask &= ~2;
135 
136  aRecords.push_back( rk );
137  }
138  }
139  }
140 }
wxString pin
Definition: export_d356.h:35
int x_location
Definition: export_d356.h:42
bool mechanical
Definition: export_d356.h:38
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:81
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
bool midpoint
Definition: export_d356.h:36
FOOTPRINTS & Footprints()
Definition: board.h:305
wxString refdes
Definition: export_d356.h:34
int soldermask
Definition: export_d356.h:40
wxString netname
Definition: export_d356.h:33
static int compute_pad_access_code(BOARD *aPcb, LSET aLayerMask)
Definition: export_d356.cpp:51
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
Definition: pad.h:60
int y_location
Definition: export_d356.h:43
wxPoint m_AuxOrigin
origin for plot exports

References D356_RECORD::access, B_Mask, compute_pad_access_code(), D356_RECORD::drill, F_Mask, BOARD::Footprints(), BOARD::GetDesignSettings(), D356_RECORD::hole, KiROUND(), BOARD_DESIGN_SETTINGS::m_AuxOrigin, D356_RECORD::mechanical, D356_RECORD::midpoint, D356_RECORD::netname, pad, PAD_ATTRIB_NPTH, PAD_ATTRIB_SMD, PAD_SHAPE_CIRCLE, D356_RECORD::pin, D356_RECORD::refdes, D356_RECORD::rotation, D356_RECORD::smd, D356_RECORD::soldermask, D356_RECORD::x_location, D356_RECORD::x_size, D356_RECORD::y_location, and D356_RECORD::y_size.

Referenced by IPC356D_WRITER::Write().

◆ build_via_testpoints()

static void build_via_testpoints ( BOARD aPcb,
std::vector< D356_RECORD > &  aRecords 
)
static

Definition at line 166 of file export_d356.cpp.

167 {
168  wxPoint origin = aPcb->GetDesignSettings().m_AuxOrigin;
169 
170  // Enumerate all the track segments and keep the vias
171  for( auto track : aPcb->Tracks() )
172  {
173  if( track->Type() == PCB_VIA_T )
174  {
175  VIA *via = (VIA*) track;
176  NETINFO_ITEM *net = track->GetNet();
177 
178  D356_RECORD rk;
179  rk.smd = false;
180  rk.hole = true;
181  if( net )
182  rk.netname = net->GetNetname();
183  else
184  rk.netname = wxEmptyString;
185  rk.refdes = wxT("VIA");
186  rk.pin = wxT("");
187  rk.midpoint = true; // Vias are always midpoints
188  rk.drill = via->GetDrillValue();
189  rk.mechanical = false;
190 
191  PCB_LAYER_ID top_layer, bottom_layer;
192 
193  via->LayerPair( &top_layer, &bottom_layer );
194 
195  rk.access = via_access_code( aPcb, top_layer, bottom_layer );
196  rk.x_location = via->GetPosition().x - origin.x;
197  rk.y_location = origin.y - via->GetPosition().y;
198  rk.x_size = via->GetWidth();
199  rk.y_size = 0; // Round so height = 0
200  rk.rotation = 0;
201  rk.soldermask = 3; // XXX always tented?
202 
203  aRecords.push_back( rk );
204  }
205  }
206 }
Definition: track.h:343
wxString pin
Definition: export_d356.h:35
int x_location
Definition: export_d356.h:42
bool mechanical
Definition: export_d356.h:38
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
bool midpoint
Definition: export_d356.h:36
PCB_LAYER_ID
A quick note on layer IDs:
wxString refdes
Definition: export_d356.h:34
const wxString & GetNetname() const
Definition: netinfo.h:119
int soldermask
Definition: export_d356.h:40
wxString netname
Definition: export_d356.h:33
Handle the data for a net.
Definition: netinfo.h:64
static int via_access_code(BOARD *aPcb, int top_layer, int bottom_layer)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
int y_location
Definition: export_d356.h:43
wxPoint m_AuxOrigin
origin for plot exports
TRACKS & Tracks()
Definition: board.h:302

References D356_RECORD::access, D356_RECORD::drill, BOARD::GetDesignSettings(), NETINFO_ITEM::GetNetname(), D356_RECORD::hole, BOARD_DESIGN_SETTINGS::m_AuxOrigin, D356_RECORD::mechanical, D356_RECORD::midpoint, D356_RECORD::netname, PCB_VIA_T, D356_RECORD::pin, D356_RECORD::refdes, D356_RECORD::rotation, D356_RECORD::smd, D356_RECORD::soldermask, BOARD::Tracks(), via, via_access_code(), D356_RECORD::x_location, D356_RECORD::x_size, D356_RECORD::y_location, and D356_RECORD::y_size.

Referenced by IPC356D_WRITER::Write().

◆ compute_pad_access_code()

static int compute_pad_access_code ( BOARD aPcb,
LSET  aLayerMask 
)
static

Definition at line 51 of file export_d356.cpp.

52 {
53  // Non-copper is not interesting here
54  aLayerMask &= LSET::AllCuMask();
55  if( !aLayerMask.any() )
56  return -1;
57 
58  // Traditional TH pad
59  if( aLayerMask[F_Cu] && aLayerMask[B_Cu] )
60  return 0;
61 
62  // Front SMD pad
63  if( aLayerMask[F_Cu] )
64  return 1;
65 
66  // Back SMD pad
67  if( aLayerMask[B_Cu] )
68  return aPcb->GetCopperLayerCount();
69 
70  // OK, we have an inner-layer only pad (and I have no idea about
71  // what could be used for); anyway, find the first copper layer
72  // it's on
73  for( LAYER_NUM layer = In1_Cu; layer < B_Cu; ++layer )
74  {
75  if( aLayerMask[layer] )
76  return layer + 1;
77  }
78 
79  // This shouldn't happen
80  return -1;
81 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
int LAYER_NUM
This can be replaced with int and removed.
int GetCopperLayerCount() const
Definition: board.cpp:435

References LSET::AllCuMask(), B_Cu, F_Cu, BOARD::GetCopperLayerCount(), and In1_Cu.

Referenced by build_pad_testpoints().

◆ intern_new_d356_netname()

static const wxString intern_new_d356_netname ( const wxString &  aNetname,
std::map< wxString, wxString > &  aMap,
std::set< wxString > &  aSet 
)
static

Definition at line 209 of file export_d356.cpp.

211 {
212  wxString canon;
213 
214  for( size_t ii = 0; ii < aNetname.Len(); ++ii )
215  {
216  // Rule: we can only use the standard ASCII, control excluded
217  wxUniChar ch = aNetname[ii];
218 
219  if( ch > 126 || !std::isgraph( static_cast<unsigned char>( ch ) ) )
220  ch = '?';
221 
222  canon += ch;
223  }
224 
225  // Rule: only uppercase (unofficial, but known to give problems
226  // otherwise)
227  canon.MakeUpper();
228 
229  // Rule: maximum length is 14 characters, otherwise we keep the tail
230  if( canon.size() > 14 )
231  {
232  canon = canon.Right( 14 );
233  }
234 
235  // Check if it's still unique
236  if( aSet.count( canon ) )
237  {
238  // Nope, need to uniquify it, trim it more and add a number
239  wxString base( canon );
240  if( base.size() > 10 )
241  {
242  base = base.Right( 10 );
243  }
244 
245  int ctr = 0;
246  do
247  {
248  ++ctr;
249  canon = base;
250  canon << '#' << ctr;
251  } while ( aSet.count( canon ) );
252  }
253 
254  // Register it
255  aMap[aNetname] = canon;
256  aSet.insert( canon );
257  return canon;
258 }

Referenced by IPC356D_WRITER::write_D356_records().

◆ iu_to_d356()

static int iu_to_d356 ( int  iu,
int  clamp 
)
static

Definition at line 84 of file export_d356.cpp.

85 {
86  int val = KiROUND( iu / ( IU_PER_MILS / 10 ) );
87  if( val > clamp ) return clamp;
88  if( val < -clamp ) return -clamp;
89  return val;
90 }
#define IU_PER_MILS
Definition: plotter.cpp:137
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References IU_PER_MILS, and KiROUND().

Referenced by IPC356D_WRITER::write_D356_records().

◆ via_access_code()

static int via_access_code ( BOARD aPcb,
int  top_layer,
int  bottom_layer 
)
static

Definition at line 145 of file export_d356.cpp.

146 {
147  // Easy case for through vias: top_layer is component, bottom_layer is
148  // solder, access code is 0
149  if( (top_layer == F_Cu) && (bottom_layer == B_Cu) )
150  return 0;
151 
152  // Blind via, reachable from front
153  if( top_layer == F_Cu )
154  return 1;
155 
156  // Blind via, reachable from bottom
157  if( bottom_layer == B_Cu )
158  return aPcb->GetCopperLayerCount();
159 
160  // It's a buried via, accessible from some inner layer
161  // (maybe could be used for testing before laminating? no idea)
162  return bottom_layer + 1; // XXX is this correct?
163 }
int GetCopperLayerCount() const
Definition: board.cpp:435

References B_Cu, F_Cu, and BOARD::GetCopperLayerCount().

Referenced by build_via_testpoints().