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.

95 {
96  wxPoint origin = aPcb->GetDesignSettings().m_AuxOrigin;
97 
98  for( auto module : aPcb->Modules() )
99  {
100  for( auto pad : module->Pads() )
101  {
102  D356_RECORD rk;
103  rk.access = compute_pad_access_code( aPcb, pad->GetLayerSet() );
104 
105  // It could be a mask only pad, we only handle pads with copper here
106  if( rk.access != -1 )
107  {
108  rk.netname = pad->GetNetname();
109  rk.pin = pad->GetName();
110  rk.refdes = module->GetReference();
111  rk.midpoint = false; // XXX MAYBE need to be computed (how?)
112  const wxSize& drill = pad->GetDrillSize();
113  rk.drill = std::min( drill.x, drill.y );
114  rk.hole = (rk.drill != 0);
115  rk.smd = pad->GetAttribute() == PAD_ATTRIB_SMD;
116  rk.mechanical = (pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED);
117  rk.x_location = pad->GetPosition().x - origin.x;
118  rk.y_location = origin.y - pad->GetPosition().y;
119  rk.x_size = pad->GetSize().x;
120 
121  // Rule: round pads have y = 0
122  if( pad->GetShape() == PAD_SHAPE_CIRCLE )
123  rk.y_size = 0;
124  else
125  rk.y_size = pad->GetSize().y;
126 
127  rk.rotation = -KiROUND( pad->GetOrientation() ) / 10;
128  if( rk.rotation < 0 ) rk.rotation += 360;
129 
130  // the value indicates which sides are *not* accessible
131  rk.soldermask = 3;
132  if( pad->GetLayerSet()[F_Mask] )
133  rk.soldermask &= ~1;
134  if( pad->GetLayerSet()[B_Mask] )
135  rk.soldermask &= ~2;
136 
137  aRecords.push_back( rk );
138  }
139  }
140  }
141 }
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:85
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
Function GetDesignSettings.
Definition: class_board.h:553
bool midpoint
Definition: export_d356.h:36
MODULES & Modules()
Definition: class_board.h:266
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: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:68
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::GetDesignSettings(), BOARD_ITEM::GetLayerSet(), D356_RECORD::hole, KiROUND(), BOARD_DESIGN_SETTINGS::m_AuxOrigin, 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 167 of file export_d356.cpp.

168 {
169  wxPoint origin = aPcb->GetDesignSettings().m_AuxOrigin;
170 
171  // Enumerate all the track segments and keep the vias
172  for( auto track : aPcb->Tracks() )
173  {
174  if( track->Type() == PCB_VIA_T )
175  {
176  VIA *via = (VIA*) track;
177  NETINFO_ITEM *net = track->GetNet();
178 
179  D356_RECORD rk;
180  rk.smd = false;
181  rk.hole = true;
182  if( net )
183  rk.netname = net->GetNetname();
184  else
185  rk.netname = wxEmptyString;
186  rk.refdes = wxT("VIA");
187  rk.pin = wxT("");
188  rk.midpoint = true; // Vias are always midpoints
189  rk.drill = via->GetDrillValue();
190  rk.mechanical = false;
191 
192  PCB_LAYER_ID top_layer, bottom_layer;
193 
194  via->LayerPair( &top_layer, &bottom_layer );
195 
196  rk.access = via_access_code( aPcb, top_layer, bottom_layer );
197  rk.x_location = via->GetPosition().x - origin.x;
198  rk.y_location = origin.y - via->GetPosition().y;
199  rk.x_size = via->GetWidth();
200  rk.y_size = 0; // Round so height = 0
201  rk.rotation = 0;
202  rk.soldermask = 3; // XXX always tented?
203 
204  aRecords.push_back( rk );
205  }
206  }
207 }
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
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:553
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
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:110
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
wxPoint GetPosition() const override
Definition: class_track.h:413
int y_location
Definition: export_d356.h:43
wxPoint m_AuxOrigin
origin for plot exports
TRACKS & Tracks()
Definition: class_board.h:257

References D356_RECORD::access, D356_RECORD::drill, BOARD::GetDesignSettings(), VIA::GetDrillValue(), NETINFO_ITEM::GetNet(), NETINFO_ITEM::GetNetname(), VIA::GetPosition(), TRACK::GetWidth(), D356_RECORD::hole, VIA::LayerPair(), 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_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:712
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 210 of file export_d356.cpp.

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

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

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

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

Referenced by build_via_testpoints().