60#include <wx/filename.h>
61#include <wx/txtstrm.h>
62#include <wx/wfstream.h>
63#include <boost/ptr_container/ptr_map.hpp>
67static inline long parseInt(
const wxString& aValue,
double aScalar )
69 double value = std::numeric_limits<double>::max();
92 if( aValue.EndsWith( wxT(
"mm" ) ) )
94 aScalar *= 100000.0 / 25.4;
96 else if( aValue.EndsWith( wxT(
"mil" ) ) )
103 aValue.ToCDouble(&value);
105 if( value == std::numeric_limits<double>::max() )
106 THROW_IO_ERRORF(
_(
"Cannot convert '%s' to an integer." ), aValue.GetData() );
108 return KiROUND( value * aScalar );
112#define TEXT_DEFAULT_SIZE ( 40 * pcbIUScale.IU_PER_MILS )
113#define OLD_GPCB_UNIT_CONV pcbIUScale.IU_PER_MILS
114#define NEW_GPCB_UNIT_CONV ( 0.01 * pcbIUScale.IU_PER_MILS )
159 void Remove(
const wxString& aFootprintName );
167 static long long GetTimestamp(
const wxString& aLibPath );
187 bool testFlags(
const wxString& aFlag,
long aMask,
const wxChar* aName );
238 if( !dir.IsOpened() )
248 if( !dir.GetFirst( &fullName, fileSpec ) )
251 wxString cacheErrorMsg;
271 if( !cacheErrorMsg.IsEmpty() )
272 cacheErrorMsg += wxT(
"\n\n" );
274 cacheErrorMsg += ioe.
What();
276 }
while( dir.GetNext( &fullName ) );
278 if( !cacheErrorMsg.IsEmpty() )
285 std::string footprintName =
TO_UTF8( aFootprintName );
293 aFootprintName.GetData() );
297 wxString fullPath = it->second->GetFileName().GetFullPath();
299 wxRemoveFile( fullPath );
326 wxArrayString parameters;
327 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
nullptr );
329 if( aLineReader->
ReadLine() ==
nullptr )
334 paramCnt = parameters.GetCount();
344 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) != 0 )
346 msg.Printf(
_(
"Unknown token '%s'" ), parameters[0] );
351 if( paramCnt < 10 || paramCnt > 14 )
353 msg.Printf(
_(
"Element token contains %d parameters." ), paramCnt );
359 if( parameters[1] == wxT(
"(" ) )
364 footprint->SetLibDescription( parameters[3] );
365 footprint->SetReference( parameters[4] );
369 footprint->SetLibDescription( parameters[2] );
370 footprint->SetReference( parameters[3] );
375 footprint->SetValue( parameters[5] );
379 if( footprint->Value().GetText().IsEmpty() )
380 footprint->Value().SetText( wxT(
"VAL**" ) );
382 if( footprint->Reference().GetText().IsEmpty() )
383 footprint->Reference().SetText( wxT(
"REF**" ) );
390 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
393 if( parameters[0] == wxT(
")" ) )
396 paramCnt = parameters.GetCount();
401 if( parameters[1] == wxT(
"(" ) )
408 parameters[0], paramCnt );
411 if( parameters[0].CmpNoCase( wxT(
"ElementLine" ) ) == 0 )
415 msg.Printf( wxT(
"ElementLine token contains %d parameters." ), paramCnt );
423 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) ) );
425 static_cast<int>(
parseInt( parameters[5], conv_unit ) ) ) );
429 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
430 shape->
Move( footprint->GetPosition() );
432 footprint->Add( shape );
437 if( parameters[0].CmpNoCase( wxT(
"ElementArc" ) ) == 0 )
441 msg.Printf( wxT(
"ElementArc token contains %d parameters." ), paramCnt );
449 footprint->Add( shape );
452 int radius =
static_cast<int>( (
parseInt( parameters[4], conv_unit ) +
453 parseInt( parameters[5], conv_unit ) ) / 2 );
456 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
480 shape->
SetStart( arcStart + centre );
489 shape->
Rotate( { 0, 0 }, footprint->GetOrientation() );
490 shape->
Move( footprint->GetPosition() );
499 if( parameters[0].CmpNoCase( wxT(
"Pad" ) ) == 0 )
501 if( paramCnt < 10 || paramCnt > 13 )
503 msg.Printf( wxT(
"Pad token contains %d parameters." ), paramCnt );
508 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( footprint.get() );
516 pad->SetLayerSet( pad_front );
518 if(
testFlags( parameters[paramCnt-2], 0x0080, wxT(
"onsolder" ) ) )
519 pad->SetLayerSet( pad_back );
529 pad->SetNumber( parameters[paramCnt-3] );
531 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
532 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
533 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
534 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
535 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
537 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
551 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
552 maskMargin = ( maskMargin - width ) / 2;
553 pad->SetLocalSolderMaskMargin( maskMargin );
558 pad->SetOrientation( orient );
560 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
564 padPos += footprint->GetPosition();
565 pad->SetPosition( padPos );
567 if( !
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
575 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
577 footprint->Add(
pad.release() );
581 m_owner->Report( wxString::Format(
_(
"Invalid zero-sized pad ignored in\n"
596 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
598 if( paramCnt < 8 || paramCnt > 12 )
600 msg.Printf( wxT(
"Pin token contains %d parameters." ), paramCnt );
612 pad->SetLayerSet( pad_set );
614 if(
testFlags( parameters[paramCnt-2], 0x0100, wxT(
"square" ) ) )
621 pad->SetNumber( parameters[paramCnt-3] );
624 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
626 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
644 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
645 maskMargin = ( maskMargin - padSize ) / 2;
646 pad->SetLocalSolderMaskMargin( maskMargin );
648 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
652 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
655 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
657 padPos += footprint->GetPosition();
658 pad->SetPosition( padPos );
666 footprint->Add(
pad );
671 footprint->AutoPositionFields();
673 return footprint.release();
681 char* line = aLineReader->
Line();
695 aParameterList.Add( tmp );
700 aParameterList.Add( tmp );
705 if( aParameterList.GetCount() == 1 )
717 aParameterList.Add( tmp );
722 aParameterList.Add( tmp );
736 aParameterList.Add( tmp );
748 aParameterList.Add( wxEmptyString );
759 aParameterList.Add( tmp );
791 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
795 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
798 else if( aFlag.Contains( aName ) )
819 m_ctl( aControlFlags ),
855 const std::map<std::string, UTF8>* aProperties )
857 wxFileName fn( aFootprintPath );
863 char* line = reader.
Line();
868 if( strncasecmp( line,
"Element", strlen(
"Element" ) ) != 0 )
871 aFootprintNameOut = fn.GetName();
878 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
880 wxDir dir( aLibraryPath );
883 if( !dir.IsOpened() )
899 errorMsg = ioe.
What();
905 for(
const auto& footprint :
m_cache->GetFootprints() )
906 aFootprintNames.Add(
From_UTF8( footprint.first.c_str() ) );
908 if( !errorMsg.IsEmpty() && !aBestEfforts )
914 const wxString& aFootprintName,
915 const std::map<std::string, UTF8>* aProperties,
922 auto it =
m_cache->GetFootprints().find(
TO_UTF8( aFootprintName ) );
924 if( it ==
m_cache->GetFootprints().end() )
927 return it->second->GetFootprint().get();
932 bool aKeepUUID,
const std::map<std::string, UTF8>* aProperties )
942 copy->SetParent(
nullptr );
951 const std::map<std::string, UTF8>* aProperties )
958 THROW_IO_ERRORF(
_(
"Library '%s' is read only." ), aLibraryPath.GetData() );
960 m_cache->Remove( aFootprintName );
967 fn.SetPath( aLibraryPath );
970 if( !fn.DirExists() )
973 if( !fn.IsDirWritable() )
974 THROW_IO_ERRORF(
_(
"Insufficient permissions to delete folder '%s'." ), aLibraryPath.GetData() );
976 wxDir dir( aLibraryPath );
978 if( dir.HasSubDirs() )
979 THROW_IO_ERRORF(
_(
"Library folder '%s' has unexpected sub-folders." ), aLibraryPath.GetData() );
989 for(
unsigned i = 0; i < files.GetCount(); i++ )
997 aLibraryPath.GetData() );
1001 for(
unsigned i = 0; i < files.GetCount(); i++ )
1002 wxRemoveFile( files[i] );
1005 wxLogTrace(
traceGedaPcbPlugin, wxT(
"Removing footprint library '%s'" ), aLibraryPath.GetData() );
1009 if( !wxRmdir( aLibraryPath ) )
1010 THROW_IO_ERRORF(
_(
"Footprint library '%s' cannot be deleted." ), aLibraryPath.GetData() );
1016 wxMilliSleep( 250L );
1054 char* line = aLineReader->
Line();
1065 if( !tmp.IsEmpty() )
1067 aParameterList.Add( tmp );
1072 aParameterList.Add( tmp );
1075 if( aParameterList.GetCount() == 1 )
1085 if( !tmp.IsEmpty() )
1087 aParameterList.Add( tmp );
1092 aParameterList.Add( tmp );
1107 if( !tmp.IsEmpty() )
1109 aParameterList.Add( tmp );
1120 aParameterList.Add( wxEmptyString );
1131 aParameterList.Add( tmp );
1163 if( aFlag.StartsWith( wxT(
"0x" ), &number ) || aFlag.StartsWith( wxT(
"0X" ), &number ) )
1167 if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
1170 else if( aFlag.Contains( aName ) )
1184 wxFileInputStream input( aFileName );
1189 wxTextInputStream
text( input );
1191 for(
int i = 0; i < 20; i++ )
1196 wxString line =
text.ReadLine();
1198 if( line.Contains( wxS(
"PCB[" ) ) || line.Contains( wxS(
"PCB(" ) ) )
1208 wxString
name = aLayerName.Lower();
1210 if(
name.Contains( wxT(
"outline" ) ) ||
name.Contains( wxT(
"route" ) ) )
1213 if(
name.Contains( wxT(
"silk" ) ) )
1215 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1221 if(
name.Contains( wxT(
"mask" ) ) )
1223 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1229 if(
name.Contains( wxT(
"paste" ) ) )
1231 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) ) )
1237 if(
name.Contains( wxT(
"fab" ) ) )
1241 if(
name.Contains( wxT(
"component" ) ) ||
name.Contains( wxT(
"top" ) )
1242 || ( aGedaLayer == 1 && !
name.Contains( wxT(
"solder" ) ) ) )
1247 if(
name.Contains( wxT(
"solder" ) ) ||
name.Contains( wxT(
"bottom" ) )
1248 || aGedaLayer == 2 )
1254 if( aGedaLayer >= 3 && aGedaLayer <= 16 )
1256 int innerIdx = aGedaLayer - 3;
1262 return innerLayers[innerIdx];
1272 int paramCnt = aParameters.GetCount();
1275 THROW_IO_ERRORF(
_(
"Via token contains %d parameters, expected at least 10." ), paramCnt );
1279 int x =
static_cast<int>(
parseInt( aParameters[2], aConvUnit ) );
1280 int y =
static_cast<int>(
parseInt( aParameters[3], aConvUnit ) );
1281 int thickness =
static_cast<int>(
parseInt( aParameters[4], aConvUnit ) );
1282 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() );
1449 pad->SetLayerSet( pad_front );
1451 if(
testFlags( parameters[paramCnt - 2], 0x0080, wxT(
"onsolder" ) ) )
1452 pad->SetLayerSet( pad_back );
1454 pad->SetNumber( parameters[paramCnt - 3] );
1456 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1457 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1458 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1459 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1460 int width =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1462 double angle = atan2( (
double)
delta.y, (
double)
delta.x );
1464 if( paramCnt == 13 )
1469 int maskMargin =
static_cast<int>(
parseInt( parameters[8], conv_unit ) );
1470 maskMargin = ( maskMargin - width ) / 2;
1471 pad->SetLocalSolderMaskMargin( maskMargin );
1475 pad->SetOrientation( orient );
1477 VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
1481 padPos += footprint->GetPosition();
1482 pad->SetPosition( padPos );
1484 if( !
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1492 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
1493 footprint->Add(
pad.release() );
1499 if( parameters[0].CmpNoCase( wxT(
"Pin" ) ) == 0 )
1501 if( paramCnt < 8 || paramCnt > 12 )
1511 pad->SetLayerSet( pad_set );
1513 if(
testFlags( parameters[paramCnt - 2], 0x0100, wxT(
"square" ) ) )
1516 pad->SetNumber( parameters[paramCnt - 3] );
1519 static_cast<int>(
parseInt( parameters[3], conv_unit ) ) );
1521 int padSize =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1526 if( paramCnt == 12 )
1531 int maskMargin =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1532 maskMargin = ( maskMargin - padSize ) / 2;
1533 pad->SetLocalSolderMaskMargin( maskMargin );
1535 drillSize =
static_cast<int>(
parseInt( parameters[7], conv_unit ) );
1539 drillSize =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1542 pad->SetDrillSize(
VECTOR2I( drillSize, drillSize ) );
1544 padPos += footprint->GetPosition();
1545 pad->SetPosition( padPos );
1553 footprint->Add(
pad );
1560 wxString elementFlags = aParameters[2];
1562 if( elementFlags.Contains( wxT(
"onsolder" ) ) )
1565 footprint->AutoPositionFields();
1567 return footprint.release();
1575 int paramCnt = aParameters.GetCount();
1581 aParameters[2].ToLong( &layerNum );
1586 layerName = aParameters[3];
1595 int layerCount =
static_cast<int>( layerNum );
1601 wxArrayString parameters;
1602 double conv_unit = aConvUnit;
1609 if( parameters.IsEmpty() || parameters[0] == wxT(
"(" ) )
1612 if( parameters[0] == wxT(
")" ) )
1615 paramCnt = parameters.GetCount();
1619 if( parameters[1] == wxT(
"(" ) )
1626 if( parameters[0].CmpNoCase( wxT(
"Line" ) ) == 0 )
1631 int x1 =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1632 int y1 =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1633 int x2 =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1634 int y2 =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1635 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1661 if( parameters[0].CmpNoCase( wxT(
"Arc" ) ) == 0 )
1666 int cx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1667 int cy =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1668 int arcWidth =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1669 int arcHeight =
static_cast<int>(
parseInt( parameters[5], conv_unit ) );
1670 int thickness =
static_cast<int>(
parseInt( parameters[6], conv_unit ) );
1671 int radius = ( arcWidth + arcHeight ) / 2;
1689 arc->
SetStart( arcStart + centre );
1692 RotatePoint( arcMid, -start_angle - sweep_angle / 2 );
1693 arc->
SetMid( arcMid + centre );
1696 RotatePoint( arcEnd, -start_angle - sweep_angle );
1697 arc->
SetEnd( arcEnd + centre );
1717 shape->
SetStart( arcStart + centre );
1729 if( parameters[0].CmpNoCase( wxT(
"Polygon" ) ) == 0 )
1737 const int outlineIdx = -1;
1738 bool parsingPoints =
false;
1742 wxArrayString polyParams;
1745 if( polyParams.IsEmpty() )
1748 if( polyParams[0] == wxT(
")" ) )
1751 if( polyParams[0] == wxT(
"(" ) )
1753 parsingPoints =
true;
1757 if( !parsingPoints )
1761 for(
size_t i = 0; i < polyParams.GetCount(); i++ )
1763 if( polyParams[i] == wxT(
"[" ) && i + 2 < polyParams.GetCount() )
1765 int px =
static_cast<int>(
parseInt( polyParams[i + 1], conv_unit ) );
1766 int py =
static_cast<int>(
parseInt( polyParams[i + 2], conv_unit ) );
1787 if( parameters[0].CmpNoCase( wxT(
"Text" ) ) == 0 )
1793 text->SetLayer( kicadLayer );
1795 int tx =
static_cast<int>(
parseInt( parameters[2], conv_unit ) );
1796 int ty =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1800 parameters[4].ToLong( &direction );
1803 text->SetTextAngle( textAngle );
1806 parameters[5].ToLong( &
scale );
1811 text->SetText( parameters[6] );
1828 std::map<wxString, FOOTPRINT*> fpByRef;
1831 fpByRef[fp->GetReference()] = fp;
1833 wxArrayString parameters;
1840 if( parameters.IsEmpty() )
1843 if( parameters[0] == wxT(
")" ) )
1846 if( parameters[0] == wxT(
"(" ) )
1850 if( parameters[0].CmpNoCase( wxT(
"Net" ) ) == 0 )
1854 if( parameters.GetCount() > 3 )
1855 netName = parameters[2];
1859 auto it =
m_netMap.find( netName );
1863 netInfo = it->second;
1875 wxArrayString netParams;
1878 if( netParams.IsEmpty() )
1881 if( netParams[0] == wxT(
")" ) )
1884 if( netParams[0] == wxT(
"(" ) )
1888 if( netParams[0].CmpNoCase( wxT(
"Connect" ) ) == 0 && netParams.GetCount() > 3 )
1890 wxString connectStr = netParams[2];
1893 int lastDash = connectStr.Find(
'-',
true );
1895 if( lastDash == wxNOT_FOUND )
1898 wxString refdes = connectStr.Left( lastDash );
1899 wxString pinNumber = connectStr.Mid( lastDash + 1 );
1901 auto fpIt = fpByRef.find( refdes );
1903 if( fpIt == fpByRef.end() )
1906 for(
PAD*
pad : fpIt->second->Pads() )
1908 if(
pad->GetNumber() == pinNumber )
1910 pad->SetNet( netInfo );
1922 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
1926 init( aProperties );
1943 wxArrayString parameters;
1946 if( parameters.IsEmpty() )
1949 int paramCnt = parameters.GetCount();
1953 if( parameters[1] == wxT(
"(" ) )
1960 if( parameters[0].CmpNoCase( wxT(
"PCB" ) ) == 0 )
1964 int boardWidth =
static_cast<int>(
parseInt( parameters[3], conv_unit ) );
1965 int boardHeight =
static_cast<int>(
parseInt( parameters[4], conv_unit ) );
1968 VECTOR2I pageSize( boardWidth, boardHeight );
1972 m_board->SetPageSettings( page );
1979 if( parameters[0].CmpNoCase( wxT(
"FileVersion" ) ) == 0 )
1983 if( parameters[0].CmpNoCase( wxT(
"Grid" ) ) == 0
1984 || parameters[0].CmpNoCase( wxT(
"Cursor" ) ) == 0
1985 || parameters[0].CmpNoCase( wxT(
"Thermal" ) ) == 0
1986 || parameters[0].CmpNoCase( wxT(
"DRC" ) ) == 0
1987 || parameters[0].CmpNoCase( wxT(
"Flags" ) ) == 0
1988 || parameters[0].CmpNoCase( wxT(
"Groups" ) ) == 0
1989 || parameters[0].CmpNoCase( wxT(
"Styles" ) ) == 0
1990 || parameters[0].CmpNoCase( wxT(
"Attribute" ) ) == 0 )
1996 if( parameters[0].CmpNoCase( wxT(
"Via" ) ) == 0 )
2003 if( parameters[0].CmpNoCase( wxT(
"Element" ) ) == 0 )
2021 if( parameters[0].CmpNoCase( wxT(
"Layer" ) ) == 0 )
2023 parseLayer( parameters, &reader, conv_unit );
2028 if( parameters[0].CmpNoCase( wxT(
"Rat" ) ) == 0 )
2032 if( parameters[0].CmpNoCase( wxT(
"NetList" ) ) == 0 )
2053 m_board->m_LegacyDesignSettingsLoaded =
true;
2054 m_board->m_LegacyNetclassesLoaded =
true;
2060 std::vector<FOOTPRINT*> retval;
2063 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...
@ NORMAL
Shape is the same on all layers.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
void SetMid(const VECTOR2I &aMid)
A #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 loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Parse aFileName into aBoard.
void parseNetList(LINE_READER *aLineReader)
std::unique_ptr< FOOTPRINT > FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
std::map< wxString, NETINFO_ITEM * > m_netMap
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
void init(const std::map< std::string, UTF8 > *aProperties)
std::unique_ptr< FOOTPRINT > ImportFootprint(const wxString &aFootprintPath, wxString &aFootprintNameOut, const std::map< std::string, UTF8 > *aProperties) override
Load a single footprint from aFootprintPath and put its name in aFootprintNameOut.
GPCB_FPL_CACHE * m_cache
Footprint library cache.
bool testFlags(const wxString &aFlag, long aMask, const wxChar *aName)
FOOTPRINT * parseElement(wxArrayString &aParameters, LINE_READER *aLineReader, double aConvUnit)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void parseParameters(wxArrayString &aParameterList, LINE_READER *aLineReader)
void parseLayer(wxArrayString &aParameters, LINE_READER *aLineReader, double aConvUnit)
std::vector< FOOTPRINT * > m_cachedFootprints
LINE_READER * m_reader
no ownership here.
friend class GPCB_FPL_CACHE
PCB_LAYER_ID mapLayer(int aGedaLayer, const wxString &aLayerName) const
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties, bool checkModified)
BOARD * m_board
The board BOARD being worked on, no ownership here.
virtual bool CanReadBoard(const wxString &aFileName) const
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)
bool AppendCorner(const VECTOR2I &aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
bool SetNetCode(int aNetCode, bool aNoAssert) override
Override that clamps the netcode to 0 when this zone is in copper-thieving fill mode.
void SetIsFilled(bool isFilled)
void SetAssignedPriority(unsigned aPriority)
int GetNumCorners(void) const
Access to m_Poly parameters.
static constexpr EDA_ANGLE ANGLE_360
static constexpr EDA_ANGLE ANGLE_180
#define IGNORE_PARENT_GROUP
void CollectFilesLoopSafe(const wxString &aRoot, wxArrayString &aFiles, const wxString &aFileSpec, int aFlags)
Recursively collect every file under aRoot, deduplicating subdirectories by their resolved path.
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.