KiCad PCB EDA Suite
PCAD2KICAD::PCB_VIA Class Reference

#include <pcb_via.h>

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

Public Member Functions

 PCB_VIA (PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
 
 ~PCB_VIA ()
 
virtual void Parse (XNODE *aNode, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion) override
 
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 (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
 

Detailed Description

Definition at line 40 of file pcb_via.h.

Constructor & Destructor Documentation

◆ PCB_VIA()

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

Definition at line 37 of file pcb_via.cpp.

37  : PCB_PAD( aCallbacks, aBoard )
38 {
39  m_objType = wxT( 'V' );
40 }
PCB_PAD(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_pad.cpp:37

References PCAD2KICAD::PCB_COMPONENT::m_objType.

◆ ~PCB_VIA()

PCAD2KICAD::PCB_VIA::~PCB_VIA ( )

Definition at line 43 of file pcb_via.cpp.

44 {
45 }

Member Function Documentation

◆ AddToBoard()

void PCAD2KICAD::PCB_PAD::AddToBoard ( )
overridevirtualinherited

Implements PCAD2KICAD::PCB_COMPONENT.

Definition at line 313 of file pcb_pad.cpp.

314 {
315  PCB_PAD_SHAPE* padShape;
316  int i;
317  int width = 0;
318  int height = 0;
319 
320  if( m_objType == wxT( 'V' ) ) // via
321  {
322  // choose one of the shapes
323  for( i = 0; i < (int) m_Shapes.GetCount(); i++ )
324  {
325  padShape = m_Shapes[i];
326 
327  if( padShape->m_Width > 0 && padShape->m_Height > 0 )
328  {
329  if( padShape->m_KiCadLayer == F_Cu
330  || padShape->m_KiCadLayer == B_Cu )
331  {
332  width = padShape->m_Width;
333  height = padShape->m_Height;
334 
335  break;
336  }
337  }
338  }
339 
340  if( width == 0 || height == 0 )
341  return;
342 
343  if( IsCopperLayer( m_KiCadLayer ) )
344  {
345  VIA* via = new VIA( m_board );
346  m_board->Add( via );
347 
348  via->SetPosition( wxPoint( m_positionX, m_positionY ) );
349  via->SetEnd( wxPoint( m_positionX, m_positionY ) );
350 
351  via->SetWidth( height );
352  via->SetViaType( VIATYPE::THROUGH );
353  via->SetLayerPair( F_Cu, B_Cu );
354  via->SetDrill( m_Hole );
355 
356  via->SetLayer( m_KiCadLayer );
357  via->SetNetCode( m_netCode );
358  }
359  }
360  else // pad
361  {
362  FOOTPRINT* footprint = new FOOTPRINT( m_board );
363  m_board->Add( footprint, ADD_MODE::APPEND );
364 
366 
367  footprint->SetPosition( wxPoint( m_positionX, m_positionY ) );
368  AddToFootprint( footprint, 0, true );
369  }
370 }
Definition: track.h:343
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_pad.h:52
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
wxString m_defaultPinDes
Definition: pcb_pad.h:62
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1438
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:42

References BOARD::Add(), PCAD2KICAD::PCB_PAD::AddToFootprint(), APPEND, B_Cu, F_Cu, IsCopperLayer(), PCAD2KICAD::PCB_COMPONENT::m_board, PCAD2KICAD::PCB_PAD::m_defaultPinDes, PCAD2KICAD::PCB_PAD_SHAPE::m_Height, PCAD2KICAD::PCB_PAD::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, PCAD2KICAD::PCB_PAD::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)
inlineoverridevirtualinherited

Reimplemented from PCAD2KICAD::PCB_COMPONENT.

Definition at line 52 of file pcb_pad.h.

53  {
54  AddToFootprint( aFootprint, 0, true );
55  }
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_pad.h:52

Referenced by PCAD2KICAD::PCB_PAD::AddToBoard().

◆ AddToFootprint() [2/2]

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

Definition at line 189 of file pcb_pad.cpp.

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

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, PCAD2KICAD::PCB_PAD::m_Hole, PCAD2KICAD::PCB_PAD::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, PCAD2KICAD::PCB_PAD::m_Shapes, PCAD2KICAD::PCB_PAD_SHAPE::m_Width, Millimeter2iu(), NPTH, NULL, OVAL, pad, PAD_DRILL_SHAPE_CIRCLE, PTH, RECT, RotatePoint(), ROUNDRECT, SMD, and PCAD2KICAD::_TTEXTVALUE::text.

◆ Flip()

void PCAD2KICAD::PCB_PAD::Flip ( )
overridevirtualinherited

Reimplemented from PCAD2KICAD::PCB_COMPONENT.

Definition at line 175 of file pcb_pad.cpp.

176 {
177  int i;
178 
180 
181  if( m_objType == wxT( 'P' ) )
183 
184  for( i = 0; i < (int)m_Shapes.GetCount(); i++ )
186 }
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:521
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:42

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

◆ GetKiCadLayer()

◆ GetNetCode()

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

◆ Parse()

void PCAD2KICAD::PCB_VIA::Parse ( XNODE aNode,
const wxString &  aDefaultMeasurementUnit,
const wxString &  aActualConversion 
)
overridevirtual

Reimplemented from PCAD2KICAD::PCB_PAD.

Definition at line 48 of file pcb_via.cpp.

51 {
52  XNODE* lNode, * tNode;
53  wxString propValue;
54  PCB_VIA_SHAPE* viaShape;
55 
56  m_rotation = 0;
57  lNode = FindNode( aNode, wxT( "viaStyleRef" ) );
58 
59  if( lNode )
60  {
61  lNode->GetAttribute( wxT( "Name" ), &propValue );
62  propValue.Trim( false );
63  propValue.Trim( true );
64  m_name.text = propValue;
65  }
66 
67  lNode = FindNode( aNode, wxT( "pt" ) );
68 
69  if( lNode )
70  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
71  &m_positionX, &m_positionY, aActualConversion );
72 
73  lNode = FindNode( aNode, wxT( "netNameRef" ) );
74 
75  if( lNode )
76  {
77  lNode->GetAttribute( wxT( "Name" ), &propValue );
78  propValue.Trim( false );
79  propValue.Trim( true );
80  m_net = propValue;
82  }
83 
84  lNode = aNode;
85 
86  while( lNode && lNode->GetName() != wxT( "www.lura.sk" ) )
87  lNode = lNode->GetParent();
88 
89  lNode = FindNode( lNode, wxT( "library" ) );
90 
91  if ( !lNode )
92  THROW_IO_ERROR( wxT( "Unable to find library section" ) );
93 
94  lNode = FindNode( lNode, wxT( "viaStyleDef" ) );
95 
96  while( lNode )
97  {
98  lNode->GetAttribute( wxT( "Name" ), &propValue );
99 
100  if( propValue.IsSameAs( m_name.text, false ) )
101  break;
102 
103  lNode = lNode->GetNext();
104  }
105 
106  if ( !lNode )
107  THROW_IO_ERROR( wxString::Format( wxT( "Unable to find viaStyleDef " ) + m_name.text ) );
108 
109  if( lNode )
110  {
111  tNode = lNode;
112  lNode = FindNode( tNode, wxT( "holeDiam" ) );
113 
114  if( lNode )
115  SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_Hole,
116  aActualConversion );
117 
118  lNode = FindNode( tNode, wxT( "viaShape" ) );
119 
120  while( lNode )
121  {
122  if( lNode->GetName() == wxT( "viaShape" ) )
123  {
124  // we support only Vias on specific layers......
125  // we do not support vias on "Plane", "NonSignal" , "Signal" ... layerr
126  if( FindNode( lNode, wxT( "layerNumRef" ) ) )
127  {
128  viaShape = new PCB_VIA_SHAPE( m_callbacks, m_board );
129  viaShape->Parse( lNode, aDefaultMeasurementUnit, aActualConversion );
130  m_Shapes.Add( viaShape );
131  }
132  }
133 
134  lNode = lNode->GetNext();
135  }
136  }
137 }
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void SetWidth(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
XNODE * GetParent() const
Definition: xnode.h:72
int GetNetCode(wxString aNetName) const
Definition: pcb_component.h:71
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 * FindNode(XNODE *aChild, const wxString &aTag)
PCB_CALLBACKS * m_callbacks
Definition: pcb_component.h:74
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:42
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References PCAD2KICAD::FindNode(), Format(), PCAD2KICAD::PCB_COMPONENT::GetNetCode(), XNODE::GetParent(), PCAD2KICAD::PCB_COMPONENT::m_board, PCAD2KICAD::PCB_COMPONENT::m_callbacks, PCAD2KICAD::PCB_PAD::m_Hole, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_net, PCAD2KICAD::PCB_COMPONENT::m_netCode, PCAD2KICAD::PCB_COMPONENT::m_positionX, PCAD2KICAD::PCB_COMPONENT::m_positionY, PCAD2KICAD::PCB_COMPONENT::m_rotation, PCAD2KICAD::PCB_PAD::m_Shapes, PCAD2KICAD::PCB_VIA_SHAPE::Parse(), PCAD2KICAD::SetPosition(), PCAD2KICAD::SetWidth(), 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_Hole

int PCAD2KICAD::PCB_PAD::m_Hole
inherited

◆ m_IsHolePlated

bool PCAD2KICAD::PCB_PAD::m_IsHolePlated
inherited

◆ m_KiCadLayer

◆ m_name

◆ m_net

◆ m_netCode

◆ m_Number

int PCAD2KICAD::PCB_PAD::m_Number
inherited

Definition at line 39 of file pcb_pad.h.

Referenced by PCAD2KICAD::PCB_PAD::Parse(), and PCAD2KICAD::PCB_PAD::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
inherited

◆ m_tag

int PCAD2KICAD::PCB_COMPONENT::m_tag
inherited

Definition at line 48 of file pcb_component.h.

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

◆ m_uuid

KIID PCAD2KICAD::PCB_COMPONENT::m_uuid
inherited

Definition at line 52 of file pcb_component.h.


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