63#include <wx/filename.h>
64#include <wx/txtstrm.h>
65#include <wx/wfstream.h>
66#include <boost/ptr_container/ptr_map.hpp>
70static inline long parseInt(
const wxString& aValue,
double aScalar )
72 double value = std::numeric_limits<double>::max();
95 if( aValue.EndsWith( wxT(
"mm" ) ) )
97 aScalar *= 100000.0 / 25.4;
99 else if( aValue.EndsWith( wxT(
"mil" ) ) )
106 aValue.ToCDouble(&value);
108 if( value == std::numeric_limits<double>::max() )
110 THROW_IO_ERROR( wxString::Format(
_(
"Cannot convert '%s' to an integer." ),
111 aValue.GetData() ) );
114 return KiROUND( value * aScalar );
118#define TEXT_DEFAULT_SIZE ( 40 * pcbIUScale.IU_PER_MILS )
119#define OLD_GPCB_UNIT_CONV pcbIUScale.IU_PER_MILS
120#define NEW_GPCB_UNIT_CONV ( 0.01 * pcbIUScale.IU_PER_MILS )
165 void Remove(
const wxString& aFootprintName );
173 static long long GetTimestamp(
const wxString& aLibPath );
193 bool testFlags(
const wxString& aFlag,
long aMask,
const wxChar* aName );
244 if( !dir.IsOpened() )
246 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' not found." ),
257 if( !dir.GetFirst( &fullName, fileSpec ) )
260 wxString cacheErrorMsg;
280 if( !cacheErrorMsg.IsEmpty() )
281 cacheErrorMsg += wxT(
"\n\n" );
283 cacheErrorMsg += ioe.
What();
285 }
while( dir.GetNext( &fullName ) );
287 if( !cacheErrorMsg.IsEmpty() )
294 std::string footprintName =
TO_UTF8( aFootprintName );
300 THROW_IO_ERROR( wxString::Format(
_(
"Library '%s' has no footprint '%s'." ),
302 aFootprintName.GetData() ) );
306 wxString fullPath = it->second->GetFileName().GetFullPath();
308 wxRemoveFile( fullPath );
335 wxArrayString parameters;
336 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
nullptr );
338 if( aLineReader->
ReadLine() ==
nullptr )
340 msg = aLineReader->
GetSource() + wxT(
": empty file" );
346 paramCnt = parameters.GetCount();
356 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) != 0 )
358 msg.Printf(
_(
"Unknown token '%s'" ), parameters[0] );
363 if( paramCnt < 10 || paramCnt > 14 )
365 msg.Printf(
_(
"Element token contains %d parameters." ), paramCnt );
371 if( parameters[1] == wxT(
"(" ) )
376 footprint->SetLibDescription( parameters[3] );
377 footprint->SetReference( parameters[4] );
381 footprint->SetLibDescription( parameters[2] );
382 footprint->SetReference( parameters[3] );
387 footprint->SetValue( parameters[5] );
391 if( footprint->Value().GetText().IsEmpty() )
392 footprint->Value().SetText( wxT(
"VAL**" ) );
394 if( footprint->Reference().GetText().IsEmpty() )
395 footprint->Reference().SetText( wxT(
"REF**" ) );
402 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
405 if( parameters[0] == wxT(
")" ) )
408 paramCnt = parameters.GetCount();
413 if( parameters[1] == wxT(
"(" ) )
420 parameters[0], paramCnt );
423 if( parameters[0].CmpNoCase( wxT(
"ElementLine" ) ) == 0 )
427 msg.Printf( wxT(
"ElementLine token contains %d parameters." ), paramCnt );
435 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) ) );
437 static_cast<int>(
parseInt( parameters[5], conv_unit ) ) ) );
441 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
442 shape->
Move( footprint->GetPosition() );
444 footprint->Add( shape );
449 if( parameters[0].CmpNoCase( wxT(
"ElementArc" ) ) == 0 )
453 msg.Printf( wxT(
"ElementArc token contains %d parameters." ), paramCnt );
461 footprint->Add( shape );
464 int radius =
static_cast<int>( (
parseInt( parameters[4], conv_unit ) +
465 parseInt( parameters[5], conv_unit ) ) / 2 );
468 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
492 shape->
SetStart( arcStart + centre );
501 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
502 shape->
Move( footprint->GetPosition() );
511 if( parameters[0].CmpNoCase( wxT(
"Pad" ) ) == 0 )
513 if( paramCnt < 10 || paramCnt > 13 )
515 msg.Printf( wxT(
"Pad token contains %d parameters." ), paramCnt );
520 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( footprint.get() );
527 pad->SetLayerSet( pad_front );
529 if(
testFlags( parameters[paramCnt-2], 0x0080, wxT(
"onsolder" ) ) )
530 pad->SetLayerSet( pad_back );
540 pad->SetNumber( parameters[paramCnt-3] );
542 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
543 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
544 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
545 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
546 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
548 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
562 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
563 maskMargin = ( maskMargin - width ) / 2;
564 pad->SetLocalSolderMaskMargin( maskMargin );
569 pad->SetOrientation( orient );
571 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
575 padPos += footprint->GetPosition();
576 pad->SetPosition( padPos );
578 if( !
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
586 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
588 footprint->Add(
pad.release() );
592 wxLogError(
_(
"Invalid zero-sized pad ignored in\nfile: %s" ),
605 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
607 if( paramCnt < 8 || paramCnt > 12 )
609 msg.Printf( wxT(
"Pin token contains %d parameters." ), paramCnt );
620 pad->SetLayerSet( pad_set );
622 if(
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
629 pad->SetNumber( parameters[paramCnt-3] );
632 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
634 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
652 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
653 maskMargin = ( maskMargin - padSize ) / 2;
654 pad->SetLocalSolderMaskMargin( maskMargin );
656 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
660 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
663 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
665 padPos += footprint->GetPosition();
666 pad->SetPosition( padPos );
674 footprint->Add(
pad );
679 footprint->AutoPositionFields();
681 return footprint.release();
689 char* line = aLineReader->
Line();
703 aParameterList.Add( tmp );
708 aParameterList.Add( tmp );
713 if( aParameterList.GetCount() == 1 )
725 aParameterList.Add( tmp );
730 aParameterList.Add( tmp );
744 aParameterList.Add( tmp );
756 aParameterList.Add( wxEmptyString );
767 aParameterList.Add( tmp );
799 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
803 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
806 else if( aFlag.Contains( aName ) )
827 m_ctl( aControlFlags ),
863 wxString& aFootprintNameOut,
864 const std::map<std::string, UTF8>* aProperties )
866 wxFileName fn( aFootprintPath );
872 char* line = reader.
Line();
877 if( strncasecmp( line,
"Element", strlen(
"Element" ) ) != 0 )
880 aFootprintNameOut = fn.GetName();
887 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
889 wxDir dir( aLibraryPath );
892 if( !dir.IsOpened() )
897 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' not found." ), aLibraryPath ) );
908 errorMsg = ioe.
What();
914 for(
const auto& footprint :
m_cache->GetFootprints() )
915 aFootprintNames.Add(
From_UTF8( footprint.first.c_str() ) );
917 if( !errorMsg.IsEmpty() && !aBestEfforts )
923 const wxString& aFootprintName,
924 const std::map<std::string, UTF8>* aProperties,
931 auto it =
m_cache->GetFootprints().find(
TO_UTF8( aFootprintName ) );
933 if( it ==
m_cache->GetFootprints().end() )
936 return it->second->GetFootprint().get();
941 const wxString& aFootprintName,
943 const std::map<std::string, UTF8>* aProperties )
953 copy->SetParent(
nullptr );
962 const std::map<std::string, UTF8>* aProperties )
971 aLibraryPath.GetData() ) );
974 m_cache->Remove( aFootprintName );
981 fn.SetPath( aLibraryPath );
984 if( !fn.DirExists() )
987 if( !fn.IsDirWritable() )
989 THROW_IO_ERROR( wxString::Format(
_(
"Insufficient permissions to delete folder '%s'." ),
990 aLibraryPath.GetData() ) );
993 wxDir dir( aLibraryPath );
995 if( dir.HasSubDirs() )
997 THROW_IO_ERROR( wxString::Format(
_(
"Library folder '%s' has unexpected sub-folders." ),
998 aLibraryPath.GetData() ) );
1002 if( dir.HasFiles() )
1006 wxArrayString files;
1008 wxDir::GetAllFiles( aLibraryPath, &files );
1010 for( i = 0; i < files.GetCount(); i++ )
1016 THROW_IO_ERROR( wxString::Format(
_(
"Unexpected file '%s' found in library '%s'." ),
1018 aLibraryPath.GetData() ) );
1022 for( i = 0; i < files.GetCount(); i++ )
1024 wxRemoveFile( files[i] );
1029 aLibraryPath.GetData() );
1033 if( !wxRmdir( aLibraryPath ) )
1035 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' cannot be deleted." ),
1036 aLibraryPath.GetData() ) );
1043 wxMilliSleep( 250L );
1081 char* line = aLineReader->
Line();
1092 if( !tmp.IsEmpty() )
1094 aParameterList.Add( tmp );
1099 aParameterList.Add( tmp );
1102 if( aParameterList.GetCount() == 1 )
1112 if( !tmp.IsEmpty() )
1114 aParameterList.Add( tmp );
1119 aParameterList.Add( tmp );
1134 if( !tmp.IsEmpty() )
1136 aParameterList.Add( tmp );
1147 aParameterList.Add( wxEmptyString );
1158 aParameterList.Add( tmp );
1190 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
1194 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
1197 else if( aFlag.Contains( aName ) )
1211 wxFileInputStream input( aFileName );
1216 wxTextInputStream
text( input );
1218 for(
int i = 0; i < 20; i++ )
1223 wxString line =
text.ReadLine();
1225 if( line.Contains( wxS(
"PCB[" ) ) || line.Contains( wxS(
"PCB(" ) ) )
1235 wxString
name = aLayerName.Lower();
1237 if(
name.Contains( wxT(
"outline" ) ) ||
name.Contains( wxT(
"route" ) ) )
1240 if(
name.Contains( wxT(
"silk" ) ) )
1242 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1248 if(
name.Contains( wxT(
"mask" ) ) )
1250 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1256 if(
name.Contains( wxT(
"paste" ) ) )
1258 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1264 if(
name.Contains( wxT(
"fab" ) ) )
1268 if(
name.Contains( wxT(
"component" ) ) ||
name.Contains( wxT(
"top" ) )
1269 || ( aGedaLayer == 1 && !
name.Contains( wxT(
"solder" ) ) ) )
1274 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) )
1275 || aGedaLayer == 2 )
1281 if( aGedaLayer >= 3 && aGedaLayer <= 16 )
1283 int innerIdx = aGedaLayer - 3;
1289 return innerLayers[innerIdx];
1299 int paramCnt = aParameters.GetCount();
1304 _(
"Via token contains %d parameters, expected at least 10." ), paramCnt ) );
1309 int x =
static_cast<int>(
parseInt( aParameters[2], aConvUnit ) );
1310 int y =
static_cast<int>(
parseInt( aParameters[3], aConvUnit ) );
1311 int thickness =
static_cast<int>(
parseInt( aParameters[4], aConvUnit ) );
1312 int drill =
static_cast<int>(
parseInt( aParameters[7], aConvUnit ) );
1316 via->SetDrill( drill );
1328 int paramCnt = aParameters.GetCount();
1329 double conv_unit = aConvUnit;
1332 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
m_board );
1334 if( paramCnt < 10 || paramCnt > 14 )
1336 msg.Printf(
_(
"Element token contains %d parameters." ), paramCnt );
1343 int descIdx, nameIdx, valueIdx, mxIdx;
1360 footprint->SetLibDescription( aParameters[descIdx] );
1361 footprint->SetReference( aParameters[nameIdx] );
1364 footprint->SetValue( aParameters[valueIdx] );
1366 if( footprint->Value().GetText().IsEmpty() )
1367 footprint->Value().SetText( wxT(
"VAL**" ) );
1369 if( footprint->Reference().GetText().IsEmpty() )
1370 footprint->Reference().SetText( wxT(
"REF**" ) );
1373 if( mxIdx > 0 && paramCnt > 12 )
1375 int mx =
static_cast<int>(
parseInt( aParameters[mxIdx], conv_unit ) );
1376 int my =
static_cast<int>(
parseInt( aParameters[mxIdx + 1], conv_unit ) );
1377 footprint->SetPosition(
VECTOR2I( mx, my ) );
1380 wxArrayString parameters;
1387 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1390 if( parameters[0] == wxT(
")" ) )
1393 paramCnt = parameters.GetCount();
1397 if( parameters[1] == wxT(
"(" ) )
1404 if( parameters[0].CmpNoCase( wxT(
"ElementLine" ) ) == 0 )
1412 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) ) );
1414 static_cast<int>(
parseInt( parameters[5], conv_unit ) ) ) );
1418 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
1419 shape->
Move( footprint->GetPosition() );
1421 footprint->Add( shape );
1426 if( parameters[0].CmpNoCase( wxT(
"ElementArc" ) ) == 0 )
1428 if( paramCnt != 10 )
1433 footprint->Add( shape );
1435 int radius =
static_cast<int>( (
parseInt( parameters[4], conv_unit )
1436 +
parseInt( parameters[5], conv_unit ) ) / 2 );
1439 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1459 shape->
SetStart( arcStart + centre );
1466 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
1467 shape->
Move( footprint->GetPosition() );
1472 if( parameters[0].CmpNoCase( wxT(
"Pad" ) ) == 0 )
1474 if( paramCnt < 10 || paramCnt > 13 )
1477 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( footprint.get() );
1484 pad->SetLayerSet( pad_front );
1486 if(
testFlags( parameters[paramCnt - 2], 0x0080, wxT(
"onsolder" ) ) )
1487 pad->SetLayerSet( pad_back );
1489 pad->SetNumber( parameters[paramCnt - 3] );
1491 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1492 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1493 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1494 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1495 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1497 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
1499 if( paramCnt == 13 )
1504 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
1505 maskMargin = ( maskMargin - width ) / 2;
1506 pad->SetLocalSolderMaskMargin( maskMargin );
1510 pad->SetOrientation( orient );
1512 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
1517 padPos += footprint->GetPosition();
1518 pad->SetPosition( padPos );
1520 if( !
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1533 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
1534 footprint->Add(
pad.release() );
1540 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
1542 if( paramCnt < 8 || paramCnt > 12 )
1552 pad->SetLayerSet( pad_set );
1554 if(
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1557 pad->SetNumber( parameters[paramCnt - 3] );
1560 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1562 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1567 if( paramCnt == 12 )
1572 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1573 maskMargin = ( maskMargin - padSize ) / 2;
1574 pad->SetLocalSolderMaskMargin( maskMargin );
1576 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
1580 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1583 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
1585 padPos += footprint->GetPosition();
1586 pad->SetPosition( padPos );
1595 footprint->Add(
pad );
1602 wxString elementFlags = aParameters[2];
1604 if( elementFlags.Contains( wxT(
"onsolder" ) ) )
1607 footprint->AutoPositionFields();
1609 return footprint.release();
1618 int paramCnt = aParameters.GetCount();
1624 aParameters[2].ToLong( &layerNum );
1629 layerName = aParameters[3];
1638 int layerCount =
static_cast<int>( layerNum );
1644 wxArrayString parameters;
1645 double conv_unit = aConvUnit;
1652 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1655 if( parameters[0] == wxT(
")" ) )
1658 paramCnt = parameters.GetCount();
1662 if( parameters[1] == wxT(
"(" ) )
1669 if( parameters[0].CmpNoCase( wxT(
"Line" ) ) == 0 )
1674 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1675 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1676 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1677 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1678 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1704 if( parameters[0].CmpNoCase( wxT(
"Arc" ) ) == 0 )
1709 int cx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1710 int cy =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1711 int arcWidth =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1712 int arcHeight =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1713 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1714 int radius = ( arcWidth + arcHeight ) / 2;
1734 arc->
SetStart( arcStart + centre );
1737 RotatePoint( arcMid, -start_angle - sweep_angle / 2 );
1738 arc->
SetMid( arcMid + centre );
1741 RotatePoint( arcEnd, -start_angle - sweep_angle );
1742 arc->
SetEnd( arcEnd + centre );
1762 shape->
SetStart( arcStart + centre );
1774 if( parameters[0].CmpNoCase( wxT(
"Polygon" ) ) == 0 )
1782 const int outlineIdx = -1;
1783 bool parsingPoints =
false;
1787 wxArrayString polyParams;
1790 if( polyParams.IsEmpty() )
1793 if( polyParams[0] == wxT(
")" ) )
1796 if( polyParams[0] == wxT(
"(" ) )
1798 parsingPoints =
true;
1802 if( !parsingPoints )
1806 for(
size_t i = 0; i < polyParams.GetCount(); i++ )
1808 if( polyParams[i] == wxT(
"[" ) && i + 2 < polyParams.GetCount() )
1810 int px =
static_cast<int>(
parseInt( polyParams[i + 1], conv_unit ) );
1811 int py =
static_cast<int>(
parseInt( polyParams[i + 2], conv_unit ) );
1832 if( parameters[0].CmpNoCase( wxT(
"Text" ) ) == 0 )
1838 text->SetLayer( kicadLayer );
1840 int tx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1841 int ty =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1845 parameters[4].ToLong( &direction );
1848 text->SetTextAngle( textAngle );
1851 parameters[5].ToLong( &
scale );
1856 text->SetText( parameters[6] );
1873 std::map<wxString, FOOTPRINT*> fpByRef;
1876 fpByRef[fp->GetReference()] = fp;
1878 wxArrayString parameters;
1885 if( parameters.IsEmpty() )
1888 if( parameters[0] == wxT(
")" ) )
1891 if( parameters[0] == wxT(
"(" ) )
1895 if( parameters[0].CmpNoCase( wxT(
"Net" ) ) == 0 )
1899 if( parameters.GetCount() > 3 )
1900 netName = parameters[2];
1904 auto it =
m_netMap.find( netName );
1908 netInfo = it->second;
1920 wxArrayString netParams;
1923 if( netParams.IsEmpty() )
1926 if( netParams[0] == wxT(
")" ) )
1929 if( netParams[0] == wxT(
"(" ) )
1933 if( netParams[0].CmpNoCase( wxT(
"Connect" ) ) == 0 && netParams.GetCount() > 3 )
1935 wxString connectStr = netParams[2];
1938 int lastDash = connectStr.Find(
'-',
true );
1940 if( lastDash == wxNOT_FOUND )
1943 wxString refdes = connectStr.Left( lastDash );
1944 wxString pinNumber = connectStr.Mid( lastDash + 1 );
1946 auto fpIt = fpByRef.find( refdes );
1948 if( fpIt == fpByRef.end() )
1951 for(
PAD*
pad : fpIt->second->Pads() )
1953 if(
pad->GetNumber() == pinNumber )
1955 pad->SetNet( netInfo );
1967 const std::map<std::string, UTF8>* aProperties,
1972 init( aProperties );
1977 m_board->SetFileName( aFileName );
1979 std::unique_ptr<BOARD> deleter( aAppendToMe ?
nullptr :
m_board );
1994 wxArrayString parameters;
1997 if( parameters.IsEmpty() )
2000 int paramCnt = parameters.GetCount();
2004 if( parameters[1] == wxT(
"(" ) )
2011 if( parameters[0].CmpNoCase( wxT(
"PCB" ) ) == 0 )
2015 int boardWidth =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
2016 int boardHeight =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
2019 VECTOR2I pageSize( boardWidth, boardHeight );
2023 m_board->SetPageSettings( page );
2030 if( parameters[0].CmpNoCase( wxT(
"FileVersion" ) ) == 0 )
2034 if( parameters[0].CmpNoCase( wxT(
"Grid" ) ) == 0
2035 || parameters[0].CmpNoCase( wxT(
"Cursor" ) ) == 0
2036 || parameters[0].CmpNoCase( wxT(
"Thermal" ) ) == 0
2037 || parameters[0].CmpNoCase( wxT(
"DRC" ) ) == 0
2038 || parameters[0].CmpNoCase( wxT(
"Flags" ) ) == 0
2039 || parameters[0].CmpNoCase( wxT(
"Groups" ) ) == 0
2040 || parameters[0].CmpNoCase( wxT(
"Styles" ) ) == 0
2041 || parameters[0].CmpNoCase( wxT(
"Attribute" ) ) == 0 )
2047 if( parameters[0].CmpNoCase( wxT(
"Via" ) ) == 0 )
2054 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) == 0 )
2072 if( parameters[0].CmpNoCase( wxT(
"Layer" ) ) == 0 )
2074 parseLayer( parameters, &reader, conv_unit );
2079 if( parameters[0].CmpNoCase( wxT(
"Rat" ) ) == 0 )
2083 if( parameters[0].CmpNoCase( wxT(
"NetList" ) ) == 0 )
2104 m_board->m_LegacyDesignSettingsLoaded =
true;
2105 m_board->m_LegacyNetclassesLoaded =
true;
2114 std::vector<FOOTPRINT*> retval;
2117 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)
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
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)
void SetCenter(const VECTOR2I &aCenter)
void SetStart(const VECTOR2I &aStart)
void SetShape(SHAPE_T aShape)
void SetEnd(const VECTOR2I &aEnd)
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
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.
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 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...
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
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 #PLUGIN 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 parseNetList(LINE_READER *aLineReader)
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
Checks if this PCB_IO can read the specified board file.
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...
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)
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
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.
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
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
Checks if this PCB_IO can read the specified board file.
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 Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
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)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetIsFilled(bool isFilled)
bool AppendCorner(VECTOR2I aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
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
static const std::string GedaPcbFootprintLibFileExtension
static const std::string KiCadFootprintFileExtension
const wxChar *const traceGedaPcbPlugin
Flag to enable GEDA PCB plugin debug output.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
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 From_UTF8(const char *cstring)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
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.