60#include <wx/filename.h>
61#include <wx/txtstrm.h>
62#include <wx/wfstream.h>
63#include <boost/ptr_container/ptr_map.hpp>
67static inline long parseInt(
const wxString& aValue,
double aScalar )
69 double value = std::numeric_limits<double>::max();
92 if( aValue.EndsWith( wxT(
"mm" ) ) )
94 aScalar *= 100000.0 / 25.4;
96 else if( aValue.EndsWith( wxT(
"mil" ) ) )
103 aValue.ToCDouble(&value);
105 if( value == std::numeric_limits<double>::max() )
106 THROW_IO_ERRORF(
_(
"Cannot convert '%s' to an integer." ), aValue.GetData() );
108 return KiROUND( value * aScalar );
112#define TEXT_DEFAULT_SIZE ( 40 * pcbIUScale.IU_PER_MILS )
113#define OLD_GPCB_UNIT_CONV pcbIUScale.IU_PER_MILS
114#define NEW_GPCB_UNIT_CONV ( 0.01 * pcbIUScale.IU_PER_MILS )
159 void Remove(
const wxString& aFootprintName );
167 static long long GetTimestamp(
const wxString& aLibPath );
187 bool testFlags(
const wxString& aFlag,
long aMask,
const wxChar* aName );
238 if( !dir.IsOpened() )
248 if( !dir.GetFirst( &fullName, fileSpec ) )
251 wxString cacheErrorMsg;
271 if( !cacheErrorMsg.IsEmpty() )
272 cacheErrorMsg += wxT(
"\n\n" );
274 cacheErrorMsg += ioe.
What();
276 }
while( dir.GetNext( &fullName ) );
278 if( !cacheErrorMsg.IsEmpty() )
285 std::string footprintName =
TO_UTF8( aFootprintName );
293 aFootprintName.GetData() );
297 wxString fullPath = it->second->GetFileName().GetFullPath();
299 wxRemoveFile( fullPath );
326 wxArrayString parameters;
327 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
nullptr );
329 if( aLineReader->
ReadLine() ==
nullptr )
334 paramCnt = parameters.GetCount();
344 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) != 0 )
346 msg.Printf(
_(
"Unknown token '%s'" ), parameters[0] );
351 if( paramCnt < 10 || paramCnt > 14 )
353 msg.Printf(
_(
"Element token contains %d parameters." ), paramCnt );
359 if( parameters[1] == wxT(
"(" ) )
364 footprint->SetLibDescription( parameters[3] );
365 footprint->SetReference( parameters[4] );
369 footprint->SetLibDescription( parameters[2] );
370 footprint->SetReference( parameters[3] );
375 footprint->SetValue( parameters[5] );
379 if( footprint->Value().GetText().IsEmpty() )
380 footprint->Value().SetText( wxT(
"VAL**" ) );
382 if( footprint->Reference().GetText().IsEmpty() )
383 footprint->Reference().SetText( wxT(
"REF**" ) );
390 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
393 if( parameters[0] == wxT(
")" ) )
396 paramCnt = parameters.GetCount();
401 if( parameters[1] == wxT(
"(" ) )
408 parameters[0], paramCnt );
411 if( parameters[0].CmpNoCase( wxT(
"ElementLine" ) ) == 0 )
415 msg.Printf( wxT(
"ElementLine token contains %d parameters." ), paramCnt );
423 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) ) );
425 static_cast<int>(
parseInt( parameters[5], conv_unit ) ) ) );
429 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
430 shape->
Move( footprint->GetPosition() );
432 footprint->Add( shape );
437 if( parameters[0].CmpNoCase( wxT(
"ElementArc" ) ) == 0 )
441 msg.Printf( wxT(
"ElementArc token contains %d parameters." ), paramCnt );
449 footprint->Add( shape );
452 int radius =
static_cast<int>( (
parseInt( parameters[4], conv_unit ) +
453 parseInt( parameters[5], conv_unit ) ) / 2 );
456 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
480 shape->
SetStart( arcStart + centre );
489 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
490 shape->
Move( footprint->GetPosition() );
499 if( parameters[0].CmpNoCase( wxT(
"Pad" ) ) == 0 )
501 if( paramCnt < 10 || paramCnt > 13 )
503 msg.Printf( wxT(
"Pad token contains %d parameters." ), paramCnt );
508 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( footprint.get() );
516 pad->SetLayerSet( pad_front );
518 if(
testFlags( parameters[paramCnt-2], 0x0080, wxT(
"onsolder" ) ) )
519 pad->SetLayerSet( pad_back );
529 pad->SetNumber( parameters[paramCnt-3] );
531 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
532 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
533 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
534 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
535 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
537 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
551 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
552 maskMargin = ( maskMargin - width ) / 2;
553 pad->SetLocalSolderMaskMargin( maskMargin );
558 pad->SetOrientation( orient );
560 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
564 padPos += footprint->GetPosition();
565 pad->SetPosition( padPos );
567 if( !
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
577 pad->Padstack().ForEachUniqueLayer(
582 if( padSize.
x <= 0 || padSize.
y <= 0 )
588 m_owner->Report( wxString::Format(
_(
"Invalid zero-sized pad ignored in\nfile: %s" ),
594 footprint->Add(
pad.release() );
606 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
608 if( paramCnt < 8 || paramCnt > 12 )
610 msg.Printf( wxT(
"Pin token contains %d parameters." ), paramCnt );
622 pad->SetLayerSet( pad_set );
624 if(
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
631 pad->SetNumber( parameters[paramCnt-3] );
634 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
636 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
654 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
655 maskMargin = ( maskMargin - padSize ) / 2;
656 pad->SetLocalSolderMaskMargin( maskMargin );
658 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
662 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
665 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
667 padPos += footprint->GetPosition();
668 pad->SetPosition( padPos );
676 footprint->Add(
pad );
681 footprint->AutoPositionFields();
683 return footprint.release();
691 char* line = aLineReader->
Line();
705 aParameterList.Add( tmp );
710 aParameterList.Add( tmp );
715 if( aParameterList.GetCount() == 1 )
727 aParameterList.Add( tmp );
732 aParameterList.Add( tmp );
746 aParameterList.Add( tmp );
758 aParameterList.Add( wxEmptyString );
769 aParameterList.Add( tmp );
801 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
805 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
808 else if( aFlag.Contains( aName ) )
829 m_ctl( aControlFlags ),
865 const std::map<std::string, UTF8>* aProperties )
867 wxFileName fn( aFootprintPath );
873 char* line = reader.
Line();
878 if( strncasecmp( line,
"Element", strlen(
"Element" ) ) != 0 )
881 aFootprintNameOut = fn.GetName();
888 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
890 wxDir dir( aLibraryPath );
893 if( !dir.IsOpened() )
909 errorMsg = ioe.
What();
915 for(
const auto& footprint :
m_cache->GetFootprints() )
916 aFootprintNames.Add(
From_UTF8( footprint.first.c_str() ) );
918 if( !errorMsg.IsEmpty() && !aBestEfforts )
924 const wxString& aFootprintName,
925 const std::map<std::string, UTF8>* aProperties,
932 auto it =
m_cache->GetFootprints().find(
TO_UTF8( aFootprintName ) );
934 if( it ==
m_cache->GetFootprints().end() )
937 return it->second->GetFootprint().get();
942 bool aKeepUUID,
const std::map<std::string, UTF8>* aProperties )
952 copy->SetParent(
nullptr );
961 const std::map<std::string, UTF8>* aProperties )
968 THROW_IO_ERRORF(
_(
"Library '%s' is read only." ), aLibraryPath.GetData() );
970 m_cache->Remove( aFootprintName );
977 fn.SetPath( aLibraryPath );
980 if( !fn.DirExists() )
983 if( !fn.IsDirWritable() )
984 THROW_IO_ERRORF(
_(
"Insufficient permissions to delete folder '%s'." ), aLibraryPath.GetData() );
986 wxDir dir( aLibraryPath );
988 if( dir.HasSubDirs() )
989 THROW_IO_ERRORF(
_(
"Library folder '%s' has unexpected sub-folders." ), aLibraryPath.GetData() );
999 for(
unsigned i = 0; i < files.GetCount(); i++ )
1007 aLibraryPath.GetData() );
1011 for(
unsigned i = 0; i < files.GetCount(); i++ )
1012 wxRemoveFile( files[i] );
1015 wxLogTrace(
traceGedaPcbPlugin, wxT(
"Removing footprint library '%s'" ), aLibraryPath.GetData() );
1019 if( !wxRmdir( aLibraryPath ) )
1020 THROW_IO_ERRORF(
_(
"Footprint library '%s' cannot be deleted." ), aLibraryPath.GetData() );
1026 wxMilliSleep( 250L );
1064 char* line = aLineReader->
Line();
1075 if( !tmp.IsEmpty() )
1077 aParameterList.Add( tmp );
1082 aParameterList.Add( tmp );
1085 if( aParameterList.GetCount() == 1 )
1095 if( !tmp.IsEmpty() )
1097 aParameterList.Add( tmp );
1102 aParameterList.Add( tmp );
1117 if( !tmp.IsEmpty() )
1119 aParameterList.Add( tmp );
1130 aParameterList.Add( wxEmptyString );
1141 aParameterList.Add( tmp );
1173 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
1177 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
1180 else if( aFlag.Contains( aName ) )
1194 wxFileInputStream input( aFileName );
1199 wxTextInputStream
text( input );
1201 for(
int i = 0; i < 20; i++ )
1206 wxString line =
text.ReadLine();
1208 if( line.Contains( wxS(
"PCB[" ) ) || line.Contains( wxS(
"PCB(" ) ) )
1218 wxString
name = aLayerName.Lower();
1220 if(
name.Contains( wxT(
"outline" ) ) ||
name.Contains( wxT(
"route" ) ) )
1223 if(
name.Contains( wxT(
"silk" ) ) )
1225 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1231 if(
name.Contains( wxT(
"mask" ) ) )
1233 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1239 if(
name.Contains( wxT(
"paste" ) ) )
1241 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1247 if(
name.Contains( wxT(
"fab" ) ) )
1251 if(
name.Contains( wxT(
"component" ) ) ||
name.Contains( wxT(
"top" ) )
1252 || ( aGedaLayer == 1 && !
name.Contains( wxT(
"solder" ) ) ) )
1257 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) )
1258 || aGedaLayer == 2 )
1264 if( aGedaLayer >= 3 && aGedaLayer <= 16 )
1266 int innerIdx = aGedaLayer - 3;
1272 return innerLayers[innerIdx];
1282 int paramCnt = aParameters.GetCount();
1285 THROW_IO_ERRORF(
_(
"Via token contains %d parameters, expected at least 10." ), paramCnt );
1289 int x =
static_cast<int>(
parseInt( aParameters[2], aConvUnit ) );
1290 int y =
static_cast<int>(
parseInt( aParameters[3], aConvUnit ) );
1291 int thickness =
static_cast<int>(
parseInt( aParameters[4], aConvUnit ) );
1292 int drill =
static_cast<int>(
parseInt( aParameters[7], aConvUnit ) );
1297 via->SetDrill( drill );
1308 int paramCnt = aParameters.GetCount();
1309 double conv_unit = aConvUnit;
1311 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
m_board );
1313 if( paramCnt < 10 || paramCnt > 14 )
1319 int descIdx, nameIdx, valueIdx, mxIdx;
1336 footprint->SetLibDescription( aParameters[descIdx] );
1337 footprint->SetReference( aParameters[nameIdx] );
1340 footprint->SetValue( aParameters[valueIdx] );
1342 if( footprint->Value().GetText().IsEmpty() )
1343 footprint->Value().SetText( wxT(
"VAL**" ) );
1345 if( footprint->Reference().GetText().IsEmpty() )
1346 footprint->Reference().SetText( wxT(
"REF**" ) );
1349 if( mxIdx > 0 && paramCnt > 12 )
1351 int mx =
static_cast<int>(
parseInt( aParameters[mxIdx], conv_unit ) );
1352 int my =
static_cast<int>(
parseInt( aParameters[mxIdx + 1], conv_unit ) );
1353 footprint->SetPosition(
VECTOR2I( mx, my ) );
1356 wxArrayString parameters;
1363 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1366 if( parameters[0] == wxT(
")" ) )
1369 paramCnt = parameters.GetCount();
1373 if( parameters[1] == wxT(
"(" ) )
1380 if( parameters[0].CmpNoCase( wxT(
"ElementLine" ) ) == 0 )
1388 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) ) );
1390 static_cast<int>(
parseInt( parameters[5], conv_unit ) ) ) );
1394 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
1395 shape->
Move( footprint->GetPosition() );
1397 footprint->Add( shape );
1402 if( parameters[0].CmpNoCase( wxT(
"ElementArc" ) ) == 0 )
1404 if( paramCnt != 10 )
1409 footprint->Add( shape );
1411 int radius =
static_cast<int>( (
parseInt( parameters[4], conv_unit )
1412 +
parseInt( parameters[5], conv_unit ) ) / 2 );
1415 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1433 shape->
SetStart( arcStart + centre );
1440 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
1441 shape->
Move( footprint->GetPosition() );
1446 if( parameters[0].CmpNoCase( wxT(
"Pad" ) ) == 0 )
1448 if( paramCnt < 10 || paramCnt > 13 )
1451 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( footprint.get() );
1459 pad->SetLayerSet( pad_front );
1461 if(
testFlags( parameters[paramCnt - 2], 0x0080, wxT(
"onsolder" ) ) )
1462 pad->SetLayerSet( pad_back );
1464 pad->SetNumber( parameters[paramCnt - 3] );
1466 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1467 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1468 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1469 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1470 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1472 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
1474 if( paramCnt == 13 )
1479 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
1480 maskMargin = ( maskMargin - width ) / 2;
1481 pad->SetLocalSolderMaskMargin( maskMargin );
1485 pad->SetOrientation( orient );
1487 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
1491 padPos += footprint->GetPosition();
1492 pad->SetPosition( padPos );
1494 if( !
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1502 bool badPad =
false;
1504 pad->Padstack().ForEachUniqueLayer(
1509 if( padSize.
x <= 0 || padSize.
y <= 0 )
1515 Report( wxString::Format(
_(
"Invalid zero-sized pad ignored in\nfile: %s" ),
1521 footprint->Add(
pad.release() );
1528 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
1530 if( paramCnt < 8 || paramCnt > 12 )
1540 pad->SetLayerSet( pad_set );
1542 if(
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1545 pad->SetNumber( parameters[paramCnt - 3] );
1548 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1550 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1555 if( paramCnt == 12 )
1560 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1561 maskMargin = ( maskMargin - padSize ) / 2;
1562 pad->SetLocalSolderMaskMargin( maskMargin );
1564 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
1568 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1571 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
1573 padPos += footprint->GetPosition();
1574 pad->SetPosition( padPos );
1582 footprint->Add(
pad );
1589 wxString elementFlags = aParameters[2];
1591 if( elementFlags.Contains( wxT(
"onsolder" ) ) )
1594 footprint->AutoPositionFields();
1596 return footprint.release();
1604 int paramCnt = aParameters.GetCount();
1610 aParameters[2].ToLong( &layerNum );
1615 layerName = aParameters[3];
1624 int layerCount =
static_cast<int>( layerNum );
1630 wxArrayString parameters;
1631 double conv_unit = aConvUnit;
1638 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1641 if( parameters[0] == wxT(
")" ) )
1644 paramCnt = parameters.GetCount();
1648 if( parameters[1] == wxT(
"(" ) )
1655 if( parameters[0].CmpNoCase( wxT(
"Line" ) ) == 0 )
1660 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1661 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1662 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1663 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1664 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1690 if( parameters[0].CmpNoCase( wxT(
"Arc" ) ) == 0 )
1695 int cx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1696 int cy =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1697 int arcWidth =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1698 int arcHeight =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1699 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1700 int radius = ( arcWidth + arcHeight ) / 2;
1718 arc->
SetStart( arcStart + centre );
1721 RotatePoint( arcMid, -start_angle - sweep_angle / 2 );
1722 arc->
SetMid( arcMid + centre );
1725 RotatePoint( arcEnd, -start_angle - sweep_angle );
1726 arc->
SetEnd( arcEnd + centre );
1746 shape->
SetStart( arcStart + centre );
1758 if( parameters[0].CmpNoCase( wxT(
"Polygon" ) ) == 0 )
1766 const int outlineIdx = -1;
1767 bool parsingPoints =
false;
1771 wxArrayString polyParams;
1774 if( polyParams.IsEmpty() )
1777 if( polyParams[0] == wxT(
")" ) )
1780 if( polyParams[0] == wxT(
"(" ) )
1782 parsingPoints =
true;
1786 if( !parsingPoints )
1790 for(
size_t i = 0; i < polyParams.GetCount(); i++ )
1792 if( polyParams[i] == wxT(
"[" ) && i + 2 < polyParams.GetCount() )
1794 int px =
static_cast<int>(
parseInt( polyParams[i + 1], conv_unit ) );
1795 int py =
static_cast<int>(
parseInt( polyParams[i + 2], conv_unit ) );
1816 if( parameters[0].CmpNoCase( wxT(
"Text" ) ) == 0 )
1822 text->SetLayer( kicadLayer );
1824 int tx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1825 int ty =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1829 parameters[4].ToLong( &direction );
1832 text->SetTextAngle( textAngle );
1835 parameters[5].ToLong( &
scale );
1840 text->SetText( parameters[6] );
1857 std::map<wxString, FOOTPRINT*> fpByRef;
1860 fpByRef[fp->GetReference()] = fp;
1862 wxArrayString parameters;
1869 if( parameters.IsEmpty() )
1872 if( parameters[0] == wxT(
")" ) )
1875 if( parameters[0] == wxT(
"(" ) )
1879 if( parameters[0].CmpNoCase( wxT(
"Net" ) ) == 0 )
1883 if( parameters.GetCount() > 3 )
1884 netName = parameters[2];
1888 auto it =
m_netMap.find( netName );
1892 netInfo = it->second;
1904 wxArrayString netParams;
1907 if( netParams.IsEmpty() )
1910 if( netParams[0] == wxT(
")" ) )
1913 if( netParams[0] == wxT(
"(" ) )
1917 if( netParams[0].CmpNoCase( wxT(
"Connect" ) ) == 0 && netParams.GetCount() > 3 )
1919 wxString connectStr = netParams[2];
1922 int lastDash = connectStr.Find(
'-',
true );
1924 if( lastDash == wxNOT_FOUND )
1927 wxString refdes = connectStr.Left( lastDash );
1928 wxString pinNumber = connectStr.Mid( lastDash + 1 );
1930 auto fpIt = fpByRef.find( refdes );
1932 if( fpIt == fpByRef.end() )
1935 for(
PAD*
pad : fpIt->second->Pads() )
1937 if(
pad->GetNumber() == pinNumber )
1939 pad->SetNet( netInfo );
1951 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
1955 init( aProperties );
1972 wxArrayString parameters;
1975 if( parameters.IsEmpty() )
1978 int paramCnt = parameters.GetCount();
1982 if( parameters[1] == wxT(
"(" ) )
1989 if( parameters[0].CmpNoCase( wxT(
"PCB" ) ) == 0 )
1993 int boardWidth =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1994 int boardHeight =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1997 VECTOR2I pageSize( boardWidth, boardHeight );
2001 m_board->SetPageSettings( page );
2008 if( parameters[0].CmpNoCase( wxT(
"FileVersion" ) ) == 0 )
2012 if( parameters[0].CmpNoCase( wxT(
"Grid" ) ) == 0
2013 || parameters[0].CmpNoCase( wxT(
"Cursor" ) ) == 0
2014 || parameters[0].CmpNoCase( wxT(
"Thermal" ) ) == 0
2015 || parameters[0].CmpNoCase( wxT(
"DRC" ) ) == 0
2016 || parameters[0].CmpNoCase( wxT(
"Flags" ) ) == 0
2017 || parameters[0].CmpNoCase( wxT(
"Groups" ) ) == 0
2018 || parameters[0].CmpNoCase( wxT(
"Styles" ) ) == 0
2019 || parameters[0].CmpNoCase( wxT(
"Attribute" ) ) == 0 )
2025 if( parameters[0].CmpNoCase( wxT(
"Via" ) ) == 0 )
2032 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) == 0 )
2050 if( parameters[0].CmpNoCase( wxT(
"Layer" ) ) == 0 )
2052 parseLayer( parameters, &reader, conv_unit );
2057 if( parameters[0].CmpNoCase( wxT(
"Rat" ) ) == 0 )
2061 if( parameters[0].CmpNoCase( wxT(
"NetList" ) ) == 0 )
2082 m_board->m_LegacyDesignSettingsLoaded =
true;
2083 m_board->m_LegacyNetclassesLoaded =
true;
2089 std::vector<FOOTPRINT*> retval;
2092 retval.push_back(
static_cast<FOOTPRINT*
>( fp->Clone() ) );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
BASE_SET & set(size_t pos)
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Container for design settings for a BOARD object.
void SetEnabledLayers(const LSET &aMask)
Change the bit-mask of enabled layers to aMask.
const LSET & GetEnabledLayers() const
Return a bit-mask of all the layers that are enabled.
Information pertinent to a Pcbnew printed circuit board.
virtual void SetParent(EDA_ITEM *aParent)
A LINE_READER that reads from an open file.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
RAII class to set and restore the fontconfig reporter.
helper class for creating a footprint library cache.
std::unique_ptr< FOOTPRINT > m_footprint
WX_FILENAME GetFileName() const
std::unique_ptr< FOOTPRINT > & GetFootprint()
WX_FILENAME m_filename
The full file name and path of the footprint to cache.
GPCB_FPL_CACHE_ENTRY(FOOTPRINT *aFootprint, const WX_FILENAME &aFileName)
FOOTPRINT * parseFOOTPRINT(LINE_READER *aLineReader)
void Remove(const wxString &aFootprintName)
boost::ptr_map< std::string, GPCB_FPL_CACHE_ENTRY > & GetFootprints()
GPCB_FPL_CACHE(PCB_IO_GEDA *aOwner, const wxString &aLibraryPath)
bool IsModified()
Return true if the cache is not up-to-date.
static long long GetTimestamp(const wxString &aLibPath)
Generate a timestamp representing all source files in the cache (including the parent directory).
PCB_IO_GEDA * m_owner
Plugin object that owns the cache.
boost::ptr_map< std::string, GPCB_FPL_CACHE_ENTRY > m_footprints
Map of footprint filename to cache entries.
void parseParameters(wxArrayString &aParameterList, LINE_READER *aLineReader)
Extract parameters and tokens from aLineReader and adds them to aParameterList.
long long m_cache_timestamp
A hash of the timestamps for all the footprint files.
wxFileName m_lib_path
The path of the library.
bool m_cache_dirty
Stored separately because it's expensive to check m_cache_timestamp against all the files.
void Load()
Save not implemented for the Geda PCB footprint library format.
bool testFlags(const wxString &aFlag, long aMask, const wxChar *aName)
Test aFlag for aMask or aName.
virtual void Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A logical library item identifier and consists of various portions much like a URI.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
char * Line() const
Return a pointer to the last line that was read in.
static LOAD_INFO_REPORTER & GetInstance()
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Handle the data for a net.
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
static NETINFO_ITEM * OrphanedItem()
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
@ NORMAL
Shape is the same on all layers.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
void SetMid(const VECTOR2I &aMid)
A PCB_IO derivation for saving and loading Geda PCB files.
void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete aFootprintName from the library at aLibraryPath.
void parseVia(wxArrayString &aParameters, double aConvUnit)
void loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Parse aFileName into aBoard.
void parseNetList(LINE_READER *aLineReader)
std::unique_ptr< FOOTPRINT > FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
std::map< wxString, NETINFO_ITEM * > m_netMap
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
bool CanReadBoard(const wxString &aFileName) const override
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
void init(const std::map< std::string, UTF8 > *aProperties)
std::unique_ptr< FOOTPRINT > ImportFootprint(const wxString &aFootprintPath, wxString &aFootprintNameOut, const std::map< std::string, UTF8 > *aProperties) override
Load a single footprint from aFootprintPath and put its name in aFootprintNameOut.
GPCB_FPL_CACHE * m_cache
Footprint library cache.
bool testFlags(const wxString &aFlag, long aMask, const wxChar *aName)
FOOTPRINT * parseElement(wxArrayString &aParameters, LINE_READER *aLineReader, double aConvUnit)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void parseParameters(wxArrayString &aParameterList, LINE_READER *aLineReader)
void parseLayer(wxArrayString &aParameters, LINE_READER *aLineReader, double aConvUnit)
std::vector< FOOTPRINT * > m_cachedFootprints
LINE_READER * m_reader
no ownership here.
friend class GPCB_FPL_CACHE
PCB_LAYER_ID mapLayer(int aGedaLayer, const wxString &aLayerName) const
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties, bool checkModified)
BOARD * m_board
The board BOARD being worked on, no ownership here.
virtual bool CanReadBoard(const wxString &aFileName) const
PCB_IO(const wxString &aName)
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
void SetCenter(const VECTOR2I &aCenter) override
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
void SetShape(SHAPE_T aShape) override
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void SetStart(const VECTOR2I &aStart) override
void SetStroke(const STROKE_PARAMS &aStroke) override
void SetEnd(const VECTOR2I &aEnd)
void SetStart(const VECTOR2I &aStart)
virtual void SetWidth(int aWidth)
Container for project specific data.
Simple container to manage line stroke parameters.
Read lines of text from another LINE_READER but only returns non-comment lines and non-blank lines wi...
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
A wrapper around a wxFileName which is much more performant with a subset of the API.
void SetFullName(const wxString &aFileNameAndExtension)
wxString GetFullPath() const
Handle a list of polygons defining a copper zone.
void SetLocalClearance(std::optional< int > aClearance)
bool AppendCorner(const VECTOR2I &aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
bool SetNetCode(int aNetCode, bool aNoAssert) override
Override that clamps the netcode to 0 when this zone is in copper-thieving fill mode.
void SetIsFilled(bool isFilled)
void SetAssignedPriority(unsigned aPriority)
int GetNumCorners(void) const
Access to m_Poly parameters.
static constexpr EDA_ANGLE ANGLE_360
static constexpr EDA_ANGLE ANGLE_180
#define IGNORE_PARENT_GROUP
void CollectFilesLoopSafe(const wxString &aRoot, wxArrayString &aFiles, const wxString &aFileSpec, int aFlags)
Recursively collect every file under aRoot, deduplicating subdirectories by their resolved path.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
static const std::string GedaPcbFootprintLibFileExtension
static const std::string KiCadFootprintFileExtension
const wxChar *const traceGedaPcbPlugin
Flag to enable GEDA PCB plugin debug output.
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
@ SMD
Smd pad, appears on the solder paste layer (default)
static long parseInt(const wxString &aValue, double aScalar)
#define NEW_GPCB_UNIT_CONV
#define OLD_GPCB_UNIT_CONV
#define TEXT_DEFAULT_SIZE
Geda PCB file plugin definition file.
int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.