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() );
515 pad->SetLayerSet( pad_front );
517 if(
testFlags( parameters[paramCnt-2], 0x0080, wxT(
"onsolder" ) ) )
518 pad->SetLayerSet( pad_back );
528 pad->SetNumber( parameters[paramCnt-3] );
530 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
531 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
532 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
533 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
534 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
536 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
550 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
551 maskMargin = ( maskMargin - width ) / 2;
552 pad->SetLocalSolderMaskMargin( maskMargin );
557 pad->SetOrientation( orient );
559 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
563 padPos += footprint->GetPosition();
564 pad->SetPosition( padPos );
566 if( !
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
574 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
576 footprint->Add(
pad.release() );
580 m_owner->Report( wxString::Format(
_(
"Invalid zero-sized pad ignored in\n"
595 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
597 if( paramCnt < 8 || paramCnt > 12 )
599 msg.Printf( wxT(
"Pin token contains %d parameters." ), paramCnt );
610 pad->SetLayerSet( pad_set );
612 if(
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
619 pad->SetNumber( parameters[paramCnt-3] );
622 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
624 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
642 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
643 maskMargin = ( maskMargin - padSize ) / 2;
644 pad->SetLocalSolderMaskMargin( maskMargin );
646 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
650 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
653 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
655 padPos += footprint->GetPosition();
656 pad->SetPosition( padPos );
664 footprint->Add(
pad );
669 footprint->AutoPositionFields();
671 return footprint.release();
679 char* line = aLineReader->
Line();
693 aParameterList.Add( tmp );
698 aParameterList.Add( tmp );
703 if( aParameterList.GetCount() == 1 )
715 aParameterList.Add( tmp );
720 aParameterList.Add( tmp );
734 aParameterList.Add( tmp );
746 aParameterList.Add( wxEmptyString );
757 aParameterList.Add( tmp );
789 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
793 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
796 else if( aFlag.Contains( aName ) )
817 m_ctl( aControlFlags ),
853 wxString& aFootprintNameOut,
854 const std::map<std::string, UTF8>* aProperties )
856 wxFileName fn( aFootprintPath );
862 char* line = reader.
Line();
867 if( strncasecmp( line,
"Element", strlen(
"Element" ) ) != 0 )
870 aFootprintNameOut = fn.GetName();
877 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
879 wxDir dir( aLibraryPath );
882 if( !dir.IsOpened() )
898 errorMsg = ioe.
What();
904 for(
const auto& footprint :
m_cache->GetFootprints() )
905 aFootprintNames.Add(
From_UTF8( footprint.first.c_str() ) );
907 if( !errorMsg.IsEmpty() && !aBestEfforts )
913 const wxString& aFootprintName,
914 const std::map<std::string, UTF8>* aProperties,
921 auto it =
m_cache->GetFootprints().find(
TO_UTF8( aFootprintName ) );
923 if( it ==
m_cache->GetFootprints().end() )
926 return it->second->GetFootprint().get();
931 const wxString& aFootprintName,
933 const std::map<std::string, UTF8>* aProperties )
943 copy->SetParent(
nullptr );
952 const std::map<std::string, UTF8>* aProperties )
959 THROW_IO_ERRORF(
_(
"Library '%s' is read only." ), aLibraryPath.GetData() );
961 m_cache->Remove( aFootprintName );
968 fn.SetPath( aLibraryPath );
971 if( !fn.DirExists() )
974 if( !fn.IsDirWritable() )
975 THROW_IO_ERRORF(
_(
"Insufficient permissions to delete folder '%s'." ), aLibraryPath.GetData() );
977 wxDir dir( aLibraryPath );
979 if( dir.HasSubDirs() )
980 THROW_IO_ERRORF(
_(
"Library folder '%s' has unexpected sub-folders." ), aLibraryPath.GetData() );
990 for(
unsigned i = 0; i < files.GetCount(); i++ )
998 aLibraryPath.GetData() );
1002 for(
unsigned i = 0; i < files.GetCount(); i++ )
1003 wxRemoveFile( files[i] );
1006 wxLogTrace(
traceGedaPcbPlugin, wxT(
"Removing footprint library '%s'" ), aLibraryPath.GetData() );
1010 if( !wxRmdir( aLibraryPath ) )
1011 THROW_IO_ERRORF(
_(
"Footprint library '%s' cannot be deleted." ), aLibraryPath.GetData() );
1017 wxMilliSleep( 250L );
1055 char* line = aLineReader->
Line();
1066 if( !tmp.IsEmpty() )
1068 aParameterList.Add( tmp );
1073 aParameterList.Add( tmp );
1076 if( aParameterList.GetCount() == 1 )
1086 if( !tmp.IsEmpty() )
1088 aParameterList.Add( tmp );
1093 aParameterList.Add( tmp );
1108 if( !tmp.IsEmpty() )
1110 aParameterList.Add( tmp );
1121 aParameterList.Add( wxEmptyString );
1132 aParameterList.Add( tmp );
1164 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
1168 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
1171 else if( aFlag.Contains( aName ) )
1185 wxFileInputStream input( aFileName );
1190 wxTextInputStream
text( input );
1192 for(
int i = 0; i < 20; i++ )
1197 wxString line =
text.ReadLine();
1199 if( line.Contains( wxS(
"PCB[" ) ) || line.Contains( wxS(
"PCB(" ) ) )
1209 wxString
name = aLayerName.Lower();
1211 if(
name.Contains( wxT(
"outline" ) ) ||
name.Contains( wxT(
"route" ) ) )
1214 if(
name.Contains( wxT(
"silk" ) ) )
1216 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1222 if(
name.Contains( wxT(
"mask" ) ) )
1224 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1230 if(
name.Contains( wxT(
"paste" ) ) )
1232 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1238 if(
name.Contains( wxT(
"fab" ) ) )
1242 if(
name.Contains( wxT(
"component" ) ) ||
name.Contains( wxT(
"top" ) )
1243 || ( aGedaLayer == 1 && !
name.Contains( wxT(
"solder" ) ) ) )
1248 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) )
1249 || aGedaLayer == 2 )
1255 if( aGedaLayer >= 3 && aGedaLayer <= 16 )
1257 int innerIdx = aGedaLayer - 3;
1263 return innerLayers[innerIdx];
1273 int paramCnt = aParameters.GetCount();
1276 THROW_IO_ERRORF(
_(
"Via token contains %d parameters, expected at least 10." ), paramCnt );
1280 int x =
static_cast<int>(
parseInt( aParameters[2], aConvUnit ) );
1281 int y =
static_cast<int>(
parseInt( aParameters[3], aConvUnit ) );
1282 int thickness =
static_cast<int>(
parseInt( aParameters[4], aConvUnit ) );
1283 int drill =
static_cast<int>(
parseInt( aParameters[7], aConvUnit ) );
1287 via->SetDrill( drill );
1298 int paramCnt = aParameters.GetCount();
1299 double conv_unit = aConvUnit;
1301 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
m_board );
1303 if( paramCnt < 10 || paramCnt > 14 )
1309 int descIdx, nameIdx, valueIdx, mxIdx;
1326 footprint->SetLibDescription( aParameters[descIdx] );
1327 footprint->SetReference( aParameters[nameIdx] );
1330 footprint->SetValue( aParameters[valueIdx] );
1332 if( footprint->Value().GetText().IsEmpty() )
1333 footprint->Value().SetText( wxT(
"VAL**" ) );
1335 if( footprint->Reference().GetText().IsEmpty() )
1336 footprint->Reference().SetText( wxT(
"REF**" ) );
1339 if( mxIdx > 0 && paramCnt > 12 )
1341 int mx =
static_cast<int>(
parseInt( aParameters[mxIdx], conv_unit ) );
1342 int my =
static_cast<int>(
parseInt( aParameters[mxIdx + 1], conv_unit ) );
1343 footprint->SetPosition(
VECTOR2I( mx, my ) );
1346 wxArrayString parameters;
1353 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1356 if( parameters[0] == wxT(
")" ) )
1359 paramCnt = parameters.GetCount();
1363 if( parameters[1] == wxT(
"(" ) )
1370 if( parameters[0].CmpNoCase( wxT(
"ElementLine" ) ) == 0 )
1378 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) ) );
1380 static_cast<int>(
parseInt( parameters[5], conv_unit ) ) ) );
1384 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
1385 shape->
Move( footprint->GetPosition() );
1387 footprint->Add( shape );
1392 if( parameters[0].CmpNoCase( wxT(
"ElementArc" ) ) == 0 )
1394 if( paramCnt != 10 )
1399 footprint->Add( shape );
1401 int radius =
static_cast<int>( (
parseInt( parameters[4], conv_unit )
1402 +
parseInt( parameters[5], conv_unit ) ) / 2 );
1405 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1423 shape->
SetStart( arcStart + centre );
1430 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
1431 shape->
Move( footprint->GetPosition() );
1436 if( parameters[0].CmpNoCase( wxT(
"Pad" ) ) == 0 )
1438 if( paramCnt < 10 || paramCnt > 13 )
1441 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( footprint.get() );
1448 pad->SetLayerSet( pad_front );
1450 if(
testFlags( parameters[paramCnt - 2], 0x0080, wxT(
"onsolder" ) ) )
1451 pad->SetLayerSet( pad_back );
1453 pad->SetNumber( parameters[paramCnt - 3] );
1455 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1456 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1457 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1458 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1459 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1461 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
1463 if( paramCnt == 13 )
1468 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
1469 maskMargin = ( maskMargin - width ) / 2;
1470 pad->SetLocalSolderMaskMargin( maskMargin );
1474 pad->SetOrientation( orient );
1476 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
1480 padPos += footprint->GetPosition();
1481 pad->SetPosition( padPos );
1483 if( !
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1491 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
1492 footprint->Add(
pad.release() );
1498 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
1500 if( paramCnt < 8 || paramCnt > 12 )
1509 pad->SetLayerSet( pad_set );
1511 if(
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1514 pad->SetNumber( parameters[paramCnt - 3] );
1517 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1519 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1524 if( paramCnt == 12 )
1529 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1530 maskMargin = ( maskMargin - padSize ) / 2;
1531 pad->SetLocalSolderMaskMargin( maskMargin );
1533 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
1537 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1540 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
1542 padPos += footprint->GetPosition();
1543 pad->SetPosition( padPos );
1551 footprint->Add(
pad );
1558 wxString elementFlags = aParameters[2];
1560 if( elementFlags.Contains( wxT(
"onsolder" ) ) )
1563 footprint->AutoPositionFields();
1565 return footprint.release();
1573 int paramCnt = aParameters.GetCount();
1579 aParameters[2].ToLong( &layerNum );
1584 layerName = aParameters[3];
1593 int layerCount =
static_cast<int>( layerNum );
1599 wxArrayString parameters;
1600 double conv_unit = aConvUnit;
1607 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1610 if( parameters[0] == wxT(
")" ) )
1613 paramCnt = parameters.GetCount();
1617 if( parameters[1] == wxT(
"(" ) )
1624 if( parameters[0].CmpNoCase( wxT(
"Line" ) ) == 0 )
1629 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1630 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1631 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1632 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1633 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1659 if( parameters[0].CmpNoCase( wxT(
"Arc" ) ) == 0 )
1664 int cx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1665 int cy =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1666 int arcWidth =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1667 int arcHeight =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1668 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1669 int radius = ( arcWidth + arcHeight ) / 2;
1687 arc->
SetStart( arcStart + centre );
1690 RotatePoint( arcMid, -start_angle - sweep_angle / 2 );
1691 arc->
SetMid( arcMid + centre );
1694 RotatePoint( arcEnd, -start_angle - sweep_angle );
1695 arc->
SetEnd( arcEnd + centre );
1715 shape->
SetStart( arcStart + centre );
1727 if( parameters[0].CmpNoCase( wxT(
"Polygon" ) ) == 0 )
1735 const int outlineIdx = -1;
1736 bool parsingPoints =
false;
1740 wxArrayString polyParams;
1743 if( polyParams.IsEmpty() )
1746 if( polyParams[0] == wxT(
")" ) )
1749 if( polyParams[0] == wxT(
"(" ) )
1751 parsingPoints =
true;
1755 if( !parsingPoints )
1759 for(
size_t i = 0; i < polyParams.GetCount(); i++ )
1761 if( polyParams[i] == wxT(
"[" ) && i + 2 < polyParams.GetCount() )
1763 int px =
static_cast<int>(
parseInt( polyParams[i + 1], conv_unit ) );
1764 int py =
static_cast<int>(
parseInt( polyParams[i + 2], conv_unit ) );
1785 if( parameters[0].CmpNoCase( wxT(
"Text" ) ) == 0 )
1791 text->SetLayer( kicadLayer );
1793 int tx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1794 int ty =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1798 parameters[4].ToLong( &direction );
1801 text->SetTextAngle( textAngle );
1804 parameters[5].ToLong( &
scale );
1809 text->SetText( parameters[6] );
1826 std::map<wxString, FOOTPRINT*> fpByRef;
1829 fpByRef[fp->GetReference()] = fp;
1831 wxArrayString parameters;
1838 if( parameters.IsEmpty() )
1841 if( parameters[0] == wxT(
")" ) )
1844 if( parameters[0] == wxT(
"(" ) )
1848 if( parameters[0].CmpNoCase( wxT(
"Net" ) ) == 0 )
1852 if( parameters.GetCount() > 3 )
1853 netName = parameters[2];
1857 auto it =
m_netMap.find( netName );
1861 netInfo = it->second;
1873 wxArrayString netParams;
1876 if( netParams.IsEmpty() )
1879 if( netParams[0] == wxT(
")" ) )
1882 if( netParams[0] == wxT(
"(" ) )
1886 if( netParams[0].CmpNoCase( wxT(
"Connect" ) ) == 0 && netParams.GetCount() > 3 )
1888 wxString connectStr = netParams[2];
1891 int lastDash = connectStr.Find(
'-',
true );
1893 if( lastDash == wxNOT_FOUND )
1896 wxString refdes = connectStr.Left( lastDash );
1897 wxString pinNumber = connectStr.Mid( lastDash + 1 );
1899 auto fpIt = fpByRef.find( refdes );
1901 if( fpIt == fpByRef.end() )
1904 for(
PAD*
pad : fpIt->second->Pads() )
1906 if(
pad->GetNumber() == pinNumber )
1908 pad->SetNet( netInfo );
1920 const std::map<std::string, UTF8>* aProperties,
1925 init( aProperties );
1930 m_board->SetFileName( aFileName );
1932 std::unique_ptr<BOARD> deleter( aAppendToMe ?
nullptr :
m_board );
1947 wxArrayString parameters;
1950 if( parameters.IsEmpty() )
1953 int paramCnt = parameters.GetCount();
1957 if( parameters[1] == wxT(
"(" ) )
1964 if( parameters[0].CmpNoCase( wxT(
"PCB" ) ) == 0 )
1968 int boardWidth =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1969 int boardHeight =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1972 VECTOR2I pageSize( boardWidth, boardHeight );
1976 m_board->SetPageSettings( page );
1983 if( parameters[0].CmpNoCase( wxT(
"FileVersion" ) ) == 0 )
1987 if( parameters[0].CmpNoCase( wxT(
"Grid" ) ) == 0
1988 || parameters[0].CmpNoCase( wxT(
"Cursor" ) ) == 0
1989 || parameters[0].CmpNoCase( wxT(
"Thermal" ) ) == 0
1990 || parameters[0].CmpNoCase( wxT(
"DRC" ) ) == 0
1991 || parameters[0].CmpNoCase( wxT(
"Flags" ) ) == 0
1992 || parameters[0].CmpNoCase( wxT(
"Groups" ) ) == 0
1993 || parameters[0].CmpNoCase( wxT(
"Styles" ) ) == 0
1994 || parameters[0].CmpNoCase( wxT(
"Attribute" ) ) == 0 )
2000 if( parameters[0].CmpNoCase( wxT(
"Via" ) ) == 0 )
2007 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) == 0 )
2025 if( parameters[0].CmpNoCase( wxT(
"Layer" ) ) == 0 )
2027 parseLayer( parameters, &reader, conv_unit );
2032 if( parameters[0].CmpNoCase( wxT(
"Rat" ) ) == 0 )
2036 if( parameters[0].CmpNoCase( wxT(
"NetList" ) ) == 0 )
2057 m_board->m_LegacyDesignSettingsLoaded =
true;
2058 m_board->m_LegacyNetclassesLoaded =
true;
2067 std::vector<FOOTPRINT*> retval;
2070 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_IO_ERRORF(msg,...)
#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.