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() )
107 THROW_IO_ERROR( wxString::Format(
_(
"Cannot convert '%s' to an integer." ),
108 aValue.GetData() ) );
111 return KiROUND( value * aScalar );
115#define TEXT_DEFAULT_SIZE ( 40 * pcbIUScale.IU_PER_MILS )
116#define OLD_GPCB_UNIT_CONV pcbIUScale.IU_PER_MILS
117#define NEW_GPCB_UNIT_CONV ( 0.01 * pcbIUScale.IU_PER_MILS )
162 void Remove(
const wxString& aFootprintName );
170 static long long GetTimestamp(
const wxString& aLibPath );
190 bool testFlags(
const wxString& aFlag,
long aMask,
const wxChar* aName );
241 if( !dir.IsOpened() )
243 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' not found." ),
254 if( !dir.GetFirst( &fullName, fileSpec ) )
257 wxString cacheErrorMsg;
277 if( !cacheErrorMsg.IsEmpty() )
278 cacheErrorMsg += wxT(
"\n\n" );
280 cacheErrorMsg += ioe.
What();
282 }
while( dir.GetNext( &fullName ) );
284 if( !cacheErrorMsg.IsEmpty() )
291 std::string footprintName =
TO_UTF8( aFootprintName );
297 THROW_IO_ERROR( wxString::Format(
_(
"Library '%s' has no footprint '%s'." ),
299 aFootprintName.GetData() ) );
303 wxString fullPath = it->second->GetFileName().GetFullPath();
305 wxRemoveFile( fullPath );
332 wxArrayString parameters;
333 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
nullptr );
335 if( aLineReader->
ReadLine() ==
nullptr )
337 msg = aLineReader->
GetSource() + wxT(
": empty file" );
343 paramCnt = parameters.GetCount();
353 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) != 0 )
355 msg.Printf(
_(
"Unknown token '%s'" ), parameters[0] );
360 if( paramCnt < 10 || paramCnt > 14 )
362 msg.Printf(
_(
"Element token contains %d parameters." ), paramCnt );
368 if( parameters[1] == wxT(
"(" ) )
373 footprint->SetLibDescription( parameters[3] );
374 footprint->SetReference( parameters[4] );
378 footprint->SetLibDescription( parameters[2] );
379 footprint->SetReference( parameters[3] );
384 footprint->SetValue( parameters[5] );
388 if( footprint->Value().GetText().IsEmpty() )
389 footprint->Value().SetText( wxT(
"VAL**" ) );
391 if( footprint->Reference().GetText().IsEmpty() )
392 footprint->Reference().SetText( wxT(
"REF**" ) );
399 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
402 if( parameters[0] == wxT(
")" ) )
405 paramCnt = parameters.GetCount();
410 if( parameters[1] == wxT(
"(" ) )
417 parameters[0], paramCnt );
420 if( parameters[0].CmpNoCase( wxT(
"ElementLine" ) ) == 0 )
424 msg.Printf( wxT(
"ElementLine token contains %d parameters." ), paramCnt );
432 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) ) );
434 static_cast<int>(
parseInt( parameters[5], conv_unit ) ) ) );
438 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
439 shape->
Move( footprint->GetPosition() );
441 footprint->Add( shape );
446 if( parameters[0].CmpNoCase( wxT(
"ElementArc" ) ) == 0 )
450 msg.Printf( wxT(
"ElementArc token contains %d parameters." ), paramCnt );
458 footprint->Add( shape );
461 int radius =
static_cast<int>( (
parseInt( parameters[4], conv_unit ) +
462 parseInt( parameters[5], conv_unit ) ) / 2 );
465 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
489 shape->
SetStart( arcStart + centre );
498 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
499 shape->
Move( footprint->GetPosition() );
508 if( parameters[0].CmpNoCase( wxT(
"Pad" ) ) == 0 )
510 if( paramCnt < 10 || paramCnt > 13 )
512 msg.Printf( wxT(
"Pad token contains %d parameters." ), paramCnt );
517 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( footprint.get() );
524 pad->SetLayerSet( pad_front );
526 if(
testFlags( parameters[paramCnt-2], 0x0080, wxT(
"onsolder" ) ) )
527 pad->SetLayerSet( pad_back );
537 pad->SetNumber( parameters[paramCnt-3] );
539 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
540 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
541 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
542 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
543 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
545 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
559 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
560 maskMargin = ( maskMargin - width ) / 2;
561 pad->SetLocalSolderMaskMargin( maskMargin );
566 pad->SetOrientation( orient );
568 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
572 padPos += footprint->GetPosition();
573 pad->SetPosition( padPos );
575 if( !
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
583 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
585 footprint->Add(
pad.release() );
589 wxLogError(
_(
"Invalid zero-sized pad ignored in\nfile: %s" ),
602 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
604 if( paramCnt < 8 || paramCnt > 12 )
606 msg.Printf( wxT(
"Pin token contains %d parameters." ), paramCnt );
617 pad->SetLayerSet( pad_set );
619 if(
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
626 pad->SetNumber( parameters[paramCnt-3] );
629 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
631 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
649 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
650 maskMargin = ( maskMargin - padSize ) / 2;
651 pad->SetLocalSolderMaskMargin( maskMargin );
653 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
657 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
660 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
662 padPos += footprint->GetPosition();
663 pad->SetPosition( padPos );
671 footprint->Add(
pad );
676 footprint->AutoPositionFields();
678 return footprint.release();
686 char* line = aLineReader->
Line();
700 aParameterList.Add( tmp );
705 aParameterList.Add( tmp );
710 if( aParameterList.GetCount() == 1 )
722 aParameterList.Add( tmp );
727 aParameterList.Add( tmp );
741 aParameterList.Add( tmp );
753 aParameterList.Add( wxEmptyString );
764 aParameterList.Add( tmp );
796 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
800 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
803 else if( aFlag.Contains( aName ) )
824 m_ctl( aControlFlags ),
860 wxString& aFootprintNameOut,
861 const std::map<std::string, UTF8>* aProperties )
863 wxFileName fn( aFootprintPath );
869 char* line = reader.
Line();
874 if( strncasecmp( line,
"Element", strlen(
"Element" ) ) != 0 )
877 aFootprintNameOut = fn.GetName();
884 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
886 wxDir dir( aLibraryPath );
889 if( !dir.IsOpened() )
894 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' not found." ), aLibraryPath ) );
905 errorMsg = ioe.
What();
911 for(
const auto& footprint :
m_cache->GetFootprints() )
912 aFootprintNames.Add(
From_UTF8( footprint.first.c_str() ) );
914 if( !errorMsg.IsEmpty() && !aBestEfforts )
920 const wxString& aFootprintName,
921 const std::map<std::string, UTF8>* aProperties,
928 auto it =
m_cache->GetFootprints().find(
TO_UTF8( aFootprintName ) );
930 if( it ==
m_cache->GetFootprints().end() )
933 return it->second->GetFootprint().get();
938 const wxString& aFootprintName,
940 const std::map<std::string, UTF8>* aProperties )
950 copy->SetParent(
nullptr );
959 const std::map<std::string, UTF8>* aProperties )
968 aLibraryPath.GetData() ) );
971 m_cache->Remove( aFootprintName );
978 fn.SetPath( aLibraryPath );
981 if( !fn.DirExists() )
984 if( !fn.IsDirWritable() )
986 THROW_IO_ERROR( wxString::Format(
_(
"Insufficient permissions to delete folder '%s'." ),
987 aLibraryPath.GetData() ) );
990 wxDir dir( aLibraryPath );
992 if( dir.HasSubDirs() )
994 THROW_IO_ERROR( wxString::Format(
_(
"Library folder '%s' has unexpected sub-folders." ),
995 aLibraryPath.GetData() ) );
1003 wxArrayString files;
1007 for( i = 0; i < files.GetCount(); i++ )
1013 THROW_IO_ERROR( wxString::Format(
_(
"Unexpected file '%s' found in library '%s'." ),
1015 aLibraryPath.GetData() ) );
1019 for( i = 0; i < files.GetCount(); i++ )
1021 wxRemoveFile( files[i] );
1026 aLibraryPath.GetData() );
1030 if( !wxRmdir( aLibraryPath ) )
1032 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' cannot be deleted." ),
1033 aLibraryPath.GetData() ) );
1040 wxMilliSleep( 250L );
1078 char* line = aLineReader->
Line();
1089 if( !tmp.IsEmpty() )
1091 aParameterList.Add( tmp );
1096 aParameterList.Add( tmp );
1099 if( aParameterList.GetCount() == 1 )
1109 if( !tmp.IsEmpty() )
1111 aParameterList.Add( tmp );
1116 aParameterList.Add( tmp );
1131 if( !tmp.IsEmpty() )
1133 aParameterList.Add( tmp );
1144 aParameterList.Add( wxEmptyString );
1155 aParameterList.Add( tmp );
1187 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
1191 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
1194 else if( aFlag.Contains( aName ) )
1208 wxFileInputStream input( aFileName );
1213 wxTextInputStream
text( input );
1215 for(
int i = 0; i < 20; i++ )
1220 wxString line =
text.ReadLine();
1222 if( line.Contains( wxS(
"PCB[" ) ) || line.Contains( wxS(
"PCB(" ) ) )
1232 wxString
name = aLayerName.Lower();
1234 if(
name.Contains( wxT(
"outline" ) ) ||
name.Contains( wxT(
"route" ) ) )
1237 if(
name.Contains( wxT(
"silk" ) ) )
1239 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1245 if(
name.Contains( wxT(
"mask" ) ) )
1247 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1253 if(
name.Contains( wxT(
"paste" ) ) )
1255 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1261 if(
name.Contains( wxT(
"fab" ) ) )
1265 if(
name.Contains( wxT(
"component" ) ) ||
name.Contains( wxT(
"top" ) )
1266 || ( aGedaLayer == 1 && !
name.Contains( wxT(
"solder" ) ) ) )
1271 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) )
1272 || aGedaLayer == 2 )
1278 if( aGedaLayer >= 3 && aGedaLayer <= 16 )
1280 int innerIdx = aGedaLayer - 3;
1286 return innerLayers[innerIdx];
1296 int paramCnt = aParameters.GetCount();
1301 _(
"Via token contains %d parameters, expected at least 10." ), paramCnt ) );
1306 int x =
static_cast<int>(
parseInt( aParameters[2], aConvUnit ) );
1307 int y =
static_cast<int>(
parseInt( aParameters[3], aConvUnit ) );
1308 int thickness =
static_cast<int>(
parseInt( aParameters[4], aConvUnit ) );
1309 int drill =
static_cast<int>(
parseInt( aParameters[7], aConvUnit ) );
1313 via->SetDrill( drill );
1325 int paramCnt = aParameters.GetCount();
1326 double conv_unit = aConvUnit;
1329 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
m_board );
1331 if( paramCnt < 10 || paramCnt > 14 )
1333 msg.Printf(
_(
"Element token contains %d parameters." ), paramCnt );
1340 int descIdx, nameIdx, valueIdx, mxIdx;
1357 footprint->SetLibDescription( aParameters[descIdx] );
1358 footprint->SetReference( aParameters[nameIdx] );
1361 footprint->SetValue( aParameters[valueIdx] );
1363 if( footprint->Value().GetText().IsEmpty() )
1364 footprint->Value().SetText( wxT(
"VAL**" ) );
1366 if( footprint->Reference().GetText().IsEmpty() )
1367 footprint->Reference().SetText( wxT(
"REF**" ) );
1370 if( mxIdx > 0 && paramCnt > 12 )
1372 int mx =
static_cast<int>(
parseInt( aParameters[mxIdx], conv_unit ) );
1373 int my =
static_cast<int>(
parseInt( aParameters[mxIdx + 1], conv_unit ) );
1374 footprint->SetPosition(
VECTOR2I( mx, my ) );
1377 wxArrayString parameters;
1384 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1387 if( parameters[0] == wxT(
")" ) )
1390 paramCnt = parameters.GetCount();
1394 if( parameters[1] == wxT(
"(" ) )
1401 if( parameters[0].CmpNoCase( wxT(
"ElementLine" ) ) == 0 )
1409 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) ) );
1411 static_cast<int>(
parseInt( parameters[5], conv_unit ) ) ) );
1415 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
1416 shape->
Move( footprint->GetPosition() );
1418 footprint->Add( shape );
1423 if( parameters[0].CmpNoCase( wxT(
"ElementArc" ) ) == 0 )
1425 if( paramCnt != 10 )
1430 footprint->Add( shape );
1432 int radius =
static_cast<int>( (
parseInt( parameters[4], conv_unit )
1433 +
parseInt( parameters[5], conv_unit ) ) / 2 );
1436 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1456 shape->
SetStart( arcStart + centre );
1463 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
1464 shape->
Move( footprint->GetPosition() );
1469 if( parameters[0].CmpNoCase( wxT(
"Pad" ) ) == 0 )
1471 if( paramCnt < 10 || paramCnt > 13 )
1474 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( footprint.get() );
1481 pad->SetLayerSet( pad_front );
1483 if(
testFlags( parameters[paramCnt - 2], 0x0080, wxT(
"onsolder" ) ) )
1484 pad->SetLayerSet( pad_back );
1486 pad->SetNumber( parameters[paramCnt - 3] );
1488 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1489 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1490 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1491 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1492 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1494 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
1496 if( paramCnt == 13 )
1501 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
1502 maskMargin = ( maskMargin - width ) / 2;
1503 pad->SetLocalSolderMaskMargin( maskMargin );
1507 pad->SetOrientation( orient );
1509 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
1514 padPos += footprint->GetPosition();
1515 pad->SetPosition( padPos );
1517 if( !
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1530 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
1531 footprint->Add(
pad.release() );
1537 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
1539 if( paramCnt < 8 || paramCnt > 12 )
1549 pad->SetLayerSet( pad_set );
1551 if(
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1554 pad->SetNumber( parameters[paramCnt - 3] );
1557 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1559 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1564 if( paramCnt == 12 )
1569 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1570 maskMargin = ( maskMargin - padSize ) / 2;
1571 pad->SetLocalSolderMaskMargin( maskMargin );
1573 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
1577 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1580 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
1582 padPos += footprint->GetPosition();
1583 pad->SetPosition( padPos );
1592 footprint->Add(
pad );
1599 wxString elementFlags = aParameters[2];
1601 if( elementFlags.Contains( wxT(
"onsolder" ) ) )
1604 footprint->AutoPositionFields();
1606 return footprint.release();
1615 int paramCnt = aParameters.GetCount();
1621 aParameters[2].ToLong( &layerNum );
1626 layerName = aParameters[3];
1635 int layerCount =
static_cast<int>( layerNum );
1641 wxArrayString parameters;
1642 double conv_unit = aConvUnit;
1649 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1652 if( parameters[0] == wxT(
")" ) )
1655 paramCnt = parameters.GetCount();
1659 if( parameters[1] == wxT(
"(" ) )
1666 if( parameters[0].CmpNoCase( wxT(
"Line" ) ) == 0 )
1671 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1672 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1673 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1674 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1675 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1701 if( parameters[0].CmpNoCase( wxT(
"Arc" ) ) == 0 )
1706 int cx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1707 int cy =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1708 int arcWidth =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1709 int arcHeight =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1710 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1711 int radius = ( arcWidth + arcHeight ) / 2;
1731 arc->
SetStart( arcStart + centre );
1734 RotatePoint( arcMid, -start_angle - sweep_angle / 2 );
1735 arc->
SetMid( arcMid + centre );
1738 RotatePoint( arcEnd, -start_angle - sweep_angle );
1739 arc->
SetEnd( arcEnd + centre );
1759 shape->
SetStart( arcStart + centre );
1771 if( parameters[0].CmpNoCase( wxT(
"Polygon" ) ) == 0 )
1779 const int outlineIdx = -1;
1780 bool parsingPoints =
false;
1784 wxArrayString polyParams;
1787 if( polyParams.IsEmpty() )
1790 if( polyParams[0] == wxT(
")" ) )
1793 if( polyParams[0] == wxT(
"(" ) )
1795 parsingPoints =
true;
1799 if( !parsingPoints )
1803 for(
size_t i = 0; i < polyParams.GetCount(); i++ )
1805 if( polyParams[i] == wxT(
"[" ) && i + 2 < polyParams.GetCount() )
1807 int px =
static_cast<int>(
parseInt( polyParams[i + 1], conv_unit ) );
1808 int py =
static_cast<int>(
parseInt( polyParams[i + 2], conv_unit ) );
1829 if( parameters[0].CmpNoCase( wxT(
"Text" ) ) == 0 )
1835 text->SetLayer( kicadLayer );
1837 int tx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1838 int ty =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1842 parameters[4].ToLong( &direction );
1845 text->SetTextAngle( textAngle );
1848 parameters[5].ToLong( &
scale );
1853 text->SetText( parameters[6] );
1870 std::map<wxString, FOOTPRINT*> fpByRef;
1873 fpByRef[fp->GetReference()] = fp;
1875 wxArrayString parameters;
1882 if( parameters.IsEmpty() )
1885 if( parameters[0] == wxT(
")" ) )
1888 if( parameters[0] == wxT(
"(" ) )
1892 if( parameters[0].CmpNoCase( wxT(
"Net" ) ) == 0 )
1896 if( parameters.GetCount() > 3 )
1897 netName = parameters[2];
1901 auto it =
m_netMap.find( netName );
1905 netInfo = it->second;
1917 wxArrayString netParams;
1920 if( netParams.IsEmpty() )
1923 if( netParams[0] == wxT(
")" ) )
1926 if( netParams[0] == wxT(
"(" ) )
1930 if( netParams[0].CmpNoCase( wxT(
"Connect" ) ) == 0 && netParams.GetCount() > 3 )
1932 wxString connectStr = netParams[2];
1935 int lastDash = connectStr.Find(
'-',
true );
1937 if( lastDash == wxNOT_FOUND )
1940 wxString refdes = connectStr.Left( lastDash );
1941 wxString pinNumber = connectStr.Mid( lastDash + 1 );
1943 auto fpIt = fpByRef.find( refdes );
1945 if( fpIt == fpByRef.end() )
1948 for(
PAD*
pad : fpIt->second->Pads() )
1950 if(
pad->GetNumber() == pinNumber )
1952 pad->SetNet( netInfo );
1964 const std::map<std::string, UTF8>* aProperties,
1969 init( aProperties );
1974 m_board->SetFileName( aFileName );
1976 std::unique_ptr<BOARD> deleter( aAppendToMe ?
nullptr :
m_board );
1991 wxArrayString parameters;
1994 if( parameters.IsEmpty() )
1997 int paramCnt = parameters.GetCount();
2001 if( parameters[1] == wxT(
"(" ) )
2008 if( parameters[0].CmpNoCase( wxT(
"PCB" ) ) == 0 )
2012 int boardWidth =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
2013 int boardHeight =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
2016 VECTOR2I pageSize( boardWidth, boardHeight );
2020 m_board->SetPageSettings( page );
2027 if( parameters[0].CmpNoCase( wxT(
"FileVersion" ) ) == 0 )
2031 if( parameters[0].CmpNoCase( wxT(
"Grid" ) ) == 0
2032 || parameters[0].CmpNoCase( wxT(
"Cursor" ) ) == 0
2033 || parameters[0].CmpNoCase( wxT(
"Thermal" ) ) == 0
2034 || parameters[0].CmpNoCase( wxT(
"DRC" ) ) == 0
2035 || parameters[0].CmpNoCase( wxT(
"Flags" ) ) == 0
2036 || parameters[0].CmpNoCase( wxT(
"Groups" ) ) == 0
2037 || parameters[0].CmpNoCase( wxT(
"Styles" ) ) == 0
2038 || parameters[0].CmpNoCase( wxT(
"Attribute" ) ) == 0 )
2044 if( parameters[0].CmpNoCase( wxT(
"Via" ) ) == 0 )
2051 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) == 0 )
2069 if( parameters[0].CmpNoCase( wxT(
"Layer" ) ) == 0 )
2071 parseLayer( parameters, &reader, conv_unit );
2076 if( parameters[0].CmpNoCase( wxT(
"Rat" ) ) == 0 )
2080 if( parameters[0].CmpNoCase( wxT(
"NetList" ) ) == 0 )
2101 m_board->m_LegacyDesignSettingsLoaded =
true;
2102 m_board->m_LegacyNetclassesLoaded =
true;
2111 std::vector<FOOTPRINT*> retval;
2114 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)
void SetCenter(const VECTOR2I &aCenter)
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 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...
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 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)
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)
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
void CollectFilesLoopSafe(const wxString &aRoot, wxArrayString &aFiles, const wxString &aFileSpec, int aFlags)
Recursively collect every file under aRoot, deduplicating subdirectories by their resolved path.
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.