KiCad PCB EDA Suite
export_d356.cpp File Reference

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

#include <fctsys.h>
#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 <pcbnew.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_edge_mod.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 94 of file export_d356.cpp.

96 {
97  wxPoint origin = aPcb->GetAuxOrigin();
98 
99  for( auto module : aPcb->Modules() )
100  {
101  for( auto pad : module->Pads() )
102  {
103  D356_RECORD rk;
104  rk.access = compute_pad_access_code( aPcb, pad->GetLayerSet() );
105 
106  // It could be a mask only pad, we only handle pads with copper here
107  if( rk.access != -1 )
108  {
109  rk.netname = pad->GetNetname();
110  rk.pin = pad->GetName();
111  rk.refdes = module->GetReference();
112  rk.midpoint = false; // XXX MAYBE need to be computed (how?)
113  const wxSize& drill = pad->GetDrillSize();
114  rk.drill = std::min( drill.x, drill.y );
115  rk.hole = (rk.drill != 0);
116  rk.smd = pad->GetAttribute() == PAD_ATTRIB_SMD;
117  rk.mechanical = (pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED);
118  rk.x_location = pad->GetPosition().x - origin.x;
119  rk.y_location = origin.y - pad->GetPosition().y;
120  rk.x_size = pad->GetSize().x;
121 
122  // Rule: round pads have y = 0
123  if( pad->GetShape() == PAD_SHAPE_CIRCLE )
124  rk.y_size = 0;
125  else
126  rk.y_size = pad->GetSize().y;
127 
128  rk.rotation = -KiROUND( pad->GetOrientation() ) / 10;
129  if( rk.rotation < 0 ) rk.rotation += 360;
130 
131  // the value indicates which sides are *not* accessible
132  rk.soldermask = 3;
133  if( pad->GetLayerSet()[F_Mask] )
134  rk.soldermask &= ~1;
135  if( pad->GetLayerSet()[B_Mask] )
136  rk.soldermask &= ~2;
137 
138  aRecords.push_back( rk );
139  }
140  }
141  }
142 }
wxString pin
Definition: export_d356.h:35
int x_location
Definition: export_d356.h:42
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
bool mechanical
Definition: export_d356.h:38
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
bool midpoint
Definition: export_d356.h:36
MODULES & Modules()
Definition: class_board.h:256
wxString refdes
Definition: export_d356.h:34
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:364
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:52
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:61
int y_location
Definition: export_d356.h:43

References D356_RECORD::access, B_Mask, compute_pad_access_code(), D356_RECORD::drill, F_Mask, BOARD::GetAuxOrigin(), BOARD_ITEM::GetLayerSet(), D356_RECORD::hole, KiROUND(), D356_RECORD::mechanical, D356_RECORD::midpoint, BOARD::Modules(), D356_RECORD::netname, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_SHAPE_CIRCLE, D356_RECORD::pin, D356_RECORD::refdes, D356_RECORD::rotation, D356_RECORD::smd, D356_RECORD::soldermask, wxPoint::x, D356_RECORD::x_location, D356_RECORD::x_size, wxPoint::y, 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 168 of file export_d356.cpp.

170 {
171  wxPoint origin = aPcb->GetAuxOrigin();
172 
173  // Enumerate all the track segments and keep the vias
174  for( auto track : aPcb->Tracks() )
175  {
176  if( track->Type() == PCB_VIA_T )
177  {
178  VIA *via = (VIA*) track;
179  NETINFO_ITEM *net = track->GetNet();
180 
181  D356_RECORD rk;
182  rk.smd = false;
183  rk.hole = true;
184  if( net )
185  rk.netname = net->GetNetname();
186  else
187  rk.netname = wxEmptyString;
188  rk.refdes = wxT("VIA");
189  rk.pin = wxT("");
190  rk.midpoint = true; // Vias are always midpoints
191  rk.drill = via->GetDrillValue();
192  rk.mechanical = false;
193 
194  PCB_LAYER_ID top_layer, bottom_layer;
195 
196  via->LayerPair( &top_layer, &bottom_layer );
197 
198  rk.access = via_access_code( aPcb, top_layer, bottom_layer );
199  rk.x_location = via->GetPosition().x - origin.x;
200  rk.y_location = origin.y - via->GetPosition().y;
201  rk.x_size = via->GetWidth();
202  rk.y_size = 0; // Round so height = 0
203  rk.rotation = 0;
204  rk.soldermask = 3; // XXX always tented?
205 
206  aRecords.push_back( rk );
207  }
208  }
209 }
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
wxString pin
Definition: export_d356.h:35
int x_location
Definition: export_d356.h:42
bool mechanical
Definition: export_d356.h:38
bool midpoint
Definition: export_d356.h:36
PCB_LAYER_ID
A quick note on layer IDs:
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
wxString refdes
Definition: export_d356.h:34
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:364
const wxPoint GetPosition() const override
Definition: class_track.h:408
int soldermask
Definition: export_d356.h:40
wxString netname
Definition: export_d356.h:33
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int GetWidth() const
Definition: class_track.h:112
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
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:97
int y_location
Definition: export_d356.h:43
TRACKS & Tracks()
Definition: class_board.h:247

References D356_RECORD::access, D356_RECORD::drill, BOARD::GetAuxOrigin(), VIA::GetDrillValue(), NETINFO_ITEM::GetNet(), NETINFO_ITEM::GetNetname(), VIA::GetPosition(), TRACK::GetWidth(), D356_RECORD::hole, VIA::LayerPair(), 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_access_code(), wxPoint::x, D356_RECORD::x_location, D356_RECORD::x_size, wxPoint::y, 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 52 of file export_d356.cpp.

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

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 212 of file export_d356.cpp.

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

Referenced by IPC356D_WRITER::write_D356_records().

◆ iu_to_d356()

static int iu_to_d356 ( int  iu,
int  clamp 
)
static

Definition at line 85 of file export_d356.cpp.

86 {
87  int val = KiROUND( iu / ( IU_PER_MILS / 10 ) );
88  if( val > clamp ) return clamp;
89  if( val < -clamp ) return -clamp;
90  return val;
91 }
#define IU_PER_MILS
Definition: plotter.cpp:138
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:61

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 147 of file export_d356.cpp.

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

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

Referenced by build_via_testpoints().