KiCad PCB EDA Suite
PCAD2KICAD::PCB Class Reference

#include <pcb.h>

Inheritance diagram for PCAD2KICAD::PCB:
PCAD2KICAD::PCB_FOOTPRINT PCAD2KICAD::PCB_CALLBACKS PCAD2KICAD::PCB_COMPONENT

Public Member Functions

 PCB (BOARD *aBoard)
 
 ~PCB ()
 
PCB_LAYER_ID GetKiCadLayer (int aPCadLayer) const override
 
LAYER_TYPE_T GetLayerType (int aPCadLayer) const override
 
wxString GetLayerNetNameRef (int aPCadLayer) const override
 
int GetNetCode (const wxString &aNetName) const override
 
void ParseBoard (wxStatusBar *aStatusBar, wxXmlDocument *aXmlDoc, const wxString &aActualConversion)
 
void AddToBoard () override
 
XNODEFindModulePatternDefName (XNODE *aNode, const wxString &aName)
 
void DoLayerContentsObjects (XNODE *aNode, PCB_FOOTPRINT *aFootprint, PCB_COMPONENTS_ARRAY *aList, wxStatusBar *aStatusBar, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
 
void SetName (const wxString &aPin, const wxString &aName)
 
virtual void Parse (XNODE *aNode, wxStatusBar *aStatusBar, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
 
virtual void Flip () override
 
virtual void SetPosOffset (int aX_offs, int aY_offs)
 
virtual void AddToFootprint (FOOTPRINT *aFootprint)
 
PCB_LAYER_ID GetKiCadLayer () const
 

Public Attributes

PCB_COMPONENTS_ARRAY m_PcbComponents
 
PCB_NETS_ARRAY m_PcbNetlist
 
wxString m_DefaultMeasurementUnit
 
std::map< int, TLAYERm_LayersMap
 
int m_SizeX
 
int m_SizeY
 
TTEXTVALUE m_Value
 
PCB_COMPONENTS_ARRAY m_FootprintItems
 
int m_Mirror
 
VERTICES_ARRAY m_BoardOutline
 
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 Member Functions

XNODEFindCompDefName (XNODE *aNode, const wxString &aName) const
 
void SetTextProperty (XNODE *aNode, TTEXTVALUE *aTextValue, const wxString &aPatGraphRefName, const wxString &aXmlName, const wxString &aActualConversion)
 
void DoPCBComponents (XNODE *aNode, wxXmlDocument *aXmlDoc, const wxString &aActualConversion, wxStatusBar *aStatusBar)
 
void ConnectPinToNet (const wxString &aCr, const wxString &aPr, const wxString &aNetName)
 
int FindLayer (const wxString &aLayerName) const
 
void MapLayer (XNODE *aNode)
 
int FindOutlinePoint (const VERTICES_ARRAY *aOutline, wxRealPoint aPoint) const
 
double GetDistance (const wxRealPoint *aPoint1, const wxRealPoint *aPoint2) const
 
void GetBoardOutline (wxXmlDocument *aXmlDoc, const wxString &aActualConversion)
 

Private Attributes

wxArrayString m_layersStackup
 

Detailed Description

Definition at line 46 of file pcb.h.

Constructor & Destructor Documentation

◆ PCB()

PCAD2KICAD::PCB::PCB ( BOARD aBoard)

Definition at line 79 of file pcb.cpp.

79  :
80  PCB_FOOTPRINT( this, aBoard )
81 {
82  m_DefaultMeasurementUnit = wxT( "mil" );
83 
84  for( size_t i = 0; i < 8; ++i )
85  {
86  TLAYER layer;
87  layer.KiCadLayer = F_Mask; // default
88  layer.layerType = LAYER_TYPE_NONSIGNAL; // default
89  layer.netNameRef = wxT( "" ); // default
90 
91  m_LayersMap.insert( std::make_pair( i, layer ) );
92  }
93 
94  m_SizeX = 0;
95  m_SizeY = 0;
96 
97  m_LayersMap[1].KiCadLayer = F_Cu;
98  m_LayersMap[1].layerType = LAYER_TYPE_SIGNAL;
99 
100  m_LayersMap[2].KiCadLayer = B_Cu;
101  m_LayersMap[2].layerType = LAYER_TYPE_SIGNAL;
102 
103  m_LayersMap[3].KiCadLayer = Eco2_User;
104  m_LayersMap[6].KiCadLayer = F_SilkS;
105  m_LayersMap[7].KiCadLayer = B_SilkS;
106 }
int m_SizeX
Definition: pcb.h:66
PCB_LAYER_ID KiCadLayer
Definition: pcb_callbacks.h:46
std::map< int, TLAYER > m_LayersMap
Definition: pcb.h:65
wxString m_DefaultMeasurementUnit
Definition: pcb.h:64
LAYER_TYPE_T layerType
Definition: pcb_callbacks.h:47
wxString netNameRef
Definition: pcb_callbacks.h:48
int m_SizeY
Definition: pcb.h:67
Definition: layer_ids.h:71
PCB_FOOTPRINT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)

References B_Cu, B_SilkS, Eco2_User, F_Cu, F_Mask, F_SilkS, TLAYER::KiCadLayer, LAYER_TYPE_NONSIGNAL, LAYER_TYPE_SIGNAL, TLAYER::layerType, m_DefaultMeasurementUnit, m_LayersMap, m_SizeX, m_SizeY, and TLAYER::netNameRef.

◆ ~PCB()

PCAD2KICAD::PCB::~PCB ( )

Definition at line 109 of file pcb.cpp.

110 {
111  int i;
112 
113  for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
114  {
115  delete m_PcbComponents[i];
116  }
117 
118  for( i = 0; i < (int) m_PcbNetlist.GetCount(); i++ )
119  {
120  delete m_PcbNetlist[i];
121  }
122 }
PCB_COMPONENTS_ARRAY m_PcbComponents
Definition: pcb.h:62
PCB_NETS_ARRAY m_PcbNetlist
Definition: pcb.h:63

References m_PcbComponents, and m_PcbNetlist.

Member Function Documentation

◆ AddToBoard()

void PCAD2KICAD::PCB::AddToBoard ( )
overridevirtual

Implements PCAD2KICAD::PCB_COMPONENT.

Definition at line 942 of file pcb.cpp.

943 {
944  int i;
945  PCB_NET* net;
946 
948 
949  for( i = 0; i < (int) m_PcbNetlist.GetCount(); i++ )
950  {
951  net = m_PcbNetlist[i];
952 
953  m_board->Add( new NETINFO_ITEM( m_board, net->m_Name, net->m_NetCode ) );
954  }
955 
956  for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
957  {
958  m_PcbComponents[i]->AddToBoard();
959  }
960 }
void SetCopperLayerCount(int aCount)
Definition: board.cpp:461
PCB_COMPONENTS_ARRAY m_PcbComponents
Definition: pcb.h:62
PCB_NETS_ARRAY m_PcbNetlist
Definition: pcb.h:63
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:608
wxArrayString m_layersStackup
Definition: pcb.h:86
Handle the data for a net.
Definition: netinfo.h:64

References BOARD::Add(), PCAD2KICAD::PCB_COMPONENT::m_board, m_layersStackup, PCAD2KICAD::PCB_NET::m_Name, PCAD2KICAD::PCB_NET::m_NetCode, m_PcbComponents, m_PcbNetlist, and BOARD::SetCopperLayerCount().

Referenced by PCAD_PLUGIN::Load().

◆ AddToFootprint()

void PCAD2KICAD::PCB_COMPONENT::AddToFootprint ( FOOTPRINT aFootprint)
virtualinherited

◆ ConnectPinToNet()

void PCAD2KICAD::PCB::ConnectPinToNet ( const wxString &  aCr,
const wxString &  aPr,
const wxString &  aNetName 
)
private

Definition at line 428 of file pcb.cpp.

430 {
431  PCB_FOOTPRINT* footprint;
432  PCB_PAD* cp;
433  int i, j;
434 
435  for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
436  {
437  footprint = (PCB_FOOTPRINT*) m_PcbComponents[i];
438 
439  if( footprint->m_objType == wxT( 'M' ) && footprint->m_name.text == aCompRef )
440  {
441  for( j = 0; j < (int) footprint->m_FootprintItems.GetCount(); j++ )
442  {
443  if( footprint->m_FootprintItems[j]->m_objType == wxT( 'P' ) )
444  {
445  cp = (PCB_PAD*) footprint->m_FootprintItems[j];
446 
447  if( cp->m_name.text == aPinRef )
448  cp->m_net = aNetName;
449  }
450  }
451  }
452  }
453 }
PCB_COMPONENTS_ARRAY m_PcbComponents
Definition: pcb.h:62
PCB_FOOTPRINT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)

References PCAD2KICAD::PCB_FOOTPRINT::m_FootprintItems, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_net, PCAD2KICAD::PCB_COMPONENT::m_objType, m_PcbComponents, and PCAD2KICAD::TTEXTVALUE::text.

Referenced by ParseBoard().

◆ DoLayerContentsObjects()

void PCAD2KICAD::PCB_FOOTPRINT::DoLayerContentsObjects ( XNODE aNode,
PCB_FOOTPRINT aFootprint,
PCB_COMPONENTS_ARRAY *  aList,
wxStatusBar *  aStatusBar,
const wxString &  aDefaultMeasurementUnit,
const wxString &  aActualConversion 
)
inherited

Definition at line 218 of file pcb_footprint.cpp.

222 {
223  PCB_ARC* arc;
224  PCB_POLYGON* polygon;
225  PCB_POLYGON *plane_layer = nullptr;
226  PCB_COPPER_POUR* copperPour;
227  PCB_CUTOUT* cutout;
228  PCB_PLANE* plane;
229  VERTICES_ARRAY* plane_layer_polygon;
230  PCB_LINE* line;
231  PCB_TEXT* text;
232  XNODE* lNode, * tNode;
233  wxString propValue;
234  long long i;
235  int PCadLayer;
236  long num = 0;
237 
238  i = 0;
239 
240  // aStatusBar->SetStatusText( wxT( "Processing LAYER CONTENT OBJECTS " ) );
241  if( FindNode( aNode, wxT( "layerNumRef" ) ) )
242  FindNode( aNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &num );
243 
244  PCadLayer = (int) num;
245 
246  if( m_callbacks->GetLayerType( PCadLayer ) == LAYER_TYPE_PLANE )
247  {
248  plane_layer = new PCB_POLYGON( m_callbacks, m_board, PCadLayer );
249  plane_layer->AssignNet( m_callbacks->GetLayerNetNameRef( PCadLayer ) );
250  plane_layer->SetOutline( &m_BoardOutline );
251  aList->Add( plane_layer );
252 
253  // fill the polygon with the same contour as its outline is
254  //plane_layer->AddIsland( &m_boardOutline );
255  }
256 
257  lNode = aNode->GetChildren();
258 
259  while( lNode )
260  {
261  i++;
262  // aStatusBar->SetStatusText( wxString::Format( "Processing LAYER CONTENT OBJECTS :%lld",
263  // i ) );
264 
265  if( lNode->GetName() == wxT( "line" ) )
266  {
267  line = new PCB_LINE( m_callbacks, m_board );
268  line->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
269  aList->Add( line );
270  }
271 
272  if( lNode->GetName() == wxT( "text" ) )
273  {
274  text = new PCB_TEXT( m_callbacks, m_board );
275  text->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
276  aList->Add( text );
277  }
278 
279  // added as Sergeys request 02/2008
280  if( lNode->GetName() == wxT( "attr" ) )
281  {
282  // assign fonts to Module Name,Value,Type,....s
283  lNode->GetAttribute( wxT( "Name" ), &propValue );
284  propValue.Trim( false );
285  propValue.Trim( true );
286 
287  if( propValue == wxT( "RefDes" ) )
288  {
289  tNode = FindNode( lNode, wxT( "textStyleRef" ) );
290 
291  if( tNode && aFootprint )
292  {
293  // TODO: to understand and may be repair
294  // Alexander Lunev: originally in Delphi version of the project there was
295  // a strange access to pcbModule->m_name (it was global variable). This access
296  // is necessary when the function DoLayerContentsObjects() is called from
297  // function CreatePCBModule(). However it is not clear whether the access is
298  // required when the function DoLayerContentsObjects() is called from
299  // function ProcessXMLtoPCBLib().
300  SetFontProperty( tNode, &aFootprint->m_name, aDefaultMeasurementUnit,
301  aActualConversion );
302  }
303  }
304  }
305 
306  // added as Sergeys request 02/2008
307  if( lNode->GetName() == wxT( "arc" ) || lNode->GetName() == wxT( "triplePointArc" ) )
308  {
309  arc = new PCB_ARC( m_callbacks, m_board );
310  arc->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
311  aList->Add( arc );
312  }
313 
314  if( lNode->GetName() == wxT( "pcbPoly" ) )
315  {
316  if( m_callbacks->GetLayerType( PCadLayer ) == LAYER_TYPE_PLANE )
317  {
318  plane_layer_polygon = new VERTICES_ARRAY;
319  wxASSERT( plane_layer );
320  plane_layer->FormPolygon( lNode, plane_layer_polygon, aDefaultMeasurementUnit,
321  aActualConversion );
322  plane_layer->m_cutouts.Add( plane_layer_polygon );
323  }
324  else
325  {
326  polygon = new PCB_POLYGON( m_callbacks, m_board, PCadLayer );
327 
328  if( polygon->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
329  aList->Add( polygon );
330  else
331  delete polygon;
332  }
333  }
334 
335  if( lNode->GetName() == wxT( "copperPour95" ) )
336  {
337  copperPour = new PCB_COPPER_POUR( m_callbacks, m_board, PCadLayer );
338 
339  if( copperPour->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
340  aList->Add( copperPour );
341  else
342  delete copperPour;
343  }
344 
345  if( lNode->GetName() == wxT( "polyCutOut" ) )
346  {
347  cutout = new PCB_CUTOUT( m_callbacks, m_board, PCadLayer );
348 
349  if( cutout->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
350  aList->Add( cutout );
351  else
352  delete cutout;
353  }
354 
355  if( lNode->GetName() == wxT( "planeObj" ) )
356  {
357  plane = new PCB_PLANE( m_callbacks, m_board, PCadLayer );
358 
359  if( plane->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
360  aList->Add( plane );
361  else
362  delete plane;
363  }
364 
365  lNode = lNode->GetNext();
366  }
367 }
void SetFontProperty(XNODE *aNode, TTEXTVALUE *aTextValue, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
virtual wxString GetLayerNetNameRef(int aPCadLayer) const =0
virtual LAYER_TYPE_T GetLayerType(int aPCadLayer) const =0
XNODE * GetChildren() const
Definition: xnode.h:62
VERTICES_ARRAY m_BoardOutline
Definition: pcb_footprint.h:66
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:67
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
PCB_CALLBACKS * m_callbacks
Definition: pcb_component.h:78

References PCAD2KICAD::PCB_POLYGON::AssignNet(), PCAD2KICAD::FindNode(), PCAD2KICAD::PCB_POLYGON::FormPolygon(), XNODE::GetChildren(), PCAD2KICAD::PCB_CALLBACKS::GetLayerNetNameRef(), PCAD2KICAD::PCB_CALLBACKS::GetLayerType(), XNODE::GetNext(), LAYER_TYPE_PLANE, PCAD2KICAD::PCB_COMPONENT::m_board, PCAD2KICAD::PCB_FOOTPRINT::m_BoardOutline, PCAD2KICAD::PCB_COMPONENT::m_callbacks, PCAD2KICAD::PCB_POLYGON::m_cutouts, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_PLANE::Parse(), PCAD2KICAD::PCB_COPPER_POUR::Parse(), PCAD2KICAD::PCB_CUTOUT::Parse(), PCAD2KICAD::PCB_ARC::Parse(), PCAD2KICAD::PCB_LINE::Parse(), PCAD2KICAD::PCB_POLYGON::Parse(), PCAD2KICAD::SetFontProperty(), PCAD2KICAD::PCB_POLYGON::SetOutline(), and text.

Referenced by PCAD2KICAD::PCB_FOOTPRINT::Parse(), and ParseBoard().

◆ DoPCBComponents()

void PCAD2KICAD::PCB::DoPCBComponents ( XNODE aNode,
wxXmlDocument *  aXmlDoc,
const wxString &  aActualConversion,
wxStatusBar *  aStatusBar 
)
private

Definition at line 239 of file pcb.cpp.

241 {
242  XNODE* lNode, * tNode, * mNode;
243  PCB_FOOTPRINT* fp;
244  PCB_PAD* pad;
245  PCB_VIA* via;
246  PCB_KEEPOUT* keepOut;
247  wxString cn, str, propValue;
248 
249  lNode = aNode->GetChildren();
250 
251  while( lNode )
252  {
253  fp = nullptr;
254 
255  if( lNode->GetName() == wxT( "pattern" ) )
256  {
257  FindNode( lNode, wxT( "patternRef" ) )->GetAttribute( wxT( "Name" ),
258  &cn );
259  cn = ValidateName( cn );
260  tNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
261 
262  if( tNode && cn.Len() > 0 )
263  {
264  tNode = FindModulePatternDefName( tNode, cn );
265 
266  if( tNode )
267  {
268  fp = new PCB_FOOTPRINT( this, m_board );
269 
270  mNode = FindNode( lNode, wxT( "patternGraphicsNameRef" ) );
271 
272  if( mNode )
273  mNode->GetAttribute( wxT( "Name" ), &fp->m_patGraphRefName );
274 
275  fp->Parse( tNode, aStatusBar, m_DefaultMeasurementUnit, aActualConversion );
276  }
277  }
278 
279  if( fp )
280  {
281  fp->m_compRef = cn; // default - in new version of file it is updated later....
282  tNode = FindNode( lNode, wxT( "refDesRef" ) );
283 
284  if( tNode )
285  {
286  tNode->GetAttribute( wxT( "Name" ), &fp->m_name.text );
287  SetTextProperty( lNode, &fp->m_name, fp->m_patGraphRefName, wxT( "RefDes" ),
288  aActualConversion );
289  SetTextProperty( lNode, &fp->m_Value, fp->m_patGraphRefName, wxT( "Value" ),
290  aActualConversion );
291  }
292 
293  tNode = FindNode( lNode, wxT( "pt" ) );
294 
295  if( tNode )
296  {
297  SetPosition( tNode->GetNodeContent(), m_DefaultMeasurementUnit,
298  &fp->m_positionX, &fp->m_positionY, aActualConversion );
299  }
300 
301  tNode = FindNode( lNode, wxT( "rotation" ) );
302 
303  if( tNode )
304  {
305  str = tNode->GetNodeContent();
306  str.Trim( false );
307  fp->m_rotation = StrToInt1Units( str );
308  }
309 
310  str = FindNodeGetContent( lNode, wxT( "isFlipped" ) );
311 
312  if( str == wxT( "True" ) )
313  fp->m_Mirror = 1;
314 
315  tNode = aNode;
316 
317  while( tNode->GetName() != wxT( "www.lura.sk" ) )
318  tNode = tNode->GetParent();
319 
320  tNode = FindNode( tNode, wxT( "netlist" ) );
321 
322  if( tNode )
323  {
324  tNode = FindNode( tNode, wxT( "compInst" ) );
325 
326  while( tNode )
327  {
328  tNode->GetAttribute( wxT( "Name" ), &propValue );
329 
330  if( propValue == fp->m_name.text )
331  {
332  if( FindNode( tNode, wxT( "compValue" ) ) )
333  {
334  FindNode( tNode,
335  wxT( "compValue" ) )->GetAttribute( wxT( "Name" ),
336  &fp->m_Value.text );
337  fp->m_Value.text.Trim( false );
338  fp->m_Value.text.Trim( true );
339  }
340 
341  if( FindNode( tNode, wxT( "compRef" ) ) )
342  {
343  FindNode( tNode,
344  wxT( "compRef" ) )->GetAttribute( wxT( "Name" ),
345  &fp->m_compRef );
346  fp->m_compRef.Trim( false );
347  fp->m_compRef.Trim( true );
348  }
349 
350  tNode = nullptr;
351  }
352  else
353  {
354  tNode = tNode->GetNext();
355  }
356  }
357  }
358 
359  // map pins
360  tNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
361  tNode = FindCompDefName( tNode, fp->m_compRef );
362 
363  if( tNode )
364  {
365  tNode = FindPinMap( tNode );
366 
367  if( tNode )
368  {
369  mNode = tNode->GetChildren();
370 
371  while( mNode )
372  {
373  if( mNode->GetName() == wxT( "padNum" ) )
374  {
375  str = mNode->GetNodeContent();
376  mNode = mNode->GetNext();
377 
378  if( !mNode )
379  break;
380 
381  mNode->GetAttribute( wxT( "Name" ), &propValue );
382  fp->SetName( str, propValue );
383  mNode = mNode->GetNext();
384  }
385  else
386  {
387  mNode = mNode->GetNext();
388 
389  if( !mNode )
390  break;
391 
392  mNode = mNode->GetNext();
393  }
394  }
395  }
396  }
397 
398  m_PcbComponents.Add( fp );
399  }
400  }
401  else if( lNode->GetName() == wxT( "pad" ) )
402  {
403  pad = new PCB_PAD( this, m_board );
404  pad->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion );
405  m_PcbComponents.Add( pad );
406  }
407  else if( lNode->GetName() == wxT( "via" ) )
408  {
409  via = new PCB_VIA( this, m_board );
410  via->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion );
411  m_PcbComponents.Add( via );
412  }
413  else if( lNode->GetName() == wxT( "polyKeepOut" ) )
414  {
415  keepOut = new PCB_KEEPOUT( m_callbacks, m_board, 0 );
416 
417  if( keepOut->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion ) )
418  m_PcbComponents.Add( keepOut );
419  else
420  delete keepOut;
421  }
422 
423  lNode = lNode->GetNext();
424  }
425 }
wxString ValidateName(const wxString &aName)
XNODE * FindModulePatternDefName(XNODE *aNode, const wxString &aName)
PCB_COMPONENTS_ARRAY m_PcbComponents
Definition: pcb.h:62
void SetTextProperty(XNODE *aNode, TTEXTVALUE *aTextValue, const wxString &aPatGraphRefName, const wxString &aXmlName, const wxString &aActualConversion)
Definition: pcb.cpp:170
wxString m_DefaultMeasurementUnit
Definition: pcb.h:64
XNODE * GetChildren() const
Definition: xnode.h:62
XNODE * GetParent() const
Definition: xnode.h:72
wxString FindNodeGetContent(XNODE *aChild, const wxString &aTag)
XNODE * FindCompDefName(XNODE *aNode, const wxString &aName) const
Definition: pcb.cpp:142
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:67
PCB_FOOTPRINT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
PCB_CALLBACKS * m_callbacks
Definition: pcb_component.h:78
XNODE * FindPinMap(XNODE *aNode)
int StrToInt1Units(const wxString &aStr)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)

References FindCompDefName(), PCAD2KICAD::PCB_FOOTPRINT::FindModulePatternDefName(), PCAD2KICAD::FindNode(), PCAD2KICAD::FindNodeGetContent(), PCAD2KICAD::FindPinMap(), XNODE::GetChildren(), XNODE::GetNext(), XNODE::GetParent(), PCAD2KICAD::PCB_COMPONENT::m_board, PCAD2KICAD::PCB_COMPONENT::m_callbacks, PCAD2KICAD::PCB_COMPONENT::m_compRef, m_DefaultMeasurementUnit, PCAD2KICAD::PCB_FOOTPRINT::m_Mirror, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_patGraphRefName, m_PcbComponents, PCAD2KICAD::PCB_COMPONENT::m_positionX, PCAD2KICAD::PCB_COMPONENT::m_positionY, PCAD2KICAD::PCB_COMPONENT::m_rotation, PCAD2KICAD::PCB_FOOTPRINT::m_Value, pad, PCAD2KICAD::PCB_KEEPOUT::Parse(), PCAD2KICAD::PCB_FOOTPRINT::Parse(), PCAD2KICAD::PCB_FOOTPRINT::PCB_FOOTPRINT(), PCAD2KICAD::PCB_FOOTPRINT::SetName(), PCAD2KICAD::SetPosition(), SetTextProperty(), PCAD2KICAD::StrToInt1Units(), PCAD2KICAD::TTEXTVALUE::text, PCAD2KICAD::ValidateName(), and via.

Referenced by ParseBoard().

◆ FindCompDefName()

XNODE * PCAD2KICAD::PCB::FindCompDefName ( XNODE aNode,
const wxString &  aName 
) const
private

Definition at line 142 of file pcb.cpp.

143 {
144  XNODE* result = nullptr, * lNode;
145  wxString propValue;
146 
147  lNode = FindNode( aNode, wxT( "compDef" ) );
148 
149  while( lNode )
150  {
151  if( lNode->GetName() == wxT( "compDef" ) )
152  {
153  lNode->GetAttribute( wxT( "Name" ), &propValue );
154 
155  if( propValue == aName )
156  {
157  result = lNode;
158  lNode = nullptr;
159  }
160  }
161 
162  if( lNode )
163  lNode = lNode->GetNext();
164  }
165 
166  return result;
167 }
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:67
XNODE * FindNode(XNODE *aChild, const wxString &aTag)

References PCAD2KICAD::FindNode(), and XNODE::GetNext().

Referenced by DoPCBComponents().

◆ FindLayer()

int PCAD2KICAD::PCB::FindLayer ( const wxString &  aLayerName) const
private

Definition at line 456 of file pcb.cpp.

457 {
458  for( LAYER_NUM i = 0; i < (int)m_layersStackup.GetCount(); ++i )
459  {
460  if( m_layersStackup[i] == aLayerName )
461  return i;
462  }
463 
464  return -1;
465 }
int LAYER_NUM
This can be replaced with int and removed.
Definition: layer_ids.h:41
wxArrayString m_layersStackup
Definition: pcb.h:86

References m_layersStackup.

Referenced by MapLayer().

◆ FindModulePatternDefName()

XNODE * PCAD2KICAD::PCB_FOOTPRINT::FindModulePatternDefName ( XNODE aNode,
const wxString &  aName 
)
inherited

Definition at line 69 of file pcb_footprint.cpp.

70 {
71  XNODE* result, * lNode;
72  wxString propValue1, propValue2;
73 
74  result = nullptr;
75  lNode = FindNode( aNode, wxT( "patternDef" ) );
76 
77  while( lNode )
78  {
79  if( lNode->GetName() == wxT( "patternDef" ) )
80  {
81  lNode->GetAttribute( wxT( "Name" ), &propValue1 );
82  FindNode( lNode,
83  wxT( "originalName" ) )->GetAttribute( wxT( "Name" ), &propValue2 );
84 
85  if( ValidateName( propValue1 ) == aName || ValidateName( propValue2 ) == aName )
86  {
87  result = lNode;
88  lNode = nullptr;
89  }
90  }
91 
92  if( lNode )
93  lNode = lNode->GetNext();
94  }
95 
96  if( result == nullptr )
97  {
98  lNode = FindNode( aNode, wxT( "patternDefExtended" ) ); // New file format
99 
100  while( lNode )
101  {
102  if( lNode->GetName() == wxT( "patternDefExtended" ) )
103  {
104  lNode->GetAttribute( wxT( "Name" ), &propValue1 );
105 
106  if( ValidateName( propValue1 ) == aName )
107  {
108  result = lNode;
109  lNode = nullptr;
110  }
111  }
112 
113  if( lNode )
114  lNode = lNode->GetNext();
115  }
116  }
117 
118  return result;
119 }
wxString ValidateName(const wxString &aName)
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:67
XNODE * FindNode(XNODE *aChild, const wxString &aTag)

References PCAD2KICAD::FindNode(), XNODE::GetNext(), and PCAD2KICAD::ValidateName().

Referenced by DoPCBComponents(), and PCAD2KICAD::PCB_FOOTPRINT::FindPatternMultilayerSection().

◆ FindOutlinePoint()

int PCAD2KICAD::PCB::FindOutlinePoint ( const VERTICES_ARRAY *  aOutline,
wxRealPoint  aPoint 
) const
private

Definition at line 567 of file pcb.cpp.

568 {
569  int i;
570 
571  for( i = 0; i < (int) aOutline->GetCount(); i++ )
572  {
573  if( *((*aOutline)[i]) == aPoint )
574  return i;
575  }
576 
577  return -1;
578 }

Referenced by GetBoardOutline().

◆ Flip()

void PCAD2KICAD::PCB_FOOTPRINT::Flip ( )
overridevirtualinherited

Reimplemented from PCAD2KICAD::PCB_COMPONENT.

Definition at line 623 of file pcb_footprint.cpp.

624 {
625  int i;
626 
627  if( m_Mirror == 1 )
628  {
630 
631  for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
632  {
633  if( m_FootprintItems[i]->m_objType == wxT( 'L' ) || // lines
634  m_FootprintItems[i]->m_objType == wxT( 'A' ) || // arcs
635  m_FootprintItems[i]->m_objType == wxT( 'Z' ) || // polygons
636  m_FootprintItems[i]->m_objType == wxT( 'P' ) || // pads
637  m_FootprintItems[i]->m_objType == wxT( 'V' ) ) // vias
638  {
639  m_FootprintItems[i]->Flip();
640  }
641  }
642  }
643 }
PCB_COMPONENTS_ARRAY m_FootprintItems
Definition: pcb_footprint.h:64

References PCAD2KICAD::PCB_FOOTPRINT::m_FootprintItems, PCAD2KICAD::PCB_FOOTPRINT::m_Mirror, PCAD2KICAD::PCB_COMPONENT::m_objType, and PCAD2KICAD::PCB_COMPONENT::m_rotation.

Referenced by ParseBoard().

◆ GetBoardOutline()

void PCAD2KICAD::PCB::GetBoardOutline ( wxXmlDocument *  aXmlDoc,
const wxString &  aActualConversion 
)
private

Definition at line 596 of file pcb.cpp.

597 {
598  XNODE* iNode, *lNode, *pNode;
599  long PCadLayer = 0;
600  int x, y, i, j, targetInd;
601  wxRealPoint* xchgPoint;
602  double minDistance, distance;
603 
604  iNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
605 
606  if( iNode )
607  {
608  // COMPONENTS AND OBJECTS
609  iNode = iNode->GetChildren();
610 
611  while( iNode )
612  {
613  // objects
614  if( iNode->GetName() == wxT( "layerContents" ) )
615  {
616  if( FindNode( iNode, wxT( "layerNumRef" ) ) )
617  FindNode( iNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &PCadLayer );
618 
619  if( GetKiCadLayer( PCadLayer ) == Edge_Cuts )
620  {
621  lNode = iNode->GetChildren();
622 
623  while( lNode )
624  {
625  if( lNode->GetName() == wxT( "line" ) )
626  {
627  pNode = FindNode( lNode, wxT( "pt" ) );
628 
629  if( pNode )
630  {
631  SetPosition( pNode->GetNodeContent(), m_DefaultMeasurementUnit,
632  &x, &y, aActualConversion );
633 
634  if( FindOutlinePoint( &m_BoardOutline, wxRealPoint( x, y) ) == -1 )
635  m_BoardOutline.Add( new wxRealPoint( x, y ) );
636  }
637 
638  if( pNode )
639  pNode = pNode->GetNext();
640 
641  if( pNode )
642  {
643  SetPosition( pNode->GetNodeContent(), m_DefaultMeasurementUnit,
644  &x, &y, aActualConversion );
645 
646  if( FindOutlinePoint( &m_BoardOutline, wxRealPoint( x, y) ) == -1 )
647  m_BoardOutline.Add( new wxRealPoint( x, y ) );
648  }
649  }
650 
651  lNode = lNode->GetNext();
652  }
653 
654  //m_boardOutline.Sort( cmpFunc );
655  // sort vertices according to the distances between them
656  if( m_BoardOutline.GetCount() > 3 )
657  {
658  for( i = 0; i < (int) m_BoardOutline.GetCount() - 1; i++ )
659  {
660  minDistance = GetDistance( m_BoardOutline[i], m_BoardOutline[ i + 1] );
661  targetInd = i + 1;
662 
663  for( j = i + 2; j < (int) m_BoardOutline.GetCount(); j++ )
664  {
666 
667  if( distance < minDistance )
668  {
669  minDistance = distance;
670  targetInd = j;
671  }
672  }
673 
674  xchgPoint = m_BoardOutline[ i + 1];
675  m_BoardOutline[ i + 1] = m_BoardOutline[targetInd];
676  m_BoardOutline[targetInd] = xchgPoint;
677  }
678  }
679 
680  break;
681  }
682  }
683 
684  iNode = iNode->GetNext();
685  }
686  }
687 }
int FindOutlinePoint(const VERTICES_ARRAY *aOutline, wxRealPoint aPoint) const
Definition: pcb.cpp:567
wxString m_DefaultMeasurementUnit
Definition: pcb.h:64
XNODE * GetChildren() const
Definition: xnode.h:62
VERTICES_ARRAY m_BoardOutline
Definition: pcb_footprint.h:66
double GetDistance(const wxRealPoint *aPoint1, const wxRealPoint *aPoint2) const
Definition: pcb.cpp:590
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
PCB_LAYER_ID GetKiCadLayer() const
Definition: pcb_component.h:56
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:67
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)

References distance(), Edge_Cuts, PCAD2KICAD::FindNode(), FindOutlinePoint(), XNODE::GetChildren(), GetDistance(), PCAD2KICAD::PCB_COMPONENT::GetKiCadLayer(), XNODE::GetNext(), PCAD2KICAD::PCB_FOOTPRINT::m_BoardOutline, m_DefaultMeasurementUnit, and PCAD2KICAD::SetPosition().

Referenced by ParseBoard().

◆ GetDistance()

double PCAD2KICAD::PCB::GetDistance ( const wxRealPoint *  aPoint1,
const wxRealPoint *  aPoint2 
) const
private

Definition at line 590 of file pcb.cpp.

591 {
592  return sqrt( ( aPoint1->x - aPoint2->x ) * ( aPoint1->x - aPoint2->x ) +
593  ( aPoint1->y - aPoint2->y ) * ( aPoint1->y - aPoint2->y ) );
594 }

Referenced by GetBoardOutline().

◆ GetKiCadLayer() [1/2]

PCB_LAYER_ID PCAD2KICAD::PCB::GetKiCadLayer ( int  aPCadLayer) const
overridevirtual

Implements PCAD2KICAD::PCB_CALLBACKS.

Definition at line 46 of file pcb.cpp.

47 {
48  auto it = m_LayersMap.find( aPCadLayer );
49 
50  if( it == m_LayersMap.end() )
51  THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
52 
53  return it->second.KiCadLayer;
54 }
std::map< int, TLAYER > m_LayersMap
Definition: pcb.h:65
#define _(s)
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), m_LayersMap, and THROW_IO_ERROR.

◆ GetKiCadLayer() [2/2]

◆ GetLayerNetNameRef()

wxString PCAD2KICAD::PCB::GetLayerNetNameRef ( int  aPCadLayer) const
overridevirtual

Implements PCAD2KICAD::PCB_CALLBACKS.

Definition at line 68 of file pcb.cpp.

69 {
70  auto it = m_LayersMap.find( aPCadLayer );
71 
72  if( it == m_LayersMap.end() )
73  THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
74 
75  return it->second.netNameRef;
76 }
std::map< int, TLAYER > m_LayersMap
Definition: pcb.h:65
#define _(s)
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), m_LayersMap, and THROW_IO_ERROR.

◆ GetLayerType()

LAYER_TYPE_T PCAD2KICAD::PCB::GetLayerType ( int  aPCadLayer) const
overridevirtual

Implements PCAD2KICAD::PCB_CALLBACKS.

Definition at line 57 of file pcb.cpp.

58 {
59  auto it = m_LayersMap.find( aPCadLayer );
60 
61  if( it == m_LayersMap.end() )
62  THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
63 
64  return it->second.layerType;
65 }
std::map< int, TLAYER > m_LayersMap
Definition: pcb.h:65
#define _(s)
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), m_LayersMap, and THROW_IO_ERROR.

◆ GetNetCode()

int PCAD2KICAD::PCB::GetNetCode ( const wxString &  aNetName) const
overridevirtual

Implements PCAD2KICAD::PCB_CALLBACKS.

Definition at line 125 of file pcb.cpp.

126 {
127  const PCB_NET* net;
128 
129  for( int i = 0; i < (int) m_PcbNetlist.GetCount(); i++ )
130  {
131  net = m_PcbNetlist[i];
132 
133  if( net->m_Name == aNetName )
134  {
135  return net->m_NetCode;
136  }
137  }
138 
139  return 0;
140 }
PCB_NETS_ARRAY m_PcbNetlist
Definition: pcb.h:63

References PCAD2KICAD::PCB_NET::m_Name, PCAD2KICAD::PCB_NET::m_NetCode, and m_PcbNetlist.

◆ MapLayer()

void PCAD2KICAD::PCB::MapLayer ( XNODE aNode)
private

Definition at line 468 of file pcb.cpp.

469 {
470  wxString lName, layerType;
471  PCB_LAYER_ID KiCadLayer;
472  long num = 0;
473 
474  aNode->GetAttribute( wxT( "Name" ), &lName );
475  lName = lName.MakeUpper();
476 
477  if( lName == wxT( "TOP ASSY" ) )
478  {
479  KiCadLayer = F_Fab;
480  }
481  else if( lName == wxT( "TOP SILK" ) )
482  {
483  KiCadLayer = F_SilkS;
484  }
485  else if( lName == wxT( "TOP PASTE" ) )
486  {
487  KiCadLayer = F_Paste;
488  }
489  else if( lName == wxT( "TOP MASK" ) )
490  {
491  KiCadLayer = F_Mask;
492  }
493  else if( lName == wxT( "TOP" ) )
494  {
495  KiCadLayer = F_Cu;
496  }
497  else if( lName == wxT( "BOTTOM" ) )
498  {
499  KiCadLayer = B_Cu;
500  }
501  else if( lName == wxT( "BOT MASK" ) )
502  {
503  KiCadLayer = B_Mask;
504  }
505  else if( lName == wxT( "BOT PASTE" ) )
506  {
507  KiCadLayer = B_Paste;
508  }
509  else if( lName == wxT( "BOT SILK" ) )
510  {
511  KiCadLayer = B_SilkS;
512  }
513  else if( lName == wxT( "BOT ASSY" ) )
514  {
515  KiCadLayer = B_Fab;
516  }
517  else if( lName == wxT( "BOARD" ) )
518  {
519  KiCadLayer = Edge_Cuts;
520  }
521  else
522  {
523  int layernum = FindLayer( lName );
524 
525  if( layernum == -1 )
526  KiCadLayer = Dwgs_User; // default
527  else
528 #if 0 // was:
529  KiCadLayer = FIRST_COPPER_LAYER + m_layersStackup.GetCount() - 1 - layernum;
530 #else
531  KiCadLayer = ToLAYER_ID( layernum );
532 #endif
533  }
534 
535  if( FindNode( aNode, wxT( "layerNum" ) ) )
536  FindNode( aNode, wxT( "layerNum" ) )->GetNodeContent().ToLong( &num );
537 
538  if( num < 0 )
539  THROW_IO_ERROR( wxString::Format( wxT( "layerNum = %ld is out of range" ), num ) );
540 
541  TLAYER newlayer;
542  newlayer.KiCadLayer = KiCadLayer;
543 
544  if( FindNode( aNode, wxT( "layerType" ) ) )
545  {
546  layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim( false );
547 
548  if( layerType == wxT( "NonSignal" ) )
549  newlayer.layerType = LAYER_TYPE_NONSIGNAL;
550 
551  if( layerType == wxT( "Signal" ) )
552  newlayer.layerType = LAYER_TYPE_SIGNAL;
553 
554  if( layerType == wxT( "Plane" ) )
555  newlayer.layerType = LAYER_TYPE_PLANE;
556  }
557 
558  m_LayersMap.insert( std::make_pair( num, newlayer ) );
559 
560  if( FindNode( aNode, wxT( "netNameRef" ) ) )
561  {
562  FindNode( aNode, wxT( "netNameRef" ) )->GetAttribute( wxT( "Name" ),
563  &m_LayersMap[(int) num].netNameRef );
564  }
565 }
PCB_LAYER_ID KiCadLayer
Definition: pcb_callbacks.h:46
int FindLayer(const wxString &aLayerName) const
Definition: pcb.cpp:456
std::map< int, TLAYER > m_LayersMap
Definition: pcb.h:65
wxArrayString m_layersStackup
Definition: pcb.h:86
LAYER_TYPE_T layerType
Definition: pcb_callbacks.h:47
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
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Definition: layer_ids.h:71
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
#define FIRST_COPPER_LAYER
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905

References B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, Dwgs_User, Edge_Cuts, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, FindLayer(), PCAD2KICAD::FindNode(), FIRST_COPPER_LAYER, Format(), TLAYER::KiCadLayer, LAYER_TYPE_NONSIGNAL, LAYER_TYPE_PLANE, LAYER_TYPE_SIGNAL, TLAYER::layerType, m_LayersMap, m_layersStackup, THROW_IO_ERROR, and ToLAYER_ID().

Referenced by ParseBoard().

◆ Parse()

void PCAD2KICAD::PCB_FOOTPRINT::Parse ( XNODE aNode,
wxStatusBar *  aStatusBar,
const wxString &  aDefaultMeasurementUnit,
const wxString &  aActualConversion 
)
virtualinherited

Definition at line 388 of file pcb_footprint.cpp.

391 {
392  XNODE* lNode, * tNode, * mNode;
393  PCB_PAD* pad;
394  PCB_VIA* via;
395  wxString propValue, str;
396 
397  FindNode( aNode, wxT( "originalName" ) )->GetAttribute( wxT( "Name" ), &propValue );
398  propValue.Trim( false );
399  m_name.text = propValue;
400 
401  // aStatusBar->SetStatusText( wxT( "Creating Component : " ) + m_name.text );
402  lNode = aNode;
404 
405  if( lNode )
406  {
407  tNode = lNode;
408  tNode = tNode->GetChildren();
409 
410  while( tNode )
411  {
412  if( tNode->GetName() == wxT( "pad" ) )
413  {
414  pad = new PCB_PAD( m_callbacks, m_board );
415  pad->Parse( tNode, aDefaultMeasurementUnit, aActualConversion );
416  m_FootprintItems.Add( pad );
417  }
418 
419  if( tNode->GetName() == wxT( "via" ) )
420  {
421  via = new PCB_VIA( m_callbacks, m_board );
422  via->Parse( tNode, aDefaultMeasurementUnit, aActualConversion );
423  m_FootprintItems.Add( via );
424  }
425 
426  tNode = tNode->GetNext();
427  }
428 
429  lNode = lNode->GetParent();
430  }
431 
432  if( lNode )
433  lNode = FindNode( lNode, wxT( "layerContents" ) );
434 
435  while( lNode )
436  {
437  if( lNode->GetName() == wxT( "layerContents" ) )
438  DoLayerContentsObjects( lNode, this, &m_FootprintItems, aStatusBar,
439  aDefaultMeasurementUnit, aActualConversion );
440 
441  lNode = lNode->GetNext();
442  }
443 
444  // map pins
445  lNode = FindPinMap( aNode );
446 
447  if( lNode )
448  {
449  mNode = lNode->GetChildren();
450 
451  while( mNode )
452  {
453  if( mNode->GetName() == wxT( "padNum" ) )
454  {
455  str = mNode->GetNodeContent();
456  mNode = mNode->GetNext();
457 
458  if( !mNode )
459  break;
460 
461  mNode->GetAttribute( wxT( "Name" ), &propValue );
462  SetName( str, propValue );
463  mNode = mNode->GetNext();
464  }
465  else
466  {
467  mNode = mNode->GetNext();
468 
469  if( !mNode )
470  break;
471 
472  mNode = mNode->GetNext();
473  }
474  }
475  }
476 }
void DoLayerContentsObjects(XNODE *aNode, PCB_FOOTPRINT *aFootprint, PCB_COMPONENTS_ARRAY *aList, wxStatusBar *aStatusBar, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
XNODE * FindPatternMultilayerSection(XNODE *aNode, wxString *aPatGraphRefName)
void SetName(const wxString &aPin, const wxString &aName)
XNODE * GetChildren() const
Definition: xnode.h:62
XNODE * GetParent() const
Definition: xnode.h:72
Hold an XML or S-expression element.
Definition: xnode.h:43
PCB_COMPONENTS_ARRAY m_FootprintItems
Definition: pcb_footprint.h:64
XNODE * GetNext() const
Definition: xnode.h:67
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
PCB_CALLBACKS * m_callbacks
Definition: pcb_component.h:78
XNODE * FindPinMap(XNODE *aNode)

References PCAD2KICAD::PCB_FOOTPRINT::DoLayerContentsObjects(), PCAD2KICAD::FindNode(), PCAD2KICAD::PCB_FOOTPRINT::FindPatternMultilayerSection(), PCAD2KICAD::FindPinMap(), XNODE::GetChildren(), XNODE::GetNext(), XNODE::GetParent(), PCAD2KICAD::PCB_COMPONENT::m_board, PCAD2KICAD::PCB_COMPONENT::m_callbacks, PCAD2KICAD::PCB_FOOTPRINT::m_FootprintItems, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_patGraphRefName, pad, PCAD2KICAD::PCB_FOOTPRINT::SetName(), PCAD2KICAD::TTEXTVALUE::text, and via.

Referenced by DoPCBComponents(), and ParseBoard().

◆ ParseBoard()

void PCAD2KICAD::PCB::ParseBoard ( wxStatusBar *  aStatusBar,
wxXmlDocument *  aXmlDoc,
const wxString &  aActualConversion 
)

Definition at line 690 of file pcb.cpp.

692 {
693  XNODE* aNode;//, *aaNode;
694  PCB_NET* net;
695  PCB_COMPONENT* comp;
696  PCB_FOOTPRINT* footprint;
697  wxString compRef, pinRef, layerName, layerType;
698  int i, j, netCode;
699 
700  // Default measurement units
701  aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "asciiHeader" ) );
702 
703  if( aNode )
704  {
705  aNode = FindNode( aNode, wxT( "fileUnits" ) );
706 
707  if( aNode )
708  {
709  m_DefaultMeasurementUnit = aNode->GetNodeContent().Lower();
710  m_DefaultMeasurementUnit.Trim( true );
711  m_DefaultMeasurementUnit.Trim( false );
712  }
713  }
714 
715  // Determine layers stackup
716  aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
717 
718  /*if( aNode )
719  {
720  aNode = FindNode( aNode, wxT( "layersStackup" ) );
721 
722  if( aNode )
723  {
724  aNode = FindNode( aNode, wxT( "layerStackupData" ) );
725 
726  while( aNode )
727  {
728  if( aNode->GetName() == wxT( "layerStackupData" ) )
729  {
730  aaNode = FindNode( aNode, wxT( "layerStackupName" ) );
731 
732  if( aaNode ) {
733  aaNode->GetAttribute( wxT( "Name" ), &layerName );
734  layerName = layerName.MakeUpper();
735  m_layersStackup.Add( layerName );
736  }
737  }
738 
739  aNode = aNode->GetNext();
740  }
741  }
742  }*/
743 
744  if( aNode )
745  {
746  aNode = FindNode( aNode, wxT( "layerDef" ) );
747 
748  while( aNode )
749  {
750  if( aNode->GetName() == wxT( "layerDef" ) )
751  {
752  if( FindNode( aNode, wxT( "layerType" ) ) )
753  {
754  layerType = FindNode( aNode,
755  wxT( "layerType" ) )->GetNodeContent().Trim( false );
756 
757  if( layerType == wxT( "Signal" ) || layerType == wxT( "Plane" ) )
758  {
759  aNode->GetAttribute( wxT( "Name" ), &layerName );
760  layerName = layerName.MakeUpper();
761  m_layersStackup.Add( layerName );
762 
763  if( m_layersStackup.size() > 32 )
764  THROW_IO_ERROR( _( "KiCad only supports 32 signal layers." ) );
765  }
766  }
767  }
768 
769  aNode = aNode->GetNext();
770  }
771  }
772 
773  // Layers mapping
774  aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
775 
776  if( aNode )
777  {
778  aNode = FindNode( aNode, wxT( "layerDef" ) );
779 
780  while( aNode )
781  {
782  if( aNode->GetName() == wxT( "layerDef" ) )
783  MapLayer( aNode );
784 
785  aNode = aNode->GetNext();
786  }
787  }
788 
789  GetBoardOutline( aXmlDoc, aActualConversion );
790 
791  // NETLIST
792  // aStatusBar->SetStatusText( wxT( "Loading NETLIST " ) );
793 
794  aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "netlist" ) );
795 
796  if( aNode )
797  {
798  aNode = FindNode( aNode, wxT( "net" ) );
799 
800  netCode = 1;
801 
802  while( aNode )
803  {
804  net = new PCB_NET( netCode++ );
805  net->Parse( aNode );
806  m_PcbNetlist.Add( net );
807 
808  aNode = aNode->GetNext();
809  }
810  }
811 
812  // BOARD FILE
813  // aStatusBar->SetStatusText( wxT( "Loading BOARD DEFINITION " ) );
814 
815  aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
816 
817  if( aNode )
818  {
819  // COMPONENTS AND OBJECTS
820  aNode = aNode->GetChildren();
821 
822  while( aNode )
823  {
824  // Components/footprints
825  if( aNode->GetName() == wxT( "multiLayer" ) )
826  DoPCBComponents( aNode, aXmlDoc, aActualConversion, aStatusBar );
827 
828  // objects
829  if( aNode->GetName() == wxT( "layerContents" ) )
830  DoLayerContentsObjects( aNode, nullptr, &m_PcbComponents, aStatusBar,
831  m_DefaultMeasurementUnit, aActualConversion );
832 
833  aNode = aNode->GetNext();
834  }
835 
836  // POSTPROCESS -- SET NETLIST REFERENCES
837  // aStatusBar->SetStatusText( wxT( "Processing NETLIST " ) );
838 
839  for( i = 0; i < (int) m_PcbNetlist.GetCount(); i++ )
840  {
841  net = m_PcbNetlist[i];
842 
843  for( j = 0; j < (int) net->m_NetNodes.GetCount(); j++ )
844  {
845  compRef = net->m_NetNodes[j]->m_CompRef;
846  compRef.Trim( false );
847  compRef.Trim( true );
848  pinRef = net->m_NetNodes[j]->m_PinRef;
849  pinRef.Trim( false );
850  pinRef.Trim( true );
851  ConnectPinToNet( compRef, pinRef, net->m_Name );
852  }
853  }
854 
855  // POSTPROCESS -- FLIP COMPONENTS
856  for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
857  {
858  if( m_PcbComponents[i]->m_objType == wxT( 'M' ) )
859  ( (PCB_FOOTPRINT*) m_PcbComponents[i] )->Flip();
860  }
861 
862  // POSTPROCESS -- SET/OPTIMIZE NEW PCB POSITION
863  // aStatusBar->SetStatusText( wxT( "Optimizing BOARD POSITION " ) );
864 
865  m_SizeX = 10000000;
866  m_SizeY = 0;
867 
868  for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
869  {
870  comp = m_PcbComponents[i];
871 
872  if( comp->m_positionY < m_SizeY )
873  m_SizeY = comp->m_positionY; // max Y
874 
875  if( comp->m_positionX < m_SizeX && comp->m_positionX > 0 )
876  m_SizeX = comp->m_positionX; // Min X
877  }
878 
879  m_SizeY -= 10000;
880  m_SizeX -= 10000;
881  // aStatusBar->SetStatusText( wxT( " POSITIONING POSTPROCESS " ) );
882 
883  for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
885 
886  m_SizeX = 0;
887  m_SizeY = 0;
888 
889  for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
890  {
891  comp = m_PcbComponents[i];
892 
893  if( comp->m_positionY < m_SizeY )
894  m_SizeY = comp->m_positionY; // max Y
895 
896  if( comp->m_positionX > m_SizeX )
897  m_SizeX = comp->m_positionX; // Min X
898  }
899 
900  // SHEET SIZE CALCULATION
901  m_SizeY = -m_SizeY; // it is in absolute units
902  m_SizeX += 10000;
903  m_SizeY += 10000;
904 
905  // A4 is minimum $Descr A4 11700 8267
906  if( m_SizeX < 11700 )
907  m_SizeX = 11700;
908 
909  if( m_SizeY < 8267 )
910  m_SizeY = 8267;
911  }
912  else
913  {
914  // LIBRARY FILE
915  // aStatusBar->SetStatusText( wxT( "Processing LIBRARY FILE " ) );
916 
917  aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
918 
919  if( aNode )
920  {
921  aNode = FindNode( aNode, wxT( "compDef" ) );
922 
923  while( aNode )
924  {
925  // aStatusBar->SetStatusText( wxT( "Processing COMPONENTS " ) );
926 
927  if( aNode->GetName() == wxT( "compDef" ) )
928  {
929  footprint = new PCB_FOOTPRINT( this, m_board );
930  footprint->Parse( aNode, aStatusBar, m_DefaultMeasurementUnit,
931  aActualConversion );
932  m_PcbComponents.Add( footprint );
933  }
934 
935  aNode = aNode->GetNext();
936  }
937  }
938  }
939 }
int m_SizeX
Definition: pcb.h:66
void DoLayerContentsObjects(XNODE *aNode, PCB_FOOTPRINT *aFootprint, PCB_COMPONENTS_ARRAY *aList, wxStatusBar *aStatusBar, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
PCB_COMPONENTS_ARRAY m_PcbComponents
Definition: pcb.h:62
PCB_NETS_ARRAY m_PcbNetlist
Definition: pcb.h:63
virtual void SetPosOffset(int aX_offs, int aY_offs)
virtual void Flip() override
void ConnectPinToNet(const wxString &aCr, const wxString &aPr, const wxString &aNetName)
Definition: pcb.cpp:428
wxString m_DefaultMeasurementUnit
Definition: pcb.h:64
XNODE * GetChildren() const
Definition: xnode.h:62
wxArrayString m_layersStackup
Definition: pcb.h:86
void DoPCBComponents(XNODE *aNode, wxXmlDocument *aXmlDoc, const wxString &aActualConversion, wxStatusBar *aStatusBar)
Definition: pcb.cpp:239
int m_SizeY
Definition: pcb.h:67
#define _(s)
void GetBoardOutline(wxXmlDocument *aXmlDoc, const wxString &aActualConversion)
Definition: pcb.cpp:596
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:67
PCB_FOOTPRINT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
void MapLayer(XNODE *aNode)
Definition: pcb.cpp:468
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
PCB_COMPONENT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, ConnectPinToNet(), PCAD2KICAD::PCB_FOOTPRINT::DoLayerContentsObjects(), DoPCBComponents(), PCAD2KICAD::FindNode(), PCAD2KICAD::PCB_FOOTPRINT::Flip(), GetBoardOutline(), XNODE::GetChildren(), XNODE::GetNext(), PCAD2KICAD::PCB_COMPONENT::m_board, m_DefaultMeasurementUnit, m_layersStackup, PCAD2KICAD::PCB_NET::m_Name, PCAD2KICAD::PCB_NET::m_NetNodes, PCAD2KICAD::PCB_COMPONENT::m_objType, m_PcbComponents, m_PcbNetlist, PCAD2KICAD::PCB_COMPONENT::m_positionX, PCAD2KICAD::PCB_COMPONENT::m_positionY, m_SizeX, m_SizeY, MapLayer(), PCAD2KICAD::PCB_NET::Parse(), PCAD2KICAD::PCB_FOOTPRINT::Parse(), PCAD2KICAD::PCB_FOOTPRINT::PCB_FOOTPRINT(), PCAD2KICAD::PCB_COMPONENT::SetPosOffset(), and THROW_IO_ERROR.

Referenced by PCAD_PLUGIN::Load().

◆ SetName()

void PCAD2KICAD::PCB_FOOTPRINT::SetName ( const wxString &  aPin,
const wxString &  aName 
)
inherited

Definition at line 370 of file pcb_footprint.cpp.

371 {
372  int i;
373  long num;
374 
375  aPin.ToLong( &num );
376 
377  for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
378  {
379  if( m_FootprintItems[i]->m_objType == wxT( 'P' ) )
380  {
381  if( ( (PCB_PAD*) m_FootprintItems[i] )->m_Number == num )
382  ( (PCB_PAD*) m_FootprintItems[i] )->m_name.text = aName;
383  }
384  }
385 }
PCB_COMPONENTS_ARRAY m_FootprintItems
Definition: pcb_footprint.h:64

References PCAD2KICAD::PCB_FOOTPRINT::m_FootprintItems, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_objType, and PCAD2KICAD::TTEXTVALUE::text.

Referenced by DoPCBComponents(), and PCAD2KICAD::PCB_FOOTPRINT::Parse().

◆ SetPosOffset()

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

◆ SetTextProperty()

void PCAD2KICAD::PCB::SetTextProperty ( XNODE aNode,
TTEXTVALUE aTextValue,
const wxString &  aPatGraphRefName,
const wxString &  aXmlName,
const wxString &  aActualConversion 
)
private

Definition at line 170 of file pcb.cpp.

172 {
173  XNODE* tNode, * t1Node;
174  wxString n, nnew, pn, propValue, str;
175 
176  // aNode is pattern now
177  tNode = aNode;
178  t1Node = aNode;
179  n = aXmlName;
180 
181  // new file format version
182  if( FindNode( tNode, wxT( "patternGraphicsNameRef" ) ) )
183  {
184  FindNode( tNode,
185  wxT( "patternGraphicsNameRef" ) )->GetAttribute( wxT( "Name" ),
186  &pn );
187  pn.Trim( false );
188  pn.Trim( true );
189  tNode = FindNode( tNode, wxT( "patternGraphicsRef" ) );
190 
191  while( tNode )
192  {
193  if( tNode->GetName() == wxT( "patternGraphicsRef" ) )
194  {
195  if( FindNode( tNode, wxT( "patternGraphicsNameRef" ) ) )
196  {
197  FindNode( tNode,
198  wxT( "patternGraphicsNameRef" ) )->GetAttribute( wxT( "Name" ),
199  &propValue );
200 
201  if( propValue == pn )
202  {
203  t1Node = tNode; // find correct section with same name.
204  str = aTextValue->text;
205  str.Trim( false );
206  str.Trim( true );
207  nnew = n; // new file version
208  n = n + wxT( ' ' ) + str; // old file version
209  tNode = nullptr;
210  }
211  }
212  }
213 
214  if( tNode )
215  tNode = tNode->GetNext();
216  }
217  }
218 
219  // old version and compatible for both from this point
220  tNode = FindNode( t1Node, wxT( "attr" ) );
221 
222  while( tNode )
223  {
224  tNode->GetAttribute( wxT( "Name" ), &propValue );
225  propValue.Trim( false );
226  propValue.Trim( true );
227 
228  if( propValue == n || propValue == nnew )
229  break;
230 
231  tNode = tNode->GetNext();
232  }
233 
234  if( tNode )
235  SetTextParameters( tNode, aTextValue, m_DefaultMeasurementUnit, aActualConversion );
236 }
wxString m_DefaultMeasurementUnit
Definition: pcb.h:64
void SetTextParameters(XNODE *aNode, TTEXTVALUE *aTextValue, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:67
XNODE * FindNode(XNODE *aChild, const wxString &aTag)

References PCAD2KICAD::FindNode(), XNODE::GetNext(), m_DefaultMeasurementUnit, PCAD2KICAD::SetTextParameters(), and PCAD2KICAD::TTEXTVALUE::text.

Referenced by DoPCBComponents().

Member Data Documentation

◆ m_board

◆ m_BoardOutline

VERTICES_ARRAY PCAD2KICAD::PCB_FOOTPRINT::m_BoardOutline
inherited

◆ m_callbacks

◆ m_compRef

wxString PCAD2KICAD::PCB_COMPONENT::m_compRef
inherited

◆ m_DefaultMeasurementUnit

wxString PCAD2KICAD::PCB::m_DefaultMeasurementUnit

Definition at line 64 of file pcb.h.

Referenced by DoPCBComponents(), GetBoardOutline(), ParseBoard(), PCB(), and SetTextProperty().

◆ m_FootprintItems

◆ m_KiCadLayer

◆ m_LayersMap

std::map<int, TLAYER> PCAD2KICAD::PCB::m_LayersMap

Definition at line 65 of file pcb.h.

Referenced by GetKiCadLayer(), GetLayerNetNameRef(), GetLayerType(), MapLayer(), and PCB().

◆ m_layersStackup

wxArrayString PCAD2KICAD::PCB::m_layersStackup
private

Definition at line 86 of file pcb.h.

Referenced by AddToBoard(), FindLayer(), MapLayer(), and ParseBoard().

◆ m_Mirror

int PCAD2KICAD::PCB_FOOTPRINT::m_Mirror
inherited

◆ m_name

◆ m_net

◆ m_netCode

◆ m_objType

◆ m_patGraphRefName

wxString PCAD2KICAD::PCB_COMPONENT::m_patGraphRefName
inherited

◆ m_PCadLayer

◆ m_PcbComponents

PCB_COMPONENTS_ARRAY PCAD2KICAD::PCB::m_PcbComponents

Definition at line 62 of file pcb.h.

Referenced by AddToBoard(), ConnectPinToNet(), DoPCBComponents(), ParseBoard(), and ~PCB().

◆ m_PcbNetlist

PCB_NETS_ARRAY PCAD2KICAD::PCB::m_PcbNetlist

Definition at line 63 of file pcb.h.

Referenced by AddToBoard(), GetNetCode(), ParseBoard(), and ~PCB().

◆ m_positionX

◆ m_positionY

◆ m_rotation

◆ m_SizeX

int PCAD2KICAD::PCB::m_SizeX

Definition at line 66 of file pcb.h.

Referenced by ParseBoard(), and PCB().

◆ m_SizeY

int PCAD2KICAD::PCB::m_SizeY

Definition at line 67 of file pcb.h.

Referenced by ParseBoard(), and PCB().

◆ 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.

◆ m_Value

TTEXTVALUE PCAD2KICAD::PCB_FOOTPRINT::m_Value
inherited

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