68#include <wx/filename.h>
69#include <wx/wfstream.h>
70#include <wx/txtstrm.h>
71#include <boost/ptr_container/ptr_map.hpp>
104#define FIRST_COPPER_LAYER 0
105#define LAYER_N_BACK 0
120#define LAYER_N_FRONT 15
121#define LAST_COPPER_LAYER LAYER_N_FRONT
123#define FIRST_NON_COPPER_LAYER 16
124#define ADHESIVE_N_BACK 16
125#define ADHESIVE_N_FRONT 17
126#define SOLDERPASTE_N_BACK 18
127#define SOLDERPASTE_N_FRONT 19
128#define SILKSCREEN_N_BACK 20
129#define SILKSCREEN_N_FRONT 21
130#define SOLDERMASK_N_BACK 22
131#define SOLDERMASK_N_FRONT 23
137#define LAST_NON_COPPER_LAYER 28
141#define LAYER_BACK (1 << LAYER_N_BACK)
142#define LAYER_2 (1 << LAYER_N_2)
143#define LAYER_3 (1 << LAYER_N_3)
144#define LAYER_4 (1 << LAYER_N_4)
145#define LAYER_5 (1 << LAYER_N_5)
146#define LAYER_6 (1 << LAYER_N_6)
147#define LAYER_7 (1 << LAYER_N_7)
148#define LAYER_8 (1 << LAYER_N_8)
149#define LAYER_9 (1 << LAYER_N_9)
150#define LAYER_10 (1 << LAYER_N_10)
151#define LAYER_11 (1 << LAYER_N_11)
152#define LAYER_12 (1 << LAYER_N_12)
153#define LAYER_13 (1 << LAYER_N_13)
154#define LAYER_14 (1 << LAYER_N_14)
155#define LAYER_15 (1 << LAYER_N_15)
156#define LAYER_FRONT (1 << LAYER_N_FRONT)
157#define ADHESIVE_LAYER_BACK (1 << ADHESIVE_N_BACK)
158#define ADHESIVE_LAYER_FRONT (1 << ADHESIVE_N_FRONT)
159#define SOLDERPASTE_LAYER_BACK (1 << SOLDERPASTE_N_BACK)
160#define SOLDERPASTE_LAYER_FRONT (1 << SOLDERPASTE_N_FRONT)
161#define SILKSCREEN_LAYER_BACK (1 << SILKSCREEN_N_BACK)
162#define SILKSCREEN_LAYER_FRONT (1 << SILKSCREEN_N_FRONT)
163#define SOLDERMASK_LAYER_BACK (1 << SOLDERMASK_N_BACK)
164#define SOLDERMASK_LAYER_FRONT (1 << SOLDERMASK_N_FRONT)
165#define DRAW_LAYER (1 << DRAW_N)
166#define COMMENT_LAYER (1 << COMMENT_N)
167#define ECO1_LAYER (1 << ECO1_N)
168#define ECO2_LAYER (1 << ECO2_N)
169#define EDGE_LAYER (1 << EDGE_N)
174#define ALL_NO_CU_LAYERS 0x1FFF0000
175#define ALL_CU_LAYERS 0x0000FFFF
176#define FRONT_TECH_LAYERS (SILKSCREEN_LAYER_FRONT | SOLDERMASK_LAYER_FRONT \
177 | ADHESIVE_LAYER_FRONT | SOLDERPASTE_LAYER_FRONT)
178#define BACK_TECH_LAYERS (SILKSCREEN_LAYER_BACK | SOLDERMASK_LAYER_BACK \
179 | ADHESIVE_LAYER_BACK | SOLDERPASTE_LAYER_BACK)
180#define ALL_TECH_LAYERS (FRONT_TECH_LAYERS | BACK_TECH_LAYERS)
181#define BACK_LAYERS (LAYER_BACK | BACK_TECH_LAYERS)
182#define FRONT_LAYERS (LAYER_FRONT | FRONT_TECH_LAYERS)
184#define ALL_USER_LAYERS (DRAW_LAYER | COMMENT_LAYER | ECO1_LAYER | ECO2_LAYER )
186#define NO_LAYERS 0x00000000
188#define PCB_LEGACY_TEXT_is_REFERENCE 0
189#define PCB_LEGACY_TEXT_is_VALUE 1
190#define PCB_LEGACY_TEXT_is_DIVERS 2
193#define PCB_LEGACY_INTERNAL_UNIT 10000
196#define SZ( x ) (sizeof(x)-1)
202static bool inline isSpace(
int c ) {
return strchr(
delims, c ) !=
nullptr; }
204#define MASK(x) (1<<(x))
209 const unsigned PROGRESS_DELTA = 250;
232#define TESTLINE( x ) ( !strncasecmp( line, x, SZ( x ) ) && isSpace( line[SZ( x )] ) )
235#define TESTSUBSTR( x ) ( !strncasecmp( line, x, SZ( x ) ) )
239#define READLINE( rdr ) rdr->ReadLine()
245static inline char* ReadLine(
LINE_READER* rdr,
const char* caller )
249 const char* line = rdr->
Line();
252 if( !strcmp(
"loadSETUP", caller ) && !strcmp(
"$EndSETUP\n", line ) )
260#define READLINE( rdr ) ReadLine( rdr, __FUNCTION__ )
266 if( !strcmp(
"L", horizontal ) )
269 if( !strcmp(
"R", horizontal ) )
277 if( !strcmp(
"T", vertical ) )
280 if( !strcmp(
"B", vertical ) )
292 for(
int i = 0; aMask; ++i, aMask >>= 1 )
306 return aLegacyLayerNum ==
LAYER_N_FRONT || aLegacyLayerNum < aCu_Count;
313 unsigned old = aLayerNum;
331 newid = cu_count - 1 - old;
332 wxASSERT( newid >= 0 );
374 aMask &= ~ALL_CU_LAYERS;
377 for(
int i=0; aMask; ++i, aMask >>= 1 )
393static inline int intParse(
const char*
next,
const char** out =
nullptr )
396 return (
int) strtol(
next, (
char**) out, 10 );
406static inline long hexParse(
const char*
next,
const char** out =
nullptr )
409 return strtol(
next, (
char**) out, 16 );
443 char* line = reader.
Line();
452 if( !strncasecmp( line,
"$MODULE", strlen(
"$MODULE" ) ) )
476 std::unique_ptr<BOARD> boardDeleter;
484 boardDeleter = std::make_unique<BOARD>();
542 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
m_board );
545 std::string fpName =
StrPurge( line +
SZ(
"$MODULE" ) );
551 if( !fpName.empty() )
552 fpid.
Parse( fpName,
true );
554 footprint->SetFPID( fpid );
557 m_board->
Add( footprint.release(), ADD_MODE::APPEND );
559 else if(
TESTLINE(
"$DRAWSEGMENT" ) )
579 else if(
TESTLINE(
"$CZONE_OUTLINE" ) )
600 else if(
TESTLINE(
"$SHEETDESCR" ) )
637 char* line = aReader->
Line();
645 sscanf( line,
"PCBNEW-BOARD Version %d", &ver );
653 if( ver > LEGACY_BOARD_FILE_VERSION )
655 THROW_IO_ERROR( wxString::Format(
_(
"File '%s' has an unrecognized version: %d." ),
668 bool saw_LayerCount =
false;
677 data = strtok_r( line +
SZ(
"Units"),
delims, &saveptr );
679 if( !strcmp( data,
"mm" ) )
686 int tmp =
intParse( line +
SZ(
"LayerCount" ) );
694 saw_LayerCount =
true;
696 else if(
TESTLINE(
"EnabledLayers" ) )
698 if( !saw_LayerCount )
713 else if(
TESTLINE(
"VisibleLayers" ) )
719 if( !saw_LayerCount )
731 if( !saw_LayerCount )
738 saw_LayerCount =
true;
741 else if(
TESTLINE(
"BoardThickness" ) )
766 else if(
TESTLINE(
"$EndGENERAL" ) )
790 char* sname = strtok_r( line +
SZ(
"Sheet" ),
delims, &data );
798 m_error.Printf(
_(
"Unknown sheet type '%s' on line: %d." ),
804 char* width = strtok_r(
nullptr,
delims, &data );
805 char* height = strtok_r(
nullptr,
delims, &data );
806 char* orient = strtok_r(
nullptr,
delims, &data );
811 if( width && height )
823 if( orient && !strcmp( orient,
"portrait" ) )
896 else if(
TESTLINE(
"$EndSHEETDESCR" ) )
911 std::shared_ptr<NETCLASS> defaultNetclass = bds.
m_NetSettings->m_DefaultNetClass;
928 plot_opts.
Parse( &parser );
933 else if(
TESTLINE(
"AuxiliaryAxisOrg" ) )
944 int layer_num =
intParse( line +
SZ(
"Layer[" ), &data );
947 data = strtok_r( (
char*) data+1,
delims, &saveptr );
954 data = strtok_r(
nullptr,
delims, &saveptr );
966 defaultNetclass->SetTrackWidth( tmp );
968 else if(
TESTLINE(
"TrackWidthList" ) )
973 else if(
TESTLINE(
"TrackClearence" ) )
976 defaultNetclass->SetClearance( tmp );
978 else if(
TESTLINE(
"TrackMinWidth" ) )
983 else if(
TESTLINE(
"ZoneClearence" ) )
988 else if(
TESTLINE(
"Zone_45_Only" ) )
992 else if(
TESTLINE(
"DrawSegmWidth" ) )
997 else if(
TESTLINE(
"EdgeSegmWidth" ) )
1002 else if(
TESTLINE(
"ViaMinSize" ) )
1007 else if(
TESTLINE(
"MicroViaMinSize" ) )
1012 else if(
TESTLINE(
"ViaSizeList" ) )
1017 BIU diameter =
biuParse( line +
SZ(
"ViaSizeList" ), &data );
1019 data = strtok_r( (
char*) data,
delims, (
char**) &data );
1028 defaultNetclass->SetViaDiameter( tmp );
1033 defaultNetclass->SetViaDrill( tmp );
1035 else if(
TESTLINE(
"ViaMinDrill" ) )
1040 else if(
TESTLINE(
"MicroViaSize" ) )
1043 defaultNetclass->SetuViaDiameter( tmp );
1045 else if(
TESTLINE(
"MicroViaDrill" ) )
1048 defaultNetclass->SetuViaDrill( tmp );
1050 else if(
TESTLINE(
"MicroViaMinDrill" ) )
1055 else if(
TESTLINE(
"MicroViasAllowed" ) )
1059 else if(
TESTLINE(
"TextPcbWidth" ) )
1064 else if(
TESTLINE(
"TextPcbSize" ) )
1071 else if(
TESTLINE(
"EdgeModWidth" ) )
1077 else if(
TESTLINE(
"TextModWidth" ) )
1083 else if(
TESTLINE(
"TextModSize" ) )
1103 else if(
TESTLINE(
"Pad2MaskClearance" ) )
1108 else if(
TESTLINE(
"SolderMaskMinWidth" ) )
1113 else if(
TESTLINE(
"Pad2PasteClearance" ) )
1118 else if(
TESTLINE(
"Pad2PasteClearanceRatio" ) )
1120 double ratio = atof( line +
SZ(
"Pad2PasteClearanceRatio" ) );
1124 else if(
TESTLINE(
"GridOrigin" ) )
1131 else if(
TESTLINE(
"VisibleElements" ) )
1137 int visibleElements =
hexParse( line +
SZ(
"VisibleElements" ) );
1143 for(
size_t i = 0; i < visibles.size(); i++ )
1144 visibles.
set( i, visibleElements & ( 1u << i ) );
1184 for(
unsigned ii = 1; ii < designSettings.
m_TrackWidthList.size() - 1; ii++ )
1205 if(
TESTSUBSTR(
"D" ) && strchr(
"SCAP", line[1] ) )
1243 int orient =
intParse( data, &data );
1244 int layer_num =
intParse( data, &data );
1247 [[maybe_unused]]
long edittime =
hexParse( data, &data );
1249 char* uuid = strtok_r( (
char*) data,
delims, (
char**) &data );
1251 data = strtok_r( (
char*) data+1,
delims, (
char**) &data );
1255 if( data && data[0] ==
'F' )
1258 if( data && data[1] ==
'P' )
1268 char* uuid = strtok_r( (
char*) line +
SZ(
"Sc" ),
delims, (
char**) &data );
1280 data = line +
SZ(
"At" );
1282 if( strstr( data,
"SMD" ) )
1284 else if( strstr( data,
"VIRTUAL" ) )
1294 data = strtok_r( line +
SZ(
"AR" ),
delims, (
char**) &data );
1312 else if(
TESTLINE(
".SolderPasteRatio" ) )
1314 double tmp = atof( line +
SZ(
".SolderPasteRatio" ) );
1328 else if(
TESTLINE(
".SolderPaste" ) )
1333 else if(
TESTLINE(
".SolderMask" ) )
1338 else if(
TESTLINE(
".LocalClearance" ) )
1343 else if(
TESTLINE(
".ZoneConnection" ) )
1345 int tmp =
intParse( line +
SZ(
".ZoneConnection" ) );
1348 else if(
TESTLINE(
".ThermalWidth" ) )
1353 else if(
TESTLINE(
".ThermalGap" ) )
1358 else if(
TESTLINE(
"$EndMODULE" ) )
1364 wxString msg = wxString::Format(
_(
"Missing '$EndMODULE' for MODULE '%s'." ),
1372 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( aFootprint );
1388 char mypadnumber[50];
1390 data = line +
SZ(
"Sh" ) + 1;
1393 data = data +
ReadDelimitedText( mypadnumber, data,
sizeof( mypadnumber ) ) + 1;
1398 unsigned char padchar = (
unsigned char) *data++;
1409 case 'C': padshape =
static_cast<int>( PAD_SHAPE::CIRCLE );
break;
1410 case 'R': padshape =
static_cast<int>( PAD_SHAPE::RECTANGLE );
break;
1411 case 'O': padshape =
static_cast<int>( PAD_SHAPE::OVAL );
break;
1412 case 'T': padshape =
static_cast<int>( PAD_SHAPE::TRAPEZOID );
break;
1414 m_error.Printf(
_(
"Unknown padshape '%c=0x%02x' on line: %d of footprint: '%s'." ),
1427 const unsigned char* cp = (
unsigned char*) mypadnumber;
1440 pad->SetNumber( padNumber );
1444 pad->SetOrientation( orient );
1450 BIU drill_y = drill_x;
1456 data = strtok_r( (
char*) data,
delims, &saveptr );
1460 if( data[0] ==
'O' )
1464 data = strtok_r(
nullptr,
delims, &saveptr );
1467 data = strtok_r(
nullptr,
delims, &saveptr );
1472 pad->SetDrillShape( drShape );
1474 pad->SetDrillSize(
VECTOR2I( drill_x, drill_y ) );
1483 data = strtok_r( line +
SZ(
"At" ),
delims, &saveptr );
1485 if( !strcmp( data,
"SMD" ) )
1486 attribute = PAD_ATTRIB::SMD;
1487 else if( !strcmp( data,
"CONN" ) )
1488 attribute = PAD_ATTRIB::CONN;
1489 else if( !strcmp( data,
"HOLE" ) )
1490 attribute = PAD_ATTRIB::NPTH;
1492 attribute = PAD_ATTRIB::PTH;
1494 strtok_r(
nullptr,
delims, &saveptr );
1495 data = strtok_r(
nullptr,
delims, &saveptr );
1500 pad->SetAttribute( attribute );
1507 int netcode =
intParse( line +
SZ(
"Ne" ), &data );
1529 pad->SetFPRelativePosition( pos );
1534 pad->SetPadToDieLength( tmp );
1536 else if(
TESTLINE(
".SolderMask" ) )
1539 pad->SetLocalSolderMaskMargin( tmp );
1541 else if(
TESTLINE(
".SolderPasteRatio" ) )
1543 double tmp = atof( line +
SZ(
".SolderPasteRatio" ) );
1544 pad->SetLocalSolderPasteMarginRatio( tmp );
1546 else if(
TESTLINE(
".SolderPaste" ) )
1549 pad->SetLocalSolderPasteMargin( tmp );
1551 else if(
TESTLINE(
".LocalClearance" ) )
1554 pad->SetLocalClearance( tmp );
1556 else if(
TESTLINE(
".ZoneConnection" ) )
1558 int tmp =
intParse( line +
SZ(
".ZoneConnection" ) );
1561 else if(
TESTLINE(
".ThermalWidth" ) )
1564 pad->SetThermalSpokeWidth( tmp );
1566 else if(
TESTLINE(
".ThermalGap" ) )
1569 pad->SetThermalGap( tmp );
1573 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
1575 aFootprint->
Add(
pad.release() );
1579 wxLogError(
_(
"Invalid zero-sized pad ignored in\nfile: %s" ),
1598 case 'S': shape = SHAPE_T::SEGMENT;
break;
1599 case 'C': shape = SHAPE_T::CIRCLE;
break;
1600 case 'A': shape = SHAPE_T::ARC;
break;
1601 case 'P': shape = SHAPE_T::POLY;
break;
1603 m_error.Printf(
_(
"Unknown PCB_SHAPE type:'%c=0x%02x' on line %d of footprint '%s'." ),
1609 std::unique_ptr<PCB_SHAPE> dwg = std::make_unique<PCB_SHAPE>( aFootprint, shape );
1630 dwg->SetCenter(
VECTOR2I( center0_x, center0_y ) );
1631 dwg->SetStart(
VECTOR2I( start0_x, start0_y ) );
1632 dwg->SetArcAngleAndEnd( angle,
true );
1636 case SHAPE_T::SEGMENT:
1637 case SHAPE_T::CIRCLE:
1648 dwg->SetStart(
VECTOR2I( start0_x, start0_y ) );
1649 dwg->SetEnd(
VECTOR2I( end0_x, end0_y ) );
1660 int ptCount =
intParse( data, &data );
1665 dwg->SetStart(
VECTOR2I( start0_x, start0_y ) );
1666 dwg->SetEnd(
VECTOR2I( end0_x, end0_y ) );
1668 std::vector<VECTOR2I> pts;
1669 pts.reserve( ptCount );
1671 for(
int ii = 0; ii < ptCount; ++ii )
1688 pts.emplace_back( x, y );
1691 dwg->SetPolyPoints( pts );
1706 dwg->SetStroke(
STROKE_PARAMS( width, LINE_STYLE::SOLID ) );
1711 aFootprint->
Add( dwg.release() );
1718 const char* txt_end;
1726 int type =
intParse( line+1, &data );
1741 m_field.Replace( wxT(
"%V" ), wxT(
"${VALUE}" ) );
1742 m_field.Replace( wxT(
"%R" ), wxT(
"${REFERENCE}" ) );
1749 char* mirror = strtok_r( (
char*) data,
delims, (
char**) &data );
1750 char* hide = strtok_r(
nullptr,
delims, (
char**) &data );
1751 char* tmp = strtok_r(
nullptr,
delims, (
char**) &data );
1755 char* italic = strtok_r(
nullptr,
delims, (
char**) &data );
1757 char* hjust = strtok_r( (
char*) txt_end,
delims, (
char**) &data );
1758 char* vjust = strtok_r(
nullptr,
delims, (
char**) &data );
1772 aText->
SetVisible( !(hide && *hide ==
'I') );
1774 aText->
SetItalic( italic && *italic ==
'I' );
1827 else if(
TESTLINE(
"$EndSHAPE3D" ) )
1829 aFootprint->
Models().push_back( t3D );
1847 std::unique_ptr<PCB_SHAPE> dseg = std::make_unique<PCB_SHAPE>(
m_board );
1858 int shape =
intParse( line +
SZ(
"Po" ), &data );
1868 dseg->SetShape(
static_cast<SHAPE_T>( shape ) );
1869 dseg->SetFilled(
false );
1870 dseg->SetStroke(
STROKE_PARAMS( width, LINE_STYLE::SOLID ) );
1872 if( dseg->GetShape() == SHAPE_T::ARC )
1874 dseg->SetCenter(
VECTOR2I( start_x, start_y ) );
1875 dseg->SetStart(
VECTOR2I( end_x, end_y ) );
1879 dseg->SetStart(
VECTOR2I( start_x, start_y ) );
1880 dseg->SetEnd(
VECTOR2I( end_x, end_y ) );
1888 data = strtok_r( line +
SZ(
"De" ),
delims, &saveptr );
1890 for(
int i = 0; data; ++i, data = strtok_r(
nullptr,
delims, &saveptr ) )
1913 if( dseg->GetShape() == SHAPE_T::ARC )
1914 dseg->SetArcAngleAndEnd( angle );
1919 const_cast<KIID&
>( dseg->m_Uuid ) =
KIID( data );
1933 dseg->SetBezierC1(
VECTOR2I( x, y ) );
1940 dseg->SetBezierC2(
VECTOR2I( x, y ) );
1948 else if(
TESTLINE(
"$EndDRAWSEGMENT" ) )
1950 m_board->
Add( dseg.release(), ADD_MODE::APPEND );
1981 netCode =
intParse( line +
SZ(
"Na" ), &data );
1985 if( net ==
nullptr )
1992 THROW_IO_ERROR( wxT(
"Two net definitions in '$EQUIPOT' block" ) );
1995 else if(
TESTLINE(
"$EndEQUIPOT" ) )
2091 int layer_num =
intParse( line +
SZ(
"De" ), &data );
2092 int notMirrored =
intParse( data, &data );
2093 char* uuid = strtok_r( (
char*) data,
delims, (
char**) &data );
2094 char* style = strtok_r(
nullptr,
delims, (
char**) &data );
2095 char* hJustify = strtok_r(
nullptr,
delims, (
char**) &data );
2096 char* vJustify = strtok_r(
nullptr,
delims, (
char**) &data );
2100 pcbtxt->
SetItalic( !strcmp( style,
"Italic" ) );
2126 else if(
TESTLINE(
"$EndTEXTPCB" ) )
2150 if( line[0] ==
'$' )
2163 data = strtok_r( (
char*) data,
delims, (
char**) &data );
2193 int layer_num =
intParse( line +
SZ(
"De" ), &data );
2194 int type =
intParse( data, &data );
2195 int net_code =
intParse( data, &data );
2196 char* uuid = strtok_r( (
char*) data,
delims, (
char**) &data );
2199 intParse( data, (
const char**) &data );
2211 wxFAIL_MSG( wxT(
"Segment type unknown" ) );
2233 via->SetViaType( viatype );
2236 via->SetDrillDefault();
2238 via->SetDrill( drill );
2240 if(
via->GetViaType() == VIATYPE::THROUGH )
2252 via->SetLayerPair( front, back );
2299 std::shared_ptr<NETCLASS> nc = std::make_shared<NETCLASS>( wxEmptyString );
2311 std::make_unique<EDA_COMBINED_MATCHER>( netname,
CTX_NETCLASS ),
2318 nc->SetClearance( tmp );
2320 else if(
TESTLINE(
"TrackWidth" ) )
2323 nc->SetTrackWidth( tmp );
2328 nc->SetViaDiameter( tmp );
2333 nc->SetViaDrill( tmp );
2338 nc->SetuViaDiameter( tmp );
2343 nc->SetuViaDrill( tmp );
2355 else if(
TESTLINE(
"$EndNCLASS" ) )
2364 m_error.Printf(
_(
"Duplicate NETCLASS name '%s'." ), nc->GetName() );
2382 std::unique_ptr<ZONE> zc = std::make_unique<ZONE>(
m_board );
2385 bool endContour =
false;
2409 zc->AppendCorner(
VECTOR2I( x, y ), holeIndex );
2419 char* uuid = strtok_r( (
char*) line +
SZ(
"ZInfo" ),
delims, (
char**) &data );
2420 int netcode =
intParse( data, &data );
2425 const_cast<KIID&
>( zc->m_Uuid ) =
KIID( uuid );
2430 zc->BOARD_CONNECTED_ITEM::SetNetCode(
getNetCode( netcode ) );
2434 int layer_num =
intParse( line +
SZ(
"ZLayer" ) );
2441 char* hopt = strtok_r( (
char*) data,
delims, (
char**) &data );
2445 m_error.Printf(
_(
"Bad ZAux for CZONE_CONTAINER \"%s\"" ),
2446 zc->GetNetname().GetData() );
2452 case 'N': outline_hatch = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
break;
2453 case 'E': outline_hatch = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
break;
2454 case 'F': outline_hatch = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL;
break;
2456 m_error.Printf(
_(
"Bad ZAux for CZONE_CONTAINER \"%s\"" ),
2457 zc->GetNetname().GetData() );
2463 else if(
TESTLINE(
"ZSmoothing" ) )
2466 int smoothing =
intParse( line +
SZ(
"ZSmoothing" ), &data );
2471 m_error.Printf(
_(
"Bad ZSmoothing for CZONE_CONTAINER \"%s\"" ),
2472 zc->GetNetname().GetData() );
2476 zc->SetCornerSmoothingType( smoothing );
2477 zc->SetCornerRadius( cornerRadius );
2482 zc->SetIsRuleArea(
true );
2483 zc->SetDoNotAllowPads(
false );
2484 zc->SetDoNotAllowFootprints(
false );
2487 token = strtok_r( line +
SZ(
"ZKeepout" ),
delims, (
char**) &data );
2491 if( !strcmp( token,
"tracks" ) )
2493 token = strtok_r(
nullptr,
delims, (
char**) &data );
2494 zc->SetDoNotAllowTracks( token && *token ==
'N' );
2496 else if( !strcmp( token,
"vias" ) )
2498 token = strtok_r(
nullptr,
delims, (
char**) &data );
2499 zc->SetDoNotAllowVias( token && *token ==
'N' );
2501 else if( !strcmp( token,
"copperpour" ) )
2503 token = strtok_r(
nullptr,
delims, (
char**) &data );
2504 zc->SetDoNotAllowCopperPour( token && *token ==
'N' );
2507 token = strtok_r(
nullptr,
delims, (
char**) &data );
2513 int fillmode =
intParse( line +
SZ(
"ZOptions" ), &data );
2515 char fillstate = data[1];
2516 BIU thermalReliefGap =
biuParse( data += 2 , &data );
2523 wxLogWarning(
_(
"The legacy segment zone fill mode is no longer supported.\n"
2524 "Zone fills will be converted on a best-effort basis." ) );
2530 zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2531 zc->SetIsFilled( fillstate ==
'S' );
2532 zc->SetThermalReliefGap( thermalReliefGap );
2533 zc->SetThermalReliefSpokeWidth( thermalReliefCopperBridge );
2535 else if(
TESTLINE(
"ZClearance" ) )
2538 BIU clearance =
biuParse( line +
SZ(
"ZClearance" ), &data );
2539 char* padoption = strtok_r( (
char*) data,
delims, (
char**) &data );
2542 switch( *padoption )
2544 case 'I': popt = ZONE_CONNECTION::FULL;
break;
2545 case 'T': popt = ZONE_CONNECTION::THERMAL;
break;
2546 case 'H': popt = ZONE_CONNECTION::THT_THERMAL;
break;
2547 case 'X': popt = ZONE_CONNECTION::NONE;
break;
2549 m_error.Printf(
_(
"Bad ZClearance padoption for CZONE_CONTAINER \"%s\"" ),
2550 zc->GetNetname().GetData() );
2554 zc->SetLocalClearance( clearance );
2555 zc->SetPadConnection( popt );
2557 else if(
TESTLINE(
"ZMinThickness" ) )
2560 zc->SetMinThickness( thickness );
2564 int priority =
intParse( line +
SZ(
"ZPriority" ) );
2565 zc->SetAssignedPriority( priority );
2567 else if(
TESTLINE(
"$POLYSCORNERS" ) )
2572 bool makeNewOutline =
true;
2576 if(
TESTLINE(
"$endPOLYSCORNERS" ) )
2583 if( makeNewOutline )
2586 polysList.
Append( x, y );
2589 bool end_contour =
intParse( data, &data );
2592 makeNewOutline = end_contour;
2595 zc->SetFilledPolysList( zc->GetFirstLayer(), polysList );
2597 else if(
TESTLINE(
"$FILLSEGMENTS" ) )
2601 if(
TESTLINE(
"$endFILLSEGMENTS" ) )
2611 else if(
TESTLINE(
"$endCZONE_OUTLINE" ) )
2615 if( zc->GetIsRuleArea() )
2618 if( zc->GetMinThickness() > 0 )
2625 CORNER_STRATEGY::ROUND_ALL_CORNERS,
2629 zc->SetFilledPolysList( layer, inflatedFill );
2635 if( zc->GetNumCorners() > 2 )
2637 if( !zc->IsOnCopperLayer() )
2639 zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2660 std::unique_ptr<PCB_DIM_ALIGNED> dim = std::make_unique<PCB_DIM_ALIGNED>(
m_board,
2673 dim->UpdateHeight( crossBarF, crossBarO );
2675 m_board->
Add( dim.release(), ADD_MODE::APPEND );
2688 int shape =
intParse( line +
SZ(
"De" ), (
const char**) &data );
2689 int layer_num =
intParse( data, &data );
2690 char* uuid = strtok_r( (
char*) data,
delims, (
char**) &data );
2693 const_cast<KIID&
>( dim->m_Uuid ) =
KIID( uuid );
2703 dim->SetOverrideText(
From_UTF8( buf ) );
2704 dim->SetOverrideTextEnabled(
true );
2705 dim->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX );
2706 dim->SetAutoUnits();
2716 char* mirror = strtok_r( (
char*) data,
delims, (
char**) &data );
2718 dim->SetTextPos(
VECTOR2I( pos_x, pos_y ) );
2719 dim->SetTextSize(
VECTOR2I( width, height ) );
2720 dim->SetMirrored( mirror && *mirror ==
'0' );
2721 dim->SetTextThickness( thickn );
2722 dim->SetTextAngle( orient );
2733 dim->SetLineThickness( width );
2734 crossBarO =
VECTOR2I( crossBarOx, crossBarOy );
2735 crossBarF =
VECTOR2I( crossBarFx, crossBarFy );
2746 dim->SetStart(
VECTOR2I( featureLineDOx, featureLineDOy ) );
2757 dim->SetEnd(
VECTOR2I( featureLineGOx, featureLineGOy ) );
2811 int shape =
intParse( line +
SZ(
"Po" ), &data );
2812 int layer_num =
intParse( data, &data );
2817 char* uuid = strtok_r( (
char*) data,
delims, (
char**) &data );
2825 VECTOR2I( pos_x, pos_y ), size, width );
2842 double fval = strtod( aValue, &nptr );
2846 m_error.Printf(
_(
"Invalid floating point number in file: '%s'\nline: %d, offset: %d" ),
2854 if( aValue == nptr )
2856 m_error.Printf(
_(
"Missing floating point number in file: '%s'\nline: %d, offset: %d" ),
2881 double fval = strtod( aValue, &nptr );
2885 m_error.Printf(
_(
"Invalid floating point number in file: '%s'\nline: %d, offset: %d" ),
2893 if( aValue == nptr )
2895 m_error.Printf(
_(
"Missing floating point number in file: '%s'\nline: %d, offset: %d" ),
2973 static long long GetTimestamp(
const wxString& aLibPath );
2989 m_lib_path( aLibraryPath ),
2991 m_cache_dirty( true ),
2992 m_cache_timestamp( 0 )
3007 return wxFileName( aLibPath ).GetModificationTime().GetValue().GetValue();
3036 if( !
TESTLINE(
"PCBNEW-LibModule-V1" ) )
3039 while( ( line = aReader->
ReadLine() ) !=
nullptr )
3043 const char* units = strtok_r( line +
SZ(
"Units" ),
delims, &data );
3045 if( !strcmp( units,
"mm" ) )
3063 char* line = aReader->
Line();
3071 while( ( line = aReader->
ReadLine() ) !=
nullptr )
3084 }
while( ( line = aReader->
ReadLine() ) !=
nullptr );
3092 char* line = aReader->
Line();
3099 std::unique_ptr<FOOTPRINT> fp_ptr = std::make_unique<FOOTPRINT>(
m_owner->
m_board );
3101 std::string footprintName =
StrPurge( line +
SZ(
"$MODULE" ) );
3108 fp_ptr->SetFPID(
LIB_ID( wxEmptyString, footprintName ) );
3130 FOOTPRINT_MAP::const_iterator it =
m_footprints.find( footprintName );
3136 wxFAIL_MSG( wxT(
"error doing cache insert using guaranteed unique name" ) );
3143 bool nameOK =
false;
3149 std::string newName = footprintName;
3152 snprintf( buf,
sizeof(buf),
"%d", version++ );
3165 wxFAIL_MSG( wxT(
"error doing cache insert using guaranteed unique "
3173 }
while( ( line = aReader->
ReadLine() ) !=
nullptr );
3201 init( aProperties );
3209 errorMsg = ioe.
What();
3216 aFootprintNames.Add(
From_UTF8( footprint.first.c_str() ) );
3218 if( !errorMsg.IsEmpty() && !aBestEfforts )
3224 const wxString& aFootprintName,
bool aKeepUUID,
3229 init( aProperties );
3234 FOOTPRINT_MAP::const_iterator it = footprints.find(
TO_UTF8( aFootprintName ) );
3236 if( it == footprints.end() )
3243 copy->SetParent(
nullptr );
3251 wxFileName fn = aLibraryPath;
3253 if( !fn.FileExists() )
3258 if( wxRemove( aLibraryPath ) )
3260 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' cannot be deleted." ),
3261 aLibraryPath.GetData() ) );
3294 m_progressReporter( nullptr ),
3295 m_lastProgressLine( 0 ),
3297 m_reader( nullptr ),
constexpr int ARC_HIGH_DEF
constexpr EDA_IU_SCALE pcbIUScale
LAYER_T
The allowed types of layers, same as Specctra DSN spec.
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
void SetGridOrigin(const VECTOR2I &aOrigin)
std::unique_ptr< PAD > m_Pad_Master
void SetAuxOrigin(const VECTOR2I &aOrigin)
int m_SolderMaskExpansion
int m_TextThickness[LAYER_CLASS_COUNT]
std::vector< int > m_TrackWidthList
int m_LineThickness[LAYER_CLASS_COUNT]
void SetBoardThickness(int aThickness)
double m_SolderPasteMarginRatio
VECTOR2I m_TextSize[LAYER_CLASS_COUNT]
std::vector< VIA_DIMENSION > m_ViasDimensionsList
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
void SetFPRelativePosition(const VECTOR2I &aPos)
Information pertinent to a Pcbnew printed circuit board.
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
void SetZoneSettings(const ZONE_SETTINGS &aSettings) override
Set the zone settings for this container.
void SetFileName(const wxString &aFileName)
const ZONE_SETTINGS & GetZoneSettings() const override
Fetch the zone settings for this container.
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
void SetPageSettings(const PAGE_INFO &aPageSettings)
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
bool m_LegacyNetclassesLoaded
True if netclasses were loaded from the file.
void SetCopperLayerCount(int aCount)
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Change the type of the layer given by aLayer.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
void SetVisibleElements(const GAL_SET &aMask)
A proxy function that calls the correspondent function in m_BoardSettings.
void SetFileFormatVersionAtLoad(int aVersion)
void SetTextSize(VECTOR2I aNewSize)
virtual const wxString & GetText() const
Return the string associated with the text object.
void SetTextPos(const VECTOR2I &aPoint)
void SetMirrored(bool isMirrored)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual void SetVisible(bool aVisible)
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetItalic(bool aItalic)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
A LINE_READER that reads from an open file.
void Rewind()
Rewind the file and resets the line number back to zero.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
VECTOR3D m_Offset
3D model offset (mm)
VECTOR3D m_Rotation
3D model rotation (degrees)
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
wxString m_Filename
The 3D shape filename in 3D library.
Helper for storing and iterating over GAL_LAYER_IDs.
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 PLUGIN derivation which could possibly be put into a DLL/DSO.
unsigned m_lastProgressLine
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
int getNetCode(int aNetCode)
bool CanReadFootprint(const wxString &aFileName) const override
Checks if this PLUGIN can read a footprint from specified file or directory.
BIU biuParse(const char *aValue, const char **nptrptr=nullptr)
Parse an ASCII decimal floating point value and scales it into a BIU according to the current value o...
static LSET leg_mask2new(int cu_count, unsigned aMask)
void loadFP_SHAPE(FOOTPRINT *aFootprint)
void init(const STRING_UTF8_MAP *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
double diskToBiu
convert from disk engineering units to BIUs
void loadTrackList(int aStructType)
Read a list of segments (Tracks and Vias, or Segzones)
bool m_showLegacySegmentZoneWarning
wxString m_field
reused to stuff FOOTPRINT fields.
static int getVersion(LINE_READER *aReader)
static PCB_LAYER_ID leg_layer2new(int cu_count, int aLayerNum)
PROGRESS_REPORTER * m_progressReporter
may be NULL, no ownership
double biuToDisk
convert from BIUs to disk engineering units with this scale factor
unsigned m_lineCount
for progress reporting
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const STRING_UTF8_MAP *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
void loadFOOTPRINT(FOOTPRINT *aFootprint)
void loadPAD(FOOTPRINT *aFootprint)
void checkpoint()
Converts net code using the mapping table if available, otherwise returns unchanged net code.
void loadAllSections(bool doAppend)
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
bool FootprintLibDelete(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing footprint library and returns true, or if library does not exist returns false,...
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
void load3D(FOOTPRINT *aFootprint)
EDA_ANGLE degParse(const char *aValue, const char **nptrptr=nullptr)
Parse an ASCII decimal floating point value which is certainly an angle in tenths of a degree.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
void loadZONE_CONTAINER()
wxString m_error
for throwing exceptions
std::vector< int > m_netCodes
net codes mapping for boards being loaded
const STRING_UTF8_MAP * m_props
passed via Save() or Load(), no ownership,
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PLUGIN can read the specified board file.
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
LINE_READER * m_reader
no ownership here.
void SetReader(LINE_READER *aReader)
void loadMODULE_TEXT(PCB_TEXT *aText)
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
BOARD * m_board
which BOARD, no ownership here
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
const UTF8 & GetLibItemName() const
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.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
LSET is a set of PCB_LAYER_IDs.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
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 ...
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
static const wxChar Custom[]
"User" defined page type
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
The parser for PCB_PLOT_PARAMS.
Parameters and options when plotting/printing a board.
void Parse(PCB_PLOT_PARAMS_PARSER *aParser)
void SetWidth(int aWidth)
void SetEnd(const VECTOR2I &aEnd)
void SetPosition(const VECTOR2I &aPos) override
virtual bool CanReadFootprint(const wxString &aFileName) const
Checks if this PLUGIN can read a footprint from specified file or directory.
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PLUGIN can read the specified board file.
A progress reporter interface for use in multi-threaded environments.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
Container for project specific data.
Represent a set of closed polygons.
void InflateWithLinkedHoles(int aFactor, CORNER_STRATEGY aCornerStrategy, int aMaxError, POLYGON_MODE aFastMode)
Perform outline inflation/deflation, using round corners.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
A name/value tuple with unique names and optional values.
Simple container to manage line stroke parameters.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
void SetRevision(const wxString &aRevision)
void SetComment(int aIdx, const wxString &aComment)
void SetTitle(const wxString &aTitle)
void SetCompany(const wxString &aCompany)
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
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.
ZONE_SETTINGS handles zones parameters.
static int GetDefaultHatchPitch()
This file is part of the common library.
#define FIRST_COPPER_LAYER
static bool isSpace(char cc)
Test for whitespace.
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
void ignore_unused(const T &)
#define THROW_IO_ERROR(msg)
PCB_LAYER_ID
A quick note on layer IDs:
static GR_TEXT_V_ALIGN_T vertJustify(const char *vertical)
static int intParse(const char *next, const char **out=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define SILKSCREEN_N_BACK
#define PCB_LEGACY_TEXT_is_DIVERS
#define SZ(x)
Get the length of a string constant, at compile time.
static const char delims[]
#define TESTSUBSTR(x)
C sub-string compare test for a specific length of characters.
#define LAST_NON_COPPER_LAYER
#define SOLDERMASK_N_FRONT
#define SOLDERMASK_N_BACK
bool is_leg_copperlayer_valid(int aCu_Count, int aLegacyLayerNum)
#define SOLDERPASTE_N_BACK
int layerMaskCountSet(LEG_MASK aMask)
Count the number of set layers in the mask.
static long hexParse(const char *next, const char **out=nullptr)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
#define SOLDERPASTE_N_FRONT
#define PCB_LEGACY_TEXT_is_REFERENCE
static GR_TEXT_H_ALIGN_T horizJustify(const char *horizontal)
#define SILKSCREEN_N_FRONT
#define TESTLINE(x)
C string compare test for a specific length of characters.
boost::ptr_map< std::string, FOOTPRINT > FOOTPRINT_MAP
#define FIRST_NON_COPPER_LAYER
#define PCB_LEGACY_TEXT_is_VALUE
static bool isSpace(int c)
#define FOOTPRINT_LIBRARY_HEADER_CNT
#define FOOTPRINT_LIBRARY_HEADER
This file contains miscellaneous commonly used macros and functions.
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
PAD_DRILL_SHAPE_T
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
wxString From_UTF8(const char *cstring)
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
static LAYER_T ParseType(const char *aType)
Convert a string to a LAYER_T.
The footprint portion of the PLUGIN API, and only for the LEGACY_PLUGIN, so therefore is private to t...
LP_CACHE(LEGACY_PLUGIN *aOwner, const wxString &aLibraryPath)
void ReadAndVerifyHeader(LINE_READER *aReader)
long long m_cache_timestamp
void LoadModules(LINE_READER *aReader)
FOOTPRINT_MAP m_footprints
static long long GetTimestamp(const wxString &aLibPath)
void SkipIndex(LINE_READER *aReader)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ NOT_USED
the 3d code uses this value
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
ZONE_BORDER_DISPLAY_STYLE
Zone border styles.
ZONE_CONNECTION
How pads are covered by copper in zone.