KiCad PCB EDA Suite
PCAD2KICAD::PCB_PAD Class Reference

#include <pcb_pad.h>

Inheritance diagram for PCAD2KICAD::PCB_PAD:
PCAD2KICAD::PCB_COMPONENT PCAD2KICAD::PCB_VIA

Public Member Functions

 PCB_PAD (PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
 
 ~PCB_PAD ()
 
virtual void Parse (XNODE *aNode, const wxString &aDefaultUnits, const wxString &aActualConversion)
 
virtual void Flip () override
 
void AddToFootprint (FOOTPRINT *aFootprint) override
 
void AddToFootprint (FOOTPRINT *aFootprint, int aRotation, bool aEncapsulatedPad)
 
void AddToBoard () override
 
virtual void SetPosOffset (int aX_offs, int aY_offs)
 
PCB_LAYER_ID GetKiCadLayer () const
 
int GetNetCode (const wxString &aNetName) const
 

Public Attributes

int m_Number
 
int m_Hole
 
bool m_IsHolePlated
 
PCB_PAD_SHAPES_ARRAY m_Shapes
 
int m_tag
 
char m_objType
 
int m_PCadLayer
 
PCB_LAYER_ID m_KiCadLayer
 
KIID m_uuid
 
int m_positionX
 
int m_positionY
 
int m_rotation
 
TTEXTVALUE m_name
 
wxString m_net
 
int m_netCode
 
wxString m_compRef
 
wxString m_patGraphRefName
 

Protected Attributes

PCB_CALLBACKSm_callbacks
 
BOARDm_board
 

Private Attributes

wxString m_defaultPinDes
 

Detailed Description

Definition at line 38 of file pcb_pad.h.

Constructor & Destructor Documentation

◆ PCB_PAD()

PCAD2KICAD::PCB_PAD::PCB_PAD ( PCB_CALLBACKS aCallbacks,
BOARD aBoard 
)

Definition at line 42 of file pcb_pad.cpp.

42  :
43  PCB_COMPONENT( aCallbacks, aBoard )
44 {
45  m_objType = wxT( 'P' );
46  m_Number = 0;
47  m_Hole = 0;
48  m_IsHolePlated = true;
49  m_defaultPinDes = wxEmptyString;
50 }
wxString m_defaultPinDes
Definition: pcb_pad.h:64
PCB_COMPONENT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)

References m_defaultPinDes, m_Hole, m_IsHolePlated, m_Number, and PCAD2KICAD::PCB_COMPONENT::m_objType.

◆ ~PCB_PAD()

PCAD2KICAD::PCB_PAD::~PCB_PAD ( )

Definition at line 53 of file pcb_pad.cpp.

54 {
55  int i;
56 
57  for( i = 0; i < (int) m_Shapes.GetCount(); i++ )
58  delete m_Shapes[i];
59 }
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:61

References m_Shapes.

Member Function Documentation

◆ AddToBoard()

void PCAD2KICAD::PCB_PAD::AddToBoard ( )
overridevirtual

Implements PCAD2KICAD::PCB_COMPONENT.

Definition at line 327 of file pcb_pad.cpp.

328 {
329  PCB_PAD_SHAPE* padShape;
330  int i;
331  int width = 0;
332  int height = 0;
333 
334  if( m_objType == wxT( 'V' ) ) // via
335  {
336  // choose one of the shapes
337  for( i = 0; i < (int) m_Shapes.GetCount(); i++ )
338  {
339  padShape = m_Shapes[i];
340 
341  if( padShape->m_Width > 0 && padShape->m_Height > 0 )
342  {
343  if( padShape->m_KiCadLayer == F_Cu
344  || padShape->m_KiCadLayer == B_Cu )
345  {
346  width = padShape->m_Width;
347  height = padShape->m_Height;
348 
349  break;
350  }
351  }
352  }
353 
354  if( width == 0 || height == 0 )
355  return;
356 
357  if( IsCopperLayer( m_KiCadLayer ) )
358  {
359  PCB_VIA* via = new PCB_VIA( m_board );
360  m_board->Add( via );
361 
362  via->SetPosition( wxPoint( m_positionX, m_positionY ) );
363  via->SetEnd( wxPoint( m_positionX, m_positionY ) );
364 
365  via->SetWidth( height );
366  via->SetViaType( VIATYPE::THROUGH );
367  via->SetLayerPair( F_Cu, B_Cu );
368  via->SetDrill( m_Hole );
369 
370  via->SetLayer( m_KiCadLayer );
371  via->SetNetCode( m_netCode );
372  }
373  }
374  else // pad
375  {
376  FOOTPRINT* footprint = new FOOTPRINT( m_board );
377  m_board->Add( footprint, ADD_MODE::APPEND );
378 
380 
381  footprint->SetPosition( wxPoint( m_positionX, m_positionY ) );
382  AddToFootprint( footprint, 0, true );
383  }
384 }
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_pad.h:49
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:608
wxString m_defaultPinDes
Definition: pcb_pad.h:64
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:796
Definition: layer_ids.h:71
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1543
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:61

References BOARD::Add(), AddToFootprint(), APPEND, B_Cu, F_Cu, IsCopperLayer(), PCAD2KICAD::PCB_COMPONENT::m_board, m_defaultPinDes, PCAD2KICAD::PCB_PAD_SHAPE::m_Height, m_Hole, PCAD2KICAD::PCB_COMPONENT::m_KiCadLayer, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_netCode, PCAD2KICAD::PCB_COMPONENT::m_objType, PCAD2KICAD::PCB_COMPONENT::m_positionX, PCAD2KICAD::PCB_COMPONENT::m_positionY, m_Shapes, PCAD2KICAD::PCB_PAD_SHAPE::m_Width, FOOTPRINT::SetPosition(), PCAD2KICAD::TTEXTVALUE::text, THROUGH, and via.

◆ AddToFootprint() [1/2]

void PCAD2KICAD::PCB_PAD::AddToFootprint ( FOOTPRINT aFootprint)
inlineoverridevirtual

Reimplemented from PCAD2KICAD::PCB_COMPONENT.

Definition at line 49 of file pcb_pad.h.

50  {
51  AddToFootprint( aFootprint, 0, true );
52  }
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_pad.h:49

Referenced by AddToBoard().

◆ AddToFootprint() [2/2]

void PCAD2KICAD::PCB_PAD::AddToFootprint ( FOOTPRINT aFootprint,
int  aRotation,
bool  aEncapsulatedPad 
)

Definition at line 195 of file pcb_pad.cpp.

196 {
197  PCB_PAD_SHAPE* padShape;
198  wxString padShapeName = wxT( "Ellipse" );
199  PAD_ATTRIB padType;
200  int i;
201  int width = 0;
202  int height = 0;
203 
204  PAD* pad = new PAD( aFootprint );
205 
206  if( !m_IsHolePlated && m_Hole )
207  {
208  // mechanical hole
209  pad->SetShape( PAD_SHAPE::CIRCLE );
210  pad->SetAttribute( PAD_ATTRIB::NPTH );
211 
212  pad->SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );
213  pad->SetDrillSize( wxSize( m_Hole, m_Hole ) );
214  pad->SetSize( wxSize( m_Hole, m_Hole ) );
215 
216  // Mounting Hole: Solder Mask Margin from Top Layer Width size.
217  // Used the default zone clearance (simplify)
218  if( m_Shapes.GetCount() && m_Shapes[0]->m_Shape == wxT( "MtHole" ) )
219  {
220  int sm_margin = ( m_Shapes[0]->m_Width - m_Hole ) / 2;
221  pad->SetLocalSolderMaskMargin( sm_margin );
222  pad->SetLocalClearance( sm_margin + Millimeter2iu( 0.254 ) );
223  }
224 
225  pad->SetLayerSet( LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask ) );
226  }
227  else
228  {
229  ( m_Hole ) ? padType = PAD_ATTRIB::PTH : padType = PAD_ATTRIB::SMD;
230 
231  // form layer mask
232  for( i = 0; i < (int) m_Shapes.GetCount(); i++ )
233  {
234  padShape = m_Shapes[i];
235 
236  if( padShape->m_Width > 0 && padShape->m_Height > 0 )
237  {
238  if( padShape->m_KiCadLayer == F_Cu ||
239  padShape->m_KiCadLayer == B_Cu )
240  {
241  padShapeName = padShape->m_Shape;
242  width = padShape->m_Width;
243  height = padShape->m_Height;
244 
245  // assume this is SMD pad
246  if( padShape->m_KiCadLayer == F_Cu )
247  pad->SetLayerSet( LSET( 3, F_Cu, F_Paste, F_Mask ) );
248  else
249  pad->SetLayerSet( LSET( 3, B_Cu, B_Paste, B_Mask ) );
250 
251  break;
252  }
253  }
254  }
255 
256  if( width == 0 || height == 0 )
257  {
258  delete pad;
259  return;
260  }
261 
262  if( padType == PAD_ATTRIB::PTH )
263  // actually this is a thru-hole pad
264  pad->SetLayerSet( LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask ) );
265 
266  pad->SetNumber( m_name.text );
267 
268  if( padShapeName == wxT( "Oval" )
269  || padShapeName == wxT( "Ellipse" )
270  || padShapeName == wxT( "MtHole" ) )
271  {
272  if( width != height )
273  pad->SetShape( PAD_SHAPE::OVAL );
274  else
275  pad->SetShape( PAD_SHAPE::CIRCLE );
276  }
277  else if( padShapeName == wxT( "Rect" ) )
278  {
279  pad->SetShape( PAD_SHAPE::RECT );
280  }
281  else if( padShapeName == wxT( "RndRect" ) )
282  {
283  pad->SetShape( PAD_SHAPE::ROUNDRECT );
284  }
285  else if( padShapeName == wxT( "Polygon" ) )
286  {
287  pad->SetShape( PAD_SHAPE::RECT ); // approximation
288  }
289 
290  pad->SetSize( wxSize( width, height ) );
291  pad->SetDelta( wxSize( 0, 0 ) );
292  pad->SetOrientation( m_rotation + aRotation );
293 
294  pad->SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );
295  pad->SetOffset( wxPoint( 0, 0 ) );
296  pad->SetDrillSize( wxSize( m_Hole, m_Hole ) );
297 
298  pad->SetAttribute( padType );
299 
300  // Set the proper net code
301  NETINFO_ITEM* netinfo = m_board->FindNet( m_net );
302 
303  if( netinfo == nullptr ) // I believe this should not happen, but just in case
304  {
305  // It is a new net
306  netinfo = new NETINFO_ITEM( m_board, m_net );
307  m_board->Add( netinfo );
308  }
309 
310  pad->SetNetCode( netinfo->GetNetCode() );
311  }
312 
313  if( !aEncapsulatedPad )
314  {
315  // pad's "Position" is not relative to the footprint's, whereas Pos0 is relative to
316  // the footprint's but is the unrotated coordinate.
317  wxPoint padpos( m_positionX, m_positionY );
318  pad->SetPos0( padpos );
319  RotatePoint( &padpos, aFootprint->GetOrientation() );
320  pad->SetPosition( padpos + aFootprint->GetPosition() );
321  }
322 
323  aFootprint->Add( pad );
324 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1325
Smd pad, appears on the solder paste layer (default)
double GetOrientation() const
Definition: footprint.h:190
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
Plated through hole pad.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:608
like PAD_PTH, but not plated
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
Definition: pad_shapes.h:79
Handle the data for a net.
Definition: netinfo.h:66
Definition: layer_ids.h:71
wxPoint GetPosition() const override
Definition: footprint.h:186
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:513
Definition: pad.h:57
static constexpr int Millimeter2iu(double mm)
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:61
int GetNetCode() const
Definition: netinfo.h:115

References FOOTPRINT::Add(), BOARD::Add(), LSET::AllCuMask(), B_Cu, B_Mask, B_Paste, CIRCLE, F_Cu, F_Mask, F_Paste, BOARD::FindNet(), NETINFO_ITEM::GetNetCode(), FOOTPRINT::GetOrientation(), FOOTPRINT::GetPosition(), PCAD2KICAD::PCB_COMPONENT::m_board, PCAD2KICAD::PCB_PAD_SHAPE::m_Height, m_Hole, m_IsHolePlated, PCAD2KICAD::PCB_COMPONENT::m_KiCadLayer, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_net, PCAD2KICAD::PCB_COMPONENT::m_positionX, PCAD2KICAD::PCB_COMPONENT::m_positionY, PCAD2KICAD::PCB_COMPONENT::m_rotation, PCAD2KICAD::PCB_PAD_SHAPE::m_Shape, m_Shapes, PCAD2KICAD::PCB_PAD_SHAPE::m_Width, Millimeter2iu(), NPTH, OVAL, pad, PAD_DRILL_SHAPE_CIRCLE, PTH, RECT, RotatePoint(), ROUNDRECT, SMD, and PCAD2KICAD::TTEXTVALUE::text.

◆ Flip()

void PCAD2KICAD::PCB_PAD::Flip ( )
overridevirtual

Reimplemented from PCAD2KICAD::PCB_COMPONENT.

Definition at line 181 of file pcb_pad.cpp.

182 {
183  int i;
184 
186 
187  if( m_objType == wxT( 'P' ) )
189 
190  for( i = 0; i < (int)m_Shapes.GetCount(); i++ )
192 }
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:521
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:61

References PCAD2KICAD::PCB_COMPONENT::Flip(), FlipLayer(), PCAD2KICAD::PCB_COMPONENT::m_KiCadLayer, PCAD2KICAD::PCB_COMPONENT::m_objType, PCAD2KICAD::PCB_COMPONENT::m_rotation, and m_Shapes.

◆ GetKiCadLayer()

◆ GetNetCode()

int PCAD2KICAD::PCB_COMPONENT::GetNetCode ( const wxString &  aNetName) const
inlineinherited

◆ Parse()

void PCAD2KICAD::PCB_PAD::Parse ( XNODE aNode,
const wxString &  aDefaultUnits,
const wxString &  aActualConversion 
)
virtual

Reimplemented in PCAD2KICAD::PCB_VIA.

Definition at line 62 of file pcb_pad.cpp.

64 {
65  XNODE* lNode;
66  XNODE* cNode;
67  long num;
68  wxString propValue, str, emsg;
69  PCB_PAD_SHAPE* padShape;
70 
71  m_rotation = 0;
72  lNode = FindNode( aNode, wxT( "padNum" ) );
73 
74  if( lNode )
75  {
76  lNode->GetNodeContent().ToLong( &num );
77  m_Number = (int) num;
78  }
79 
80  lNode = FindNode( aNode, wxT( "padStyleRef" ) );
81 
82  if( lNode )
83  {
84  lNode->GetAttribute( wxT( "Name" ), &propValue );
85  propValue.Trim( false );
86  m_name.text = propValue;
87  }
88 
89  lNode = FindNode( aNode, wxT( "pt" ) );
90 
91  if( lNode )
92  {
93  SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_positionX, &m_positionY,
94  aActualConversion );
95  }
96 
97  lNode = FindNode( aNode, wxT( "rotation" ) );
98 
99  if( lNode )
100  {
101  str = lNode->GetNodeContent();
102  str.Trim( false );
103  m_rotation = StrToInt1Units( str );
104  }
105 
106  lNode = FindNode( aNode, wxT( "netNameRef" ) );
107 
108  if( lNode )
109  {
110  lNode->GetAttribute( wxT( "Name" ), &propValue );
111  propValue.Trim( false );
112  propValue.Trim( true );
113  m_net = propValue;
115  }
116 
117  lNode = FindNode( aNode, wxT( "defaultPinDes" ) );
118 
119  if( lNode )
120  {
121  lNode->GetAttribute( wxT( "Name" ), &propValue );
122 
123  //propValue.Trim( false );
124  m_defaultPinDes = propValue;
125  }
126 
127  lNode = aNode;
128 
129  while( lNode && lNode->GetName() != wxT( "www.lura.sk" ) )
130  lNode = lNode->GetParent();
131 
132  lNode = FindNode( lNode, wxT( "library" ) );
133 
134  if ( !lNode )
135  THROW_IO_ERROR( wxT( "Unable to find library section" ) );
136 
137  lNode = FindNode( lNode, wxT( "padStyleDef" ) );
138 
139  while( lNode )
140  {
141  lNode->GetAttribute( wxT( "Name" ), &propValue );
142 
143  if( propValue.IsSameAs( m_name.text, false) )
144  break;
145 
146  lNode = lNode->GetNext();
147  }
148 
149  if ( !lNode )
150  THROW_IO_ERROR( wxString::Format( wxT( "Unable to find padStyleDef " ) + m_name.text ) );
151 
152  cNode = FindNode( lNode, wxT( "holeDiam" ) );
153 
154  if( cNode )
155  SetWidth( cNode->GetNodeContent(), aDefaultUnits, &m_Hole, aActualConversion );
156 
157  if( FindNodeGetContent( lNode, wxT( "isHolePlated" ) ) == wxT( "False" ) )
158  m_IsHolePlated = false;
159 
160  cNode = FindNode( lNode, wxT( "padShape" ) );
161 
162  while( cNode )
163  {
164  if( cNode->GetName() == wxT( "padShape" ) )
165  {
166  // we support only Pads on specific layers......
167  // we do not support pads on "Plane", "NonSignal" , "Signal" ... layerr
168  if( FindNode( cNode, wxT( "layerNumRef" ) ) )
169  {
170  padShape = new PCB_PAD_SHAPE( m_callbacks, m_board );
171  padShape->Parse( cNode, aDefaultUnits, aActualConversion );
172  m_Shapes.Add( padShape );
173  }
174  }
175 
176  cNode = cNode->GetNext();
177  }
178 }
void SetWidth(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
int GetNetCode(const wxString &aNetName) const
Definition: pcb_component.h:58
XNODE * GetParent() const
Definition: xnode.h:72
wxString FindNodeGetContent(XNODE *aChild, const wxString &aTag)
wxString m_defaultPinDes
Definition: pcb_pad.h:64
Hold an XML or S-expression element.
Definition: xnode.h:43
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
XNODE * GetNext() const
Definition: xnode.h:67
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
PCB_CALLBACKS * m_callbacks
Definition: pcb_component.h:78
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:61
int StrToInt1Units(const wxString &aStr)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)

References PCAD2KICAD::FindNode(), PCAD2KICAD::FindNodeGetContent(), Format(), PCAD2KICAD::PCB_COMPONENT::GetNetCode(), XNODE::GetNext(), XNODE::GetParent(), PCAD2KICAD::PCB_COMPONENT::m_board, PCAD2KICAD::PCB_COMPONENT::m_callbacks, m_defaultPinDes, m_Hole, m_IsHolePlated, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_net, PCAD2KICAD::PCB_COMPONENT::m_netCode, m_Number, PCAD2KICAD::PCB_COMPONENT::m_positionX, PCAD2KICAD::PCB_COMPONENT::m_positionY, PCAD2KICAD::PCB_COMPONENT::m_rotation, m_Shapes, PCAD2KICAD::PCB_PAD_SHAPE::Parse(), PCAD2KICAD::SetPosition(), PCAD2KICAD::SetWidth(), PCAD2KICAD::StrToInt1Units(), PCAD2KICAD::TTEXTVALUE::text, and THROW_IO_ERROR.

◆ SetPosOffset()

void PCAD2KICAD::PCB_COMPONENT::SetPosOffset ( int  aX_offs,
int  aY_offs 
)
virtualinherited

Member Data Documentation

◆ m_board

◆ m_callbacks

◆ m_compRef

wxString PCAD2KICAD::PCB_COMPONENT::m_compRef
inherited

◆ m_defaultPinDes

wxString PCAD2KICAD::PCB_PAD::m_defaultPinDes
private

Definition at line 64 of file pcb_pad.h.

Referenced by AddToBoard(), Parse(), and PCB_PAD().

◆ m_Hole

int PCAD2KICAD::PCB_PAD::m_Hole

Definition at line 59 of file pcb_pad.h.

Referenced by AddToBoard(), AddToFootprint(), PCAD2KICAD::PCB_VIA::Parse(), Parse(), and PCB_PAD().

◆ m_IsHolePlated

bool PCAD2KICAD::PCB_PAD::m_IsHolePlated

Definition at line 60 of file pcb_pad.h.

Referenced by AddToFootprint(), Parse(), and PCB_PAD().

◆ m_KiCadLayer

◆ m_name

◆ m_net

◆ m_netCode

◆ m_Number

int PCAD2KICAD::PCB_PAD::m_Number

Definition at line 58 of file pcb_pad.h.

Referenced by Parse(), and PCB_PAD().

◆ m_objType

◆ m_patGraphRefName

wxString PCAD2KICAD::PCB_COMPONENT::m_patGraphRefName
inherited

◆ m_PCadLayer

◆ m_positionX

◆ m_positionY

◆ m_rotation

◆ m_Shapes

PCB_PAD_SHAPES_ARRAY PCAD2KICAD::PCB_PAD::m_Shapes

Definition at line 61 of file pcb_pad.h.

Referenced by AddToBoard(), AddToFootprint(), Flip(), PCAD2KICAD::PCB_VIA::Parse(), Parse(), and ~PCB_PAD().

◆ m_tag

int PCAD2KICAD::PCB_COMPONENT::m_tag
inherited

Definition at line 63 of file pcb_component.h.

Referenced by PCAD2KICAD::PCB_COMPONENT::PCB_COMPONENT().

◆ m_uuid

KIID PCAD2KICAD::PCB_COMPONENT::m_uuid
inherited

Definition at line 67 of file pcb_component.h.


The documentation for this class was generated from the following files: