KiCad PCB EDA Suite
PCAD2KICAD::PCB Class Reference

#include <pcb.h>

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

Public Member Functions

 PCB (BOARD *aBoard)
 
 ~PCB ()
 
PCB_LAYER_ID GetKiCadLayer (int aPCadLayer) override
 
LAYER_TYPE_T GetLayerType (int aPCadLayer) override
 
wxString GetLayerNetNameRef (int aPCadLayer) override
 
int GetNetCode (wxString aNetName) override
 
void ParseBoard (wxStatusBar *aStatusBar, wxXmlDocument *aXmlDoc, const wxString &aActualConversion)
 
void AddToBoard () override
 
XNODEFindModulePatternDefName (XNODE *aNode, const wxString &aName)
 
void DoLayerContentsObjects (XNODE *aNode, PCB_MODULE *aPCBModule, 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 AddToModule (MODULE *aModule)
 
PCB_LAYER_ID GetKiCadLayer ()
 

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_moduleObjects
 
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)
 
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)
 
void MapLayer (XNODE *aNode)
 
int FindOutlinePoint (VERTICES_ARRAY *aOutline, wxRealPoint aPoint)
 
double GetDistance (wxRealPoint *aPoint1, wxRealPoint *aPoint2)
 
void GetBoardOutline (wxXmlDocument *aXmlDoc, const wxString &aActualConversion)
 

Private Attributes

wxArrayString m_layersStackup
 

Detailed Description

Definition at line 42 of file pcb.h.

Constructor & Destructor Documentation

◆ PCB()

PCAD2KICAD::PCB::PCB ( BOARD aBoard)

Definition at line 80 of file pcb.cpp.

80  : PCB_MODULE( 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 }
wxString netNameRef
Definition: pcb_callbacks.h:47
std::map< int, TLAYER > m_layersMap
Definition: pcb.h:48
int m_sizeX
Definition: pcb.h:49
int m_sizeY
Definition: pcb.h:50
PCB_MODULE(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_module.cpp:43
PCB_LAYER_ID KiCadLayer
Definition: pcb_callbacks.h:45
LAYER_TYPE_T layerType
Definition: pcb_callbacks.h:46
wxString m_defaultMeasurementUnit
Definition: pcb.h:47

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_NETS_ARRAY m_pcbNetlist
Definition: pcb.h:46
PCB_COMPONENTS_ARRAY m_pcbComponents
Definition: pcb.h:45

References m_pcbComponents, and m_pcbNetlist.

Member Function Documentation

◆ AddToBoard()

void PCAD2KICAD::PCB::AddToBoard ( )
overridevirtual

Implements PCAD2KICAD::PCB_COMPONENT.

Definition at line 932 of file pcb.cpp.

933 {
934  int i;
935  PCB_NET* net;
936 
938 
939  for( i = 0; i < (int) m_pcbNetlist.GetCount(); i++ )
940  {
941  net = m_pcbNetlist[i];
942 
943  m_board->Add( new NETINFO_ITEM( m_board, net->m_name, net->m_netCode ) );
944  }
945 
946  for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
947  {
948  m_pcbComponents[i]->AddToBoard();
949  }
950 }
PCB_NETS_ARRAY m_pcbNetlist
Definition: pcb.h:46
void SetCopperLayerCount(int aCount)
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
wxArrayString m_layersStackup
Definition: pcb.h:67
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
PCB_COMPONENTS_ARRAY m_pcbComponents
Definition: pcb.h:45

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().

◆ AddToModule()

void PCAD2KICAD::PCB_COMPONENT::AddToModule ( MODULE aModule)
virtualinherited

◆ ConnectPinToNet()

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

Definition at line 430 of file pcb.cpp.

433 {
434  PCB_MODULE* module;
435  PCB_PAD* cp;
436  int i, j;
437 
438  for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
439  {
440  module = (PCB_MODULE*) m_pcbComponents[i];
441 
442  if( module->m_objType == wxT( 'M' ) && module->m_name.text == aCompRef )
443  {
444  for( j = 0; j < (int) module->m_moduleObjects.GetCount(); j++ )
445  {
446  if( module->m_moduleObjects[j]->m_objType == wxT( 'P' ) )
447  {
448  cp = (PCB_PAD*) module->m_moduleObjects[j];
449 
450  if( cp->m_name.text == aPinRef )
451  cp->m_net = aNetName;
452  }
453  }
454  }
455  }
456 }
PCB_MODULE(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_module.cpp:43
PCB_COMPONENTS_ARRAY m_pcbComponents
Definition: pcb.h:45

References PCAD2KICAD::PCB_MODULE::m_moduleObjects, 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_MODULE::DoLayerContentsObjects ( XNODE aNode,
PCB_MODULE aPCBModule,
PCB_COMPONENTS_ARRAY *  aList,
wxStatusBar *  aStatusBar,
const wxString &  aDefaultMeasurementUnit,
const wxString &  aActualConversion 
)
inherited

Definition at line 210 of file pcb_module.cpp.

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

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_MODULE::m_boardOutline, PCAD2KICAD::PCB_COMPONENT::m_callbacks, PCAD2KICAD::PCB_POLYGON::m_cutouts, PCAD2KICAD::PCB_COMPONENT::m_name, NULL, PCAD2KICAD::PCB_PLANE::Parse(), PCAD2KICAD::PCB_COPPER_POUR::Parse(), PCAD2KICAD::PCB_CUTOUT::Parse(), PCAD2KICAD::PCB_TEXT::Parse(), PCAD2KICAD::PCB_ARC::Parse(), PCAD2KICAD::PCB_LINE::Parse(), PCAD2KICAD::PCB_POLYGON::Parse(), PCAD2KICAD::SetFontProperty(), and PCAD2KICAD::PCB_POLYGON::SetOutline().

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

◆ DoPCBComponents()

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

Definition at line 241 of file pcb.cpp.

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

References FindCompDefName(), PCAD2KICAD::PCB_MODULE::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_MODULE::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_MODULE::m_value, NULL, PCAD2KICAD::PCB_KEEPOUT::Parse(), PCAD2KICAD::PCB_VIA::Parse(), PCAD2KICAD::PCB_PAD::Parse(), PCAD2KICAD::PCB_MODULE::Parse(), PCAD2KICAD::PCB_MODULE::PCB_MODULE(), PCAD2KICAD::PCB_MODULE::SetName(), PCAD2KICAD::SetPosition(), SetTextProperty(), PCAD2KICAD::StrToInt1Units(), PCAD2KICAD::_TTEXTVALUE::text, and PCAD2KICAD::ValidateName().

Referenced by ParseBoard().

◆ FindCompDefName()

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

Definition at line 142 of file pcb.cpp.

143 {
144  XNODE* result = NULL, * 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 = NULL;
159  }
160  }
161 
162  if( lNode )
163  lNode = lNode->GetNext();
164  }
165 
166  return result;
167 }
#define NULL
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
XNODE * FindNode(XNODE *aChild, const wxString &aTag)

References PCAD2KICAD::FindNode(), and NULL.

Referenced by DoPCBComponents().

◆ FindLayer()

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

Definition at line 459 of file pcb.cpp.

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

References m_layersStackup.

Referenced by MapLayer().

◆ FindModulePatternDefName()

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

Definition at line 64 of file pcb_module.cpp.

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

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

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

◆ FindOutlinePoint()

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

Definition at line 564 of file pcb.cpp.

565 {
566  int i;
567 
568  for( i = 0; i < (int) aOutline->GetCount(); i++ )
569  if( *((*aOutline)[i]) == aPoint )
570  return i;
571 
572  return -1;
573 }

Referenced by GetBoardOutline().

◆ Flip()

void PCAD2KICAD::PCB_MODULE::Flip ( )
overridevirtualinherited

Reimplemented from PCAD2KICAD::PCB_COMPONENT.

Definition at line 620 of file pcb_module.cpp.

621 {
622  int i;
623 
624  if( m_mirror == 1 )
625  {
627 
628  for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
629  {
630  if( m_moduleObjects[i]->m_objType == wxT( 'L' ) || // lines
631  m_moduleObjects[i]->m_objType == wxT( 'A' ) || // arcs
632  m_moduleObjects[i]->m_objType == wxT( 'Z' ) || // polygons
633  m_moduleObjects[i]->m_objType == wxT( 'P' ) || // pads
634  m_moduleObjects[i]->m_objType == wxT( 'V' ) ) // vias
635  {
636  m_moduleObjects[i]->Flip();
637  }
638  }
639  }
640 }
PCB_COMPONENTS_ARRAY m_moduleObjects
Definition: pcb_module.h:44

References PCAD2KICAD::PCB_MODULE::m_mirror, PCAD2KICAD::PCB_MODULE::m_moduleObjects, 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 590 of file pcb.cpp.

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

References distance(), Edge_Cuts, PCAD2KICAD::FindNode(), FindOutlinePoint(), XNODE::GetChildren(), GetDistance(), PCAD2KICAD::PCB_COMPONENT::GetKiCadLayer(), XNODE::GetNext(), PCAD2KICAD::PCB_MODULE::m_boardOutline, m_defaultMeasurementUnit, and PCAD2KICAD::SetPosition().

Referenced by ParseBoard().

◆ GetDistance()

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

Definition at line 582 of file pcb.cpp.

583 {
584  return sqrt( ( aPoint1->x - aPoint2->x ) *
585  ( aPoint1->x - aPoint2->x ) +
586  ( aPoint1->y - aPoint2->y ) *
587  ( aPoint1->y - aPoint2->y ) );
588 }

Referenced by GetBoardOutline().

◆ GetKiCadLayer() [1/2]

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

Implements PCAD2KICAD::PCB_CALLBACKS.

Definition at line 50 of file pcb.cpp.

51 {
52  auto it = m_layersMap.find( aPCadLayer );
53 
54  if( it == m_layersMap.end() )
55  THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
56 
57  return it->second.KiCadLayer;
58 }
std::map< int, TLAYER > m_layersMap
Definition: pcb.h:48
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
#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)
overridevirtual

Implements PCAD2KICAD::PCB_CALLBACKS.

Definition at line 70 of file pcb.cpp.

71 {
72  auto it = m_layersMap.find( aPCadLayer );
73 
74  if( it == m_layersMap.end() )
75  THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
76 
77  return it->second.netNameRef;
78 }
std::map< int, TLAYER > m_layersMap
Definition: pcb.h:48
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
#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)
overridevirtual

Implements PCAD2KICAD::PCB_CALLBACKS.

Definition at line 60 of file pcb.cpp.

61 {
62  auto it = m_layersMap.find( aPCadLayer );
63 
64  if( it == m_layersMap.end() )
65  THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
66 
67  return it->second.layerType;
68 }
std::map< int, TLAYER > m_layersMap
Definition: pcb.h:48
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ GetNetCode()

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

Implements PCAD2KICAD::PCB_CALLBACKS.

Definition at line 125 of file pcb.cpp.

126 {
127  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:46

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 489 of file pcb.cpp.

490 {
491  wxString lName, layerType;
492  PCB_LAYER_ID KiCadLayer;
493  long num = 0;
494 
495  aNode->GetAttribute( wxT( "Name" ), &lName );
496  lName = lName.MakeUpper();
497 
498  if( lName == wxT( "TOP ASSY" ) )
499  KiCadLayer = F_Fab;
500  else if( lName == wxT( "TOP SILK" ) )
501  KiCadLayer = F_SilkS;
502  else if( lName == wxT( "TOP PASTE" ) )
503  KiCadLayer = F_Paste;
504  else if( lName == wxT( "TOP MASK" ) )
505  KiCadLayer = F_Mask;
506  else if( lName == wxT( "TOP" ) )
507  KiCadLayer = F_Cu;
508  else if( lName == wxT( "BOTTOM" ) )
509  KiCadLayer = B_Cu;
510  else if( lName == wxT( "BOT MASK" ) )
511  KiCadLayer = B_Mask;
512  else if( lName == wxT( "BOT PASTE" ) )
513  KiCadLayer = B_Paste;
514  else if( lName == wxT( "BOT SILK" ) )
515  KiCadLayer = B_SilkS;
516  else if( lName == wxT( "BOT ASSY" ) )
517  KiCadLayer = B_Fab;
518  else if( lName == wxT( "BOARD" ) )
519  KiCadLayer = Edge_Cuts;
520  else
521  {
522  int layernum = FindLayer( lName );
523 
524  if( layernum == -1 )
525  KiCadLayer = Dwgs_User; // default
526  else
527 #if 0 // was:
528  KiCadLayer = FIRST_COPPER_LAYER + m_layersStackup.GetCount() - 1 - layernum;
529 #else
530  KiCadLayer = ToLAYER_ID( layernum );
531 #endif
532  }
533 
534  if( FindNode( aNode, wxT( "layerNum" ) ) )
535  FindNode( aNode, wxT( "layerNum" ) )->GetNodeContent().ToLong( &num );
536 
537  if( num < 0 )
538  THROW_IO_ERROR( wxString::Format( wxT( "layerNum = %ld is out of range" ), num ) );
539 
540  TLAYER newlayer;
541  newlayer.KiCadLayer = KiCadLayer;
542 
543  if( FindNode( aNode, wxT( "layerType" ) ) )
544  {
545  layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim( false );
546 
547  if( layerType == wxT( "NonSignal" ) )
548  newlayer.layerType = LAYER_TYPE_NONSIGNAL;
549  if( layerType == wxT( "Signal" ) )
550  newlayer.layerType = LAYER_TYPE_SIGNAL;
551  if( layerType == wxT( "Plane" ) )
552  newlayer.layerType = LAYER_TYPE_PLANE;
553  }
554 
555  m_layersMap.insert( std::make_pair( num, newlayer ) );
556 
557  if( FindNode( aNode, wxT( "netNameRef" ) ) )
558  {
559  FindNode( aNode, wxT( "netNameRef" ) )->GetAttribute( wxT( "Name" ),
560  &m_layersMap[(int) num].netNameRef );
561  }
562 }
std::map< int, TLAYER > m_layersMap
Definition: pcb.h:48
PCB_LAYER_ID
A quick note on layer IDs:
wxArrayString m_layersStackup
Definition: pcb.h:67
PCB_LAYER_ID KiCadLayer
Definition: pcb_callbacks.h:45
int FindLayer(const wxString &aLayerName)
Definition: pcb.cpp:459
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
LAYER_TYPE_T layerType
Definition: pcb_callbacks.h:46
#define FIRST_COPPER_LAYER
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:897

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_MODULE::Parse ( XNODE aNode,
wxStatusBar *  aStatusBar,
const wxString &  aDefaultMeasurementUnit,
const wxString &  aActualConversion 
)
virtualinherited

Definition at line 383 of file pcb_module.cpp.

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

References PCAD2KICAD::PCB_MODULE::DoLayerContentsObjects(), PCAD2KICAD::FindNode(), PCAD2KICAD::PCB_MODULE::FindPatternMultilayerSection(), PCAD2KICAD::FindPinMap(), XNODE::GetChildren(), XNODE::GetNext(), XNODE::GetParent(), PCAD2KICAD::PCB_COMPONENT::m_board, PCAD2KICAD::PCB_COMPONENT::m_callbacks, PCAD2KICAD::PCB_MODULE::m_moduleObjects, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_patGraphRefName, PCAD2KICAD::PCB_VIA::Parse(), PCAD2KICAD::PCB_PAD::Parse(), PCAD2KICAD::PCB_MODULE::SetName(), and PCAD2KICAD::_TTEXTVALUE::text.

Referenced by DoPCBComponents(), and ParseBoard().

◆ ParseBoard()

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

Definition at line 681 of file pcb.cpp.

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

References _, ConnectPinToNet(), PCAD2KICAD::PCB_MODULE::DoLayerContentsObjects(), DoPCBComponents(), PCAD2KICAD::FindNode(), PCAD2KICAD::PCB_MODULE::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(), NULL, PCAD2KICAD::PCB_NET::Parse(), PCAD2KICAD::PCB_MODULE::Parse(), PCAD2KICAD::PCB_MODULE::PCB_MODULE(), PCAD2KICAD::PCB_COMPONENT::SetPosOffset(), and THROW_IO_ERROR.

Referenced by PCAD_PLUGIN::Load().

◆ SetName()

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

Definition at line 365 of file pcb_module.cpp.

366 {
367  int i;
368  long num;
369 
370  aPin.ToLong( &num );
371 
372  for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
373  {
374  if( m_moduleObjects[i]->m_objType == wxT( 'P' ) )
375  if( ( (PCB_PAD*) m_moduleObjects[i] )->m_number == num )
376  ( (PCB_PAD*) m_moduleObjects[i] )->m_name.text = aName;
377 
378 
379  }
380 }
PCB_COMPONENTS_ARRAY m_moduleObjects
Definition: pcb_module.h:44

References PCAD2KICAD::PCB_MODULE::m_moduleObjects, PCAD2KICAD::PCB_COMPONENT::m_name, PCAD2KICAD::PCB_COMPONENT::m_objType, and PCAD2KICAD::_TTEXTVALUE::text.

Referenced by DoPCBComponents(), and PCAD2KICAD::PCB_MODULE::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.

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

References PCAD2KICAD::FindNode(), XNODE::GetNext(), m_defaultMeasurementUnit, NULL, PCAD2KICAD::SetTextParameters(), and PCAD2KICAD::_TTEXTVALUE::text.

Referenced by DoPCBComponents().

Member Data Documentation

◆ m_board

◆ m_boardOutline

VERTICES_ARRAY PCAD2KICAD::PCB_MODULE::m_boardOutline
inherited

Definition at line 46 of file pcb_module.h.

Referenced by PCAD2KICAD::PCB_MODULE::DoLayerContentsObjects(), and GetBoardOutline().

◆ m_callbacks

◆ m_compRef

wxString PCAD2KICAD::PCB_COMPONENT::m_compRef
inherited

◆ m_defaultMeasurementUnit

wxString PCAD2KICAD::PCB::m_defaultMeasurementUnit

Definition at line 47 of file pcb.h.

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

◆ m_KiCadLayer

◆ m_layersMap

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

Definition at line 48 of file pcb.h.

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

◆ m_layersStackup

wxArrayString PCAD2KICAD::PCB::m_layersStackup
private

Definition at line 67 of file pcb.h.

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

◆ m_mirror

int PCAD2KICAD::PCB_MODULE::m_mirror
inherited

◆ m_moduleObjects

PCB_COMPONENTS_ARRAY PCAD2KICAD::PCB_MODULE::m_moduleObjects
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 45 of file pcb.h.

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

◆ m_pcbNetlist

PCB_NETS_ARRAY PCAD2KICAD::PCB::m_pcbNetlist

Definition at line 46 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 49 of file pcb.h.

Referenced by ParseBoard(), and PCB().

◆ m_sizeY

int PCAD2KICAD::PCB::m_sizeY

Definition at line 50 of file pcb.h.

Referenced by ParseBoard(), and PCB().

◆ m_tag

int PCAD2KICAD::PCB_COMPONENT::m_tag
inherited

Definition at line 49 of file pcb_component.h.

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

◆ m_uuid

KIID PCAD2KICAD::PCB_COMPONENT::m_uuid
inherited

Definition at line 53 of file pcb_component.h.

◆ m_value

TTEXTVALUE PCAD2KICAD::PCB_MODULE::m_value
inherited

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